Exception java.lang.NoSuchMethodError - java

I'm trying to upload pdf files in the server. And i;m using the following block of code into the controller:
#RequestMapping(value = /submit, method = RequestMethod.POST)
public String upload(UploadItem uploadItem, BindingResult result, HttpServletRequest request, HttpSession session) {
//some code here
String name = request.getServletContext().getRealPath("/pdf/" + filename);
File dest = new File(name);
try {
file.transferTo(dest);
}catch(Exception e){
System.err.println(e);
}
return "redirect:/details";
I'm doing this in order to store the pdf's into the pdf file. In my localhost works fine but when i'm executing this on the server i'm taking the following exception:
exception
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getServletContext()Ljavax/servlet/ServletContext;
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:839)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
root cause
java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getServletContext()Ljavax/servlet/ServletContext;
frontend.controller.EsteemRatingsController.handleFormUpload(EsteemRatingsController.java:113)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
If i remove the lines that provide above in the controller class is working(ofcource without uploading the pdf's). Can anyone help me with this?

That method request.getServletContext() was introduced in servlet 3.0. Make sure your container/library support that version.
edit: tomcat 6 only have servlet 2.5, see http://tomcat.apache.org/whichversion.html
it can be autowired: ServletContext and Spring MVC
public class Xxxx{
#Autowired
ServletContext context;
#RequestMapping(value = "/submit", method = RequestMethod.POST)
public String upload(UploadItem uploadItem, BindingResult result, HttpServletRequest request, HttpSession session) {
//some code here
String name = context.getRealPath("/pdf/" + filename);
...

Related

Request processing failed; nested exception is org.springframework.web.client.RestClientException

I'm working on Spring-MVC Dynamic application.
Controller:
#Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
#Autowired
RestTemplate restTemp;
#RequestMapping(value="//errorpage")
public ModelAndView errorPage(HttpSession session)
{
if(session.getAttribute("username")==null)
{
return new ModelAndView("redirect:/");
}
return new ModelAndView("errorpage");
}
#RequestMapping(value="/welcome", method=RequestMethod.POST)
public ModelAndView checkUser(HttpServletRequest request,HttpSession session,ModelAndView model) throws ParseException
{
String username=request.getParameter("username");
String pwd=request.getParameter("pwd");
String response = request.getParameter("g-recaptcha");
String ipAddress = request.getRemoteAddr();
System.out.println("ReCaptcha: "+response);
String url="https://www.google.com/recaptcha/api/siteverify";
String params="?secret=6LcHGKQUAAAAANcsmAeYQyLGK9GyazkQ7vebU-Qx&response="+response;
ReCaptchaResponse reCaptchaResponse=restTemp.exchange(url+params,HttpMethod.POST,null,ReCaptchaResponse.class).getBody();
if(reCaptchaResponse.isSuccess())
{
System.out.println("Captcha Success");
}
else
{
System.out.println("Captcha Unsuccessful");
}
}
ReCaptchaResponse.java
package com.recaptcha;
public class ReCaptchaResponse
{
private boolean success;
private String challenge_ts;
private String hostname;
//getter and setter methods
}
NOTE: getting null value of reCaptcha response.
getting error message on screen:
Request processing failed; nested exception is org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.recaptcha.ReCaptchaResponse] and content type [application/json;charset=utf-8]
Errors:
May 29, 2019 12:13:02 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [VerilogEvaluation] in context with path [/VerilogEvaluation] threw exception [Request processing failed; nested exception is org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.recaptcha.ReCaptchaResponse] and content type [application/json;charset=utf-8]] with root cause
org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.recaptcha.ReCaptchaResponse] and content type [application/json;charset=utf-8]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:110)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:809)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:793)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:572)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:530)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:448)
at com.controller.WelcomeController.checkUser(WelcomeController.java:79)
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:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
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:966)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
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.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
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:100)
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:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

LinkedIn login integration with Spring MVC web Application

