title: SpringBoot RestTemplate return 403 forbidden when executing from docker container
body: <p>I am trying to implement Spring Boot RestTemplate and invoke external REST service using Java Code. This is working as java application but when I am <strong>deploying same code in docker container</strong> I am getting error</p>
  <pre><code>org.springframework.web.client.HttpClientErrorException$Forbidden: 403 Forbidden: [error code: 1010]
  </code></pre>
  <p>Here is my code ..which is running standalone ..</p>
  <pre><code>@RequestMapping(value = &quot;/extservice&quot;, 
                      produces = MediaType.APPLICATION_JSON_VALUE, 
                      method = RequestMethod.GET)
      public User httpcall() {
          
          ResponseEntity&lt;User&gt; result = null;
           
          try {
               
              HttpHeaders headers = new HttpHeaders();
              headers.add(&quot;user-agent&quot;, &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36&quot;);
              headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
              headers.setContentType(MediaType.APPLICATION_JSON);
              HttpEntity&lt;Object&gt; entity = new HttpEntity&lt;Object&gt;(headers);
              final String uri = &quot;https://reqres.in/api/users/2&quot;;
              RestTemplate restTemplate = new RestTemplate();
               
              result = restTemplate.getForEntity(uri, User.class);
               
              System.out.println(result.toString());
           
  
          } catch (Exception e) {
  
              e.printStackTrace();
          }
          
          return result.getBody();
  
      }
  </code></pre>
  <p>and here is the error stack trace</p>
  <pre><code>org.springframework.web.client.HttpClientErrorException$Forbidden: 403 Forbidden: [error code: 1010]
      at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:109)
      at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:170)
      at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:112)
      at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
      at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:782)
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:740)
      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:674)
      at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:342)
      at com.dockerforjavadevelopers.hello.HelloController.httpcall(HelloController.java:38)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  
  ....
  
  2020-07-25 04:52:17.578 ERROR 1 --- [nio-9898-exec-4] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] in context with path [/opa-test] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
  
  java.lang.NullPointerException: null
      at com.dockerforjavadevelopers.hello.HelloController.httpcall(HelloController.java:48) ~[classes!/:0.1.0]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_212]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]
      at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]
      at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
  
  </code></pre>
  <p>Here is my docker file</p>
  <pre><code># Maven build container 
  
  FROM maven:3.6.3-jdk-11-slim as mavenbuild
  
  COPY pom.xml /tmp/
  
  COPY src /tmp/src/
  
  WORKDIR /tmp/
  
  RUN mvn package
  
  #pull base image
  
  FROM openjdk:8-jdk-alpine
  
  EXPOSE 9898
  
  #default command
  CMD java -jar /data/opa-test-0.1.0.jar
  
  #copy hello world to docker image from builder image
  
  COPY --from=mavenbuild /tmp/target/opa-test-0.1.0.jar /data/opa-test-0.1.0.jar
  </code></pre>