xCP2.0 Java Service not working - IDfSession is null - java

I'm currently working on a xCP 2.0 project with Documentum 7.0 and I'm trying to run a Java Service inside a workflow. The Java Service works alright when the function I use does no more than return a "some_string" String. But as soon as I try the actual thing and use documentum specific Objects like:
IDfSession mySession = getSession();
I get these exceptions right here:
java.lang.RuntimeException: Could not invoke the method 'test' from
interface 'class com.gemp1.Test' from BOF module 'gemp1_xCPJava' in
Process Template: 'Peticion de Nuevo Producto v2' - Activity: 'Execute
Java Service'. Workitem: '4a015abd80004959' Workflow: 'Peticion de
Nuevo Producto v2 2014-12-18' - '4d015abd8000411e' Activity: 'Execute
Java Service' - '4c015abd8002e358' Process: 'Peticion de Nuevo
Producto v2' - '4b015abd8002c56c' java.lang.Exception:
java.lang.RuntimeException: Could not invoke the method 'test' from
interface 'class com.gemp1.Test' from BOF module 'gemp1_xCPJava' at
com.documentum.bps.outbound.AbstractService.execute(AbstractService.java:98)
at
com.documentum.bpm.services.BPSIntegrationFramework.executeService(BPSIntegrationFramework.java:260)
at
com.documentum.bpm.services.BPSIntegrationFramework.executeMethod(BPSIntegrationFramework.java:92)
at
com.documentum.bpm.services.BPSIntegrationMethod.executeMethod(BPSIntegrationMethod.java:26)
at
com.documentum.bpm.rtutil.GenericWorkflowMethod.execute(GenericWorkflowMethod.java:129)
at
com.documentum.bpm.rtutil.GenericWorkflowMethod.execute(GenericWorkflowMethod.java:355)
at
com.documentum.bpm.rtutil.GenericWorkflowMethod.execute(GenericWorkflowMethod.java:70)
at com.documentum.mthdservlet.DfMethodRunner.runIt(Unknown Source)
at com.documentum.mthdservlet.AMethodRunner.runAndReturnStatus(Unknown
Source) at com.documentum.mthdservlet.DoMethod.invokeMethod(Unknown
Source) at com.documentum.mthdservlet.DoMethod.doPost(Unknown
Source) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at
org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at
org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:662) Caused by:
java.lang.RuntimeException: Could not invoke the method 'test' from
interface 'class com.gemp1.Test' from BOF module 'gemp1_xCPJava' at
com.documentum.bps.outbound.bof.runtime.BOFClient.invokeMethod(BOFClient.java:121)
at
com.documentum.bps.outbound.bof.runtime.BofModuleService.executeServiceOperation(BofModuleService.java:133)
at
com.documentum.bps.outbound.AbstractService.executeServiceInternal(AbstractService.java:122)
at
com.documentum.bps.outbound.AbstractService.execute(AbstractService.java:79)
... 32 more 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
com.documentum.bps.outbound.bof.runtime.BOFClient.invokeMethod(BOFClient.java:112)
... 35 more Caused by: java.lang.NullPointerException at
com.documentum.fc.client.DfSingleDocbaseModule.getSession(DfSingleDocbaseModule.java:58)
at com.gemp1.Test.test(Test.java:11) ... 40 more
My Java class:
package com.gemp1;
import com.documentum.fc.client.*;
import com.documentum.fc.common.DfException;
public class Test extends DfSingleDocbaseModule {
public String test() {
String result = "Hello12345";
return result;
}
public String[] getUsers() throws DfException {
String docbaseUsers[] = new String[200];
IDfCollection coll = null;
IDfSession mySession = getSession();
String myQuery = "select user_name from dm_user";
IDfQuery myDFQuery = new DfQuery(myQuery);
coll = myDFQuery.execute(mySession, IDfQuery.DF_QUERY);
int i=0;
while (coll.next()) {
docbaseUsers[i] = coll.getString("user_name");
i++;
}
return docbaseUsers;
}
}
And finally my javamodule file:
<?xml version="1.0" encoding="UTF-8"?>
<nsJavaModule:JavaModule xmlns:nsJavaModule="http://xcp.emc.com/javamodule" urn="urn:gemp1:com.emc.xcp.artifact.javamodule.category:Artifacts/Java Modules/xCPJava.javamodule" categoryId="com.emc.xcp.artifact.javamodule.category" name="xCPJava" label="xCPJava" implementationClass="com.gemp1.Test">
<implementationJars contentPath="content/modules/xCPJava.jar"/>
<implementationJars contentPath="content/modules/dfc.jar"/>
</nsJavaModule:JavaModule>
Am I missing something?

