we want to use Jglue framework for unit testing our CDI application. We use gradle for building.
We have prepared something like this:
1) Class to test:
#Default
public class RateTypeHibernateFactory implements RateTypeFactory {
#Override
public RateType getInstance(String name, String description) {
RateType rateType = getInstance();
rateType.setName(name);
rateType.setDescription(description);
return rateType;
}
}
2) Interface:
public interface RateTypeFactory {
public RateType getInstance(String name, String description);
}
3) Gradle settings (we followed getting started http://jglue.org/cdi-unit/)
dependencies {
testCompile (group: 'junit', name: 'junit', version: '4.8.2')
testCompile (group: 'org.jglue.cdi-unit', name: 'cdi-unit', version: '2.2.0')
}
4) Test class:
#RunWith(CdiRunner.class)
public class RateTypeFactoryTest {
#Inject RateTypeFactory rateTypeFactory;
#Test
public void testGetInstance() {
RateType rateType = rateTypeFactory.getInstance();
assertNotNull(rateType);
}
}
When we run this simple test, we always get this exception:
com.etnetera.projects.ticketing.model.factory.RateTypeFactoryTest > testGetInstance FAILED
java.lang.NoSuchMethodError
1 test completed, 1 failed
:test FAILED
In /build/reports/tests/index.html there is:
java.lang.NoSuchMethodError: org.jboss.weld.metadata.BeansXmlImpl.<init>(Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lorg/jboss/weld/bootstrap/spi/Scanning;Ljava/net/URL;Lorg/jboss/weld/bootstrap/spi/BeanDiscoveryMode;Ljava/lang/String;)V
at org.jglue.cdiunit.internal.WeldTestUrlDeployment.<init>(WeldTestUrlDeployment.java:80)
at org.jglue.cdiunit.CdiRunner$1.createDeployment(CdiRunner.java:71)
at org.jboss.weld.environment.se.Weld.initialize(Weld.java:137)
at org.jglue.cdiunit.CdiRunner.createTest(CdiRunner.java:82)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:258)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:255)
at org.jglue.cdiunit.CdiRunner.methodBlock(CdiRunner.java:113)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:55)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:42)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:71)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49)
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.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at $Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103)
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.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Please does anybody know how to avoid this exception? I can add some more details if needed.
This is usually caused by an unsupported version of weld being used.
However, I have just released CDI-Unit 2.2.1 which fixes a couple of issues with Gradle builds.
Please can you give it a go?
I have encountered a similar problem (with an error message a bit different). I googled a lot around this problem but did not found much about this, so I concluded that it was specific to my project. This lead me to suspect a version mismatch between the dependencies of the project.
I was using weld-servlet: 2.4.0.Final as a compile dependency and cdi-unit: 3.1.4 as a test dependency. And I noticed that cdi-unit had a dependency on weld-se-core: 2.3.2.Final. So I added weld-se-core to my dependency management with the same version as my weld-servlet artifact and it solved the problem.
For further reference, here is an extract of my pom.xml file
<properties>
<weld.version>2.4.0.Final</weld.version>
<cdi-unit.version>3.1.4</cdi-unit.version>
(...)
</properties>
<dependencyManagement>
<dependencies>
<!-- CDI -->
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>${weld.version}</version>
</dependency>
<!-- Tests -->
<dependency>
<groupId>org.jglue.cdi-unit</groupId>
<artifactId>cdi-unit</artifactId>
<version>${cdi-unit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>${weld.version}</version>
<scope>test</scope>
</dependency>
(...)
</dependencies>
</dependencyManagement>
<dependencies>
<!-- CDI -->
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
</dependency>
<!-- Tests -->
<dependency>
<groupId>org.jglue.cdi-unit</groupId>
<artifactId>cdi-unit</artifactId>
</dependency>
(...)
</dependencies>
It seems you are invoking a method on the interface without the parameters.
Instead of
RateType rateType = rateTypeFactory.getInstance();
you should probably call
RateType rateType = rateTypeFactory.getInstance("name", "description");
Maybe I missed something gradle-related?
Related
I don't know why I have that error with mockito
java.lang.NoClassDefFoundError: org/objenesis/ObjenesisStd
at org.mockito.internal.creation.jmock.ClassImposterizer.<init>(ClassImposterizer.java:36)
at org.mockito.internal.creation.jmock.ClassImposterizer.<clinit>(ClassImposterizer.java:29)
at org.mockito.internal.util.MockCreationValidator.isTypeMockable(MockCreationValidator.java:17)
at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:21)
at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:133)
at org.mockito.internal.creation.MockSettingsImpl.confirm(MockSettingsImpl.java:127)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:50)
at org.mockito.Mockito.mock(Mockito.java:1243)
at org.mockito.Mockito.mock(Mockito.java:1120)
at fr.oap.SubscriptionTest.testGetSubscriptionById(SubscriptionFactoryTest.java:24)
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 junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
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)
Caused by: java.lang.ClassNotFoundException: org.objenesis.ObjenesisStd
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)
... 29 more
About my class of Test is like this :
import junit.framework.TestCase;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import fr.aop.subscription.AbstractSubscription;
public class SubscriptionTest extends TestCase {
#Test
public void testGetSubscriptionById() {
ArgumentCaptor<AbstractSubscription>
arg=ArgumentCaptor.forClass(AbstractSubscription.class);
Subscription objMock=Mockito.mock(Subscription.class);
Mockito.when(objMock.getSubscribById(1)).thenReturn(arg.getValue());
}
}
And about the method getSubscribById whitch is in the class Subscription:
#Override
public AbstractSubscription getSubscriptionById(final Integer id) {
this.log.debug("BEGIN: getSubscriptionById id = " + id);
AbstractSubscription obj = null;
if (id != null) {
final StringBuilder queryString = new StringBuilder("select c from AbstractSubscription c ");
try {
queryString.append("where c.id = :id");
Query query = this.getEntityManager().createQuery(queryString.toString());
query = query.setParameter("id", id);
obj = (AbstractSubscription) query.getSingleResult();
} catch (final Exception exc) {
}
}
return obj;
}
when I instanciate the Subcription class it demand me the connection to the database, that's why I want to escape this and looking for a solution like mockito
ClassNotFoundException is result of a class loader that is not able to load a particular class.
In your case Mockito has a transitive dependency to Objenesis (it needs Objenesis for correct behavior). You are most likely trying to execute your test with Mockito on test class path, but without Objenesis.
You need to add Objenesis to your test class path.
For maven projects, be sure that:
you have declared Mockito as test dependency
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
to run a particular test from the command line execute
mvn test -Dtest=fullyQualifedNameToYourTestClass
You can try adding the mockito-all artifact instead of mockito-core, it works since version 1.9.5
I had a similar problem in an Android project using gradle.
Like #Popeye did for maven, I added the following line to build.gradle, among dependencies:
testImplementation 'org.objenesis:objenesis:2.3'
That solved my problem.
I was getting the same error of:
java.lang.NoClassDefFoundError: org/objenesis/ObjenesisStd
when I was running a test in a new project that was using Mockito.
Turns out in addition to adding the Mockito Dependencies I also had to add the Objenesis dependency. All I need to do was add the below dependency to my pom.xml and it all worked perfectly fine.
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>2.3</version>
<scope>test</scope>
</dependency>
I have this issue with the version of mockito-core 2.22.0.
After investigation it seems that the jar of objenesis was corrupted in my maven repository...
Just a rm -rf .m2/repository/org/objenesis is enough
I had the same problem, I deleted the mockito folder from my local repository and re-run the build, and it worked.
I have a Java EE project packaged on an ear. The ear contains one Jar where i package my #stateless EJBs and other not managed classes (my model, utils etc). For some of these EJBs i use Jax-Ws to expose their functionality as a web-service.
I try to create a logging mechanism using AOP, so i place the #Interceptors annotation in my Jax-Ws powered EJBs. The problem is that when i try to compile/build/package using maven i receive the following exception. It seems the problem is specific to wsgen cause when i put the #Interceptors annotation in the NON Jax-ws annotated EJBs it compiles and runs without any problem. I use JAva build 1.6.0_41-b02.
I also tried to find an older version of javax.interceptor-api (probably compiled in Java 1.6, as major.minor version 51.0 means that it has been compiled in JSE 7, if i get it right) but seems that 1.2 is the older one.
[ERROR] Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.2:wsgen (MyWebService) on pro
ect my-ws-ejb: Failed to execute wsgen: javax/interceptor/Interceptors : Unsupported major.minor version 51.0 -> [Help
1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plu
in:2.2:wsgen (MyWebService) on project my-ws-ejb: Failed to execute wsgen
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
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.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failed to execute wsgen
at org.jvnet.jax_ws_commons.jaxws.AbstractWsGenMojo.execute(AbstractWsGenMojo.java:148)
at org.jvnet.jax_ws_commons.jaxws.MainWsGenMojo.execute(MainWsGenMojo.java:95)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
Caused by: java.lang.UnsupportedClassVersionError: javax/interceptor/Interceptors : Unsupported major.minor version 51.
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:249)
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:95)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:107)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)
at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:370)
at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:181)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3079)
at java.lang.Class.getAnnotation(Class.java:3038)
at com.sun.tools.ws.wscompile.WsgenOptions.validateEndpointClass(WsgenOptions.java:240)
at com.sun.tools.ws.wscompile.WsgenOptions.validate(WsgenOptions.java:222)
at com.sun.tools.ws.wscompile.WsgenTool.run(WsgenTool.java:123)
at com.sun.tools.ws.WsGen.doMain(WsGen.java:74)
at org.jvnet.jax_ws_commons.jaxws.AbstractWsGenMojo.execute(AbstractWsGenMojo.java:142)
... 22 more
My pom (part):
<build>
<!-- The name of the jar file -->
<finalName>my-ws-ejb</finalName>
<plugins>
<!-- Use EJB 3.0 -->
<plugin>
<groupId>org.apache.maven.plugins
</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.0</ejbVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<!-- The WSDLs to be generated are placed here -->
<execution>
<id>MyWebService</id>
<configuration>
<sei>MyWebServiceBean</sei>
<genWsdl>true</genWsdl>
<keep>true</keep>
<verbose>true</verbose>
</configuration>
<goals>
<goal>wsgen</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<!-- Build with Java 6 -->
<source>1.6</source>
<target>1.6</target>
<!-- Show deprecations and warnings -->
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- EJB 3 -->
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<!-- EclipseLink -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence</artifactId>
<version>1.0.0.0_2-0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>persistence</artifactId>
<version>1.0.0.0_2-0</version>
<scope>provided</scope>
</dependency>
<!-- Oracle JDBC driver -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.1.0.7.0</version>
<scope>provided</scope>
</dependency>
<!-- AOP -->
<dependency>
<groupId>javax.interceptor</groupId>
<artifactId>javax.interceptor-api</artifactId>
<version>1.2</version>
</dependency>
.....
</dependencies>
My Bean (part)
#Interceptors(LoggingAopService.class)
#WebService(
serviceName = "MyWebService", portName = "MyWebService",
targetNamespace = "..."
)
#Stateless(name = "MyWebServiceBean", mappedName = "ejb/seb/MyWebServiceBean")
public class MyWebServiceBean implements MyWebService
{....}
Are you try web-beans.xml instead annotation? if didn't please check this is link. May be the maven plugin don't recognize this annotation.
The class level declaration should be look like this code:
<myapp:MyWebServiceBean>
<myfwk:LoggingAopService/>
</myapp:MyWebServiceBean>
And this interceptor need to enabled:
<Interceptors>
<myfwk:LoggingAopService/>
</Interceptors>
I didn't test these codes.
web-beans.xml declaration you sent is jboss specific ? I use web logic and found that an interceptor can be enabled by the following xml added in the META-INF/beans.xml.
<interceptors>
<class>org.samples.LoggingInterceptor</class>
</interceptors>
I will try the xml declaration but because i was in a hurry i leveraged Handler capabilities provided natively by the Jax-Ws framework (using #HandlerChain annotation) to "intercept" web service requests and responses.
I also tried to create a new annotation using the #InterceptorBinding way:
#Inherited
#InterceptorBinding
#Retention(RUNTIME)
#Target({ METHOD, TYPE })
public #interface Logging {
}
#Interceptor
#Logging
public class LoggingInterceptor {
#AroundInvoke
public Object intercept(InvocationContext context) throws Exception {...}
#Logging
#WebService(serviceName = "MyWebService", portName = "MyWebService",
targetNamespace = "...")
#Stateless(name = "MyWebServiceBean", mappedName = "ejb/seb/MyWebServiceBean")
public class MyWebServiceBean implements MyWebService
{....}
but this does not compile too, i receive the same error:
[ERROR] Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.2:w
sgen (EDocWebService) on project eDoc-ws-ejb: Failed to execute wsgen: javax/int
erceptor/InterceptorBinding : Unsupported major.minor version 51.0 -> [Help 1]
Probably this is a case where ejb-jar.xml should be used
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
<interceptors>
<interceptor>
<interceptor-class>com.mypackage.LoggingInterceptor </interceptor-class>
</interceptor>
</interceptors>
<assembly-descriptor>
<interceptor-binding>
<ejb-name>MyWebServiceBean</ejb-name>
<interceptor-class>com.package.Interceptor</interceptor-class>
</interceptor-binding>
</assembly-descriptor>
</ejb-jar>
I am currently trying to run parameterized tests with powermock, however whenever I try to instantiate any kind of mock an exception is thrown. I am also using JDK 1.6.
Here is some sample code that recreates the problem for me
Test class:
package com.test;
import static org.mockito.Mockito.mock;
import java.util.ArrayList;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.Runner;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.powermock.modules.junit4.rule.PowerMockRule;
#RunWith(Parameterized.class)
public class ParameterizedTest {
#Rule
public PowerMockRule rule = new PowerMockRule();
#Test
public void test() {
mock(Runner.class);
}
#Parameters
public static List<Object[]> data() {
ArrayList<Object[]> arrayList = new ArrayList<Object[]>();
arrayList.add(new Object[] {});
return arrayList;
}
}
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>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<powermock.version>1.5.1</powermock.version>
</properties>
<dependencies>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4-rule</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-classloading-xstream</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Stack trace:
java.lang.ExceptionInInitializerError
at org.mockito.internal.exceptions.stacktrace.ConditionalStackTraceFilter.<init>(ConditionalStackTraceFilter.java:17)
at org.mockito.exceptions.base.MockitoException.filterStackTrace(MockitoException.java:30)
at org.mockito.exceptions.base.MockitoException.<init>(MockitoException.java:19)
at org.mockito.exceptions.misusing.MockitoConfigurationException.<init>(MockitoConfigurationException.java:18)
at org.mockito.internal.configuration.ClassPathLoader.loadImplementations(ClassPathLoader.java:145)
at org.mockito.internal.configuration.ClassPathLoader.findPluginImplementation(ClassPathLoader.java:110)
at org.mockito.internal.configuration.ClassPathLoader.findPlatformMockMaker(ClassPathLoader.java:106)
at org.mockito.internal.configuration.ClassPathLoader.<clinit>(ClassPathLoader.java:59)
at org.mockito.internal.util.MockUtil.<clinit>(MockUtil.java:21)
at org.mockito.internal.MockitoCore.<init>(MockitoCore.java:40)
at org.mockito.Mockito.<clinit>(Mockito.java:932)
at com.lies.code.ParameterizedTest.test(ParameterizedTest.java:24)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.powermock.modules.junit4.rule.PowerMockStatement$1.run(PowerMockRule.java:52)
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.powermock.reflect.internal.WhiteboxImpl.performMethodInvocation(WhiteboxImpl.java:2014)
at org.powermock.reflect.internal.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.java:885)
at org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:713)
at org.powermock.reflect.Whitebox.invokeMethod(Whitebox.java:401)
at org.powermock.classloading.ClassloaderExecutor.execute(ClassloaderExecutor.java:98)
at org.powermock.classloading.ClassloaderExecutor.execute(ClassloaderExecutor.java:78)
at org.powermock.modules.junit4.rule.PowerMockStatement.evaluate(PowerMockRule.java:49)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
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)
Caused by: java.lang.NullPointerException
at org.mockito.internal.exceptions.stacktrace.StackTraceFilter.<clinit>(StackTraceFilter.java:21)
... 55 more
Ever since I heard about the #Rule feature of powermock I have wanted to use it, but have run into similar issues like this one.
Is there a way to get this to work?
Thank you to anyone that takes the time to reply
Have you tried using PowerMockIgnore? The error that you have got seems to be with that of classloading, and you can defer loading of actual classes by specifying them in PowerMockIgnore annotation
Since I've set some maven dependencies to "provided" instead of "compile" scope I got this error when starting up jetty:
JEE5 application
should run on WebSphere 7 and Jetty 7
Spring 3
The error:
java.lang.SecurityException: class "javax.servlet.ServletRequestListener"'s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(ClassLoader.java:806)
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:487)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:625)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:386)
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
at org.eclipse.jetty.server.handler.ContextHandler.setEventListeners(ContextHandler.java:554)
at org.eclipse.jetty.webapp.WebAppContext.setEventListeners(WebAppContext.java:946)
at org.eclipse.jetty.webapp.WebAppContext.addEventListener(WebAppContext.java:972)
at org.eclipse.jetty.webapp.TagLibConfiguration.preConfigure(TagLibConfiguration.java:492)
at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:418)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:454)
at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:256)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:224)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:167)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:224)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:90)
at org.eclipse.jetty.server.Server.doStart(Server.java:260)
at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:511)
at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:364)
at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:516)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
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.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
The maven section is:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<artifactId>myApp.war</artifactId>
<!--name??-->
<parent>
<groupId>com.example</groupId>
<artifactId>myApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<properties>
<java-version>1.5</java-version>
<org.springframework-version>3.0.5.RELEASE</org.springframework-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.aspectj-version>1.6.9</org.aspectj-version>
<org.slf4j-version>1.6.1</org.slf4j-version>
<cxf.version>2.5.2</cxf.version>
<jetty.version>7.6.3.v20120416</jetty.version>
<skipTests>true</skipTests>
<log4j.version>1.2.15</log4j.version>
</properties>
<!-- … -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<dependencies>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1</version>
<type>jar</type>
</dependency>
</dependencies>
<configuration>
<scanIntervalSeconds>5</scanIntervalSeconds>
<webAppConfig>
<contextPath>/</contextPath>
</webAppConfig>
<connectors>
<connector implementation="org.eclipse.jetty.server.bio.SocketConnector">
<port>8080</port>
<!-- this connector defaults to 1300 for some reason -->
</connector>
</connectors>
<!--
<useProvided>true</useProvided>
-->
</configuration>
</plugin>
Can't get the cause. Any hints welcome ;)
It looks as though you are including the servlet API as a provided dependency, and adding this to Jetty's classpath. This is colliding with Jetty's own bundled servlet API classes and causing the exception.
It is absolutely correct to include the servlet API as a provided dependency- the problem is in the <useProvided> parameter in the plugin configuration, which is adding the servlet API to the classpath. It would be better to exclude this, and, if you have any other dependencies with provided scope that aren't already in Jetty, then add them to the plugin dependencies, as you have done with commons-dbcp.
See also the comments in http://jira.codehaus.org/browse/JETTY-429, which discuss similar potential confusions.
I've had similar problem with javax.servlet because there were both 2.4 an 3.0.0 jar-versions in Eclipse Libraries/Maven Dependencies.
To fix it in Eclipse open project's pom.xml, Dependency hierarchy tab, filter by "servlet", choose (right mouse button) unnecessary 2.4(or 2.5) and "Exclude Maven Artifact ..." Thanks to Valery Gorbunov for the hint :)
I removed the
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1</version>
<type>jar</type>
</dependency>
in jetty and now it works...seems to another Logger implementation conflicts with commons-logging?! Didn't get the clue yet but for now...it works... Sometimes maven and java are not the best friends or I'm too stupid ;)
I am trying to replace standard logger initialization by some injection
1-st.
I was trying to use weld weld logging in stateless bean/webservices
#Stateless
#WebService
public class EchoSSL {
#Inject
private Logger log;
public EchoSSL() {
}
public String echo(String msg) {
log.debug("Log test");
return "Echoing: " + msg;
}
}
But it not working for me.. i get java.lang.reflect.InvocationTargetException
javax.servlet.ServletException:
java.lang.reflect.InvocationTargetException
at
org.glassfish.webservices.monitoring.WebServiceTesterServlet.doPost(WebServiceTesterServlet.java:326)
at
org.glassfish.webservices.monitoring.WebServiceTesterServlet.invoke(WebServiceTesterServlet.java:102)
at
org.glassfish.webservices.EjbWebServiceServlet.service(EjbWebServiceServlet.java:110)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at
com.sun.grizzly.http.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:195)
at
com.sun.grizzly.http.servlet.FilterChainImpl.invokeFilterChain(FilterChainImpl.java:139)
at
com.sun.grizzly.http.servlet.ServletAdapter.doService(ServletAdapter.java:376)
at
com.sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:329)
at
com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166)
at
com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:100)
at
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:245)
at
com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at
com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at
com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at
com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at
com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at
com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at
java.lang.Thread.run(Thread.java:619)
Caused by:
java.lang.reflect.InvocationTargetException
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.glassfish.webservices.monitoring.WebServiceTesterServlet.doPost(WebServiceTesterServlet.java:297)
... 24 more Caused by:
javax.xml.ws.soap.SOAPFaultException:
javax.ejb.EJBException at
com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:189)
at
com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:130)
at
com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:119)
at
com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:89)
at
com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:140)
at $Proxy484.sayHello(Unknown Source)
... 29 more Caused by:
javax.ejb.EJBException at
com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5070)
at
com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:4968)
at
com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4756)
at
com.sun.ejb.containers.WebServiceInvocationHandler.invoke(WebServiceInvocationHandler.java:200)
at $Proxy464.sayHello(Unknown Source)
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.glassfish.webservices.InvokerImpl.invoke(InvokerImpl.java:78)
at
org.glassfish.webservices.EjbInvokerImpl.invoke(EjbInvokerImpl.java:78)
at
com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:146)
at
com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:257)
at
com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:95)
at
com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:629)
at
com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:588)
at
com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:573)
at
com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:470)
at
com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:112)
at
org.glassfish.webservices.MonitoringPipe.process(MonitoringPipe.java:138)
at
com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
at
com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:629)
at
com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:588)
at
com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:573)
at
com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:470)
at
com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:112)
at
com.sun.xml.ws.tx.service.TxServerPipe.process(TxServerPipe.java:306)
at
com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
at
com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:629)
at
com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:588)
at
com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:573)
at
com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:470)
at
com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:112)
at
com.sun.enterprise.security.webservices.CommonServerSecurityPipe.processRequest(CommonServerSecurityPipe.java:195)
at
com.sun.enterprise.security.webservices.CommonServerSecurityPipe.process(CommonServerSecurityPipe.java:127)
at
com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
at
com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:629)
at
com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:588)
at
com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:573)
at
com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:470)
at
com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:295)
at
com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:519)
at
com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:288)
at
com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:143)
at
org.glassfish.webservices.Ejb3MessageDispatcher.handlePost(Ejb3MessageDispatcher.java:116)
at
org.glassfish.webservices.Ejb3MessageDispatcher.invoke(Ejb3MessageDispatcher.java:87)
at
org.glassfish.webservices.EjbWebServiceServlet.dispatchToEjbEndpoint(EjbWebServiceServlet.java:196)
at
org.glassfish.webservices.EjbWebServiceServlet.service(EjbWebServiceServlet.java:127)
... 22 more Caused by:
java.lang.NullPointerException at
ua.eset.inferno.heresy.ws.security.Hello.sayHello(Hello.java:33)
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.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1056)
at
org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1128)
at
com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5243)
at
com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:615)
at
com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
at
com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:567)
at
com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:157)
at
com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:139)
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
com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:858)
at
com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
at
com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:367)
at
com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5215)
at
com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5203)
at
com.sun.ejb.containers.WebServiceInvocationHandler.invoke(WebServiceInvocationHandler.java:188)
... 66 more
What is missed ?
2-nd
than I try this tutorial that is referenced to this - Custom Injections
But it also dosen`t help.
maven dependencies -
<dependencies>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-logger</artifactId>
<version>1.0.0-CR2</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-extensions</artifactId>
<version>1.0.0.Alpha1</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-api</artifactId>
<version>1.0-CR2</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
<version>1.0.1-CR2</version>
</dependency>
</dependencies>
Q1: What is the rule of weld Logger injection in ejb / web services ?
Q2: Could it be wsdl/EJB/WebService issue ?
This is my approach:
Add the following dependencies to the pom.xml:
<!-- SL4J API -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.0</version>
</dependency>
<!-- SLF4J JDK14 Binding -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.6.0</version>
</dependency>
<!-- Injectable Weld-Logger -->
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-logger</artifactId>
<version>1.0.0-CR2</version>
</dependency>
Inject the Logger and use it as usual:
import javax.inject.Inject;
import org.slf4j.Logger;
public class Example {
#Inject
private Logger logger;
public void exampleFunc() {
logger.info("Hello Logger!");
}
}
If you wanna use Log4J instead of the SLF4J-JDK14-binding, i found this page. I tried it, but i couldn't get it to work so i still stick with my own solution.
Make sure your bean is in a bean archive - i.e. that you have META-INF/beans.xml
Apart from the weld extension, which I can't help you with unless you give the whole exception, you can create a producer that #Produces a Logger
The default slf4j logger producer is defined in Weld Extensions. You can see how the producer is written here if you wanted to wire up your own without including all of Weld Extensions.
in this case I haven`t placed bean.xml in META-INF.