MSF4J micoservice trying to communicate with a SOAP service - axis2

I am trying to develop a microservice using MSF4J. The service gets the header details of the input request and try to communicate with a SOAP service for further operations. This logic when written as a normal application works fine but when converted to a microservice it throws the following the exception
[org.apache.axis2.context.AbstractContext] : OnDemandLogger initialized for class org.apache.axis2.context.AbstractContext is:org.apache.commons.logging.internal.JclLogger#6b972f62
[org.apache.axis2.util.Loader] : Trying to find [org/apache/axis2/deployment/axis2_default.xml] using sun.misc.Launcher$AppClassLoader#73d16e93 class loader.
2016-07-21 17:45:48 ERROR ChannelChunkResponder:103 - Resource method threw an exception
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.wso2.msf4j.internal.router.HttpMethodInfo.invoke(HttpMethodInfo.java:95)
at org.wso2.msf4j.internal.router.HttpDispatcher.channelRead0(HttpDispatcher.java:53)
at org.wso2.msf4j.internal.router.HttpDispatcher.channelRead0(HttpDispatcher.java:31)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
at org.wso2.msf4j.internal.router.RequestRouter.channelRead0(RequestRouter.java:83)
at org.wso2.msf4j.internal.router.RequestRouter.channelRead0(RequestRouter.java:44)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:244)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:110)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoSuchMethodError: org.apache.axiom.om.OMAbstractFactory.getMetaFactory()Lorg/apache/axiom/om/OMMetaFactory;
at org.apache.axiom.om.OMXMLBuilderFactory.createOMBuilder(OMXMLBuilderFactory.java:87)
at org.apache.axiom.om.OMXMLBuilderFactory.createOMBuilder(OMXMLBuilderFactory.java:73)
at org.apache.axis2.util.XMLUtils.toOM(XMLUtils.java:590)
at org.apache.axis2.util.XMLUtils.toOM(XMLUtils.java:575)
at org.apache.axis2.deployment.DescriptionBuilder.buildOM(DescriptionBuilder.java:97)
at org.apache.axis2.deployment.AxisConfigBuilder.populateConfig(AxisConfigBuilder.java:91)
at org.apache.axis2.deployment.DeploymentEngine.populateAxisConfiguration(DeploymentEngine.java:887)
at org.apache.axis2.deployment.FileSystemConfigurator.getAxisConfiguration(FileSystemConfigurator.java:116)
at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContext(ConfigurationContextFactory.java:64)
at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContextFromFileSystem(ConfigurationContextFactory.java:210)
at org.apache.axis2.client.ServiceClient.configureServiceClient(ServiceClient.java:150)
at org.apache.axis2.client.ServiceClient.<init>(ServiceClient.java:143)
at org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub.<init>(OAuth2TokenValidationServiceStub.java:103)
at org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub.<init>(OAuth2TokenValidationServiceStub.java:89)
at com.wipro.oauth.manager.IDManagementClient.validateToken(IDManagementClient.java:220)
at com.wipro.oauth.manager.IdentityServerRest.getOAuthToken(IdentityServerRest.java:126)
... 37 more
The SOAP service, the microservice tries to communicate with is the "OAuth2TokenValidationService" of the WSO2 Identity Server.
The method the incorporates the call to the SAOP service is as follows
public OAuth2TokenValidationResponseDTO validateToken(
String accessTokenIdentifier)
throws RemoteException, LoginAuthenticationExceptionException {
OAuth2TokenValidationServiceStub stub = new OAuth2TokenValidationServiceStub(
null, server
+ "/services/OAuth2TokenValidationService");
ServiceClient e3 = stub._getServiceClient();
Options option3 = e3.getOptions();
HttpTransportProperties.Authenticator auth1 = new HttpTransportProperties.Authenticator();
auth1.setUsername(utUsername);
auth1.setPassword(utPassword);
auth1.setPreemptiveAuthentication(true);
option3.setManageSession(true);
/*option2.setProperty(Constants.Configuration.MESSAGE_TYPE,HTTPConstants.MEDIA_TYPE_APPLICATION_ECHO_XML);
option2.setProperty(Constants.Configuration.DISABLE_SOAP_ACTION,Boolean.TRUE);*/
option3.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth1);
/*option2.setProperty("Cookie", authCookie);*/
e3.setOptions(option3);
OAuth2TokenValidationRequestDTO oauthReq = new OAuth2TokenValidationRequestDTO();
OAuth2TokenValidationRequestDTO_OAuth2AccessToken accessToken = new OAuth2TokenValidationRequestDTO_OAuth2AccessToken();
accessToken.setTokenType("Bearer");
accessToken.setIdentifier(accessTokenIdentifier);
oauthReq.setAccessToken(accessToken);
oauthReq.setRequiredClaimURIs(null);
OAuth2TokenValidationResponseDTO resp = stub.validate(oauthReq);
return resp;
}
The following dependency has been added while converting the normal application to microservice.
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.transport</artifactId>
<version>5.0.0-alpha</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
The dependencies related to the AXIOM are
<dependency>
<groupId>org.apache.ws.commons.axiom.wso2</groupId>
<artifactId>axiom</artifactId>
<version>1.2.11.wso2v4</version>
</dependency>
<dependency>
<groupId>org.apache.woden</groupId>
<artifactId>woden-impl-dom</artifactId>
<version>1.0M8</version>
</dependency>
Any help for resolving this issue will be greatly appreciated.