Related

InvocationTargetException - Call Rest service from java Soap webservice using httpClient

I am created soap webservice in my server. And I want to call other service(In another server) from my soap service using httpClient with "POST" method. I used "httpclient-4.2.2.jar" and "httpcore-4.2.2.jar".
Code snippet:
public class User {
public static String addUser(String userEmail, String password) {
final String uri = "http://www.example.com/";
String requestParams = String.format("{\"userEmail\": \"%s\", \"password\": \"%s\"}", userEmail, password);
final HttpClient client = new DefaultHttpClient();
final HttpPost postMethod = new HttpPost(uri);
postMethod.setEntity(new StringEntity(requestParams, "utf-8"));
try {
final HttpResponse response = client.execute(postMethod);
final String responseData = EntityUtils.toString(response.getEntity(), "utf-8");
System.out.println(responseData);
} catch(final Exception e) {
e.printStackTrace();
}
return responseData;
}
}
When I call this menthod from another class using the following code.
User.addUser(userEmail, password);
Stacktrace:
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.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.geronimo.tomcat.valve.DefaultSubjectValve.invoke(DefaultSubjectValve.java:56)
at org.apache.geronimo.tomcat.GeronimoStandardContext$SystemMethodValve.invoke(GeronimoStandardContext.java:406)
at org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(GeronimoBeforeAfterValve.java:47)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555)
at org.apache.geronimo.tomcat.valve.ThreadCleanerValve.invoke(ThreadCleanerValve.java:40)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.VerifyError: Cannot inherit from final class
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 org.apache.geronimo.kernel.classloader.JarFileClassLoader.access$200(JarFileClassLoader.java:52)
at org.apache.geronimo.kernel.classloader.JarFileClassLoader$6.run(JarFileClassLoader.java:308)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.geronimo.kernel.classloader.JarFileClassLoader.findClass(JarFileClassLoader.java:260)
at org.apache.geronimo.kernel.config.MultiParentClassLoader.loadOptimizedClass(MultiParentClassLoader.java:441)
at org.apache.geronimo.kernel.config.MultiParentClassLoader.loadClass(MultiParentClassLoader.java:281)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.apache.http.impl.client.DefaultHttpClient.createHttpParams(DefaultHttpClient.java:157)
at org.apache.http.impl.client.AbstractHttpClient.getParams(AbstractHttpClient.java:448)
at org.apache.http.impl.client.AbstractHttpClient.createClientConnectionManager(AbstractHttpClient.java:309)
at org.apache.http.impl.client.AbstractHttpClient.getConnectionManager(AbstractHttpClient.java:466)
at org.apache.http.impl.client.AbstractHttpClient.createHttpContext(AbstractHttpClient.java:286)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:851)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
at com.test.User.addUser(User.java:18)
... 34 more
It throws the "InvocationTargetException". What may be the problem? Can you give your suggestions?
The problem is right there in the stacktrace:
Caused by: java.lang.VerifyError: Cannot inherit from final class
and if you look closer at the lines below, you can see an indication of where it goes wrong (hint: DefaultHttpClient.createHttpParams(DefaultHttpClient.java:157))
To cut to the chase: Loose the final modifiers on uri, client, postMethod, response and responseData. They're unnecessary and/or wrongly used anyway.
On a completely other note, you could add final modifiers to the methods formal arguments userEmail and password, but do read up on final first.
Cheers,

IllegalArgumentException when trying to get objects from Oracle database with JPA

