Handler processing failed; nested exception is java.lang.NoSuchMethodError - java

I run local have no bug ,but I release on server it occur error Handler processing failed; nested exception is java.lang.NoSuchMethodError.This is old project in my company.Used spring+hibernate+struts2.This bug confuse me 2 weeks this is server Excption:
<html><head><title>Apache Tomcat/5.5.20 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoSuchMethodError: com.golden.ex.bs.app.menber.dao.MenberDao.getComp(Ljava/lang/String;)Ljava/util/List;
org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1259)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:920)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:801)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
com.golden.ex.framework.core.filter.FlashFilter.doFilterInternal(FlashFilter.java:30)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
com.golden.ex.framework.core.filter.LoggerMDCFilter.doFilterInternal(LoggerMDCFilter.java:43)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
</pre></p><p><b>root cause</b> <pre>java.lang.NoSuchMethodError: com.golden.ex.bs.app.menber.dao.MenberDao.getComp(Ljava/lang/String;)Ljava/util/List;
com.restful.CompService.getCompRemote(CompService.java:39)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:920)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:801)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
com.golden.ex.framework.core.filter.FlashFilter.doFilterInternal(FlashFilter.java:30)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
com.golden.ex.framework.core.filter.LoggerMDCFilter.doFilterInternal(LoggerMDCFilter.java:43)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
</pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/5.5.20</h3></body></html>
The controller:
package com.restful;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.golden.ex.bs.app.menber.dao.MenberDao;
import com.golden.ex.bs.app.menber.service.MbOptService;
#Controller
#RequestMapping("/CompService")
public class CompService
{
#Autowired
private MbOptService mboptService;
#Autowired
private MenberDao menberDao;
#ResponseBody
#RequestMapping(value = "/getCompRemote" ,produces = {"text/html;charset=UTF-8"})
public String getCompRemote(#RequestParam("company") String test)
{
String comp=test;
System.out.println("=============进入接口==========");
String company=comp;
List<Map> menber =this.menberDao.getComp(company);
if(menber==null||menber.equals(""))
{
return ApiResponse.buildSuccessResponse(201,"不存在公司",menber);
}
else
{
return ApiResponse.buildSuccessResponse(200,"成功",menber);
}
}
#ResponseBody
#RequestMapping(value = "/joinCompRemote" ,produces = {"text/html;charset=UTF-8"})
public String joinCompRemote(#RequestParam("company") String company,#RequestParam("userid") String userid)
{
System.out.println("=============进入接口==========");
boolean check=this.mboptService.checkJoinUser(userid);
if(check==true)
{
//修改,更新optemp公司代码 status 0未审核 1通过 2未通过
this.mboptService.joinUpdate(userid,company);
}
else
{
//新增,增加一笔
this.mboptService.joinInsert(userid,company);
}
return ApiResponse.buildSuccessResponse(200,"您的审核已提交,等待该公司确认");
}
}
The Dao:
public List<Map> getComp(String company)
{
String sql="select HYDM,MBNAME from BS_MENBER where MBNAME like '%"+company+"%'";
List<Map> bs=this.listSQL(sql);
return bs;
}
I've looked up the relevant questions, but most of them don't fit my case ,My IDE is myeclipse 6.0 and jboss4.0.5GA
thanks

I think you have different version of MemberDao class on your server then in local. Check on your JBoss container, that your packaged jar which includes "MemberDao.java" is overwritten when you deploy your app. Maybe you deployed your "compservice.jar" into the container's global lib folder.

Related

I have 2 Service classes that both extend the same parent class with an autowired bean, I can use the bean in one class but not in the other [duplicate]

This question already has answers here:
Why is my Spring #Autowired field null?
(21 answers)
Closed 5 years ago.
I'm still pretty new to Spring, but I'm currently facing an issue of which I don't know the cause and I can't figure it out with only a nullpointerexception.
I have 2 classes that both implement the same Abstract class. InventoryService and InventoryMailService. All 3 are in the same package that is successfully being scanned with component-scan. I'm trying to use my globalPrefService bean, which I can succesfully use in my InventoryService but somehow not in my InventoryMailService.
This is my AbstractService that I use to wire my services together:
package com.paperfoam.inventory.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
#Service("abstractService")
public abstract class AbstractService {
protected InventoryService inventoryService;
protected FinancialCalculationService financialCalculationService;
protected SupplierService supplierService;
protected UserService userService;
protected GlobalPrefService globalPrefService;
#Autowired
public void setGlobalPrefService(GlobalPrefService globalPrefService) {
this.globalPrefService = globalPrefService;
}
#Autowired
public void setInventoryService(InventoryService inventoryService) {
this.inventoryService = inventoryService;
}
#Autowired
protected void setFinancialCalculationService(FinancialCalculationService financialCalculationService) {
this.financialCalculationService = financialCalculationService;
}
#Autowired
protected void setSupplierService(SupplierService supplierService) {
this.supplierService = supplierService;
}
#Autowired
protected void setUsersService(UserService userService) {
this.userService = userService;
}
}
This is the the InventoryService (minus some non-related functions), when I try to call my GlobalPrefService it works just fine:
package com.paperfoam.inventory.service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.paperfoam.inventory.dao.InventoryDao;
import com.paperfoam.inventory.dao.InventoryLogItemDao;
import com.paperfoam.inventory.objects.InventoryItem;
import com.paperfoam.inventory.objects.InventoryLogItem;
#Service("inventoryService")
public class InventoryService extends AbstractService {
private InventoryDao inventoryDao;
private InventoryLogItemDao inventoryLogItemDao;
public InventoryDao getInventoryDao() {
return inventoryDao;
}
#Autowired
public void setInventoryDao(InventoryDao inventoryDao) {
this.inventoryDao = inventoryDao;
}
#Autowired
public void setInventoryLogItemDao(InventoryLogItemDao inventoryLogItemDao) {
this.inventoryLogItemDao = inventoryLogItemDao;
}
// This is the method where I succesfully use my GlobalPrefService
public List<InventoryItem> getAllInventoryItems() {
System.out.println(globalPrefService.getPreferenceValue("mailusername")); // this succesfully prints my preferenceValue to the console
return inventoryDao.getInventoryList();
}
}
However, I have my other class (same package) that extends the same AbstractService that returns a NullPointerException when I try to use it:
package com.paperfoam.inventory.service;
import java.io.File;
import java.util.logging.Logger;
import javax.mail.internet.MimeMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.mail.MailParseException;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import com.paperfoam.inventory.config.JavaBeanConfig;
import com.paperfoam.inventory.objects.InventoryItem;
import com.paperfoam.inventory.objects.Supplier;
#Service("inventoryMailService")
public class InventoryMailService extends AbstractService {
public void sendMessageWithAttachment(String to, String subject, String text, String pathToAttachment) {
System.out.println(globalPrefService.getPreferenceValue("mailusername")); // NullPointerException on the globalPrefService!
/*
JavaBeanConfig javaBean = new JavaBeanConfig();
JavaMailSender mailSender = javaBean.getJavaMailSender(globalPrefService);
try {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setTo(to);
helper.setSubject(subject);
helper.setText(text);
Resource file = new ClassPathResource(pathToAttachment);
helper.addAttachment("hoera.png", file);
mailSender.send(message);
} catch (Exception e) {
e.printStackTrace();
}
*/
}
}
The error I get:
SEVERE: Servlet.service() for servlet [paperfoam] in context with path [/bulletjournal] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at com.paperfoam.inventory.service.InventoryMailService.sendMessageWithAttachment(InventoryMailService.java:30) // This is the system.out line
at com.paperfoam.inventory.controllers.InventoryController.showInventoryStatistics(InventoryController.java:165)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
I have been staring at this for a while and I can't figure out what causes this. Everything is annotated in the same way, they extend the same class that autowires the bean in, they are in the same package that is being scanned and the access modifiers are also the same.
I also tried to clean/rebuild my project a few times, does anyone have any idea what I am missing here?
Thank you for reading.
In response to the comment:
My InventoryService gets Autowired in the controller.
protected InventoryService inventoryService;
#Autowired
public void setInventoryService(InventoryService inventoryService) {
this.inventoryService = inventoryService;
}
But I manually instantiate my InventoryMailService (and I'm starting to think thats the mistake) for debugging.
#RequestMapping(value = { "/statistics", "/" })
public String showInventoryStatistics(Model model) {
Map<Integer, Long> calculated = financialCalculationService.getSuppliersWithTotalWorth();
List<Supplier> allSuppliers = supplierService.convertSupplierHashmapToObjectList(calculated);
List<InventoryItem> lowItems = inventoryService.getLowInventoryItems();
List<InventoryLogItem> recentChanges = inventoryService.getRecentChanges();
model.addAttribute("suppliers", allSuppliers);
model.addAttribute("lowitems", lowItems);
model.addAttribute("recentchanges", recentChanges);
InventoryMailService mail = new InventoryMailService();
System.out.println(mail.toString());
mail.sendMessageWithAttachment("Redacted#gmail.com", "betere mail", "test123", "com/paperfoam/inventory/mail/success.png");
return JspPage.INVENTORY_STATISTICS;
}
I didn't even stop to think that that might affect the autowiring down the road, does that matter to spring?
For spring to handle dependency injection the entire dependency chain needs to be autowired, so you need to also autowire InventoryMailService in InventoryController.

Paypal Java-SDK Payment Execute issue

I am trying to integrate Papal with my Spring Web Service. I am refering Advanced Server Integration and using this SDK Create Payment Sample.
Here is my Client Side Code
<script src="https://www.paypalobjects.com/api/checkout.js">
</script>
<h1>Paypal Integration - Advanced Server Side Integration</h1>
<div id="paypal-button-container"></div>
<script>
// Render the PayPal button
paypal.Button.render({
// Set your environment
env: 'sandbox', // sandbox | production
// Wait for the PayPal button to be clicked
payment: function() {
// Make a call to the merchant server to set up the payment
return paypal.request.post('http://localhost:8080/api/createpayment').then(function(res) {
console.log(res);
return res.payToken;
});
},
// Wait for the payment to be authorized by the customer
onAuthorize: function(data, actions) {
// Make a call to the merchant server to execute the payment
return paypal.request.post('http://localhost:8080/api/executepayment', {
payToken: data.paymentID,
payerId: data.payerID
}).then(function(res) {
console.log(res);
document.querySelector('#paypal-button-container').innerText = 'Payment Complete!';
});
}
}, '#paypal-button-container');
</script>
Here is my Web Service
#RequestMapping(value = "/executepayment", method = RequestMethod.POST)
public #ResponseBody
Payment executePayment(HttpServletRequest request, HttpServletResponse response) {
Map<String, String> map = new HashMap<String, String>();
Payment createdPayment = null;
try {
final String clientID = "<clientId>";
final String clientSecret = "<clientSecret>";
// ### Api Context
// Pass in a `ApiContext` object to authenticate
// the call and to send a unique request id
// (that ensures idempotency). The SDK generates
// a request id if you do not pass one explicitly.
APIContext apiContext = new APIContext(clientID, clientSecret, "sandbox");
if (request.getParameter("payerId") != null) {
logger.info("Payment Execution");
Payment payment = new Payment();
if (request.getParameter("guid") != null) {
payment.setId(map.get(request.getParameter("guid")));
}
PaymentExecution paymentExecution = new PaymentExecution();
paymentExecution.setPayerId(request.getParameter("payerId"));
createdPayment = payment.execute(apiContext, paymentExecution);
logger.info("Executed Payment - Request :: \n " + Payment.getLastRequest());
logger.info("Exceuted Payment - Response :; \n " + Payment.getLastResponse());
//ResultPrinter.addResult(req, resp, "Executed The Payment", Payment.getLastRequest(), Payment.getLastResponse(), null);
//ResultPrinter.addResult(req, resp, "Executed The Payment", Payment.getLastRequest(), null, e.getMessage());
}
} catch (Exception e) {
logger.error("Execute Payment Exception ");
e.printStackTrace();
}
return createdPayment;
}
When I click on Paypal Checkout button. It popups the Paypal Login Screen and authorization is working fine. After that I am trying to execute payment using my API. But I am getting 500 Internal Server Error when I call payment.execute(apiContext, paymentExecution) method. Here is the complete Stacktrace
[http-nio-8080-exec-42] ERROR com.paypal.base.HttpConnection - Response code: 500 Error response: <html><head><title>JBoss Web/7.0.17.Final - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: com.paypal.foundation.security.ObjectEncryptionException.<init>(Lcom/paypal/platform/ec/InternalError;Ljava/lang/Throwable;[Ljava/lang/String;)V org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:116) org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:336) org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:249) org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153) org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:181) org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:289) org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:209) javax.servlet.http.HttpServlet.service(HttpServlet.java:754) org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265) org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:83) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) com.paypal.api.utils.MultiReadServletFilter.doFilter(MultiReadServletFilter.java:23) com.paypal.foundation.service.rest.logging.StandardOuterTransactionCALFilter.doFilter(StandardOuterTransactionCALFilter.java:95) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) com.paypal.common.resource.filter.SecurityContextFilter.doFilter(SecurityContextFilter.java:75)</pre></p><p><b>root cause</b> <pre>org.apache.cxf.interceptor.Fault: com.paypal.foundation.security.ObjectEncryptionException.<init>(Lcom/paypal/platform/ec/InternalError;Ljava/lang/Throwable;[Ljava/lang/String;)V org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:170) org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:136) org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:204) org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:101) org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94) org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:249) org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153) org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:181) org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:289) org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:209) javax.servlet.http.HttpServlet.service(HttpServlet.java:754) org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265) org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:83) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) com.paypal.api.utils.MultiReadServletFilter.doFilter(MultiReadServletFilter.java:23) com.paypal.foundation.service.rest.logging.StandardOuterTransactionCALFilter.doFilter(StandardOuterTransactionCALFilter.java:95) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) com.paypal.common.resource.filter.SecurityContextFilter.doFilter(SecurityContextFilter.java:75)</pre></p><p><b>root cause</b> <pre>java.lang.NoSuchMethodError: com.paypal.foundation.security.ObjectEncryptionException.<init>(Lcom/paypal/platform/ec/InternalError;Ljava/lang/Throwable;[Ljava/lang/String;)V com.paypal.foundation.security.InvalidInputDataException.<init>(InvalidInputDataException.java:11) com.paypal.foundation.security.crypto.AbstractIdEncryptor.decrypt(AbstractIdEncryptor.java:81) com.paypal.domains.common.utils.crypto.impl.IdCryptUtilImpl.decryptId(IdCryptUtilImpl.java:103) com.paypal.domains.payment.dal.dao.impl.PaymentsFacadeDAOImpl.findPaymentByEncryptedId(PaymentsFacadeDAOImpl.java:301) com.paypal.domains.payment.bo.impl.PaymentBOFactory.getPaymentForRoutingCheck(PaymentBOFactory.java:340) com.paypal.api.service.impl.PaymentServiceImpl.checkRoutingToSymphony(PaymentServiceImpl.java:2167) com.paypal.api.service.impl.PaymentServiceImpl.executePayment(PaymentServiceImpl.java:811) sun.reflect.GeneratedMethodAccessor168.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:188) org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:104) org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:204) org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:101) org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94) org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:249) org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153) org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:181) org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:289) org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:209) javax.servlet.http.HttpServlet.service(HttpServlet.java:754) org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265) org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:83) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerReque2017-05-03 17:48:33 ERROR UserController:740 - Create Payment Exception
stFilter.java:76) com.paypal.api.utils.MultiReadServletFilter.doFilter(MultiReadServletFilter.java:23) com.paypal.foundation.service.rest.logging.StandardOuterTransactionCALFilter.doFilter(StandardOuterTransactionCALFilter.java:95) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) com.paypal.common.resource.filter.SecurityContextFilter.doFilter(SecurityContextFilter.java:75)</pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the JBoss Web/7.0.17.Final logs.</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/7.0.17.Final</h3></body></html>
response-code: 500 details: null
at com.paypal.base.rest.PayPalRESTException.createFromHttpErrorException(PayPalRESTException.java:72)
at com.paypal.base.rest.PayPalResource.execute(PayPalResource.java:431)
at com.paypal.base.rest.PayPalResource.configureAndExecute(PayPalResource.java:295)
at com.paypal.base.rest.PayPalResource.configureAndExecute(PayPalResource.java:228)
at com.paypal.api.payments.Payment.execute(Payment.java:226)
at com.statementgames.controllers.UserController.createPayment(UserController.java:640)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at com.statementgames.filters.CORSFilter.doFilter(CORSFilter.java:54)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:509)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1104)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.paypal.base.exception.HttpErrorException: Response code: 500 Error response: <html><head><title>JBoss Web/7.0.17.Final - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: com.paypal.foundation.security.ObjectEncryptionException.<init>(Lcom/paypal/platform/ec/InternalError;Ljava/lang/Throwable;[Ljava/lang/String;)V org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:116) org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:336) org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:249) org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153) org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:181) org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:289) org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:209) javax.servlet.http.HttpServlet.service(HttpServlet.java:754) org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265) org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:83) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) com.paypal.api.utils.MultiReadServletFilter.doFilter(MultiReadServletFilter.java:23) com.paypal.foundation.service.rest.logging.StandardOuterTransactionCALFilter.doFilter(StandardOuterTransactionCALFilter.java:95) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) com.paypal.common.resource.filter.SecurityContextFilter.doFilter(SecurityContextFilter.java:75)</pre></p><p><b>root cause</b> <pre>org.apache.cxf.interceptor.Fault: com.paypal.foundation.security.ObjectEncryptionException.<init>(Lcom/paypal/platform/ec/InternalError;Ljava/lang/Throwable;[Ljava/lang/String;)V org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:170) org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:136) org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:204) org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:101) org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94) org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:249) org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153) org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:181) org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:289) org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:209) javax.servlet.http.HttpServlet.service(HttpServlet.java:754) org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265) org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:83) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) com.paypal.api.utils.MultiReadServletFilter.doFilter(MultiReadServletFilter.java:23) com.paypal.foundation.service.rest.logging.StandardOuterTransactionCALFilter.doFilter(StandardOuterTransactionCALFilter.java:95) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) com.paypal.common.resource.filter.SecurityContextFilter.doFilter(SecurityContextFilter.java:75)</pre></p><p><b>root cause</b> <pre>java.lang.NoSuchMethodError: com.paypal.foundation.security.ObjectEncryptionException.<init>(Lcom/paypal/platform/ec/InternalError;Ljava/lang/Throwable;[Ljava/lang/String;)V com.paypal.foundation.security.InvalidInputDataException.<init>(InvalidInputDataException.java:11) com.paypal.foundation.security.crypto.AbstractIdEncryptor.decrypt(AbstractIdEncryptor.java:81) com.paypal.domains.common.utils.crypto.impl.IdCryptUtilImpl.decryptId(IdCryptUtilImpl.java:103) com.paypal.domains.payment.dal.dao.impl.PaymentsFacadeDAOImpl.findPaymentByEncryptedId(PaymentsFacadeDAOImpl.java:301) com.paypal.domains.payment.bo.impl.PaymentBOFactory.getPaymentForRoutingCheck(PaymentBOFactory.java:340) com.paypal.api.service.impl.PaymentServiceImpl.checkRoutingToSymphony(PaymentServiceImpl.java:2167) com.paypal.api.service.impl.PaymentServiceImpl.executePayment(PaymentServiceImpl.java:811) sun.reflect.GeneratedMethodAccessor168.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:188) org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:104) org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:204) org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:101) org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94) org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:249) org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222) org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153) org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:181) org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:289) org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:209) javax.servlet.http.HttpServlet.service(HttpServlet.java:754) org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265) org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:83) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) com.paypal.api.utils.MultiReadServletFilter.doFilter(MultiReadServletFilter.java:23) com.paypal.foundation.service.rest.logging.StandardOuterTransactionCALFilter.doFilter(StandardOuterTransactionCALFilter.java:95) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) com.paypal.common.resource.filter.SecurityContextFilter.doFilter(SecurityContextFilter.java:75)</pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the JBoss Web/7.0.17.Final logs.</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/7.0.17.Final</h3></body></html>
at com.paypal.base.HttpConnection.executeWithStream(HttpConnection.java:162)
at com.paypal.base.HttpConnection.execute(HttpConnection.java:65)
at com.paypal.base.rest.PayPalResource.execute(PayPalResource.java:417)
... 45 more
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: https://api.sandbox.paypal.com/v1/payments/payment/706473799bd24b5792e463df41140a61/execute
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1890)
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1885)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1884)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1457)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at com.paypal.base.HttpConnection.executeWithStream(HttpConnection.java:132)
... 47 more
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: https://api.sandbox.paypal.com/v1/payments/payment/706473799bd24b5792e463df41140a61/execute
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1840)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
at com.paypal.base.HttpConnection.executeWithStream(HttpConnection.java:117)
... 47 more
I can't figure out whats going wrong. Is there any issue in Paypal-Java-SDK or in my Server side code. Am I doing anything Wrong?
This error is because of wrong Payment Id. I just changed the code as
if (request.getParameter("paymentId") != null) {
payment.setId(request.getParameter("paymentId"));
}
I think Paypal should handle this kind of errors and show some proper error message in Response JSON like Payment ID missing, Invalid Payment ID or something. It's weird to get 500 Internal Server Error and It's very hard to debug.

