Jackson: "Conflicting setter definitions for property" in JUnit Tests - json

I have an application that queries EC2 Instance data using Amazon's AWS SDK for Java. The Instance is serialized to a JSON String using the Jackson wrapper class included in the AWS SDK. Later, I'm able to use the Jackson.fromJsonString(String, Class) method to deserialize the JSON String back into an EC2 Instance object.
This all works great in my application code. However, it fails every single time when run from a JUnit test within Eclipse. I'm using the exact same data, and the exact same deserialization code. When I run it from a JUnit test, though, I get the following Exception:
com.amazonaws.SdkClientException: Unable to parse Json String.
at com.amazonaws.util.json.Jackson.fromJsonString(Jackson.java:66)
at com.myapp.filters.test.AbstractResourceFilterCriteriaTest.testMeetsCriteria_Fail(AbstractResourceFilterCriteriaTest.java:166)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
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:678)
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: com.fasterxml.jackson.databind.JsonMappingException: Conflicting setter definitions for property "instanceType": com.amazonaws.services.ec2.model.Instance#setInstanceType(1 params) vs com.amazonaws.services.ec2.model.Instance#setInstanceType(1 params)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:269)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:461)
at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:3838)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3732)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2726)
at com.amazonaws.util.json.Jackson.fromJsonString(Jackson.java:64)
... 26 more
Caused by: java.lang.IllegalArgumentException: Conflicting setter definitions for property "instanceType": com.amazonaws.services.ec2.model.Instance#setInstanceType(1 params) vs com.amazonaws.services.ec2.model.Instance#setInstanceType(1 params)
at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.getSetter(POJOPropertyBuilder.java:300)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.filterBeanProps(BeanDeserializerFactory.java:619)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.addBeanProps(BeanDeserializerFactory.java:515)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:256)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:169)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:403)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:352)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264)
... 33 more
Any idea what on earth could be going wrong here? Why is it that it works just fine in the main application code, but fails when run as a JUnit test? Since I don't own the Instance object (it's part of Amazon's SDK) I can't modify any Jackson annotations. Any idea how I can get around this for my unit tests?

I would say you have a version issue with SDK between tests and production possibly. Looking at their source code for this class:
https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-ec2/src/main/java/com/amazonaws/services/ec2/model/Instance.java
They appear to have an annotation for jackson on one of the two setters, specifying that's the one to use for serialization / de-serialization. This is the latest version, I didn't tool back in history to see if older version was missing this.

Related

Getting class is frozen Runtime Exception while invoking webservice call and port-type

We are trying to make a soap webservice call when we are getting the below Runtime exception continously. we are running on AJSC7 platform.
Ecception is coming from "org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create"
iLib: ILIB-MSG-009 Something went wrong in the transformer.
java.lang.RuntimeException: com.att.csi.csi.namespaces.customercareprofile.types._public.commondatamodel.DiscountInfo$JaxbAccessorF_description class is frozen
at ilib.javassist.CtClassType.checkModify(CtClassType.java:309)
at ilib.javassist.CtBehavior.getMethodInfo(CtBehavior.java:111)
at com.att.ilib.transformer.InstrumentMeTransformer.getAnnotation(InstrumentMeTransformer.java:82)
at com.att.ilib.transformer.InstrumentMeTransformer.transform(InstrumentMeTransformer.java:62)
at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.lang.ClassLoader.defineClass(ClassLoader.java:642)
at sun.reflect.GeneratedMethodAccessor47.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.xml.bind.v2.runtime.reflect.opt.Injector.inject(Injector.java:271)
at com.sun.xml.bind.v2.runtime.reflect.opt.Injector.inject(Injector.java:92)
at com.sun.xml.bind.v2.runtime.reflect.opt.AccessorInjector.prepare(AccessorInjector.java:87)
use isFrozen( ) method to check if it is acutally frozen and deFrost it for further modification. Javassist freezes a class when it is loaded so that further changes will be prohibited.
check out the following links for further reference.
official javassist tuorial for frozen class
samples for deFrost( )

bootstrap PowerMock with #Rule ,but failed

#RunWith(PowerMockRunner.class)
#PrepareForTest({ SessionUtil.class})
public class FundControllerTest {
XXXXXXXXXXXXXXX.......
}
Run Junit as above, it works well.
But when I try to run Junit as below, it failed. Because I need use Eclemma to
coverage my test, so I switch to use #Rule to bootstrap PowerMock, but failed. Please help.
#PrepareForTest({ SessionUtil.class})
public class FundControllerTest {
#Rule
public PowerMockRule rule = new PowerMockRule();
/*
static{
PowerMockAgent.initializeIfNeeded();
}
*/
XXXXXXXXXXXXXXXXXXXXXXXXX..........
}
java.lang.RuntimeException: com.sun.tools.attach.AttachNotSupportedException: Unable to enqueue operation: the target VM does not support attach mechanism
at org.powermock.modules.agent.AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(AgentLoader.java:122)
at org.powermock.modules.agent.AgentLoader.loadAgent(AgentLoader.java:81)
at org.powermock.modules.agent.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:40)
at org.powermock.modules.agent.PowerMockAgent.initializeIfNeeded(PowerMockAgent.java:91)
at com.hsbc.mf.frtend.twfunds.controller.FundControllerTest.<clinit>(FundControllerTest.java:53)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:199)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:56)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:39)
at java.lang.reflect.Constructor.newInstance(Constructor.java:527)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
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: com.sun.tools.attach.AttachNotSupportedException: Unable to enqueue operation: the target VM does not support attach mechanism
at sun.tools.attach.WindowsVirtualMachine.<init>(WindowsVirtualMachine.java:64)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:56)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:39)
at java.lang.reflect.Constructor.newInstance(Constructor.java:527)
at org.powermock.reflect.internal.WhiteboxImpl.createInstance(WhiteboxImpl.java:1455)
at org.powermock.reflect.internal.WhiteboxImpl.invokeConstructor(WhiteboxImpl.java:1303)
at org.powermock.reflect.Whitebox.invokeConstructor(Whitebox.java:497)
at org.powermock.modules.agent.AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(AgentLoader.java:120)
... 28 more
When you find a snake in your bed, does it matter whether it crawled through the open window; or came through the front door?
In other words: in order to allow for mocking static code; PowerMock needs to manipulate the byte code of that production class SessionUtils. And EclEmma also relies on byte code manipulation.
Perhaps, at some future point, the implementations of both frameworks will work together (but the corresponding bug is almost two years old; and there isn't much activity around it; so don't hold your breath on it).
But today, PowerMock and EclEmma do not work together. End of story.
And it doesn't matter to "pull in" PowerMock using its own runner; or using the "rule approach". Because as said: the problem is that you found that snake in your bed; and not "how did it get there".
Now you simply have to decide what is more important to you: to keep your production code as is (and its design, that forces you to mock static calls with PowerMock); or to acquire coverage information.
My personal two cents: that is one of the reasons why my team gave up on PowerMock completely. Instead, we focus on writing code that is testable without mocking static/new calls; and guess what: that works fine. And our production code is better than before.

App Engine - Google Cloud SQL - Local MySQL database for jUnit - rdbms package not found

The offline database in MySQL is working fine when i launch the app but i would like to make it work also for my unit testing!
But it tells me that the "rdbms" package is missing.
May be am i'm missing an import or something because i got the following Exception :
java.lang.AssertionError: Exception = com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'rdbms' or call 'OpenConnection()' was not found.
at org.junit.Assert.fail(Assert.java:93)
at testDb.DbUserUnitTestCase.testAdd(DbUserUnitTestCase.java:50)
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:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
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.junit.runners.ParentRunner.run(ParentRunner.java:300)
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: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.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)
Looks like i'm not the only one have the trouble too:
https://groups.google.com/forum/?fromgroups=#!topic/google-cloud-sql-discuss/gyIOtJSrRkY
http://googlecloudsql.blogspot.com/2012/03/unit-testing-google-cloud-sql-with.html
https://groups.google.com/forum/#!msg/google-appengine/VOMSNqn2FWI/bNf5pmqvDQUJ
:/
OK, I had this same problem and was finally able to get it to work. Here is a summary of the issue:
The com.google.appengine.api.rdbms.AppEngineDriver driver ONLY works if you are running within actual App Engine, or in the local App Engine dev environment. It does NOT work (gives this "rdbms" package missing error) when you are running just in unit tests or outside of App Engine. This is true even if you set the rdbms.driver system property to something else.
The driver that DOES work in a non-App Engine java process is com.google.cloud.sql.Driver.
Unfortunately, things get tricky if you are using DriverManager.getConnection() to load the driver (which most datasources do). This method looks at registered drivers to see which one can load the supplied URL. Thus, you'll get into trouble if you register BOTH AppEngineDriver and com.google.cloud.sql.Driver - the "wrong one" may get used when you are loading a jdbc:google:rdbms DB URL.
In my case, I am using maven, Spring and iBatis. My solution is that when running test cases I use Spring's SimpleDriverDataSource. This data source let's you use an ACTUAL driver instance, instead of just specifying the class name. That means you don't have to worry about having both AppEngineDriver and com.google.cloud.sql.Driver in your classpath:
<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<constructor-arg>
<bean class="com.google.cloud.sql.Driver"/>
</constructor-arg>
<constructor-arg value="jdbc:google:rdbms://myProject:myInstance/myDb"/>
</bean>
Also, note that com.google.cloud.sql.Driver doesn't appear to be packaged in any of the standard maven artifacts. Instead, it comes in the appengine-java-sdk at appengine-java-sdk-1.7.3/lib/impl/google_sql.jar. For me, there was other stuff in google_sql.jar that was colliding with other dependencies I have (some jackson libraries), so instead I pulled out just the com.google packages into a separate jar. I then added this jar to my dependencies in maven as explained here: https://devcenter.heroku.com/articles/local-maven-dependencies. I then added this as a dependency to my project with test scope.
I guess i'm gonna respond to my own question, i found a work around doing this
if(isUnitTesting) {
String url = "jdbc:mysql://localhost:3306/project";
connection = DriverManager.getConnection(url, "root","");
} else {
DriverManager.registerDriver(new AppEngineDriver());
connection = DriverManager.getConnection("jdbc:google:rdbms://"+instanceName+"/project");
}
Not the best way i guess so feel free to respond if you have a better answer!

gwt java.lang.ExceptionInInitializerError

I'm working on a GWT app, and keep getting the error shown below.
I followed the GWT tutorial regarding naming conventions for servlet classes, and followed the Service / Async / ServiceImpl structure.
I also tried adding the -XX:-UseSplitVerifier VM argument to fix a previous problem. any ideas on what's going on?
SEVERE: javax.servlet.ServletContext log: Exception while dispatching incoming RPC
call
java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at
com.google.appengine.tools.development.agent.runtime.Runtime.newInstance_
(Runtime.java:127)
at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance
(Runtime.java:135)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader.instantiate
(ServerSerializationStreamReader.java:914)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader.deserialize
(ServerSerializationStreamReader.java:556)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamReader.readObject
(AbstractSerializationStreamReader.java:119)
at
com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader$ValueReader$8.
readValue(ServerSerializationStreamReader.java:138)
at
com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader.deserializeValue
(ServerSerializationStreamReader.java:385)
at com.google.gwt.user.server.rpc.RPC.decodeRequest(RPC.java:303)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall
(RemoteServiceServlet.java:206)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost
(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost
(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
(ServletHandler.java:1166)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter
(HeaderVerificationFilter.java:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter
(ServeBlobFilter.java:60)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter
(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter
(StaticFileFilter.java:122)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
(ServletHandler.java:1157)
at com.google.appengine.tools.development.BackendServersFilter.doFilter
(BackendServersFilter.java:97)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle
(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle
(DevAppEngineWebAppContext.java:78)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at
com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle
(JettyContainerService.java:369)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.UnsupportedOperationException: ERROR: GWT.create() is only usable
in client code! It cannot be called, for example, from server code. If you are
running a unit test, check that your test case extends GWTTestCase and that
GWT.create() is not called from within an initializer or constructor.
at com.google.gwt.core.client.GWT.create(GWT.java:91)
at com.google.gwt.user.client.ui.UIObject.<clinit>(UIObject.java:187)
... 46 more
Almost for sure you are calling a class that is GWT client only. You have the error:
Caused by: java.lang.UnsupportedOperationException: ERROR: GWT.create() is only usable
in client code! It cannot be called, for example, from server code. If you are
running a unit test, check that your test case extends GWTTestCase and that
GWT.create() is not called from within an initializer or constructor.
You don't need to specifically call "GWT.create()" yourself to get that exception. you might be calling a GWT client only class on the server side. Also you might containg a "client only" object in one of your RPC's arguments or even on shared code being called on the server side.
FWIW, I had the same error and it ended up being a constant (static final) that used GWT.create() to initialise. The constant was in a class that needed to be loaded by the GIN dependency injection parser.
IE: It was trying to load the class (and call GWT.create()) during module compile.

Getting java.rmi.RemoteException: EJB Exception Eventhough classpath, XMLs, Beans are correctly defined and deployed

I am having bad time debugging with this problem. I am migrating my codes from Java 1.4 to JDK 6 and Weblogic 8.1.5 to Weblogic 10.3. I have converted the deployment descriptors of EJBs using DDConverver utility of weblogic. Beans consists of stateless session and Entity beans (2.1). Application is made of JSP as front-end and EJBs as middle ware. While logging i am calling one session bean which internally called entity beans and loads the same. I am getting following exception when Session bean calls entity bean. Session call is successful, only the issue is entity call from session bean.
I am using development environment for this. JSPs are stored at
C:\MisasiaAppln10.3_DEV\misasia\autodeploy\misasia
EJBs are deployed at
C:\MisasiaAppln10.3_DEV\misasia\servers\AdminServer\upload
Exception Details:
java.rmi.RemoteException: EJB Exception: ; nested exception is:
java.lang.NoClassDefFoundError: com/misasia/admin/setupmaster/SetupMasterHome
at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:205)
at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:222)
at com.misasia.admin.ctrlsession.controlSession_ho24d0_EOImpl_1030_WLStub.login(Unknown Source)
at jsp_servlet.__index._jspService(__index.java:197)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.ServletStubImpl.onAddToMapException(ServletStubImpl.java:408)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:318)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3498)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Caused by: java.lang.NoClassDefFoundError: com/misasia/admin/setupmaster/SetupMasterHome
at com.misasia.admin.ctrlsession.controlBean.loadSetupMaster(controlBean.java:149)
at com.misasia.admin.ctrlsession.controlBean.login(controlBean.java:119)
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.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:126)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:114)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:15)
at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:54)
at com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:30)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:126)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:114)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
at $Proxy60.login(Unknown Source)
at com.misasia.admin.ctrlsession.controlSession_ho24d0_EOImpl.login(controlSession_ho24d0_EOImpl.java:840)
at com.misasia.admin.ctrlsession.controlSession_ho24d0_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:172)
... 18 more
Caused by: java.lang.ClassNotFoundException: com.misasia.admin.setupmaster.SetupMasterHome
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:283)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:256)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:176)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
... 44 more
Sample Codes:
Call of Session from JSP (THIS WORKS FINE)
env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3://localhost:7001");
ic = new InitialContext(env);
ctrlHome = (controlHome)ic.lookup("controlSessionEJB");
ctrl = (control)ctrlHome.create();
Call of Entity from Session (THIS FAILS)
Object refsetup = ic.lookup("java:comp/env/ejb/SetupMasterEJB");
// This is the line which gives an error
SetupMasterHome setuph = (SetupMasterHome)PortableRemoteObject.narrow(refsetup, SetupMasterHome.class);
java.lang.NoClassDefFoundError:
com/misasia/admin/setupmaster/SetupMasterHome
means that SetupMasterHome.class is missing in server/module classpath while executing ControlBean's loadSetupMaster method. Adding appropriate jar will solve the problem.