I have a web service like this:
<camelContext id="camel-CallAPI" xmlns="http://camel.apache.org/schema/blueprint" >
<!--Web service starts working -->
<restConfiguration bindingMode="auto" component="restlet" host="localhost" port="8889"/>
<rest path="/check">
<post uri="/version" consumes="application/json" produces="application/json">
<to uri="direct:first"/>
</post>
</rest>
<route>
<from uri="direct:first"/>
<setHeader headerName="Content-Type" id="header_contentType">
<constant>application/json</constant>
</setHeader>
<log message="after set header :: ${body}"/>
<to uri="http4://..."/>
<convertBodyTo type="java.lang.String"/>
<log message="the result of the testCheckLastVersion :: ${body}"/>
I'm sending a json content to this web service with the help of postman, and I need my web service to send that json to another API that has been mentioned in direct:first.
but when I call my web service in postman an error is happening:
org.apache.camel.InvalidPayloadException: No body available of type: java.io.InputStream but has value: {version=apk.1.10.0} of type: java.util.LinkedHashMap on: Message[ID-localhost-localdomain-1549348033140-14-4]. Caused by: No type converter available to convert from type: java.util.LinkedHashMap to the required type: java.io.InputStream with value {version=apk.1.10.0}.
can any one help me with this?
I found the solution, the exception caused because I was set the bindingMode="auto" in camelContext which was not suitable here, by removing that, the problem solved.
<camelContext id="camel-CallAPI" xmlns="http://camel.apache.org/schema/blueprint" >
<!--Web service starts working -->
<restConfiguration component="restlet" host="localhost" port="8889"/>
<rest path="/say">
<post uri="/hi" consumes="application/json" produces="application/json">
<to uri="direct:first"/>
</post>
</rest>
<route>
<from uri="direct:first"/>
<setHeader headerName="Content-Type" id="_setHeader2">
<constant>application/json</constant>
</setHeader>
<to uri="http4://..."/>
<convertBodyTo type="java.lang.String"/>
<log message="the result of the testCheckLastVersion :: ${body}"/>
</route>
</camelContext>
Related
<Body>
<ProductMasterDataStatus>
<Status>INVALID</Status>
<Errors>
<Error source="HUB">
<Description>Data Validation Error (Product code length is invalid.)</Description>
<Code>#A16</Code>
</Error>
</Errors>
</ProductMasterDataStatus>
</Body>
I want to check the ProductMasterDataStatus is in this xml if it is there i want to change the route in camel route.
<camelContext id="cbr-example-context" xmlns="http://camel.apache.org/schema/spring">
<route id="_route1">
<from id="_from1" uri="file:///d:/in"/>
<camel:choice id="_choice1">
<camel:when id="_when1">
<camel:xpath>
</camel:xpath>
<camel:to id="_to1" uri="file:C:/outbox_Denmark"/>
</camel:when>
<process id="_process_transform" ref="myTransform"/>
<to id="_to1" uri="file:///d:/out?fileName=Product.xml"/>
</route>
The xpath expression is //ProductMasterDataStatus, so you should check if this is not null.
<camelContext id="cbr-example-context" xmlns="http://camel.apache.org/schema/spring">
<route id="_route1">
<from id="_from1" uri="file:///d:/in"/>
<camel:choice id="_choice1">
<camel:when id="_when1">
<camel:xpath>//ProductMasterDataStatus != null</camel:xpath>
<camel:to id="_to1" uri="file:C:/outbox_Denmark"/>
</camel:when>
<process id="_process_transform" ref="myTransform"/>
<to id="_to1" uri="file:///d:/out?fileName=Product.xml"/>
</route>
I need to set a JSON content as the message payload of a apache camel rest request. I tried it as follows. But it doesn't work.
<rest path="/service" consumes="application/json" produces="application/json">
<put type="com.xxxx.yyyyy.esb.models.UserServiceMapping"
uri="/create">
<route>
<log message="${body.serviceUrl}" />
<log message="${body.mappedServiceObject}" />
<log message="${body.systemUserDetails.userName}" />
<log message="${body.systemUserDetails.password}" />
<setBody> <simple>{"${body.mappedServiceObject}":{"userName" :
"${body.userName}", "password" : "${body.password}"}} </simple> </setBody>
<setHeader headerName="CamelRestletLogin">
<simple>admin</simple>
</setHeader>
<setHeader headerName="CamelRestletPassword">
<simple>admin</simple>
</setHeader>
<to
uri="restlet:http://xxx.xxx.x.xx:8081/xxxxxx/services/yyyyyyy/V1.0/users/create?restletMethod=POST" />
</route>
</put>
</rest>
I need to exit from a loop when the body contains 'SUCCEDDED' in Jboss/Apache camel. I have tried using Stop() but that doesnt work since it stops every connection(eg:DBConnection).
Here is the sample code:
60
10000
${body}
contains 'SUCCEEDED'
<CXF bean call />
<log loggingLevel="INFO"
message="response
: ${body}">
<description>Logs the 2nd SOAP Response.</description>
</log>
<setBody>
<xpath>{{status.xpath}}</xpath>
</setBody>
<convertBodyTo type="java.lang.String" />
</otherwise>
</choice>
</loop>
<to uri="direct:loopend">
</to>
</route>
i made a camel route in my application with spring dsl.I want to copy the exchange body with using multicast EIP.But when i use this, i can take the exchange bodyfrom one of my endpoint.In the second one (which is endpoint in multicast ) ,the exchange body is null.Why this is happening like this?
EDIT
This is my route:
<route errorHandlerRef="dlc1" id="mobitRoute1">
<from uri="cxf:bean:mobit-okuma?dataFormat=PAYLOAD" />
<wireTap uri="activemq:queue:anaMobitQueue" />
<to uri="velocity:response.vm" />
</route>
<route id="mobitRoute2" errorHandlerRef="dlc2">
<from uri="activemq:queue:anaMobitQueue" />
<unmarshal ref="myJaxb" />
<to uri="bean:timeChanging" />
<multicast>
<to uri="activemq:queue:mobitOkumaq" />
<to uri="activemq:queue:AysMobit" />
</multicast>
</route>
<route errorHandlerRef="dlc3" id="mobitRoute3">
<from uri="activemq:queue:AysMobit" />
<!-- <unmarshal ref="myJaxb" /> -->
<to uri="bean:fromPayload" />
<to uri="cxf:bean:ays-service?dataFormat=POJO" />
</route>
<route errorHandlerRef="dlc4" id="mobitRoute4">
<from uri="activemq:queue:mobitOkumaq" />
<to uri="cxf:bean:mobit-okumaReal?dataFormat=POJO" />
</route>
I found the solution by transforming xml when i put the exchange to the queue.This is why ? I don't know.
<route errorHandlerRef="dlc1" id="mobitRoute1">
<from uri="cxf:bean:mobit-okuma?dataFormat=PAYLOAD" />
<wireTap uri="activemq:queue:anaMobitQueue" />
<to uri="velocity:response.vm" />
</route>
<route errorHandlerRef="dlc1" id="mobitRoute2">
<from uri="activemq:queue:anaMobitQueue" />
<camel:pipeline>
<unmarshal ref="myJaxb" />
<to uri="bean:timeChanging" />
<!-- <to uri="direct:unmarshalled"/> -->
<marshal ref="myJaxb" />
<camel:multicast>
<to uri="activemq:queue:BegisMobit" />
<to uri="activemq:queue:AysMobit" />
</camel:multicast>
</camel:pipeline>
</route>
<route errorHandlerRef="dlc2" id="mobitRoute3">
<from uri="activemq:queue:AysMobit" />
<unmarshal ref="myJaxb" />
<to uri="bean:fromPayload" />
<to uri="cxf:bean:ays-service?dataFormat=POJO" />
</route>
<route errorHandlerRef="dlc3" id="mobitRoute4">
<from uri="activemq:queue:BegisMobit" />
<unmarshal ref="myJaxb" />
<to uri="cxf:bean:mobit-okumaReal?dataFormat=POJO" />
</route>
I tried using both a proxy and an API in WSO2 ESB to test the aggregation of similar SOAP web services into one response but I'm just having time-outs. For testing I'm using a Weather web service (http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl). I'm basically calling the same action GetCityWeatherByZIP twice by using the clone mediator providing a different ZIP code for each, and then aggregating the results. Eventualy the intention is to call web services which are hosted on different servers but for the moment I was trying to use the same service. I would appreciate any help I can get.
Below is the proxy config:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="aggre"
transports="http"
statistics="disable"
trace="enable"
startOnLoad="true">
<target>
<inSequence>
<clone>
<target>
<sequence>
<payloadFactory media-type="xml">
<format>
<m0:GetCityWeatherByZIP xmlns:m0="http://ws.cdyne.com/WeatherWS/">
<m0:ZIP>11001</m0:ZIP>
</m0:GetCityWeatherByZIP>
</format>
<args/>
</payloadFactory>
<header name="Action" scope="default" value="urn:GetCityWeatherByZIP "/>
<call>
<endpoint key="weather"/>
</call>
</sequence>
</target>
<target>
<sequence>
<payloadFactory media-type="xml">
<format>
<m0:GetCityWeatherByZIP xmlns:m0="http://ws.cdyne.com/WeatherWS/">
<m0:ZIP>11010</m0:ZIP>
</m0:GetCityWeatherByZIP>
</format>
<args/>
</payloadFactory>
<header name="Action" scope="default" value="urn:GetCityWeatherByZIP "/>
<call>
<endpoint key="weather"/>
</call>
</sequence>
</target>
</clone>
<aggregate>
<completeCondition>
<messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete xmlns:m0="http://ws.cdyne.com/WeatherWS"
expression="/m0:GetCityWeatherByZIPResponse">
<drop/>
</onComplete>
</aggregate>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
<description/>
</proxy>
Below is the weather endpoint config:
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="weather">
<address uri="http://wsf.cdyne.com/WeatherWS/Weather.asmx" format="soap11">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
Carbon Log:
TID: [0] [ESB] [2014-07-08 11:10:44,377] INFO {org.apache.axis2.transport.http.HTTPSender} - Unable to sendViaPost to url[http://servername:8281/services/aggre.aggreHttpSoap11Endpoint] {org.apache.axis2.transport.http.HTTPSender}
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:150)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:78)
at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:106)
at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1116)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.readLine(MultiThreadedHttpConnectionManager.java:1413)
at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1973)
at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1735)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1098)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:622)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:451)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:278)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:430)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:554)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:530)
at org.apache.jsp.admin.jsp.WSRequestXSSproxy_005fajaxprocessor_jsp._jspService(org.apache.jsp.admin.jsp.WSRequestXSSproxy_005fajaxprocessor_jsp:276)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.wso2.carbon.ui.JspServlet.service(JspServlet.java:155)
at org.wso2.carbon.ui.TilesJspServlet.service(TilesJspServlet.java:80)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.equinox.http.helper.ContextPathServletAdaptor.service(ContextPathServletAdaptor.java:37)
at org.eclipse.equinox.http.servlet.internal.ServletRegistration.service(ServletRegistration.java:61)
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:128)
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:68)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.wso2.carbon.tomcat.ext.servlet.DelegationServlet.service(DelegationServlet.java:68)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.wso2.carbon.tomcat.ext.filter.CharacterSetFilter.doFilter(CharacterSetFilter.java:61)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.wso2.carbon.tomcat.ext.valves.CompositeValve.continueInvocation(CompositeValve.java:178)
at org.wso2.carbon.tomcat.ext.valves.TomcatValveContainer.invokeValves(TomcatValveContainer.java:49)
at org.wso2.carbon.tomcat.ext.valves.CompositeValve.invoke(CompositeValve.java:141)
at org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve.invoke(CarbonStuckThreadDetectionValve.java:156)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.wso2.carbon.tomcat.ext.valves.CarbonContextCreatorValve.invoke(CarbonContextCreatorValve.java:52)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1653)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
TID: [0] [ESB] [2014-07-08 11:10:44,420] WARN {org.apache.synapse.transport.passthru.SourceHandler} - Connection time out after request is read: http-incoming-295 {org.apache.synapse.transport.passthru.SourceHandler}
SOAP Action is incorrect, must be http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP
Namespace for the aggregate's onComplete xpath expression is incorrect, a '/' is missing at the end : http://ws.cdyne.com/WeatherWS/
After aggregation, you don't want to drop the message, you want to send it as a response : replace <drop/> with <send/> in the "onComplete" mediation
The response will be a soap message and SOAP Body must have one root node as first child so you have to apply a transformation, for exemple :
<payloadFactory media-type="xml">
<format>
<response>
$1
</response>
</format>
<args>
<arg evaluator="xml" xmlns:m0="http://ws.cdyne.com/WeatherWS/" expression="//m0:GetCityWeatherByZIPResponse"/>
</args>
</payloadFactory>
By default, clone mediator stop parent mediation, you need to specify continueParent="true" if you want the aggregate to be executed
With call mediator, underline worker thread returns without waiting for the response : the request used to execute your proxy will reach your aggregate : before executing aggregate mediator, test if the message is a GetCityWeatherByZIPResponse
Complete proxy :
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="TestSOF"
transports="http"
statistics="disable"
trace="enable"
startOnLoad="true">
<target>
<inSequence>
<clone continueParent="true">
<target>
<sequence>
<payloadFactory media-type="xml">
<format>
<m0:GetCityWeatherByZIP xmlns:m0="http://ws.cdyne.com/WeatherWS/">
<m0:ZIP>11001</m0:ZIP>
</m0:GetCityWeatherByZIP>
</format>
<args/>
</payloadFactory>
<header name="Action" scope="default" value="http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP"/>
<call>
<endpoint key="weather"/>
</call>
</sequence>
</target>
<target>
<sequence>
<payloadFactory media-type="xml">
<format>
<m0:GetCityWeatherByZIP xmlns:m0="http://ws.cdyne.com/WeatherWS/">
<m0:ZIP>11010</m0:ZIP>
</m0:GetCityWeatherByZIP>
</format>
<args/>
</payloadFactory>
<header name="Action" scope="default" value="http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP"/>
<call>
<endpoint key="weather"/>
</call>
</sequence>
</target>
</clone>
<filter source="local-name($body/*[1])" regex="GetCityWeatherByZIPResponse">
<then>
<aggregate>
<completeCondition>
<messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete xmlns:m0="http://ws.cdyne.com/WeatherWS/"
expression="//m0:GetCityWeatherByZIPResponse">
<payloadFactory media-type="xml">
<format>
<response>
$1
</response>
</format>
<args>
<arg evaluator="xml" xmlns:m0="http://ws.cdyne.com/WeatherWS/" expression="//m0:GetCityWeatherByZIPResponse"/>
</args>
</payloadFactory>
<send/>
</onComplete>
</aggregate>
</then>
</filter>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
<description/>
</proxy>
Endpoint :
<?xml version="1.0" encoding="UTF-8"?>
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="weather">
<wsdl service="Weather"
port="WeatherSoap"
uri="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"/>
</endpoint>
The response I get :
<response xmlns="http://ws.apache.org/ns/synapse">
<GetCityWeatherByZIPResponse xmlns="http://ws.cdyne.com/WeatherWS/">
<GetCityWeatherByZIPResult>
<Success>true</Success>
<ResponseText>City Found</ResponseText>
<State>NY</State>
<City>Franklin Square</City>
<WeatherStationCity>Farmingdale</WeatherStationCity>
<WeatherID>14</WeatherID>
<Description>Cloudy</Description>
<Temperature>73</Temperature>
<RelativeHumidity>78</RelativeHumidity>
<Wind>S6</Wind>
<Pressure>29.75R</Pressure>
<Visibility/>
<WindChill/>
<Remarks/>
</GetCityWeatherByZIPResult>
</GetCityWeatherByZIPResponse>
<GetCityWeatherByZIPResponse xmlns="http://ws.cdyne.com/WeatherWS/">
<GetCityWeatherByZIPResult>
<Success>true</Success>
<ResponseText>City Found</ResponseText>
<State>NY</State>
<City>Floral Park</City>
<WeatherStationCity>Farmingdale</WeatherStationCity>
<WeatherID>14</WeatherID>
<Description>Cloudy</Description>
<Temperature>73</Temperature>
<RelativeHumidity>78</RelativeHumidity>
<Wind>S6</Wind>
<Pressure>29.75R</Pressure>
<Visibility/>
<WindChill/>
<Remarks/>
</GetCityWeatherByZIPResult>
</GetCityWeatherByZIPResponse>
</response>
call mediator rely on non-blocking transport : edit repository/conf/nhttp.properties and add
http.socket.timeout.sender=60000 if you agree to wait for 60 seconds