I set up a project to Inject bean
But when you try to start getting a null pointer error
Can you tell that I did not ?
public_html\WEB-INF\faces-config.xml
<?xml version='1.0' encoding='UTF-8'?>
<faces-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<application>
<locale-config>
<default-locale>ru</default-locale>
</locale-config>
<resource-bundle>
<base-name>by.softclub.abank.admin.ui.resources.Labels</base-name>
<var>lbl</var>
</resource-bundle>
<resource-bundle>
<base-name>by.softclub.abank.admin.ui.resources.Regexp</base-name>
<var>regexp</var>
</resource-bundle>
<action-listener>org.primefaces.application.DialogActionListener</action-listener>
<navigation-handler>org.primefaces.application.DialogNavigationHandler</navigation-handler>
<!-- <view-handler>org.primefaces.application.DialogViewHandler</view-handler> -->
<el-resolver>
org.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver
</el-resolver>
</application>
<factory>
<exception-handler-factory>
org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory
</exception-handler-factory>
</factory>
<lifecycle>
<phase-listener>by.softclub.abank.admin.ui.faces.UniqueSessionPhaseListener</phase-listener>
</lifecycle>
</faces-config>
public_html\WEB-INF\beans.xml
<beans 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/beans_1_1.xsd"
version="1.2" bean-discovery-mode="annotated">
<!-- some content -->
</beans>
UniqueSessionPhaseListener
public class UniqueSessionPhaseListener implements PhaseListener {
#Inject
ApplicationBean applicationBean;
public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
}
public void afterPhase(PhaseEvent phaseEvent) {
}
public void beforePhase(PhaseEvent phaseEvent) {
if (applicationBean.sessionIntercepted(FacesUtils.getSession())) {
SessionBean sessionBean = (SessionBean) FacesUtils.getSession().getAttribute("sessionBean");
if (sessionBean.isAuthenticated()) {
sessionBean.logoutAction();
}
}
}
}
ApplicationBean
#ApplicationScoped
#Named("applicationBean")
public class ApplicationBean implements Serializable {
public ApplicationBean() {
}
}
Error log
09:35:58,189 ERROR [stderr] (default task-35) java.lang.NullPointerException
09:35:58,189 ERROR [stderr] (default task-35) at by.softclub.abank.admin.ui.faces.UniqueSessionPhaseListener.beforePhase(UniqueSessionPhaseListener.java:26)
09:35:58,189 ERROR [stderr] (default task-35) at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)
09:35:58,190 ERROR [stderr] (default task-35) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)
09:35:58,190 ERROR [stderr] (default task-35) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
09:35:58,190 ERROR [stderr] (default task-35) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)
09:35:58,190 ERROR [stderr] (default task-35) at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:98)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
09:35:58,190 ERROR [stderr] (default task-35) at com.github.zhanhb.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:55)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
09:35:58,190 ERROR [stderr] (default task-35) at by.softclub.abank.admin.ui.faces.UrlFilter.doFilter(UrlFilter.java:118)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
09:35:58,190 ERROR [stderr] (default task-35) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
09:35:58,193 ERROR [stderr] (default task-35) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774)
09:35:58,193 ERROR [stderr] (default task-35) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
09:35:58,193 ERROR [stderr] (default task-35) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
09:35:58,193 ERROR [stderr] (default task-35) at java.lang.Thread.run(Thread.java:745)
09:35:58,193 SEVERE [org.primefaces.application.exceptionhandler.PrimeExceptionHandler] (default task-35) null: java.lang.NullPointerException
at by.softclub.abank.admin.ui.faces.UniqueSessionPhaseListener.beforePhase(UniqueSessionPhaseListener.java:26) [classes:]
at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228) [jsf-impl-2.2.12-jbossorg-2.jar:2.2.12-jbossorg-2]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99) [jsf-impl-2.2.12-jbossorg-2.jar:2.2.12-jbossorg-2]
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) [jsf-impl-2.2.12-jbossorg-2.jar:2.2.12-jbossorg-2]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659) [jboss-jsf-api_2.2_spec-2.2.12.jar:2.2.12]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:98) [primefaces-5.0.jar:5.0]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at com.github.zhanhb.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:55) [character-encoding-filter-2.1.6.4.jar:]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at by.softclub.abank.admin.ui.faces.UrlFilter.doFilter(UrlFilter.java:118) [classes:]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_102]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_102]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_102]
I try
How to #Inject in a PhaseListener
But also null pointer
public static ApplicationBean getApplicationBean() {
FacesContext context = FacesContext.getCurrentInstance();
return context.getApplication()
.evaluateExpressionGet(context, "#{applicationBean}", ApplicationBean.class);
}
Whee ApplicationBean was annotated #ManagedBean all work fine
Change PhaseListener
import javax.el.ELContext;
import javax.enterprise.context.ApplicationScoped;
import javax.faces.application.Application;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import javax.naming.InitialContext;
import javax.naming.NamingException;
#ApplicationScoped
public class UniqueSessionPhaseListener implements PhaseListener {
public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
}
public void afterPhase(PhaseEvent phaseEvent) {
}
public void beforePhase(PhaseEvent phaseEvent) {
FacesContext context = FacesContext.getCurrentInstance();
ELContext elContext = context.getELContext();
Object object = context.getApplication().evaluateExpressionGet(context, "#{applicationBean}", Object.class);
Application application = context.getApplication();
ApplicationBean applicationBean0 = application.evaluateExpressionGet(context, "#{applicationBean}", ApplicationBean.class);
ApplicationBean applicationBean00 = (ApplicationBean) application.getExpressionFactory().createValueExpression(elContext, "#{applicationBean}", ApplicationBean.class).getValue(elContext);
ApplicationBean applicationBean000 = (ApplicationBean) elContext.getELResolver().getValue(elContext, null, "applicationBean");
ApplicationBean applicationBean = (ApplicationBean) FacesContext.getCurrentInstance().getApplication().getELResolver().getValue(elContext, null, "#{applicationBean}");
ApplicationBean applicationBean1 = context.getApplication().evaluateExpressionGet(context, "#{applicationBean}", ApplicationBean.class);
InitialContext initialContext = null;
try {
initialContext = new InitialContext();
ApplicationBean beanManager = (ApplicationBean) initialContext.lookup("java:comp/applicationBean");
} catch (NamingException e) {
e.printStackTrace();
}
ApplicationBean bean = FacesUtils.getApplicationBean();
if (bean.sessionIntercepted(FacesUtils.getSession())) {
SessionBean sessionBean = (SessionBean) FacesUtils.getSession().getAttribute("sessionBean");
if (sessionBean.isAuthenticated()) {
sessionBean.logoutAction();
}
}
}
}
Updated 21.09.2016
Add questions:
1) How can I find is on the right path lies beans.xml (faces-config is in the WEB-INF), so I think unlikely but still there is the idea that with the beans.xml that something is wrong.
2) Server Settings, his library (I WildFly 9) can not be to influence the CDI application?
Related
HEELP!!
I have a problem running the code, it does not execute the Sql statement and I cannot locate the error between the DAO class and the rest service.
I already added the exceptions of SQLException and ClassNotFound in the DAO class but I still cannot locate the error, and I already executed the code in a separate class and if the request of the BD returns, which means that the driver is well configured.
package com.DAO;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
//import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.connection.ConexionPSQL;
import com.IDAO.EmployeIDAO;
import com.model.EmployeObject;
public class EmployeDAO implements EmployeIDAO {
#Override
public List<EmployeObject> obtener() {
Connection co = null;
Statement stm = null;
ResultSet rs = null;
String sql = "SELECT * FROM TABLE_EMPLOYES";
List<EmployeObject> listaCliente = new
ArrayList<EmployeObject>();
try {
co = ConexionPSQL.crearConexion();
stm = co.createStatement();
rs = stm.executeQuery(sql);
while (rs.next()) {
EmployeObject e = new EmployeObject();
e.setId(rs.getInt(1));
e.setNombre(rs.getString(2));
e.setApellido(rs.getString(3));
listaCliente.add(e);
}
stm.close();
rs.close();
co.close();
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
return listaCliente;
}
}
`` ``` ``` ``` ``` ``` ``` ``` ``` ``` ``` ``` ``` ``` ``` `
package com.IDAO;
import java.util.List;
import com.model.EmployeObject;
public interface EmployeIDAO {
public boolean registrar(EmployeObject employe);
public List<EmployeObject> obtener();
public boolean actualizar(EmployeObject employe);
public boolean eliminar(EmployeObject employe);
}
`` ``` ``` ``` ``` ``` ``` ``` ``` ```
package REST;
import java.util.List;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import com.DAO.EmployeDAO;
import com.model.EmployeObject;
import javax.ws.rs.Produces;
// http://localhost:8080/RestService/resources/MyRestService/verEmpleados
#GET
#Path("/verEmpleados")
#Produces(MediaType.APPLICATION_JSON)
public List<EmployeObject> VerEmpleado() {
List<EmployeObject> verEmpleados = empleados.obtener();
return verEmpleados;
}
`` ``` ``` ``` ``` ``` ``` ``` ``` ```
I hope I can help, thank you very much
Here are the error messages
10:55:27,125 ERROR [stderr] (default task-2) at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
10:55:27,125 ERROR [stderr] (default task-2) at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:412)
10:55:27,125 ERROR [stderr] (default task-2) at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:400)
10:55:27,125 ERROR [stderr] (default task-2) at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
10:55:27,126 ERROR [stderr] (default task-2) at java.lang.Class.forName0(Native Method)
10:55:27,126 ERROR [stderr] (default task-2) at java.lang.Class.forName(Unknown Source)
10:55:27,126 ERROR [stderr] (default task-2) at com.connection.ConexionPSQL.crearConexion(ConexionPSQL.java:17)
10:55:27,126 ERROR [stderr] (default task-2) at com.DAO.EmployeDAO.obtener(EmployeDAO.java:55)
10:55:27,127 ERROR [stderr] (default task-2) at REST.RestService.VerEmpleado(RestService.java:46)
10:55:27,127 ERROR [stderr] (default task-2) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
10:55:27,127 ERROR [stderr] (default task-2) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
10:55:27,127 ERROR [stderr] (default task-2) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
10:55:27,127 ERROR [stderr] (default task-2) at java.lang.reflect.Method.invoke(Unknown Source)
10:55:27,127 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
10:55:27,128 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
10:55:27,128 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
10:55:27,128 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
10:55:27,128 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:406)
10:55:27,129 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:213)
10:55:27,129 ERROR [stderr] (default task-2) at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:228)
10:55:27,129 ERROR [stderr] (default task-2) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
10:55:27,129 ERROR [stderr] (default task-2) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
10:55:27,130 ERROR [stderr] (default task-2) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
10:55:27,130 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
10:55:27,130 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
10:55:27,130 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
10:55:27,130 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
10:55:27,131 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10:55:27,131 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
10:55:27,131 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
10:55:27,131 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10:55:27,131 ERROR [stderr] (default task-2) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
10:55:27,132 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
10:55:27,132 ERROR [stderr] (default task-2) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
10:55:27,132 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
10:55:27,132 ERROR [stderr] (default task-2) at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
10:55:27,134 ERROR [stderr] (default task-2) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
10:55:27,134 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10:55:27,134 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
10:55:27,135 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10:55:27,135 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
10:55:27,135 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10:55:27,135 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
10:55:27,136 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
10:55:27,136 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
10:55:27,136 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
10:55:27,136 ERROR [stderr] (default task-2) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
10:55:27,137 ERROR [stderr] (default task-2) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
10:55:27,137 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
10:55:27,137 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
10:55:27,137 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
10:55:27,138 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
10:55:27,138 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
10:55:27,138 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
10:55:27,138 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
10:55:27,138 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
10:55:27,139 ERROR [stderr] (default task-2) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:326)
10:55:27,139 ERROR [stderr] (default task-2) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:812)
10:55:27,139 ERROR [stderr] (default task-2) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
10:55:27,139 ERROR [stderr] (default task-2) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
10:55:27,139 ERROR [stderr] (default task-2) at java.lang.Thread.run(Unknown Source)
well i created a restful webservice wi th a get method that returns a list of bank transactions based on an account id. the service works fine when i test.
Then i created a restful client in my managedBean. this exceptions pops out when i invoke my webservice.
i tried this method already with a list of all clients (without parameters) and it worked but when i add a parameter to my transactions method the id could not be extracted from my request.
this is my webservice
#Stateless
#Path("/transactions")
public class TransactionWebService {
#EJB
private GestionAccountsLocal local1;
#EJB
private GestionTransactionsLocal local2;
#GET
#Path("/{id}")
#Produces(MediaType.APPLICATION_JSON)
public List<Transaction> getTransactionById(#PathParam(value="id") Integer id)
{
Account account=local1.findAccountByid(id);
return local2.showTransactionByAccount(account);
}
}
this is my restful client
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.json.JsonException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import org.json.JSONArray;
#ManagedBean
#SessionScoped
public class WebServiceTransaction {
private WebTarget webtarget;
private Client client;
private entities.Account account;
private Transaction transaction;
private List<Transaction> transactions;
private static final String base_url= "http://localhost:8383/ebankingWEB/rest/transactions" ;
public WebTarget getWebtarget() {
return webtarget;
}
public void setWebtarget(WebTarget webtarget) {
this.webtarget = webtarget;
}
public Transaction getTransaction() {
return transaction;
}
public void setTransaction(Transaction transaction) {
this.transaction = transaction;
}
public static String getBaseUrl() {
return base_url;
}
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
public WebServiceTransaction() {
client= ClientBuilder.newClient();
webtarget=client.target(base_url).path("id");
}
public List<Transaction> getTransactions() {
return transactions;
}
public void setTransactions(List<Transaction> transactions) {
this.transactions = transactions;
}
public List<Transaction> convertToList (String jsonListString) throws JsonException{
try{
JSONArray jsonList = new JSONArray(jsonListString);
transactions = new ArrayList<Transaction>();
for (int i=0 ; i < jsonList.length();i++){
Transaction transaction = new Transaction(jsonList.get(i).toString());
transactions.add(transaction);
}
return transactions;
}
catch (Exception e) {
throw new JsonException(e.getMessage());
}
}
public List<Transaction> getTransactionsByAccount (Integer id){
try{
WebTarget ressource = webtarget;
ressource.path(MessageFormat.format("{0}" , new Object[]{id}));
String jsonListString = ressource.request(MediaType.APPLICATION_JSON).get(String.class);
return convertToList(jsonListString);
}
catch (Exception e){
String message = "non existant transactions ";
FacesContext.getCurrentInstance()
.addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_INFO,
message, null));
e.printStackTrace();
return new ArrayList<Transaction>();
}
}
public entities.Account getAccount() {
return account;
}
public void setAccount(entities.Account account) {
this.account = account;
}
}
and this is my log
15:51:05,177 WARN [org.jboss.resteasy.core.ExceptionHandler] (default task-26) failed to execute: javax.ws.rs.NotFoundException: Unable to extract parameter from http request: javax.ws.rs.PathParam("id") value is 'id' for public java.util.List webServices.TransactionWebService.getTransactionById(java.lang.Integer)
at org.jboss.resteasy.core.PathParamInjector$1.throwProcessingException(PathParamInjector.java:54) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.StringParameterInjector.extractValue(StringParameterInjector.java:336) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.PathParamInjector.inject(PathParamInjector.java:131) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:89) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:112) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.8.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_75]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_75]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_75]
Caused by: java.lang.NumberFormatException: For input string: "id"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) [rt.jar:1.7.0_75]
at java.lang.Integer.parseInt(Integer.java:492) [rt.jar:1.7.0_75]
at java.lang.Integer.<init>(Integer.java:677) [rt.jar:1.7.0_75]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_75]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [rt.jar:1.7.0_75]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.7.0_75]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) [rt.jar:1.7.0_75]
at org.jboss.resteasy.core.StringParameterInjector.extractValue(StringParameterInjector.java:319) [resteasy-jaxrs-3.0.8.Final.jar:]
... 38 more
15:51:05,191 ERROR [stderr] (default task-25) javax.ws.rs.NotFoundException: HTTP 404 Not Found
15:51:05,191 ERROR [stderr] (default task-25) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:181)
15:51:05,191 ERROR [stderr] (default task-25) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:154)
15:51:05,191 ERROR [stderr] (default task-25) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:444)
15:51:05,192 ERROR [stderr] (default task-25) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.get(ClientInvocationBuilder.java:165)
15:51:05,192 ERROR [stderr] (default task-25) at tn.esprit.webServiceData.WebServiceTransaction.getTransactionsByAccount(WebServiceTransaction.java:89)
15:51:05,192 ERROR [stderr] (default task-25) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
15:51:05,192 ERROR [stderr] (default task-25) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
15:51:05,192 ERROR [stderr] (default task-25) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
15:51:05,192 ERROR [stderr] (default task-25) at java.lang.reflect.Method.invoke(Method.java:606)
15:51:05,193 ERROR [stderr] (default task-25) at javax.el.ELUtil.invokeMethod(ELUtil.java:308)
15:51:05,193 ERROR [stderr] (default task-25) at javax.el.BeanELResolver.invoke(BeanELResolver.java:537)
15:51:05,193 ERROR [stderr] (default task-25) at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
15:51:05,193 ERROR [stderr] (default task-25) at com.sun.el.parser.AstValue.invoke(AstValue.java:269)
15:51:05,193 ERROR [stderr] (default task-25) at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
15:51:05,193 ERROR [stderr] (default task-25) at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
15:51:05,194 ERROR [stderr] (default task-25) at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
15:51:05,194 ERROR [stderr] (default task-25) at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
15:51:05,194 ERROR [stderr] (default task-25) at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
15:51:05,194 ERROR [stderr] (default task-25) at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
15:51:05,194 ERROR [stderr] (default task-25) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
15:51:05,194 ERROR [stderr] (default task-25) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
15:51:05,194 ERROR [stderr] (default task-25) at javax.faces.component.UICommand.broadcast(UICommand.java:315)
15:51:05,195 ERROR [stderr] (default task-25) at javax.faces.component.UIData.broadcast(UIData.java:1108)
15:51:05,195 ERROR [stderr] (default task-25) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
15:51:05,195 ERROR [stderr] (default task-25) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
15:51:05,195 ERROR [stderr] (default task-25) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
15:51:05,195 ERROR [stderr] (default task-25) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
15:51:05,195 ERROR [stderr] (default task-25) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
15:51:05,196 ERROR [stderr] (default task-25) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
15:51:05,196 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
15:51:05,196 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
15:51:05,196 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
15:51:05,196 ERROR [stderr] (default task-25) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
15:51:05,196 ERROR [stderr] (default task-25) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
15:51:05,197 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113)
15:51:05,197 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
15:51:05,197 ERROR [stderr] (default task-25) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
15:51:05,197 ERROR [stderr] (default task-25) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
15:51:05,197 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61)
15:51:05,197 ERROR [stderr] (default task-25) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
15:51:05,198 ERROR [stderr] (default task-25) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727)
15:51:05,198 ERROR [stderr] (default task-25) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
15:51:05,198 ERROR [stderr] (default task-25) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
15:51:05,198 ERROR [stderr] (default task-25) at java.lang.Thread.run(Thread.java:745)
PS:
i think this line is the issue since it gets the base url but the id is not extracted correctly webtarget=client.target(base_url).path("id");
if you need anything else please let me know.
You configured your Service with
#Path("/{id}")
So you should not mention the path fragment "/id" in your webtaregt in the constructor :
webtarget=client.target(base_url).path("id"); // wrong
webtarget=client.target(base_url); // OK
Ex : considering transaction id=1 exists, check on your webbrowser :
../transactions/id/1 //wrong
../transactions/1 // OK
i corrected my rest client and it worked like a charm.
webtarget=client.target(base_url);
and
WebTarget ressource = webtarget;
ressource = ressource.path(MessageFormat.format("{0}" , new Object[]{id}));
before that , i didn't affect a ressource to my parameter.
I want the payload of my HTTP request to be converted into a JSON string and I am using Jackson library for it. First I convert it to a Map and then to a JSON string.
try {
ObjectMapper mapper = new ObjectMapper();
JsonParser jsonParser = mapper.getFactory().createParser(httpRequest.getInputStream());
System.out.println("JSON PARSER: " + jsonParser +
" TOKEN: " + jsonParser.getCurrentToken());
Map<String, Object> jsonMap = mapper.readValue(jsonParser, Map.class);
} catch (IOException e) {
e.printStackTrace();
}
I get exception:
com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input ERROR [stderr] (default task-2) at [Source: io.undertow.servlet.spec.ServletInputStreamImpl#4b68bbaa; line: 1, column: 1]
ERROR [stderr] (default task-2) at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
ERROR [stderr] (default task-2) at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3029)
ERROR [stderr] (default task-2) at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:2944)
ERROR [stderr] (default task-2) at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1587)
ERROR [stderr] (default task-2)
ERROR [stderr] (default task-2) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2016-07-18 11:52:15,973 ERROR [stderr] (default task-2) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
2016-07-18 11:52:15,973 ERROR [stderr] (default task-2) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2016-07-18 11:52:15,973 ERROR [stderr] (default task-2) at java.lang.reflect.Method.invoke(Method.java:606)
2016-07-18 11:52:15,973 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)
2016-07-18 11:52:15,973 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:280)
2016-07-18 11:52:15,974 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:234)
2016-07-18 11:52:15,974 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:221)
2016-07-18 11:52:15,974 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)
2016-07-18 11:52:15,974 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)
2016-07-18 11:52:15,974 ERROR [stderr] (default task-2) at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
2016-07-18 11:52:15,974 ERROR [stderr] (default task-2) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
2016-07-18 11:52:15,975 ERROR [stderr] (default task-2) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
2016-07-18 11:52:15,975 ERROR [stderr] (default task-2) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
2016-07-18 11:52:15,975 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
2016-07-18 11:52:15,975 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
2016-07-18 11:52:15,975 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
2016-07-18 11:52:15,975 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
2016-07-18 11:52:15,975 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
2016-07-18 11:52:15,976 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113)
2016-07-18 11:52:15,976 ERROR [stderr] (default task-2) at io.undertow.security.handlers.AuthenticationCallHandler.handleRequest(AuthenticationCallHandler.java:52)
2016-07-18 11:52:15,976 ERROR [stderr] (default task-2) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
2016-07-18 11:52:15,976 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61)
2016-07-18 11:52:15,976 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
2016-07-18 11:52:15,976 ERROR [stderr] (default task-2) at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
2016-07-18 11:52:15,976 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
2016-07-18 11:52:15,977 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
2016-07-18 11:52:15,977 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
2016-07-18 11:52:15,977 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
2016-07-18 11:52:15,977 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240)
2016-07-18 11:52:15,977 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227)
2016-07-18 11:52:15,977 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73)
2016-07-18 11:52:15,978 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146)
2016-07-18 11:52:15,978 ERROR [stderr] (default task-2) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:168)
2016-07-18 11:52:15,978 ERROR [stderr] (default task-2) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:687)
2016-07-18 11:52:15,978 ERROR [stderr] (default task-2) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
2016-07-18 11:52:15,978 ERROR [stderr] (default task-2) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
2016-07-18 11:52:15,978 ERROR [stderr] (default task-2) at java.lang.Thread.run(Thread.java:724)
The following line:
System.out.println("JSON PARSER: " + jsonParser +
" TOKEN: " + jsonParser.getCurrentToken());
Prints:
JSON PARSER: com.fasterxml.jackson.core.json.UTF8StreamJsonParser#6634789d TOKEN: null
My token is coming null.
Am I missing something? What is the corrcet way to extract data from HTTP request stream?
The following should do the trick:
// Read the request payload into a String
StringBuilder buffer = new StringBuilder();
BufferedReader reader = request.getReader();
String line;
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
String data = buffer.toString();
// If the String is not empty, parses the payload into a map
Map<String, Object> jsonMap = null;
if (!data.isEmpty()) {
ObjectMapper mapper = new ObjectMapper();
jsonMap = mapper.readValue(data, Map.class);
}
I do it like this:
BufferedReader bufReader = new BufferedReader(new InputStreamReader
(new URL(myUrlString).openStream()));
StringBuilder myStrBuilder = new StringBuilder();
while((builderLine = bufReader.readLine()) != null) {
myStrBuilder.append(builderLine);
}
JSONArray myJsonArry = new JSONArray(myStrBuilder.toString());
List<Object> myArrayList = new ArrayList<Object>(toList(myJsonArry));
Collection<Map<String,String>> mapsCol = new HashSet<Map<String,String>>();
for (int i=0; i < myArrayList.size(); i++) {
mapsCol.add((HashMap<String, String>)myArrayList.get(i));
}
I've got a Jax-RS server which is supposed to keep a list of files accessible via ssh that I can then download or stream via HTTP.
I've been trying to read the files with JSch's SFTP channel, but I keep receiving a NullPointerException.
Here's the MessageBodyWriter I wrote:
#Provider
#Produces("video/*")
public class MediaBodyWriter implements MessageBodyWriter<MediaFile> {
#Override
public long getSize(MediaFile mFile, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
return mFile.getFileSize();
}
#Override
public boolean isWriteable(Class<?> type, Type arg1, Annotation[] arg2, MediaType arg3) {
return type.equals(MediaFile.class);
}
#Override
public void writeTo(MediaFile mFile,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) throws IOException, WebApplicationException {
mFile.streamFile(entityStream); //line 41
}
}
Here's MediaFile class minus the getters and setters:
#Entity
#XmlRootElement
public class MediaFile {
#Id
#GeneratedValue
Long id;
#JsonIgnore
#ManyToOne(cascade=CascadeType.ALL)
#PrimaryKeyJoinColumn
MediaRepo repo;
String filePath;
String fileName;
transient JSch jsch;
transient Session session;
transient ChannelSftp sftp;
public MediaFile(){}
public void prepForDownload(){
if(sftp != null)
return;
try{
jsch = new JSch();
session = jsch.getSession(repo.getUsername(), repo.getHost(), repo.getPort());
session.setPassword(repo.getPassword());
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
sftp = (ChannelSftp)session.openChannel("sftp");
}catch(Exception e){
e.printStackTrace();
}
}
public long getFileSize(){
prepForDownload();
try {
return sftp.lstat(getCompletePath()).getSize();
} catch (SftpException e) {
e.printStackTrace();
}
return 0;
}
private String getCompletePath(){
return repo.getBasePath()+filePath+fileName;
}
public void streamFile(OutputStream output){
prepForDownload();
try {
sftp.get(getCompletePath(), output);
} catch (SftpException e) {
e.printStackTrace();
}
}
}
And here's the error I'm receiving:
13:50:05,260 ERROR [stderr] (default task-5) 4:
13:50:05,260 ERROR [stderr] (default task-5) at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:1011)
13:50:05,260 ERROR [stderr] (default task-5) at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:984)
13:50:05,261 ERROR [stderr] (default task-5) at model.MediaFile.streamFile(MediaFile.java:75)
13:50:05,261 ERROR [stderr] (default task-5) at MediaBodyWriter.writeTo(MediaBodyWriter.java:41)
13:50:05,261 ERROR [stderr] (default task-5) at MediaBodyWriter.writeTo(MediaBodyWriter.java:1)
13:50:05,261 ERROR [stderr] (default task-5) at MediaBodyWriter$Proxy$_$$_WeldClientProxy.writeTo(Unknown Source)
13:50:05,261 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.writeTo(AbstractWriterInterceptorContext.java:131)
13:50:05,261 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.interception.ServerWriterInterceptorContext.writeTo(ServerWriterInterceptorContext.java:60)
13:50:05,262 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:120)
13:50:05,262 ERROR [stderr] (default task-5) at org.jboss.resteasy.security.doseta.DigitalSigningInterceptor.aroundWriteTo(DigitalSigningInterceptor.java:145)
13:50:05,262 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:124)
13:50:05,262 ERROR [stderr] (default task-5) at org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.aroundWriteTo(GZIPEncodingInterceptor.java:100)
13:50:05,262 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:124)
13:50:05,262 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:98)
13:50:05,262 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:466)
13:50:05,263 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:415)
13:50:05,263 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:202)
13:50:05,263 ERROR [stderr] (default task-5) at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)
13:50:05,263 ERROR [stderr] (default task-5) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
13:50:05,263 ERROR [stderr] (default task-5) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
13:50:05,263 ERROR [stderr] (default task-5) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
13:50:05,263 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
13:50:05,263 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
13:50:05,264 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
13:50:05,264 ERROR [stderr] (default task-5) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
13:50:05,264 ERROR [stderr] (default task-5) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:50:05,264 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
13:50:05,264 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
13:50:05,264 ERROR [stderr] (default task-5) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:50:05,265 ERROR [stderr] (default task-5) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
13:50:05,265 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
13:50:05,265 ERROR [stderr] (default task-5) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
13:50:05,265 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
13:50:05,265 ERROR [stderr] (default task-5) at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
13:50:05,266 ERROR [stderr] (default task-5) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
13:50:05,266 ERROR [stderr] (default task-5) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:50:05,266 ERROR [stderr] (default task-5) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
13:50:05,266 ERROR [stderr] (default task-5) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:50:05,266 ERROR [stderr] (default task-5) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:50:05,266 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284)
13:50:05,267 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
13:50:05,267 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
13:50:05,267 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
13:50:05,267 ERROR [stderr] (default task-5) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
13:50:05,267 ERROR [stderr] (default task-5) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
13:50:05,267 ERROR [stderr] (default task-5) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
13:50:05,268 ERROR [stderr] (default task-5) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
13:50:05,268 ERROR [stderr] (default task-5) at java.lang.Thread.run(Thread.java:745)
13:50:05,268 ERROR [stderr] (default task-5) Caused by: java.lang.NullPointerException
13:50:05,268 ERROR [stderr] (default task-5) at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:994)
13:50:05,269 ERROR [stderr] (default task-5) ... 47 more
You have to call the .connect() on the ChannelSftp, before you can use it, as all JSch SFTP examples show.
For example, see the official JSch SFTP example:
Channel channel=session.openChannel("sftp");
channel.connect();
ChannelSftp c=(ChannelSftp)channel;
I am working on a Spring MVC app in which I am creating a route containing a list of route stop objects. Following is my RouteModel class:
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
#Entity
#Table(name="Route")
public class RouteModel {
#Id
#Column(name="routeid")
#GeneratedValue
private int routeId;
#Column(name="routename")
private String routeName;
#Column(name="routedesc")
private String routeDesc;
#OneToMany(mappedBy = "routeModel")
#Cascade({CascadeType.ALL})
private List<RouteStopModel> routeStopList;
}
and RouteStopModel:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
#Entity
#Table(name="RouteStop")
public class RouteStopModel {
#Id
#Column(name="routestopid")
#GeneratedValue
private int routeStopId;
#Column(name="routestopname")
private String routeStopName;
#Column(name="routestopdesc")
private String routeStopDescription;
#ManyToOne
#JoinColumn(name="routeid")
private RouteModel routeModel;
#Column(name="locationid")
private int locationId;
}
After setting, rout stop list, following dao code I am using to persist route model and routestop list:
session.persist(routeModel);
But I am getting following exception:
org.hibernate.PersistentObjectException: detached entity passed to persist: com.bizmerlin.scm.model.RouteModel
23:11:59,058 ERROR [stderr] (http--127.0.0.1-9090-4) at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:141)
23:11:59,058 ERROR [stderr] (http--127.0.0.1-9090-4) at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:78)
23:11:59,074 ERROR [stderr] (http--127.0.0.1-9090-4) at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:772)
23:11:59,074 ERROR [stderr] (http--127.0.0.1-9090-4) at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:746)
23:11:59,089 ERROR [stderr] (http--127.0.0.1-9090-4) at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:750)
23:11:59,089 ERROR [stderr] (http--127.0.0.1-9090-4) at com.bizmerlin.scm.dao.RouteDao.updateRoute(RouteDao.java:64)
23:11:59,089 ERROR [stderr] (http--127.0.0.1-9090-4) at com.bizmerlin.scm.dao.RouteDao$$FastClassByCGLIB$$71cea667.invoke(<generated>)
23:11:59,105 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
23:11:59,105 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:713)
23:11:59,121 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
23:11:59,121 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
23:11:59,136 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
23:11:59,136 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
23:11:59,152 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
23:11:59,152 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:646)
23:11:59,167 ERROR [stderr] (http--127.0.0.1-9090-4) at com.bizmerlin.scm.dao.RouteDao$$EnhancerByCGLIB$$da879638.updateRoute(<generated>)
23:11:59,183 ERROR [stderr] (http--127.0.0.1-9090-4) at com.bizmerlin.scm.services.RouteService.updateRoute(RouteService.java:40)
23:11:59,199 ERROR [stderr] (http--127.0.0.1-9090-4) at com.bizmerlin.scm.controller.RouteController.editRoute(RouteController.java:115)
23:11:59,214 ERROR [stderr] (http--127.0.0.1-9090-4) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
23:11:59,214 ERROR [stderr] (http--127.0.0.1-9090-4) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
23:11:59,214 ERROR [stderr] (http--127.0.0.1-9090-4) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
23:11:59,230 ERROR [stderr] (http--127.0.0.1-9090-4) at java.lang.reflect.Method.invoke(Method.java:606)
23:11:59,230 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:214)
23:11:59,246 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
23:11:59,261 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
23:11:59,261 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:748)
23:11:59,277 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
23:11:59,277 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
23:11:59,292 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
23:11:59,292 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
23:11:59,308 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931)
23:11:59,308 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:833)
23:11:59,308 ERROR [stderr] (http--127.0.0.1-9090-4) at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
23:11:59,324 ERROR [stderr] (http--127.0.0.1-9090-4) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
23:11:59,324 ERROR [stderr] (http--127.0.0.1-9090-4) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
23:11:59,339 ERROR [stderr] (http--127.0.0.1-9090-4) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
23:11:59,339 ERROR [stderr] (http--127.0.0.1-9090-4) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
23:11:59,355 ERROR [stderr] (http--127.0.0.1-9090-4) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
23:11:59,355 ERROR [stderr] (http--127.0.0.1-9090-4) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
23:11:59,371 ERROR [stderr] (http--127.0.0.1-9090-4) at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
23:11:59,371 ERROR [stderr] (http--127.0.0.1-9090-4) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
23:11:59,386 ERROR [stderr] (http--127.0.0.1-9090-4) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
23:11:59,386 ERROR [stderr] (http--127.0.0.1-9090-4) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
23:11:59,402 ERROR [stderr] (http--127.0.0.1-9090-4) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
23:11:59,433 ERROR [stderr] (http--127.0.0.1-9090-4) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
23:11:59,464 ERROR [stderr] (http--127.0.0.1-9090-4) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
23:11:59,464 ERROR [stderr] (http--127.0.0.1-9090-4) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
23:11:59,480 ERROR [stderr] (http--127.0.0.1-9090-4) at java.lang.Thread.run(Thread.java:744)
try put CascadeType.ALL annotation in your entity
#ManyToOne(cascade = CascadeType.ALL)
#JoinColumn(name="routeid")
private RouteModel routeModel;