You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "magic.coder" <ni...@gmail.com> on 2012/07/11 12:01:16 UTC

problem with camel-http routing with spring dsl

Hi I am trying to call a webservice using camel-http component.

When I write my routing logic using java-dsl, it just works fine and I can
retrieve the soap response in String format as out message body. However,
when I do the same using spring-dsl I get the following error.

*WARN  DirectProducer - No consumers available on endpoint:
Endpoint[direct://MyProducerUri] to process: Exchange[Message:
<soapenv:Envelope ....> .... </soapenv:Envelope>]*

and I get the response as null.

Following is my code and camel-route.xml.

*ApplicationContext applicationContext = new
ClassPathXmlApplicationContext("META-INF/spring/camel-route.xml");
CamelContext context = new SpringCamelContext(applicationContext);

try {
context.start();
String soapMessage = "<soapenv:Envelope ....>.....</soapenv:Envelope>"; //
Truncating the actual soap request xml content here with .... .
Exchange exchange = new DefaultExchange(context);
ProducerTemplate template = exchange.getContext().createProducerTemplate();
exchange.getIn().setBody(soapMessage);
exchange.setPattern(ExchangePattern.InOut);
exchange.getIn().setHeader("SOAPAction", "");
exchange = template.send("direct:MyProducerUri", exchange);
String output = exchange.getOut().getBody(String.class);
System.out.println(output);
} finally {
context.stop();
}*

camel-route.xml

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:camel="http://camel.apache.org/schema/spring"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
         http://www.springframework.org/schema/beans/spring-beans-3.0.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>
			<from uri="direct:MyProducerUri"/>
			<to
uri="http://localhost:8080/camel-example-cxf-tomcat/webservices/incident"/>
		</route>
	</camelContext>
</beans>

Routing logic in java dsl-->

context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
   
from("direct:MyProducerUri").to("http://localhost:8080/camel-example-cxf-tomcat/webservices/incident");
}
});

I have deployed the webservice in my local machine tomcat.
Please help me with this. I am sure this is some configuration issue.

--
View this message in context: http://camel.465427.n5.nabble.com/problem-with-camel-http-routing-with-spring-dsl-tp5715852.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: problem with camel-http routing with spring dsl

Posted by "magic.coder" <ni...@gmail.com>.
Worked like a charm.. Thanks a lot Mr. Claus Ibsen.

Regards,
magic.coder

--
View this message in context: http://camel.465427.n5.nabble.com/problem-with-camel-http-routing-with-spring-dsl-tp5715852p5716021.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: problem with camel-http routing with spring dsl

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jul 11, 2012 at 12:01 PM, magic.coder <ni...@gmail.com> wrote:
> Hi I am trying to call a webservice using camel-http component.
>
> When I write my routing logic using java-dsl, it just works fine and I can
> retrieve the soap response in String format as out message body. However,
> when I do the same using spring-dsl I get the following error.
>
> *WARN  DirectProducer - No consumers available on endpoint:
> Endpoint[direct://MyProducerUri] to process: Exchange[Message:
> <soapenv:Envelope ....> .... </soapenv:Envelope>]*
>
> and I get the response as null.
>
> Following is my code and camel-route.xml.
>
> *ApplicationContext applicationContext = new
> ClassPathXmlApplicationContext("META-INF/spring/camel-route.xml");
> CamelContext context = new SpringCamelContext(applicationContext);
>

This is wrong ^^^^, you should not create a new camel context. But
lookup the existing context from the spring application context
instead. As when spring startup, eg you need to call start on
applicationContext, then all the namespace gets executed, and there is
the Camel namespace parser which executes the <camelContext ...>
..</camelContext> from the XML file, and creates a new CamelContext
and enlist that into the spring app context bean registry.

Therefore you should lookup that bean.

eg

CamelContext context = applicationContext.getBean("myCamel, CamelContext.class);

And then in the XML file set the <camelContext id="myCamel" ...> eg
set the id attribute to give it an id, you can lookup.



> try {
> context.start();
> String soapMessage = "<soapenv:Envelope ....>.....</soapenv:Envelope>"; //
> Truncating the actual soap request xml content here with .... .
> Exchange exchange = new DefaultExchange(context);
> ProducerTemplate template = exchange.getContext().createProducerTemplate();
> exchange.getIn().setBody(soapMessage);
> exchange.setPattern(ExchangePattern.InOut);
> exchange.getIn().setHeader("SOAPAction", "");
> exchange = template.send("direct:MyProducerUri", exchange);
> String output = exchange.getOut().getBody(String.class);
> System.out.println(output);
> } finally {
> context.stop();
> }*
>
> camel-route.xml
>
> <beans xmlns="http://www.springframework.org/schema/beans"
>         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>         xmlns:camel="http://camel.apache.org/schema/spring"
>         xsi:schemaLocation="http://www.springframework.org/schema/beans
>          http://www.springframework.org/schema/beans/spring-beans-3.0.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>
>                         <from uri="direct:MyProducerUri"/>
>                         <to
> uri="http://localhost:8080/camel-example-cxf-tomcat/webservices/incident"/>
>                 </route>
>         </camelContext>
> </beans>
>
> Routing logic in java dsl-->
>
> context.addRoutes(new RouteBuilder() {
> @Override
> public void configure() throws Exception {
>
> from("direct:MyProducerUri").to("http://localhost:8080/camel-example-cxf-tomcat/webservices/incident");
> }
> });
>
> I have deployed the webservice in my local machine tomcat.
> Please help me with this. I am sure this is some configuration issue.
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/problem-with-camel-http-routing-with-spring-dsl-tp5715852.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen