title: PUT request resulted in 500 (Server Error); invoking error handler
body: <h1>Method to update metadata info of my model through Rest client</h1>
  
  <p>my requirement is to do a PUT operation based on a key,along ith this i am sending request parameter for my model which is ProjectMetadata here.</p>
  
  <pre><code>@RequestMapping(value = "/api/di/v1/app/{projectKey}/metadata", method = RequestMethod.PUT, consumes = "application/json")
  public ResponseEntity&lt;?&gt; updateProject(@PathVariable(value = "projectKey") 
  String projectKey,
          @RequestBody ProjectMetadata metadata) throws JSONException {
  
      HttpHeaders headers = new HttpHeaders();
      headers.setContentType(MediaType.APPLICATION_JSON);
      headers.add("Authorization", "Basic &lt;aut key&gt;");
  
      JSONObject requestBody = new JSONObject();
      requestBody.put("label", metadata.getLabel());
      requestBody.put("description", metadata.getDescription());
      requestBody.put("shortDesc", metadata.getShortDesc());
      requestBody.put("tag", metadata.getTags());
      logger.debug("requestBody" + requestBody);
  
      HttpEntity&lt;String&gt; requestEntity = new HttpEntity&lt;String&gt;(requestBody.toString(), headers);
      logger.debug("requestentity" + requestEntity.toString());
  
      RestTemplate restTemplate = new RestTemplate();
      String url = "http://&lt;&gt;/public/api/projects/{projectKey}/metadata";
      logger.debug("trying to send request to create project");
      ResponseEntity&lt;?&gt; createResponse = null;
  
      try {
          createResponse = restTemplate.exchange(url, HttpMethod.PUT, requestEntity, String.class, projectKey);
          // restTemplate.put(url, requestEntity,projectKey);
      } catch (HttpClientErrorException e) {
  
          logger.error("Exceptions occurred while processing the request::");
          return new ResponseEntity&lt;String&gt;(e.getResponseBodyAsString(), HttpStatus.BAD_REQUEST);
      }
      return createResponse;
  }
  </code></pre>
  
  <h2>ProjectMetadata Model</h2>
  
  <pre><code>public class ProjectMetadata 
  {
     private String label;
     private String description;
     private String shortDesc;
     private List&lt;String&gt; tags;
  
     public ProjectMetadata() {
         super();
     }
     public ProjectMetadata(String label, String description, String shortDesc, List&lt;String&gt; tags) {
         super();
         this.label = label;
         this.description = description;
         this.shortDesc = shortDesc;
         this.tags = tags;
     }
     public String getLabel() {
         return label;
     }
     public void setLabel(String label) {
         this.label = label;
     }
     public String getDescription() {
         return description;
     }
     public void setDescription(String description) {
         this.description = description;
     }
     public String getShortDesc() {
         return shortDesc;
     }
     public void setShortDesc(String shortDesc) {
         this.shortDesc = shortDesc;
     }
     public List&lt;String&gt; getTags() {
         return tags;
     }
     public void setTags(List&lt;String&gt; tags) {
         this.tags = tags;
     }
  </code></pre>
  
  <p>}</p>
  
  <h1>error stack</h1>
  
  <pre><code>&gt;2018-04-10 11:48:00,342 11345 [http-nio-9080-exec-1] DEBUG o.s.core.annotation.AnnotationUtils - Failed to meta-introspect annotation [interface org.springframework.web.bind.annotation.RequestBody]: java.lang.NullPointerException
  2018-04-10 11:48:00,350 11353 [http-nio-9080-exec-1] DEBUG c.p.controller.ProjectController - requestBody{"description":"adsfy","shortDesc":"nsfdf","label":"testapp","tag":["tag12"]}
  2018-04-10 11:48:00,354 11357 [http-nio-9080-exec-1] DEBUG c.p.controller.ProjectController - requestentity&lt;{"description":"adsfy","shortDesc":"nsfdf","label":"testapp","tag":["tag12"]},{Content-Type=[application/json], Authorization=[Basic &lt;&gt;]}&gt;
  2018-04-10 11:48:00,366 11369 [http-nio-9080-exec-1] DEBUG c.p.controller.ProjectController - trying to send request to create project
  2018-04-10 11:48:00,394 11397 [http-nio-9080-exec-1] DEBUG o.s.web.client.RestTemplate - Created PUT request for "http://&lt;&gt;/public/api/projects/abcde/metadata"
  2018-04-10 11:48:00,394 11397 [http-nio-9080-exec-1] DEBUG o.s.web.client.RestTemplate - Setting request Accept header to [text/plain, application/json, application/*+json, */*]
  2018-04-10 11:48:00,394 11397 [http-nio-9080-exec-1] DEBUG o.s.web.client.RestTemplate - Writing [{"description":"adsfy","shortDesc":"nsfdf","label":"testapp","tag":["tag12"]}] as "application/json" using [org.springframework.http.converter.StringHttpMessageConverter@6c0f36de]
  2018-04-10 11:48:00,954 11957 [http-nio-9080-exec-1] DEBUG o.s.web.client.RestTemplate - PUT request for "http://&lt;&gt;/public/api/projects/abcde/metadata" resulted in 500 (Server Error); invoking error handler
  2018-04-10 11:48:00,954 11957 [http-nio-9080-exec-1] DEBUG o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Resolving exception from handler [public org.springframework.http.ResponseEntity&lt;?&gt; com.project.controller.ProjectController.updateProject(java.lang.String,com.model.project.ProjectMetadata) throws org.json.JSONException]: org.springframework.web.client.HttpServerErrorException: 500 Server Error
  2018-04-10 11:48:00,958 11961 [http-nio-9080-exec-1] DEBUG o.s.w.s.m.a.ResponseStatusExceptionResolver - Resolving exception from handler [public org.springframework.http.ResponseEntity&lt;?&gt; com.project.controller.ProjectController.updateProject(java.lang.String,com.model.project.ProjectMetadata) throws org.json.JSONException]: org.springframework.web.client.HttpServerErrorException: 500 Server Error
  2018-04-10 11:48:00,958 11961 [http-nio-9080-exec-1] DEBUG o.s.w.s.m.s.DefaultHandlerExceptionResolver - Resolving exception from handler [public org.springframework.http.ResponseEntity&lt;?&gt; com.project.controller.ProjectController.updateProject(java.lang.String,com.model.project.ProjectMetadata) throws org.json.JSONException]: org.springframework.web.client.HttpServerErrorException: 500 Server Error
  2018-04-10 11:48:00,962 11965 [http-nio-9080-exec-1] DEBUG o.s.web.servlet.DispatcherServlet - Could not complete request
  org.springframework.web.client.HttpServerErrorException: 500 Server Error
      at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:97)
      at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:79)
      at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
      at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:777)
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:730)
      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:686)
      at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:602)
      at com.project.controller.ProjectController.updateProject(ProjectController.java:120)
      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:209)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
      at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:892)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:664)
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
      at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
      at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
      at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
      at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
      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)
  2018-04-10 11:48:00,962 11965 [http-nio-9080-exec-1] DEBUG o.s.b.w.s.f.OrderedRequestContextFilter - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@440e2d74
  2018-04-10 11:48:00,966 11969 [http-nio-9080-exec-1] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.HttpServerErrorException: 500 Server Error] with root cause
  org.springframework.web.client.HttpServerErrorException: 500 Server Error
      at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:97)
      at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:79)
      at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
      at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:777)
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:730)
      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:686)
      at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:602)
      at com.project.controller.ProjectController.updateProject(ProjectController.java:120)
      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:209)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
      at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:892)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:664)
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
      at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
      at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
      at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
      at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
      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)
  2018-04-10 11:48:00,970 11973 [http-nio-9080-exec-1] DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name 'dispatcherServlet' processing PUT request for [/error]
  2018-04-10 11:48:00,970 11973 [http-nio-9080-exec-1] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /error
  2018-04-10 11:48:00,974 11977 [http-nio-9080-exec-1] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Returning handler method [public org.springframework.http.ResponseEntity&lt;java.util.Map&lt;java.lang.String, java.lang.Object&gt;&gt; org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)]
  2018-04-10 11:48:00,974 11977 [http-nio-9080-exec-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'basicErrorController'
  2018-04-10 11:48:01,006 12009 [http-nio-9080-exec-1] DEBUG o.s.w.s.m.m.a.HttpEntityMethodProcessor - Written [{timestamp=Tue Apr 10 11:48:00 IST 2018, status=500, error=Internal Server Error, message=500 Server Error, path=/rfi/api/di/v1/app/abcde/metadata/}] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@4e9658b5]
  2018-04-10 11:48:01,006 12009 [http-nio-9080-exec-1] DEBUG o.s.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
  2018-04-10 11:48:01,006 12009 [http-nio-9080-exec-1] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request
  </code></pre>
  
  <p><i>
  What is causing this error?Plase help</i></p>
  
  <p><a href="https://i.stack.imgur.com/YlAW6.png" rel="nofollow noreferrer">request and response image</a></p>
  
  <p><a href="https://i.stack.imgur.com/A4kXG.png" rel="nofollow noreferrer">headers</a></p>
  
  <p><a href="https://i.stack.imgur.com/Agszb.png" rel="nofollow noreferrer">request</a></p>