Can you please try with the latest MSF4J 2.0 release?
The root cause of this issue is: Caused by: java.lang.NoSuchMethodError: org.apache.axiom.om.OMAbstractFactory.getMetaFactory()Lorg/apache/axiom/om/OMMetaFactory;
What this means is, in the dependency tree, most probably another version of Axiom is getting pulled in as a transitive dependency.
Run; mvn dependency:tree and find out what other versions of Axiom are getting pulled in and exclude those version from the Maven build.

Related

How to generate TOC

My Version:jkd11
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-JAXB-MOXy</artifactId>
<version>11.4.5</version>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-export-fo</artifactId>
<version>11.4.5</version>
</dependency>
I try below code but throw Docx4JException,but the github demo just that https://github.com/plutext/docx4j/blob/docx4j-parent-11.1.0/docx4j-samples-docx4j/src/main/java/org/docx4j/samples/TocAdd.java
TocGenerator tocGenerator = new TocGenerator(word);
tocGenerator.generateToc(0,"TOC \\o \"1-3\" \\h \\z \\u ",false);
org.docx4j.toc.TocException: Exception exporting package
at org.docx4j.toc.TocGenerator.getPageNumbersMapViaFOP(TocGenerator.java:792)
at org.docx4j.toc.TocGenerator.getPageNumbersMap(TocGenerator.java:651)
at org.docx4j.toc.TocGenerator.populateToc(TocGenerator.java:398)
at org.docx4j.toc.TocGenerator.generateToc(TocGenerator.java:262)
at org.docx4j.toc.TocGenerator.generateToc(TocGenerator.java:230)
at org.docx4j.toc.TocGenerator.generateToc(TocGenerator.java:190)
at com.erayt.studio.business.word.BusWordCreate.createWord(BusWordCreate.java:106)
at com.erayt.studio.test.WordTest.lambda$test$0(WordTest.java:66)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Exception exporting package
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:108)
at org.docx4j.Docx4J.toFO(Docx4J.java:710)
at org.docx4j.toc.TocGenerator.getPageNumbersMapViaFOP(TocGenerator.java:764)
... 14 more
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: You must invoke FORendererApacheFOP.getFOUserAgent
at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.render(FORendererApacheFOP.java:124)
at org.docx4j.convert.out.fo.AbstractFOExporter.postprocess(AbstractFOExporter.java:168)
at org.docx4j.convert.out.fo.AbstractFOExporter.postprocess(AbstractFOExporter.java:47)
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:83)
... 16 more
This was fixed at https://github.com/plutext/docx4j/commit/50cfa5cabe08ab133f28c54b59f73d082d3e80a4 and will be in v11.4.6
In the meantime you could try an earlier release such as 8.3.2 or 11.3.2.

