Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/apache/http/client/protocol/HttpClientContext

Yves Nicolas picture Yves Nicolas · Feb 11, 2014 · Viewed 11.1k times · Source

I am struggling with a NoClassDefFound exception in access to spring-social linked in and facebook. What is strange is I have a project which works using the same code for connexion and one which does nt. I have gone thru the differences between the 2 of them and doesnt see any which makes sense to me.

Here is the full trace I get. Any hint or search direction is welcome.

    type Exception report
    message Handler processing failed; nested exception is java.lang.NoClassDefFoundError:     org/apache/http/client/protocol/HttpClientContext

    description The server encountered an internal error that prevented it from fulfilling this request.exception

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/apache/http/client/protocol/HttpClientContext
    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:936)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
    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)

root cause

java.lang.NoClassDefFoundError: org/apache/http/client/protocol/HttpClientContext
    org.springframework.social.support.ClientHttpRequestFactorySelector$HttpComponentsClientRequestFactoryCreator$1.createHttpContext(ClientHttpRequestFactorySelector.java:80)
    org.springframework.http.client.HttpComponentsClientHttpRequestFactory.createRequest(HttpComponentsClientHttpRequestFactory.java:134)
    org.springframework.http.client.support.HttpAccessor.createRequest(HttpAccessor.java:76)
    org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:484)
    org.springframework.web.client.RestTemplate.execute(RestTemplate.java:452)
    org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:302)
    org.springframework.social.oauth2.OAuth2Template.postForAccessGrant(OAuth2Template.java:232)
    org.springframework.social.oauth2.OAuth2Template.exchangeForAccess(OAuth2Template.java:142)
    org.springframework.social.connect.web.ConnectSupport.completeConnection(ConnectSupport.java:151)
    org.springframework.social.connect.web.ConnectController.oauth2Callback(ConnectController.java:250)
    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:606)
    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:936)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
    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)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.37 logs.

Answer

Vincent Devillers picture Vincent Devillers · Feb 11, 2014

org/apache/http/client/protocol/HttpClientContext is a class packaged in httpcomponents-client since the 4.3 (https://hc.apache.org/httpcomponents-client-4.3.x/httpclient/apidocs/org/apache/http/client/protocol/HttpClientContext.html). I think you don't have the right version or the project at all.

Try adding this:

<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpclient</artifactId>
  <version>4.3.2</version>
</dependency>