IllegalStateException on camel cxf route in FUSE (servicemix) ESB - apache-camel

I try to set up a camel (Ver. 2.4.0) route in a FUSE (Ver. 4.3.0) ESB/OSGi container.
It should be a simple cxf-proxy to route a WebService call from a 'proxy' address to a real service.
I read several documentation:
CXF Proxy Example
camel cxf component
and set up the following spring configuration:
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd
http://camel.apache.org/schema/osgi
http://camel.apache.org/schema/osgi/camel-osgi.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd">
<import
resource="classpath:META-INF/cxf/cxf.xml" />
<import
resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import
resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
<import
resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml" />
<!-- the proxy service -->
<cxf:cxfEndpoint
id="myServiceProxy"
address="http://localhost:9003/cxf/myService"
serviceClass="foo.bar.iface.MyServiceInterface" />
<!-- my real existing cxf soap service -->
<cxf:cxfEndpoint
id="myService"
address="http://foo.bar/services/myService"
wsdlURL="http://foo.bar/services/myService?wsdl"
serviceClass="foo.bar.iface.MyServiceInterface"
serviceName="s:MyService"
endpointName="s:MyServiceEndpoint"
xmlns:s="http://foo.bar/iface/" />
<!-- route -->
<camel:camelContext>
<camel:route>
<camel:from
uri="cxf:bean:myServiceProxy" />
<camel:to
uri="cxf:bean:myService" />
</camel:route>
</camel:camelContext>
</beans>
Trying to start the bundle in FUSE leads to this exception
karaf#root> Exception in thread "SpringOsgiExtenderThread-22" org.apache.camel.RuntimeCamelException: java.lang.IllegalStateException: Endpoint address should be a relative URI wrt to the servlet address (use '/xxx' for example)
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1126)
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:103)
at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:231)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
I do not know what's wrong. I doubt that my Endpoint address is wrong and I do not know what my servlet address is (there is no cxf:cxfEndoint servelt address attribute).
Any help to lead me in the right direction to solve this problem would be appreciated.
Thanks
Klaus

I finally found out what's wrong.
Instead
<!-- the proxy service -->
<cxf:cxfEndpoint
id="myServiceProxy"
address="http://localhost:9003/cxf/myService"
serviceClass="foo.bar.iface.MyServiceInterface" />
it has to be
<!-- the proxy service -->
<cxf:cxfEndpoint
id="myServiceProxy"
address="/myService"
serviceClass="foo.bar.iface.MyServiceInterface" />
As the first approach worked well running the camel project outside FUSE (in this case a the http server will be started to provide the service) it has to be a relative address inside FUSE.
Inside FUSE the embedded HTTP server which runs on (localhost:8181) will be used and the service url will be extended to http://localhost:8181/cxf/myService.

Related

Spring bean from one bundle is not accessible in camel route in another bundle

