I am trying to send message to ActiveMQ Queue from WSO2 with help of below API:
<resource methods="GET">
<inSequence>
<log level="custom">
<property name="Bashir bhhhh" value="Service"/>
</log>
<call>
<endpoint key="check_ep"/>
</call>
<log level="custom">
<property name="Bashir bhhhh" value="Service Ends"/>
</log>
</inSequence>
</resource>
The message is delivering to the queue but when I terminate the request from postman I get this error. Unable to figure out what is this error and how can it be resolved. Clarifying that message is delivering to the ActiveMQ queue but the request is not ending, and on terminating manually from postman getting this error.
ERROR {JMSSender} - Did not receive a JMS response within 30000 ms to destination : temp-queue://ID:IBM-PF3K6KLP-59783-1674314596400-1:2:1 with JMS correlation ID : ID:IBM-PF3K6KLP-59783-1674314596400-1:2:1:1:1
ERROR {Axis2Sender} - {api:finch} Unexpected error during sending message out java.lang.NullPointerException
Any help would mean a lot.
For JMS Producing scenarios, you need to set the following property.
<property action="set" name="OUT_ONLY" value="true"/>
<resource methods="GET">
<inSequence>
<log level="custom">
<property name="Bashir bhhhh" value="Service"/>
</log>
<property action="set" name="OUT_ONLY" value="true"/>
<call>
<endpoint key="check_ep"/>
</call>
<log level="custom">
<property name="Bashir bhhhh" value="Service Ends"/>
</log>
</inSequence>
</resource>
If you want to do a guaranteed delivery scenario you can check JMS Dual channel example here.
Related
I'm trying to develop a sequence in Wso2 esb. I need to log the URL of the endpoint
this a snippet of my sequence
<script language="js"><![CDATA[
var log = mc.getServiceLog();
var requestBody = mc.getProperty("requestBody");
log.info("Avant de checker l'adresse "+requestBody.city);
mc.setProperty("addressNonNull",1);
if (requestBody.street || requestBody.zip || requestBody.city || requestBody.country) {
if(requestBody.street) {
mc.setProperty("query.param.street",requestBody.street);
}
if(requestBody.city) {
mc.setProperty("query.param.city",requestBody.city);
}
mc.setProperty("addressNonNull",1);
}
log.info("crm_create_subtasks_v2 address_value ==>"+requestBody.street+"|" +requestBody.zip+"|"+requestBody.city);
]]>
</script>
<switch source="get-property('addressNonNull')" xmlns:ns="http://org.apache.synapse/xsd">
<case regex="1.0">
<header name="Content-Type" scope="transport" value="application/json"/>
<property name="Content-Encoding" action="remove" scope="transport"/>
<property name="Authorization" expression="fn:concat('Basic ', base64Encode('user:password'))" scope="transport" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<call>
<endpoint key="jira_address_exist_v2"/>
</call>
<property expression="json-eval($.)" name="check address exist"
scope="default" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<log>
<property name="create_subtasks_v2 response jira_address_exist_v2" expression="json-eval($.)"/>
</log>
I need to display URL generated befor making request to the endpoint "jira_address_exist_v2" in the logs.
Best regards
Add this just before the call mediator,
<log level="simple"/>
<call>
<endpoint key="jira_address_exist_v2"/>
</call>
Not sure if this works, but at least you can give it a try. Add the following just before .
<log level="full">
<property name="To" expression="$trp:To" />
<property name="TO" expression="$trp:TO" />
</log>
If this doesn't work you can also enable wire log. Go to the esb console -> confiugre -> logging and search for a class xxx.http.wire and enable debug. Then you'll see what the esb receives and sends out.
I have a proxy service to search a user in multiple systems and should return the combined responses in JSON format.I get the responses combined but instead of getting it in JSON format I get the responses in XML format.
I can see JSON responses in WSO2 server logs as below:
[2016-07-19 07:26:58,249] INFO - LogMediator To: http://www.w3.org/2005/08/addr
essing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:895c4303-6de5-49
88-a4d1-c06275582841, Direction: response, Component = Application2, Payload: {
"findUsers":[
{"id":"20","add_state":"0","remove_state":"0","supervisor_id_name":"","idc_id":"
3","backup_supervisor_name":"","backup_supervisor":"","business_unit_id":"","com
pany":"companyb","creation_date":"2016-05-11 18:02:42.0","deletion_date":"","dep
artment":"922","display_name":"Kevin Mollo (companyb)","email_address":"Kevin.Mo
llo#companyb.com","exception_count":"","first_name":"Kevin","is_terminated":"Fal
se","job_status":"Active","last_name":"Mollo","legacy_employee_id":"171352","sup
ervisor_id":"","termination_date":"","title":"Broadband Technician","unique_id":
"9000070","user_id":"user71","violation_count":""}
]
}
[2016-07-19 07:26:58,888] INFO - LogMediator To: http://www.w3.org/2005/08/addr
essing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:0cee9dc3-b6e6-48
81-9bdd-a89ec22999a7, Direction: response, Component = Application1, Payload: {"vi
ewableIdentityAttributes":{"Email":"Kevin.Mollo#companyb.com","cn":"Kevin Mollo"
,"Last Name":"Mollo","First Name":"Kevin"},"assignedRoles":[],"listAttributes":[
"First Name","Last Name","Email","cn"]}
However, I don't get response in JSON format after calling the proxy url.
Below is my ESB configuration:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="SPRSAPproxy"
transports="http,https"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log/>
<clone>
<target>
<sequence>
<property name="Application" value="Application1"/>
<property name="messageType"
value="application/xacml+json"
scope="axis2"
type="STRING"/>
<property name="Authorization"
expression="fn:concat('Basic ', base64Encode('username:password'))"
scope="transport"/>
<send>
<endpoint>
<address uri="http://hostname1:8080/identityiq/rest/identities/9000070"/>
</endpoint>
</send>
</sequence>
</target>
<target>
<sequence>
<property name="Application" value="Application2"/>
<property name="messageType"
value="application/json"
scope="axis2"
type="STRING"/>
<send>
<endpoint>
<address uri="http://hostname2:8080/aveksa/command.submit?cmd=findUsers&format=json&unique_id=9000070"/>
</endpoint>
</send>
</sequence>
</target>
</clone>
</inSequence>
<outSequence>
<log level="full" description="">
<property name="Component" expression="get-property('Application')"/>
</log>
<aggregate>
<completeCondition>
<messageCount min="2"/>
</completeCondition>
<onComplete expression="/">
<property name="messageType"
value="application/xacml+json"
scope="axis2"
type="STRING"
description="messageType"/>
<enrich>
<source clone="true" xpath="/"/>
<target type="body"/>
</enrich>
<send/>
</onComplete>
</aggregate>
</outSequence>
<faultSequence>
<log level="full" category="WARN"/>
</faultSequence>
</target>
<description/>
</proxy>
I get the response as below:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header/><soapenv:Body><jsonObject><findUsers><id>20</id><add_state>0</add_state><remove_state>0</remove_state><supervisor_id_name></supervisor_id_name><idc_id>3</idc_id><backup_supervisor_name></backup_supervisor_name><backup_supervisor></backup_supervisor><business_unit_id></business_unit_id><company>companyb</company><creation_date>2016-05-11 18:02:42.0</creation_date><deletion_date></deletion_date><department>922</department><display_name>Kevin Mollo (companyb)</display_name><email_address>Kevin.Mollo#companyb.com</email_address><exception_count></exception_count><first_name>Kevin</first_name><is_terminated>False</is_terminated><job_status>Active</job_status><last_name>Mollo</last_name><legacy_employee_id>171352</legacy_employee_id><supervisor_id></supervisor_id><termination_date></termination_date><title>Broadband Technician</title><unique_id>9000070</unique_id><user_id>user71</user_id><violation_count></violation_count></findUsers></jsonObject><soapenv:Envelope><soapenv:Header/><soapenv:Body><jsonObject><viewableIdentityAttributes><Email>Kevin.Mollo#companyb.com</Email><cn>Kevin Mollo</cn><Last Name>Mollo</Last Name><First Name>Kevin</First Name></viewableIdentityAttributes><listAttributes>First Name</listAttributes><listAttributes>Last Name</listAttributes><listAttributes>Email</listAttributes><listAttributes>cn</listAttributes></jsonObject></soapenv:Body></soapenv:Envelope></soapenv:Body></soapenv:Envelope>
Please let me know how I can get the JSON response.
Any help would be greatly appreciated.
You can set the messageType to application/json instead of application/xacml+json in outSequence and try.
<property name="messageType" value="application/json" scope="axis2" type="STRING" description="messageType"/>
Also there is no application/xacml+json message formatters and message builders shipped with WSO2 ESB by default. If you need to use these formats you have to write your own formatters and builders and configure them in axis2.xml file.
Below is the proxy implemented in WSO2 ESB 4.8.1, this return response in binary format as shown next to the proxy code. Response is expected in the xml response.
Note: This proxy returns xml response in WSO2 ESB 4.9.0 as expected.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="postIDMPCall-withheader"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<in>
<property name="ContentType" value="text/xml" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<payloadFactory media-type="xml">
<format>
<organizationList xmlns="">
<Organization>
<sourceRecordId>132</sourceRecordId>
<idmpRecordId>0</idmpRecordId>
<orgName>depcomp</orgName>
<smeNumber/>
<psmflCode/>
<countryCode>AF</countryCode>
<shortName/>
<remarks/>
<address>addressgger</address>
<city>mys</city>
<state>kar</state>
<postalCode>234</postalCode>
<contactPhone/>
<phoneExtension/>
<faxNumber/>
<faxExtension/>
<webSite/>
<active>YES</active>
<organizationId/>
</Organization>
</organizationList>
</format>
<args/>
</payloadFactory>
<log>
<property name="before call" expression="$body"/>
</log>
<property name="user" value="system" scope="default" type="STRING"/>
<property name="password"
value="Password2#"
scope="default"
type="STRING"/>
<header name="_user" scope="transport" expression="get-property('user')"/>
<header name="_password"
scope="transport"
expression="get-property('password')"/>
<log>
<property name="header" expression="get-property('user')"/>
</log>
<call blocking="true">
<endpoint>
<address uri="http://<ipaddress>:<port>/<rest-Services-path>/UpdateOrganization"
format="rest"/>
</endpoint>
</call>
<log>
<property name="after call" expression="$body"/>
</log>
<property name="messageType" value="text/xml" scope="axis2" type="STRING"/> <header name="To" scope="default" action="remove"/>
<property name="RESPONSE" value="true"/>
<send/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<drop/>
</in>
</inSequence>
</target>
</proxy>
1.Logs:
[ESB] [2016-05-04 15:10:27,222] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: /services/postIDMPCall-withheader.postIDMPCall-withheaderHttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:b5814442-977e-43ed-9cc9-f60faa46c5c2, Direction: request, before call = <soapenv:Body xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><organizationList><Organization><sourceRecordId>132</sourceRecordId><idmpRecordId>0</idmpRecordId><orgName>depcomp</orgName><smeNumber></smeNumber><psmflCode></psmflCode><countryCode>AF</countryCode><shortName></shortName><remarks></remarks><address>addressgger</address><city>mys</city><state>kar</state><postalCode>234</postalCode><contactPhone></contactPhone><phoneExtension></phoneExtension><faxNumber></faxNumber><faxExtension></faxExtension><webSite></webSite><active>YES</active><organizationId></organizationId></Organization></organizationList></soapenv:Body> {org.apache.synapse.mediators.builtin.LogMediator}
TID: [0] [ESB] [2016-05-04 15:10:27,230] INFO {org.apache.synapse.core.axis2.TimeoutHandler} - This engine will expire all callbacks after : 120 seconds, irrespective of the timeout action, after the specified or optional timeout {org.apache.synapse.core.axis2.TimeoutHandler}
TID: [0] [ESB] [2016-05-04 15:10:31,066] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:cee9a5c2-1f64-4ff3-a6bd-712785567f8d, Direction: request, after call = <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><axis2ns1:binary xmlns:axis2ns1="http://ws.apache.org/commons/ns/payload">PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pgo8b3JnYW5pemF0aW9uUmVzcG9uc2VMaXN0PgogICAgPE9yZ2FuaXphdGlvbj4KICAgICAgICA8c291cmNlUmVjb3JkSWQ+MTMyPC9zb3VyY2VSZWNvcmRJZD4KICAgICAgICA8aWRtcFJlY29yZElkPjE3MTY5PC9pZG1wUmVjb3JkSWQ+CiAgICAgICAgPHN1Y2Nlc3M+U1VDQ0VTUzwvc3VjY2Vzcz4KICAgICAgICA8ZXJyb3I+Tm8gRXJyb3JzPC9lcnJvcj4KICAgIDwvT3JnYW5pemF0aW9uPgo8L29yZ2FuaXphdGlvblJlc3BvbnNlTGlzdD4K</axis2ns1:binary></soapenv:Body> {org.apache.synapse.mediators.builtin.LogMediator}
2.Response received in binary format:
<axis2ns6:binary xmlns:axis2ns6="http://ws.apache.org/commons/ns/payload">PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pgo8b3JnYW5pemF0aW9uUmVzcG9uc2VMaXN0PgogICAgPE9yZ2FuaXphdGlvbj4KICAgICAgICA8c3VjY2Vzcz5GQUlMVVJFPC9zdWNjZXNzPgogICAgICAgIDxlcnJvcj5SZWNvcmQgaXMgbm90IHByb2Nlc3NlZCBzdWNjZXNzZnVsbHkuIFBsZWFzZSBQcm92aWRlIHZhbGlkIFJlcXVlc3QgWE1MPC9lcnJvcj4KICAgIDwvT3JnYW5pemF0aW9uPgo8L29yZ2FuaXphdGlvblJlc3BvbnNlTGlzdD4K</axis2ns6:binary>
To convert an XML payload to JSON, set the messageType property to application/json in the axis2 scope before sending message to an endpoint.
<property name="messageType" value="application/json" scope="axis2"/>
I am not sure why you only have inSequence .
And you are logging both before and after call content inside inSequence.
Can you use outSequence and check ? i.e
<outSequence>
<property name="messageType" value="application/json" scope="axis2"/>
<send/>
</outSequence>
Please check that you have enabled the binary message builder/formatter in /repository/conf/axis2/axis2.xml. If so, disable binary message builder and use default message builders/formatters and try this again.
PayloadFactory mediator I’m using JSON format string. The Problem is, when I enable the following lines in /repository/conf/axis2/axis2.xml, POST request works fine, but GET request produce error message.
<!--messageFormatter contentType="application/json"
class="org.apache.axis2.json.JSONStreamFormatter"/-->
<!--messageBuilder contentType="application/json"
class="org.apache.axis2.json.JSONStreamBuilder"/-->
Here is the ESB template for paypal List all Payment Resources:
<template name="listPaymentResources" xmlns="http://ws.apache.org/ns/synapse">
<sequence class="sequence">
<payloadFactory media-type="json">
<format>
{}
</format>
</payloadFactory>
<property name="messageType" scope="axis2" value="application/json" />
<call>
<endpoint>
<http method="get" uri-template="{uri.var.paypalUrl}/v1/payments/payment"/>
</endpoint>
</call>
</sequence>
</template>
Proxy service:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="listPaymentResources"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property xmlns:ns="uri.var.payment"
name="ppurl"
expression="//ns:paypalurl/text()"/>
<PayPal.config>
<appUri>{$ctx:ppurl}</appUri>
</PayPal.config>
<PayPal.listPaymentResources/>
<respond/>
</inSequence>
<outSequence>
<log/>
<send/>
</outSequence>
</target>
<description/>
</proxy>
The Error log:
[2013-12-11 17:25:10,971] ERROR - TargetHandler Unexpected error: Cannot get a J
SON writer
java.lang.UnsupportedOperationException: Cannot get a JSON writer
at org.apache.axis2.json.JSONStreamFormatter.getJSONWriter(JSONStreamFor
matter.java:63)
at org.apache.axis2.json.AbstractJSONMessageFormatter.getTargetAddress(A
bstractJSONMessageFormatter.java:228)
at org.apache.synapse.transport.passthru.TargetRequest.start(TargetReque
st.java:152)
at org.apache.synapse.transport.passthru.TargetHandler.requestReady(Targ
etHandler.java:136)
at org.apache.http.impl.nio.DefaultNHttpClientConnection.produceOutput(D
efaultNHttpClientConnection.java:244)
at org.apache.synapse.transport.http.conn.LoggingNHttpClientConnection.p
roduceOutput(LoggingNHttpClientConnection.java:112)
at org.apache.synapse.transport.passthru.ClientIODispatch.onOutputReady(
ClientIODispatch.java:88)
at org.apache.synapse.transport.passthru.ClientIODispatch.onOutputReady(
ClientIODispatch.java:41)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.outputReady(Abstr
actIODispatch.java:148)
I have done some testing on the subject on latest release of the WSO2 ESB and i could not able to reproduce this given issue.
I have this WSO2 ESB proxy:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="sid008" transports="http" startOnLoad="true" trace="disable">
<target>
<inSequence>
<switch source="get-property('inquiryId')">
<log level="full"/>
<case regex="">
<send/>
</case>
<default>
</default>
</switch>
</inSequence>
<outSequence>
<....some processing..>
<send/>
</outSequence>
</target>
<publishWSDL key="CommonService.wsdl">
<resource location="request.xsd" key="request.xsd"/>
<resource location="response.xsd" key="response.xsd"/>
<resource location="SMEV.xsd" key="SMEV.xsd"/>
<resource location="statusAndError.xsd" key="statusAndError.xsd"/>
</publishWSDL>
</proxy>
In this proxy in default case doesn't run outSequence without send mediator. How can I do it without send mediator
Try this config for :
<default>
<... some processing ...>
<header action="remove" name="To"/>
<property action="set" name="RESPONSE" scope="default" type="STRING" value="true"/>
<send/>
</default>
With this config, you'll send response to client directly from inSequence part (you won't get into outSequence).
The rational behind In and Out sequence is:
In seq : When a message comes to a proxy service from a client, it always goes to the In sequence.
Out Seq: When a proxy service sends a message out from ESB to a backend service, the response will always come to Out seq (Unless specify the sequence using receiving seq.)
Hope this helps.