I want to test camel spring integration example from the apache camel site
http://camel.apache.org/springintegration.html but I am getting the exception
org.apache.camel.RuntimeCamelException: org.springframework.integration.MessageDeliveryException: Dispatcher has no subscribers for channel outputchannel.
my short code is given below:
<channel id="inChannel"/>
<channel id="outputChannel"/>
<beans:bean id="greeting" class="com.javarticles.spring.integration.Greeting"/>
<service-activator input-channel="inChannel" ref="greeting" method="sayHello" output-channel="outputChannel"/>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq:activemqsource"/>
<to uri="log:input"/>
<to uri="spring-integration:inChannel? inputChannel=outputChannel"/>
<to uri="log:output"/>
</route>
I tried to search related problems but I did not get with camel could any one tell me how to subscribe the outputchannel
According to the Camel documentation mentioned by you, the config should be like this:
<to uri="spring-integration:inputChannel?inOut=true&inputChannel=outputChannel"/>
Your issue is inOut=true:
The exchange pattern that the Spring integration endpoint should use. If inOut=true then a reply channel is expected, either from the Spring Integration Message header or configured on the endpoint.
Related
I use servicemix. I'm trying to send messages from jetty to the queue, but I get the following error:
enter image description here
my blueprint:
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="jetty:http://localhost:8180/test"/>
<to uri="activemq://events_test" />
</route>
</camelContext>
if i use route from jetty to file - everything works as it should
Exchange pattern of your route is InOut, so your jetty consumer waiting response from activemq producer. Response will appear if you have activemq consumer that will process your jetty request. If activemq producer shouldn't make response and you need just save request in queue use "inOnly" instead if "to", like this:
<inOnly uri="activemq://events_test" />
I have a mock endpoint at 8001 that will echo anything provided to it.
I have an http endpoint that will submit the end of the URL to the mock endpoint, and provide a response from the endpoint's response.
That works fine.
The challenge is, I want the http route to use only 1 tcp connection to the 8001 endpoint.
I created a worker group as explained elsewhere, and set the worker count to 1. Looking through the source code, I'm thinking this approach should work.
However, when I do this bash command:
for a in {1..5}; do curl "http://localhost:8080/upstream/REQUESTNUM$a" > $a.txt & done;
I see multiple connections to 8001. I would have expected the http endpoint requests would have to share a single pool worker, but that doesn't seem to be the case.
Perhaps I am missing something, or perhaps there is another way to accomplish my goal of using only 1 back-end tcp connection for all the http requests.
How do I accomplish it?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext
xmlns="http://camel.apache.org/schema/spring">
<route id="mockUpstream">
<from
uri="netty4:tcp://localhost:8001?sync=true&textline=true&keepAlive=true&disconnect=false&reuseChannel=true" />
<log message="Incoming to upstream: ${body}" />
<transform>
<simple>${body}</simple>
</transform>
</route>
<route id="httpServer">
<from
uri="netty4-http:http://0.0.0.0:8080/upstream?matchOnUriPrefix=true" />
<!-- optional just use CamelHttpQuery from header, for full query -->
<log
message="Incoming http command: ${in.headers[CamelHttpPath]}" />
<transform>
<simple>${in.headers[CamelHttpPath]}</simple>
</transform>
<to
uri="netty4:tcp://localhost:8001?workerGroup=#sharedPool&sync=true&textline=true&keepAlive=true&disconnect=false&reuseChannel=true" />
<transform>
<simple>${body}</simple>
</transform>
</route>
</camelContext>
<bean id="poolBuilder"
class="org.apache.camel.component.netty4.NettyWorkerPoolBuilder">
<property name="workerCount" value="1" />
</bean>
<bean id="sharedPool" class="io.netty.channel.EventLoopGroup"
factory-bean="poolBuilder" factory-method="build"
destroy-method="shutdown">
</bean>
</beans>
Looking at the logs, with TRACE level logging, I saw the NettyProducer's pool was indeed set to use 1 max active connection, but the NettyProducer was allowed 100 idle connections. I changed the following line and it is now behaving as expected:
<to
uri="netty4:tcp://localhost:8001?workerGroup=#sharedPool&sync=true&textline=true&keepAlive=true&disconnect=false&reuseChannel=true&producerPoolMaxActive=1&producerPoolMaxIdle=1" />
I assumed the "producer" settings were only good for the producer side (netty in mock host route) of the connection, but it looks like they can be used by the consumer end (netty in http route), too.
edit: I confused the terms producer and consumer and got that backwards above. Seeing that the "to" element is producing a request for something to consume, the producer* parameters make sense for (netty in http route). The (netty in mock host route) is the consumer of requests.
I am developing a code-first SOAP service inside JBoss Fuse. I defined an interface my.endpoint.Interface with input and output classes. The wsdl is generated fine and the service is working. The endpoint is handled by CXF which invokes my Camel routes.
Versions:
JBoss Fuse 6.2.1
Apache Camel 2.15.1
Apache CXF 3.0.4
This is the configuration of my bundle:
<blueprint>
<cxf:cxfEndpoint id="myEndpoint"
address="/my/"
serviceClass="my.endpoint.Interface">
</cxf:cxfEndpoint>
<camelContext>
<route>
<from uri="cxf:bean:myEndpoint" />
<to uri="bean:doProcess" />
</route>
</camelContext>
</blueprint>
I would like to apply XML validation using an XSD to the incoming payloads.
How do I configure CXF in this particular environment?
I didn't find out where to specify the XSD CxfEndpointConfigurer interface:
<!-- blueprint file -->
<from uri="cxf:bean:myEndpoint?cxfEndpointConfigurer=configurer" />
// java file
#Override
public void configureServer(Server server) {
// where do I set XSD in here?
}
Configuring the cxfEndpoint in blueprint file raises an Exception at runtime
<cxf:cxfEndpoint id="readingsEndpoint"
address="/readings/"
serviceClass="my.endpoint.Interface">
<cxf:schemaLocations>
<schemaLocation>classpath:my/endpoint/schema1.xsd</schemaLocation>
</cxf:schemaLocations>
</cxf:cxfEndpoint>
Does not work, raising the following exception:
Unable to start blueprint container for bundle my.bundle/0.0.0.SNAPSHOT
java.lang.NullPointerException
at org.apache.aries.blueprint.container.RecipeBuilder.getValue(RecipeBuilder.java:355)[23:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.RecipeBuilder.getValue(RecipeBuilder.java:334)[23:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.RecipeBuilder.createBeanRecipe(RecipeBuilder.java:278)[23:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.RecipeBuilder.createRecipe(RecipeBuilder.java:110)[23:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.RecipeBuilder.createRepository(RecipeBuilder.java:93)[23:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.getRepository(BlueprintContainerImpl.java:481)[23:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:328)[23:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:269)[23:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:294)[23:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:263)[23:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:253)[23:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)[17:org.apache.aries.util:1.1.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)[17:org.apache.aries.util:1.1.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)[17:org.apache.aries.util:1.1.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)[17:org.apache.aries.util:1.1.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)[17:org.apache.aries.util:1.1.0]
at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1127)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:696)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:484)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4429)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2100)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.Felix.updateBundle(Felix.java:2412)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.BundleImpl.update(BundleImpl.java:994)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.karaf.shell.dev.watch.BundleWatcher.run(BundleWatcher.java:120)[43:org.apache.karaf.shell.dev:2.4.0.redhat-621084]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_101]
In my contract-first setup I enable schema validation in a blueprint context like so:
<cxf:cxfEndpoint id="cxfEndpoint" address="http://0.0.0.0:${cxf.port}/${application-path}" serviceClass="my.generated.service.Class" >
<cxf:properties>
<entry key="schema-validation-enabled" value="true" />
</cxf:properties>
</cxf:cxfEndpoint>
This should work for code first just as well.
If your XSD is separate from the WSDL, i.e. a different file you can use the validator component.
<camelContext>
<route>
<from uri="cxf:bean:myEndpoint" />
<to uri="validator:my/endpoint/schema1.xsd" />
<to uri="bean:doProcess" />
</route>
</camelContext>
You should probably also enclose that with a doTry/doCatch or add an error handler to your route or context.
To configure the cxf-endpoint to set the Exchange body to the actual soap:body you can to the following:
<cxf:cxfEndpoint id="readingsEndpoint"
address="/readings/"
serviceClass="my.endpoint.Interface">
<cxf:properties>
<entry key="dataFormat" value="PAYLOAD"/>
</cxf:properties>
</cxf:cxfEndpoint>
I know I can define Camel routes in stand-alone xml file, using the Blueprint syntax. If I move one of this file in the "deploy" folder of ServiceMix, it automatically becomes an OSGI bundle. My question is, can I set an endpoint to this new bundle, accessible from outside?
I would like to do something like this:
blue_route1.xml
<blueprint>
<camelContext>
<route>
<from uri="http:my_servicemix:8181/blue_route1_endpoint" />
<to uri="jetty:http://server1" />
</route>
</camelContext>
</blueprint>
blue_route1 becomes an OSGI bundle once deployed, but where should I define "blue_route1_endpoint" ? Is it doable?
[UPDATE]
summering, I want that an external WS is able to send messages to blue_route1_endpoint, where the blue_route1 bundle will redirect messages according to Camel routes, without the need to create a new WS "Blue_route1" to deploy in ServiceMix
______________________
| ____________ |
external-->(blue_route1_endpoint)==|==-->|blue_route1|--|-->(http://server1)
WS | |___________| |
|____________________|
ServiceMix
Found it! I didn't get that it's so easy. To make ServiceMix listen on a port, I just have to specify the endpoint using the Camel-jetty component.
So, to answer my question, I solved in this way:
install the camel-jetty component in ServiceMix
features:install camel-jetty
Write the camel-route with Blueprint, in blue_route1.xml file
<?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"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri:="jetty:http:my_servicemix:8181/blue_route1_endpoint">
<to uri="http://localhost:8080/user/services/user?bridgeEndpoint=true&throwExceptionOnFailure=false"/>
</route>
<route>
<from uri="jetty:http://0.0.0.0:6969/sp_role?matchOnUriPrefix=true"/>
<setHeader headerName="Content-Type">
<groovy>"text/xml; charset=utf-8"</groovy>
</setHeader>
<to uri="http://server1"/>
</route>
</camelContext>
</blueprint>
I used a random port 8181 to listen to... but I could choose every number, ServiceMix will automatically start a jetty component, listening and consuming on that port/endpoint.
For SOAP messages you need CXF Component and wsdl file of your webservice. You can configure your endpoint outside of the camelContext like this:
<cxf:cxfEndpoint id="yourId" address="/your/address/to/endpoint"
serviceClass="your.java.ServiceClass"
wsdlURL="path/to/your/wsdl/file.wsdl" />
And in your route use tag like this:
<from uri="cxf:bean:yourId"/>
You need to add namespace and schemaLocation to your blueprint to use cxf namespace, use this:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.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">
I've encountered a very strange problem with Fuse ESB 7.1.0: when a cxf endpoint produces a fault, then this fault doesn't look like an exception, so I can't process it using doCatch construction.
The cxf endpoint is defined as follows:
<cxf:cxfEndpoint id="cxf-ep" address="${ws.url}" serviceClass="MyServiceClass">
<cxf:properties>
<entry key="dataFormat" value="POJO" />
</cxf:properties>
</cxf:cxfEndpoint>
And here is a short code snippet where I expect an exception:
<doTry>
<to uri="cxf:bean:cxf-ep" />
<doCatch>
<exception>org.apache.cxf.interceptor.Fault</exception>
<handled>
<constant>true</constant>
</handled>
<to uri="log:exceptions?multiline=true&showCaughtException=true&showStackTrace=true&showBody=true&showProperties=true&showHeaders=true&level=ERROR" />
</doCatch>
</doTry>
I've tried to add handleFault="true" attribute to both a camel context and a route, but without success.
A bundle with a similar parameters and routes has worked as expected on Fuse ESB/ServiceMix 4.4.1, so it looks like a regression or maybe something has changed in camel in the new release?
Another interesting moment is that when a web server is not available, then camel produces org.apache.cxf.interceptor.Fault, so it can't be handled as an exception!
Camel version: 2.10.0.fuse-71-047