I am New to Spring ,and I want to log into a Spring MVC app. With LinkedIn ,
I use SCRIBE for login , but when I run the application, it throws an exception.
My controller code for linkedin in MVC is like:
#RequestMapping(value="/loginlinkedin", method=RequestMethod.GET)
public String callback(WebRequest request){
OAuthService service=linkedInServiceProvider.getService();
System.out.println("above request token");
//request token
Token requestToken=service.getRequestToken();
System.out.println(requestToken);
System.out.println("below request token");
//getting authorized url
String oauth_verif= service.getAuthorizationUrl(requestToken);
System.out.println(oauth_verif);
//verifing the requested token
Verifier verifier=new Verifier(in.nextLine());
System.out.println("below verifier"+verifier);
//get AccessToken
Token accessToken=service.getAccessToken(requestToken, verifier);
System.out.println("access tolen"+accessToken);
OAuthRequest oauthRequest=new OAuthRequest(Verb.GET, "http://api.linkedin.com/v1/people/~:(id,first-name,last-name,industry,headline)");
System.out.println("outhrequest"+oauthRequest);
service.signRequest(accessToken, oauthRequest);
Response outhResponse=oauthRequest.send();
System.out.println(outhResponse.getBody());
//ModelAndView mav=new ModelAndView("redirect:loginPage");
return "result";
}
and beans for linked login:
<bean id="linkedInServiceProvider" class="com.spring.handler.OAuthServiceProvider">
<constructor-arg name="oauthServiceConfig" ref="linkedInServiceConfig" />
</bean
And OAuthServiceConfig class for configuration of service:
package com.spring.handler;
import org.scribe.builder.api.Api;
public class OAuthServiceConfig {
private String apiKey;
private String apiSecret;
private String callback;
private Class apiClass;
public OAuthServiceConfig(String apiKey,String apiSecret,String callback,Class apiClass){
super();
this.apiKey=apiKey;
this.apiSecret=apiSecret;
this.callback=callback;
this.apiClass=apiClass;
System.out.println(apiKey+apiSecret+callback+apiClass);
}
public String getApiKey() {
return apiKey;
}
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
public String getApiSecret() {
return apiSecret;
}
public void setApiSecret(String apiSecret) {
this.apiSecret = apiSecret;
}
public String getCallback() {
return callback;
}
public void setCallback(String callback) {
this.callback = callback;
}
public Class getApiClass() {
return apiClass;
}
public void setApiClass(Class apiClass) {
this.apiClass = apiClass;
}
}
and OAuthServiceProvider class for providing the service to OAuthService using linkedInServiceProvider.getService() method:
package com.spring.handler;
import org.scribe.builder.ServiceBuilder;
import org.scribe.oauth.OAuthService;
public class OAuthServiceProvider {
OAuthServiceConfig oauthServiceConfig;
public OAuthServiceProvider() {
}
public OAuthServiceProvider(OAuthServiceConfig oauthServiceConfig) {
this.oauthServiceConfig = oauthServiceConfig;
}
public OAuthService getService() {
System.out.println(oauthServiceConfig);
return new ServiceBuilder().provider(oauthServiceConfig.getApiClass())
.apiKey(oauthServiceConfig.getApiKey())
.apiSecret(oauthServiceConfig.getApiSecret())
.callback(oauthServiceConfig.getCallback()).build();
}
}
But when I log into the application, the exception thrown is:
May 28, 2015 5:42:17 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [HelloWebHandler] in context with path [/SpringHandler] threw exception [Request processing failed; nested exception is org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract token and secret from this: 'oauth_problem=permission_unknown'] with root cause
org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract token and secret from this: 'oauth_problem=permission_unknown'
at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:41)
at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:27)
at org.scribe.oauth.OAuth10aServiceImpl.getAccessToken(OAuth10aServiceImpl.java:104)
at org.scribe.oauth.OAuth10aServiceImpl.getAccessToken(OAuth10aServiceImpl.java:85)
at org.scribe.oauth.OAuth10aServiceImpl.getAccessToken(OAuth10aServiceImpl.java:90)
at com.spring.handler.UserController.callback(UserController.java:109)
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.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
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:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
permission_unknown: The User hasn't decided whether to permit
this Consumer to access Protected Resources. Usually happens when the
Consumer requests Access Token before the user completes authorization
process.
To trace and solve your problem :
Turn the scribe debug mode on executing debug() method on ServiceBuilder.
Read carefully the Getting started guide from scribe-java
Review your code for inconsistences:
//verifing the requested token
Verifier verifier=new Verifier(in.nextLine());
System.out.println("below verifier"+verifier);
What's in? you have to verify the request token, seems like you copied that line from the scribe examples, anyway it's hard to believe that your code works because in is not declared.
Rebuild your controller: implement the start authentication method first, get or store the request token attribute and redirect to the authorization url (linkedin url) if its required (service.getAuthorizationUrl()); implement your callback method, (after the user has approved the access to his profile, he is redirected to our callback endpoint defined in your OAuthServiceConfig class) and get the oauth_verifier and the request token to verify and obtain the accessToken, store it, sign the request... etc... etc