This is my method which talks to the database with JPA:
public Collection<ModuleConnection> getConnections(int parentModuleId) {
Query query = em.createQuery("SELECT moduleConnection FROM ModuleConnection As moduleConnection WHERE moduleConnection.parentModule = :parentModuleId");
query.setParameter("parentModuleId", parentModuleId);
List<ModuleConnection> cons = query.getResultList();
return cons;
}
I am calling this method like this:
Collection<ModuleConnection> connections = bh.getConnections(module.getModuleId());
Everytime I do this, I get this exception:
java.lang.IllegalArgumentException: Can not set int field xyz.BomModule.moduleId to java.lang.Integer
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168)
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:55)
at sun.reflect.UnsafeIntegerFieldAccessorImpl.getInt(UnsafeIntegerFieldAccessorImpl.java:56)
at sun.reflect.UnsafeIntegerFieldAccessorImpl.get(UnsafeIntegerFieldAccessorImpl.java:36)
at java.lang.reflect.Field.get(Field.java:372)
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:55)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:206)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3619)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3335)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:204)
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:241)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:430)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:110)
at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:61)
at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:514)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1589)
at org.hibernate.loader.Loader.doQuery(Loader.java:696)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2228)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:67)
at xyz.getConnections(BomHandling.java:194)
at org.apache.jsp.js.jquery_002dtreeview.demo.bom_005fexample_jsp._jspService(bom_005fexample_jsp.java:222)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:722)
11:38:03,373 ERROR [CachedConnectionValve] Application error: jsp did not complete its transaction
This is how the table looks like:
CREATE TABLE "MODULECONNECTION"
(
"ID" NUMBER(10,0) NOT NULL ENABLE,
"QUANTITY" NUMBER(10,0) NOT NULL ENABLE,
"PARENTMODULE_MODULEID" NUMBER(10,0),
"SUBMODULE_MODULEID" NUMBER(10,0)
)
Any idea how I can fix this?
I think your query should just be
SELECT moduleConnection FROM ModuleConnection As moduleConnection
WHERE moduleConnection.parentModule.id = :parentModuleId
You could use your original query if the argument of the query was of type Module (the type of the associated entity, and not the type of its ID)

Java Wicket resource issue

Im working on a web app where we keep the code and web resources (such as css, image files etc) separated.
I have a file located here:
project root/src/main/webapp/images/icons/16/add.png
And in this location:
project root/src/main/java/se/su/dsv/scipro/icons
I have a class like so:
package se.su.dsv.scipro.icons;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.model.Model;
public class ImageIcon extends Image {
private static final long serialVersionUID = 1L;
public static final String ICON_NEW_ADD = "../../../../../../webapp/images/icons/16/add.png";
public ImageIcon(String id, String name, String size, String alt){
super(id, new ResourceReference(ImageIcon.class, name));
if(alt != null){
add(new AttributeAppender("alt", true, new Model<String>(alt), " "));
}
else {
add(new AttributeAppender("alt", true, new Model<String>(name), " "));
}
}
public ImageIcon(String id, String name){
this(id, name, "", null);
}
public ImageIcon(String id, String name, String alt){
this(id, name, "", alt);
}
public static ResourceReference getImage(String imageName, String imageSize){
return new ResourceReference(ImageIcon.class, imageName);
}
}
But when I use this class somewhere in a panel or a page, e.g. like this:
add(new ImageIcon("new_add", ImageIcon.ICON_NEW_ADD));
I get the following exception:
2011 Oct 18 11:11:17,947[ERROR] - RequestCycle - Can't instantiate page using constructor public se.su.dsv.scipro.basepages.DemoPage(org.apache.wicket.PageParameters) and argument
org.apache.wicket.WicketRuntimeException: Can't instantiate page using constructor public se.su.dsv.scipro.basepages.DemoPage(org.apache.wicket.PageParameters) and argument
at org.apache.wicket.session.DefaultPageFactory.createPage(DefaultPageFactory.java:212)
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:65)
at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.newPage(BookmarkablePageRequestTarget.java:298)
at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.getPage(BookmarkablePageRequestTarget.java:320)
at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.processEvents(BookmarkablePageRequestTarget.java:234)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1436)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:486)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:319)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.apache.wicket.session.DefaultPageFactory.createPage(DefaultPageFactory.java:188)
... 27 more
Caused by: java.lang.IllegalArgumentException: Invalid path ../../../../../../webapp/images/icons/16/add.png
at org.apache.wicket.util.lang.Packages.absolutePath(Packages.java:105)
at org.apache.wicket.util.lang.Packages.absolutePath(Packages.java:44)
at org.apache.wicket.markup.html.PackageResource.<init>(PackageResource.java:504)
at org.apache.wicket.markup.html.PackageResource.newPackageResource(PackageResource.java:448)
at org.apache.wicket.markup.html.PackageResource.get(PackageResource.java:424)
at org.apache.wicket.ResourceReference.newResource(ResourceReference.java:304)
at org.apache.wicket.ResourceReference.bind(ResourceReference.java:151)
at org.apache.wicket.markup.html.image.resource.LocalizedImageResource.bind(LocalizedImageResource.java:180)
at org.apache.wicket.markup.html.image.resource.LocalizedImageResource.setResourceReference(LocalizedImageResource.java:246)
at org.apache.wicket.markup.html.image.Image.setImageResourceReference(Image.java:178)
at org.apache.wicket.markup.html.image.Image.<init>(Image.java:101)
at org.apache.wicket.markup.html.image.Image.<init>(Image.java:77)
at se.su.dsv.scipro.icons.ImageIcon.<init>(ImageIcon.java:83)
at se.su.dsv.scipro.icons.ImageIcon.<init>(ImageIcon.java:93)
at se.su.dsv.scipro.basepages.DemoPage.<init>(DemoPage.java:16)
... 32 more
I guess it is because the image file resides outside any Java package? How can I address this?
Use a ContextRelativeResource. With it, the path to the image will be considered relative to the context root.
For instance, if you'd show this image with the following HTML:
<img src="images/icons/16/add.png">
Use the following:
new Image("add", new ContextRelativeResource("/images/icons/16/add.png")))
You might also find this blog post useful.
There's no ResourceReference version of this variant that I'm aware of, although you can try to integrate the one attached in this JIRA issue: WICKET-790

