I try to integrate the arquillian solution into my maven EJB project which contains juste the EJBs which I uses in other separate projects.
I use Jboss EAP6.
So i have make it as the following :
I made the arquillian.xml into ejbModule/src/test/resources/:
<container qualifier="jboss" default="true">
<configuration>
<property name="jbossHome">D:\jbdevstudio\jboss-eap-6.2</property>
</configuration>
</container>
in the pom of my project i added the following dependencies:
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-jbossas-embedded-6</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-junit</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
<profiles>
<profile>
<id>jbossas-embedded-6</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>arq-jbossas-managed</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-containermanaged</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>arq-jbossas-remote</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-containerremote</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
The Test Class :
import javax.inject.Inject;
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.oap.subscription.AbstractSubscription;
#RunWith(Arquillian.class)
public class SubscriptionFactoryTest {
#Inject
private SubscriptionFactory subscriptionFactory;
#Deployment
public static JavaArchive getDeployement() {
System.out.println("### testSayHelloEJB");
return ShrinkWrap.create(JavaArchive.class, "subscriptionFactory.jar")
.addClasses(AbstractSubscription.class,SubscriptionFactory.class);
}
#Test
public void getSubscriptionByIdTest() {
System.out.println("### testSayHelloEJB");
}
}
The EJB Class:
#Remote(ISubscriptionFactoryRemote.class)
#Local(ISubscriptionFactoryLocal.class)
#Stateless
public class SubscriptionFactory extends AbstractSubscription implements ISubscriptionFactoryRemote {
#Override
public AbstractSubscription getSubscriptionById(final Integer id) {
AbstractSubscription ret = null;
if (id != null) {
// create query
final StringBuilder queryString = new StringBuilder("select c from AbstractSubscription c ");
try {
queryString.append("where c.id = :id");
// create query
Query query = this.getEntityManager().createQuery(queryString.toString());
// set parameter
query = query.setParameter("id", id);
// recovers refCountry
ret = (AbstractSubscription) query.getSingleResult();
} catch (final Exception exc) {
}
}
return ret;
}
}
When i run the class test as Junit test , it gives me the errors :
janv. 20, 2015 12:15:34 PM org.jboss.arquillian.impl.client.container.ContainerRegistryCreator getActivatedConfiguration
Infos: Could not read active container configuration: null
the Faillure Trace:
java.lang.NoClassDefFoundError: Lorg/jboss/embedded/api/server/JBossASEmbeddedServer;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2397)
at java.lang.Class.getDeclaredFields(Class.java:1806)
at org.jboss.arquillian.impl.core.Reflections.getFieldInjectionPoints(Reflections.java:74)
... 79 more
Any idea.
You're using a very old version of Arquillian, I'd use at least version 1.1.0.Final. I also don't think you need a few of the Arquillian dependencies you have defined.
Remove the arquillian-jbossas-embedded-6 and arquillian-junit depdendencies.
There are plenty of quickstart examples of how to use Arquillian with JBoss EAP. Have a look at some of the pom's there as it might help.
Related
MainClass
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
public class WebSocketServer {
private Server server;
public void setup() {
server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(12345);
server.addConnector(connector);
ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
contextHandler.setContextPath("/");
contextHandler.addServlet(WebSocketServlet.class, "/websocket");
JettyWebSocketServletContainerInitializer.configure(contextHandler, null);
server.setHandler(contextHandler);
}
public void start() throws Exception {
server.start();
server.dump(System.err);
server.join();
}
public static void main(String args[]) throws Exception {
WebSocketServer webSocketServer = new WebSocketServer();
webSocketServer.setup();
webSocketServer.start();
}
}
JettyWebsocketServelet Implementation:
public class WebSocketServlet extends JettyWebSocketServlet {
#Override
protected void configure(JettyWebSocketServletFactory factory) {
// TODO Auto-generated method stub
factory.register(WebSocketServer.class);
}
}
Dependency:
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-jetty-server</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>11.0.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-jetty-client</artifactId>
<version>11.0.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-annotations</artifactId>
<version>11.0.0.beta3</version>
</dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
<version>11.0.2</version>
</dependency>
Error:
java.nio.channels.ClosedChannelException
at org.eclipse.jetty.websocket.core.internal.WebSocketSessionState.onEof(WebSocketSessionState.java:174)
at org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession.onEof(WebSocketCoreSession.java:329)
at org.eclipse.jetty.websocket.core.internal.WebSocketConnection.fillAndParse(WebSocketConnection.java:456)
at org.eclipse.jetty.websocket.core.internal.WebSocketConnection.onFillable(WebSocketConnection.java:314)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:319)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
at org.eclipse.jetty.io.SocketChannelEndPoint$1.run(SocketChannelEndPoint.java:101)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:132)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:894)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1038)
at java.base/java.lang.Thread.run(Thread.java:834)
Connecting getting refused and getting above error ****JDK version is 11 ****
The error message is the result of two mildly different versions of the same dependency on the classpath.SImply it means that there are multiple or more than one dependency in the classpath.I could not point you an exact solution on this but generally to debug use the JVM with -verbose option then look at the classes that were being loaded when the exception occurs. You should see some surprising information. For instance, having multiple copies of the same dependency and versions you never expected or would have accepted if you knew they were being included.
To resolve this problem with duplicate jars you can use http://maven.apache.org/plugins/maven-dependency-plugin/ combined with https://maven.apache.org/enforcer/maven-enforcer-plugin/.You need to add those jars to a section of your top-level POM.
I am learning REST services and face the problem: RestEasy cannot find my resources, even though I've tried various ways to demonstrate them.
Exception:
Failed to execute: javax.ws.rs.NotFoundException: RESTEASY003210: Could not find resource for full path: http://localhost:8080/RestfullService/services/hello
where RestfullService is the name of my project, /service - applicationPath, hello - resource. None of the errors (404 etc.) are shown on this pages.
My web.xml
(by the way, I've met controversial approaches regarding the content of web.xml while using web app server 3.0. According to official manuals, it is not required, but lots of people argue for it. What is the best practice?)
<?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>RestEasy sample Web Application</display-name>
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.store.model.WebConfig</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/</param-value>
</context-param>
</web-app>
My pom.xml (Although I've added all dependencies manually, the problem wasn't eliminated)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>RestfullService</groupId>
<artifactId>RestfullService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>webapp\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- <executions> <execution> <phase>package</phase> <configuration> <webXml>\webapp\WEB-INF\web.xml</webXml>
</configuration> </execution> </executions> -->
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.7</version>
<configuration>
<modules>
<ejbModule>
<!-- property configurations goes here -->
</ejbModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>JBoss repository</id>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.4.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>3.0.4.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-servlet-initializer</artifactId>
<version>3.0.4.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.4.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>3.0.4.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<version>3.0.4.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
<version>3.0.4.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-7.0</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.2_spec</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0-EDR1</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
<version>1.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
</dependencies>
</project>
ServiceInitialisation.java (both options with and without the body of this class didn't help):
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
#ApplicationPath("/services")
public class ServiceInitialisation extends Application{
// private Set<Object> singletons = new HashSet<Object>();
// private Set<Class<?>> classes = new HashSet<Class<?>>();
//
// public ServiceInitialisation() {
// singletons.add(new GoodsWebServiceImpl());
// }
//
// #Override
// public Set<Object> getSingletons() {
// return singletons;
// }
//
// #Override
// public Set<Class<?>> getClasses() {
// return classes;
// }
}
And finally services:
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import com.store.entity.Item;
#Path("/")
public interface GoodsWebService {
#GET
#Path("/hello")
#Produces("application/json")
public Response greet();
// id: \\d+ - regex for cheching if it is int #GET #Path("{id:
\\d+}")
#Produces("application/json")
public Response
getInfoById(#PathParam("id") int id);
#GET
#Path("/all")
#Produces("application/json")
public List<Item> getAllItems();
}
package com.store.restService;
import java.util.ArrayList;
import java.util.List;
//import org.json.JSONException;
//import org.json.JSONObject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import org.json.JSONObject;
import com.store.entity.Item;
import com.store.entity.Shop;
#Path("/")
public class GoodsWebServiceImpl implements GoodsWebService
{
private static List<Item>data;
private static List<Shop>shops1;
private static List<Shop>shops2;
private static List<Shop>shops3;
private static Shop shop1;
private static Shop shop2;
private static Shop shop3;
static {
shop1 = new Shop(1,4.55, 1);
shop2 = new Shop(2,9.99, 2);
shop3 = new Shop(3,6,0);
shops1.add(shop1); shops1.add(shop2);
shops2.add(shop3); shops2.add(shop1);
shops3.add(shop2); shops3.add(shop3);
data = new ArrayList<>();
data.add(new Item(1, "hand", shops1));
data.add(new Item(2, "pen", shops2));
data.add(new Item(3, "ball", shops2));
}
public static Item getItemById(int id){
for(Item e: data){
if(e.getId()==id) return e;
}
throw new RuntimeException("Can't find Item with id -" + id);
}
public static List<Item> getAll(){
return data;
}
#Override
public Response greet(){
String result = "Hello!";
return Response.status(200).entity(result).build();
}
#Override
public Response getInfoById(int id){
JSONObject jsonObject = new JSONObject();
Item item = getItemById(id);
jsonObject.put("Id ", item.getId());
jsonObject.put("Mpn ", item.getMpn());
jsonObject.put("Shop ", item.getShops());
String result = "Output:\n" + jsonObject;
return Response.status(200).entity(result).build();
}
#Override
public List<Item> getAllItems(){
// JSONObject jsonObject = new JSONObject();
// List<Item> items = getAll();
// jsonObject.put("List", items);
// JSONArray jArray = jsonObject.getJSONArray("List");
// for(int i=0; i<jArray.length(); i++){
// System.out.println(jArray.getJSONObject(i).getString("id"));
// System.out.println(jArray.getJSONObject(i).getString("mpn"));
// System.out.println(jArray.getJSONObject(i).getString("shop"));
// }
return getAll();
}
}
I would be gratefull for any comments, since all the available solutions in the web were already been unsuccessfully tried.
Thanks in advanced
Update:
Due to the fact that only a few manuals were succesfully deployed on my machine, I suppose I choose incorrect setting during the process of creation of the project.
I create the project for REST in this way: create Dynamic web project -> convert it to Maven -> add dependencies etc. -> trying to deploy
Screenshot of them:
The image is here
Update2
Moreover, I've noticed that every time I start WildFly I meet the same error. I have tried to create a few project with various dependencies, but the result is the same. How to deal with it?
22:45:09,109 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC000001: Failed to start service jboss.deployment.unit."RestService.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."RestService.war".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of deployment "RestService.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:163)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer from [Module "deployment.RestService.war:main" from Service Module Loader]
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.checkDeclaredApplicationClassAsServlet(JaxrsScanningProcessor.java:292)
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.scanWebDeployment(JaxrsScanningProcessor.java:153)
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.deploy(JaxrsScanningProcessor.java:104)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:156)
... 5 more
Caused by: java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer from [Module "deployment.RestService.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.checkDeclaredApplicationClassAsServlet(JaxrsScanningProcessor.java:290)
... 8 more
22:45:09,114 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 1) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"RestService.war\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"RestService.war\".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of deployment \"RestService.war\"
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer from [Module \"deployment.RestService.war:main\" from Service Module Loader]
Caused by: java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer from [Module \"deployment.RestService.war:main\" from Service Module Loader]"}}
You don't need web.xml, the resteasy-servlet, or any explicit RESTEasy dependencies in your POM.
You'd better start with a simple working example, e.g. https://github.com/wildfly/quickstart/tree/10.x/jaxrs-client.
Despite its name, this sample not only includes a JAX-RS client, but also a JAX-RS service.
I would like to convert the Spring Integration based web services to Spring Boot Application.
My application is developed using spring integration web services.
I want to convert that existed application into spring boot.I have tried to find many demos. No demo is available in online.
While converting I was facing this issue.
My Soap meesage response after submitting the request is as follows:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring xml:lang="en">No adapter for endpoint [countryGateway]: Is your endpoint annotated with #Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Startup of the application is given below
Application.Java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.integration.config.EnableIntegration;
#SpringBootApplication
#EnableIntegration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Spring configuration is as below
Sample-context.xml
<bean id="payloadMapping"
class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
<property name="mappings">
<props>
<prop
key="{http://spring.io/guides/gs-producing-web-service}getCountryRequest">countryGateway</prop>
</props>
</property>
</bean>
<int:channel id="countryRequestChannel"></int:channel>
<int:channel id="countryResponseChannel"></int:channel>
<int:channel id="countryErrorChannel"></int:channel>
<int-ws:inbound-gateway id="countryGateway"
error-channel="countryErrorChannel" request-channel="countryRequestChannel"
reply-channel="countryResponseChannel" />
<int:service-activator input-channel="countryRequestChannel" output-channel="countryResponseChannel" method="hello" ref="sampleActivator"></int:service-activator>
<bean id="sampleActivator" class="com.sample.country.SampleValidate"></bean>
Maven configuration is as below
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample.country</groupId>
<artifactId>springbootsample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<!-- Adding the dependencies -->
<dependencies>
<!-- To support web services -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-ws</artifactId>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-ws</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-xml</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>org.apache.ws.xmlschema</groupId>
<artifactId>xmlschema-core</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
</dependency>
<dependency>
<groupId>xom</groupId>
<artifactId>xom</artifactId>
<version>1.2.5</version>
</dependency>
</dependencies>
</project>
Web service configuration that i used is as given below
WebServiceConfig.java
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ws.config.annotation.EnableWs;
import org.springframework.ws.config.annotation.WsConfigurerAdapter;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
import org.springframework.xml.xsd.SimpleXsdSchema;
import org.springframework.xml.xsd.XsdSchema;
#EnableWs
#Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
#Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/ws/*");
}
#Bean(name = "countries")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("CountriesPort");
wsdl11Definition.setLocationUri("/ws");
wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
wsdl11Definition.setSchema(countriesSchema);
return wsdl11Definition;
}
#Bean
public XsdSchema countriesSchema() {
return new SimpleXsdSchema(new ClassPathResource("countries.xsd"));
}
}
I don't see you referencing the Sample-context.xml anywhere.
Try adding
#ImportResource("Sample-context.ml")
to the Application class.
EDIT
#EnableWs doesn't add a MessageEndpointAdapter, just a MethodEndpointAdapter.
This works...
#EnableWs
#Configuration
#ImportResource("Sample-context.xml")
public class WebServiceConfig extends WsConfigurerAdapter {
#Bean
public ServletRegistrationBean messageDispatcherServlet(MessageDispatcherServlet servlet) {
return new ServletRegistrationBean(servlet, "/ws/*");
}
#Bean
public MessageDispatcherServlet servlet() {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setTransformWsdlLocations(true);
return servlet;
}
#Bean
public MessageEndpointAdapter adapter() {
return new MessageEndpointAdapter();
}
#Bean(name = "countries")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("CountriesPort");
wsdl11Definition.setLocationUri("/ws");
wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
wsdl11Definition.setSchema(countriesSchema);
return wsdl11Definition;
}
#Bean
public XsdSchema countriesSchema() {
return new SimpleXsdSchema(new ClassPathResource("countries.xsd"));
}
}
I am completely baffled by this, and am not sure what else I can do to get this to work.
Using #Fetch on a relationship, will eagerly fetch that relationship.
Template.fetch can be used to fetch a relationship, if the property is not annotated with #fetch, i.e lazy loading. Does this type of lazy loading work with sets?
I have a node entity called Project, which has a set of scans. When I try to fetch the set of scans I only get 1 scan. When I modify the Project class to use #Fetch, I get 3 scans. The right amount of scans is 3. Using template.fetch is not giving me the entire collection. The question is why? Is there something wrong in my code?
The issue here is ProjectServiceImpl.findAllScans();
Below is my source code, starting with my maven pom file.
<!-- Spring Version -->
<properties>
<java-version>1.8</java-version>
<spring.version>4.0.9.RELEASE</spring.version>
<spring.security.version>3.2.5.RELEASE</spring.security.version>
<jackson.version>2.3.0</jackson.version>
<guava.version>15.0</guava.version>
<spring.neo4j.version>3.1.5.RELEASE</spring.neo4j.version>
<spring.mongodb.version>1.6.2.RELEASE</spring.mongodb.version>
<ehcache.version>2.9.0</ehcache.version>
<logback.version>1.1.2</logback.version>
<jcloverslf4j.version>1.7.10</jcloverslf4j.version>
<javax.servlet.version>3.1.0</javax.servlet.version>
<javax.validation.version>1.1.0.Final</javax.validation.version>
<spring.swagger.version>1.0.0</spring.swagger.version>
<spring.swagger.ui.version>0.4</spring.swagger.ui.version>
</properties>
<repositories>
<repository>
<id>jcenter-release</id>
<name>jcenter</name>
<url>http://oss.jfrog.org/artifactory/oss-release-local/</url>
</repository>
<repository>
<id>oss-jfrog-artifactory</id>
<name>oss-jfrog-artifactory-releases</name>
<url>http://oss.jfrog.org/artifactory/oss-release-local</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.ajar</groupId>
<artifactId>swagger-spring-mvc-ui</artifactId>
<version>${spring.swagger.ui.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-springmvc</artifactId>
<version>${spring.swagger.version}</version>
</dependency>
<!-- Spring Framework Core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</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>
<!-- Jackson JSON Dependencies-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- Servlet 3.1 and Java EE Validation API-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${javax.validation.version}</version>
</dependency>
<!-- Spring Data MongoDB -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>${spring.mongodb.version}</version>
</dependency>
<!-- Spring Data Neo4J -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>${spring.neo4j.version}</version>
</dependency>
<!-- Ehcache -->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>${ehcache.version}</version>
</dependency>
<!-- Google Guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<!-- Logback -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${jcloverslf4j.version}</version>
</dependency>
</dependencies>
<build>
<finalName>TEST</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
The Project Pojo:
#NodeEntity
public class Project {
// Properties
#GraphId
private Long id;
#Indexed(unique = true)
private String name;
#Indexed
private String xxxxId;
// Relationships
#RelatedTo(type = "HAS_SCAN", elementClass = Scan.class)
private Set<Scan> scans;
The next code snippet below is the scan class I use.
#NodeEntity
public class Scan {
// Properties
#GraphId
private Long id;
#Indexed
private String xxxxId;
#Indexed
private String projectVersion;
#Indexed
private Date date;
//Relationships
#RelatedTo(type = "NEXT_SCAN")
private Scan scan;
#RelatedTo(type = "HAS_ISSUE", elementClass = Issue.class)
private Set<Issue> issues;
#RelatedTo(type = "HAS_DEPENDENCY", elementClass = Dependency.class)
private Set<Dependency> dependencies;
#RelatedTo(type = "HAS_PACKAGE", elementClass = Package.class)
private Set<Package> packages;
The next code snippet below is the repository class I use.
#Repository
public interface ProjectRepository extends GraphRepository<Project> {
#Query("MATCH (p:Project) RETURN p")
public Set<Project> findAllProjects();
#Query("MATCH (p:Project {xxxId:{0}}) RETURN p")
public Project findProjectById(String projectId);
}
The class below is snippet of the service class I use, where I am calling template.fetch
#Service
#Transactional
public class ProjectServiceImpl implements ProjectService {
#Autowired
private Neo4jTemplate template;
#Autowired
private ProjectRepository projectRepository;
#Autowired
private ScanRepository scanRepository;
private static final Logger LOGGER = LoggerFactory.getLogger(ProjectServiceImpl.class);
#Override
public ProjectsDTO findAllProjects() {
return DTOTransformerUtil.transformProjectSetToProjectsDTO(projectRepository.findAllProjects());
}
#Override
public ProjectDTO findProject(String projectId) {
if (projectId != null) {
return DTOTransformerUtil.transformProjectToProjectDTO(projectRepository.findProjectById(projectId));
}
return null;
}
#Override
public ScansDTO findAllScans(String projectId) {
if (projectId != null) {
Project project = projectRepository.findProjectById(projectId);
return DTOTransformerUtil.transformScanSetToScansDTO(template.fetch(project.getScans()));
}
return null;
}
I am completely lost as to what the issue maybe be, i am currently trying older version of Spring data neo4j, maybe that may help resolve the issue.
I'm trying to add unit testing of ReST calls using JerseyTest framework in my project. I've copy-pasted a most trivial example, but I get a run-time exception:
java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:298)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:272)
at org.glassfish.jersey.test.JerseyTest.<init>(JerseyTest.java:142)
at com.dfc.warroom.rest.SimpleTest.<init>(SimpleTest.java:19)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:187)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:236)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:233)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Attaching the code and pom dependencies:
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Application;
import static junit.framework.Assert.assertEquals;
public class SimpleTest extends JerseyTest {
#Path("hello")
public static class HelloResource {
#GET
public String getHello() {
return "Hello World!";
}
}
#Override
protected Application configure() {
return new ResourceConfig(HelloResource.class);
}
#Test
public void test() {
final String hello = target("hello").request().get(String.class);
assertEquals("Hello World!", hello);
}
}
<dependencies>
<dependency>
<groupId>com.dfc</groupId>
<artifactId>war-room</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" -->
<artifactId>jersey-container-servlet</artifactId>
<version>2.6</version>
</dependency>
<!-- Required only when you are using JAX-RS Client -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.3.0</version>
</dependency>
<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-jetty</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.18.1</version>
</dependency>
<dependency>
<groupId>com.eclipsesource.jaxrs</groupId>
<artifactId>jersey-all</artifactId>
<version>2.8</version>
</dependency>
</dependencies>
As already said, this error is due to a conflict in your dependencies (probably between jersey 1 and 2). More information here. In fact, you use the version 1.18 of jersey-server, and other versions 2.6 in your pom.xml.
Solved by removing jersey-server and jersey-all dependencies, updating jersey dependencies to the latest version (2.15) and adding jetty dependencies.
I had the same issue
I was getting this library transitively:
org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.14
All of my jersey libs where version 2.6, excluding the above made my test cases pass. I add this:
<exclusion>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</exclusion>
</exclusions>