Publish JavaScript Client over Apache cxf with Spring configuration - spring

We are publishing a REST-API in our Server-Application. The Rest-API is configured with Spring and uses Apache cxf. The whole configuration is defined in xml and via Annotaions.
Now we have a JavaScript client that uses the rest-api and we want to publish the client (index.html,bundle.js,... ) with the webserver from apache cxf.
Example: localhost:7564/api/v1/webapp
We want to use the embedded web server from Apache cxf to publish the js client. No additinal Tomcat/Apache/... .
There are many exmaples with static-content but none of these are using Spring/ApacheCxf/embeddedWebserver and xml/Annotation-based configuration.
Any ideas?
xml configuration loaded in our Spring applicationcontext.xml:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
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-4.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
<!-- Apache CXF initiale Konfiguration -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<jaxrs:server
id="jaxrsEmbeddedServer"
address="http://0.0.0.0:7564/api/v1" >
<jaxrs:serviceBeans>
<bean class="com.isp.lea.service.web.api.v1.RootApi" />
...
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean
id="cors-filter"
class="org.apache.cxf.rs.security.cors.CrossOriginResourceSharingFilter" />
...
</jaxrs:providers>
<jaxrs:features>
<ref bean="swagger2Feature" />
...
</jaxrs:features>
</jaxrs:server>
Rest-api example:
#Path( "/" )
#SuppressWarnings( "javadoc" )
public class RootApi extends RestApi
{
#GET
#ApiOperation( value = "Hello World! ",
notes = "Notes...",
tags = { "apm" } )
public String nichts()
{
return "Hello!";
}
}

Related

How can i configure my spring aop xml with aop.xml an load time weaving?

I have one "Hello word" application on spring AOP and configured by XML, it looks like this:
public class CustomerBoImpl {
public CustomerBoImpl() {
super();
}
protected void addCustomer(){
System.out.println("addCustomer() is running ");
}
}
public class App {
public static void main(String[] args) throws Exception {
ApplicationContext appContext =
new ClassPathXmlApplicationContext("Spring-Customer.xml");
CustomerBoImpl customer =
(CustomerBoImpl) appContext.getBean("customerBo");
customer.addCustomer();
}
}
My spring configuration looks like this:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="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://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">
<aop:aspectj-autoproxy />
<!-- this switches on the load-time weaving -->
<context:load-time-weaver aspectj-weaving="on" />
<bean id="customerBo" class="com.mkyong.saad.CustomerBoImpl"
scope="singleton" />
<!-- Aspect -->
<bean id="logAspect" class="com.mkyong.saad.LoggingAspect" />
<aop:config>
<aop:aspect id="aspectLoggging" ref="logAspect">
<!-- #Before -->
<aop:pointcut id="pointCutBefore"
expression="execution(* com.mkyong.saad.CustomerBoImpl.addCustomer(..))" />
<aop:before method="logBefore" pointcut-ref="pointCutBefore" />
<!-- #After -->
<aop:pointcut id="pointCutAfter"
expression="execution(* com.mkyong.saad.CustomerBoImpl.addCustomer(..))" />
<aop:after method="logAfter" pointcut-ref="pointCutAfter" />
</aop:aspect>
</aop:config>
that doesn't work because of protected method, so I tried to use load time weaving with aop.xml like this:
<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<weaver>
<!-- only weave classes in our application-specific packages -->
<include within="com.mkyong.saad.*"/>
</weaver>
<aspects>
<!-- weave in just this aspect -->
<aspect name="com.mkyong.saad.LoggingAspect"/>
</aspects>
</aspectj>
Source code for the aspect:
public class LoggingAspect {
public void logBefore(JoinPoint joinPoint) {
System.out.println("logBefore() is running!");
System.out.println("hijacked : " + joinPoint.getSignature().getName());
System.out.println("******");
}
public void logAfter(JoinPoint joinPoint) {
System.out.println("logAfter() is running!");
System.out.println("hijacked : " + joinPoint.getSignature().getName());
System.out.println("******");
}
}
but it doesn't work, only if I change to annotation config. SOS PLZ
removing the following code in your aop.xml, then run your jvm with args like this: -javaagent:"yourpath/spring-instrument-***.jar"
<weaver>
<!-- only weave classes in our application-specific packages -->
<include within="com.mkyong.saad.*"/>
</weaver>

