Add CORSHandler to a camel-jetty component - proxy

I need to add the following CORSHandler to a camel-jetty component.
public class CORSHandler extends AbstractHandler
{
#Override
public void handle(String arg0, Request arg1, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
System.out.println("GOT REQUEST!!!!!!!");
if(request.getMethod().equals("OPTIONS")){
System.out.println("CORSFilter HTTP Request BS: " + request.getMethod());
// Authorize (allow) all domains to consume the content
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Allow-Methods","GET, OPTIONS, HEAD, PUT, POST");
response.addHeader("Access-Control-Allow-Headers","Authorization");
// For HTTP OPTIONS verb/method reply with ACCEPTED status code -- per CORS handshake
if (request.getMethod().equals("OPTIONS")) {
response.setStatus(HttpServletResponse.SC_ACCEPTED);
arg1.setHandled(true);
}
}
}
}
I'm trying the following way,
from("jetty:http://0.0.0.0:8082/proxy?disableStreamCache=true&matchOnUriPrefix=true&enableMultipartFilter=false&handlers=#corsHandler")
.to("jetty:http://localhost:8085/myWebApp/foo?bridgeEndpoint=true&throwExceptionOnFailure=false&traceEnabled=true")
.to("log:MyLogger?level=INFO&showAll=true");
Following is my camel-context.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:camel="http://camel.apache.org/schema/spring"
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-2.0.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean class="com.abccom.route.CloudServiceRoute" id="cloudServiceRoute"/>
<bean class="com.abccom.CORSHandler" id="corsHandler"/>
<camelContext id="esbConsoleCamelContext" xmlns="http://camel.apache.org/schema/spring">
<routeBuilder ref="cloudServiceRoute"/>
</camelContext>
</beans>
I'm getting the following exception upon deployment.
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: jetty://http://0.0.0.0:8082/proxy?disableStreamCache=true&enableMultipartFilter=false&handlers=%23corsHandler&matchOnUriPrefix=true due to: No bean could be found in the registry for: corsHandler of type: java.lang.Object
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:723)
at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:80)
at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:219)
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:112)
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:118)
at org.apache.camel.model.FromDefinition.resolveEndpoint(FromDefinition.java:69)
at org.apache.camel.impl.DefaultRouteContext.getEndpoint(DefaultRouteContext.java:94)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1278)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:204)
Any info on how should I configure the CORSHandler for the camel-jetty component?
Following is my pom.xml
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.abccom</groupId>
<artifactId>console-service-esb</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<name>WildFly Camel CDI Application</name>
<url>http://www.myorganization.org</url>
<!-- Properties -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- WildFly versions -->
<version.wildfly>10.1.0.Final</version.wildfly>
<!-- Other versions -->
<version.apache.camel>2.19.3</version.apache.camel>
<version.junit>4.12</version.junit>
<!-- Plugin versions -->
<version.maven.compiler.plugin>3.1</version.maven.compiler.plugin>
<version.maven.surefire.plugin>2.18.1</version.maven.surefire.plugin>
<version.maven.war.plugin>3.0.0</version.maven.war.plugin>
<version.wildfly.maven.plugin>1.2.0.Final</version.wildfly.maven.plugin>
<!-- maven-compiler-plugin -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- Arquillian application server properties -->
<jboss.home>${env.JBOSS_HOME}</jboss.home>
<server.config>standalone-camel.xml</server.config>
</properties>
<!-- DependencyManagement -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.wildfly.camel</groupId>
<artifactId>wildfly-camel-bom</artifactId>
<version>4.9.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<!-- Dependencies -->
<dependencies>
<!-- Provided -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cdi</artifactId>
<version>${version.apache.camel}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-restlet</artifactId>
<version>${version.apache.camel}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jetty</artifactId>
<version>${version.apache.camel}</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.2_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_1.1_spec</artifactId>
<version>1.0.1.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-git</artifactId>
<version>${version.apache.camel}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jasypt</artifactId>
<version>${version.apache.camel}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.5</version>
</dependency>
<!--HTTP camel component dependency -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http</artifactId>
<version>${version.apache.camel}</version>
</dependency>
</dependencies>
<!-- Build-->
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.maven.compiler.plugin}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${version.maven.war.plugin}</version>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
<configuration>
<version>${version.wildfly}</version>
<serverConfig>${server.config}</serverConfig>
</configuration>
</plugin>
</plugins>
</build>
<!-- Profiles -->
<profiles>
<profile>
<!-- The default profile skips all tests, though you can tune it to run just unit tests based on a custom pattern -->
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.maven.surefire.plugin}</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<!-- Repositories -->
<repositories>
<repository>
<id>jboss-public-repository</id>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>
</project>
Following is my web.xml
<web-app>
<servlet>
<display-name>Camel Http Transport Servlet</display-name>
<servlet-name>CamelServlet</servlet-name>
<servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CamelServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>