How to solve object is not an instance of declaring class in Liferay

I am trying to deploy a book application which will display some book information and also allow user to add,remove,delete,upload/download etc.But while i am trying to deploy the application i am getting error of object is not an instance of delaring class .I don't know how to solve this erro please help i am posting my exception
14:13:12,567 ERROR [RuntimePageImpl-1][PortletServlet:116] javax.portlet.PortletException: java.lang.reflect.InvocationTargetException
javax.portlet.PortletException: java.lang.reflect.InvocationTargetException
at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:323)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:103)
at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:55)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:112)
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 com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:96)
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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:604)
at com.liferay.portlet.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:677)
at com.liferay.portlet.InvokerPortletImpl.render(InvokerPortletImpl.java:406)
at org.apache.jsp.html.portal.render_005fportlet_jsp._jspService(render_005fportlet_jsp.java:1242)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at com.liferay.portal.servlet.DirectRequestDispatcher.include(DirectRequestDispatcher.java:57)
at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.doDispatch(ClassLoaderRequestDispatcherWrapper.java:78)
at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.include(ClassLoaderRequestDispatcherWrapper.java:53)
at com.liferay.portlet.PortletContainerImpl._doRender(PortletContainerImpl.java:655)
at com.liferay.portlet.PortletContainerImpl.render(PortletContainerImpl.java:138)
at com.liferay.portlet.SecurityPortletContainerWrapper.render(SecurityPortletContainerWrapper.java:141)
at com.liferay.portlet.RestrictPortletContainerWrapper.render(RestrictPortletContainerWrapper.java:126)
at com.liferay.portal.kernel.portlet.PortletContainerUtil.render(PortletContainerUtil.java:156)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer._render(PortletRenderer.java:120)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer.access$4(PortletRenderer.java:107)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer$PortletRendererCallable.doCall(PortletRenderer.java:174)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer$PortletRendererCallable.doCall(PortletRenderer.java:1)
at com.liferay.portal.kernel.executor.CopyThreadLocalCallable.call(CopyThreadLocalCallable.java:69)
at java.util.concurrent.FutureTask.run(Unknown Source)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:682)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:593)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
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 javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:319)
... 39 more
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
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 com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:67)
at com.sun.proxy.$Proxy418.filterRenderURL(Unknown Source)
at com.liferay.portlet.PortletResponseImpl.doCreateLiferayPortletURL(PortletResponseImpl.java:692)
at com.liferay.portlet.PortletResponseImpl$LiferayPortletURLPrivilegedAction.run(PortletResponseImpl.java:773)
at com.liferay.portlet.PortletResponseImpl$LiferayPortletURLPrivilegedAction.run(PortletResponseImpl.java:1)
at com.liferay.portal.security.lang.DoPrivilegedUtil$NoPACL.wrap(DoPrivilegedUtil.java:64)
at com.liferay.portal.security.lang.DoPrivilegedUtil.wrap(DoPrivilegedUtil.java:26)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:267)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:259)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:281)
at com.liferay.portlet.PortletResponseImpl.createRenderURL(PortletResponseImpl.java:291)
at com.liferay.portlet.PortletResponseImpl.createRenderURL(PortletResponseImpl.java:286)
at com.msh.base.BookCatalogPortlet.generateUrls(BookCatalogPortlet.java:436)
at com.msh.base.BookCatalogPortlet.showBooks(BookCatalogPortlet.java:214)
... 44 more
Apr 18, 2015 2:13:12 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet BookCatalog Servlet threw exception
java.lang.IllegalArgumentException: object is not an instance of declaring class
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 com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:67)
at com.sun.proxy.$Proxy418.filterRenderURL(Unknown Source)
at com.liferay.portlet.PortletResponseImpl.doCreateLiferayPortletURL(PortletResponseImpl.java:692)
at com.liferay.portlet.PortletResponseImpl$LiferayPortletURLPrivilegedAction.run(PortletResponseImpl.java:773)
at com.liferay.portlet.PortletResponseImpl$LiferayPortletURLPrivilegedAction.run(PortletResponseImpl.java:1)
at com.liferay.portal.security.lang.DoPrivilegedUtil$NoPACL.wrap(DoPrivilegedUtil.java:64)
at com.liferay.portal.security.lang.DoPrivilegedUtil.wrap(DoPrivilegedUtil.java:26)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:267)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:259)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:281)
at com.liferay.portlet.PortletResponseImpl.createRenderURL(PortletResponseImpl.java:291)
at com.liferay.portlet.PortletResponseImpl.createRenderURL(PortletResponseImpl.java:286)
at com.msh.base.BookCatalogPortlet.generateUrls(BookCatalogPortlet.java:436)
at com.msh.base.BookCatalogPortlet.showBooks(BookCatalogPortlet.java:214)
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 javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:319)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:103)
at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:55)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:112)
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 com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:96)
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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:604)
at com.liferay.portlet.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:677)
at com.liferay.portlet.InvokerPortletImpl.render(InvokerPortletImpl.java:406)
at org.apache.jsp.html.portal.render_005fportlet_jsp._jspService(render_005fportlet_jsp.java:1242)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at com.liferay.portal.servlet.DirectRequestDispatcher.include(DirectRequestDispatcher.java:57)
at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.doDispatch(ClassLoaderRequestDispatcherWrapper.java:78)
at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.include(ClassLoaderRequestDispatcherWrapper.java:53)
at com.liferay.portlet.PortletContainerImpl._doRender(PortletContainerImpl.java:655)
at com.liferay.portlet.PortletContainerImpl.render(PortletContainerImpl.java:138)
at com.liferay.portlet.SecurityPortletContainerWrapper.render(SecurityPortletContainerWrapper.java:141)
at com.liferay.portlet.RestrictPortletContainerWrapper.render(RestrictPortletContainerWrapper.java:126)
at com.liferay.portal.kernel.portlet.PortletContainerUtil.render(PortletContainerUtil.java:156)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer._render(PortletRenderer.java:120)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer.access$4(PortletRenderer.java:107)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer$PortletRendererCallable.doCall(PortletRenderer.java:174)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer$PortletRendererCallable.doCall(PortletRenderer.java:1)
at com.liferay.portal.kernel.executor.CopyThreadLocalCallable.call(CopyThreadLocalCallable.java:69)
at java.util.concurrent.FutureTask.run(Unknown Source)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:682)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:593)
at java.lang.Thread.run(Unknown Source)
14:13:12,583 ERROR [RuntimePageImpl-1][render_portlet_jsp:132] null
java.lang.IllegalArgumentException: object is not an instance of declaring class
at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:67)
at com.liferay.portlet.PortletResponseImpl.doCreateLiferayPortletURL(PortletResponseImpl.java:692)
at com.liferay.portlet.PortletResponseImpl$LiferayPortletURLPrivilegedAction.run(PortletResponseImpl.java:773)
at com.liferay.portlet.PortletResponseImpl$LiferayPortletURLPrivilegedAction.run(PortletResponseImpl.java:1)
at com.liferay.portal.security.lang.DoPrivilegedUtil$NoPACL.wrap(DoPrivilegedUtil.java:64)
at com.liferay.portal.security.lang.DoPrivilegedUtil.wrap(DoPrivilegedUtil.java:26)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:267)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:259)
at com.liferay.portlet.PortletResponseImpl.createLiferayPortletURL(PortletResponseImpl.java:281)
at com.liferay.portlet.PortletResponseImpl.createRenderURL(PortletResponseImpl.java:291)
at com.liferay.portlet.PortletResponseImpl.createRenderURL(PortletResponseImpl.java:286)
at com.msh.base.BookCatalogPortlet.generateUrls(BookCatalogPortlet.java:436)
at com.msh.base.BookCatalogPortlet.showBooks(BookCatalogPortlet.java:214)
at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:319)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:103)
at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:55)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:112)
14:27:50,329 INFO [BookCatalogPortlet:180] Entering showBooks method
14:27:50,332 INFO [BookCatalogPortlet:144] Size of the Database :4
14:27:50,332 INFO [BookCatalogPortlet:145] Current book count in catalog : 4
14:27:50,333 INFO [BookCatalogPortlet:506] Support portlet mode edit
14:27:50,333 INFO [BookCatalogPortlet:506] Support portlet mode help
14:27:50,333 INFO [BookCatalogPortlet:506] Support portlet mode view
14:27:50,333 INFO [BookCatalogPortlet:506] Support portlet mode about
14:27:50,333 INFO [BookCatalogPortlet:506] Support portlet mode config
14:27:50,334 INFO [BookCatalogPortlet:506] Support portlet mode edit_defaults
14:27:50,334 INFO [BookCatalogPortlet:506] Support portlet mode preview
14:27:50,334 INFO [BookCatalogPortlet:506] Support portlet mode print
14:27:50,335 INFO [BookCatalogPortlet:519] Support window state maximized
14:27:50,335 INFO [BookCatalogPortlet:519] Support window state minimized
14:27:50,335 INFO [BookCatalogPortlet:519] Support window state normal
14:27:50,336 INFO [BookCatalogPortlet:519] Support window state exclusive
14:27:50,336 INFO [BookCatalogPortlet:519] Support window state pop_up
14:27:50,341 ERROR [RuntimePageImpl-3][PortletServlet:116] javax.portlet.PortletException: java.lang.reflect.InvocationTargetException
javax.portlet.PortletException: java.lang.reflect.InvocationTargetException
at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:323)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:103)
at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:55)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
These are GenerateUrls() and showBooks() method
private void generateUrls(RenderRequest request, RenderResponse response)
throws PortletModeException, WindowStateException {
// Render URL for Print hyperlink
PortletURL printModeUrl = response.createRenderURL();
if (request.isPortletModeAllowed(new PortletMode("print"))) {
printModeUrl.setPortletMode(new PortletMode("print"));
}
if (request.isWindowStateAllowed(new WindowState("pop_up"))) {
printModeUrl.setWindowState(new WindowState("pop_up"));
}
request.setAttribute("printModeUrl", printModeUrl);
// Action URL for upload Toc action
PortletURL uploadTocActionUrl = response.createActionURL();
uploadTocActionUrl.setParameter("myaction", "uploadTocAction");
uploadTocActionUrl.setParameter(ActionRequest.ACTION_NAME,
"uploadTocAction");
request.setAttribute("uploadTocActionUrl", uploadTocActionUrl);
// Render URL for Full Screen hyperlink
PortletURL fullScreenUrl = response.createRenderURL();
fullScreenUrl.setWindowState(WindowState.MAXIMIZED);
request.setAttribute("fullScreenUrl", fullScreenUrl);
// Render URL for Help hyperlink
PortletURL helpUrl = response.createRenderURL();
helpUrl.setPortletMode(PortletMode.HELP);
request.setAttribute("helpUrl", helpUrl);
// Render URL for Home hyperlink
PortletURL homeUrl = response.createRenderURL();
homeUrl.setPortletMode(PortletMode.VIEW);
request.setAttribute("homeUrl", homeUrl);
// Render URL for Preferences hyperlink
PortletURL prefUrl = response.createRenderURL();
prefUrl.setPortletMode(PortletMode.EDIT);
request.setAttribute("prefUrl", prefUrl);
// Render URL for form submission for Adding book
PortletURL addBookFormUrl = response.createRenderURL();
addBookFormUrl.setParameter("myaction", "addBookForm");
request.setAttribute("addBookFormUrl", addBookFormUrl);
// Action URL for Add Book Action
PortletURL addBookActionUrl = response.createActionURL();
addBookActionUrl.setParameter(ActionRequest.ACTION_NAME,
"addBookAction");
request.setAttribute("addBookActionUrl", addBookActionUrl);
// Action URL for resetting search
PortletURL resetActionUrl = response.createActionURL();
resetActionUrl.setParameter(ActionRequest.ACTION_NAME, "resetAction");
request.setAttribute("resetActionUrl", resetActionUrl);
// Action URL for searching books
PortletURL searchBookActionUrl = response.createActionURL();
searchBookActionUrl.setParameter(ActionRequest.ACTION_NAME,
"searchBookAction");
request.setAttribute("searchBookActionUrl", searchBookActionUrl);
// Render URL for Refresh Search Results link
PortletURL refreshResultsUrl = response.createRenderURL();
refreshResultsUrl.setParameter("myaction", "refreshResults");
request.setAttribute("refreshResultsUrl", refreshResultsUrl);
}
#SuppressWarnings("unchecked")
#RenderMode(name = "VIEW")
public void showBooks(RenderRequest request, RenderResponse response)
throws Exception {
logger.info("Entering showBooks method");
//--return if the content is still valid
if(isMarkupValid(request, response)) {
response.getCacheControl().setUseCachedContent(true);
response.getCacheControl().setExpirationTime(100);
return;
} else {
BookDataObject catalog = (BookDataObject) getPortletContext()
.getAttribute("bookCatalog");
int currentCountInDatastore = catalog.getBooks().size();
// -- set the currentCountInDatabase as the etag value
response.getCacheControl().setETag("" + currentCountInDatastore);
}
PortalContext context = request.getPortalContext();
printSupportedPortletModes(context);
printSupportedWindowStates(context);
// --get user attributes user.name.given and user.name.family
Map<String, Object> userAttributeMap = (Map<String, Object>) request
.getAttribute(PortletRequest.USER_INFO);
String firstName = "";
String lastName = "";
if (userAttributeMap != null) {
firstName = (String) userAttributeMap.get("user.name.given");
lastName = (String) userAttributeMap.get("user.name.family");
request.setAttribute("firstName", firstName);
request.setAttribute("lastName", lastName);
}
String portalInfo = context.getPortalInfo();
request.setAttribute("portalInfo", portalInfo);
// --generate all the URLs that will be used by the portlet
generateUrls(request, response);
String myaction = request.getParameter("myaction");
if (myaction != null) {
logger.info("myaction parameter is not null. Value is " + myaction);
request.getPortletSession().setAttribute("myaction", myaction,
PortletSession.PORTLET_SCOPE);
} else {
// -- if myaction is NULL then show the home page of Book
// catalog
// page
request.getPortletSession().setAttribute("myaction", "showCatalog",
PortletSession.PORTLET_SCOPE);
}
// -- send myaction as a request attribute to the BookServlet.
request.setAttribute("myaction", request.getPortletSession()
.getAttribute("myaction"));
// --dynamically obtain the title for the portlet, based on myaction
String titleKey = "portlet.title."
+ (String) request.getPortletSession().getAttribute("myaction");
response.setTitle(getResourceBundle(request.getLocale()).getString(
titleKey));
// --if the action is uploadTocForm then store the ISBN number of
// the
// --book for which the TOC is being uploaded. The upload action
// will use the ISBN number to create file name -- refer home.jsp
// page
if (((String) request.getAttribute("myaction"))
.equalsIgnoreCase("uploadTocForm")) {
request.getPortletSession().setAttribute("isbnNumber",
request.getParameter("isbnNumber"));
}
if (((String) request.getPortletSession().getAttribute("myaction"))
.equalsIgnoreCase("showSearchResults")) {
request.setAttribute("matchingBooks", request.getPortletSession()
.getAttribute("matchingBooks"));
}
// its important to encode URLs
PortletRequestDispatcher dispatcher = request.getPortletSession()
.getPortletContext().getRequestDispatcher(
response.encodeURL("/myservlet/bookServlet"));
dispatcher.include(request, response);
}
My guess is that in your showBooks() or generateUrls() method you cast an object to another object or do something with an object that is illegal. If you could post the code in the two methods mentioned I could give you a better answer.
As the problem lies deeper within the stacktrace, my guess is that you have some files on the classpath that better shouldn't be there, or are on there twice. Make sure that you have, for example, portlet.jar in the appserver's global classpath and not in your webapp's WEB-INF/lib. Same goes for portal-impl.jar, that one should live within Liferay, but nowhere else - neither global nor your application.
Also, it might help to mark some line numbers. You have several appearances of response.createRenderURL in the code and it'd be good to know if the problem is in the first appearance or some time later.