spring data jpa and commons compatibility

I meet an exception running a project using spring data jpa
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 18 in XML document from class path resource [META-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; systemId: http://www.springframework.org/schema/data/jpa/spring-jpa.xsd; lineNumber: 18; columnNumber: 51; src-resolve: Cannot resolve the name 'repository:repositories' to a(n) 'type definition' component.
I read through many docs and blogs and I think this is possibly caused by incompatibility of spring data jpa and spring data commons package versions.
Now I'm using
spring-data-commons-core-1.4.1.Release
spring-data-commons-1.10.0.release
spring-data-jpa-1.8.0.
Any suggestion on the version control to get rid of such error?
Also I would like to ask for suggestions how to make such version control easier(any website, docs or tools). Thanks for advice in advance.
Below is the namespace I use
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:repository="http://www.springframework.org/schema/data/repository"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.xsd">
The repository:repository is not from my applicationContext.xml. I did use jpa:repository as
<jpa:repositories base-package="com.canreef.calendar"/>
I found this roots in spring-repository.xsd
In spring-jpa.xsd there is a line with ref to repository:auditing-attributes:
<xsd:element name="auditing">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="org.springframework.data.jpa.domain.support.AuditingEntityListener" />
<tool:exports type="org.springframework.data.auditing.AuditingHandler" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType>
<xsd:attributeGroup ref="repository:auditing-attributes" />
</xsd:complexType>
</xsd:element>
While in spring-repository.xsd there is the bean:
-<xsd:attributeGroup name="auditing-attributes">
-<xsd:attribute name="auditor-aware-ref">
-<xsd:annotation>
-<xsd:documentation>
<![CDATA[ References a bean of type AuditorAware to represent the current principal. ]]>
</xsd:documentation>
-<xsd:appinfo>
-<tool:annotation kind="ref">
<tool:assignable-to type="org.springframework.data.domain.AuditorAware"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
...omitted...
</xsd:attributeGroup>
Therefore this should be caused by not able to fetch the repository.xsd.

hibernate ehcache timeToLiveSeconds not working

I am using query cache in Spring Data, Hibernate, ehcache environment. The ehcache dependency is compile 'org.hibernate:hibernate-ehcache:3.3.1.GA'
The ehcache dependency tree is
+--- org.hibernate:hibernate-ehcache:3.3.1.GA
| +--- org.hibernate:hibernate-core:3.3.1.GA -> 3.6.6.Final (*)
| +--- net.sf.ehcache:ehcache:1.2.3
| | \--- commons-collections:commons-collections:2.1 -> 3.2.1
| \--- org.slf4j:slf4j-api:1.5.2 -> 1.6.5
I have a resources/ehcache.xml with timeToLiveSeconds configured to 5 minutes.
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<diskStore path="/home/prayag/cache_"/>
<defaultCache
eternal="false"
maxElementsInMemory="1000"
overflowToDisk="true"
diskPersistent="true"
timeToLiveSeconds="300"
diskExpiryThreadIntervalSeconds="300"
memoryStoreEvictionPolicy="LRU"
/>
</ehcache>
Caching works but after 5 minutes, cache doesn't get auto-flushed and no new changes are shown.
Not even following code to remove cache works.
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
CacheManager cacheManager = CacheManager.getInstance();
String[] names = cacheManager.getCacheNames();
for (String name : names) {
if (name.equals("merchantServices")) {
Cache cache = cacheManager.getCache(name);
cache.removeAll();
}
}
My Caching configuration(jpa-context.xml) with cacheName merchantServices is
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns:p="http://www.springframework.org/schema/p"
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache.xsd"
default-autowire="byName">
<tx:annotation-driven />
<cache:annotation-driven />
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="merchantServices"/>
</set>
</property>
</bean>
</beans>
Caching files at diskStore are as below,
prayag#prayag:~/cache_$ ls -l
total 4
-rw-rw-r-- 1 prayag prayag 0 Sep 20 13:31 org.hibernate.cache.StandardQueryCache.data
-rw-rw-r-- 1 prayag prayag 0 Sep 20 15:26 org.hibernate.cache.StandardQueryCache.index
-rw-rw-r-- 1 prayag prayag 2268 Sep 20 15:24 org.hibernate.cache.UpdateTimestampsCache.data
-rw-rw-r-- 1 prayag prayag 0 Sep 20 15:26 org.hibernate.cache.UpdateTimestampsCache.index
org.hibernate.cache.UpdateTimestampsCache.data has following content.
prayag#prayag:~/cache_$ vi org.hibernate.cache.UpdateTimestampsCache.data
¬í^#^Esr^#^Vnet.sf.ehcache.Element.e^H<90>Iî-<9d>^B^#^LJ^#^LcreationTimeZ^#^GeternalJ^#^HhitCountJ^#^NlastAccessTimeJ^#^NlastUpdateTimeZ^#^KlifespanSetJ^#^TnextToLastAccessTimeI^#
timeToIdleI^#
timeToLiveJ^#^GversionL^#^Ckeyt^#^RLjava/lang/Object;L^#^Evalueq^#~^#^Axp^#^#^AA:°<84>Ä^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^AA:°<84>Ä^A^#^#^#^#^#^#^#^#^#^#^#^#^#^#^A,^#^#^AA:°<84>Ät^#^GServicesr^#^Njava.lang.Long;<8b>ä<90>Ì<8f>#ß^B^#^AJ^#^Evaluexr^#^Pjava.lang.Number<86>¬<95>^]^K<94>à<8b>^B^#^#xp^#^T^S«^HL0^#^#°^#¬í^#^Esr^#^Vnet.sf.ehcache.Element.e^H<90>Iî-<9d>^B^#^LJ^#^LcreationTimeZ^#^GeternalJ^#^HhitCountJ^#^NlastAccessTimeJ^#^NlastUpdateTimeZ^#^KlifespanSetJ^#^TnextToLastAccessTimeI^#
timeToIdleI^#
timeToLiveJ^#^GversionL^#^Ckeyt^#^RLjava/lang/Object;L^#^Evalueq^#~^#^Axp^#^#^AA:°<84>Ä^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^AA:°<84>Ä^A^#^#^#^#^#^#^#^#^#^#^#^#^#^#^A,^#^#^AA:°<84>Ät^#^Lservice_tagssr^#^Njava.lang.Long;<8b>ä<90>Ì<8f>#ß^B^#^AJ^#^Evaluexr^#^Pjava.lang.Number<86>¬<95>^]^K<94>à<8b>^B^#^#xp^#^T^S«^HL0^#^T^S¥[\°^#¬í^#^Esr^#^Vnet.sf.ehcache.Element.e^H<90>Iî-<9d>^B^#^LJ^#^LcreationTimeZ^#^GeternalJ^#^HhitCountJ^#^NlastAccessTimeJ^#^NlastUpdateTimeZ^#^KlifespanSetJ^#^TnextToLastAccessTimeI^#
timeToIdleI^#
timeToLiveJ^#^GversionL^#^Ckeyt^#^RLjava/lang/Object;L^#^Evalueq^#~^#^Axp^#^#^AA:±%^Q^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^AA:±%^Q^A^#^#^#^#^#^#^#^#^#^#^#^#^#^#^A,^#^#^AA:±%^Qt^#
SessionLogsr^#^Njava.lang.Long;<8b>ä<90>Ì<8f>#ß^B^#^AJ^#^Evaluexr^#^Pjava.lang.Number<86>¬<95>^]^K<94>à<8b>^B^#^#xp^#^T^S«^RQ^#^#^#¬í^#^Esr^#^Vnet.sf.ehcache.Element.e^H<90>Iî-<9d>^B^#^LJ^#^LcreationTimeZ^#^GeternalJ^#^HhitCountJ^#^NlastAccessTimeJ^#^NlastUpdateTimeZ^#^KlifespanSetJ^#^TnextToLastAccessTimeI^#
timeToIdleI^#
timeToLiveJ^#^GversionL^#^Ckeyt^#^RLjava/lang/Object;L^#^Evalueq^#~^#^Axp^#^#^AA:°<84>Ä^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^AA:°<84>Ä^A^#^#^#^#^#^#^#^#^#^#^#^#^#^#^A,^#^#^AA:°<84>Ät^#^SServiceAccessStatussr^#^Njava.lang.Long;<8b>ä<90>Ì<8f>#ß^B^#^AJ^#^Evaluexr^#^Pjava.lang.Number<86>¬<95>^]^K<94>à<8b>^B^#^#xp^#^T^S«^HL0^#¬í^#^Esr^#^Vnet.sf.ehcache.Element.e^H<90>Iî-<9d>^B^#^LJ^#^LcreationTimeZ^#^GeternalJ^#^HhitCountJ^#^NlastAccessTimeJ^#^NlastUpdateTimeZ^#^KlifespanSetJ^#^TnextToLastAccessTimeI^#
timeToIdleI^#
timeToLiveJ^#^GversionL^#^Ckeyt^#^RLjava/lang/Object;L^#^Evalueq^#~^#^Axp^#^#^AA:°<84>Ä^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^AA:°<84>Ä^A^#^#^#^#^#^#^#^#^#^#^#^#^#^#^A,^#^#^AA:°<84>Ät^#^HBankInfosr^#^Njava.lang.Long;<8b>ä<90>Ì<8f>#ß^B^#^AJ^#^Evaluexr^#^Pjava.lang.Number<86>¬<95>^]^K<94>à<8b>^B^#^#xp^#^T^S«^HL0^#¬í^#^Esr^#^Vnet.sf.ehcache.Element.e^H<90>Iî-<9d>^B^#^LJ^#^LcreationTimeZ^#^GeternalJ^#^HhitCountJ^#^NlastAccessTimeJ^#^NlastUpdateTimeZ^#^KlifespanSetJ^#^TnextToLastAccessTimeI^#
timeToIdleI^#
timeToLiveJ^#^GversionL^#^Ckeyt^#^RLjava/lang/Object;L^#^Evalueq^#~^#^Axp^#^#^AA:¼ó1^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^AA:¼ó1^A^#^#^#^#^#^#^#^#^#^#^#^#^#^#^A,^#^#^AA:¼ó1t^#^KUserSessionsr^#^Njava.lang.Long;<8b>ä<90>Ì<8f>#ß^B^#^AJ^#^Evaluexr^#^Pjava.lang.Number<86>¬<95>^]^K<94>à<8b>^B^#^#xp^#^T^S«Ï3^#^#
More of my configuration is here in earlier post Spring Data + Hibernate Query Caching not working
References
refresh/reset EHCache regions
Basically you are facing ehcache autoflush problem which is discussed over here.
Problem with auto flush in ehcache
There is a solution to your problem which has been discussed over here. hope it helps you coz I aint an ehcache pro.. :P
How Configuration Affects Element Flushing and Eviction

Spring Integration: Getting XSD Validation Error: cos-all-limited.1.2

I am getting below XSD Valdation error on running Spring Integrtion code:
demo-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cos-all-limited.1.2: An ''all'' model group must appear in a particle with '{'min occurs'}'='{'max occurs'}'=1, and that particle must be part of a pair which constitutes the '{'content type'}' of a complex type definition.
demo-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:int="http://www.springframework.org/schema/integration"
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd">
<import resource="jdbc-context.xml" />
<int:channel id="request" />
<int:channel id="response" />
<int:gateway id="demoService" service-interface="com.integration.DemoService" />
<int-jdbc:outbound-gateway
update="INSERT INTO Demo
SELECT EID, BR from tab1, tab2
WHERE tab1.BR=tab2.BR AND tab1.BR=:payload "
request-channel="requestChannel" reply-channel="responseChannel"
data-source="dataSource" />
<int:logging-channel-adapter id="loggingChannel"
channel="responseChannel" expression="'Inserted successfully'" />
</beans>
It looks as if your schema validator didn't like the schema -- but the schema looks OK to me (and more important, it looks OK Saxon, which is more reliable than I am on some details).
On the other hand, both Xerces and Saxon agree with your unnamed XSD validator that the document you show is invalid; they complain about the expression attribute on the int:logging-channel-adapter element and say that no attribute of that name is allowed.

Having trouble with content based routing in Camel with a CXFRS endpoint and xPath

I am trying to create a route that is determined by the content in the REST payload using xPath. I have been successful in using routing based on the message header:
<when>
<simple>${headers.operationName} == 'createContainerOutput'</simple>
<bean ref="containerOutputProcessor"/>
</when>
which properly invokes the containerOutputProcessor...
but for this xPath route:
<when>
<xpath>/*[local-name()='order-request']/#type='TrayOutput'</xpath>
<bean ref="containerOutputProcessor"/>
</when>
I get the the exception:
org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.w3c.dom.Document with value [com.mmi.ws.ContainerOutputOrderRequest#6290dc]
for this payload
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order-request type="TrayOutput">
<parameter name="orderName">Example Tray Output Order</parameter>
<parameter name="enableScan">true</parameter>
<parameter name="autoStart">false</parameter>
<parameter name="priority">3</parameter>
<item barcode="23990001"/>
<item barcode="23990002"/>
</order-request>
Is this type of routing a good idea? Is there a better way to route based on what type of order-request is being submitted?
Thanks for any help/guidance you may have for me!
Here is the complete context
<?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:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd">
<!-- enable Spring #Component scan -->
<context:component-scan base-package="com.mmi.ws"/>
<!-- web service beans -->
<bean id="containerOutputWS" class="com.mmi.ws.service.impl.ContainerOutputWSImpl" />
<bean id="containerTypesWS" class="com.mmi.ws.service.impl.ContainerTypesWSImpl" />
<!-- processor beans -->
<bean id="containerOutputProcessor" class="com.mmi.ws.service.ContainerOutputProcessor" />
<bean id="containerTypesProcessor" class="com.mmi.ws.service.ContainerTypesProcessor" />
<bean id="unsupportedPathProcessor" class="com.mmi.ws.service.UnsupportedPathProcessor" />
<!-- Define the real JAXRS back end service -->
<jaxrs:server id="restService"
address="http://localhost:9998/sc"
staticSubresourceResolution="true">
<jaxrs:serviceBeans>
<ref bean="containerOutputWS"/>
<ref bean="containerTypesWS"/>
</jaxrs:serviceBeans>
</jaxrs:server>
<!-- define the restful server and client endpoints -->
<cxf:rsServer id="rsServer" address="http://localhost:9999/sc" loggingFeatureEnabled="true" loggingSizeLimit="20">
<cxf:serviceBeans >
<ref bean="containerOutputWS"/>
<ref bean="containerTypesWS"/>
</cxf:serviceBeans>
</cxf:rsServer>
<cxf:rsServer id="rsClient" address="http://localhost:9998/sc" loggingFeatureEnabled="true" loggingSizeLimit="20">
<cxf:serviceBeans >
<ref bean="containerOutputWS"/>
<ref bean="containerTypesWS"/>
</cxf:serviceBeans>
</cxf:rsServer>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<!--
any classes in the below 'packageScan'packages that extends RouteBuilder
will be added as a camel route. At least one route is required to start the cxf web service
-->
<packageScan>
<package>com.mmi.ws</package>
</packageScan>
<dataFormats>
<xstream id="xstream-utf8" encoding="UTF-8"/>
<xstream id="xstream-default"/>
</dataFormats>
<!-- route starts from the cxf webservice -->
<route streamCache="true">
<from uri="cxfrs://bean://rsServer"/>
<log message="XML payload to send to REST WS:${body}" />
<setHeader headerName="CamelCxfRsUsingHttpAPI"><constant>True</constant> </setHeader>
<choice>
<when>
<simple>${headers.operationName} == 'getContainers'</simple>
<bean ref="containerTypesProcessor"/>
</when>
<when>
<xpath>/*[local-name()='order-request']/#type='TrayOutput'</xpath>
<bean ref="containerOutputProcessor"/>
</when>
<otherwise>
<bean ref="unsupportedPathProcessor"/>
<to uri="cxfrs://bean://rsClient"/>
</otherwise>
</choice>
</route>
</camelContext>
</beans>
and the web service class:
#Path("/container/output/")
public class ContainerOutputWSImpl
{
#POST
#Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
#Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ContainerOutputView createContainerOutput(ContainerOutputOrderRequest containerOutput) {
// TODO Auto-generated method stub
return new ContainerOutputView();
}
}
and finally, the xml payload and error stack:
Address: http://localhost:9999/sc/container/output/
Encoding: ISO-8859-1
Http-Method: POST
Content-Type: application/xml
Headers: {accept-encoding=[gzip,deflate], connection=[keep-alive], Content-Length=[384], content-type=[application/xml], Host=[localhost:9999], User-Agent=[Apache-HttpClient/4.1.1 (java 1.5)]}
Payload: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order-request type="TrayOutput">
<parameter name="orderName">Example Tray Output Order</parameter>
<parameter name="enableScan">true</parameter>
<parameter name="autoStart">false</parameter>
<parameter name="priority">3</parameter>
<item barcode="23990001"/>
<item barcode="23990002"/>
</order-request>
--------------------------------------
[ERROR] 2013-02-07 17:53:37.059 [qtp27633254-28: DefaultErrorHandler] Failed delivery for (MessageId: ID-PWY-EHANSEN-3070-1360288389778-0-2 on ExchangeId: ID-PWY-EHANSEN-3070-1360288389778-0-1). Exhausted after delivery attempt: 1 caught: org.apache.camel.RuntimeCamelException: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.w3c.dom.Document with value [com.mmi.ws.ContainerOutputOrderRequest#9fbbe5]
org.apache.camel.RuntimeCamelException: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.w3c.dom.Document with value [com.mmi.ws.ContainerOutputOrderRequest#9fbbe5]
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1271)
at org.apache.camel.builder.xml.XPathBuilder.getDocument(XPathBuilder.java:1027)
at org.apache.camel.builder.xml.XPathBuilder.doInEvaluateAs(XPathBuilder.java:850)
at org.apache.camel.builder.xml.XPathBuilder.evaluateAs(XPathBuilder.java:757)
at org.apache.camel.builder.xml.XPathBuilder.matches(XPathBuilder.java:145)
at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:66)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:73)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:334)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:220)
at org.apache.camel.processor.interceptor.StreamCachingInterceptor.process(StreamCachingInterceptor.java:52)
at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:303)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:117)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
at org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(RouteInflightRepositoryProcessor.java:48)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:73)
at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.asyncInvoke(CxfRsInvoker.java:87)
at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.performInvocation(CxfRsInvoker.java:57)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:201)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:102)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1074)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1010)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:365)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:722)
Before the content based router, you can convert the message to take out the payload from the internal CXF list. There is a trick with the simple language to grab the first index from the list:
<transform>
<simple>${body[0]}</simple>
</transform>
<choice>
...
Do you have camel-jaxb on the classpath. If so it may work out of the box without that trick. Not sure though, as CXF is a bit special. Also dependes on what version of Camel / CXF you use. You should really mention this when you ask questions!

Resources