ControllerAdvice not handling exception

I have a spring boot 1.3.3 application. I have a rest controller that throws an exception in certain situations. The exceptions are being thrown and the message printed but the ControllerAdvice class is not being fired. Here's my relevant files:
TestController.java
#Controller
public class TestController {
// RESTful method
#RequestMapping(
value = "/test",
method = RequestMethod.POST,
consumes = "application/json",
produces = "application/json")
#ResponseBody
public JsonNode fooRestTest(#RequestHeader HttpHeaders header,
#RequestBody String payload) {
ControllerUtil.validateHeaders(header);
return null;
}
}
ControllerUtil.java
public class ControllerUtil {
public static void validateHeaders(HttpHeaders headers) {
if(headers.get("test-field") == null) {
throw new InvalidHeaderException("Invalid test-field in header");
}
}
}
InvalidHeaderException.java
public class InvalidHeaderException extends RuntimeException {
public InvalidHeaderException(String message) {
super(message);
}
public InvalidHeaderException(String message, Throwable cause) {
super(message, cause);
}
}
AppErrorController.java
#ControllerAdvice
#EnableWebMvc
public class AppErrorController {
#ExceptionHandler(InvalidHeaderException.class)
public ModelAndView handleHeaderError(HttpServletRequest req, Exception ex) {
ModelAndView mav = new ModelAndView();
mav.addObject("exception", ex);
mav.addObject("url", req.getRequestURL());
mav.addObject("timestamp", LocalDateTime.now());
mav.addObject("status", 400);
return mav;
}
}
web.xml
<web-app id="RBGApp" version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>FooTester</display-name>
<servlet>
<servlet-name>Foo_Test</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Mappings -->
<servlet-mapping>
<servlet-name>Foo_Test</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
MvcConfiguration.java
#Configuration
#EnableWebMvc
public class MvcConfiguration extends WebMvcConfigurerAdapter {
#Autowired
ServletContext servletContext;
#Override
public void configureDefaultServletHandling(
DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
#Bean
public ViewResolver getJspViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("WEB-INF/jsp/views/");
resolver.setSuffix(".jsp");
resolver.setOrder(1);
return resolver;
}
}
I tested this with a request from postman and it throws the exception and prints out the line:
Invalid test-field in header
But the code never goes into the AppErrorController at all. So none of the other values like timestamp are populated. Any idea what i'm doing wrong here?
Edit 1:
This is what postman spits out as the response:
<html>
<head>
<title>Apache Tomcat/7.0.62 - Error report</title>
<style>
<!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}-->
</style>
</head>
<body>
<h1>HTTP Status 500 - Invalid test-field in header</h1>
<HR size="1" noshade="noshade">
<p>
<b>type</b> Exception report
</p>
<p>
<b>message</b>
<u>Invalid test-field in header</u>
</p>
<p>
<b>description</b>
<u>The server encountered an internal error that prevented it from fulfilling this request.</u>
</p>
<p>
<b>exception</b>
<pre>controllers.exceptions.InvalidHeaderException: Invalid test-field in header
controllers.util.ControllerUtil.validateHeaders(ControllerUtil.java:12)
controllers.TestController.fooRestTest(TestController.java:77)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:497)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)
javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:120)
org.springframework.boot.context.web.ErrorPageFilter.access$000(ErrorPageFilter.java:61)
org.springframework.boot.context.web.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:95)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:113)
</pre>
</p>
<p>
<b>note</b>
<u>The full stack trace of the root cause is available in the Apache Tomcat/7.0.62 logs.</u>
</p>
<HR size="1" noshade="noshade">
<h3>Apache Tomcat/7.0.62</h3>
</body>
</html>
Edit 2: Console output when making the postman request
09:08:14.373 [http-bio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'Foo_Test' processing POST request for [/TEST]
09:08:14.381 [http-bio-8080-exec-1] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /test
09:08:14.390 [http-bio-8080-exec-1] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Returning handler method [public com.fasterxml.jackson.databind.JsonNode controllers.AlertController.getAlertsForRest(org.springframework.http.HttpHeaders,java.lang.String)]
09:08:14.390 [http-bio-8080-exec-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'alertController'
09:08:14.426 [http-bio-8080-exec-1] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor - Read [class java.lang.String] as "application/json" with [org.springframework.http.converter.StringHttpMessageConverter#4732b26d]
09:08:14.436 [http-bio-8080-exec-1] DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - Resolving exception from handler [public com.fasterxml.jackson.databind.JsonNode controllers.AlertController.getAlertsForRest(org.springframework.http.HttpHeaders,java.lang.String)]: controllers.exceptions.InvalidHeaderException: Invalid test-field in header
09:08:14.439 [http-bio-8080-exec-1] DEBUG org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver - Resolving exception from handler [public com.fasterxml.jackson.databind.JsonNode controllers.AlertController.getAlertsForRest(org.springframework.http.HttpHeaders,java.lang.String)]: controllers.exceptions.InvalidHeaderException: Invalid test-field in header
09:08:14.439 [http-bio-8080-exec-1] DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Resolving exception from handler [public com.fasterxml.jackson.databind.JsonNode controllers.AlertController.getAlertsForRest(org.springframework.http.HttpHeaders,java.lang.String)]: controllers.exceptions.InvalidHeaderException: Invalid test-field in header
09:08:14.443 [http-bio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet - Could not complete request
controllers.exceptions.InvalidHeaderException: Invalid test-field in header
controllers.util.ControllerUtil.validateHeaders(ControllerUtil.java:12)
controllers.TestController.fooRestTest(TestController.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:120)
at org.springframework.boot.context.web.ErrorPageFilter.access$000(ErrorPageFilter.java:61)
at org.springframework.boot.context.web.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:95)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:113)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Do you have messages like java.lang.IllegalStateException: No suitable resolver for argument in your log files?
Try to use same exception type at handleHeaderError method argument: InvalidHeaderException instead of Exception. Like this:
#ControllerAdvice
#EnableWebMvc
public class AppErrorController {
#ExceptionHandler(InvalidHeaderException.class)
public ModelAndView handleHeaderError(HttpServletRequest req, InvalidHeaderException ex) {
ModelAndView mav = new ModelAndView();
mav.addObject("exception", ex);
mav.addObject("url", req.getRequestURL());
mav.addObject("timestamp", LocalDateTime.now());
mav.addObject("status", 400);
return mav;
}
}
May be there is some other handler that is Handling this request(from first 5 lines of console output). That might be in any of the jars that are in the build path of your project.
We need to set priority of your handler as Highest, so control comes here first.
I think adding #Order(Ordered.HIGHEST_PRECEDENCE) after #EnableWebMvc might solve the problem.
#ControllerAdvice
#EnableWebMvc
#Order(Ordered.HIGHEST_PRECEDENCE)
public class AppErrorController {
#ExceptionHandler(InvalidHeaderException.class)
public ModelAndView handleHeaderError(HttpServletRequest req, InvalidHeaderException ex) {
ModelAndView mav = new ModelAndView();
mav.addObject("exception", ex);
mav.addObject("url", req.getRequestURL());
mav.addObject("timestamp", LocalDateTime.now());
mav.addObject("status", 400);
return mav;
}
Also if it doesn't work try changing InvalidHeaderException.class to Exception.class (Regardless of what exception it is control would come here). Also debugging would be helpful in your case.

Pathvariable on Controller class level does not work Spring Restful

I have a controller where I have controller level mapping as "/subjects/{subjectId}/lessons" which is required due to some reason
#RestController
#RequestMapping( value = "/subjects/{subjectId}/lessons",produces = { MediaType.APPLICATION_JSON_VALUE } )
public class LessonController {
.......
#RequestMapping( method = RequestMethod.GET )
public ResponseEntity<Resources<Resource<Lesson>>> getAllSjubject(#PathVariable(value = "subjectId") int subjectId){
List<Lesson> lessonList = lessonService.getAllLessons(subjectId);
Resources<Resource<Lesson>> resource = this.lessonResourceAssembler.toLessonResourceList(lessonList);
return new ResponseEntity<Resources<Resource<Lesson>>>(resource, HttpStatus.OK);
}
}
When made request it throws the exception
java.lang.IllegalArgumentException: Not enough variable values available to expand 'subjectId'
at org.springframework.web.util.UriComponents$VarArgsTemplateVariables.getValue(UriComponents.java:327)
at org.springframework.web.util.UriComponents.expandUriComponent(UriComponents.java:230)
at org.springframework.web.util.HierarchicalUriComponents$FullPathComponent.expand(HierarchicalUriComponents.java:685)
at org.springframework.web.util.HierarchicalUriComponents.expandInternal(HierarchicalUriComponents.java:328)
at org.springframework.web.util.HierarchicalUriComponents.expandInternal(HierarchicalUriComponents.java:47)
at org.springframework.web.util.UriComponents.expand(UriComponents.java:163)
at org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo(ControllerLinkBuilder.java:89)
at org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo(ControllerLinkBuilder.java:69)
at com.khaino.springrest.assembler.LessonResourceAssembler.toLessonResource(LessonResourceAssembler.java:31)
at com.khaino.springrest.assembler.LessonResourceAssembler.toLessonResourceList(LessonResourceAssembler.java:44)
at com.khaino.springrest.controller.LessonController.getAllSjubject(LessonController.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:111)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1526)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1482)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
But when I move the pathvariable to method level as below it is working correctly.
#RequestMapping( value = "/subjects",produces = { MediaType.APPLICATION_JSON_VALUE } )
public class LessonController {
......
#RequestMapping( value = "/{subjectId}/lessons", method = RequestMethod.GET )
public ResponseEntity<Resources<Resource<Lesson>>> getAllSjubject(#PathVariable("subjectId") int subjectId){
List<Lesson> lessonList = lessonService.getAllLessons(subjectId);
Resources<Resource<Lesson>> resource = this.lessonResourceAssembler.toLessonResourceList(lessonList);
return new ResponseEntity<Resources<Resource<Lesson>>>(resource, HttpStatus.OK);
}
....
}
Something wrong with my code? What could be the reason and solution?
Your mappings works in both scenarios but based on your stack trace, the following part is the source of problem:
this.lessonResourceAssembler.toLessonResourceList(lessonList)
You're creating some Hypermedia Links that contains some Template Variables which are NOT expanded.
Updated: Use this approach to create link:
linkTo(methodOn(LessonController.class).getAllSjubject(42))
.withRel(REL_SELF)
mehtodOn is in org.springframework.hateoas.mvc.ControllerLinkBuilder package, make sure you have correct static imports.
http://localhost:8080/springexample/subjects/3/lessons worked for me with code:
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
#RestController
#RequestMapping(value = "/subjects/{subjectId}/lessons", produces = { MediaType.APPLICATION_JSON_VALUE })
public class LessonController {
#RequestMapping(method = RequestMethod.GET)
public ResponseEntity getAllSjubject(
#PathVariable(value = "subjectId") int subjectId) {
System.out.println(subjectId);
return new ResponseEntity(HttpStatus.OK);
}
}
Having, Spring Dependency defined in pom.xml as: <spring.version>4.1.4.RELEASE</spring.version>

Spring Neo4j Template throws Null Pointer Exception

I am working with spring social to get a users friends and add them to a database but every time i compile and the app launches it throws this error My class is below the error.
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/see-my-style] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at org.springframework.data.neo4j.support.Neo4jTemplate.getMappingPolicy(Neo4jTemplate.java:486)
at org.springframework.data.neo4j.support.Neo4jTemplate.getMappingPolicy(Neo4jTemplate.java:656)
at org.springframework.data.neo4j.support.Neo4jTemplate.save(Neo4jTemplate.java:293)
at org.springframework.data.neo4j.support.Neo4jTemplate.save(Neo4jTemplate.java:287)
at org.springframework.social.quickstart.HomeController.home(HomeController.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Here is the class im working with
package org.springframework.social.quickstart;
import java.util.List;
import javax.inject.Inject;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ImportResource;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.template.Neo4jOperations;
import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.facebook.api.FacebookProfile;
import org.springframework.social.facebook.api.PagedList;
import org.springframework.social.facebook.api.Reference;
import org.springframework.social.quickstart.repository.PersonRepository;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* Simple little #Controller that invokes Facebook and renders the result.
* The injected {#link Facebook} reference is configured with the required authorization credentials for the current user behind the scenes.
* #author Keith Donald
*/
#Controller
public class HomeController {
private final Facebook facebook;
private static final String DB_PATH = "target/neo4j-hello-db";
GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
Neo4jOperations neo = new Neo4jTemplate(graphDb);
#Inject
public HomeController(Facebook facebook) {
this.facebook = facebook;
}
#RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Model model) {
List<Reference> friends = facebook.friendOperations().getFriends();
for(Reference friend: friends)
{
neo.save(friend.getName());
}
return "home";
}
Make sure the Friend is annotated with #NodeEntity.
Tell spring the location (package(s)) of all your node entities so that it knows the mapping.
Instead of creating the graph db yourself, let spring manage it for you (use neo4j namespace)
I think you should save the Friend entity instead of name. i.e. change the below
neo.save(friend.getName());
to
neo.save(friend);

Categories