Related

Spring and Jersey rest api returned 404

i tried to make rest api with spring and jersey.
this is my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Jersey Spring Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Spring Web Application</servlet-name>
<url-pattern>/FjordRestApi/*</url-pattern>
</servlet-mapping>
</web-app>
and this is my service file:
package com.persistent.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.persistent.entity.User;
import com.persistent.entity.UsersList;
#Path("/us")
#Component
public class UsersService {
#Autowired
SessionFactory sessionFactory;
#GET
#Transactional
#Path("/getUsers")
#Produces("application/json")
#SuppressWarnings("unchecked")
public UsersList getUsers() {
final Session session = sessionFactory.getCurrentSession();
final Criteria criteria = session.createCriteria(User.class);
criteria.add(Restrictions.eq("risk", 1));
return new UsersList(criteria.list());
}
}
when i used ServletRunner with the method getResponse
like this:
public void testFoo() {
WebResponse response;
try {
response = getClient().getResponse("http://localhost:8282/FjordRestApi/us/getUsers");
System.out.println(response.getText());
} catch (Exception e) {
e.printStackTrace();
}
}
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.persistent</groupId>
<artifactId>FjordRestApi</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>FjordRestApi</name>
<build>
<!-- <finalName>jerseySpringJPA</finalName> -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<inherited>true</inherited>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.1.5.v20100705</version>
<configuration>
<webApp>${project.build.directory}/${project.build.finalName}.war</webApp>
<!--<systemPropertiesFile>${build.testOutputDirectory}/change-service.properties</systemPropertiesFile> -->
<stopPort>9966</stopPort>
<stopKey>foo</stopKey>
<webAppConfig>
<!--<contextPath>/v1</contextPath> -->
</webAppConfig>
<systemProperties>
<systemProperty>
<name>database.properties</name>
<value>file:${project.basedir}/target/test-classes/database.properties</value>
</systemProperty>
<systemProperty>
<name>jetty.port</name>
<value>${jetty.port}</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
<jersey.version>1.1.4.1</jersey.version>
<!-- Avoids MacRoman encoding on OSX -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<jetty.port>8282</jetty.port>
</properties>
<dependencies>
<!-- Unit Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8</version>
</dependency>
<dependency>
<groupId>httpunit</groupId>
<artifactId>httpunit</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.test</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<!-- Jersey -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>${jersey.version}</version>
<!-- These exclusions keep jersey-spring dependencies on spring 2.0 from
getting resolved by maven -->
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.web</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.transaction</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.context</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.orm</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.8.0.GA</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.0.Final</version>
</dependency>
<!-- In Memory Database -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
</dependency>
<!-- Jersey Support for JSON -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- This is LAST for a reason, dbunit dependencies load older versions
of log4j which causes issues with spring bean loader -->
<dependency>
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
<version>2.4.8</version>
</dependency>
<!-- My favorite java library -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>r08</version>
</dependency>
</dependencies>
<repositories>
<!-- Jersey Official Maven Repo -->
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for maven</name>
<url>http://download.java.net/maven/2/</url>
</repository>
<!-- Spring Official Maven Repo -->
<repository>
<id>com.springsource.repository.bundles.release</id>
<name>EBR Spring Release Repository</name>
<url>http://repository.springsource.com/maven/bundles/release</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.external</id>
<name>EBR External Release Repository</name>
<url>http://repository.springsource.com/maven/bundles/external</url>
</repository>
<!-- Hibernate Official Maven Repo -->
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>
</project>
its returned the correct json text but when i went to the url directly i got 404 error, such as when i run postman get request i got 404 error page.
the console not showing anything when i did above steps.
what can i do?
tnx a lot
I think your configurations needs to add init-param for jersey ( depends on your version of jersey ofcourse ) .
try to add :
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>
com.sun.jersey.spi.spring.container.servlet.SpringServlet
</servlet-class>
<init-param>
<param-name>
com.sun.jersey.config.property.packages
</param-name>
<param-value>your package</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
I advice you to read the docs of jersey for the providers config
,if doesn't work ( depends on jersey version, try to change
com.sun.jersey.config.property.packages
by
jersey.config.server.provider.packages

Spring Boot 1.5.1 MongoDB connection Error

Hi I am not able to connect to MongoDB using Spring Boot 1.5.1.
Any suggestions are appreciated.
Below is my Application.properties file.
server.port = 9026
spring.data.mongodb.uri=mongodb://username:password#primaryurl:32020,secondaryurl:32020/name?replicaSet=name&connectTimeoutMS=300000
spring.data.mongodb.authentication-database=admin
logging.file = configDD-service.log
Here is my error mesaage:
No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=MULTIPLE,
serverDescriptions=[ServerDescription{address=zlp14853.vci.att.com:32020, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException:
Exception authenticating MongoCredential{mechanism=null, userName='vtmUsr', source='vtm', password=<hidden>, mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException:
Command failed with error 18: 'Authentication failed.' on server zlp14853.vci.att.com:32020. The full response is { "ok" : 0.0, "code" : 18, "errmsg" : "Authentication failed." }}},
ServerDescription{address=zlp14852.vci.att.com:32020, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException:
Exception authenticating MongoCredential{mechanism=null, userName='vtmUsr', source='vtm', password=<hidden>, mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException:
Command failed with error 18: 'Authentication failed.' on server zlp14852.vci.att.com:32020. The full response is { "ok" : 0.0, "code" : 18, "errmsg" : "Authentication failed." }}}]}.
Waiting for 30000 ms before timing out
Parent POM.xml
<?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>com.att.vtm</groupId>
<artifactId>configdd</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>configdd</name>
<description>configdd Management</description>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>configdd-dao-adapter</module>
<module>configdd-service</module>
</modules>
</project>
Module 1 pom.xml.
<?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">
<parent>
<groupId>com.att.vtm</groupId>
<artifactId>configdd</artifactId>
<version>1.0</version>
<relativePath>..</relativePath>
</parent>
<groupId>com.att.vtm</groupId>
<version>1.0</version>
<modelVersion>4.0.0</modelVersion>
<artifactId>configdd-dao-adapter</artifactId>
<name>configdd-daoadapter</name>
<description>configdd Dao Adapter</description>
<dependencies>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<!-- <version>1.8.4.RELEASE</version> -->
<exclusions>
<exclusion>
<artifactId>mongo-java-driver</artifactId>
<groupId>org.mongodb</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</execution>
</executions>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- Make a jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Module 2 POM.xml.
<?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>
<parent>
<groupId>com.att.vtm</groupId>
<artifactId>configdd</artifactId>
<version>1.0</version>
<relativePath>..</relativePath>
</parent>
<artifactId>configdd-service</artifactId>
<version>1.0</version>
<name>configdd-service</name>
<description>configdd Service</description>
<!-- <dependencyManagement>-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency> -->
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>com.att.vtm</groupId>
<artifactId>configdd-dao-adapter</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
<version>2.4.5</version>
</dependency>
<!-- <dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency> -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.2.2</version>
<scope>compile</scope>
</dependency>
<!-- <dependency>
<groupId>com.att.vtm</groupId>
<artifactId>cbus-soap-adapter</artifactId>
<version>1.0</version>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>com.att.Application</start-class>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.2.3.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<skipTests>true</skipTests>
<jvmArgs>-Xmx2048m -Xms1536m -XX:PermSize=512m -XX:MaxPermSize=1024m</jvmArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
I was able to connect using this connection string:
spring.data.mongodb.uri=mongodb://username:password#primaryurl:32020,secondaryurl:32020/name?replicaSet=name&connectTimeoutMS=300000
The replica set name is mandoary in the connection string.

JPA does not return any data from CloudSQL

I have project based on maven for deployment on GoogleAppEngine. I have local MySQL DB (for development) and remote CloudSQL DB (for production)
My code is based on google github
Data inside CloudSQL and MySQL are identical. I have a problem when trying to retrieve data via named query on production - list of size 0 is returned. On local MySQL DB code returns data correctly. I even tried to retrieve data from ClodSQL using standard java.sql.Connection and I was able to retrieve data. No data are returned only when requested from JPA.
Named query used:
#NamedQueries({(name = "Device.getDevices", = "SELECT d FROM Device d")
my persistence.xml
<?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-device">
<class>commander.apprecorder.database.pojos.device.Device</class>
<properties>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="datanucleus.autoCreateSchema" value="true"/>
</properties>
</persistence-unit>
</persistence>
Content of pom.xml
<?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>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<groupId>group</groupId>
<artifactId>art</artifactId>
<properties>
<app.id>appid</app.id>
<app.version>version</app.version>
<appengine.version>1.9.30</appengine.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<gcloud.plugin.version>2.0.9.74.v20150814</gcloud.plugin.version>
<objectify.version>5.1.5</objectify.version>
<guava.version>18.0</guava.version>
<datanucleus.jpa.version>3.1.1</datanucleus.jpa.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
<cloudsql.device.url>
jdbc:google:mysql://some:instance:name/db?user=xxx
</cloudsql.device.url>
<cloudsql.device.url.dev>jdbc:mysql://localhost/db?user=x</cloudsql.device.url.dev>
<datanucleus-core.version>4.0.0-release</datanucleus-core.version>
<datanucleus-maven-plugin.version>4.0.0-release</datanucleus-maven-plugin.version>
<datanucleus-accessplatform-jpa-rdbms.version>4.0.0-release</datanucleus-accessplatform-jpa-rdbms.version>
<javax.persistence.version>2.1.0</javax.persistence.version>
</properties>
<prerequisites>
<maven>3.1.0</maven>
</prerequisites>
<dependencies>
<!-- Compile/runtime dependencies -->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>${appengine.version}</version>
</dependency>
<dependency>
<groupId>com.google.appengine.tools</groupId>
<artifactId>appengine-gcs-client</artifactId>
<version>0.5</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20151123</version>
</dependency>
<!--JPA start -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.25</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-accessplatform-jpa-rdbms</artifactId>
<version>${datanucleus-accessplatform-jpa-rdbms.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>javax.persistence</artifactId>
<version>${javax.persistence.version}</version>
</dependency>
<!--JPA end -->
<!-- [START Objectify_Dependencies] -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>com.googlecode.objectify</groupId>
<artifactId>objectify</artifactId>
<version>${objectify.version}</version>
</dependency>
<!-- [END Objectify_Dependencies] -->
<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>2.0.2-beta</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>${appengine.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>${appengine.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- for hot reload of the web application-->
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>display-dependency-updates</goal>
<goal>display-plugin-updates</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>3.2</version>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
<dependencies>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>${datanucleus-core.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<archiveClasses>true</archiveClasses>
<webResources>
<!-- in order to interpolate version from pom into appengine-web.xml -->
<resource>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.version}</version>
<configuration>
<enableJarClasses>false</enableJarClasses>
<version>${app.version}</version>
<!-- Comment in the below snippet to bind to all IPs instead of just localhost -->
<!-- address>0.0.0.0</address>
<port>8080</port -->
<!-- Comment in the below snippet to enable local debugging with a remote debugger
like those included with Eclipse or IntelliJ -->
<!-- jvmFlags>
<jvmFlag>-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n</jvmFlag>
</jvmFlags -->
</configuration>
</plugin>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>gcloud-maven-plugin</artifactId>
<version>${gcloud.plugin.version}</version>
<configuration>
<set_default>true</set_default>
</configuration>
</plugin>
<!--DB start-->
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-maven-plugin</artifactId>
<version>${datanucleus-maven-plugin.version}</version>
<configuration>
<api>JPA</api>
<persistenceUnitName>transactions-optional-device</persistenceUnitName>
<fork>false</fork>
<!--<persistenceUnitName>Demo</persistenceUnitName>-->
<!--<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>-->
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>${datanucleus-core.version}</version>
</dependency>
</dependencies>
</plugin>
<!--JPA end-->
</plugins>
</build>
And servlet for JPA
#Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/plain");
Map<String, String> properties = new HashMap();
if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
properties.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.GoogleDriver");
properties.put("javax.persistence.jdbc.url", System.getProperty("cloudsql.device.url"));
} else {
properties.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver");
properties.put("javax.persistence.jdbc.url", System.getProperty("cloudsql.device.url.dev"));
}
// List all the rows.
EntityManagerFactory emf = Persistence.createEntityManagerFactory(
"transactions-optional-device", properties);
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
resp.getWriter().println("performing query");
List<Device> result = em.createNamedQuery("Device.getDevices", Device.class).getResultList();
resp.getWriter().println("Starting to list devices - " + result.size());
for (Device g : result) {
resp.getWriter().println(g.getA() + "_" + g.getB());
}
em.getTransaction().commit();
em.close();
}
There is no error inside app engine log. Can you please tell me what is wrong? Thanks :)
I set log level to ALL and found out that Datanucleus was trying to access datastore. It created new table inside datastore and retrieved its content - no data.
I have no idea why it was trying to access datastore and was not using CloudSQL, but nevermind...
I replaced DataNucles for Hibernate by tutorial inside google github and it worked on first time
Migration was easy, only persistance.xml and pom.xml had to be modified.

what's contain ${Session.resources} in applicationContext?

i'm trying to understand this applicationContex:
<tx:annotation-driven/>
<!-- Definició dels beans de sessió i usuari -->
**<import resource="${session.resources}" />**
<!-- Definició dels beans del subjecte anònim -->
${session.subjecteanonim}
<!-- Integració amb BASE OnLine -->
<import resource="classpath:bf-modul-baseonline-appConfiguration.xml" />
<import resource="classpath:gim.logica-context.xml" />
<!-- Serveis de lògica de negoci proporcionats per base
<jee:remote-slsb id="serveiMestreMunicipiEns"
business-interface="cat.base.mestres.servei.IServeiMestreMunicipiEns"
jndi-name="${cat.base.mestre.municipi.ens.service.name}">
<jee:environment>
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=${cat.base.mestre.municipi.ens.jndi.url}
java.naming.provider.port=${cat.base.mestre.municipi.ens.jndi.port}
</jee:environment>
</jee:remote-slsb>
-->
so, my problem is that I don't know where is defined ${session.resources}, and what can i have inside? is from jsf?I hope you apologize for my strnge english, ty.
ztb.
this is the parent's pom:
http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
<groupId>cat.base</groupId>
<artifactId>gim</artifactId>
<version>0.0.2-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>cat.base.baseframe</groupId>
<artifactId>projecte-pare-baseframe</artifactId>
<version>0.0.11.a</version>
</parent>
<modules>
<module>gim.assistent</module>
</modules>
<properties>
<project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>cat.base</groupId>
<artifactId>mme.domini</artifactId>
<version>1.3.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
and this i the pom's application
http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
<parent>
<groupId>cat.base</groupId>
<artifactId>gim</artifactId>
<version>0.0.2-SNAPSHOT</version>
</parent>
<artifactId>gim.assistent</artifactId>
<packaging>war</packaging>
<name>Assistent d'Expedients GIM</name>
<build>
<finalName>gim.assistent.${profile.entorn}</finalName>
<resources>
<resource>
<directory>./</directory>
<includes>
<include>change.log</include>
</includes>
</resource>
<resource>
<directory>src/main/resources/</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>src\main\webapp\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- domini, servei deps. -->
<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-ejb3x</artifactId>
<version>4.2.3.GA</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.2.1.ga</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-annotations-ejb3</artifactId>
<version>4.2.3.GA</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.client</groupId>
<artifactId>jbossall-client</artifactId>
<version>EAP-4.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<!-- test deps. -->
<dependency>
<groupId>com.ibm.informix</groupId>
<artifactId>ifxjdbc</artifactId>
<version>2.21.JC2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
<!-- ui deps. -->
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>org.springframework.js</artifactId>
<version>2.0.5.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>org.springframework.faces</artifactId>
<version>2.0.5.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>org.springframework.binding</artifactId>
<version>2.0.5.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>org.springframework.webflow</artifactId>
<version>2.0.5.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>1.2_10</version>
<scope>provided</scope>
</dependency>
</dependencies>
<!-- PERFILS DE CONSTRUCCIÓ -->
<profiles>
<!-- PERFIL CIUTADA -->
<profile>
<id>ciutada</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
<includes>
<include>**/applicationContext.xml</include>
<include>**/web.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<profile.entorn>ciutada</profile.entorn>
<session.resources>classpath:bf-modul-session-bd-jbosscache-appConfiguration.xml</session.resources>
<session.postproces>classpath*:bf-modul-session-bd.properties</session.postproces>
<session.subjecteanonim>
<![CDATA[
<import resource="classpath:bf-modul-subjecte-anonim-appConfiguration.xml" />
]]>
</session.subjecteanonim>
<webxml.module.filter>cat.base.baseframe.modules.login.session.bd.BaseSessionLoginJBossCacheFilter</webxml.module.filter>
<webxml.module.listener>cat.base.baseframe.modules.login.session.bd.BaseSessionHttpSessionEventListener</webxml.module.listener>
<webxml.login.config>
<![CDATA[
<login-config>
<auth-method>CLIENT-CERT</auth-method>
</login-config>
]]>
</webxml.login.config>
<webxml.subjecte.anonim.filter>
<![CDATA[
<filter>
<filter-name>SubjecteAnonimFilter</filter-name>
<filter-class>cat.base.baseframe.modules.anonim.filtre.SubjecteAnonimFilter</filter-class>
<init-param>
<param-name>acceptaAnonims</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SubjecteAnonimFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
]]>
</webxml.subjecte.anonim.filter>
</properties>
</profile>
<!-- PERFIL EMPLEAT -->
<profile>
<id>empleat</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
<includes>
<include>**/applicationContext.xml</include>
<include>**/web.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<profile.entorn>empleat</profile.entorn>
<session.resources>classpath*:bf-modul-session-ldap-jbosscache-appConfiguration.xml</session.resources>
<session.postproces>classpath*:bf-modul-session-ldap.properties</session.postproces>
<session.subjecteanonim/>
<webxml.module.filter>cat.base.baseframe.modules.login.session.ldap.BaseSessionLoginJBossCacheFilter</webxml.module.filter>
<webxml.module.listener>cat.base.baseframe.modules.login.session.ldap.BaseSessionHttpSessionEventListener</webxml.module.listener>
<webxml.login.config>
<![CDATA[
<login-config>
<auth-method>FORM</auth-method>
<realm-name>BaseRealm</realm-name>
<form-login-config>
<form-login-page>/security/login-page.jsp</form-login-page>
<form-error-page>/security/login-error.jsp</form-error-page>
</form-login-config>
</login-config>
]]>
</webxml.login.config>
<webxml.subjecte.anonim.filter />
</properties>
</profile>
</profiles>
Ok ! i find a way to understand!
this variables are defined at pom anf do reference to maven profile a way to aunthenticate.
<session.resources>classpath:bf-modul-session-bd-jbosscacheappConfiguration.xml</session.resources>
I felt like a stupid monkey.
ztb