I have one jar file (connection.jar) which is an OSGI bundle with folder structure src/main/resources/META-INF/spring/mq-connect.xml
following connectivity code is placed in the mq-connect.xml
<beans ...... >
....
....
....
....
<!-- AMQ jms component -->
<bean id="amqtx" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="amqPooledConnectFactory" />
...
...
...
<property name="maxConcurrentConsumers" value="${concurrent.consumers}" />
</bean>
</beans>
I have another osgi bundle (connection_impl.jar) which contains camel routes. I want to use "amqtx" bean as the component in the camel endpoint.
Following is the code which I put in the camel-context.xml to access the "amqtx"
<beans ...... >
<import resource="classpath*:mq-connect.xml"/>
...
...
...
...
<camelContext trace="true" streamCache="true" autoStartup="true" xmlns="http://camel.apache.org/schema/spring">
<route customId="true" id="TEST_AMQ">
<description>Test connectivity from another file</description>
<from uri="amqtx:INBOUND.QUEUE" />
<transacted ref="AMQ_PROPAGATION_REQUIRED" />
<to uri="OUTBOUND.QUEUE" />
<log message="Route completed successfully" />
</route>
</camelContext>
</beans>
I am using jboss-a-mq-6.2.1 and deploying to Karaf container. OSGi bundle connection.jar deploys successfully but connection_impl fails to deploy.
It gives following error in the A-MQ logs
Stack Trace:
org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: Failed to create route TEST_AMQ:
Route(TEST_AMQ)[[From[amqtx:INBOUND.QUEUE]] -> ... because of Failed to resolve endpoint: amqtx://INBOUND.QUEUE due to: No component found with scheme: amqtx
I tried the part in various ways but still amqtx is not accessible in another bundle.
Please suggest any missing import,export/wrong configuration so that amqtx component in connection.jar is accessible in connection_impl.jar
Not sure if you can make this work at all but it is definitely not recommended to import a spring xml in another bundle.
Better export the bean as a service in the first bundle and refer it as a service in the second. This will also decouple your bundle in a better way.
I am in agreement with Christian. When you are using OSGI bundles are typically isolated unless you explicitly set exports for a library another bundle uses or you are exposing an OSGI Service. If you would like to setup an OSGI service my recommendation is doing it the Spring Framework way since its relatively clean. You can expose your Component via an interface. I'll show an example below.
Typically I like to have 3 bundles managing this. I usually have a bundle that contains just the interface that I will be exposing between separate bundles. A Bundle that is the implementation of the interface and a bundle that leverages the interface's injected implementation to accomplish a task.
//Interface bundle will expose an Interface and any Pojos associated. Ex:
public interface AlternateFacilityApi {
public String getAlternateFacility(String facilityName);
}
//Implementation bundle will register an OSGI service based off of the implementation bean from your interface (yes the previous bundle is a dependency OSGI wires in)
public Class MyAlternateFacilityImpl implements AlternateFacilityApi {
public String getAlternateFacility(String facilityName) {
return "Bob's house";
}
//camel context
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:ctx="http://www.springframework.org/schema/context"
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
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<osgi:service id="AlternateFacilityService" ref="alternateFacilityService" interface="com.world.api.AlternateFacilityApi" />
<bean id="alternateFacilityService" class="com.world.service.MyAlternateFacilityImpl"
/>
</beans>
//Ok and finally the Process looking to leverage the OSGI Service
public Class AlternateFacilityLookup {
private AlternateFacilityApi apiLookupBean;
public String getMyAlternateFacility(String facilityName) {
return apiLookupBean.getAlternateFacility(facilityName);
}
//excluded setters and getters
}
//camel context
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:ctx="http://www.springframework.org/schema/context"
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
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<osgi:reference id="AlternateFacilityLookupService" interface="com.world.api.AlternateFacilityApi" />
<bean id="MyAlternateFacilityBean" class="com.awesome.AlternateFacilityLookup">
<property name="apiLookupBean" ref="AlternateFacilityLookupService" />
</bean>

messages not being consumed by apache camel using servicemix as a broker

So I'm trying to use apache servicemix/camel to aggregate some messages coming through a JMS queue. The logic I have is dead-simple I just want it to use the last message received and only send it through 3 seconds after the last one.
I have servicemix setup as a message broker and I'm able to use it in such a capacity however it doesn't seem to trigger the route. I've never done this before so odds are I'm horribly off-base but here is what I have so far (put this in deploy/fedora-messaging/camel-context.xml)
<?xml version="1.0" encoding="UTF-8"?>
<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-2.5.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="activemq:topic:fedora.apim.update.merge"/>
<aggregate completionTimeout="3000">
<correlationExpression>
<simple>header.pid</simple>
</correlationExpression>
<to uri="log:events"/>
<to uri="activemq:topic:fedora.apim.update"/>
</aggregate>
</route>
</camelContext>
<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
</beans>
The osgi application appears to start and run without error, and messages are received and queued in the topic:fedora.apim.update.merge however they just sit in the queue and never get consumed or pushed out to the destination queue.
I tested your route as a standalone application (outside of a ServiceMix container) with following broker configuration and everything worked as expected:
<broker xmlns="http://activemq.apache.org/schema/core" useJmx="true"
persistent="false">
<transportConnectors>
<transportConnector uri="tcp://localhost:61616" />
</transportConnectors>
</broker>
So, I guess, we can assume that your Camel route definition is not the problem but the ActiveMQ configuration and/or ServiceMix set-up.
EDIT:
Note, that messages to JMS topic destinations are lost if no active subscriber is connected to the destination. If you need some kind of persistence use durable subscribers or JMS queue destinations.

JBOSS FUSE Bundle is waiting for namespace handlers in GracePeriod

I tried to add bean into blueprint.
Added CXF namespace. But, JBOSS FUSE shows
13:10:28,339 | INFO | NAPSHOT-thread-1 | BlueprintContainerImpl | 14 - org.apache.aries.blueprint.core - 1.0.1.redhat-60024 | Bundle camel-basic is waiting for namespace handlers [http://camel.apache.org/schema/cxf]
So, I remove the cxf and added blueprint namespace
http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
But, still no use, It shows same error for this namespace also.
Do I need to change anything in pom, blueprint.xml r need install anything in jboss fuse?
I have no clue about this.
blueprint.xml
<?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:camel="http://camel.apache.org/schema/blueprint" 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">
<camelContext id="blueprintContext"
trace="false"
xmlns="http://camel.apache.org/schema/blueprint">
<route id="httpBridge">
<from uri="jetty:http://localhost:8282/service_sample_proxy/services_proxy/WebserviceClassPort?matchOnUriPrefix=true"/>
<process ref="downloadLogger"/>
<to uri="jetty:http://localhost:8080/service_sample/services/WebserviceClassPort?bridgeEndpoint=true&throwExceptionOnFailure=false"/>
<process ref="downloadLogger"/>
<to uri="bean:helloBean"/>
</route>
</camelContext>
<cxf:cxfEndpoint id="webserviceProxy"
address="http://localhost:8383/service_sample_proxy/services_proxy/WebserviceClassPort"
endpointName="tns:WebserviceClassPort"
serviceName="tns:WebserviceClassService"
wsdlURL="wsdl/webserviceclass.wsdl"
xmlns:tns="http://webservice/" />
<bean id="helloBean" class="org.fusesource.example.HelloBean" />
<bean id="downloadLogger" class="org.fusesource.example.DownloadLogger"/>
</blueprint>
I haven't used this bean in any place. First I need to resolve this problem then I need to use it in route.
I check the
Please help me.
Install all needed features into your Fuse container (see here for more information):
features:addUrl mvn:org.apache.camel.karaf/apache-camel/2.9.0/xml/features
features:install war
features:install cxf
features:install camel-jaxb
features:install camel-blueprint
features:install camel-cxf
Well, I went through all the steps stated above to find out it still does not work in blueprint.
Strangely as soon as the route was dropped in the spring xml and taken out of blueprint everything started working like a magic.
Tried camel-cxf instead cxf and worked with blueprint

No declaration for cxfEndpoint in Servicemix deployment

I am trying to get a CXF endpoint working on Servicemix 4. I have created a Spring archetype with a CXF endpoint and successfully installed it with Maven. Having run osgi:install - s mvn: it installs onto Servicemix but the logs are displaying:
Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=springdm,
config=osgibundle:/META-INF/spring/*.xml))
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 21 in XML document
from URL [bundle://218.0:0/META-INF/spring/camel-context.xml] is invalid; nested exception is
org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no
declaration can be found for element 'cxf:cxfEndpoint'
I have built this route just on Camel before with the following in my context.xml file:
<beans ...
xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://cxf.apache.org/tranposrts/camel http://cxf.apache.org/tranposrts/camel.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<cxf:cxfEndpoint id="wspoc"
address="http://localhost:8181/ws/ping"
serviceClass="net.ja.smx.springdm.PongImpl" />
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="cxf:bean:wspoc"/>
<to uri="activemq:helloQ" />
</route>
</camelContext>
This is a clone of a working Camel context file but I cannot see why ServiceMix is throwing the error when it starts. The only difference is that the pom file does not use CXF as a dependency but it is in the section which I took from the online example.
I would be grateful for any pointers for any missing imports or corrections to the context file or anything that I ought to check for.
Many thanks.
Shortly after posting, I discovered that I was missing the camel-cxf dependency in my POM file which causes this error. I also needed to make sure that it was the right version as this caused an error in ServiceMix finding the correct META.cxf file.

Annotated beans not getting injected for JAX-RS CXF service

I have a CXF RESTful service which is working just fine. Problem is when I try to inject my DAO using an annotation:
#Resource
private MyDAO myDAO;
It's not getting injected. My JAX-RS service is Spring configured like so:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<jaxrs:server id="message" serviceClass="com.foo.MessageResourceImpl" address="/">
<jaxrs:features>
<cxf:logging/>
</jaxrs:features>
</jaxrs:server>
</beans>
The DAO is getting initialized by Spring and I have verified the bean works in any other POJO, just not the CXF service. Furthermore, I don't see any errors in the logs
The solution is to serviceBeans:
<jaxrs:serviceBeans>
<bean class="com.foo.MessageResourceImpl"/>
</jaxrs:serviceBeans>
When using #serviceClass, CXF instantiates the class, not Spring.

Resources