I am trying to deploy a simple web service to Glassfish. Here is the web service class:
import com.dv.testrunner.extended.Task;
import com.medallion.etl.exception.StepExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
/**
*
* #author dvargo
*/
#WebService(serviceName = "Execute")
public class Execute
{
/**
* Web service operation
*/
#WebMethod(operationName = "executeTask")
public boolean executeTask(#WebParam(name = "task") Task task)
{
boolean setUp = task.setUp();
boolean execute;
try
{
execute = task.execute();
}
catch (StepExecutionException ex)
{
Logger.getLogger(Execute.class.getName()).log(Level.SEVERE, null, ex);
return false;
}
return setUp && execute;
}
}
Task is a simple interface. Here is the interface:
package com.dv.testrunner.extended;
import com.medallion.etl.exception.StepExecutionException;
/**
*
* #author dvargo
*/
public interface Task
{
public boolean execute() throws StepExecutionException;
public boolean setUp();
}
When I try to deploy my web service via Netbeans, I get the following error:
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.RuntimeException: Servlet web service endpoint '' failure
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:138)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:294)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:462)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:382)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:355)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1064)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1244)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1232)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:459)
at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:209)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:168)
at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:238)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
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:680)
Does anyone have any ideas on what is happening and how I may fix it? Is it that I can not use Task as a parameter?
JAX-WS does not allow interfaces as method parameters. Try replacing Task with a class.
Not only JAX-WS does not allow interfaces, it even makes no sense in your case. How would you specify what the task is supposed to do? You need a concrete class as a parameter, and the class needs to be annotated with #XmlRootElement. If you want your endpoint to support different tasks, you will need more operations with different names to achieve that.
Related
I'm trying to create a project with glassfish JSF and JPA, but I'm having trouble with the persistence unit in the persistence.xml file.
The error is the following:
GlassFish 3.1 at localhost
2014-05-06T12:47:52.326-0300|INFO: Initializing Mojarra 2.1.6
(SNAPSHOT 20111206) for context '/K19-Integracao-JSF-JPA'
2014-05-06T12:47:52.649-0300|SEVERE:
WebModule[/K19-Integracao-JSF-JPA]PWC1270: Exception starting filter
br.com.k19.filters.JPAFilter java.lang.InstantiationException at
org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:124)
at
org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4685)
at
org.apache.catalina.core.StandardContext.start(StandardContext.java:5377)
at com.sun.enterprise.web.WebModule.start(WebModule.java:498) at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
at
com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2018)
at
com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
at
com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
at
org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
at
com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
at
com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
at
org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
at
com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
at
com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
at
com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
at
com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
at
com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
at
com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
at
com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
at
com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
at
com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
at
com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
at
com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
at
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at
com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
at
com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at
com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
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:744) Caused by:
javax.persistence.PersistenceException: No Persistence provider for
EntityManager named k19pu at
javax.persistence.Persistence.createEntityManagerFactory(Unknown
Source) at
javax.persistence.Persistence.createEntityManagerFactory(Unknown
Source) at br.com.k19.filters.JPAFilter.init(JPAFilter.java:57) at
org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:264)
at
org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:120)
... 41 more
2014-05-06T12:47:52.662-0300|INFO: WEB0671: Loading application
[K19-Integracao-JSF-JPA] at [/K19-Integracao-JSF-JPA]
2014-05-06T12:47:52.693-0300|INFO: K19-Integracao-JSF-JPA was
successfully deployed in 774 milliseconds.
2014-05-06T12:47:53.049-0300|SEVERE: Error Rendering
View[/carros.xhtml] javax.el.ELException: /carros.xhtml #24,58
rendered="#{not empty carroBean.carros}":
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.UIComponentBase.isRendered(UIComponentBase.java:413)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1751)
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
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:1542)
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:849)
at
com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at
com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
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:744) Caused by:
java.lang.NullPointerException at
br.com.k19.modelo.CarroRepository.buscaTodos(CarroRepository.java:21)
at br.com.k19.controle.CarroBean.getCarros(CarroBean.java:30) 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
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.parser.AstEmpty.getValue(AstEmpty.java:66) at
com.sun.el.parser.AstNot.getValue(AstNot.java:63) at
com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
at
com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
... 35 more
2014-05-06T12:47:53.053-0300|WARNING: StandardWrapperValve[Faces
Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw
exception java.lang.NullPointerException at
br.com.k19.modelo.CarroRepository.buscaTodos(CarroRepository.java:21)
at br.com.k19.controle.CarroBean.getCarros(CarroBean.java:30) 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
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.parser.AstEmpty.getValue(AstEmpty.java:66) at
com.sun.el.parser.AstNot.getValue(AstNot.java:63) at
com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
at
com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at
javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at
javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:413)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1751)
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
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:1542)
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:849)
at
com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at
com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
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:744)
And the classes I am using are as follows:
package br.com.k19.modelo;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
public class CarroRepository {
private EntityManager manager;
public CarroRepository(EntityManager manager) {
this.manager = manager;
}
public void adiciona(Carro carro) {
this.manager.persist(carro);
}
public List<Carro> buscaTodos() {
Query query = this.manager.createQuery("select x from Carro x");
return query.getResultList();
}
}
package br.com.k19.modelo;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
#Entity
public class Carro implements Serializable {
/**
*
*/
private static final long serialVersionUID = 4209908627808946183L;
#Id #GeneratedValue
private Long id;
private String marca;
private String modelo;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getMarca() {
return marca;
}
public void setMarca(String marca) {
this.marca = marca;
}
public String getModelo() {
return modelo;
}
public void setModelo(String modelo) {
this.modelo = modelo;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}
package br.com.k19.filters;
import java.io.IOException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
#WebFilter(servletNames={"Faces Servlet"})
public class JPAFilter implements Filter {
private EntityManagerFactory factory;
#Override
public void destroy() {
this.factory.close();
}
#Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// Chegada
EntityManager manager = factory.createEntityManager();
request.setAttribute("EntityManager", manager);
manager.getTransaction().begin();
// Chegada
// Faces Servelet
chain.doFilter(request, response);
// Faces Servelet
// Saída
try {
manager.getTransaction().commit();
} catch(Exception e) {
manager.getTransaction().rollback();
} finally {
manager.close();
}
// Saída
}
#Override
public void init(FilterConfig filterConfig) throws ServletException {
this.factory = Persistence.createEntityManagerFactory("K19-PU");
}
}
package br.com.k19.controle;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.servlet.http.HttpServletRequest;
import br.com.k19.modelo.Carro;
import br.com.k19.modelo.CarroRepository;
#ManagedBean
public class CarroBean {
private Carro carro = new Carro();
public void adicionaCarro() {
EntityManager manager = this.getEntityManager();
CarroRepository repository = new CarroRepository(manager);
repository.adiciona(carro);
carro = new Carro();
}
public List<Carro> getCarros() {
EntityManager manager = this.getEntityManager();
CarroRepository repository = new CarroRepository(manager);
return repository.buscaTodos();
}
private EntityManager getEntityManager() {
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext ec = fc.getExternalContext();
HttpServletRequest request = (HttpServletRequest) ec.getRequest();
EntityManager manager = (EntityManager) request.getAttribute("EntityManager");
return manager;
}
public Carro getCarro() {
return carro;
}
public void setCarro(Carro carro) {
this.carro = carro;
}
}
And the file carro.xhtml
<!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:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>K19 treinamentos</title>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="Marca: " for="campo-marca" />
<h:inputText value="#{carroBean.carro.marca}" id="campo-marca" />
<h:outputLabel value="Modelo: " for="campo-modelo" />
<h:inputText value="#{carroBean.carro.modelo}" id="campo-modelo" />
<h:commandButton action="#{carroBean.adicionaCarro}" value="Adicionar" />
</h:panelGrid>
</h:form>
<h:panelGroup rendered="#{not empty carroBean.carros}" >
<h1>Lista de Carros</h1>
<ul>
<ui:repeat value="#{carroBean.carros}" var="carro">
<li> <h:outputText value="#{carro.marca} #{carro.modelo}" /> </li>
</ui:repeat>
</ul>
</h:panelGroup>
</h:body>
</html>
My persistence.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="K19-PU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="admin" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/K19DB"/>
</properties>
</persistence-unit>
</persistence>
My persistence.xml in this folder: ~/workspace/K19-Integracao-JSF-JPA/src/META-INF/persistence.xml
I put the mysql connector jar in the glassfish directory:
/opt/glassfish3/glassfish/lib/mysql-connector-java-5.1.30-bin.jar
I'm sorry for posting so much, is that I'm already crazy with this error.
I already searched a lot on the internet and can not resolve the problem, please can someone help me?
I think should always look at the root cause of exception. In your case
Caused by: javax.persistence.PersistenceException:
No Persistence provider for EntityManager named k19pu at javax.persistence.Persistence.createEntityManagerFactory
Your persistence.xml is not valid that's why EntityManagerFactory can't be get created.
due this you are also getting NLP at CarroRepository#buscaTodos method
Caused by: java.lang.NullPointerException at br.com.k19.modelo.CarroRepository.buscaTodos
So Please correct your Persistence.xml and make sure same PU. hope this will solve your problem
Here's the problem:
2014-05-06T12:47:53.049-0300|SEVERE: Error Rendering View[/carros.xhtml] javax.el.ELException: /carros.xhtml #24,58 rendered="#{not empty carroBean.carros}": java.lang.NullPointerException
...
Caused by: java.lang.NullPointerException at br.com.k19.modelo.CarroRepository.buscaTodos(CarroRepository.java:21) at br.com.k19.controle.CarroBean.getCarros(CarroBean.java:30)
Looking until CarroRepository#buscaTodos, line 21 of CarroRepository.java: file, we get this line:
Query query = this.manager.createQuery("select x from Carro x");
The NullPointerException means that EntityManager manager is null.
You have to check why the EntityManagerFactory cannot create a new instance of EntityManager in your JPAFilter servlet filter.
I have an ejb file that contains some files and a message driven bean.
When I run my ejb file, I got this error.
EJB Container initialization error.
However, when I remove the message driven bean from my ejb. My ejb can run smoothly.
Any ideas on how to resolve this issue?
Error of Glassfish server here
http://pastebin.com/HkyRFnwE
SEVERE: Exception while loading the app : EJB Container initialization error
java.lang.Exception
at com.sun.enterprise.connectors.inbound.ConnectorMessageBeanClient.setup(ConnectorMessageBeanClient.java:233)
at com.sun.ejb.containers.MessageBeanContainer.<init>(MessageBeanContainer.java:205)
at com.sun.ejb.containers.ContainerFactoryImpl.createContainer(ContainerFactoryImpl.java:121)
at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:230)
at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:305)
at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:108)
at org.glassfish.internal.data.ModuleInfo.load(ModuleInfo.java:186)
at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:264)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:460)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
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:724)
Caused by: java.security.PrivilegedActionException: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.enterprise.connectors.inbound.ConnectorMessageBeanClient.getActivationSpec(ConnectorMessageBeanClient.java:257)
at com.sun.enterprise.connectors.inbound.ConnectorMessageBeanClient.setup(ConnectorMessageBeanClient.java:213)
... 36 more
Caused by: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException
at com.sun.enterprise.connectors.util.SetMethodAction.handleException(SetMethodAction.java:152)
at com.sun.enterprise.connectors.util.SetMethodAction.run(SetMethodAction.java:136)
... 39 more
Caused by: 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 com.sun.enterprise.connectors.util.SetMethodAction.run(SetMethodAction.java:105)
... 39 more
Caused by: java.lang.IllegalArgumentException: MQJMSRA_AS4001: setSubscriptionDurability:Invalid subscriptionDurability=durable
at com.sun.messaging.jms.ra.ActivationSpec.setSubscriptionDurability(ActivationSpec.java:537)
... 44 more
I guess your EJB module uses the EJBContainer. A word of caution is that the EJBContainer only supports EJB lite which does not include remote EJBs nor MDBs. Refer to this link for details
EJBContainer is mainly for testing in JUnit, it is not meant for production code.
You get the exception
Caused by: java.lang.IllegalArgumentException: MQJMSRA_AS4001:
setSubscriptionDurability:Invalid subscriptionDurability=durable
because the subscriptionDurability property value is case sensitive and you specified it as lowercase, i.e. "durable" instead of the correct value of Durable (i.e. with first letter capitalized)
I've had the same problem and this was the cause.
This property enables you to configure the durability of the topic
subscriber. Durable subscribers can survive any disconnection from the
JMS server.
The valid values are Durable and NonDurable.
The problem can be reproduced with the following MDB (Message Driven Bean):
#JMSDestinationDefinition(name = "BookingTopic", interfaceName = "javax.jms.Topic",
resourceAdapter = "jmsra", destinationName = "BookingTopic") #MessageDriven(activationConfig = {
#ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
#ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "BookingTopic"),
#ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "durable"),
#ActivationConfigProperty(propertyName = "clientId", propertyValue = "BookingTopic"),
#ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "BookingTopic") }) public class ReservationNotifier implements MessageListener {
private static final Logger loggger = Logger.getLogger(ReservationNotifier.class.getSimpleName());
public ReservationNotifier() {
}
#Override
public void onMessage(Message message) {
try {
Booking booking = (Booking) ((ObjectMessage) message).getObject();
loggger.log(Level.INFO, "Sending e-mail containing reservation information to {0}", booking.getCustomer().getEmail());
} catch (JMSException ex) {
loggger.log(Level.SEVERE, "Error reading booking from topic");
}
}
}
1) Can you schedule a message driven bean to access a queue only at certain times?
For example, user has two contact options - between 9am-5pm and 5pm-10pm. I'd like to have two MDB one that is only active from 9am-5pm and the other at 3pm-10pm.
Both queues have messages sent to them throughout the day but I'd only like to process them at the specific times.
Ideally #Schedule would work but unfortunately it doesn't.
Using Glassfish 3.1.2 and ActiveMQ 5.5.1 but I'm pretty sure it's not an implementation specific question.
Edit 1
Code
#MessageDriven(
activationConfig = {
#ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
#ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/queue/amqmsg")
})
public class ExampleMessageBean implements MessageListener {
#Schedule(second="*", minute="*", hour="9-17", persistent = false)
public void onMessage(Message message) {
try {
System.out.println("We've received a message: " + message.getJMSMessageID());
System.out.println("\n\n Message\n\n" + message);
} catch (JMSException e) {
e.printStackTrace();
}
}
}
Getting error on deployment. I don't think it's possible for #Schedule to be used in this way. Can anyone confirm?
SEVERE: Exception while invoking class org.glassfish.ejb.startup.EjbDeployer load method java.lang.RuntimeException: EJB Container initialization error
at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:242)
at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:299)
at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:105)
at org.glassfish.internal.data.ModuleInfo.load(ModuleInfo.java:186)
at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:264)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:460)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
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:662)
Caused by: javax.ejb.EJBException: Invalid #Timeout or #Schedule signature for: public void com.name.mdb.ExampleMessageBean.onMessage(javax.jms.Message) #Timeout or #Schedule method must return void and be a no-arg method or take a single javax.ejb.Timer param
at com.sun.ejb.containers.BaseContainer.processEjbTimeoutMethod(BaseContainer.java:2219)
at com.sun.ejb.containers.BaseContainer.<init>(BaseContainer.java:743)
at com.sun.ejb.containers.MessageBeanContainer.<init>(MessageBeanContainer.java:142)
at com.sun.ejb.containers.ContainerFactoryImpl.createContainer(ContainerFactoryImpl.java:121)
at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:230)
... 33 more
SEVERE: Exception while loading the app
INFO: No timers to be deleted for id: 87558812344647680
SEVERE: Exception while loading the app : EJB Container initialization error
javax.ejb.EJBException: Invalid #Timeout or #Schedule signature for: public void com.test.mdb.ExampleMessageBean.onMessage(javax.jms.Message) #Timeout or #Schedule method must return void and be a no-arg method or take a single javax.ejb.Timer param
at com.sun.ejb.containers.BaseContainer.processEjbTimeoutMethod(BaseContainer.java:2219)
at com.sun.ejb.containers.BaseContainer.<init>(BaseContainer.java:743)
at com.sun.ejb.containers.MessageBeanContainer.<init>(MessageBeanContainer.java:142)
at com.sun.ejb.containers.ContainerFactoryImpl.createContainer(ContainerFactoryImpl.java:121)
at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:230)
at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:299)
at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:105)
at org.glassfish.internal.data.ModuleInfo.load(ModuleInfo.java:186)
at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:264)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:460)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
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:662)
Schedule doesnt like being called on your method which has the message param. How would it know this argument.
Just add the items to a queue and process seperately.
#MessageDriven(
activationConfig = {
#ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
#ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/queue/amqmsg")
})
public class ExampleMessageBean implements MessageListener {
private BlockingQueue<Message> queue = new ArrayBlockingQueue<Message>() ;
#Schedule(second="*", minute="*", hour="9-17", persistent = false)
public void process()
{
//process queue here.
}
public void onMessage(Message message) {
try {
System.out.println("We've received a message: " + message.getJMSMessageID());
queue.add(message);
System.out.println("\n\n Message\n\n" + message);
} catch (JMSException e) {
e.printStackTrace();
}
}
I have a servlet that has a suspending method and a broadcasting one:
#GET
#Path("/notification")
#Produces( { "application/x-javascript", MediaType.APPLICATION_JSON })
#Suspend
public JSONWithPadding getNextNotification(
#QueryParam("callback") #DefaultValue("callback") String callback) {
Random random = new Random();
Notification n = new Notification();
n.setMessage("Message is " + Long.toHexString(random.nextLong()));
n.setMessage("S-" + Long.toHexString(random.nextLong()));
return new JSONWithPadding(n, callback);
}
I invoke this from a browser and see the following nice output in my browser:
<!-- ---------------------------------------------------------------- http://github.com/Atmosphere ------------------------------------------------------------------------ -->
<!-- Welcome to the Atmosphere Framework.....
<!-- --------------------------------------------------------------------------------------------------------------------------------------------------------------------- -->
<!-- EOD -->callback({"message":"S-c897404ad5703dcc","sender":null}
So my object is nicely serialized to JSONP.
Now I call my broadcaster method:
#Context Broadcaster bc;
#Broadcast({JsonpFilter.class})
#GET
#Path("/broadcast5")
public Broadcastable broadcast5() {
Random random = new Random();
Notification n = new Notification();
n.setMessage("Message is " + Long.toHexString(random.nextLong()));
n.setMessage("S-" + Long.toHexString(random.nextLong()));
return new Broadcastable(new JSONWithPadding(n, "callback111"), bc);
}
On the server side I get the following exception and nothing is broadcasted:
[#|2012-01-19T17:28:30.483+0100|WARNING|glassfish3.1.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_Thr
eadID=20;_ThreadName=http-thread-pool-8080(5);|StandardWrapperValve[AtmosphereServlet]: PWC1406: Servlet.service() for s
ervlet AtmosphereServlet threw exception
java.lang.RuntimeException: javax.servlet.ServletException: Throwable
at org.atmosphere.handler.ReflectorServletProcessor.onRequest(ReflectorServletProcessor.java:154)
at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:219)
at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:154)
at org.atmosphere.container.GrizzlyCometSupport.service(GrizzlyCometSupport.java:103)
at org.atmosphere.container.GlassFishWebSocketSupport.service(GlassFishWebSocketSupport.java:101)
at org.atmosphere.cpr.AtmosphereServlet.doCometSupport(AtmosphereServlet.java:1212)
at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:1171)
at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:1157)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
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 com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.comet.CometEngine.executeServlet(CometEngine.java:444)
at com.sun.grizzly.comet.CometEngine.handle(CometEngine.java:308)
at com.sun.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java:87)
at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:171)
at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:143)
at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:94)
at com.sun.grizzly.http.TaskBase.run(TaskBase.java:193)
at com.sun.grizzly.http.TaskBase.execute(TaskBase.java:175)
at com.sun.grizzly.arp.DefaultAsyncHandler.handle(DefaultAsyncHandler.java:145)
at com.sun.grizzly.arp.AsyncProtocolFilter.execute(AsyncProtocolFilter.java:204)
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:662)
Caused by: javax.servlet.ServletException: Throwable
at org.atmosphere.util.AtmosphereFilterChain.doFilter(AtmosphereFilterChain.java:165)
at org.atmosphere.util.AtmosphereFilterChain.invokeFilterChain(AtmosphereFilterChain.java:116)
at org.atmosphere.handler.ReflectorServletProcessor$FilterChainServletWrapper.service(ReflectorServletProcessor.
java:293)
at org.atmosphere.handler.ReflectorServletProcessor.onRequest(ReflectorServletProcessor.java:151)
... 41 more
Caused by: java.lang.AbstractMethodError: org.atmosphere.commons.jersey.JsonpFilter.filter(Ljava/lang/Object;Ljava/lang/
Object;)Lorg/atmosphere/cpr/BroadcastFilter$BroadcastAction;
at org.atmosphere.cpr.BroadcasterConfig.filter(BroadcasterConfig.java:447)
at org.atmosphere.cpr.DefaultBroadcaster.filter(DefaultBroadcaster.java:890)
at org.atmosphere.cpr.DefaultBroadcaster.broadcast(DefaultBroadcaster.java:875)
at org.atmosphere.jersey.AtmosphereFilter$Filter.broadcast(AtmosphereFilter.java:632)
at org.atmosphere.jersey.AtmosphereFilter$Filter.filter(AtmosphereFilter.java:468)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1416)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.atmosphere.util.AtmosphereFilterChain.doFilter(AtmosphereFilterChain.java:155)
... 44 more
|#]
How could I make my broadcaster work? Do I need to return JSONWithPadding object or only the POJO?
You get an AbstractMethodError. Do you have atmosphere-commons on your classpath?
I want to have a configuration parameter injected this way:
public class MyManagedBean {
#Inject
public MyManagedBean(#Named("user") String user){
....
}
}
So I tried to implement a producer method this way:
#ApplicationScoped
public class MyConfiguration {
private Properties loadProperties() {
Properties properties = new Properties();
try {
properties.load(getClass().getResourceAsStream(
"user.properties"));
} catch (IOException e) {
throw new RuntimeException();
}
return properties;
}
#Produces
#Named("user")
String getUser() {
return loadProperties().getProperty("user");
}
}
I have other bean defined this way:
public class OtherManagedBean {
#Inject
public OtherManagedBean(MyManagedBean myManagedBean){
....
}
}
However, I'm having this exception when I try to deploy it:
INFO: WEB0671: Loading application [example-ear#example-war.war] at [example]
SEVERE: Exception while loading the app
SEVERE: Exception while loading the app : WELD-001410 The injection point [parameter 1] of [constructor] #Inject public com.example.OtherManagedBean(MyManagedBean) has non-proxyable dependencies
org.jboss.weld.exceptions.UnproxyableResolutionException: WELD-001410 The injection point [parameter 1] of [constructor] #Inject public com.example.OtherManagedBean(MyManagedBean) has non-proxyable dependencies
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:317)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:139)
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:162)
at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:385)
at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:371)
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:390)
at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:190)
at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:128)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:298)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:370)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:355)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1067)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1247)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:465)
at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:222)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:168)
at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:234)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
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:662)
Any idea?
Thanks.
It looks like you need a default (no-arg) constructor for your MyManagedBean to make it proxyable. I am not really sure about why it is needed, since MyManagedBean is a #Dependent bean and so is not proxied AFAIK; I do not know even why a proxyable bean needs a default constructor, to be honest This seems to be an implementation detail or a little point from CDI specification that was ignored. Anyway, I bet it can make a good new question :)
EDIT: I discovered why a proxyable bean needs a default construction. It is no mistery, actually: since the proxy of a bean is a subclass of the same bean, the proxy needs to call a super() constructor in its own construction. If it has no non-private default constructor, it does not know which constructor to call. One can even imagine a scenario where the injected constructor is called to create the proxy, but I do not know which kind of complexity it can add to a CDI implementation; it may not be so easy to do...