WSO2 API Manager Consume Error While Caching is enabled - wso2

When I enable Caching for an API and try to consume it, I receive the response code error 500 with a description - "Error while building message". The response works fine when Caching is turned off. Any ideas?

This error can be occurred if you are passing a empty value to the request body for a POST request. Because the default JSON builder trying to convert JSON to XML and you can see this error when converting an empty message.
If you are sending a empty body for a post request change the builder and formatter to JsonStreamBuilder and JsonStreamFormatter using following steps.
1) Open axis2.xml which is in (APIM_HOME)/repository/conf/axis2 folder and comment the default JSON builder and formatter.
<!--messageBuilder contentType="application/json"
class="org.apache.synapse.commons.json.JsonBuilder"/-->
<!--messageFormatter contentType="application/json"
class="org.apache.synapse.commons.json.JsonFormatter"/-->
2) Un-comment the JsonStreamBuilder and JsonStreamFormatter.
<messageBuilder contentType="application/json"
class="org.apache.synapse.commons.json.JsonStreamBuilder"/>
<messageFormatter contentType="application/json"
class="org.apache.synapse.commons.json.JsonStreamFormatter"/>

Related

WSO2 EI 6.6.0 hal_json Format Issue

6.0 to call a Drupal 8 RESTful web service endpoint which returns the response in hal_json format. I have never come across this format before but this is what the Drupal 8 response is in. The Content-Type is "application/hal+json". For more information, this is the Drupal 8 link - https://www.drupal.org/docs/8/core/modules/rest/3-post-for-creating-content-entities
I'm using a property mediator to convert the response from hal_json format to XML but I'm getting the below error:
OMException in getSOAPBuilder org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{' (code 123) in prolog; expected '<'
I searched online for this error and found that this type of error usually occurs when the API response is in a format that is not enabled in WSO2 (it needs to be enabled in the axis2.xml file). Can anyone please tell me what property I need to add to my axis2.xml file? I think is needs to be a message formatter and builder property.
I have not worked with the JSON message type specified. But if it is a valid JSON message you can define a JsonStreamBuilder builder for this message type. The message builder can be defined as follows in the axis2.xml file under messageBuilders in [EI_HOME]/conf/axis2 directory
<messageBuilders>
..
<messageBuilder contentType="application/hal+json"
class="org.wso2.carbon.integrator.core.json.JsonStreamBuilder"/>
..
</messageBuilders>
After modifying the axis2.xml you need to perform a server restart in order for this to take effect.

WSO2 contentType text/html overlap with application/xml in axis2.xml

I have two APIs. Someone returning to contentType text/html. Other one returning contentType application/xml.
I added this parameter in WSO2/ axis2.xml file for wso2 should read to text/html
And i got succes from API but now other API ( i mean return to application/xml) , thats not working correct.
Can someone help me please? How should i do?
Thanks
If you want to enable message relay, so that messages of a specific content type are not built or formatted but simply pass through the ESB, you can specify the message relay builder (org.wso2.carbon.relay.BinaryRelayBuilder) for that content type. Make sure that you specify message builder and formatter for both the content types (application/xml , text/html). Refer to the following sample configuration. You need to add these in the axis2.xml file under messageFormatters and messageBuilders.
Message formatters
<messageFormatter contentType="application/xml"
class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
<messageFormatter contentType="text/html"
class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
Message builders
<messageBuilder contentType="text/xml"
class="org.wso2.carbon.relay.BinaryRelayBuilder"/>
<messageBuilder contentType="application/xml"
class="org.apache.axis2.builder.ApplicationXMLBuilder"/>
[1]-https://docs.wso2.com/display/EI611/Configuring+Message+Relay

How to write the post request in wso2 api manager?

i want to send the POST request with JSON as POST data and it should also accept attachments. I checked the documentation but unable to create the POST
Create a new api with http post type and Payload Parameter name and body parameter type.
if you use form/multipart you must edit some axis2 config file in api manager.
go to wso2am/repository/conf/axis2 and edit axis2.xml.
add this lines:
<messageFormatter contentType="multipart/form-data"
class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
<messageFormatter contentType="multipart/form-data"
class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>

JMeter returns wsdl as a response

Im trying to do simple web service test using JMeter. I'm using SOAP/XML-RPC Request with simpliest configuration
URL = https://...address here..?wsdl
SOAP action and Use KeepAlive stay unchecked
XML request is loaded from file, correctly
What is more i have added View Result Tree to see results.
Thats all.
Problem is i'm still getting whole wsdl file as a response (i have expected a normal soap response for my xml soap requst).
I have tested in SOAPui this request and url - everythink working fine. Do i need do add smth more? maybe this is problem with https protocol?
What is more i have tried WebService (SOAP) Request (DEPRECATED) however im getting exception becouse of using https while i want to use load WSDL.
Any ideas to solve my problem?
Here is a request from View Result Tree
POST https://...address here..?wsdl
POST data:
Filename: D:\install\apache-jmeter-2.11\TEST\request.xml
<actual file content, not shown here>
[no cookies]
Request Headers:
Content-Type: text/xml
Connection: close
User-Agent: Jakarta Commons-HttpClient/3.1
Host: hostname
Content-Length: 1826
EDIT: i solved this problem by doing configuration like this:
ULR = https://..address here.. (NO WSDL)
SOAP action specified (url from wsdl)
KeepAlive checked
XML pasted in textbox section
However when i load xml from file - test fails with message couldnt parse stream. The same message pasted into textbox section - works perfectly. Whats wrong?
Configuration:
URL : scheme://..address here.. (NO WSDL)
SOAP action specified (url from wsdl)
KeepAlive checked
path to XML file pasted into right section
File encoding:
XML was not loading as i expected because of encoding.
I had set UTF-8 with BOM encoding while my service expected UTF-8 without BOM.

Problem with Posting JSON object with WSRequest

I want Play to call a webservice. The webservice accepts application/json and returns this as well. With the following code I'm trying to achieve this. (Note, the headers.put(xxx) are added later in an effort to solve the problem).
WSRequest request = WS.url(targetURL);
request.body = new Gson().toJson(user);
request.headers.put("Content-type","application/json");
request.headers.put("Accept","application/json");
request.post();
The strange thing is that my JBOSS server replies: "Cannot consume content type". If I use my 'Simple REST client' plugin in my Chrome browser, and provide the entire JSON Body GSon created and add the content-type header, I get a valid response. Is this not the way to send JSON to the server? Or am I missing some fundamental piece here?
While checking the API documentation on the WSRequest class i noticed the field mime-type
By setting it as follows JBOSS (resteasy) accepted my request succesfully.
request.mimeType = "application/json";