Need an example POM file for running a Pentaho kitchen/pan transformation and job during the integration test phase

I have spent too many hours on Google and on the Pentaho forums looking for a simple example for what I would think would be common use case. I am asking fellow SE folks to help answer this question.
I have a project which is a mixture of Java and Pentaho ETL jobs. We would like to build, test, and deploy both types of projects using maven 3.
I am looking for an example POM that will execute the transformations and jobs (using kitchen/pan, I assume) during the integration test phase. In addition, if possible,
an example of what you are doing to test the kettle jobs within the database (e.g. DBunit). So far here is what I have for information.
The user docs for kitchen which shows how to run a job on the command line in batch file: http://wiki.pentaho.com/display/EAI/Kitchen+User+Documentation
The user docs for PAN which shows how to run a transformation on the command line in batch file: http://wiki.pentaho.com/display/EAI/Pan+User+Documentation
While I could use exec plugin(http://mojo.codehaus.org/exec-maven-plugin/) to execute a batch file which invokes kitchen and pan, that seems like a hack at best. I am looking for a more "native" maven approach
A work in progress POM file:
<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>pentaho-example</groupId>
<artifactId>pentaho-example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>pentaho-example</name>
<!--
required by pentaho stuff to bring in the needed jars to run via
command line for testing
-->
<repositories>
<repository>
<releases>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<id>pentaho-repo</id>
<url>http://repo.pentaho.org/artifactory/pentaho/</url>
</repository>
<repository>
<id>pentaho-third-party</id>
<url>http://repo.pentaho.org/artifactory/third-party/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.7</version>
</dependency>
<dependency>
<groupId>org.pentaho</groupId>
<artifactId>core</artifactId>
<version>4.2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>project</descriptorRef>
</descriptorRefs>
<!--
<descriptors> <descriptor>src/assemble/etl-only.xml</descriptor>
</descriptors>
-->
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Does anyone have more information or an example POM to show how this can be done?
TIA,
Scott
<?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>module-groupId</groupId>
<artifactId>module-artifact-id</artifactId>
<version>2.4.6-SNAPSHOT</version>
<packaging>pom</packaging>
<name>module-name</name>
<modules>
<module>...</module>
<module>...</module>
<module>...</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<eula-wrap_create-dist-phase />
<eula-wrap_assign-deps-to-properties-phase />
<mockito.version>1.10.19</mockito.version>
<pentaho-metadata.version>7.1.0.0-12</pentaho-metadata.version>
<eula-wrap_create-izpack-installer-jar-phase />
<pdi.version>7.1.0.0-12</pdi.version>
<eula-wrap_attach-dist-phase />
<junit.version>4.12</junit.version>
<jersey.version>1.19.1</jersey.version>
<jsr311-api.version>1.1.1</jsr311-api.version>
</properties>
<dependencies>
<!-- https://public.nexus.pentaho.org/content/groups/omni/ -->
<dependency>
<groupId>pentaho</groupId>
<artifactId>mondrian</artifactId>
<version>3.12.0.1-196</version>
</dependency>
<!-- https://public.nexus.pentaho.org/content/groups/omni/ -->
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-core</artifactId>
<version>${pdi.version}</version>
<exclusions>
<exclusion>
<artifactId>xercesImpl</artifactId>
<groupId>xerces</groupId>
</exclusion>
<exclusion>
<artifactId>commons-httpclient</artifactId>
<groupId>commons-httpclient</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-engine</artifactId>
<version>${pdi.version}</version>
</dependency>
<!--<dependency>
<groupId>org.pentaho.di.plugins</groupId>
<artifactId>pdi-core-plugins-impl</artifactId>
<version>${pdi.version}</version>
</dependency> -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.9.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>*</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/xml-apis/xml-apis -->
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>25.0-jre</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.quartz-scheduler/quartz -->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-math3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.11.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-compress -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.18</version>
</dependency>
</dependencies>
<!-- Build Settings -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<tagNameFormat>v#{project.version}</tagNameFormat>
<autoVersionSubmodules>true</autoVersionSubmodules>
<releaseProfiles>releases</releaseProfiles>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>releases</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Java example
import java.util.logging.Level;
import java.util.logging.Logger;
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.job.Job;
import org.pentaho.di.job.JobMeta;
import org.pentaho.di.repository.Repository;
public class KettleJobExec {
private static final Logger logger = Logger.getLogger(KettleJobExec.class.getName());
public static void runJob(String jobPath) {
try {
//System.setProperty("KETTLE_HOME",PropertyManager.getInstance().getPropertyAsString(Constantes.KETTLE_HOME));
Repository repository = null;
logger.log(Level.INFO, "Kettle enviroment init");
KettleEnvironment.init(false);
logger.log(Level.INFO, "JobMeta creation: " + jobPath);
JobMeta jobMeta = new JobMeta(jobPath, repository);
logger.log(Level.INFO, "Job creation");
Job job = new Job(repository, jobMeta);
logger.log(Level.INFO, "Job start");
job.start();
logger.log(Level.INFO, "Job wait until finished");
job.waitUntilFinished();
if (job.getErrors() > 0) {
throw new Exception("Error Executing Job: " + job.getStatus());
}
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);
} finally {
logger.log(Level.INFO, "Kettle enviroment shutdown");
KettleEnvironment.shutdown();
}
}
}

Resources