WSO2 ESB FORCE_HTTP_1.0 not working - wso2

I'm trying to force the WSO2 to set the http version to 1.0 because the client of a service requires the Content-Length property. I configured the following properties in the outSequence, before the <send/>:
<property name="FORCE_HTTP_1.0" value="true" scope="axis2"/>
<property name="DISABLE_CHUNKING" value="true" scope="axis2"/>
but it doesn't works! The response header:
HTTP/1.0 200 OK
userAgent: Synapse-PT-HttpComponents-NIO
Host: localhost:8280
SOAPAction: "sendMessage"
Accept-Encoding: gzip,deflate
Content-Type: text/xml; charset=UTF-8
Server: WSO2-PassThrough-HTTP
Date: Thu, 13 Mar 2014 21:55:25 GMT
Connection: Close
I'm using ESB 4.6.0 and SoapUI to call the service.
Why the Content-Length doesn't appears? What's wrong?

This is a bug in ESB and we fixed it recently.
https://wso2.org/jira/browse/ESBJAVA-2985
The properties you mentioned are not working in outSequence path.
The fix should be available in next release.
The patch for Synapse transport is also attached in ESBJAVA-2985 and you may patch the Synapse version in your WSO2 ESB.

Related

REST Proxy Server with Apache Synapse

Iam new to the ESB's and Apache Synapse. I have a simple REST API that takes a GET method and returns a simple json response. I tried to create a proxy with Apache Synapse.
The configuration is given below.
<proxy name="SampeJsonProxy">
<target>
<endpoint>
<address uri="http://localhost:8081/kafka/publish/hello" format="json" methods="GET"/>
</endpoint>
<inSequence>
<log level="full"/>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
</proxy>
When I do a curl on the REST API I get response as
curl -v http://127.0.0.1:8081/kafka/publish/hello
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8081 (#0)
> GET /kafka/publish/hello HTTP/1.1
> Host: 127.0.0.1:8081
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 200
< Content-Type: text/plain;charset=UTF-8
< Content-Length: 48
< Date: Wed, 10 Feb 2021 13:48:27 GMT
<
{"name": "John", "age": 31, "city": "New York"}* Connection #0 to host 127.0.0.1 left intact
When I do a curl on the synapse server I get as below without response.
curl -v http://127.0.0.1:8280/kafka/publish/hello
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8280 (#0)
> GET /kafka/publish/hello HTTP/1.1
> Host: 127.0.0.1:8280
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 202 Accepted
< Date: Wed, 10 Feb 2021 13:48:18 GMT
< Server: Synapse-PT-HttpComponents-NIO
< Transfer-Encoding: chunked
<
* Connection #0 to host 127.0.0.1 left intact
The log on synapse server is shown below.
INFO LogMediator To: /kafka/publish/hello, MessageID: urn:uuid:46af1619-6bbb-4fe9-b00f-2ec1e7e938a3, Direction: request
I ran the configuration by editing the synapse_sample_150.xml and replacing content with above proxy and run it as synapse.bat -sample 150.
I don't understand why this is not working. Can someone help me understand the problem. I refered the second example in the here.
I found the problem. I was hitting at the wrong proxy.Giving a curl at http://127.0.0.1:8280/services/SampeJsonProxy
solves the gives the right output.

Connecting Mule to Salesforce's SOAP based Web Service

I am trying to connect MuleSfot to Salesforce SOAP based web service using Web Service Consumer. Trying in SOAPUI first but getting INVALID_SESSION_ID, I need to login in Salesforce to get the ID but not clear.
Help please!!
EDIT 1
Request I am sending
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:="http://soap.sforce.com/schemas/class/WebService">
<soapenv:Header>
<AllowFieldTruncationHeader>
<allowFieldTruncation>false</allowFieldTruncation>
</AllowFieldTruncationHeader>
<DebuggingHeader>
<!--Zero or more repetitions:-->
<categories>
<category>All</category>
<level>None</level>
</categories>
<debugLevel>None</debugLevel>
</DebuggingHeader>
<CallOptions>
<client>?</client>
</CallOptions>
<SessionHeader>
<sessionId>?</sessionId>
</SessionHeader>
</soapenv:Header>
<soapenv:Body>
</soapenv:Body>
</soapenv:Envelope>
? for client is fine.
It's session ID which I cant get
RAW REQUEST
POST https://cs61.salesforce.com/services/Soap/class/WebService HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Content-Length: 972
Host: cs61.salesforce.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
RAW RESPONSE
HTTP/1.1 500 Server Error
Date: Tue, 24 Jan 2017 04:18:15 GMT
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Content-Security-Policy: reflected-xss block;report-uri /_/ContentDomainCSPNoAuth?type=xss
Content-Security-Policy: referrer origin-when-cross-origin
Set-Cookie: BrowserId=CdHsqmLzR3OFRklUfp1p3g;Path=/;Domain=.salesforce.com;Expires=Sat, 25-Mar-2017 04:18:15 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: text/xml; charset=utf-8
Transfer-Encoding: chunked
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="http://soap.sforce.com/schemas/class/WebService">
<soapenv:Body>
<soapenv:Fault>
<faultcode>sf:INVALID_SESSION_ID</faultcode>
<faultstring>INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session</faultstring>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
I got it. Needed to login to Salesforce first, used the login() call and get session ID.
Thanks

Convert SoapUI Request into CFHTTP

I am looking at a request in SoapUI that is sending header info to a specific endpoint but I am having a hard time recreating it in ColdFusion.
Below is what the RAW request looks like in SoapUI:
>> "GET https://test-01.mywebsite.com/data_api//1.0/service/requests HTTP/1.1[\r][\n]"
>> "Accept-Encoding: gzip,deflate[\r][\n]"
>> "Authorization: Bearer A1BEC30F7E0273059E775A6A2645E273[\r][\n]"
>> "Host: test-01.mywebsite.com[\r][\n]"
>> "Connection: Keep-Alive[\r][\n]"
>> "User-Agent: Apache-HttpClient/4.1.1 (java 1.5)[\r][\n]"
>> "[\r][\n]"
<< "HTTP/1.1 200 OK[\r][\n]"
<< "Pragma: No-cache[\r][\n]"
<< "Cache-Control: no-cache[\r][\n]"
<< "Expires: Wed, 31 Dec 1969 16:00:00 PST[\r][\n]"
<< "Content-Type: application/json;charset=UTF-8[\r][\n]"
<< "Content-Length: 6796[\r][\n]"
<< "Date: Fri, 13 May 2016 15:40:08 GMT[\r][\n]"
<< "Server: hws[\r][\n]"
<< "Set-Cookie: X-HR-ClientSessionId=2_10.85.12.121_1463154008475;Secure; path=/; HttpOnly[\r][\n]"
<< "Content-Encoding: deflate[\r][\n]”
I am not sure if I am not formatting the Authorization header correctly or what but any help would be great.
EDIT I got a RAW HTML output from the client which I have updated above. I am still trying to recreate that header in ColdFusion.
My New question(s): Do the "New Line" characters make a difference in the header values? Should I also add a parameter for the content type?
I did try the following:
<cfset NL="Bearer BD4DF031B24180C9338F0D9F060556A7" & Chr(10) & Chr(13)/>
<cfhttp method="get" url="https://test-01.mywebsite.com/data_api//1.0/service/requests" result="orderList">
<cfhttpparam type="HEADER" name="Authorization" value="#NL#">
<cfhttpparam type="Header" name="Accept-Encoding" value="gzip,deflate">
</cfhttp>
<cfset CurrentOrders = deserializeJSON(orderList.filecontent)>
<cfdump var="#CurrentOrders#">
When I dump everything from the cfhttp call I get:
struct
Charset UTF-8
ErrorDetail [empty string]
Filecontent Connection Failure
Header HTTP/1.1 200 OK Connection: close Expires: Wed, 31 Dec 1969 16:00:00 PST Date: Tue, 17 May 2016 19:23:36 GMT Server: hws Pragma: No-cache Cache-Control: no-cache Set-Cookie: X-HR-ClientSessionId=3_12.161.115.226_1463513016026;Secure; path=/; HttpOnly Content-Type: application/json;charset=UTF-8
Mimetype application/json
Responseheader
struct
Cache-Control no-cache
Connection close
Content-Type application/json;charset=UTF-8
Date Tue, 17 May 2016 19:23:36 GMT
Expires Wed, 31 Dec 1969 16:00:00 PST
Explanation OK
Http_Version HTTP/1.1
Pragma No-cache
Server hws
Set-Cookie X-HR-ClientSessionId=3_12.161.115.226_1463513016026;Secure; path=/; HttpOnly
Status_Code 200
Statuscode 200 OK
Text NO
I am getting a 200 OK status code but still getting a Connection Failure.
It looks like you're double encrypting your security token.
I modified your code so I could capture the request with Fiddler as per Leighs Answer. To get ColdFusion to send the traffic through Fiddler I modified Dmitri Pisarenko answer for http and added it to my JVM Arguments.
<cfhttp method="get" url="http://localhost/data_api/1.0/service/requests" result="orderList">
<cfhttpparam type="HEADER" name="Authorization" value="Basic #ToBase64("Bearer 6EDC52118E164AE659EA2C772F3B9804")#">
<cfhttpparam type="Header" name="Accept-Encoding" value="gzip,deflate">
</cfhttp>
The head I get leaving the cfhttp request is:
GET http://localhost/data_api/1.0/service/requests HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip,deflate
Connection: close
Authorization: Basic QmVhcmVyIDZFREM1MjExOEUxNjRBRTY1OUVBMkM3NzJGM0I5ODA0
Host: localhost
Connection: Keep-Alive
As you can see, the Authorization header isn't the same as what SoapUI created.
I modified the value of the Authorization param to : "Bearer 6EDC52118E164AE659EA2C772F3B9804" and I get a header with an authentication header that matches the raw header from SoapUI:
GET http://localhost/data_api/1.0/service/requests HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip,deflate
Connection: close
Authorization: Bearer 6EDC52118E164AE659EA2C772F3B9804
Host: localhost
Connection: Keep-Alive

wso2 esb 4.8.1 callout mediator and multipart/form-data bug?

We are having problems with callout and multipart/form-data
Our api is for upload a file
We have this builder and formater configured
<messageBuilder contentType="multipart/form-data" class="org.wso2.carbon.relay.BinaryRelayBuilder"/>
<messageFormatter contentType="multipart/form-data" class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
But in execution we see that org.wso2.carbon.relay.BinaryRelayBuilder is used, but when we call an endpoint with callout mediator the
message formater that is executed is MultipartFormDataBuilder instead ExpandingMessageFormatter, that make that the attachment don't arrive to the endpoint (we supose this is a bug)
<api xmlns="http://ws.apache.org/ns/synapse" name="CloneTest" context="/cloneTest">
<resource methods="POST" uri-template="/test6">
<inSequence>
<sequence key="Clone3Sequence"></sequence>
<log level="full">
<property name="***** IN Estoy en el GET /cloneTest/test5 sequence11- $.clave = " expression="json-eval($.clave)"></property>
</log>
<drop></drop>
</inSequence>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="Clone3Sequence" trace="disable">
<property name="HTTP_METHOD" value="POST" scope="axis2"></property>
<callout serviceURL="http://localhost:1234/ProyectoWebMultipartForm/UploadServlet/recurso1">
<source type="envelope"></source>
<target key="RESPUESTA"></target>
</callout>
<property xmlns:ns="http://org.apache.synapse/xsd" name="RESPUESTAAAAAAAA" expression="get-property('RESPUESTA')"></property>
</sequence>
Request that arrive to the esb
POST /cloneTest/test6 HTTP/1.1
Host: 127.0.0.1:1234
Connection: keep-alive
Content-Length: 300
Cache-Control: no-cache
Origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
apikey: b7608e32c2bb4aaa85c47584bf1b5508
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryNuCtYYL1ByZXkmrY
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36
Postman-Token: 218244a6-8fc3-1911-b2db-22ff2bf93bd1
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: es-ES,es;q=0.8
------WebKitFormBoundaryNuCtYYL1ByZXkmrY
Content-Disposition: form-data; name="payload"
{"a","b"}
------WebKitFormBoundaryNuCtYYL1ByZXkmrY
Content-Disposition: form-data; name="file"; filename="prueba.txt"
Content-Type: text/plain
pruebaaaaaaaa
------WebKitFormBoundaryNuCtYYL1ByZXkmrY--
Request that arrive to the endpoint
POST /ProyectoWebMultipartForm/UploadServlet/recurso1/test6 HTTP/1.1
Content-Type: multipart/form-data; charset=UTF-8; boundary=MIMEBoundary_02d66e5320a1bf4a46f61b9faa892f7837ffed6e9ee5e74d
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: es-ES,es;q=0.8
apikey: b7608e32c2bb4aaa85c47584bf1b5508
Cache-Control: no-cache
Origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
Postman-Token: 218244a6-8fc3-1911-b2db-22ff2bf93bd1
User-Agent: Axis2
Host: 127.0.0.1:1234
Transfer-Encoding: chunked
0
We supose that this is a bug in WSO2 4.8.1 version, could someone confirm this to us?
Thanks in advance
Did you check the defined message formatters and builders in the ESB_HOME/repository/conf/axis2/axis2_blocking_client.xml for the specific contentType(multipart/form-data) because callout mediator is using for sending request as a blocking way. So it is internally using axis2_blocking_client.xml

WSO2 ESB sending MTOM encoded request from proxy service

I need to send MTOM encoded request from WSO2 ESB proxy service.
I'm setting parameters:
<property name="enableMTOM" value="true" scope="axis2" type="STRING"/>
<property name="messageType" value="multipart/related" scope="axis2" type="STRING"/>
and it works fine.
Headers of the request:
POST /alfresco/cmisws/DiscoveryService HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: multipart/related; boundary="MIMEBoundary_a62df4c2a350faee72d4e9faf54c07e7135aa06bcf30bf02"; type="application/xop+xml"; start="<0.b62df4c2a350faee72d4e9faf54c07e7135aa06bcf30bf02#apache.org>"; start-info="text/xml"
SOAPAction: "urn:mediate"
Transfer-Encoding: chunked
Host: 127.0.0.1:8181
Connection: Keep-Alive
User-Agent: Synapse-PT-HttpComponents-NIO
67b
--MIMEBoundary_a62df4c2a350faee72d4e9faf54c07e7135aa06bcf30bf02
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <0.b62df4c2a350faee72d4e9faf54c07e7135aa06bcf30bf02#apache.org>
But I need to call my proxy service as HTTP GET. So when I need to send MTOM encoded request from proxy service, I'm setting additional attribute format="soap11" in the endpoint definition.
And message is no longer MTOM encoded - Content-Type is text/xml.
POST /alfresco/cmisws/DiscoveryService HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml
Transfer-Encoding: chunked
Host: 127.0.0.1:8181
Connection: Keep-Alive
User-Agent: Synapse-PT-HttpComponents-NIO
678
--MIMEBoundary_c62df4c2a350faee60d6513af54c07e7035aa06bcf30bf02
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <0.d62df4c2a350faee60d6513af54c07e7035aa06bcf30bf02#apache.org>
Without format="soap11" attribute I'am getting error
SequenceMediator Error while building message
org.apache.axiom.om.OMException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,530]
Message: The element type "body" must be terminated by the matching end-tag "</body>".
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)
Sequence deffinition:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="GetDocIdFromAlfresco">
<property name="enableMTOM" value="true" scope="axis2" type="STRING"/>
<property name="messageType" value="multipart/related" scope="axis2" type="STRING"/>
<payloadFactory media-type="xml">
.
.
.
</payloadFactory>
<call>
<endpoint>
<address uri="http://localhost:8080/alfresco/cmisws/DiscoveryService" format="soap11"/>
</endpoint>
</call>
<respond/>
</sequence>
How can I send MTOM encoded request from proxy service called as HTTP GET?
You can not send multipart with GET request, as it should not contain body, only a header.
I encountered this before: it seems that ESB does not allow creating a mtom-enabled get-request, because there is no content to mtom-ifie. But for CMIS, you really need this: the CMIS specs specify that all request, also the GET requests, should be encoded.
In the end I worked around it by creating a custom mediator that does all CMIS contact via the OpenCMIS java api.