在搜索的日子里,我找不到任何有用的东西。也许我只是没有找对地方。
这里的想法 - 非常简单:我想通过 J2EE 中的内置 RMI 将一个对象从一个 EJB 传递到另一个。
据我所知,这是可能的,但我发现人们说的唯一真实的事情是使对象可序列化,所以我有(实际上我序列化了它的废话),但仍然没有骰子。所以这是一个测试用例,当关键代码未注释时,这会导致NullPointerException 。
我应该提到,在尝试完成这项工作时,我遇到了许多我无法克服的错误。这只是我在这个简单示例中得到的错误。我希望有人可以帮助我解决这个特定的问题,我可以对其进行调整。
因此,在 NetBeans 中工作时,Glassfish 服务器已完全更新,我有一个企业应用程序,其中包括另外两个项目:一个EJB 项目和一个Web 项目。
有以下共享接口:
ejbModule.interfaces.ABeanInterface
package ejbModule.interfaces;
import javax.ejb.Remote;
@Remote
public interface ABeanInterface {
public SrzedObjInterface getObject();
public String getString(); // To show that a simple String object can be passed
}
ejbModule.interfaces.SrzedObjInterface
package ejbModule.interfaces;
import java.io.Serializable;
public interface SrzedObjInterface extends Serializable {
public String getTheString();
}
EJB 项目具有以下类:
ejbModule.ejb.ABean:
package ejbModule.ejb;
import ejbModule.interfaces.ABeanInterface;
import ejbModule.obj.SrzedObj;
import ejbModule.interfaces.SrzedObjInterface;
import javax.ejb.Stateless;
@Stateless
public class ABean implements ABeanInterface {
@Override
public SrzedObjInterface getObject() {
return new SrzedObj();
}
@Override
public String getString() {
return "This is not the String I want";
}
}
ejbModule.obj
package ejbModule.obj;
import ejbModule.interfaces.SrzedObjInterface;
import java.io.Serializable;
public class SrzedObj implements SrzedObjInterface, Serializable {
protected String TheString = "This is the string I want";
@Override
public String getTheString() {
return TheString;
}
}
Web 项目包括 JSF 库,并具有以下类和测试网页,以及标准 beans.xml 文件(未显示)和 web.xml 文件(未显示):
webModule.webbean
package webModule;
import ejbModule.interfaces.ABeanInterface;
import ejbModule.interfaces.SrzedObjInterface;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
@Named
@RequestScoped
public class webbean {
@EJB
private ABeanInterface ABeanInstance;
// The string I want
public String getStringViaObject() {
// Code that produces the error
// ----------------------------
//SrzedObjInterface SrzedObject = ABeanInstance.getObject(); // Throws the NullPointerException
//return SrzedObject.getAString();
// ----------------------------
return "";
}
// The string that I don't want
public String getString() {
return ABeanInstance.getString();
}
// Also not the string I want, but here to show that this is possible
public String getLocalString() {
return "The local string";
}
}
索引.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
</h:head>
<h:body>
<h1>The strings</h1>
<p>The local string: <h:outputText value="#{webbean.localString}"/></p>
<p>The string: <h:outputText value="#{webbean.string}"/></p>
<p>The string from the object: <h:outputText value="#{webbean.stringViaObject}"/></p>
</h:body>
</html>
除了 Netbeans 为我包含的标准文件之外,仅此而已。
由此产生的堆栈跟踪(引入了问题代码)是:
SEVERE: Error Rendering View[/index.xhtml]
javax.el.ELException: /index.xhtml @18,90 value="#{webbean.stringViaObject}": java.lang.NullPointerException
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIOutput.getValue(UIOutput.java:169)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at com.sun.corba.ee.impl.orbutil.ClassInfoCache$ClassInfo.<init>(ClassInfoCache.java:156)
at com.sun.corba.ee.impl.orbutil.ClassInfoCache.get(ClassInfoCache.java:281)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1097)
at com.sun.corba.ee.impl.encoding.CDRInputObject.read_value(CDRInputObject.java:531)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$14.read(DynamicMethodMarshallerImpl.java:384)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.readResult(DynamicMethodMarshallerImpl.java:483)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:203)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:152)
at com.sun.corba.ee.impl.presentation.rmi.codegen.CodegenStubBase.invoke(CodegenStubBase.java:227)
at ejbModule.interfaces.__ABeanInterface_Remote_DynamicStub.getObject(ejbModule/interfaces/__ABeanInterface_Remote_DynamicStub.java)
at ejbModule.interfaces._ABeanInterface_Wrapper.getObject(ejbModule/interfaces/_ABeanInterface_Wrapper.java)
at webModule.webbean.getStringViaObject(webbean.java:18)
at webModule.webbean$Proxy$_$$_WeldClientProxy.getStringViaObject(webbean$Proxy$_$$_WeldClientProxy.java)
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:601)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:363)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstValue.getValue(AstValue.java:138)
at com.sun.el.parser.AstValue.getValue(AstValue.java:183)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
... 41 more
非常感谢任何有耐心阅读所有内容的人!我真的很感激任何帮助。