#StackBounty: #java #web-services #weblogic #axis2 unable to access service for a webapp on specially weblogic

Bounty: 50

I was testing my webservices calls for one of my webapp and seems like it is working on every web-servers except Weblogic.

Seems like there is a bug from Weblogic side. I am attaching the logs and also code.

Here are the logs :

2017-06-08 12:06:40,744 ERROR [org.apache.axis2.engine.AxisEngine] - <The service cannot be found for the endpoint reference (EPR) http://localhost:7001/***/services/***>
org.apache.axis2.AxisFault: The service cannot be found for the endpoint reference (EPR) http://localhost:7001/***/services/***
       at org.apache.axis2.engine.DispatchPhase.checkPostConditions(DispatchPhase.java:65)
       at org.apache.axis2.engine.Phase.invoke(Phase.java:334)
       at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:254)
       at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:160)
       at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:173)
       at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:144)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:751)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
       at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
       at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
       at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
       at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:346)
       at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
       at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
       at com.***.tools.auth.client.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:90)
       at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
       at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3436)
       at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3402)
       at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
       at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
       at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
       at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2285)
       at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2201)
       at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
       at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1572)
       at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255)
       at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)
       at weblogic.work.ExecuteThread.run(ExecuteThread.java:263)

I tried on Tomcat, Jboss and Websphere, It works fine.

Here is the code:

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
            ServletException {

        // Conditionally select and set the character encoding to be used
        if (ignore || (request.getCharacterEncoding() == null)) {
            String encoding = selectEncoding(request);
            if (encoding != null)
                request.setCharacterEncoding(encoding);
        }

        // Pass control on to the next filter
        chain.doFilter(request, response);

        response.setCharacterEncoding(encoding);
    }

Update:

updating web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/config/xxxx/xxxx.xml
            /WEB-INF/config/xxxx/xxxx.xml
            /WEB-INF/applicationContext.xml
            /WEB-INF/config/xxxx/xxxx.xml
            /WEB-INF/classes/xxxx.xml
        </param-value>
    </context-param>

    <!-- Uncomment this section to enable container managed authentication. You'll also need to configure security in the container.
     <context-param>
        <param-name>CBA_Prefix</param-name>
        <param-value>xxxx</param-value>
        <description>Org Prefix - CBA</description>
    </context-param> 
    -->

    <filter>
        <filter-name>EncodeFilter</filter-name>
        <filter-class>com.xxxx.tools.auth.client.SetCharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter>
        <filter-name>authFilter</filter-name>
        <filter-class>com.xxx.tools.auth.client.AuthServletFilter</filter-class>
    </filter>
    <filter>
        <filter-name>ResponseOverrideFilter</filter-name>
        <filter-class>
            org.displaytag.filter.ResponseOverrideFilter
        </filter-class>
    </filter>

    <filter-mapping>
        <filter-name>EncodeFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>authFilter</filter-name>
        <url-pattern>*.do</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>authFilter</filter-name>
        <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>ResponseOverrideFilter</filter-name>
        <url-pattern>*.do</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config-base.xml,/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>configuration</servlet-name>
        <servlet-class>com.xxx.xxxx.xxx.xxx.aConfiguration</servlet-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>
                ${}/xxxx.xml,
                /WEB-INF/config/XSSConfig.xml,
                /WEB-INF/config/xxxx.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>      
    <!-- Axis2  API -->     
    <servlet>
        <servlet-name>AxisServlet</servlet-name>
        <display-name>Apache-Axis Servlet</display-name>
        <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>      

    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

    <!-- Axis2  servlet mapping-->  
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/servlet/AxisServlet</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>*.jws</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>  
    <!-- END OF Axis2 case management API servlet mapping-->    

    <welcome-file-list>
        <welcome-file>Index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <!-- error pages -->
    <error-page>
        <error-code>404</error-code>
        <location>/WEB-INF/jsps/Error.jsp</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/WEB-INF/jsps/Error.jsp</location>
    </error-page>
    <error-page>
        <exception-type>java.lang.Throwable</exception-type>
        <location>/WEB-INF/jsps/Error.jsp</location>
    </error-page>


    <taglib>
        <taglib-uri>http://www.xxxx.com/xxxx/xxxx/xxxx/tags-html</taglib-uri>
        <taglib-location>/WEB-INF/tlds/aa-html.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>http://xxxx.xxxx/tags-tools</taglib-uri>
        <taglib-location>/WEB-INF/tlds/xxxx.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>/WEB-INF/xxx.tld</taglib-uri>
        <taglib-location>/WEB-INF/tlds/xxx.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>/WEB-INF/xxx</taglib-uri>
        <taglib-location>/WEB-INF/tlds/xxxx</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
        <taglib-location>/WEB-INF/tlds/struts-bean.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
        <taglib-location>/WEB-INF/tlds/struts-html.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
        <taglib-location>/WEB-INF/tlds/struts-logic.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>/WEB-INF/xxxx</taglib-uri>
        <taglib-location>/WEB-INF/tlds/xxxx</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
        <taglib-location>/WEB-INF/tlds/struts-tiles.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>http://jakarta.apache.org/struts/tags-bean</taglib-uri>
        <taglib-location>/WEB-INF/tlds/struts-bean.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>http://jakarta.apache.org/struts/tags-html</taglib-uri>
        <taglib-location>/WEB-INF/tlds/struts-html.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>http://jakarta.apache.org/struts/tags-logic</taglib-uri>
        <taglib-location>/WEB-INF/tlds/struts-logic.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>http://jakarta.apache.org/struts/tags-tiles</taglib-uri>
        <taglib-location>/WEB-INF/tlds/struts-tiles.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>http://jakarta.apache.org/taglibs/display</taglib-uri>
        <taglib-location>/WEB-INF/tlds/xxxx</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>http://www.rsasecurity.com/taglibs/RSAList</taglib-uri>
        <taglib-location>/WEB-INF/tlds/xxxx</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>http://displaytag.sf.net</taglib-uri>
        <taglib-location>/WEB-INF/tlds/display.tld</taglib-location>
    </taglib>
    <resource-ref>
        <description>DB Connection</description>
        <res-ref-name>jdbc/xxxxDB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

    <resource-ref>
        <res-ref-name>jdbc/xxxDB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

    <resource-ref>
        <res-ref-name>jdbc/xxxDB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

    <!--   ========================== Container Managed Security =======================  -->

    <!-- Uncomment this section to enable container managed authentication. You'll also need to configure security in the container.
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Protected Area</web-resource-name>
            <url-pattern>/*</url-pattern>
            <http-method>DELETE</http-method>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
            <http-method>PUT</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>xxx</role-name>
            <role-name>xxx</role-name>
            <role-name>xxx</role-name>
            <role-name>xxx</role-name>
            <role-name>xxxx</role-name>
        </auth-constraint>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>default</realm-name>
    </login-config>
    <security-role>
        <description>Admin User</description>
        <role-name>admin</role-name>
    </security-role>
    <security-role>
        <role-name>csr</role-name>
    </security-role>
    <security-role>
        <role-name>xxx</role-name>
    </security-role>
    <security-role>
        <role-name>xxx</role-name>
    </security-role>
    <security-role>
        <role-name>xxx</role-name>
    </security-role>
    -->

    <!--   ============================= Env Entries =================================== -->

    <env-entry>
        <env-entry-name>moduleName</env-entry-name>
        <env-entry-value>xxx</env-entry-value>
        <env-entry-type>java.lang.String</env-entry-type>       
    </env-entry>

    <env-entry>
        <description>Required when accessing PM core database under DB2 using DAOFactory</description>
        <env-entry-name>db2SchemaName</env-entry-name>
        <env-entry-value>xxx</env-entry-value> 
        <env-entry-type>java.lang.String</env-entry-type> 
    </env-entry>

</web-app>


Get this bounty!!!

Installing Apache UserGrid on linux

About the Project

Apache Usergrid is an open-source Backend-as-a-Service (BaaS or mBaaS) composed of an integrated distributed NoSQL database, application layer and client tier with SDKs for developers looking to rapidly build web and/or mobile applications. It provides elementary services and retrieval features like:

  • User Registration & Management
  • Data Storage
  • File Storage
  • Queues
  • Full Text Search
  • Geolocation Search
  • Joins

It is a multi-tenant system designed for deployment to public cloud environments (such as Amazon Web Services, Rackspace, etc.) or to run on traditional server infrastructures so that anyone can run their own private BaaS deployment.

For architects and back-end teams, it aims to provide a distributed, easily extendable, operationally predictable and highly scalable solution. For front-end developers, it aims to simplify the development process by enabling them to rapidly build and operate mobile and web applications without requiring backend expertise.

Usergrid 2.1.0 Deployment Guide

Though the Usergrid Deployment guide seems to be simple enough, I faced certain hiccups and it took me about 4 days to figure out what I was doing wrong.

This document explains how to deploy the Usergrid v2.1.0 Backend-as-a-Service (BaaS), which comprises the Usergrid Stack, a Java web application, and the Usergrid Portal, which is an HTML5/JavaScript application.

Prerequsites

Below are the software requirements for Usergrid 2.1.0 Stack and Portal. You can install them all on one computer for development purposes, and for deployment you can deploy them separately using clustering.

Linux or a UNIX-like system (Usergrid may run on Windows, but we haven’t tried it)

Download the Apache Usergrid 2.1.0 binary release from the official Usergrid releases page:

After untarring the files that you need for deploying Usergrid Stack and Portal are ROOT.war and usergrid-portal.tar.

Stack STEP #1: Setup Cassandra

As mentioned in prerequisites, follow the installation guide given in link

Usergrid uses Cassandra’s Thrift protocol
Before starting cassandra, on Cassandra 2.x releases you MUST enable Thrift by setting start_rpc in your cassandra.yaml file:

    #Whether to start the thrift rpc server.
    start_rpc: true

Note:DataStax no longer supports the DataStax Community version of Apache Cassandra or the DataStax Distribution of Apache Cassandra. It is best to follow the Apache Documentation

Once you are up and running make a note of these things:

  • The name of the Cassandra cluster
  • Hostname or IP address of each Cassandra node
    • in case of same machine as Usergrid, then localhost. Usergrid would then be running on single machine embedded mode.
  • Port number used for Cassandra RPC (the default is 9160)
  • Replication factor of Cassandra cluster

Stack STEP #2: Setup ElasticSearch

Usergrid also needs access to at least one ElasticSearch node. As with Cassandra, you can setup single ElasticSearch node on your computer, and you should run a cluster in production.

Steps:

  • Download and unzip Elasticsearch
  • Run bin/elasticsearch (or bin\elasticsearch -d on Linux as Background Process) (or bin\elasticsearch.bat on Windows)
  • Run curl http://localhost:9200/

Once you are up and running make a note of these things:

  • The name of the ElasticSearch cluster
  • Hostname or IP address of each ElasticSearch node
    • in case of same machine as Usergrid, then localhost. Usergrid would then be running on single machine embedded mode.
  • Port number used for ElasticSearch protocol (the default is 9200)

Stack STEP #3: Setup Tomcat

The Usergrid Stack is contained in a file named ROOT.war, a standard Java EE WAR ready for deployment to Tomcat. On each machine that will run the Usergrid Stack you must install the Java SE 8 JDK and Tomcat 7+.

Stack STEP #4: Configure Usergrid Stack

You must create a Usergrid properties file called usergrid-deployment.properties. The properties in this file tell Usergrid how to communicate with Cassandra and ElasticSearch, and how to form URLs using the hostname you wish to use for Usegrid. There are many properties that you can set to configure Usergrid.

Once you have created your Usergrid properties file, place it in the Tomcat lib directory. On a Linux system, that directory is probably located at /path/to/tomcat7/lib/

The Default Usergrid Properties File

You should review the defaults in the above file. To get you started, let’s look at a minimal example properties file that you can edit and use as your own.

Please note that if you are installing Usergrid on the same machine as Cassandra Server, then set the following property to true

   #Tell Usergrid that Cassandra is not embedded.
   cassandra.embedded=true

Stack STEP #5: Deploy ROOT.war to Tomcat

The next step is to deploy the Usergrid Stack software to Tomcat. There are a variety of ways of doing this and the simplest is probably to place the Usergrid Stack ROOT.war file into the Tomcat webapps directory, then restart Tomcat.

Look for messages like this, which indicate that the ROOT.war file was deployed:

INFO: Starting service Catalina
Jan 29, 2016 1:00:32 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.59
Jan 29, 2016 1:00:32 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /usr/share/tomcat7/webapps/ROOT.war

Does it work?

you can use curl:

curl http://localhost:8080/status

If you get a JSON file of status data, then you’re ready to move to the next step. You should see a response that begins like this:

{
“timestamp” : 1454090178953,
“duration” : 10,
“status” : {
“started” : 1453957327516,
“uptime” : 132851437,
“version” : “201601240200-595955dff9ee4a706de9d97b86c5f0636fe24b43”,
“cassandraAvailable” : true,
“cassandraStatus” : “GREEN”,
“managementAppIndexStatus” : “GREEN”,
“queueDepth” : 0,
“org.apache.usergrid.count.AbstractBatcher” : {
“add_invocation” : {
“type” : “timer”,
“unit” : “microseconds”,
… etc. …

Initialize the Usergrid Database

Next, you must initialize the Usergrid database, index and query systems.

To do this you must issue a series of HTTP operations using the superuser credentials. You can only do this if Usergrid is configured to allow superused login via this property usergrid.sysadmin.login.allowed=true and if you used the above example properties file, it is allowed.

The three operation you must perform are expressed by the curl commands below and, of course, you will have ot change the password test to match the superuser password that you set in your Usergrid properties file.

curl -X PUT http://localhost:8080/system/database/setup -u superuser:test
curl -X PUT http://localhost:8080/system/database/bootstrap -u superuser:test
curl -X GET http://localhost:8080/system/superuser/setup -u superuser:test

When you issue each of those curl commands, you should see a success message like this:

{
“action” : “cassandra setup”,
“status” : “ok”,
“timestamp” : 1454100922067,
“duration” : 374
}

Now that you’ve gotten Usergrid up and running, you’re ready to deploy the Usergrid Portal.

Deploying the Usergrid Portal

The Usergrid Portal is an HTML5/JavaScript application, a bunch of static files that can be deployed to any web server, e.g. Apache HTTPD or Tomcat.

To deploy the Portal to a web server, you will un-tar the usergrid-portal.tar file into directory that serves as the root directory of your web pages.

Once you have done that there is one more step. You need to configure the portal so that it can find the Usergrid stack. You do that by editing the portal/config.js and changing this line:

Usergrid.overrideUrl = ’http://localhost:8080/‘;

To set the hostname that you will be using for your Usergrid installation.

I have deployed a sample instance and tested the same. You can find the system ready configurations in TechUtils repository

Unirest: Lightweight HTTP Request Client Libraries

UniRest

Unirest is a set of lightweight HTTP libraries available in multiple languages, built and maintained by the Mashape team.

Unirest.post("http://httpbin.org/post")
  .queryString("name", "Mark")
  .field("last", "Polo")
  .asJson()

Features

  • Make GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS requests
  • Both syncronous and asynchronous (non-blocking) requests
  • It supports form parameters, file uploads and custom body entities
  • Easily add route parameters without ugly string concatenations
  • Supports gzip
  • Supports Basic Authentication natively
  • Customizable timeout, concurrency levels and proxy settings
  • Customizable default headers for every request (DRY)
  • Customizable HttpClient and HttpAsyncClient implementation
  • Automatic JSON parsing into a native object for JSON responses
  • Customizable binding, with mapping from response body to java Object

Installing

Is easy as pie. Kidding. It’s about as easy as doing these little steps:

With Maven

You can use Maven by including the library:

<dependency>
    <groupId>com.mashape.unirest</groupId>
    <artifactId>unirest-java</artifactId>
    <version>1.4.7</version>
</dependency>

There are dependencies for Unirest-Java, these should be already installed, and they are as follows:

<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpclient</artifactId>
  <version>4.3.6</version>
</dependency>
<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpasyncclient</artifactId>
  <version>4.0.2</version>
</dependency>
<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpmime</artifactId>
  <version>4.3.6</version>
</dependency>
<dependency>
  <groupId>org.json</groupId>
  <artifactId>json</artifactId>
  <version>20140107</version>
</dependency>

If you would like to run tests, also add the following dependency along with the others:

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.11</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>commons-io</groupId>
  <artifactId>commons-io</artifactId>
  <version>2.4</version>
  <scope>test</scope>
</dependency>

Without Maven

Alternatively if you don’t use Maven, you can directly include the JAR file in the classpath:http://oss.sonatype.org/content/repositories/releases/com/mashape/unirest/unirest-java/1.4.7/unirest-java-1.4.7.jar

Don’t forget to also install the dependencies (org.json, httpclient 4.3.6, httpmime 4.3.6,httpasyncclient 4.0.2) in the classpath too.

There is also a way to generate a Unirest-Java JAR file that already includes the required dependencies, but you will need Maven to generate it. Follow the instructions at http://blog.mashape.com/post/69117323931/installing-unirest-java-with-the-maven-assembly-plugin

Creating Request

So you’re probably wondering how using Unirest makes creating requests in Java easier, here is a basic POST request that will explain everything:

HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post")
  .header("accept", "application/json")
  .queryString("apiKey", "123")
  .field("parameter", "value")
  .field("foo", "bar")
  .asJson();

Requests are made when as[Type]() is invoked, possible types include Json, Binary, String, Object.

If the request supports and it is of type HttpRequestWithBody, a body it can be passed along with.body(String|JsonNode|Object). For using .body(Object) some pre-configuration is needed (see below).

If you already have a map of parameters or do not wish to use seperate field methods for each one there is a.fields(Map<String, Object> fields) method that will serialize each key – value to form parameters on your request.

.headers(Map<String, String> headers) is also supported in replacement of multiple header methods.

Full Documentation @ unirest.io