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.
Related
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.
I am using WSO2 EI 6.4.0
I have created an API which will call external URL to get the information. Below is my code for an API in WSO2 EI
<?xml version="1.0" encoding="UTF-8"?>
<api context="/api/seqadd" name="seq_mediator" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST GET">
<inSequence>
<property name="basicAuth" scope="default" type="STRING" value="xxxxx"/>
<property name="grant_type" scope="default" type="STRING" value="client_credentials"/>
<property name="scope" scope="default" type="STRING" value="vvv/.drer"/>
<payloadFactory media-type="xml">
<format>
<root>
<grant_type>$1</grant_type>
<scope>$2</scope>
</root>
</format>
<args>
<arg1 evaluator="xml" expression="$ctx:grant_type"/>
<arg2 evaluator="xml" expression="$ctx:scope"/>
</args>
</payloadFactory>
<property expression="fn:concat('Basic ', get-property('basicAuth'))" name="Authorization" scope="transport" type="STRING"/>
<property name="messageType" scope="axis2" type="STRING" value="application/x-www-form-urlencoded"/>
<property expression="$body/*" name="payload created"/>
<property expression="get-property('axis2','REST_URL_POSTFIX')" name="resource" scope="default" type="STRING"/>
<property action="remove" name="REST_URL_POSTFIX" scope="default"/>
<call blocking="true">
<endpoint name="URL">
<http method="post" uri-template="https://example.com/login/v1.0/token"/>
</endpoint>
</call>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<property expression="json-eval($.access_token)" name="Authorization" scope="default" type="STRING"/>
<property expression="fn:concat('Bearer ', get-property('Authorization'))" name="Authorization" scope="transport" type="STRING"/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
When calling this API, I am getting below error
[2020-03-02 14:36:52,829] [EI-Core] DEBUG - headers http-incoming-2 >> GET /api/seqadd HTTP/1.0
[2020-03-02 14:36:52,829] [EI-Core] DEBUG - headers http-incoming-2 >> X-Forwarded-Host: example.com
[2020-03-02 14:36:52,829] [EI-Core] DEBUG - headers http-incoming-2 >> X-Forwarded-Server: example.com
[2020-03-02 14:36:52,829] [EI-Core] DEBUG - headers http-incoming-2 >> Connection: close
[2020-03-02 14:36:52,829] [EI-Core] DEBUG - headers http-incoming-2 >> Content-Type: application/x-www-form-urlencoded
[2020-03-02 14:36:52,829] [EI-Core] DEBUG - headers http-incoming-2 >> User-Agent: PostmanRuntime/7.22.0
[2020-03-02 14:36:52,830] [EI-Core] DEBUG - headers http-incoming-2 >> Accept: */*
[2020-03-02 14:36:52,830] [EI-Core] DEBUG - headers http-incoming-2 >> Cache-Control: no-cache
[2020-03-02 14:36:52,830] [EI-Core] DEBUG - headers http-incoming-2 >> Accept-Encoding: gzip, deflate, br
[2020-03-02 14:36:52,983] [EI-Core] DEBUG - header >> "POST /login/v1.0/token HTTP/1.1[\r][\n]"
[2020-03-02 14:36:52,989] [EI-Core] DEBUG - header >> "Content-Type: application/x-www-form-urlencoded; charset=UTF-8[\r][\n]"
[2020-03-02 14:36:52,989] [EI-Core] DEBUG - header >> "Accept: */*[\r][\n]"
[2020-03-02 14:36:52,989] [EI-Core] DEBUG - header >> "Accept-Encoding: gzip, deflate, br[\r][\n]"
[2020-03-02 14:36:52,989] [EI-Core] DEBUG - header >> "Authorization: Basic xxxxx[\r][\n]"
[2020-03-02 14:36:52,989] [EI-Core] DEBUG - header >> "Cache-Control: no-cache[\r][\n]"
[2020-03-02 14:36:52,990] [EI-Core] DEBUG - header >> "X-Forwarded-Host: example.com[\r][\n]"
[2020-03-02 14:36:52,990] [EI-Core] DEBUG - header >> "X-Forwarded-Server: example.com[\r][\n]"
[2020-03-02 14:36:52,990] [EI-Core] DEBUG - header >> "User-Agent: Axis2[\r][\n]"
[2020-03-02 14:36:52,990] [EI-Core] DEBUG - header >> "Host: example.com[\r][\n]"
[2020-03-02 14:36:52,990] [EI-Core] DEBUG - header >> "Transfer-Encoding: chunked[\r][\n]"
[2020-03-02 14:36:52,990] [EI-Core] DEBUG - header >> "[\r][\n]"
[2020-03-02 14:36:52,991] [EI-Core] DEBUG - content >> "53[\r][\n]"
[2020-03-02 14:36:52,992] [EI-Core] DEBUG - content >> "grant_type=client_credentials&scope=vvv%2F.drer"
[2020-03-02 14:36:52,992] [EI-Core] DEBUG - content >> "[\r][\n]"
[2020-03-02 14:36:52,992] [EI-Core] DEBUG - content >> "0"
[2020-03-02 14:36:52,992] [EI-Core] DEBUG - content >> "[\r][\n]"
[2020-03-02 14:36:52,992] [EI-Core] DEBUG - content >> "[\r][\n]"
[2020-03-02 14:36:53,001] [EI-Core] DEBUG - header << "HTTP/1.1 404 Not Found[\r][\n]"
[2020-03-02 14:36:53,001] [EI-Core] DEBUG - header << "HTTP/1.1 404 Not Found[\r][\n]"
[2020-03-02 14:36:53,002] [EI-Core] DEBUG - header << "Cache-Control: private[\r][\n]"
[2020-03-02 14:36:53,002] [EI-Core] DEBUG - header << "Strict-Transport-Security: max-age=31536000; includeSubDomains[\r][\n]"
[2020-03-02 14:36:53,002] [EI-Core] DEBUG - header << "X-Content-Type-Options: nosniff[\r][\n]"
[2020-03-02 14:36:53,003] [EI-Core] DEBUG - header << "Set-Cookie: x-ms-gateway-slice=prod; path=/; SameSite=None; secure; HttpOnly[\r][\n]"
[2020-03-02 14:36:53,003] [EI-Core] DEBUG - header << "Date: Mon, 02 Mar 2020 14:36:52 GMT[\r][\n]"
[2020-03-02 14:36:53,003] [EI-Core] DEBUG - header << "Content-Length: 0[\r][\n]"
[2020-03-02 14:36:53,003] [EI-Core] DEBUG - header << "[\r][\n]"
[2020-03-02 14:36:53,006] [EI-Core] INFO - HTTPSender Unable to sendViaPost to url[https://example.com/login/v1.0/token]
org.apache.axis2.AxisFault: Transport error: 404 Error: Not Found
at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:371)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:200)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:81)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:459)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:286)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:441)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:227)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
at org.apache.synapse.message.senders.blocking.BlockingMsgSender.sendReceive(BlockingMsgSender.java:490)
at org.apache.synapse.message.senders.blocking.BlockingMsgSender.send(BlockingMsgSender.java:382)
at org.apache.synapse.core.axis2.Axis2FlexibleMEPClient.send(Axis2FlexibleMEPClient.java:88)
at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:85)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:547)
at org.apache.synapse.endpoints.AbstractEndpoint.send(AbstractEndpoint.java:384)
at org.apache.synapse.endpoints.HTTPEndpoint.send(HTTPEndpoint.java:85)
at org.apache.synapse.mediators.builtin.CallMediator.handleBlockingCall(CallMediator.java:164)
at org.apache.synapse.mediators.builtin.CallMediator.mediate(CallMediator.java:119)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:108)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:70)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.rest.Resource.process(Resource.java:351)
at org.apache.synapse.rest.API.process(API.java:399)
at org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.java:135)
at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:113)
at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:71)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:303)
at org.apache.synapse.core.axis2.SynapseMessageReceiver.receive(SynapseMessageReceiver.java:92)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:337)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:158)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
I have added the SSL certificate for the token URL as well. Can some one please guide.
I am able to get the token URL working from Postman. I am not getting what could go wrong here, as this is common API and I have used earlier as well for other URls.
Thanks
I´m trying to make a proxy using WSO2 ESB to consume services like "services/UserIdentityManagementAdminService?wsdl" and scim like ""wso2/scim/Users" in wso2 IS, (I want to balance a IS in HA with a https address Endpoint) , I have a proxy and I can consume scim but when I try to get wsdl wso2 esb just sent a log like:
INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: /services/PRX_SC_IS_SERVICES/services/UserInformationRecoveryService?wsdl,
MessageID: urn:uuid:10516b34-8004-4c70-9d4c-61957e4d9147, Direction: request, Envelope: {org.apache.synapse.mediators.builtin.LogMediator}
I think that the problem is that in the URL use services after the proxy name because when I call another URL I haven´t problem.
My Proxy Config:
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="PRX_SC_IS_SERVICES"
transports="http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="Authorization"
expression="fn:concat('Basic ', base64Encode('admin:admin'))"
scope="transport"/>
<send>
<endpoint key="IS_EP_HTTPS"/>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
<description/>
With WSO2 you can´t do a generic proxy and you can´t use the word services after a proxy name.
The easy way to do this is install a Nginx and use it like proxy reverse with a conf like this:
upstream https.is{
server IP_IS01:9446;
server IP_IS02:9446;
}
server {
listen 8443 ssl;
server_name IP_HOST;
ssl_certificate ssl.crt;
ssl_certificate_key ssl.key;
location / {
proxy_pass https://https.is/;
proxy_set_header Host $http_host;
}
}
Another thing that you can do is move in the ESB the context services (axis2.xml and carbon.xml) to another context and deploy two APIs that rewrite the context /services and /wso2/scim, because now the proxy services should be redirect to another context and for example /services/UserAdmin to a IS wsdl.
API example:
<resource methods="POST" uri-template="/PRX*">
<inSequence>
<send>
<endpoint>
<address uri="http://HOST_ESB:PORT_ESB/newservicescontext/"></address>
</endpoint>
</send>
</inSequence>
<outSequence>
<send></send>
</outSequence>
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
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.