I want to log the Apache CXF inbound and outbound interceptors logs inside the File instead of Console
Maven project :
1) Created a file named 'org.apache.cxf.Logger' under META-INF\cxf and placed the below text
META-INF\cxf\org.apache.cxf.Logger
org.apache.cxf.common.logging.Log4jLogger
2) application-context.xml:
<cxf:bus>
<cxf:inInterceptors>
<ref bean="loggingInInterceptor"/>
</cxf:inInterceptors>
<cxf:outInterceptors>
<ref bean="loggingOutInterceptor"/>
</cxf:outInterceptors>
<cxf:outFaultInterceptors>
<ref bean="loggingOutInterceptor"/>
</cxf:outFaultInterceptors>
<cxf:inFaultInterceptors>
<ref bean="loggingInInterceptor"/>
</cxf:inFaultInterceptors>
</cxf:bus>
<jaxrs:server id="services" address="/mysvc">
<jaxrs:serviceBeans>
<ref bean="myserviceImpl" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
</jaxrs:providers>
<jaxrs:outInterceptors>
<ref bean="loggingOutInterceptor" />
</jaxrs:outInterceptors>
<jaxrs:inInterceptors>
<ref bean="loggingInInterceptor" />
</jaxrs:inInterceptors>
</jaxrs:server>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor" id="loggingInInterceptor" />
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" id="loggingOutInterceptor" />
3) log4j2.xml: under src\main\resources folder
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="CompanyServices" packages="">
<Appenders>
<RollingFile name="RollingFile" fileName="D:/temp/companyfile.log"
filePattern="companyfile-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout>
<Pattern>%d %p [%t] %C:%L - %m%n</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="10 MB" />
</Policies>
</RollingFile>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout>
<Pattern>%d %p [%t] %C:%L - %m%n</Pattern>
</PatternLayout>
</Console>
</Appenders>
<Loggers>
<Logger name="com.myorg.mycompany" level="trace"
additivity="false">
<AppenderRef ref="RollingFile" />
</Logger>
<Logger name="org.apache.cxf.interceptor" level="info"
additivity="false">
<AppenderRef ref="RollingFile" />
</Logger>
<Root level="all">
<AppenderRef ref="RollingFile" />
</Root>
</Loggers>
</Configuration>
4. pom.xml :
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
A file was getting generated and printing only my application level logs to my file. But not printing CXF interceptors logs in to the file.
Please suggest what's going wrong?
step 1) Redirect to Slf4jLogger as it looks like redirecting to the Log4jLogger does not seem to work with Log4j2. In addition SLF4J allows more flexibility afterwards if you ever decided to change logging framework.
step 2) I think the above configuration could be simplified a bit. You are adding the logging interceptors to both the CXF bus and your JAX-RS endpoint. If you only want messages to be logged for your endpoint, add them there. If not, add them to the bus as such you do not need to repeat the configuration for possible other endpoints.
Also on the endpoint you did not add the logging interceptors to the fault interceptor chains. If you basically want to log all messages it is probably easier to use the CXF LoggingFeature. For more details on the difference between interceptors and features, check this blog post I wrote.
step 4) You would need the following dependencies:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
I've created a blog post which explains how to configure CXF for log4j2 in more detail.
Related
How to configuring WildFly 8.x JTA data-source properly in order to use JPA with EclipseLink and Microsoft's SQLServer Database?
A: Configure EclipseLink with WildFly
1- Download EclipseLink jar from Maven:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.2</version>
</dependency>
2- Rename it to eclipselink.jar.
3- Download JipiJapa EclipseLink Integration jar from Maven:
<dependency>
<groupId>org.jipijapa</groupId>
<artifactId>jipijapa-eclipselink</artifactId>
<version>1.0.1.Final</version>
</dependency>
4- Rename it to jipijapa_eclipselink.jar.
5- Create folder [JBOSS_HOME]\modules\org\eclipse\persistence\main.
6- Create module.xml in the same folder and paste the following into
it:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.eclipse.persistence">
<resources>
<resource-root path="eclipselink.jar" />
<resource-root path="jipijapa_eclipselink.jar" />
</resources>
<dependencies>
<module name="javax.api" />
<module name="javax.persistence.api" />
<module name="javax.transaction.api" />
<module name="javax.validation.api" />
<module name="javax.xml.bind.api" />
<module name="org.antlr" />
<module name="org.apache.commons.collections" />
<module name="org.dom4j" />
<module name="org.javassist" />
<module name="org.jboss.logging" />
<module name="javax.ws.rs.api"/>
</dependencies>
</module>
7- Copy eclipselink.jar and jipijapa_eclipselink.jar into the same folder.
B: Configure MSSQL with WildFly
1- Download MSSQL JDBC jar from Maven:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.5.2.jre8</version>
<scope>test</scope>
</dependency>
2- Rename it to mssql.jar.
3- Download SqlJdbc4 jar from Maven:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
4- Rename it to sqljdbc4.jar.
5- Create folder [JBOSS_HOME]\modules\com\microsoft\main.
6- Create module.xml in the same folder and paste the following into it:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.microsoft">
<resources>
<resource-root path="sqljdbc4.jar"/>
<resource-root path="mssql.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
7- Copy both mssql.jar and sqljdbc4.jar into the same folder.
8- Edit [JBOSS_HOME]\standalone\configuration\standalone.xml by adding the following datasource (search for <datasources> tag and insert the following datasource into it):
<datasource jta="true" jndi-name="java:jboss/MyDS" pool-name="MyDS" enabled="true" use-ccm="true">
<connection-url>jdbc:sqlserver://localhost:1433;databaseName=DBName</connection-url>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<driver>sqlserver</driver>
<security>
<user-name>username</user-name>
<password>password</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<timeout>
<set-tx-query-timeout>false</set-tx-query-timeout>
<blocking-timeout-millis>0</blocking-timeout-millis>
<idle-timeout-minutes>0</idle-timeout-minutes>
<query-timeout>0</query-timeout>
<use-try-lock>0</use-try-lock>
<allocation-retry>0</allocation-retry>
<allocation-retry-wait-millis>0</allocation-retry-wait-millis>
</timeout>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
9- Edit [JBOSS_HOME]\standalone\configuration\standalone.xml by adding the following driver (search for <datasources> tag, you will find a <drivers> tag inside, insert the following driver into it):
<driver name="sqlserver" module="com.microsoft">
<xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerXADataSource</xa-datasource-class>
</driver>
10- Add the following persistence unit into the persistence.xml file:
<persistence-unit name="my-persistence-unit" transaction-type="JTA">
<description>My Persistence Unit</description>
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:jboss/MyDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create" />
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.PostgreSQLPlatform" />
</properties>
</persistence-unit>
11- Don't forget to change the following values in steps '8' and '10' above accourding to your preferences: HostName, DBName, username, password, java:jboss/MyDS, my-persistence-unit.
12- You don't have to make any changes to your pom.xml file, here is mine:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jpa</groupId>
<artifactId>JPATest</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<finalName>JPATest</finalName>
</build>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
I am trying to publish secured SOAP server as a consuming endpoint at JBoss Fuse camel route.
I have the following endpoint and Jetty-security description in my Blueprint configuration:
...
<cxf:cxfEndpoint
xmlns:crm="http://www.bank.com/CRM"
id="crmOutboundService"
address="https://localhost:9001/cxf/CRMOutbound"
serviceName="crm:CRMOutboundRq"
endpointName="crm:ASBOCRMOutPort"
wsdlURL="model/ASBOCRMOut/CRMOutboundRq.wsdl"
serviceClass="com.bank.SAXSourceService">
<cxf:properties>
<entry key="dataFormat" value="PAYLOAD"/>
</cxf:properties>
</cxf:cxfEndpoint>
<httpj:engine-factory bus="cxf">
<httpj:engine port="9001">
<httpj:tlsServerParameters secureSocketProtocol="TLSv1">
<sec:keyManagers keyPassword="password">
<sec:keyStore type="JKS" password="password"
file="/opt/esb/security/keystore.jks"/>
</sec:keyManagers>
<sec:trustManagers>
<sec:keyStore type="JKS" password="password"
file="/opt/esb/security/truststore.jks"/>
</sec:trustManagers>
<sec:cipherSuitesFilter>
<sec:include>.*_WITH_3DES_.*</sec:include>
<sec:include>.*_WITH_DES_.*</sec:include>
<sec:exclude>.*_WITH_NULL_.*</sec:exclude>
<sec:exclude>.*_DH_anon_.*</sec:exclude>
</sec:cipherSuitesFilter>
<sec:clientAuthentication want="true" required="true"/>
</httpj:tlsServerParameters>
</httpj:engine>
</httpj:engine-factory>
...
Everything as in manual from here: https://access.redhat.com/documentation/en-us/red_hat_jboss_fuse/6.2/pdf/apache_cxf_security_guide/Red_Hat_JBoss_Fuse-6.2-Apache_CXF_Security_Guide-en-US.pdf
I have (among others) the following dependencies in pom.xml:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-blueprint</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
</dependency>
When application bundle is deployed into JBoss Fuse the following exception comes:
org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to load class org.eclipse.jetty.server.Connector from recipe MapRecipe[name='#recipe-11850']"
The questions are: why does such an error take place and what is the right way to establish secured SOAP server in JBoss Fuse?
We have ended up with adding the following directive into Blueprint descriptor:
<bean id="server" class="org.eclipse.jetty.server.Server"/>
The error has gone, and the application is working correctly, but we do not actually understand why, because there are no any references to the new bean. We are trying to figure out, if this directive starts new instance of Jetty server.
Learning Apache Camel-
Trying to deploy an application on jboss-fuse-6.1.0.redhat-379.
The POM is as follows
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dao</groupId>
<artifactId>camelDAO</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>bundle</packaging>
<properties>
<camel-version>2.13.0</camel-version>
</properties>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.17</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jdbc</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-sql</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<version>${camel-version}</version>
</plugin>
</plugins>
</build>
</project>
In database config file have configured the following
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/univ" />
<property name="username" value="root" />
<property name="password" value="pass" />
</bean>
<bean id="sqlComponent"
class="org.apache.camel.component.sql.SqlComponent">
<property name="dataSource" ref="dataSource" />
</bean>
and in route have made call to sql component
<to uri="sqlComponent:{{sql.insertData}}" />
while deploying on fuse getting-
Error executing command: Error starting bundles:
Unable to start bundle 255: Unresolved constraint in bundle
com.dao.came
lDAO [255]: Unable to resolve 255.0: missing requirement [255.0]
osgi.wiring.pac
kage; (&(osgi.wiring.package=org.apache.camel.component.sql)
(version>=2.13.0)(!(
version>=3.0.0))) [caused by: Unable to resolve 253.0: missing
requirement [253.
0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.camel)
(version>=2.13.0
)(!(version>=3.0.0)))]
Have installed the jars using wrap:install, still getting the above error
Kindly help me figure out. Thanks
Try to import missing packages:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Description>${project.description}</Bundle-Description>
<Import-Package>
*,
org.apache.camel.osgi,
org.apache.camel.component.sql,
org.apache.camel
</Import-Package>
</instructions>
</configuration>
</plugin>
And camel-sql feature must be installed.
UPDATED:
Have installed the jars using wrap:install
You need to do that only for database drivers, all other must be installed by features.
> <bean id="sqlComponent"
> class="org.apache.camel.component.sql.SqlComponent">
> <property name="dataSource" ref="dataSource" />
> </bean>
That can be implemented simpler:
<to uri="sql:{{sql.insertData}}?dataSource=dataSource" />
And please, check your Camel version, installed on jboss fuse server, it must match the one specified in your project.
You need to install Mysql Connector in Jboss Fuse.
For install we need to run the following statement in the Fuse terminal.
osgi:install -s wrap:mvn:mysql/mysql-connector-java/5.1.39
Version can be changed based on your mysql connector used.
Once after install. try to run your project.
I have a camel route fronted with a CXF Web Service consumer (from). I'm deploying in Glassfish 4.0 and this works fine when using the servlet spec 2.4. I now need to enhance the route by adding some persistence along the way which is being done with JPA. Doing this requires an upgrade to servlet spec 2.5+ (I've gone to 3.0)
When the servlet spec is changed to 2.5+ the following error occurs on deployment: java.lang.IllegalStateException: The lifecycle method [finalizeConfig] must not throw a checked exception. Most solutions to this say to remove cxf-rt-transports-http-jetty-2.7.11.jar.
When the jetty jar is removed, the deployment error becomes: java.io.IOException: Could not find destination factory for transport http://schemas.xmlsoap.org/soap/http
Solutions to this, such as CXF BusException No DestinationFactory for namespace http://cxf.apache.org/transports/http OR org.apache.cxf.BusException: No DestinationFactory was found for the namespace http://schemas.xmlsoap.org/soap/http/ say to import the cxf-servlet.xml file which then requires the inclusion of the jar cxf-rt-transports-http-2.7.11.jar (I removed this when I removed the jetty jar). Including these files then gives the following deployment error: java.io.IOException: Cannot find any registered HttpDestinationFactory from the Bus.
The solutions for this error all say to include the jar cxf-rt-transports-http-jetty-2.7.11.jar. This puts me back where I started having to remove it due to the servlet spec upgrade.
I've been able to create a small project to demonstrate this and have included the contents below. I've also tried deploying on Glassfish 4.1 and various combinations of different jar versions (CXF 3.0 excluding the 2.7 jars from camel etc) but I'm still unable to deploy the app in Glassfish.
I'm able to run this with the maven camel plugin 'mvm camel:run' (this requires de-scoping the cxf-rt-transports-http*.jar files from test. Of course this works because I'm outside the glassfish container.
Any help would be greatly appreciated.
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>camel-cxf-gf</artifactId>
<packaging>war</packaging>
<version>0.1</version>
<name>Camel with CXF in GF</name>
<properties>
<camel-version>2.13.1</camel-version>
<cxf-version>2.7.11</cxf-version>
<buildNumber>0.1</buildNumber>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- cxf using slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
<!-- using Jetty with CXF -->
<!-- "The Google" says to exclude this when deploying to Glassfish (test scope only) -->
<!-- To run with mvn camel:run, comment out the test scope on BOTH cxf-rt dependencies -->
<!-- However, if present for GF deploy, you get the error: The lifecycle method [finalizeConfig] must not throw a checked exception -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf-version}</version>
<scope>test</scope>
</dependency>
<!-- "The Google" says to exclude this (test scope only) -->
<!-- To run with mvn camel:run, comment out the test scope on BOTH cxf-rt dependencies -->
<!-- If present for GF deploy, you get the error: java.io.IOException: Cannot find any registered HttpDestinationFactory from the Bus -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- allows the route to be executed via 'mvn camel:run', NOTE: must comment out the test scope on the cxf-rt-transports dependencies above.... -->
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<version>${camel-version}</version>
<configuration>
<fileApplicationContextUri>
classpath:META-INF/applicationContext.xml
</fileApplicationContextUri>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<webXml>web/WEB-INF/web.xml</webXml>
<failOnMissingWebXml>true</failOnMissingWebXml>
<archive>
<manifestEntries>
<Build-Version>${project.version}</Build-Version>
<Build-Revision>${buildNumber}</Build-Revision>
<Build-Date>${maven.build.timestamp}</Build-Date>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>Camel CXF, JMS Web Application</display-name>
<!-- location of spring xml files -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/applicationContext.xml</param-value>
</context-param>
<!-- the listener that kick-starts Spring -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
The CXF Service:
package com.example;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
#WebService(serviceName = "HelloMessage", targetNamespace = "http://example.com/")
public interface HelloMessageEndpoint {
#WebMethod(operationName = "sayHello")
#WebResult(name = "messageAnswer", targetNamespace = "http://example.com/", partName = "messageAnswer")
public String sayHello(#WebParam(name = "name") String name);
}
My applicationContext.xml which contains the Spring DSL camel route (under resources/META-INF):
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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://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"/>
<!-- This doesn't seem to make a difference -->
<!--<import resource="classpath:META-INF/cxf/cxf-extension-camel.xml"/>-->
<!-- When cxf-rt-transports-http is removed (test scope) cxf-servlet.xml is no longer available -->
<!--<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>-->
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<cxf:cxfEndpoint id="helloMessageEndpoint"
address="http://0.0.0.0:9000/HelloWS/"
serviceClass="com.example.HelloMessageEndpoint"
endpointName="HelloMessageEndpoint"
serviceName="HelloMessage"
loggingFeatureEnabled="false"/>
<camelContext id="messageContext" streamCache="true" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="cxf:bean:helloMessageEndpoint"/>
<log loggingLevel="INFO" message="====> CXF Message Body: ${body}"/>
</route>
</camelContext>
</beans>
As you are using address="http://0.0.0.0:9000/HelloWS/", not the relative path, cxf-rt-transports-http-jetty-2.7.11.jar is need. If you want to use the servlet transport you need to deploy the CXFServlet in you web.xml first, and setup the address of to be relative path, then you should be able to access the CXF endpoint there.
Using the Google Eclipse Plugin, my project automatically comes with two files inside the META-INF folder: jdoconfig.xml and persistence.xml. Per the instructions on https://developers.google.com/appengine/docs/java/datastore/jpa/overview, my persistence file is supposed to have the following line for jpa datastore storage:
<provider>org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider</provider>
But when I open the persistence file I found
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="transactions-optional">
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
<properties>
<property name="datanucleus.NontransactionalRead" value="true"/>
<property name="datanucleus.NontransactionalWrite" value="true"/>
<property name="datanucleus.ConnectionURL" value="appengine"/>
</properties>
</persistence-unit>
</persistence>
and the jdoconfig.xml file is
<?xml version="1.0" encoding="utf-8"?>
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">
<persistence-manager-factory name="transactions-optional">
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory"/>
<property name="javax.jdo.option.ConnectionURL" value="appengine"/>
<property name="javax.jdo.option.NontransactionalRead" value="true"/>
<property name="javax.jdo.option.NontransactionalWrite" value="true"/>
<property name="javax.jdo.option.RetainValues" value="true"/>
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
</persistence-manager-factory>
</jdoconfig>
With those default contents, JPA has not been saving to my datastore. So I edit the persistence.xml file to look like this
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="transactions-optional">
<provider>org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider</provider>
<properties>
<property name="datanucleus.NontransactionalRead" value="true"/>
<property name="datanucleus.NontransactionalWrite" value="true"/>
<property name="datanucleus.ConnectionURL" value="appengine"/>
</properties>
</persistence-unit>
</persistence>
How should I change the jdoconfig.xml file? Right now, with my changes to persistence but jdoconfig as is, I am getting a huge error trace.
redacted error:
java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestricted(RuntimeHelper.java:70)
at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:64)
…
…
...
Caused by: javax.persistence.PersistenceException: No persistence providers available for "transactions-optional" after trying the following discovered implementations: org.datanucleus.api.jpa.PersistenceProviderImpl
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:180)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:70)
For JPA 2.0 The provider is org.datanucleus.api.jpa.PersistenceProviderImpl Please note that persistence.xml is the configuration file used by JPA and jdoconfig.xml is used if you want to use JDO.
You first need to decide what persistence mechanism you want to use, I would assume its JPA so in fact, you can delete jdoconfig.xml.
With that been said, make sure all the reguired libs for Datanucleus is in your CLASSPATH and most importantly, persisence.xml must be in the ROOT of your CLASSPATH.
I have added a picture of the lib needed for a successful JPA 2 / Datanucleus persitence.
Also make sure your enhancer is correctly configured.
FYI: I could never get Google Eclipse Plugin to work with JPA 2, the entity enhancements never worked so I used maven. There are several ways to enhance your classes and maven is one.
Here is my pom.
<properties>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.5.0</gwtVersion>
<gxtVersion>2.2.5</gxtVersion>
<gae.version>1.7.5</gae.version>
<datanucleus.version>3.1.3</datanucleus.version>
<!-- GWT needs at least java 1.5 -->
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- DN -->
<dependency>
<groupId>com.google.appengine.orm</groupId>
<artifactId>datanucleus-appengine</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>${datanucleus.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jpa</artifactId>
<version>${datanucleus.version}</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jdo</artifactId>
<version>${datanucleus.version}</version>
</dependency>
<dependency>
<groupId>javax.jdo</groupId>
<artifactId>jdo-api</artifactId>
<version>3.0.1 </version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jpa_2.0_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-jsr107cache</artifactId>
<version>${gae.version}</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-endpoints</artifactId>
<version>${gae.version}</version>
</dependency>
<dependency>
<groupId>net.sf.jsr107cache</groupId>
<artifactId>jsr107cache</artifactId>
<version>1.1</version>
</dependency>
For the enhancements, add the following to plugins section of your pom:
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>maven-datanucleus-plugin</artifactId>
<version>${datanucleus.version}</version>
<configuration>
<api>JPA</api>
<verbose>true</verbose>
<mappingIncludes>**/entity/*.class</mappingIncludes>
<fork>false</fork>
<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
Change <mappingIncludes>**/entity/*.class</mappingIncludes> to the package where your entities are placed.
In my own case, DataNucleus Enhancer will look for classes to enhance in package/folder named entity.
Good luck
Babajide