Searching in Collection with CollectionUtils returns NullPointerException - java

I am trying to search items in a collection, but I end up in a NullPointerException, even though I know that the items are there. This is my code to search the collection:
Collection<Item> newnetSWLicense = CollectionUtils.select(sortedItems, new Predicate() {
public boolean evaluate(Object o) {
Item item = (Item)o;
return item.getVendor().equals("NewNet") && item.getItemType().equals("SW") && item.getDescription().contains("Connect7") ||
item.getVendor().equals("NewNet") && item.getItemType().equals("SW") && item.getDescription().contains("C7");
}
});
Everything works when the description of the item is like:
Connect7 Simplex SGC License
or
Connect7 Redundant SGC License
But when the description contains "C7 3.0 core TCAP 8K dialogs simplex", it returns a NullPointerException:
10:19:41,664 ERROR [STDERR] java.lang.NullPointerException
10:19:41,664 ERROR [STDERR] at org.apache.jsp.View.bom.ListBom_jsp$3.evaluate(ListBom_jsp.java:286)
10:19:41,664 ERROR [STDERR] at org.apache.commons.collections.CollectionUtils.select(CollectionUtils.java:517)
10:19:41,664 ERROR [STDERR] at org.apache.commons.collections.CollectionUtils.select(CollectionUtils.java:498)
10:19:41,664 ERROR [STDERR] at org.apache.jsp.View.bom.ListBom_jsp._jspService(ListBom_jsp.java:283)
10:19:41,664 ERROR [STDERR] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
10:19:41,664 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
10:19:41,664 ERROR [STDERR] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
10:19:41,664 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
10:19:41,664 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
10:19:41,664 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
10:19:41,664 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
10:19:41,664 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
10:19:41,664 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
10:19:41,664 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
10:19:41,664 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
10:19:41,664 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
10:19:41,664 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
10:19:41,665 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
10:19:41,665 ERROR [STDERR] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
10:19:41,665 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
10:19:41,665 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
10:19:41,665 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
10:19:41,665 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
10:19:41,665 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
10:19:41,665 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
10:19:41,665 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
10:19:41,665 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
10:19:41,665 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
10:19:41,665 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
10:19:41,665 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
10:19:41,665 ERROR [STDERR] at java.lang.Thread.run(Thread.java:722)
Any idea how to avoid this exception? Btw. vendor and item type are 100% correct.

The issue must be with your code:
return item.getVendor().equals("NewNet") && item.getItemType().equals("SW") &&
item.getDescription().contains("Connect7") ||
item.getVendor().equals("NewNet") && item.getItemType().equals("SW") &&
item.getDescription().contains("C7");
Don't put everything in a single return statement; extract the local vars first for vendor and description. Check the vars for null.
if (item == null) return false;
final String v = item.getVendor(), d = item.getDescription(),
t = item.getItemType();
return d != null && "NewNet".equals(v) && "SW".equals(t) &&
(d.contains("C7") || d.contains("Connect7"));

Related

I have a exception with java.lang.Thread.run(Unknown Source)

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)

Parsing HTTP request payload with Jackson

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));
}

JSch get() fails with NullPointerException

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;

Not able to update parent table

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;

Getting ParseException on Transport.send(message)