Getting NullPointerException on HttpRequest execute() for sending POST request to Google Places API

I am using Google Places API and trying to send a POST request to add a new place. But I keep getting a NullPointerException on the request.execute() part.
// Create POST body.
GenericData data = new GenericData();
GenericData coordinates = new GenericData();
coordinates.put("lat", latitude);
coordinates.put("lng", longitude);
data.put("location", coordinates);
data.put("accuracy", 50);
data.put("name", name);
JsonHttpContent content = new JsonHttpContent();
content.data = data;
// Send POST request.
HttpRequestFactory httpRequestFactory = LocationUtil.createRequestFactory(transport);
HttpRequest request = httpRequestFactory.buildPostRequest(new GenericUrl(GooglePlacesConsts.PLACES_REPORT_ADD_URL), content);
request.url.put("sensor", "false");
request.url.put("key", GooglePlacesConsts.API_KEY);
HttpResponse response = request.execute();
The code for createRequestFactory() is (this is from Davy's Tech Blog):
public static HttpRequestFactory createRequestFactory(final HttpTransport transport) {
return transport.createRequestFactory(new HttpRequestInitializer() {
public void initialize(HttpRequest request) {
GoogleHeaders headers = new GoogleHeaders();
headers.setApplicationName("App Name");
request.headers = headers;
JsonHttpParser parser = new JsonHttpParser();
parser.jsonFactory = new JacksonFactory();
request.addParser(parser);
}
});
}
Is the code wrong? I kinda borrowed lines of codes from different sources, because I...don't know how to correctly send a POST request in Java. Mainly, I followed the tutorial from Davy's Tech Blog, but also tried to follow this post, because the previous link provided examples only for sending GET requests, and I need to send a POST request.
By the way, this is the stack trace:
javax.faces.FacesException: #{locationBean.actionAdd}: java.lang.NullPointerException
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:349)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
... 22 more
Caused by: java.lang.NullPointerException
at com.google.api.client.http.json.JsonHttpContent.writeTo(JsonHttpContent.java:75)
at com.google.api.client.http.apache.ContentEntity.writeTo(ContentEntity.java:56)
at org.apache.http.entity.HttpEntityWrapper.writeTo(HttpEntityWrapper.java:101)
at org.apache.http.impl.client.EntityEnclosingRequestWrapper$EntityWrapper.writeTo(EntityEnclosingRequestWrapper.java:107)
at org.apache.http.impl.entity.EntitySerializer.serialize(EntitySerializer.java:127)
at org.apache.http.impl.AbstractHttpClientConnection.sendRequestEntity(AbstractHttpClientConnection.java:253)
at org.apache.http.impl.conn.AbstractClientConnAdapter.sendRequestEntity(AbstractClientConnAdapter.java:218)
at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:249)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:483)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)
at com.google.api.client.http.apache.ApacheHttpRequest.execute(ApacheHttpRequest.java:58)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:361)
at model.location.LocationBean.actionAdd(LocationBean.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.apache.el.parser.AstValue.invoke(AstValue.java:191)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
... 23 more
Thank you!
I struggled to find a version of that class that had a line number valid for your exception, but I found 1.4.1-beta.
public void writeTo(OutputStream out) throws IOException {
JsonGenerator generator = jsonFactory.createJsonGenerator(out, JsonEncoding.UTF8);
generator.serialize(data);
generator.flush();
}
Line 45 is the first line of the method. So check that jsonFactory is not null.

NullPointerEx at org.hibernate.engine.StatefulPersistenceContext line 1401

I have asked this question in Hibernate forum for a week without an anwser - https://forum.hibernate.org/viewtopic.php?f=1&t=1011634. I am really stuck here and hopefully can get help here. I got NullPointerException from org.hibernate.engine.StatefulPersistenceContext.
My hibernate dependency is as follows:
org.hibernate
hibernate-entitymanager
3.5.6-Final
The exception stack is below:
2011-07-04 07:06:38,691 DEBUG [http-8080-2] mobi.esca.mobile.remoting.HttpInvokerServiceExporter (HttpInvokerServiceExporter.java:168) - java.lang.NullPointerException
java.lang.NullPointerException
at org.hibernate.engine.StatefulPersistenceContext.replaceDelayedEntityIdentityInsertKeys(StatefulPersistenceContext.java:1401)
at org.hibernate.action.EntityIdentityInsertAction.postInsert(EntityIdentityInsertAction.java:117)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:89)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:267)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:259)
at org.hibernate.engine.ActionQueue.executeInserts(ActionQueue.java:169)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:287)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:69)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:179)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:800)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:774)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:778)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:668)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365)
at $Proxy138.persist(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.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
at $Proxy59.persist(Unknown Source)
at org.springframework.orm.jpa.JpaTemplate$5.doInJpa(JpaTemplate.java:264)
at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:183)
at org.springframework.orm.jpa.JpaTemplate.persist(JpaTemplate.java:262)
at mobi.esca.persistence.GenericJPARepository.persist(GenericJPARepository.java:153)
at mobi.esca.persistence.GenericJPARepository.persistAll(GenericJPARepository.java:161)
at mobi.esca.mars.application.UsageManager.logUsageStats(UsageManager.java:43)
at mobi.esca.mars.interfaces.mobile.EndUserController.reportStats(EndUserController.java:259)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
at $Proxy137.reportStats(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 mobi.esca.mobile.remoting.RemoteInvocationAdaptor.invoke(RemoteInvocationAdaptor.java:89)
at mobi.esca.mobile.remoting.RemoteInvocationAdaptor.proceed(RemoteInvocationAdaptor.java:54)
at mobi.esca.mobile.remoting.FilterChain.doFilter(FilterChain.java:59)
at mobi.esca.mobile.remoting.MethodInvocationRateFromUserProtection.doFilter(MethodInvocationRateFromUserProtection.java:56)
at mobi.esca.mobile.remoting.FilterChain.doFilter(FilterChain.java:56)
at mobi.esca.mobile.remoting.MethodInvocationRateFromIpProtection.doFilter(MethodInvocationRateFromIpProtection.java:57)
at mobi.esca.mobile.remoting.FilterChain.doFilter(FilterChain.java:56)
at mobi.esca.mars.interfaces.mobile.ClientVersionChecker.doFilter(ClientVersionChecker.java:41)
at mobi.esca.mobile.remoting.FilterChain.doFilter(FilterChain.java:56)
at mobi.esca.mobile.remoting.AuthenticationFilter.doFilter(AuthenticationFilter.java:37)
at mobi.esca.mobile.remoting.FilterChain.doFilter(FilterChain.java:56)
at mobi.esca.mobile.remoting.HttpInvokerServiceExporter.invokeAndCreateResult(HttpInvokerServiceExporter.java:201)
at mobi.esca.mobile.remoting.HttpInvokerServiceExporter.handleRequestInternal(HttpInvokerServiceExporter.java:128)
at mobi.esca.mobile.remoting.HttpInvokerServiceExporter.handleRequest(HttpInvokerServiceExporter.java:102)
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
I am looking at the line 1401 of StatefulPersistenceContext.java file:
1396 public void replaceDelayedEntityIdentityInsertKeys(EntityKey oldKey, Serializable generatedId) {
1397 Object entity = entitiesByKey.remove( oldKey );
1398 EntityEntry oldEntry = ( EntityEntry ) entityEntries.remove( entity );
1399 parentsByChild.clear();
1400
1401 EntityKey newKey = new EntityKey( generatedId, oldEntry.getPersister(), getSession().getEntityMode() );
1402 addEntity( newKey, entity );
so the possible null object here could be oldEntry, right? Could anyone tell me when oldEntry can become null? What can i do to fix the problem?
Your help will be highly appreciated.
Many thanks,
Cheng Wei
Hi Moe,
Thanks for your reply. The exception are happening randomly in various methods in our system now, and i can not recreate it by unit test. I will give a simplest code from a method.
#Controller
public class EndUserController implements EndUserService, InvocationContextRequired
{
#Override
public void reportStats(UsageStatsDTO usageStatsDTO) throws ClientVersionOutOfDateException
{
log.debug("enter UsageReportController.reportStats()");
UsageStats usageStats = usageStatsDTO.asUsageStats(getEndUser());
usageManager.logUsageStats(usageStats);
if(usageStats.hasAppStartEvent())
{
endUserManager.updateClientVersion(getEndUser(), getClientVersion());
}
log.debug("exit UsageReportController.reportStats()");
}
......
}
#Service
public class UsageManager
{
#Autowired
private CallEventRepository callEventRepository;
#Autowired
private AppStartEventRepository appStartEventRepository;
#Autowired
private InviteEventRepository inviteEventRepository;
#Transactional
public void logUsageStats(UsageStats usageStats)
{
if (usageStats.hasCallEvent())
{
callEventRepository.persistAll(usageStats.getCallEvents());
}
if (usageStats.hasAppStartEvent())
{
appStartEventRepository.persistAll(usageStats.getAppStartEvents());
}
if (usageStats.hasInviteEvent())
{
inviteEventRepository.persistAll(usageStats.getInviteEvents());
}
}
......
}
public class GenericJPARepository<T, ID extends Serializable>
implements GenericRepository<T, ID>
{
#Override
public T persist(T entity)
{
getJpaTemplate().persist(entity);
return entity;
}
#Override
public void persistAll(Collection<T> entities)
{
for(T entity : entities)
{
persist(entity);
}
}
......
}
And all RepositoryImpl classes are the subclasses(CallEventRepository,AppStartEventRepository,InviteEventRepository) of GenericJPARepository.
Many thanks,
Cheng Wei
Can problem be caused by i detach an entity? endUserRepository.detach(detatchedEndUser); But UsageStats, the object to be persisted, does not reference to detatchedEndUser.
Thanks Moe and Maurice, Appreciate your help. I finally find the problem. the following code caused the problem:
EndUser toBePersistedEndUser = endUserRepository.persist(new EndUser(remoteEndUser));
endUserRepository.detach(toBePersistedEndUser );
return toBePersistedEndUser;
Also, i think i reveal a bug for hibernate here.
Problem solved, Many thanks,
Cheng Wei
Well, either oldEntry is null, or getSession() returns null.
Obviously, oldEntry will be null if the entityEntries doesn't contain the entry removed from entitiesByKey. It could also happen if the equals() method for EntityEntry is incorrectly implemented.

Categories

Resources