Error running Spark Main Class - Exception in thread "Thread-0" java.lang.NoClassDefFoundError: org/eclipse/jetty/server/Handler

I am learning Mongodb for Java and I am trying to run the code below which shows jetty handler error. I tried searching for solutions in different threads of this forum but none of the solutions helps me. Please help. What am I missing?
package com.mongo.practice;
import spark.Request;
import spark.Response;
import spark.Route;
import spark.Spark;
public class SparkMain {
public static void main(String[] args){
Spark.get("/", new Route() {
public Object handle(final Request request, final Response response){
return "Hello worldfrom Spark";
}
});
}
}
I get this error when run
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "Thread-0" java.lang.NoClassDefFoundError: org/eclipse/jetty/server/Handler
at spark.embeddedserver.EmbeddedServers.initialize(EmbeddedServers.java:40)
at spark.Service.lambda$init$2(Service.java:536)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.server.Handler
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
This is my 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.mongo</groupId>
<artifactId>M101J</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.7.1</version>
</dependency>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.7.2</version>
</dependency>
</dependencies>
</project>
I tried adding this
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-server -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.9.v20180320</version>
</dependency>
but it did not solve the issue
You have to add two dependencies. The following:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.22</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-util -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>9.3.24.v20180605</version>
</dependency>
The version for sl4j can varry. But the version of jetty is not flexible. I have tried with the latest version. It does not work for any other version other than this.

Arquillian managed container : Server not detected

So I "installed" Arquillian in my jboss project. I used managed container. The server is starting up when I launch my test class. I increased the timeout to 120s instead of 60s to be sure. The problem is that once the server is launched (an i can navigate in the web application), the test is never launched...
On the JUnit tab nothing is happening until the 120s are over and then I get a timeout as if the server that was started is not detected.
Once this error occured, the server is shutdown, so there is has to be a link right ?
Did anyone had the same error ?
Thanks
CODE:
this is the container in arquilian.xml
<container qualifier="jbossas-managed" default="true">
<configuration>
<property name="jbossHome">C:\Developpement\jboss-as-7.1.3.Final</property>
<property name="startupTimeoutInSeconds">120</property>
<property name="javaVmArguments">-server -Xms64m -Xmx6g -XX:MaxPermSize=1024m -Dorg.jboss.as.logging.per-deployment=false -Djava.util.Arrays.useLegacyMergeSort=true -Xrunjdwp:transport=dt_socket,address=8180,server=y,suspend=y</property>
<property name="managementPort">8180</property>
<property name="allowConnectingToRunningServer">true</property>
</configuration>
I use this in my pom file:
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-managed</artifactId>
<version>7.1.3.Final</version>
<exclusions>
<exclusion>
<groupId>google-collections</groupId>
<artifactId>google-collections</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager</artifactId>
<version>1.2.1.GA</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.0.4.Final</version>
</dependency>
This is my test file:
#RunWith(Arquillian.class)
public class BasculeTest {
private static final int COMPLETE = 0;
private static final int MONTH_INCREMENTATION = 1;
private static final int BASCULE = 2;
private static final int YEAR_INCREMENTATION = 3;
// #Inject CompteursCongesUpdate compteursCongesUpdate;
#Deployment
public static Archive<?> createTestArchive() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war").addClass(CompteursCongesUpdate.class)
.addAsWebInfResource("test-persistence.xml", "classes/META-INF/persistence.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
return war;
}
#Test
public void testBascule() {
System.out.println("------------------------------- Début TEST -------------------------------");
try {
// compteursCongesUpdate.updateCompteursConges(new Date(), MONTH_INCREMENTATION);
// System.out.println("test +" +compteursCongesUpdate);
System.out.println("--------");
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Une exception a ete levee");
}
Assert.fail("Not yet implemented");
}
}
What I can do now is start the server normally (without executing the test class with junit) and afterwards execute the test class, once the server is runnng. Then I get a new error from log4j: nosuchfielderror: NO_FORMAT
java.lang.NoSuchFieldError: NO_FORMAT
at org.apache.log4j.spi.LoggingEvent.<init>(LoggingEvent.java:106)
at org.apache.log4j.Category.forcedLog(Category.java:118)
at org.apache.log4j.Category.log(Category.java:288)
at org.jboss.logging.Log4jLogger.doLogf(Log4jLogger.java:48)
at org.jboss.logging.Logger.debugf(Logger.java:565)
at org.jboss.as.arquillian.protocol.jmx.JMXProtocolPackager.generateArquillianServiceArchive(JMXProtocolPackager.java:112)
at org.jboss.as.arquillian.protocol.jmx.JMXProtocolPackager.generateDeployment(JMXProtocolPackager.java:101)
at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.buildTestableDeployments(DeploymentGenerator.java:193)
at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.createTestableDeployments(DeploymentGenerator.java:148)
at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.generateDeployment(DeploymentGenerator.java:85)
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)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
at org.jboss.arquillian.container.test.impl.client.ContainerEventController.execute(ContainerEventController.java:100)
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)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)
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)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)
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)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeClass(EventTestRunnerAdaptor.java:80)
at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:182)
at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Unable to initialize JCR_MOCK resource resolver factory - sling mocks

