I am testing fuse63 on spring dsl for rest service, I need to proxy a rest service on camel for back end system, here is excerpt:
<camelContext id="_camelContext1_rest" xmlns="http://camel.apache.org/schema/spring">
<restConfiguration component="spark-rest" port="9091"/>
<rest path="/say">
<post consumes="application/json" produces="text/plain" uri="/hellopost">
<to uri="direct:hellopost"/>
</post>
...
<route id="_route_saypost">
<from id="_from_saypost" uri="direct:hellopost"/>
<log id="_log_saypost" message="this is hellopost"/>
<to id="_file_saypost" uri="file:/tmp2/target/messages/hellopost?fileName=${header.fileName}"/>
<setHeader headerName="camel-test" id="_setHeader1">
<constant>this is camel</constant>
</setHeader>
<setHeader headerName="CamelHttpMethod" id="_setHeader2">
<constant>POST</constant>
</setHeader>
<log id="_log_saypost_before_rest" message="before rest"/>
<to id="_to1" uri="http4://192.168.56.11:8080/test/httpheader.jsp?bridgeEndpoint=true&synchronous=true"/>
<setHeader headerName="Content-Type" id="_setHeader2">
<constant>application/json</constant>
</setHeader>
</route>
This works fine, but if I add the logging action at the end of the route:
<log id="_log_saypost_after_rest3" message="${body}"/>
</route>
the response body from camel(localhost:9091/say/hellopost) will be empty, What's the reason for the response body being cleared after a logging action?
Best regards
Lan
Use Stream caching like
<route streamCache="true">
This http://camel.apache.org/why-is-my-message-body-empty.html answers to your question.
In fact you don't have to use directy
<log />
but you have to use
<to uri="log: "/>
https://camel.apache.org/components/3.15.x/log-component.html
Related
I'm using Ehcache with Apache camel. I'm exposing a rest endpoint which should delete all the keys from Ehcache. For some reason, its not deleting the keys after calling the rest endpoint.
Following code is being used to achieve the same :
<restConfiguration component="servlet"
bindingMode="json" />
<rest path="/clear">
<get uri="/ehcache">
<to uri="direct:clear_ehcache" />
</get>
</rest>
<route id="clear_ehcache_001">
<from uri="direct:clear_ehcache" />
<setHeader headerName="CamelCacheOperation">
<constant>CamelCacheDeleteAll</constant>
</setHeader>
<setHeader headerName="CamelEhcacheAction">
<constant>REMOVE_ALL</constant>
</setHeader>
<to uri="ehcache://mycache" />
</route>
I've been stuck on this for a while now as there are no errors generated.
So it worked with the following piece of code instead :
<!-- Rest endpoint for clearing ehcache : Start -->
<restConfiguration component="servlet"
bindingMode="json" />
<rest path="/clear">
<get uri="/ehcache">
<to uri="direct:clear_ehcache" />
</get>
</rest>
<!-- Rest endpoint for clearing ehcache : End -->
<!-- Route for clearing ehcache : Start -->
<route id="clear_ehcache_001">
<from uri="direct:clear_ehcache" />
<log id="_logging_clear_ehcache"
message="Clearing Ehcache records.." />
<setHeader headerName="CamelEhcacheAction"
id="getCamelEhCacheAction003">
<constant>CLEAR</constant>
</setHeader>
<to id="_to4"
uri="ehcache://mycache?keyType=java.lang.String&valueType=java.lang.String" />
</route>
<!-- Route for clearing ehcache : End -->
I want to make such a solution:
cxf https soap service gets a request and sends it to activemq queue
1
service implementation gets message from queue 1, process it and
puts to queue 2
endpoint gets response from queue 2 and sends
response to a client
Now, I came with a kind of a solution but I'm not sure how to process response from activemq and send back as SOAP response. My camel blueprints below. Endpoint blueprint:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:soap="http://cxf.apache.org/blueprint/bindings/soap"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd
http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://cxf.apache.org/blueprint/bindings/soap http://cxf.apache.org/schemas/configuration/blueprint/soap.xsd">
<bean id="cardServiceEndpoint" class="com.endpoint.card.CardEndpoint">
<argument>
<reference interface="com.card.CardService" />
</argument>
</bean>
<cxf:cxfEndpoint
id="cardEndpoint"
address="https://host:port/soa/card"
serviceClass="com.card.CardService">
<cxf:properties>
<entry key="schema-validation-enabled" value="true" />
</cxf:properties>
</cxf:cxfEndpoint>
<bean id="jaxB" class="org.apache.camel.model.dataformat.JaxbDataFormat">
<property name="prettyPrint" value="true" />
<property name="contextPath" value="com.type.card" />
</bean>
<camelContext id="endpoint-card-cxf" xmlns="http://camel.apache.org/schema/blueprint">
<route id="endpoint-soap-in">
<from uri="cxf:bean:cardEndpoint"/>
<transform>
<simple>${body[0]}</simple>
</transform>
<marshal ref="jaxB"/>
<setHeader headerName="JMSType">
<simple>${headers.operationName}</simple>
</setHeader>
<to uri="amq:q.in"/>
</route>
<route id="endpoint-soap-out">
<from uri="amq:q.out" />
<unmarshal ref="jaxB" />
<!-- STUCK HERE :( -->
</route>
</camelContext>
</blueprint>
Service processor blueprint:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<bean id="cardService" class="com.card.impl.DefaultCardService">
<argument>
<reference interface="com.base.StashService"/>
</argument>
</bean>
<service interface="com.card.CardService" ref="cardService" />
<bean id="amqCardServiceEndpoint" class="com.card.endpoint.AmqCardEndpoint">
<argument ref="cardService" />
</bean>
<bean id="jaxB" class="org.apache.camel.model.dataformat.JaxbDataFormat">
<property name="prettyPrint" value="true" />
<property name="contextPath" value="com.type.base:com.type.card" />
</bean>
<camelContext id="service-card-cx" xmlns="http://camel.apache.org/schema/blueprint">
<route id="card-rq-broker">
<from uri="amq:queue:q.in?asyncConsumer=true" />
<unmarshal ref="jaxB" />
<doTry>
<bean ref="amqCardServiceEndpoint" method="invoke" />
<doCatch>
<exception>com.type.base.BaseException</exception>
<setBody>
<simple>${exception.getFaultInfo()}</simple>
</setBody>
</doCatch>
</doTry>
<marshal ref="jaxB" />
<to uri="amq:q.out" />
</route>
</camelContext>
</blueprint>
Any help or advice?
Use jmsReplyTo to specify the name of the reply queue (if you want a fixed queue name) that Camel should use for listening for the response. See more about request/reply on the Camel JMS documentation.
<to uri="amq:q.in?jmsReplyTo=q.out"/>
// continue here when reply is back
http://camel.apache.org/jms
Using WSO2 ESB 4.8.1, I have configured a WSDL proxy that I want to access over REST. the proxy points to the SOAP WSDL URI and has publish WSDL turned on. This seem to work fine and I can see the service and its various operations in the WSO2 admin UI. Likewise if I go to localhost:8280/services/
The questions is how do I pass operation specific parameters when accessing over HTTP REST?
Let's say my FooService OperationX expects a "p1" parameter, can I pass this directly when accessing localhost:8280/services/FooService/OperationX in a browser?
I tried for example localhost:8280/services/FooService/SomeOperation?p1=somevalue, but always get a validation error that the required parameter is missing:
cvc-complex-type.2.4.b: The content of element 'axis2ns15:OperationXRequest' is not complete. One of '{"somenamespace":p1}' is expected.
Can this be supported by a basic WSDL proxy? Or do I need to use the API?
I think the better option for your scenario is to use api to access over REST. Here I have created an api (I used http://jsonplaceholder.typicode.com/comments as my REST back end) which gets the query parameter(postId) which was sent in REST request (http://172.22.99.96:8290/test/comments?postId=1) and assign that value to a property called mypostId inside the api.
Then I am modifying the payload by adding the mypostId property using payload factory mediator which will match to the echo service request(I have used echo service as the SOAP backend).
Then I use enrich mediator to change my soap envelope to match the echo service request soap envelope by adding "xmlns:echo="http://echo.services.core.carbon.wso2.org"" name space. Finally I am sending my created request to echo service proxy.
<api xmlns="http://ws.apache.org/ns/synapse" name="test" context="/test">
<resource methods="GET" uri-template="/comments?postId={postId}">
<inSequence>
<log level="custom">
<property name="Message Flow" value="--- Order GET ---"></property>
</log>
<log level="custom">
<property name="postId" expression="$url:postId"></property>
</log>
<property name="mypostId" expression="$url:postId"></property>
<call>
<endpoint>
<http method="GET" uri-template="http://jsonplaceholder.typicode.com/comments?postId={uri.var.postId}"></http>
</endpoint>
</call>
<payloadFactory media-type="xml">
<format>
<echo:echoInt xmlns:echo="http://echo.services.core.carbon.wso2.org">
<in>$1</in>
</echo:echoInt>
</format>
<args>
<arg evaluator="xml" expression="get-property('mypostId')"></arg>
</args>
</payloadFactory>
<log level="full"></log>
<log level="custom">
<property name="Message Flow" value="--- After Palyload factory---"></property>
</log>
<property name="extarctedBody" expression="$body"></property>
<log level="custom">
<property name="MyextarctedBody" expression="get-property('extarctedBody')"></property>
</log>
<log level="full"></log>
<enrich>
<source type="inline" clone="true">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:echo="http://echo.services.core.carbon.wso2.org"></soapenv:Envelope>
</source>
<target type="envelope"></target>
</enrich>
<log level="custom">
<property name="Message Flow" value="--- Order GET2 ---"></property>
</log>
<log level="full"></log>
<enrich>
<source type="property" clone="true" property="extarctedBody"></source>
<target xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:echo="http://echo.services.core.carbon.wso2.org" action="child" xpath="//soapenv:Envelope"></target>
</enrich>
<log level="full"></log>
<send>
<endpoint>
<address uri="http://localhost:8290/services/echo"></address>
</endpoint>
</send>
</inSequence>
<outSequence>
<send></send>
</outSequence>
</resource>
</api>
Hope this may help you .
How can i determine that a message contains a specific element? i want to enrich the message if it does not contain specific element, but i do not know how to determine it?
thank you.
You can use the filter mediator to perform content based mediation. Following sample shows your usecase. (1) The filtering was done using the xpath matching. It searches for NOT occurrence of XPath //p:echoString/test, and performs enrich mediation based on that. Following soap body will match the filter. (2)
(1)
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="messageFilter" transports="http https" startOnLoad="true" trace="disable">
<target>
<inSequence>
<log level="full" separator=","/>
<filter xpath="not(//p:echoString/test)" xmlns:p="http://echo.services.core.carbon.wso2.org" >
<then>
<log separator=",">
<property name="XPath Matched" value="true"/>
</log>
<enrich>
<source clone="true" xpath="//p:echoString/in"/>
<target type="property" property="ORIGINAL_REQ"/>
</enrich>
<log separator=",">
<property name="ORIGINAL_REQ" expression="get-property('ORIGINAL_REQ')"/>
</log>
</then>
<else>
<log separator=",">
<property name="XPath Matched" value="false"/>
</log>
</else>
</filter>
<send>
<endpoint>
<address uri="http://localhost:9763/services/echo"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full" separator=",">
<property name="OUT-SEQUENCE" value="property_value"/>
</log>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
(2)
<body>
<p:echoString xmlns:p="http://echo.services.core.carbon.wso2.org">
<in>123</in>
<test>testing-node</test>
</p:echoString>
</body>
I am struggling to make work my message flow in the wso2 esb so I would need some help to implement a basic communication:
Service1 wants to receive an integer number
Service2 Generates random numbers
Service1 has InSequence: log, send (to addresspoint specified). OutSequence: log, send
this looks like:
<proxy name="ClientAskNumber" transports="https http" startOnLoad="true"
trace="disable">
<target faultSequence="fault">
<inSequence>
<log level="full">
<property name="Insequence" value="***" />
</log>
<send>
<endpoint>
<address uri="http://localhost:8280/services/RandomNumbers" />
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full">
<property name="Outsequence" value="***" />
</log>
<send />
</outSequence>
</target>
</proxy>
I have this response: <faultstring>System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: urn:mediate. at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()....etc
What it means? Am I missing something else? Please help. Thank you
EDIT:
I am studying the Wso2 ESB and I just need to understand how to make work a message communication, after it I will try to add different kind of mediation. I am just breaking down the problem, because I am new to this technology and as you can see I am really struggling to make it work...
EDIT2:*
<proxy xmlns="http://ws.apache.org/ns/synapse" name="ClientAskNumber" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target endpoint="RandomNumbers">
<inSequence>
<log>
<property name="CLIENTASKS" value="******C_ASKS" />
</log>
<send>
<endpoint key="RandomNumbers" />
</send>
</inSequence>
<outSequence>
<log>
<property name="CLIENTRECEIVES" value="*******C_RECEIVES" />
</log>
</outSequence>
</target>
</proxy>
In the case this helps someone else: the problem with "Server did not recognize the value of HTTP Header SOAPAction: urn:mediate..." is that I needed to add an Header mediator in order to call my webservice method "getNumbers", into my InSequence as follows:
<inSequence>
<log>
<property name="CLIENTASKS" value="******C_ASKS" />
</log>
<header name="Action" value="http://tempuri.org/getNumbers" />
<send>
<endpoint key="RandomNumbers" />
</send>
</inSequence>
and send this request via soapUI:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Numbers xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
I hope this can be useful to other persons who are using .Net Solutions with WSO2ESB (unfortunately there are not many examples out there...)
P.S. thanks to Ratha for his help
This is the flow i can tell you..
You have to point your 2nd service as the endpoint of your fist service..In the above configuration
http://localhost:8280/services/RandomNumbers --->2nd service url
ClientAskNumber -->1st service..
Now you can send the request which is needed to execute the 2nd service(ie:to retrive the random number)
So the proxy will forwrad to that endpoint and return the response to the outsequence..You should see that in the console/log since you used a log mediator.
In the error response you are getting i hope you are getting that from your second service. Check whether you are sending correct request to your endpoint