java.lang.IllegalStateException content - disposition

I am trying to use content - disposition to save something from server to client computer. When I click on button in jsp, dialog opens and I choose to save file. File is saved but I get this exception. I have read on other similar topics something like "Somewhere, your application is calling getOutputStream or getWriter more than once." but I don't know/understand where?
#Controller
public class ExportPhonebook2 {
#Autowired
private PhoneBookService phoneBookSer;
private void setResponseHeader(HttpServletResponse response, String imenikTXT, File file){
response.setHeader("Content-Length", "" + file.length());
response.setContentType("application/txt; charset=UTF-8");
response.setHeader("content-disposition", "attachement; filename=imenik.txt" );
response.setHeader("Content-Transfer-Encoding", "binary");
}
#RequestMapping(value = "/exportPhonebook.html", method = RequestMethod.POST)
public String exportPhonebook(Model model, HttpServletResponse response) {
List<User> listOfAllUsers = phoneBookSer.fetchAllUsers();
String imenik = "";
for (User user : listOfAllUsers) {
imenik = imenik + user.getPrezime() + " " + user.getIme() + ", Telefon: " + user.getTelefon() + ";\r\n" ;
}
try {
File file = new File("c:\\imenik.txt");
setResponseHeader(response, "imenik.txt", file);
FileInputStream fileIn;
fileIn = new FileInputStream(file);
OutputStream outTXT = response.getOutputStream();
byte[] outputByte = new byte[8192];
//copy binary contect to output stream
while(fileIn.read(outputByte, 0, 8192) != -1){
outTXT.write(outputByte, 0, 8192);
}
fileIn.close();
outTXT.flush();
outTXT.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "homepage";
}
}
stacktrace:
Exception initializing page context
java.lang.IllegalStateException: Cannot create a session after the response has been committed
at org.apache.catalina.connector.Request.doGetSession(Request.java:2705)
at org.apache.catalina.connector.Request.getSession(Request.java:2231)
at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:899)
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:229)
at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:572)
at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:517)
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:238)
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:238)
at org.apache.jasper.runtime.PageContextImpl._initialize(PageContextImpl.java:146)
at org.apache.jasper.runtime.PageContextImpl.initialize(PageContextImpl.java:125)
at org.apache.jasper.runtime.JspFactoryImpl.internalGetPageContext(JspFactoryImpl.java:112)
at org.apache.jasper.runtime.JspFactoryImpl.getPageContext(JspFactoryImpl.java:65)
at org.apache.jsp.WEB_002dINF.jsp.homepage_jsp._jspService(homepage_jsp.java:58)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:229)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:328)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:340)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:95)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:340)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:340)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:79)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:340)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:340)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:340)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:119)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:340)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:340)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:340)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:80)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:340)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:175)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
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:76)
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:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
This particular exception is caused because Spring MVC apparently needs to create a session during rendering of the view, but couldn't because the response is already committed with the file download. But your real problem is bigger, Spring MVC should not be rendering a view at all.
You need to tell Spring MVC to not render a view after having taken over the control of the HTTP response from Spring MVC. It is otherwise trying to append the rendered view to the end of the HTTP response which would only corrupt the file download.
I don't do Spring MVC, so I can't answer from top of head, but it appears that just returning void instead of String from the controller's action method should be sufficient in order to tell Spring MVC to not render a view.
java.lang.IllegalStateException: Cannot create a session after the response has been committed
Session creation requires a session cookie to be written to the HTTP header, before the body. Something is trying to create a session after you've flushed and closed your response.
Consider creating the session prior to writing the response.