I have a simple sling mock test that is loading json data
public class Test {
#Rule
public final SlingContext context = new SlingContext(ResourceResolverType.JCR_MOCK);
#Before
public void setUp() {
context.load().json("/test-1.json", "/content/test");
}
#Test
public void testLoad() {
Resource resource = context.resourceResolver().getResource("/content/test");
}
}
I have the following dependencies added to my pom.xml
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.sling-mock</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.testing</artifactId>
<version>2.0.16</version>
<scope>test</scope>
</dependency>
When i execute this, I get the following exception, even though sling.api (v2.2) is an existing dependency in the pom
java.lang.RuntimeException: Unable to initialize JCR_MOCK resource resolver factory.
at org.apache.sling.testing.mock.sling.context.ContextResourceResolverFactory.get(ContextResourceResolverFactory.java:66)
at org.apache.sling.testing.mock.sling.context.SlingContextImpl.newResourceResolverFactory(SlingContextImpl.java:103)
at org.apache.sling.testing.mock.sling.context.SlingContextImpl.setUp(SlingContextImpl.java:94)
at org.apache.sling.testing.mock.sling.junit.SlingContext.access$000(SlingContext.java:32)
at org.apache.sling.testing.mock.sling.junit.SlingContext$1.before(SlingContext.java:113)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.NoClassDefFoundError: org/apache/sling/api/resource/ResourceProviderFactory
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.apache.sling.testing.mock.sling.MockJcrResourceResolverFactory.getResourceResolverInternal(MockJcrResourceResolverFactory.java:74)
at org.apache.sling.testing.mock.sling.MockJcrResourceResolverFactory.getResourceResolver(MockJcrResourceResolverFactory.java:111)
at org.apache.sling.testing.mock.sling.context.ContextResourceResolverFactory.initializeJcrMock(ContextResourceResolverFactory.java:72)
at org.apache.sling.testing.mock.sling.context.ContextResourceResolverFactory.get(ContextResourceResolverFactory.java:52)
... 21 more
Caused by: java.lang.ClassNotFoundException: org.apache.sling.api.resource.ResourceProviderFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 37 more
Can someone please help?
You are missing a dependency on org.apache.sling.api ( as shown by a search by class name on search.maven.org )

Arquillian: Adding beans.xml causes "ArquillianServletRunner not found"

