WSO2 EI 6.6.0 hal_json Format Issue - wso2

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.

Related

Is there an available messageFormater or messageBuilder for contentType binary/x-gzip in WSO2?

Currently having an error Invalid UTF-8 start byte 0x8b (at char #2, byte #-1).
The response is currently zipped and would like to know how to transform the received message into xml format. The response for the service at soapUI has a Content-Type: binary/x-gzip.
What can be the messageFormater and messageBuilder in WSO2 in order to parse the data received? Or, what type of property should be used?
You have to use BinaryRelayBuilder and ExpandingMessageFormatter to just pass data through the ESB without built or formatted. This message builder and message formatter need to added into the axis2.xml file located in <EI_HOME>/conf/axis2 directory.

Error 415 Unsupported Media Type while executing list REST API from post man

I am using List REST API for loading Party data. Using the details below:
Request type : POST
URL : http://localhost:1512/rest/V1.0/list/Party
Authorization : Yes
Header : No Header information
Body : form Data ->xml file.
When I send request I am getting below error. Can you please help me.
http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
Error 415 Unsupported Media Type
In my case for PUT call, I set Body to "raw" and added "Content-Type" to "application/json"
You will need to include a header in your post request. Add a value under headers in Postman to include a key for Content-Type with a value of application/xml. You may also want to try a value of text/xml depending on what your body content is.
Here's a link for info on the difference between text/xml and application/xml.
In my case, I was creating a Web API 2.1 project in VS 2017 and I got the same problem. I just should disable SSL. The route to disable is right click on name project > properties > Debug > Anable SSL.

WSO2 API Manager "error": "no response from server"

I have published API in WSO2 using swagger JSON. After publish I am trying to call rest api using swagger in APP Console. It says
Response Body no content
Response Code 0
Response Headers {
"error": "no response from server"
}
There is no any error on server which will help me to understand problem.
Here is the request URL which I am using in local server : https://192.168.1.118:8243/api/2.0/questions/1/answers?start=1&end=1&fields=answerId%2CanswerDescription%2CcreateDate
In my API there are some custom header parameter. Because of this custom header parameter it was not working. I have added custom header parameter in api-manager.xml file.
<Access-Control-Allow-Headers>authorization,Access-Control-Allow-Origin,Content-Type,loggedInUserId,accessToken,clientToken</Access-Control-Allow-Headers>
I have faced a similar issue. I have edited the URL(from apicreator login) after it was published for first time and published it again. But the changes were never reflected. WSO2 was pointing to the old URL. Check the logs for error at "WSO2 HOME\repository\logs\wso2-apigw-errors" . Create another version and publish again and it should work.
The error is real, but misleading. In most likelihood, you've set the spec so that it returns a specific content type (say, application/json) but you actually return plain text (like a string or a number). swagger-ui expects it to be a JSON, tries to parse it and fails, giving you the wrong error message. However, it does mean your spec does not match what your API actually does.

blank Json request body in wso2 esb

I am getting the Blank JSON body in request. due to that ESB is given the below error.
org.apache.axis2.AxisFault: No JSON payload provided.
I am using the wso2 esb 4.9.0 version.
request is POST.
Can you please help in that .
This is a limitation of ESB, you can either send an empty json payload as {} or you can set the Content-Type as application/xml in the request.
According to the HTTP spec "The Content-Type entity-header field indicates the media type of the entity-body sent to the recipient or, in the case of the HEAD method, the media type that would have been sent had the request been a GET"
[1] https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
So if you are defining the media type as "application/json", then there should be a matching entity body for POST. That is why you need to send at-least empty JSON body. If you don't have a body then change the resource to GET rather POST.
But the I found the issue. yes you are right but in Wso2 ESB 4.8.1 if we pass any message with without body as post then we got the error to avoid that we had created the blank payload to call that API. as soon as I removed that blank payload issue resolved. I agreed that post need that body but I had to consume the message of other system that will provide the same (Post with body).
one more thing. if any one put log as full then also you will get the same error.

wsimport with special character and Xauthfile

I'm facing the same problem that this guy here:
wsimport Xauthfile error
Since he didn't gave a feedback and I'm new here and can't ask him if he solved his problem I'm opening a new question.
I'm using ubuntu and have JDK7 from java oracle installed.
I'm consuming a thirdparty web service. The password (...GT##ED...) for the webservice have a character that conflicts with de -Xauthfile syntax (http[s]://user:password#host:port//) because of the "#". The dots (...) represents the rest of my password.
Here is the command I'm running:
wsimport -p loa -Xauthfile "path_to_auth.txt" https://myWS?wsdl
In my auth.txt file I have:
https://user:...GT##ED...#myWS?wsdl
In return a get
parsing WSDL...
[ERROR] Server returned HTTP response code: 401 for URL: https://myWS?wsdl,
"https://myWS?wsdl" needs authorization, please provide authorization file with
read access at /home/user_name/.metro/auth or use -Xauthfile to give the
authorization file and on each line provide authorization information using this
format : http[s]://user:password#host:port//<url-path>
I search all over the net, but no success.
When I try to import the WS using SoapUI like in this tutorial I got a
[ERROR] sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid
certification path to requested target
and I don't know where to specify the ssl file for SoapUI. I tryed in
preferences -> SSL Settings
but no lucky.
That's it. I'll apreciate any help.
EDIT
OK, so I pass through the authorization, changing the characters using the HTML URL Encoding Reference, but now I'm getting the following error
[ERROR] Server redirected too many times (20), "https://ws?wsdl" needs
authorization, please provide authorization file with read access at /home/user
/.metro/auth or use -Xauthfile to give the authorization file and on each line
provide authorization information using this format :
http[s]://user:password#host:port//<url-path>
I am using Apache axis2 instead of wsimport. first this problem happened for me, and I write a bash script and it worked.
#!/bin/bash
/axis2-1.7.9/bin/wsdl2java.sh -uri http://username:password#domain/x?wsdl
I also use encoding password and username by 'url encoding' such as bellow:
##%g3E99! -(URL encoding)-> %40%23%25g3E99%21
First create auth.txt file where you need to put the following and save it in C drive:
http://username:password#localhost:port/wsdlurl
Now run the following command:
wsimport -Xauthfile C:\auth.txt -keep http://example.com/test?wsdl
This worked for me.