I am working on the WSO2 ESB Proxy service, which involves exposing the internal RESTful service via SOAP endpoint on the ESB.
My RESTful service requires Content-type = "application/rdf+xml". I tried setting it using all 3 properties mentioned in the documentation: messageType, ContentType and CONTENT_TYPE. However, the request Content-type still remains "application/xml".
Here is an excerpt from my sequence that calls REST service:
<property xmlns:ns="http://org.apache.synapse/xsd" name="REST_URL_POSTFIX" value="/record/12345" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="PUT" scope="axis2" type="STRING"/>
<property name="messageType" value="application/rdf+xml" scope="axis2" type="STRING"/>
<property name="ContentType" value="application/rdf+xml" scope="axis2" type="STRING"/>
<property name="CONTENT_TYPE" value="application/rdf+xml" scope="axis2" type="STRING"/>
<send>
<endpoint name="CQ">
<address uri="http://my_url" format="pox">
</address>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Authorization" expression="fn:concat('Basic ', base64Encode('username:password'))" scope="transport"/>
<property name="OSLC-Core-Version" value="2.0" scope="transport"/>
<property name="Accept" value="application/rdf+xml" scope="transport"/>
</endpoint>
</send>
I tested it with TCPMon and no matter what Content-type property I use, request still contains "application/xml".
Please advice.
Can you try WSO2 ESB 4.7.0 with following configuration? Note that, I have changed the address format from "pox" to "rest"
<property xmlns:ns="http://org.apache.synapse/xsd" name="REST_URL_POSTFIX" value="/record/12345" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="PUT" scope="axis2" type="STRING"/>
<property name="messageType" value="application/rdf+xml" scope="axis2" type="STRING"/>
<property name="ContentType" value="application/rdf+xml" scope="axis2" type="STRING"/>
<property name="CONTENT_TYPE" value="application/rdf+xml" scope="axis2" type="STRING"/>
<send>
<endpoint name="CQ">
<address uri="http://my_url" format="rest">
</address>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Authorization" expression="fn:concat('Basic ', base64Encode('username:password'))" scope="transport"/>
<property name="OSLC-Core-Version" value="2.0" scope="transport"/>
<property name="Accept" value="application/rdf+xml" scope="transport"/>
</endpoint>
</send>
These are the http headers sent now (captured from tcpmon)
PUT /record/12345 HTTP/1.1
Cookie: region1_configure_menu=none; region3_registry_menu=none; region4_monitor_menu=none; region5_tools_menu=none; JSESSIONID=54D2911FCD5559C6B2F723E7C6FA9B44; requestedURI="../../carbon/service-mgt/index.jsp?region=region1&item=services_list_menu"; current-breadcrumb=manage_menu%2Cservices_menu%2Cservices_list_menu%23
Authorization: null
OSLC-Core-Version: 2.0
Content-Type: application/rdf+xml
Accept: application/rdf+xml
Transfer-Encoding: chunked
Host: www.foo.com:8080
Connection: Keep-Alive
User-Agent: Synapse-PT-HttpComponents-NIO
In the configuration you have attached, you have specified the format of the address uri as "pox" .
<address uri="http://my_url" format="pox">
This will be the reason that you are getting content-type as application/xml always. Please remove this attribute and try. It should be
<address uri="http://my_url">
If you still see the issue, then try to switch to the NHTTP transport as suggested by RaviU. For that, you can first backup the axis2.xml (ESB_HOME/repository/conf/axis2/axis2.xml) as axis2_back.xml and then rename the axis2_nhttp.xml file (same location) as axis2.xml.
Can you set the content type property like this;
<property name="Content-Type” value="application/rdf+xml" scope="transport"/>
Please remove other content-type properties..
If you define like this;
[1]<property name="messageType" value="application/rdf+xml" scope="axis2" type="STRING"/>
[2]<property name="ContentType" value="application/rdf+xml" scope="axis2" type="STRING"/>
[1] for, to select messageformatter
[2]for, to select message builders
Edit;
try like this
<inSequence>
<log level="custom">
<property name="in seq --------------of proxy" expression="$trp:Content-Type"/>
</log>
<property name="messageType"
value="application/json"
scope="axis2"
type="STRING"/>
<property name="Content-Type"
value="application/json"
scope="transport"
type="STRING"/>
<log level="custom">
<property name="in seq --------------of proxy" expression="$trp:Content-Type"/>
</log>
<send>
<endpoint>
<address uri="http://localhost:5555/com"/>
</endpoint>
</send>
Sometimes, you have to enable those message formatters in axis2.xml before using them.
Check this article out. It may help if you haven't done so yet.
http://wso2.com/library/articles/axis2-configuration-part2-learning-axis2-xml#mf
Related
We have a very simple EI API. We receive an XML payload, we then extract a destination code from the XML document and, based on the destination code, we forward the payload to the appropriate endpoint.
One of our clients have made a spelling mistake in their payload and we want to correct it before we send it to the new endpoint. We want to replace the word 'Principle' with 'Principal'.
How can we replace a string in the request body with another string?
Here is our current implementation:
<inSequence>
<property expression="//MyXML/Destination" name="Destination" scope="default" type="STRING"/>
<log level="custom">
<property expression="//MyXML/Transaction/Destination" name="Destination"/>
</log>
<property action="remove" name="REST_URL_POSTFIX" scope="axis2"/>
<property description="vendorId" expression="concat('gov:/integration/endpoints/myendpoints/', get-property('uri.var.vendorId'), '_EP')" name="vendorId" scope="default" type="STRING"/>
<log category="DEBUG" description="request_log" level="full">
<property expression="get-property('vendorId')" name="Vendor ID"/>
</log>
<log description="request_log" level="custom">
<property expression="get-property('vendorId')" name="Vendor ID"/>
</log>
<send>
<endpoint key-expression="get-property('vendorId')"/>
</send>
</inSequence>
I have mediation settings for request and response:
for request(jms_in_flow):
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="jms_in_flow" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property name="transactionId" expression="get-property('MessageID')"/>
<clone continueParent="true">
<target>
<sequence>
<property action="remove" name="OUT_ONLY" value="true"/>
<property expression="$ctx:api.ut.api_version" name="api_version" scope="transport" type="STRING"/>
<property expression="$ctx:api.ut.version" name="api_short_version" scope="transport" type="STRING"/>
<property expression="$ctx:api.ut.requestTime" name="api_request_time" scope="transport" type="STRING"/>
<property expression="$ctx:REST_API_CONTEXT" name="api_context" scope="transport" type="STRING"/>
<property expression="$ctx:API_NAME" name="api_name" scope="transport" type="STRING"/>
<property name="api_message_id" expression="get-property('transactionId')" scope="transport"/>
<property value="REQUEST" name="api_message_type" scope="transport" type="STRING"/>
<property expression="$ctx:REST_FULL_REQUEST_PATH" name="api_request_path" scope="transport" type="STRING"/>
<property expression="$ctx:api.ut.HTTP_METHOD" name="api_method" scope="transport" type="STRING"/>
<property expression="$ctx:api.ut.application.name" name="api_app_name" scope="transport" type="STRING"/>
<property expression="$ctx:api.ut.userName" name="api_username" scope="transport" type="STRING"/>
<call>
<endpoint>
<address uri="jms:"AAA"/>
</endpoint>
</call>
<drop/>
<send/>
</sequence>
</target>
</clone>
for response(jms_out_flow):
<sequence name="jms_out_flow" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<clone continueParent="true">
<target>
<sequence>
<property name="RESPONSE" value="true"/>
<property name = "api_response_time" expression = "get-property('SYSTEM_TIME')" scope="transport"/>
<property name="api_message_id" expression="get-property('transactionId')" scope="transport"/>
<property value="RESPONSE" name="api_message_type" scope="transport" type="STRING"/>
<property expression="$axis2:HTTP_SC" name="http_status" scope="transport" type="STRING"/>
<call>
<endpoint>
<address uri="jms:/AAA"/>
</endpoint>
</call>
<drop/>
</sequence>
</target>
</clone>
When I execute GET request on WSO2 Manager it executes fast and successful, and PUT request is not execute and falls off after the time expires(~2min). When I remove the mediator settings for the request (jms_in_flow), PUT request starts working normally.
I think that the error is in jms_in_flow, but I can't find it.
I found in google: Enter link description here
The processing of get and put methods is different, but I don’t know how to apply it.
UPDATE.
LOGS
[2019-07-01 13:38:06,083] ERROR - Unexpected error during sending message out {org.apache.synapse.core.axis2.Axis2Sender}
org.apache.axis2.AxisFault: Did not receive a JMS response within 30000 ms to destination : temp-queue://ID:c115c33d0c81-45342-543:1:1 with JMS correlation ID : ID:c115c33d0c81-45342-543:1:1:1:1
at org.apache.axis2.transport.base.AbstractTransportSender.handleException(AbstractTransportSender.java:234)
at org.apache.axis2.transport.jms.JMSSender.waitForResponseAndProcess(JMSSender.java:435)
at org.apache.axis2.transport.jms.JMSSender.sendOverJMS(JMSSender.java:369)
at org.apache.axis2.transport.jms.JMSSender.sendMessage(JMSSender.java:192)
at org.apache.axis2.transport.base.AbstractTransportSender.invoke(AbstractTransportSender.java:112)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.synapse.core.axis2.DynamicAxisOperation$DynamicOperationClient.send(DynamicAxisOperation.java:185)
at org.apache.synapse.core.axis2.DynamicAxisOperation$DynamicOperationClient.executeImpl(DynamicAxisOperation.java:167)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
at org.apache.synapse.core.axis2.Axis2FlexibleMEPClient.send(Axis2FlexibleMEPClient.java:603)
at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:85)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:511)
at org.apache.synapse.endpoints.AbstractEndpoint.send(AbstractEndpoint.java:384)
at org.apache.synapse.endpoints.AddressEndpoint.send(AddressEndpoint.java:65)
at org.apache.synapse.mediators.builtin.CallMediator.handleNonBlockingCall(CallMediator.java:276)
at org.apache.synapse.mediators.builtin.CallMediator.mediate(CallMediator.java:121)
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.mediators.MediatorWorker.run(MediatorWorker.java:80)
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'm not sure this is related. But I think you need <property action="remove" name="OUT_ONLY" value="true"/> in the out sequence too.
I have a problem with wso2 EI 6.1.1. I tried using call mediator to post data to an endpoint, where the data is created via class I've created.
The issue is that the body seems to be always empty. The resulted object from the class is not sent as the body.
<resource methods="POST" url-mapping="/itineraries">
<inSequence>
<property description="baseUrl" expression="get-property('boBaseUrl')" name="uri.var.boBaseUrl" scope="default" type="STRING"/>
<property description="InsiteoClientId" expression="get-property('InsiteoClientID')" name="clientID" scope="default" type="STRING"/>
<property description="appVersion" expression="$trp:X-app-version" name="appVersion" scope="default" type="STRING"/>
<property description="buildingId" expression="$trp:X-current-building-id" name="uri.var.buildingId" scope="default" type="STRING"/>
<property description="wayPoints" expression="json-eval($.)" name="wayPoints" scope="default" type="STRING"/>
<call>
<endpoint>
<http method="get" uri-template="{uri.var.boBaseUrl}/api/v1/buildings/{uri.var.buildingId}"/>
</endpoint>
</call>
<property description="floors" expression="json-eval($.floors)" name="floors" scope="default" type="STRING"/>
<property description="InsiteoSiteId" expression="json-eval($.information.insiteoIDSite)" name="uri.var.insiteoSiteId" scope="default" type="STRING"/>
<class description="ItineraryClass" name="com.capgemini.smartWorkPlace.Itinerary"/>
<log level="full"/>
<header expression="get-property('InsiteoApiKey')" name="Authorization" scope="transport"/>
<call>
<endpoint>
<http method="post" uri-template="http://services.test.insiteo.com/APIV3/{uri.var.insiteoSiteId}/iti/process"/>
</endpoint>
</call>
<log level="full"/>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
The request status code returns 500 as if no body was ever sent.
I would really appreciate some help.
In your class mediator check if you're setting the created payload to the context body. If its json,
JsonUtil.getNewJsonPayload(axis2MessageContext, jsonPayload.toString(), true, true);
How can one send an email to a dynamic address?
Address endpoint's URI seem to be static.
Is there a way to inject a property in a address endpoint ?
Here is what I have so far :
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="sendMail" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="//email" name="email" scope="default" type="STRING"/>
<log level="custom">
<property expression="fn:concat('Sending mail to - ',get-property('mail'))" name="mail"/>
</log>
<property name="messageType" value="text/html" scope="axis2"/>
<property name="ContentType" value="text/html" scope="axis2"/>
<property name="Subject" value="File Received" scope="transport"/>
<property name="OUT_ONLY" value="true"/>
<send>
<endpoint name="mail2user">
<address uri="mailto:username#gmail.com"/>
</endpoint>
</send>
</sequence>
Thanks.
Define header "To" and use send without endpoint :
<header name="To"expression="fn:concat('mailto:', get-property('senderAddress'))"/>
<property name="OUT_ONLY" value="true"/>
<send/>
Don't forget to define transportSender "mailto" with class "org.apache.axis2.transport.mail.MailTransportSender" in axis2.xml
Here is the final code after jean-michel suggestion :
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="sendMail" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="//email" name="mailto" scope="default" type="STRING"/>
<log level="custom">
<property expression="fn:concat('Sending mail to - ',get-property('mailto'))" name="mail"/>
</log>
<property name="messageType" scope="axis2" type="STRING" value="text/html"/>
<property name="ContentType" scope="axis2" type="STRING" value="text/html"/>
<property name="Subject" scope="transport" type="STRING" value="File Received"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<header expression="fn:concat('mailto:', get-property('mailto'))" name="To" scope="default"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<send/>
</sequence>
I've tried this on 1.10.0 and 2.0.0
On 1.10.0, you can disable the JMS sender in repository/conf/axis2/axis2_blocking_client.xml and use the call mediator in blocking mode. This is described in this blog post: http://shenavid.blogspot.nl/2016/08/invoking-external-endpoints-using-call.html and works ok. However this method does not work in 2.0.0 even though the related issue is marked as resolved.
Has anyone else tested this on 2.0.0 already? Or found an other workaround?
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="opal_auth_and_send"
onError="gov:apimgt/customsequences/fault/json_fault.xml"
trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<property description="ORG_PAYLOAD" expression="$body/child::node()"
name="ORG_PAYLOAD" scope="default" type="STRING"/>
<property description="URL_POSTFIX"
expression="get-property('axis2', 'REST_URL_POSTFIX')"
name="URL_POSTFIX" scope="default" type="STRING"/>
<property action="remove" description="Remove REST_URL_POSTFIX"
name="REST_URL_POSTFIX" scope="axis2"/>
<property action="remove" description="Remove transport headers"
name="TRANSPORT_HEADERS" scope="axis2"/>
<header name="Authorization" scope="transport" value="Basic xxxxxxxx"/>
<property description="set messageType" name="messageType"
scope="transport" type="STRING" value="application/json"/>
<call blocking="true" description="Get Auth token (blocking)">
<endpoint>
<http method="get" trace="enable" uri-template="https://opal-demo34.ortec-finance.com/auth/api/token"/>
</endpoint>
</call>
<property description="Get Token from Response"
expression="json-eval($.token)" name="TOKEN" scope="default" type="STRING"/>
<property action="remove" description="Remove transport headers"
name="TRANSPORT_HEADERS" scope="axis2"/>
<log description="Log auth result" level="full"/>
<property description="Restore REST_URL_POSTFIX"
expression="get-property('URL_POSTFIX')" name="REST_URL_POSTFIX"
scope="axis2" type="STRING"/>
<payloadFactory description="Restore Payload" media-type="json">
<format>$1</format>
<args>
<arg evaluator="xml" expression="get-property('ORG_PAYLOAD')"/>
</args>
</payloadFactory>
<header expression="get-property('TOKEN')" name="Authorization" scope="transport"/>
</sequence>
Thanks,
Danny