Multipart Http Request

How can i initialized Multipart request..? I am uploading file using multipart/form-data content type but i can't get multipart request in my controller.So how can i get multipart request in my controller ..
Thanks in Advance.
I am getting error like this..
Jun 13, 2012 2:01:05 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/Login] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Multipart request not initialized] with root cause
java.lang.IllegalStateException: Multipart request not initialized
at org.springframework.web.multipart.support.AbstractMultipartHttpServletRequest.initializeMultipart(AbstractMultipartHttpServletRequest.java:107)
at org.springframework.web.multipart.support.AbstractMultipartHttpServletRequest.getMultipartFiles(AbstractMultipartHttpServletRequest.java:97)
at org.springframework.web.multipart.support.AbstractMultipartHttpServletRequest.getFile(AbstractMultipartHttpServletRequest.java:60)
at com.mpm.common.controller.FileUploadController.create(FileUploadController.java:62)
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.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:279)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
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)
And my JSP code is :
<body>
<h1>Please upload a file</h1>
<form method="post" action="upload.action" enctype="multipart/form-data">
<input type="text" name="name"/></br>
<input type="file" name="file"/></br>
<input type="submit"/>
</form>
</body>
and my servlet-context.xml code is :
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
</bean>
<bean id="fileUploadController" class="com.mpm.common.controller.FileUploadController" ></bean>
You seem to use Spring. In that case, I usually manage multipart requests like this:
#RequestMapping("/url")
public String method(HttpServletRequest request) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
// do stuff with multipartRequest
return "/jsp";
}
You simply need to cast your HttpServletRequest request.
public void upload(HttpServletRequest request) {
File up = new File("C:\\temp"); // path where u need to upload
// Create object of MultipartRequest to upload file
MultipartRequest m;
try {
m = new MultipartRequest(request, up.toString());
Enumeration files = m.getFileNames();
// Get the files to be uploaded from enumeration
while (files.hasMoreElements()) {
String upload = (String) files.nextElement();
filename = m.getFilesystemName(upload);
// out.println("<br/><br/><br/><br/>");
}
} catch (IOException e) {
System.out.println("Error in Uploading files...");
}
xsdName = filename.substring(0, filename.lastIndexOf('.'));
}
it was my code to do the same in servlet. Hope it helps.

Categories