Spring Rest Docs - How to obtain simple HTTP GET from SpringMVC app - spring

Am new to Spring Rest Docs... Have a preexisting codebase what was written in Spring MVC (not Spring Boot).
Some excerpts from my pom.xml looks as following:
<properties>
<snippetsDirectory>${project.build.directory}/generated-snippets</snippetsDirectory>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<version>1.2.1.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<includes>
<include>**/*Documentation.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>prepare-package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html</backend>
<doctype>book</doctype>
<sourceDocumentName>index.adoc</sourceDocumentName>
<attributes>
<snippets>${snippetsDirectory}</snippets>
</attributes>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-asciidoctor</artifactId>
<version>1.2.1.RELEASE</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/static/docs</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/generated-docs</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Have a sample web service (using SpringMVC) which issues a simple GET request:
package com.myapp.rest.controllers;
#Controller
#RequestMapping("/v2")
public class MyController {
#RequestMapping(value="users/{userId}",method=RequestMethod.GET)
public #ResponseBody Object getUserDetails(#PathVariable String userId){
Object response=null;
UserDAO dao = UserDAO.getInstance();
response=dao.getUser(userId);
return response;
}
}
Calling this using curl:
curl -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:8080/myapp/v2/users/123
Returns the following payload:
{
"device": "D045453",
"userId": "123",
"userDetails":
[
{
"propertyName": "Position",
"propertyValue": "Manager"
},
{
"propertyName": "Salary",
"propertyValue": "120000"
},
{
"propertyName": "Name",
"propertyValue": "John Smith"
}
]
}
Have setup my MockMvc test case like this:
WebAppConfiguration
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = "classpath:**/mvc-dispatcher-servlet.xml")
public class MyControllerDocumentation {
private static final String USER_ID = "123";
#Rule
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("target/generated-snippets");
#Autowired
private WebApplicationContext context;
private MockMvc mockMvc;
#Before
public void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation)).build();
}
#Test
public void getUserDetails() throws Exception {
this.mockMvc.perform(get("/v2/users/{userId}", USER_ID)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("device").isNotEmpty())
.andDo(document("{class-name}/{method-name}"));
}
}
There's no applicationContext.xml anywhere just the mvc-dispatcher-servlet.xml (which resides in src/main/webapp/WEB-INF):
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<context:component-scan base-package="com.myapp.rest.controllers" />
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
I start tomcat (because I already have a previous war file containing this rest call in $CATALINA_HOME/webapps) and when try to build the war file:
mvn clean install
This is what comes up in Surefire Reports:
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.638 sec <<< FAILURE!
getUserDetails(com.myapp.rest.controllers.MyControllerDocumentation) Time elapsed: 0.2 sec <<< FAILURE!
java.lang.AssertionError: Status expected:<200> but was:<404>
at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:54)
at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:81)
at org.springframework.test.web.servlet.result.StatusResultMatchers$10.match(StatusResultMatchers.java:665)
at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:171)
at om.myapp.rest.controllers.MyControllerDocumentation.getUserDetails(MyControllerDocumentation.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
Question(s):
How can I obtain a simple HTTP 200 from my unit test? Is this a config issue?
Inside the:
.andDo(document("{class-name}/{method-name}"));
How do I setup it to document the various properties (key / value pairs) located in the response JSON payload using Spring Rest Docs?
Am thinking that I do not need to have tomcat running (with a previous war file)?
Sorry, have never used Spring Rest Docs and just wishing someone could point me in the right direction...

Related

JBoss working project with EJB can't get deployed on Tomcat Plume

Structure of project: pom-root, ear project that's dependent on ejb and war. War project also depends on ejb. Everything is created by mvn archetype:generate and managed in IDEA. The overall project gets cleaned and packaged and then the ear is being deployed on TomcatEE Plume 7.0.5.
Task: get user data from servlet and to persist it with JPA + hibernate to PostgreSQL.
Entity class: NewUser
Stateless class: UserEJB
Maven clean and install goes well, but when I start it with Tomcat the following error prevents ear to be deployed:
26-Aug-2018 18:24:37.684 INFO [http-nio-8002-exec-5] org.apache.openejb.assembler.classic.ReloadableEntityManagerFactory.createDelegate PersistenceUnit(name=userUnit, provider=org.hibernate.jpa.HibernatePersistenceProvider) - provider time 282ms
26-Aug-2018 18:24:37.684 INFO [http-nio-8002-exec-5] org.apache.openejb.assembler.classic.Assembler.destroyApplication Undeploying app: ...\jpaTomcat\ear\target\ear-1.0-SNAPSHOT
26-Aug-2018 18:24:38.173 SEVERE [http-nio-8002-exec-5] org.apache.openejb.assembler.classic.Assembler.destroyApplication undeployException original cause
java.lang.Exception: deployment not found: RegisterEJB
NewUser class:
package com.jeorgius.entities;
import javax.persistence.*;
import java.io.Serializable;
#Entity
#Table(name = "newuser", schema = "userdata")
#SequenceGenerator(name = "h", sequenceName = "userdata.hibernate_sequence")
public class NewUser implements Serializable {
#Id
#GeneratedValue (strategy = GenerationType.SEQUENCE, generator = "h")
private Integer id;
private String nick;
private String email;
private String pw;
public String getNick() {
return nick;
}
public void setNick(String nick) {
this.nick = nick;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPw() {
return pw;
}
public void setPw(String pw) {
this.pw = pw;
}
}
RegisterEJB class:
package com.jeorgius.ejb;
import com.jeorgius.entities.NewUser;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
#Stateless
public class RegisterEJB {
#PersistenceContext(unitName = "userUnit")
EntityManager em;
public void createUser(String nick, String email, String pw) {
NewUser newUser = new NewUser();
newUser.setNick(nick);
newUser.setEmail(email);
newUser.setPw(pw);
em.persist(newUser);
}
}
index.jsp page contains only form to enter nick, email, pw with action to servlet Register:
package com.jeorgius.servlets;
import com.jeorgius.ejb.RegisterEJB;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
#WebServlet("/register")
public class Register extends HttpServlet {
#EJB
RegisterEJB registerEJB = new RegisterEJB();
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String nick = req.getParameter("nick");
String email = req.getParameter("email");
String pw = req.getParameter("pw");
registerEJB.createUser(nick, email, pw);
}
}
persistence.xml on ejb-project:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
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_2_0.xsd">
<persistence-unit name="userUnit" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.jeorgius.entities.NewUser</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/jeorgius" />
<property name="javax.persistence.jdbc.user" value="postgres" />
<property name="javax.persistence.jdbc.password" value="1234" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
</properties>
</persistence-unit>
</persistence>
ejb-project 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>
<artifactId>jpaTomcat</artifactId>
<groupId>com.jeorgius</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>back</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ejb</packaging>
<name>back</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/postgresql/postgresql -->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.3.5.Final</version>
</dependency>
</dependencies>
<build>
<finalName>jpaTomcat</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
war-project 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>
<artifactId>jpaTomcat</artifactId>
<groupId>com.jeorgius</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>front</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>front</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jsp-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.jeorgius</groupId>
<artifactId>back</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
ear-project 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>
<artifactId>jpaTomcat</artifactId>
<groupId>com.jeorgius</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>ear</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ear</packaging>
<name>ear</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.jeorgius</groupId>
<artifactId>back</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>com.jeorgius</groupId>
<artifactId>front</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
</configuration>
</plugin>
</plugins>
</build>
</project>
The exact same project runs well on JBoss server, except for the fact that I use a .xml datasource on JBoss, so persistence.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
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_2_0.xsd">
<persistence-unit name="userUnit">
<jta-data-source>java:jboss/jeorgiusDS</jta-data-source>
<class>com.jeorgius.entities.Signup</class>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
</properties>
</persistence-unit>
</persistence>
I just wanted to test my app on TomcatEE, on which I failed before using JBoss, but I still can't figure out what's wrong. TomcatEE and Tomcat Plume are supposed to work with EJB and JPA.
Tomcat Plume was also used in one of the examples on youtube and it worked well, but the guy who made the video added project libraries manually without Maven. I didn't try to do it myself yet though, but that would leave issue with building it with maven.
I spent a lot of time trying out different stuff. Feel free to ask me questions, if anything is unclear. Thanks in advance!
I think TomEE does not like that <packaging>ejb</packaging>. If you move RegisterEJB to the same project/module where your servlet is then I believe it will work (no ear, just one war file).
If you want to have RegisterEJB in a different artifact I would use <packaging>jar</packaging>.
Also this looks strange:
#EJB
RegisterEJB registerEJB = new RegisterEJB();
It should be:
#EJB
RegisterEJB registerEJB;
#Inject will also work and with that you can change your EJB to something else and it will still work.

Class not found Exception for AWS lambda

I created a aws Lambda function which prints hello world to console
configured lambda with package name where the class is present and method name to call and uploaded jar file to aws lambda function.
when i execute lambda i get an exception saying class not found.
with message as
{
"errorMessage": "Class not found: com.coreservice.lambda.Handler",
"errorType": "class java.lang.ClassNotFoundException"
}
Can't able to understand why aws unable to find class inside jar.
Below Details are project configuration
public class Handler implements RequestHandler<SNSEvent, Object> {
#Override
public Object handleRequest(final SNSEvent input, final Context context) {
if (Objects.nonNull(input) && !CollectionUtils.isNullOrEmpty(input.getRecords())) {
context.getLogger().log("Hello World");
context.getLogger().log("queue = "+ SQS_URL);
}
return StringUtils.EMPTY;
}
}
project pom :
<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.coreservice</groupId>
<artifactId>SNS-SQS-Filter-Lambda</artifactId>
<packaging>jar</packaging>
<version>136.0.0-SNAPSHOT</version>
<name>SNS-SQS-Filter-Lambda</name>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.14</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source> <!-- or 1.8 -->
<target>1.8</target> <!-- or 1.8 -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Change you lambda configuration for Handler from:
com.coreservice.lambda.Handler.handleRequest
to
com.coreservice.lambda.Handler
The com.coreservice.lambda.Handler class must implement the com.amazonaws.services.lambda.runtime.RequestHandler interface.

I Can't run Arquillian Tests on Wildfly 8.2.0.Final

i'm trying to run arquillian tests on my project, but without sucess.
I'm looking for this error but not found questions about it.
When I try to run the arquillian test, see that RuntimeException.
java.lang.RuntimeException: java.net.MalformedURLException: Unsupported protocol: remote+http
my profile wildfly-remote-arquillian in pom.xml:
<profile>
<id>wildfly-remote-arquillian</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-websockets-jsr</artifactId>
<version>1.0.0.Beta25</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.5.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>3.0.5.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-json-p-provider</artifactId>
<version>3.0.5.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-remote</artifactId>
<version>${org.wildfly}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
</plugins>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
<testResource>
<directory>src/test/resources-wildfly-remote</directory>
<filtering>true</filtering>
</testResource>
</testResources>
</build>
</profile>
my arquillian.xml:
<?xml version="1.0" encoding="UTF-8"?>
(...)
<engine>
<property name="deploymentExportPath">target/</property>
</engine>
<container qualifier="wildfly" default="true">
<protocol type="jmx-as7">
<property name="executionType">REMOTE</property>
</protocol>
<configuration>
<property name="javaVmArguments">-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=y</property>
<property name="allowConnectingToRunningServer">true</property>
<property name="managementAddress">127.0.0.1</property>
<property name="managementPort">9990</property>
<property name="username">admin</property>
<property name="password">admin</property>
</configuration>
</container>
my Arquillian Test class:
#RunWith(Arquillian.class)
public class MemberRegistrationTest {
#Deployment
public static Archive<?> createTestArchive() {
return ShrinkWrap.create(WebArchive.class, "test.war")
.addClasses(Member.class, MemberRegistration.class,
Resources.class)
.addAsResource("META-INF/test-persistence.xml", "META- INF/persistence.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
// Deploy our test datasource
.addAsWebInfResource("test-ds.xml");
}
#Inject
MemberRegistration memberRegistration;
#Inject
Logger log;
#Test
public void testRegister() throws Exception {
Member newMember = new Member();
newMember.setName("Jane Doe");
newMember.setEmail("jane#mailinator.com");
newMember.setPhoneNumber("2125551234");
memberRegistration.register(newMember);
assertNotNull(newMember.getId());
(...)
Error console:
thanks for any help.

Spring autowiring not working in Vaadin 7 UI

I have a Vaadin 7 project. It's works. Now I need to implement Hibernate 4 to access Database and I want to use also Spring 4 to use its annotations.
The problem is that the autowired annotation doesn't work. The related object is always null.
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>bermacorp</groupId>
<artifactId>b-sci</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>b-sci</name>
<properties>
<vaadin.version>7.6.1</vaadin.version>
<vaadin.plugin.version>${vaadin.version}</vaadin.plugin.version>
<jetty.plugin.version>9.2.3.v20140905</jetty.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring.version>4.2.3.RELEASE</spring.version>
<version.hibernate>4.3.6.Final</version.hibernate>
<version.slf4j>1.5.8</version.slf4j>
</properties>
<repositories>
<repository>
<id>vaadin-addons</id>
<url>http://maven.vaadin.com/vaadin-addons</url>
</repository>
<repository>
<id>vaadin-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>${vaadin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-server</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-push</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client-compiler</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-themes</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${version.hibernate}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.0.2.GA</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${version.slf4j}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.4-702.jdbc4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<packagingExcludes>WEB-INF/classes/VAADIN/gwt-unitCache/**,
WEB-INF/classes/VAADIN/widgetsets/WEB-INF/**</packagingExcludes>
</configuration>
</plugin>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${vaadin.plugin.version}</version>
<configuration>
<extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>
<webappDirectory>${basedir}/target/classes/VAADIN/widgetsets</webappDirectory>
<draftCompile>false</draftCompile>
<compileReport>false</compileReport>
<style>OBF</style>
<strict>true</strict>
</configuration>
<executions>
<execution>
<goals>
<goal>update-theme</goal>
<goal>update-widgetset</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.6.1</version>
<configuration>
<filesets>
<fileset>
<directory>src/main/webapp/VAADIN/themes</directory>
<includes>
<include>**/styles.css</include>
<include>**/styles.scss.cache</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.plugin.version}</version>
<configuration>
<scanIntervalSeconds>2</scanIntervalSeconds>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>com.vaadin</groupId>
<artifactId>
vaadin-maven-plugin
</artifactId>
<versionRange>[7.1.11,)</versionRange>
<goals>
<goal>resources</goal>
<goal>update-widgetset</goal>
<goal>compile</goal>
<goal>compile-theme</goal>
<goal>update-theme</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>vaadin-prerelease</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<repositories>
<repository>
<id>vaadin-prereleases</id>
<url>http://maven.vaadin.com/vaadin-prereleases</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>vaadin-prereleases</id>
<url>http://maven.vaadin.com/vaadin-prereleases</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</project>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" 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>b-sci</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>Bsci</servlet-name>
<servlet-class>bsci.BsciServlet</servlet-class>
<init-param>
<param-name>UI</param-name>
<param-value>bsci.BsciUI</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Bsci</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
applicationContext.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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jaxws="http://cxf.apache.org/jaxws"
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/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<context:property-placeholder location = "classpath:application.properties"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>bsci.entity</value>
</list>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<context:annotation-config />
<tx:annotation-driven/>
<context:component-scan base-package="bsci.dao"/>
<bean class="bsci.service.impl.ServizioImpl" id="servizio"/>
</beans>
BsciServlet.java
package bsci;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.vaadin.server.ServiceException;
import com.vaadin.server.SessionInitEvent;
import com.vaadin.server.SessionInitListener;
import com.vaadin.server.VaadinServlet;
#SuppressWarnings("serial")
public class BsciServlet extends VaadinServlet implements SessionInitListener {
private WebApplicationContext webApplicationContext;
#Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
try {
this.webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext());
} catch (IllegalStateException e) {
throw new ServletException("could not locate containing WebApplicationContext");
}
AutowireCapableBeanFactory ctx = getWebApplicationContext().getAutowireCapableBeanFactory();
ctx.autowireBean(this);
}
protected final AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws ServletException {
try {
return getWebApplicationContext().getAutowireCapableBeanFactory();
} catch (IllegalStateException e) {
throw new ServletException("containing context " + getWebApplicationContext() + " is not autowire-capable", e);
}
}
protected final WebApplicationContext getWebApplicationContext() throws ServletException {
if (this.webApplicationContext == null) {
throw new ServletException("can't retrieve WebApplicationContext before init() is invoked");
}
return this.webApplicationContext;
}
#Override
public void sessionInit(SessionInitEvent event) throws ServiceException {
}
#Override
protected final void servletInitialized() throws ServletException {
super.servletInitialized();
getService().addSessionInitListener(this);
getService().addSessionInitListener(new BsciSessionInitListener());
}
}
BsciSessionInitListener.java
package bsci;
import org.jsoup.nodes.Element;
import com.vaadin.server.BootstrapFragmentResponse;
import com.vaadin.server.BootstrapListener;
import com.vaadin.server.BootstrapPageResponse;
import com.vaadin.server.ServiceException;
import com.vaadin.server.SessionInitEvent;
import com.vaadin.server.SessionInitListener;
#SuppressWarnings("serial")
public class BsciSessionInitListener implements SessionInitListener {
#Override
public final void sessionInit(final SessionInitEvent event)
throws ServiceException {
event.getSession().addBootstrapListener(new BootstrapListener() {
#Override
public void modifyBootstrapPage(final BootstrapPageResponse response) {
final Element head = response.getDocument().head();
head.appendElement("meta")
.attr("name", "viewport")
.attr("content",
"width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no");
head.appendElement("meta")
.attr("name", "apple-mobile-web-app-capable")
.attr("content", "yes");
head.appendElement("meta")
.attr("name", "apple-mobile-web-app-status-bar-style")
.attr("content", "black-translucent");
String contextPath = response.getRequest().getContextPath();
}
#Override
public void modifyBootstrapFragment(
final BootstrapFragmentResponse response) {
}
});
}
}
Now in my UI class the autowired object is always null.
package bsci;
import org.springframework.beans.factory.annotation.Autowired;
import com.google.common.eventbus.Subscribe;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Widgetset;
import com.vaadin.server.Page;
import com.vaadin.server.Page.BrowserWindowResizeEvent;
import com.vaadin.server.Page.BrowserWindowResizeListener;
import com.vaadin.server.Responsive;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinSession;
import com.vaadin.ui.UI;
import com.vaadin.ui.Window;
import com.vaadin.ui.themes.ValoTheme;
import bsci.data.DataProvider;
import bsci.data.DummyDataProvider;
import bsci.entity.Utente;
import bsci.event.BsciEvent.BrowserResizeEvent;
import bsci.event.BsciEvent.CloseOpenWindowsEvent;
import bsci.event.BsciEvent.UserLoggedOutEvent;
import bsci.event.BsciEvent.UserLoginRequestedEvent;
import bsci.event.BsciEventBus;
import bsci.service.Servizio;
import bsci.view.LoginView;
import bsci.view.MainView;
#Theme("bscitheme")
#Widgetset("bsci.BsciWidgetset")
public final class BsciUI extends UI {
#Autowired
Servizio servizio;
private final DataProvider dataProvider = new DummyDataProvider();
private final BsciEventBus dashboardEventbus = new BsciEventBus();
#Override
protected void init(final VaadinRequest request) {
BsciEventBus.register(this);
Responsive.makeResponsive(this);
addStyleName(ValoTheme.UI_WITH_MENU);
updateContent();
Page.getCurrent().addBrowserWindowResizeListener(new BrowserWindowResizeListener() {
#Override
public void browserWindowResized(final BrowserWindowResizeEvent event) {
BsciEventBus.post(new BrowserResizeEvent());
}
});
}
private void updateContent() {
Utente user = (Utente) VaadinSession.getCurrent().getAttribute(Utente.class.getName());
if (user != null) {
setContent(new MainView());
removeStyleName("loginview");
getNavigator().navigateTo(getNavigator().getState());
} else {
setContent(new LoginView());
addStyleName("loginview");
}
}
#Subscribe
public void userLoginRequested(final UserLoginRequestedEvent event) {
Utente user = getDataProvider().authenticate(event.getUserName(), event.getPassword());
VaadinSession.getCurrent().setAttribute(Utente.class.getName(), user);
updateContent();
}
#Subscribe
public void userLoggedOut(final UserLoggedOutEvent event) {
VaadinSession.getCurrent().close();
Page.getCurrent().reload();
}
#Subscribe
public void closeOpenWindows(final CloseOpenWindowsEvent event) {
for (Window window : getWindows()) {
window.close();
}
}
public static DataProvider getDataProvider() {
return ((BsciUI) getCurrent()).dataProvider;
}
public static BsciEventBus getDashboardEventbus() {
return ((BsciUI) getCurrent()).dashboardEventbus;
}
public Servizio getServizio() {
return servizio;
}
}
Can you help me, please?
I don't understand the reason.
The reason is that you're trying to let Spring inject something into your UI, but Spring doesn't know about your UI.
Use the Vaadin Spring integration instead of implementing it yourself. Doing it yourself is possible, but then you need some place where you manually look up some Components in the WebApplicationContext, for example the View components could be prototype scoped beans looked up in a ViewProvider used by the Navigator. But now that we have the official Vaadin Spring integration this isn't necessary anymore.
Thanks all, but I solved the problem using vaadin spring integration add-on
<dependency>
<groupId>ru.xpoft.vaadin</groupId>
<artifactId>spring-vaadin-integration</artifactId>
<version>3.2</version>
</dependency>

How to enable Apache Tuscany SDO with OSGi container? [classloader issue]

I try to use Apache CXF in Apache ServiceMix with SDO. SDOs are provided with Apache Tuscany SDO implementation.
Here is the dependency map:
My osgi-bundle exposes a web service, bundle depends on SDO.
CXF system bundle depends on SDO too.
I installed Apache Tuscany SDO bundle stack as follows:
osgi:install -s mvn:org.apache.tuscany.sdo/tuscany-sdo-api-r2.1/1.1.1
osgi:install -s mvn:org.apache.tuscany.sdo/tuscany-sdo-impl/1.1.1
osgi:install -s mvn:org.apache.tuscany.sdo/tuscany-sdo-lib/1.1.1
osgi:install -s mvn:org.apache.tuscany.sdo/tuscany-sdo-tools/1.1.1
Start levels are:
...
tuscany-sdo-api-r2.1 28
tuscany-sdo-impl 28
tuscany-sdo-lib 28
tuscany-sdo-tools 28
Apache CXF Bundle Jar (2.4.6) 30
camel-cxf (2.8.5) 50
camel-cxf-transport (2.8.5) 50
...
MyApplication 60
Whe I restart the server I get the folowwing exception printed:
karaf#root> Exception in thread "SpringOsgiExtenderThread-4" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'iws': Invocation of init method failed; nested exception is java.lang.ExceptionInInitializerError
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ExceptionInInitializerError
at org.apache.cxf.sdo.SDODataBinding.initialize(SDODataBinding.java:128)
at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:444)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:685)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:507)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:241)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:205)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101)
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:157)
at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:203)
at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:433)
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:322)
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:239)
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:509)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1544)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 14 more
Caused by: java.lang.NullPointerException
at org.apache.tuscany.sdo.api.SDOUtil.<clinit>(SDOUtil.java:48)
... 35 more
As I can see in the source code of org.apache.tuscany.sdo.api.SDOUtil.java (link):
46 public final class SDOUtil
47 {
48 protected static SDOHelper defaultSDOHelper = ((HelperProviderBase)HelperProvider.INSTANCE).sdoHelper();
49 ...
SDOUtil class from tuscany-sdo-api-r2.1 depends on a helper class commonj.sdo.impl.HelperProvider.java.
Source code for HelperProvider.java (link)
64 static {
65 // initialize the default instance using this class's classloader
66 // set to null if none could be located (implies no default implementation)
67 HelperProvider provider;
68 try {
69 provider = getInstance(HelperProvider.class.getClassLoader());
70 } catch (NoHelperProviderException e) {
71 provider = null;
72 }
73 INSTANCE = provider;
74 }
This means that getInstance() method does not work properly.
How to make SDOHelper to get initialized correctly in an OSGi contained?
UPDATE
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">
<!-- Generated by Apache ServiceMix Archetype -->
<modelVersion>4.0.0</modelVersion>
<groupId>com.bssys</groupId>
<artifactId>eg-smx-osgi-bundle</artifactId>
<packaging>bundle</packaging>
<version>1.0-SNAPSHOT</version>
<name>Apache ServiceMix :: Camel OSGi Bundle</name>
<properties>
<camel.version>2.8.3</camel.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel.version}</version>
</dependency>
<!-- CXF SDO -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-databinding-sdo</artifactId>
<version>2.4.6</version>
</dependency>
<!-- Apache tuscany SDO -->
<dependency>
<groupId>org.apache.tuscany.sdo</groupId>
<artifactId>tuscany-sdo-api-r2.1</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sdo</groupId>
<artifactId>tuscany-sdo-impl</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sdo</groupId>
<artifactId>tuscany-sdo-lib</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sdo</groupId>
<artifactId>tuscany-sdo-tools</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.6</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Import-Package>*,org.apache.camel.osgi</Import-Package>
<Private-Package>com.bssys</Private-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
camel-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by Apache ServiceMix Archetype -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://camel.apache.org/schema/osgi"
xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
xmlns:ctx="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws"
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
http://camel.apache.org/schema/osgi http://camel.apache.org/schema/osgi/camel-osgi.xsd
http://www.springframework.org/schema/osgi-compendium http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
">
<osgi:camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="timer://myTimer?fixedRate=true&period=10000"/>
<bean ref="myTransform" method="transform"/>
<to uri="log:ExampleRouter"/>
</route>
</osgi:camelContext>
<bean id="myTransform" class="com.bssys.MyTransform">
<property name="prefix" value="${prefix}"/>
</bean>
<osgix:cm-properties id="preProps" persistent-id="com.bssys">
<prop key="prefix">MyTransform</prop>
</osgix:cm-properties>
<ctx:property-placeholder properties-ref="preProps" />
<!-- HTTP Endpoint -->
<jaxws:endpoint xmlns:iws="http://www.bssys.com/SMEV/IWS/1"
id="iws" address="/iws1"
serviceName="iws:IWSExport_BaseImportIWSHttpService"
endpointName="iws:IWSExport_BaseImportIWSHttpPort"
implementor="com.bssys.smev.iws._1.BaseImportIWSImpl">
<!--
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
-->
</jaxws:endpoint>
<!--
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route/>
</camelContext>
-->
</beans>

Resources