We're in the processing of moving a Weblogic 10.3.6 app to Weblogic 12.2.1.2. We have many EJB 2.1 beans that form part of the app. We've hit a strange problem with some of these beans.
When we have 1 ejb call another and this bean throws a checked exception (e.g. RuleException extends Exception) this is thrown as a RemoteException (RemoteEJBInvokeException). This only occurs if the app is running in a cluster. If I deploy against a standalone jvm it works fine.
The general EJB pattern is a Facade pattern. In the Facade bean we use a standard JNDI lookup to locate the Home and then run the create method to return the business interface/impl
InitialContext ctx = new InitialContext();
ReportManagementHome reportManagementHome = (ReportManagementHome) ctx.lookup("ReportManagement");
ReportManagement reportManagement = reportManagementHome.create();
ReportManagement bean runs the business logic and throws a RuleException.
This is an example method in the facade that calls the 2nd bean:
public String doTest() {
String s = null;
try
{
s = reportManagement.doValidate();
}
catch ( RuleException re )
{
rollBack();
} catch (RemoteException e)
{
e.printStackTrace();
}
return s;
}
Here is the doValidate() method in the 2nd bean:
public String doValidate( )
throws RuleException, CustomException
{
int test = 1;
if (test == 1)
{
throw new RuleException();
}
return "Hello";
}
Although the RuleException is correctly reached and thrown, by the time the facade catches it it is a RemoteException.
This is an example list of the ejbs/interfaces:
ReportManagement
ReportManagementBean
ReportManagementFacade
ReportManagementFacadeBean
ReportManagementFacadeHome
ReportManagementFacadeLocal
ReportManagementFacadeLocalHome
ReportManagementHome
ReportManagementLocal
ReportManagementLocalHome
Here is the ejb-jar.xml
<?xml version='1.0' encoding='UTF-8'?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
version="2.1">
<enterprise-beans>
<session>
<display-name>ReportManagementFacade</display-name>
<ejb-name>ReportManagementFacade</ejb-name>
<home>com.ejb.ReportManagementFacadeHome</home>
<remote>com.ejb.ReportManagementFacade</remote>
<local-home>com.ejb.ReportManagementFacadeLocalHome</local-home>
<local>com.ejb.ReportManagementFacadeLocal</local>
<ejb-class>com.ejb.ReportManagementFacadeBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
<session>
<display-name>ReportManagement</display-name>
<ejb-name>ReportManagement</ejb-name>
<home>com.ejb.ReportManagementHome</home>
<remote>com.ejb.ReportManagement</remote>
<local-home>com.ejb.ReportManagementLocalHome</local-home>
<local>com.ejb.ReportManagementLocal</local>
<ejb-class>com.ejb.ReportManagementBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>ReportManagementFacade</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
<container-transaction>
<method>
<ejb-name>ReportManagement</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
Here is the weblogic-ejb-jar.xml
<?xml version='1.0' encoding='UTF-8'?>
<weblogic-ejb-jar xmlns="http://xmlns.oracle.com/weblogic/weblogic-ejb-jar"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-ejb-jar http://xmlns.oracle.com/weblogic/weblogic-ejb-jar/1.2/weblogic-ejb-jar.xsd">
<weblogic-enterprise-bean>
<ejb-name>ReportManagementFacade</ejb-name>
<jndi-name>Destin8.ejb.reportmanagement.ReportManagementFacade</jndi-name>
<local-jndi-name>Destin8.ejb.reportmanagement.ReportManagementFacadeLocal</local-jndi-name>
<enable-call-by-reference>true</enable-call-by-reference>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ReportManagement</ejb-name>
<jndi-name>Destin8.ejb.reportmanagement.ReportManagement</jndi-name>
<local-jndi-name>Destin8.ejb.reportmanagement.ReportManagementLocal</local-jndi-name>
<enable-call-by-reference>true</enable-call-by-reference>
</weblogic-enterprise-bean>
<weblogic-compatibility>
<entity-always-uses-transaction>true</entity-always-uses-transaction>
</weblogic-compatibility>
</weblogic-ejb-jar>
And here is the StackTrace:
weblogic.rmi.RemoteEJBInvokeException: null; nested exception is:
com.exception.RuleException
at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invoke(SessionRemoteMethodInvoker.java:27)
at com.ejb.ReportManagement_tq6u66_EOImpl.doLUMValidate(Unknown Source)
at com.ejb.ReportManagementFacadeBean.doLUM(ReportManagementFacadeBean.java:82)
at com.ejb.ReportManagementFacade_sidvua_EOImpl.__WL_invoke(Unknown Source)
at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invokeInternal(SessionRemoteMethodInvoker.java:54)
at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invoke(SessionRemoteMethodInvoker.java:21)
at com.ejb.ReportManagementFacade_sidvua_EOImpl.doLUM(Unknown Source)
at com.ajf.Page1ManagedBean.refreshDate(Page1ManagedBean.java:105)
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 com.sun.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:181)
at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
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:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:650)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:286)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:260)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:350)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:32)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3683)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3649)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:326)
at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197)
at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2433)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2281)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2259)
at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1691)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1651)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:270)
at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:348)
at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:333)
at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:54)
at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:640)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:406)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:346)
Caused by: com.exception.RuleException
at com.ejb.ReportManagementBean.doLUMValidate(ReportManagementBean.java:92)
at com.ejb.ReportManagement_tq6u66_EOImpl.__WL_invoke(Unknown Source)
at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invokeInternal(SessionRemoteMethodInvoker.java:54)
at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invoke(SessionRemoteMethodInvoker.java:21)
... 55 more
Any guidance in this matter will be much appreciated.
This was fixed in a patch by Oracle on my request. The link for that patch is here Patch Link. You will need an Oracle Support log on to be able to access it.
This:
<enable-call-by-reference>true</enable-call-by-reference>
causes your remote calls in the same JVM to have local call semantics, including exception handling.
Related
The setup I have is that I am using Maven to build a Spring API project and generating a .WAR file. This war file is being deployed to a Tomcat server. My setup works locally in Eclipse with no issues or problems, and calls the correct queries/etc. However when I attempt to deploy it to the Tomcat server, I get the following error:
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findDetails found for type EmployeeInfo!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:94)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:382)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:358)
at org.springframework.data.mapping.PropertyPath.lambda$from$0(PropertyPath.java:311)
at java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:324)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:293)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:276)
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:81)
at org.springframework.data.repository.query.parser.PartTree$OrPart.lambda$new$0(PartTree.java:250)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566)
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:251)
at org.springframework.data.repository.query.parser.PartTree$Predicate.lambda$new$0(PartTree.java:380)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566)
at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:381)
at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:93)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:76)
... 96 more
I am not sure if we are missing something required to bridge the connection, or there is maybe a setting that is needed. Any assistance is welcome - I have included as many relevant files as I can think of, but let me know if anything else might be required and I will upload it too.
EmployeeInfoRepository
#Repository
public interface EmployeeInfoRepository extends JpaRepository<EmployeeInfo, Integer> {
#Query(nativeQuery = true)
public List<EmployeeInfo> findDetails(#Param("id") String id);
}
orm.xml (please note, it is located in src/main/resources/META-INF/)
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.0" xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
http://java.sun.com/xml/ns/persistence/orm_2_0.xsd ">
<named-native-query name="EmployeeInfo.findDetails" result-class="com.place.thing.model.EmployeeInfo">
<query>SELECT ... </query>
</named-native-query>
</entity-mappings>
EmployeeInfoController
#GetMapping("/intake/{id}")
public ResponseEntity<EmployeeIntakeInfoResponse> getEmployeeInfo(#PathVariable(value = "id") String id) throws ResourceNotFoundException {
List<EmployeeInfo> result = intakeFormRepo.findDetails(id);
if (result.size() != 1) {
throw new ResourceNotFoundException("Error Message Here");
}
return ResponseEntity.ok().body(new EmployeeInfoResponse(result.get(0)));
}
My Payara REST API is working fine without DB Connection, and also Postgres localhost connection works fine through DriverManager i.e.:
Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres", "postgres", "pass#123")
However, Datasource for postgresql in web.xml & Resource is throwing NullPointerException in below code:
public class AppService {
#Resource(name="java:global/esWf")
DataSource ds;
public Response test (
...
Connection conn = ds.getConnection();
...
WEB-INF/web.xml: -
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<display-name>PG-DataSource</display-name>
<data-source>
<name>java:global/esWf</name>
<class-name>org.postgresql.ds.PGSimpleDataSource</class-name>
<url>jdbc:postgresql://localhost:5432/postgres</url>
<user>postgres</user>
<password>pass#123</password>
<property>
<name>fish.payara.slow-query-threshold-in-seconds</name>
<value>5</value>
</property>
</data-source>
</web-app>
I have also tried replacing url with separate elements for server, port, db name!
This is first time I am trying to connect via Datasource & Resource, and could be am missing something minor!
Links referred: - https://blog.payara.fish/setting-up-a-data-source-in-payara-micro,
https://dzone.com/articles/easy-java-ee-microservices-with-payara-micro,
Payara DB Examples etc
Error: -
java.lang.NullPointerException
at es.dms.DmsSrv.test(DmsSrv.java:65)
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.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:124)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:167)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:176)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:79)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:469)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:391)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:80)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:253)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:232)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:680)
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:394)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:366)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:319)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1636)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:259)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:757)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:577)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:158)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:520)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:217)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:182)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:156)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:218)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:95)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:260)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:177)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:109)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:88)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:53)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:524)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:33)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
at java.lang.Thread.run(Thread.java:748)
This looks like the same issue as in resource injection in cdi bean.
Injection using #Resource doesn't work in plain CDI beans and JAX-RS resources. It only works in enterprise beans.
You have 2 options:
turn your bean into a stateless EJB - just add #Stateless annotation to the class:
#Stateless
#RequestScoped
#Path("app")
public class AppService {
#Resource(name="java:global/esWf")
DataSource ds;
public Response test (
Create a CDI producer and then inject the datasource as a CDI bean. The best practice is to use a qualifier to mark which DS you want to inject (in case there are multiple datasources in the app):
#Qualifier
#Retention(RUNTIME)
#Target({METHOD, FIELD, PARAMETER, TYPE})
public #interface Eswf {
}
---------------
#RequestScoped
public DsProducer {
#Produces
#Resource(name="java:global/esWf")
#Eswf
Datasource eswfDatasource;
}
------------------
#RequestScoped
#Path("app")
public class AppService {
#Inject
#Eswf
DataSource ds;
public Response test (
P.S. I think that you also need to change the JNDI name to use the java:app/ namespace instad of java:global/ because the DS should be available only to the deployed application. You can test whether you can retrieve the DS by JNDI name using `new InitialContext().lookup("java:global/esWf"). That should work anywhere in your application, not only in EJBs.
I created Java web application and trying to force atmosphere to use JSR-356 since, as I understood, it's the only way to use original javax.servlet.HttpSession from AtmosphereResource object.
When I deploy my application to Jetty (v. 9.3.7), I get the following errors:
16:45:16.535 [Scanner-1] ERROR org.atmosphere.util.IOUtils -
java.lang.IllegalStateException: Unable to configure jsr356 at that stage. No Servlet associated with Key[type=org.atmosphere.guice.AtmosphereGuiceServlet, annotation=[none]]
at org.atmosphere.util.IOUtils.guestRawServletPath(IOUtils.java:274) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.util.IOUtils.guestServletPath(IOUtils.java:248) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.container.JSR356AsyncSupport.<init>(JSR356AsyncSupport.java:63) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.container.JSR356AsyncSupport.<init>(JSR356AsyncSupport.java:40) [atmosphere-runtime-2.4.3.jar:2.4.3]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [na:1.8.0_74]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) [na:1.8.0_74]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [na:1.8.0_74]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) [na:1.8.0_74]
at org.atmosphere.cpr.DefaultAsyncSupportResolver.newCometSupport(DefaultAsyncSupportResolver.java:234) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.DefaultAsyncSupportResolver.resolveWebSocket(DefaultAsyncSupportResolver.java:306) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.DefaultAsyncSupportResolver.resolve(DefaultAsyncSupportResolver.java:292) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.AtmosphereFramework.autoDetectContainer(AtmosphereFramework.java:2082) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.AtmosphereFramework.init(AtmosphereFramework.java:914) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.AtmosphereFramework.init(AtmosphereFramework.java:838) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.AtmosphereFrameworkInitializer.configureFramework(AtmosphereFrameworkInitializer.java:75) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.AtmosphereServlet.configureFramework(AtmosphereServlet.java:84) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.AtmosphereServlet.configureFramework(AtmosphereServlet.java:80) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.AtmosphereServlet.init(AtmosphereServlet.java:75) [atmosphere-runtime-2.4.3.jar:2.4.3]
at com.google.inject.servlet.ServletDefinition.init(ServletDefinition.java:121) [guice-servlet-4.0.jar:na]
at com.google.inject.servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:82) [guice-servlet-4.0.jar:na]
at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:103) [guice-servlet-4.0.jar:na]
at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:220) [guice-servlet-4.0.jar:na]
at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:137) [jetty-servlet-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:856) [jetty-servlet-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:350) [jetty-servlet-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1379) [jetty-webapp-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1341) [jetty-webapp-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:772) [jetty-server-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:263) [jetty-servlet-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:517) [jetty-webapp-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:41) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:188) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:499) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:147) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:180) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(WebAppProvider.java:458) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:610) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:529) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:392) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.util.Scanner$1.run(Scanner.java:329) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115]
at java.util.TimerThread.mainLoop(Timer.java:555) [na:1.8.0_74]
at java.util.TimerThread.run(Timer.java:505) [na:1.8.0_74]
16:45:16.536 [Scanner-1] ERROR o.a.cpr.DefaultAsyncSupportResolver - Real error: Unable to configure jsr356 at that stage
java.lang.IllegalStateException: Unable to configure jsr356 at that stage
at org.atmosphere.util.IOUtils.guestRawServletPath(IOUtils.java:292) ~[atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.util.IOUtils.guestServletPath(IOUtils.java:248) ~[atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.container.JSR356AsyncSupport.<init>(JSR356AsyncSupport.java:63) ~[atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.container.JSR356AsyncSupport.<init>(JSR356AsyncSupport.java:40) ~[atmosphere-runtime-2.4.3.jar:2.4.3]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_74]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_74]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_74]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_74]
at org.atmosphere.cpr.DefaultAsyncSupportResolver.newCometSupport(DefaultAsyncSupportResolver.java:234) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.DefaultAsyncSupportResolver.resolveWebSocket(DefaultAsyncSupportResolver.java:306) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.DefaultAsyncSupportResolver.resolve(DefaultAsyncSupportResolver.java:292) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.AtmosphereFramework.autoDetectContainer(AtmosphereFramework.java:2082) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.AtmosphereFramework.init(AtmosphereFramework.java:914) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.AtmosphereFramework.init(AtmosphereFramework.java:838) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.AtmosphereFrameworkInitializer.configureFramework(AtmosphereFrameworkInitializer.java:75) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.AtmosphereServlet.configureFramework(AtmosphereServlet.java:84) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.AtmosphereServlet.configureFramework(AtmosphereServlet.java:80) [atmosphere-runtime-2.4.3.jar:2.4.3]
at org.atmosphere.cpr.AtmosphereServlet.init(AtmosphereServlet.java:75) [atmosphere-runtime-2.4.3.jar:2.4.3]
at com.google.inject.servlet.ServletDefinition.init(ServletDefinition.java:121) [guice-servlet-4.0.jar:na]
at com.google.inject.servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:82) [guice-servlet-4.0.jar:na]
at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:103) [guice-servlet-4.0.jar:na]
at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:220) [guice-servlet-4.0.jar:na]
at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:137) [jetty-servlet-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:856) [jetty-servlet-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:350) [jetty-servlet-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1379) [jetty-webapp-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1341) [jetty-webapp-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:772) [jetty-server-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:263) [jetty-servlet-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:517) [jetty-webapp-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:41) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:188) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:499) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:147) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:180) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(WebAppProvider.java:458) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:610) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:529) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:392) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115]
at org.eclipse.jetty.util.Scanner$1.run(Scanner.java:329) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115]
at java.util.TimerThread.mainLoop(Timer.java:555) [na:1.8.0_74]
at java.util.TimerThread.run(Timer.java:505) [na:1.8.0_74]
If I force native API to take the precedence with the following code
params.put(ApplicationConfig.WEBSOCKET_SUPPRESS_JSR356, "true");
then everything works fine.
Here is my deployment descriptor:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<listener>
<listener-class>com.sample.guice.GuiceContextListener</listener-class>
</listener>
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
The module used to provide all the bindings:
public class ServerModule extends AbstractModule
{
#Override
protected void configure()
{
install(new ServletModule() {
#Override
protected void configureServlets()
{
Map<String, String> params = new HashMap<>();
// params.put(ApplicationConfig.WEBSOCKET_SUPPRESS_JSR356, "true");
serve("/atmosphere").with(AtmosphereGuiceServlet.class, params);
}
});
}
}
I omitted the class annotated with #ManagedService and some other code since there are no problems. As I said, everything works fine with native websocket API.
the message:
Unable to configure jsr356 at that stage
means, that the jsr356 support needs to be added during ServletContextInitialization phase, the best in a ServletContextListener
my problem is that jetty 9.4 native websocket is not compatible with atmosphere anymore, on the other hand jsr356 is not compatible with guice
I managed to make jsr356 work with vaadin 8.8.1 and jetty 9.4, but it requires the VaadinServlet to be directly managed by Jetty. This doesn't work with Guice, which installs it's own GuiceFilter, and the servlets are not registered to Jetty directly.
look at JSR356WebsocketInitializer.initAtmosphereForVaadinServlet for more information
You can just add ApplicationConfig.JSR356_MAPPING_PATH initParameter and give it a try.
If it doesn't work ,may be you can initialize atmosphere framework explicitly and specify init param
ApplicationConfig.JSR356_MAPPING_PATH as valid key value pair .
For initialization you can see org.atmosphere.cpr.ContainerInitializer and for adding the path while initalizing the atmosphere framework
final AtmosphereFramework framework = AtmosphereFrameworkInitializer.newAtmosphereFramework(c, false, true);
// Hack to make jsr356 works. Pretty ugly.
DefaultAsyncSupportResolver resolver = new DefaultAsyncSupportResolver(framework.getAtmosphereConfig());
framework.getAtmosphereConfig().addInitParam(ApplicationConfig.JSR356_MAPPING_PATH,appropriateservletPath);
I install jetty 9 server in my Ubuntu server VCS. Structure of java rest project:
/opt/jetty/webapps/backend /
build
conf
lib
libs
logs
src/com/example/package/backend
resources
CategoryResource.java
BackendServer.java
web
WEB-INF
web.xml
BackendServer.java
import com.sun.jersey.api.container.httpserver.HttpServerFactory;
import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.net.httpserver.HttpServer;
public class BackendServer {
public static void main(String[] args) throws IOException {
HttpServer server = HttpServerFactory.create("http://localhost:" + "8080" + "/" + "backend/rest", new PackagesResourceConfig("com.droidbrew.androcommerce.backend.resources"));
DbManager.getInstance();
server.start();
System.out.println("Server running");
System.out.println("Hit return to stop...");
System.in.read();
System.out.println("Stopping server");
server.stop(0);
System.out.println("Server stopped");
}
}
CategoryResource.java
Path("/category")
public class CategoryResource {
#GET
#Path("/get_all_categories")
#Produces({MediaType.APPLICATION_JSON})
public String getAllCategories() throws SQLException {
List<Category> categoryList = DbManager.getInstance().getBackendCategoryManager().getAllCategories();
Gson gson = new Gson();
return gson.toJson(categoryList);
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Jersey</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.droidbrew.androcommerce.backend.resources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
/opt/jetty/webapps/backend.xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<Set name="configurationClasses">
<Array type="java.lang.String">
<Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item>
<Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>
<Item>org.mortbay.jetty.plus.webapp.Configuration</Item>
<Item>org.mortbay.jetty.webapp.JettyWebXmlConfiguration</Item>
<Item>org.mortbay.jetty.webapp.TagLibConfiguration</Item>
</Array>
</Set>
<Set name="contextPath">/</Set>
<Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/webapps/backend</Set>
<New id="development" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>jdbc/development</Arg>
<Arg>
<New class="org.postgresql.ds.PGConnectionPoolDataSource">
<Set name="User">user</Set>
<Set name="Password">1111</Set>
<Set name="DatabaseName">development</Set>
<Set name="ServerName">localhost</Set>
<Set name="PortNumber">5432</Set>
</New>
</Arg>
</New>
</Configure>
But after I start service jetty start and try connect ip:8085/backend/rest/category/get_all_categories I get:
HTTP ERROR: 404
Problem accessing /backend/rest/category/get_all_categories. Reason:
Not Found
UPDATE
Logs after java -DDEBUG -jar start.jar
sudo java -DDEBUG -jar start.jar
System Property [DEBUG] has been deprecated! (Use org.eclipse.jetty.LEVEL=DEBUG instead)
2014-10-06 13:09:09.522:INFO::main: Logging initialized #1090ms
ShutdownMonitor not in use (port < 0): -1
2014-10-06 13:09:10.047:INFO:oejs.Server:main: jetty-9.2.3.v20140905
2014-10-06 13:09:10.073:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/opt/jetty/webapps/] at interval 1
2014-10-06 13:09:10.096:WARN:oejd.DeploymentManager:main: Unable to reach node goal: started
java.lang.ClassNotFoundException: org.mortbay.jetty.webapp.WebAppContext
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 java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.eclipse.jetty.util.Loader.loadClass(Loader.java:86)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.nodeClass(XmlConfiguration.java:364)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:304)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:262)
at org.eclipse.jetty.deploy.providers.WebAppProvider.createContextHandler(WebAppProvider.java:291)
at org.eclipse.jetty.deploy.App.getContextHandler(App.java:101)
at org.eclipse.jetty.deploy.bindings.StandardDeployer.processBinding(StandardDeployer.java:36)
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186)
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:498)
at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:146)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:180)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64)
at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:609)
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:528)
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:391)
at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:313)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:150)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:560)
at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:235)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
at org.eclipse.jetty.server.Server.start(Server.java:387)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
at org.eclipse.jetty.server.Server.doStart(Server.java:354)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1255)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1174)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.jetty.start.Main.invokeMain(Main.java:310)
at org.eclipse.jetty.start.Main.start(Main.java:786)
at org.eclipse.jetty.start.Main.main(Main.java:111)
2014-10-06 13:09:10.111:WARN:oejuc.AbstractLifeCycle:main: FAILED ServerConnector#1d402894{HTTP/1.1}{0.0.0.0:8080}: java.net.BindException: Address already in use
java.net.BindException: Address already in use
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:444)
at sun.nio.ch.Net.bind(Net.java:436)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:320)
at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.server.Server.doStart(Server.java:366)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1255)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1174)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.jetty.start.Main.invokeMain(Main.java:310)
at org.eclipse.jetty.start.Main.start(Main.java:786)
at org.eclipse.jetty.start.Main.main(Main.java:111)
2014-10-06 13:09:10.114:WARN:oejuc.AbstractLifeCycle:main: FAILED org.eclipse.jetty.server.Server#5f281b8c: java.net.BindException: Address already in use
java.net.BindException: Address already in use
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:444)
at sun.nio.ch.Net.bind(Net.java:436)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:320)
at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.server.Server.doStart(Server.java:366)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1255)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1174)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.jetty.start.Main.invokeMain(Main.java:310)
at org.eclipse.jetty.start.Main.start(Main.java:786)
at org.eclipse.jetty.start.Main.main(Main.java:111)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.jetty.start.Main.invokeMain(Main.java:310)
at org.eclipse.jetty.start.Main.start(Main.java:786)
at org.eclipse.jetty.start.Main.main(Main.java:111)
Caused by: java.net.BindException: Address already in use
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:444)
at sun.nio.ch.Net.bind(Net.java:436)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:320)
at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.server.Server.doStart(Server.java:366)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1255)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1174)
... 7 more
Your XML files are referencing an old version of Jetty.
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
The org.mortbay.jetty namespace is for Jetty 6 or older versions of Jetty, (all of which have been EOLd for years now).
That entire XML document is wrong for Jetty 9, from the DOCTYPE, to the class references, even to the structure.
The <SystemProperty> element references a "jetty.home" variable that isn't used in jetty embedded (its only there for the jetty distribution, aka start.jar). The jetty-http-spi.jar doesn't even set or use this property.
The use of the Jetty Context XML Deployable is a feature that jetty-deploy.jar provides, however, that sort of deployable is not supported by the com.sun.net.httpserver.HttpServer concepts, either as a standalone deployable, or an internal WEB-INF/jetty-web.xml configuration.
That whole backend server war you are attempting to setup just cannot be on the com.sun.net.httpserver.HttpServer you started (not supported by that concept at a fundamental level)
Unfortunately, there is almost no troubleshooting available when you use the com.sun.net.httpserver.HttpServer techniques. Pretty much limited to logging output.
What does the logging output show?
Update: 2014, Oct 7:
About the logging output, lets see.
You are starting jetty via command line, using the Jetty 9.2.3 distribution.
That act is completely unrelated to your BackendServer use of com.sun.net.httpserver.HttpServer.
This would result in 2 different servers.
The standalone Jetty 9.2.3 distribution server
The com.sun.net.httpserver.HttpServer server
You have essentially 2 errors showing in those logs.
First is ...
java.lang.ClassNotFoundException: org.mortbay.jetty.webapp.WebAppContext
That's because you are using Jetty 6 techniques for Jetty 9. That class (actually package namespace) doesn't exist in Jetty 9.
That class (in Jetty 9) would be called org.eclipse.jetty.webapp.WebAppContext, see Configuring a Specific Web App Deployment in the Eclipse Jetty documentation website for details.
You will have to analyze and adjust most things in your example XML file to fit the realities of the nearly 200 releases since Jetty 6 and Jetty 9. Far too much time has elapsed between Jetty 6 and Jetty 9 to list what has changed. It would be equivalent to listing the differences between a Ford Model 18 and a Tesla Model S (it would be a huge list that would essentially mean 'everything' and be useless to work off of)
The other error ...
FAILED ServerConnector#1d402894{HTTP/1.1}{0.0.0.0:8080}:
java.net.BindException: Address already in use
means that this server cannot bind to port 8080, as some other server is already there.
This makes sense, as your BackendServer is also on port 8080 (per your example code).
Don't try to mix embedded-jetty and com.sun.net.httpserver.HttpServer, you will only tear your hair out trying to force com.sun.net.httpserver.HttpServer into doing what you want.
Consider using straight embedded-jetty + jersey servlet instead.
There's lots of examples of this technique online and in StackOverflow.
Here's the first one I found that had example code showing how to setup the ServletHolder for the jersey ServletContainer along with some relevant init parameters to configure it. Configuring Jersey + Jetty + JSP
I am using EJB 2.1 in a separate module in a multi-module Maven Application. I am using indirect JNDI (ie. using java:comp/env/ Not used it much). Also I am using EJB 2.1 for the first time. But since this is only a local simple EJB so not much problem.
The wiered bit about it is that it was working but suddenly without having changed any part relevant to it, it has stopped working now and I am getting NameNotFoundException. The things are done correctly as it was working. I am pretty sure about it.
First my code,
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar id="ejb-jar_ID" version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
<display-name>sr-g0a-ejb</display-name>
<enterprise-beans>
<session id="CreateAclService">
<ejb-name>CreateAclService</ejb-name>
<local-home>com.sre.g0a.CreateAclServiceLocalHome</local-home>
<local>com.sre.g0a.CreateAclServiceLocal</local>
<ejb-class>com.sre.g0a.CreateAclServiceBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<security-identity>
<description></description>
<run-as>
<description></description>
<role-name>ACL_TECH_USER</role-name>
</run-as>
</security-identity>
</session>
</enterprise-beans>
<assembly-descriptor>
<security-role>
<description>
ACL_TECH_USER</description>
<role-name>ACL_TECH_USER</role-name>
</security-role>
<method-permission>
<role-name>ACL_TECH_USER</role-name>
<method>
<ejb-name>CreateAclService</ejb-name>
<method-intf>Local</method-intf>
<method-name>createAclRole</method-name>
<method-params>
<method-param>com.sre.edms.bsc.types.EDMSAcl</method-param>
<method-param>com.sre.edms.bsc.ids.EDMSDocumentID</method-param>
</method-params>
</method>
</method-permission>
<container-transaction>
<method>
<ejb-name>CreateAclService</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>NotSupported</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
The Snippet from the web module (on the server) where from I am accessing the EJB method.
Hashtable<String, String> hashTable = new Hashtable<String, String>();
hashTable.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
//hashTable.put(Context.PROVIDER_URL, "corbaloc:iiop:localhost:9080");
Context initialContext;
try {
initialContext = new InitialContext(hashTable);
CreateAclServiceLocalHome home = (CreateAclServiceLocalHome) initialContext
.lookup("java:comp/env/ejb/CreateAclService");
//.lookup("ejblocal:ejb/CreateAclServiceLocal");
CreateAclServiceLocal service = home.create();
eDMSAcl = service.createAclRole(eDMSAcl, edmsDocumentID);
} catch (NamingException ne) {
LOGGER.log(Level.WARNING, "NamingException Occured", ne);
throw new GEMException("Failed to create ACL. NamingException Occured");
} catch (CreateException ce) {
LOGGER.log(Level.WARNING, "CreateException Occured", ce);
throw new GEMException("Failed to create ACL");
} catch (BscServiceException be) {
LOGGER.log(Level.WARNING, "BscServiceException Occured", be);
throw new GEMException("Failed to create ACL");
}
Snippet from my web.xml which shows the ejb-ref tag
<ejb-local-ref id="EJBLocalRef_1343037878938">
<description>
</description>
<ejb-ref-name>ejb/CreateAclService</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.sre.g0a.CreateAclServiceLocalHome</local-home>
<local>com.sre.g0a.CreateAclServiceLocal</local>
<ejb-link>sr-g0a-ejb.jar#CreateAclService</ejb-link>
</ejb-local-ref>
Now the stacktrace of my Exception (NamingNotFoundException)
[7/24/12 12:34:26:629 IST] 00001720 GEMEBesUtil W NamingException Occured
com.ibm.websphere.naming.CannotInstantiateObjectException: A NameNotFoundException occurred on an indirect lookup on the name java:comp/env/ejb/CreateAclService. The name java:comp/env/ejb/CreateAclService maps to a JNDI name in deployment descriptor bindings for the application performing the JNDI lookup. Make sure that the JNDI name mapping in the deployment descriptor binding is correct. If the JNDI name mapping is correct, make sure the target resource can be resolved with the specified name relative to the default initial context. [Root exception is javax.naming.NameNotFoundException: Name ejb not found in context "ejblocal:".]
at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:1081)
at com.ibm.ws.naming.urlbase.UrlContextHelper.processBoundObjectForLookup(UrlContextHelper.java:181)
at com.ibm.ws.naming.java.javaURLContextRoot.processBoundObjectForLookup(javaURLContextRoot.java:850)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookupExt(UrlContextImpl.java:1454)
at com.ibm.ws.naming.java.javaURLContextImpl.lookupExt(javaURLContextImpl.java:477)
at com.ibm.ws.naming.java.javaURLContextRoot.lookupExt(javaURLContextRoot.java:485)
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:370)
at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161)
at javax.naming.InitialContext.lookup(InitialContext.java:436)
at com.sre.g0a.server.util.GEMEBesUtil.createEDMSAcl(GEMEBesUtil.java:250)
at com.sre.g0a.server.util.GEMEBesUtil.formSrGemDocForCreation(GEMEBesUtil.java:180)
at com.sre.g0a.server.services.ImportComponentServiceImpl.createDocument(ImportComponentServiceImpl.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:551)
at com.sre.g0a.server.integration.GWTSpringController.processCall(GWTSpringController.java:57)
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:595)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1188)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:763)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:454)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1020)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3703)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:962)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1659)
Caused by: javax.naming.NameNotFoundException: Name ejb not found in context "ejblocal:".
at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1969)
at com.ibm.ws.naming.ipbase.NameSpace.retrieveBinding(NameSpace.java:1376)
at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1219)
at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:1141)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookupExt(UrlContextImpl.java:1436)
at com.ibm.ws.naming.jndicos.CNContextImpl.lookupExt(CNContextImpl.java:1425)
at com.ibm.ws.naming.jndicos.CNContextImpl.lookupExt(CNContextImpl.java:1475)
at com.ibm.ws.naming.util.IndirectJndiLookupObjectFactory$1.run(IndirectJndiLookupObjectFactory.java:373)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
at com.ibm.ws.naming.util.IndirectJndiLookupObjectFactory.getObjectInstanceExt(IndirectJndiLookupObjectFactory.java:223)
at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:990)
... 44 more
The problem was the binding.xmi file was not getting included. Included that and it worked.