I am using Arquillian[1] for testing my J2EE-App in an embedded glassfish environment inside Eclipse[2]-IDE.
package test.java;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
#RunWith(Arquillian.class)
public class ArquillianTest {
#Deployment
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class).addAsWebInfResource(EmptyAsset.INSTANCE,
ArchivePaths.create("beans.xml"));
}
#Test
public void test() {
Assert.assertNull(null);
}
}
The test executes fine until I add the showed instruction ".addAsWebInfResource(...)". When doing this, following exception is thrown:
java.lang.IllegalArgumentException: ArquillianServletRunner not found. Could not determine ContextRoot from ProtocolMetadata, please contact DeployableContainer developer.
at org.jboss.arquillian.protocol.servlet.ServletUtil.determineBaseURI(ServletUtil.java:64)
at org.jboss.arquillian.protocol.servlet.ServletURIHandler.locateTestServlet(ServletURIHandler.java:60)
at org.jboss.arquillian.protocol.servlet.ServletMethodExecutor.invoke(ServletMethodExecutor.java:77)
at org.jboss.arquillian.container.test.impl.execution.RemoteTestExecuter.execute(RemoteTestExecuter.java:120)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
at org.jboss.arquillian.container.test.impl.execution.ClientTestExecuter.execute(ClientTestExecuter.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createContext(ContainerEventController.java:142)
at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createTestContext(ContainerEventController.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:111)
at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:263)
at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:226)
at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:240)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
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.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:185)
at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Without beans.xml, of course, CDI does not work.
How can I avoid this exception?
I have uploaded my pom.xml to http://pastxt.com/P/7IT1VYWBUW
Environment: jdk1.7.0_02 / Win7 / Eclipse Juno SR1
[1] https://www.jboss.org/arquillian.html
[2] http://www.eclipse.org/
I've taken a look at your POM and your test. The issue appears to be related to GLASSFISH-16964, going by the following log entries:
SLF4J: The requested version 1.5.10 by your slf4j binding is not compatible with [1.6]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
Dec 07, 2012 2:09:59 PM org.glassfish.api.ActionReport failure
SEVERE: Exception while loading the app
Dec 07, 2012 2:09:59 PM org.glassfish.deployment.admin.DeployCommand execute
SEVERE: Exception while loading the app : org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
You have a few dependencies in your project that pull in v1.6.1 of slf4j-api. That appears to conflict with what embedded GlassFish requires - I believe it is 1.5.10 going by the logs of embedded GlassFish.
To resolve this particular issue, downgrade to the version that keeps GlassFish happy. I added the lower version as a managed dependency.
<dependencyManagement>
<dependencies>
....
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.10</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencies>
Of course, this might have an impact on the other libraries that depend on the newer version of slf4-api, so you'll have to watch out for other issues.
The best way to resolve this would be to use the remote or managed GlassFish Arquillian adapter.
ArquillianServletRunner not found. Could not determine ContextRoot from ProtocolMetadata, please contact DeployableContainer developer. seems to indicate that an error occured during the deployment. The message - you can think and express about what you want - has nothing to do with that error (source: https://developer.jboss.org/thread/173340)! You need to access the logs to figure out what's wrong which are either on the console or at a location which is configured in a file which is specified in the system property java.util.logging.config.file, e.g. add
handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=%4$s: %5$s%n
java.util.logging.ConsoleHandler.level=FINEST
In my case it was missing com.google.guava:guava:23.0:test and the issue was unrelated to adding beans.xml as Asset.EMPTY of Shrinkwrap.
Adding the below to the web.xml did the trick for me :
<servlet>
<servlet-name>ArquillianServletRunner</servlet-name>
<servlet-class>org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ArquillianServletRunner</servlet-name>
<url-pattern>/ArquillianServletRunner</url-pattern>
</servlet-mapping>
I had the same problem with Glassfish embedded 3.1.2. But it seems to be fixed in 3.1.2.2.
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.2.2</version>
<scope>provided</scope>
</dependency>