For some reason I'm getting a javax.mail.internet.ParseException when I call Transport.send() on a MimeMessage. This worked before when it was only a plain text email, but when I changed it to have both text and html it started blowing up. Any ideas what I'm doing wrong?
#Resource(mappedName = "java:/Mail")
private Session mailer;
public void sendMessage(String toEmailAddress, String subject, String content, String text) throws Exception {
try {
Message message = new MimeMessage(mailer);
MimeMultipart rootMixedMultipart = new MimeMultipart("mixed");
message.setContent(rootMixedMultipart);
MimeMultipart nestedRelatedMultipart = new MimeMultipart("related");
MimeBodyPart relatedBodyPart = new MimeBodyPart();
relatedBodyPart.setContent(nestedRelatedMultipart);
rootMixedMultipart.addBodyPart(relatedBodyPart);
MimeMultipart messageBody = new MimeMultipart("alternative");
MimeBodyPart bodyPart = null;
for (int i = 0; i < nestedRelatedMultipart.getCount(); i++) {
BodyPart bp = nestedRelatedMultipart.getBodyPart(i);
if (bp.getFileName() == null) {
bodyPart = (MimeBodyPart) bp;
}
}
if (bodyPart == null) {
MimeBodyPart mimeBodyPart = new MimeBodyPart();
nestedRelatedMultipart.addBodyPart(mimeBodyPart);
bodyPart = mimeBodyPart;
}
bodyPart.setContent(messageBody, "text/alternative");
// Create the plain text part of the message.
MimeBodyPart plainTextPart = new MimeBodyPart();
plainTextPart.setText(text, "UTF-8");
messageBody.addBodyPart(plainTextPart);
// Create the HTML text part of the message.
MimeBodyPart htmlTextPart = new MimeBodyPart();
htmlTextPart.setContent(content, "CONTENT_TYPE_HTML;charset=UTF-8");
messageBody.addBodyPart(htmlTextPart);
message.setFrom(new InternetAddress(NO_REPLY_EMAIL_ADDRESS, PERSONAL));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(toEmailAddress));
message.setSubject(subject);
message.setHeader("Precedence", "bulk");
Transport.send(message);
}
catch (Exception e) {
}
}
Here's the stack trace.
2011-03-03 00:20:05,896 ERROR [STDERR] javax.mail.internet.ParseException
2011-03-03 00:20:05,896 ERROR [STDERR] at javax.mail.internet.ContentType.<init>(ContentType.java:89)
2011-03-03 00:20:05,896 ERROR [STDERR] at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1249)
2011-03-03 00:20:05,896 ERROR [STDERR] at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1001)
2011-03-03 00:20:05,896 ERROR [STDERR] at javax.mail.internet.MimeMultipart.updateHeaders(MimeMultipart.java:333)
2011-03-03 00:20:05,896 ERROR [STDERR] at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1255)
2011-03-03 00:20:05,896 ERROR [STDERR] at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1001)
2011-03-03 00:20:05,896 ERROR [STDERR] at javax.mail.internet.MimeMultipart.updateHeaders(MimeMultipart.java:333)
2011-03-03 00:20:05,896 ERROR [STDERR] at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1255)
2011-03-03 00:20:05,896 ERROR [STDERR] at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1001)
2011-03-03 00:20:05,896 ERROR [STDERR] at javax.mail.internet.MimeMultipart.updateHeaders(MimeMultipart.java:333)
2011-03-03 00:20:05,897 ERROR [STDERR] at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1255)
2011-03-03 00:20:05,897 ERROR [STDERR] at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:2012)
2011-03-03 00:20:05,897 ERROR [STDERR] at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:1980)
2011-03-03 00:20:05,897 ERROR [STDERR] at javax.mail.Transport.send(Transport.java:97)
2011-03-03 00:20:05,897 ERROR [STDERR] at com.lawless.manager.NotificationManagerBean.sendMessage(NotificationManagerBean.java:69)
2011-03-03 00:20:05,897 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2011-03-03 00:20:05,897 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
2011-03-03 00:20:05,897 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
2011-03-03 00:20:05,897 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597)
2011-03-03 00:20:05,897 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
2011-03-03 00:20:05,897 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
2011-03-03 00:20:05,897 ERROR [STDERR] at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
2011-03-03 00:20:05,897 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,897 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
2011-03-03 00:20:05,897 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,897 ERROR [STDERR] at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
2011-03-03 00:20:05,897 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,897 ERROR [STDERR] at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
2011-03-03 00:20:05,897 ERROR [STDERR] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
2011-03-03 00:20:05,898 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,898 ERROR [STDERR] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
2011-03-03 00:20:05,898 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,898 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
2011-03-03 00:20:05,898 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,898 ERROR [STDERR] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
2011-03-03 00:20:05,898 ERROR [STDERR] at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
2011-03-03 00:20:05,898 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,898 ERROR [STDERR] at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
2011-03-03 00:20:05,898 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,898 ERROR [STDERR] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
2011-03-03 00:20:05,898 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,898 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:240)
2011-03-03 00:20:05,898 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:210)
2011-03-03 00:20:05,898 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:84)
2011-03-03 00:20:05,898 ERROR [STDERR] at $Proxy97.sendMessage(Unknown Source)
2011-03-03 00:20:05,898 ERROR [STDERR] at com.lawless.manager.CommentManagerBean.sendCommentNotification(CommentManagerBean.java:85)
2011-03-03 00:20:05,898 ERROR [STDERR] at com.lawless.manager.CommentManagerBean.addComment(CommentManagerBean.java:44)
2011-03-03 00:20:05,898 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2011-03-03 00:20:05,899 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
2011-03-03 00:20:05,899 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
2011-03-03 00:20:05,899 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597)
2011-03-03 00:20:05,899 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
2011-03-03 00:20:05,899 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
2011-03-03 00:20:05,899 ERROR [STDERR] at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
2011-03-03 00:20:05,899 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,899 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
2011-03-03 00:20:05,899 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,899 ERROR [STDERR] at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
2011-03-03 00:20:05,899 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,899 ERROR [STDERR] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
2011-03-03 00:20:05,899 ERROR [STDERR] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
2011-03-03 00:20:05,899 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,899 ERROR [STDERR] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
2011-03-03 00:20:05,899 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,899 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
2011-03-03 00:20:05,899 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,899 ERROR [STDERR] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
2011-03-03 00:20:05,900 ERROR [STDERR] at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
2011-03-03 00:20:05,900 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,900 ERROR [STDERR] at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
2011-03-03 00:20:05,900 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,900 ERROR [STDERR] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
2011-03-03 00:20:05,900 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
2011-03-03 00:20:05,900 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:240)
2011-03-03 00:20:05,900 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:210)
2011-03-03 00:20:05,900 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:84)
2011-03-03 00:20:05,900 ERROR [STDERR] at $Proxy100.addComment(Unknown Source)
2011-03-03 00:20:05,900 ERROR [STDERR] at com.lawless.web.ListingAction.addComment(ListingAction.java:97)
2011-03-03 00:20:05,900 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2011-03-03 00:20:05,900 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
2011-03-03 00:20:05,900 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
2011-03-03 00:20:05,900 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597)
2011-03-03 00:20:05,900 ERROR [STDERR] at net.sourceforge.stripes.controller.DispatcherHelper$6.intercept(DispatcherHelper.java:442)
2011-03-03 00:20:05,900 ERROR [STDERR] at net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:158)
2011-03-03 00:20:05,900 ERROR [STDERR] at org.stripesstuff.plugin.security.SecurityInterceptor.interceptEventHandling(SecurityInterceptor.java:188)
2011-03-03 00:20:05,900 ERROR [STDERR] at org.stripesstuff.plugin.security.SecurityInterceptor.intercept(SecurityInterceptor.java:120)
2011-03-03 00:20:05,901 ERROR [STDERR] at net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155)
2011-03-03 00:20:05,901 ERROR [STDERR] at net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor.intercept(BeforeAfterMethodInterceptor.java:113)
2011-03-03 00:20:05,901 ERROR [STDERR] at net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155)
2011-03-03 00:20:05,901 ERROR [STDERR] at net.sourceforge.stripes.controller.ExecutionContext.wrap(ExecutionContext.java:74)
2011-03-03 00:20:05,901 ERROR [STDERR] at net.sourceforge.stripes.controller.DispatcherHelper.invokeEventHandler(DispatcherHelper.java:440)
2011-03-03 00:20:05,901 ERROR [STDERR] at net.sourceforge.stripes.controller.DispatcherServlet.invokeEventHandler(DispatcherServlet.java:278)
2011-03-03 00:20:05,901 ERROR [STDERR] at net.sourceforge.stripes.controller.DispatcherServlet.service(DispatcherServlet.java:160)
2011-03-03 00:20:05,901 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
2011-03-03 00:20:05,901 ERROR [STDERR] at net.sourceforge.stripes.controller.DynamicMappingFilter$2.doFilter(DynamicMappingFilter.java:364)
2011-03-03 00:20:05,901 ERROR [STDERR] at net.sourceforge.stripes.controller.StripesFilter.doFilter(StripesFilter.java:247)
2011-03-03 00:20:05,901 ERROR [STDERR] at net.sourceforge.stripes.controller.DynamicMappingFilter.doFilter(DynamicMappingFilter.java:351)
2011-03-03 00:20:05,901 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
2011-03-03 00:20:05,901 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
2011-03-03 00:20:05,901 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
2011-03-03 00:20:05,901 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
2011-03-03 00:20:05,901 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
2011-03-03 00:20:05,901 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
2011-03-03 00:20:05,901 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
2011-03-03 00:20:05,901 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
2011-03-03 00:20:05,902 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
2011-03-03 00:20:05,902 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
2011-03-03 00:20:05,902 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
2011-03-03 00:20:05,902 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
2011-03-03 00:20:05,902 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
2011-03-03 00:20:05,902 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
2011-03-03 00:20:05,902 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
2011-03-03 00:20:05,902 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
2011-03-03 00:20:05,902 ERROR [STDERR] at java.lang.Thread.run(Thread.java:619)
Look at
htmlTextPart.setContent(content, "CONTENT_TYPE_HTML;charset=UTF-8");
where you want to reference to a CONTENT_TYPE_HTML, but put is a String into the contenttype parameter. CONTENT_TYPE_HTML is of course not a valid content-type declaration. CONTENT_TYPE_HTML is probably a static final String member of "SomeClass", which equals "text/html", I guess.
Instead use
htmlTextPart.setContent(content, SomeClass.CONTENT_TYPE_HTML+";charset=UTF-8");
to set the content-type to text/html;charset=utf-8. Of course replace SomeClass with the real class where the member CONTENT_TYPE_HTML was defined.
try using the following,
Email.setContent(Object o, String contentType)

Categories