Package org.springframework.http.client

Examples of org.springframework.http.client.ClientHttpResponse


    public HttpMethod getMethod() {
      return HttpMethod.POST;
    }

    public ClientHttpResponse execute() throws IOException {
      return new ClientHttpResponse() {

        public HttpHeaders getHeaders() {
          return responseHeaders;
        }
View Full Code Here


                                                  notifier.getPassword().length > 0;
            configBuilder.setAuthenticationEnabled(authenticationEnabled);

            method.setConfig(configBuilder.build());

            ClientHttpResponse response = requestFactory.execute(method, new Function<HttpClientBuilder, Void>() {
                @Nullable
                @Override
                public Void apply(@Nullable HttpClientBuilder input) {
                    final CredentialsProvider provider = Lib.net.setupProxy(settingManager, input);
                    if (authenticationEnabled) {
                        System.out.println("webUpdate: SET USER");
                        provider.setCredentials( AuthScope.ANY, new UsernamePasswordCredentials(notifier.getUsername(), String.copyValueOf(notifier.getPassword())));

                        configBuilder.setAuthenticationEnabled(true);
                    }
                    return null;
                }
            });

      // Execute the method.
      if (response.getStatusCode() != HttpStatus.OK) {
        throw new MetadataNotifierClientException("Method failed: " + response.getStatusText());
      }

      // Read the response body.
      // byte[] responseBody = method.getResponseBody();
View Full Code Here

                RequestConfig.Builder config = RequestConfig.custom();
                method.setEntity(new StringEntity(harvestResponse));
                config.setAuthenticationEnabled(false);
                method.setConfig(config.build());

                final ClientHttpResponse httpResponse = applicationContext.getBean(GeonetHttpRequestFactory.class).execute(method,
                        new Function<HttpClientBuilder, Void>() {
                            @Nullable
                            @Override
                            public Void apply(@Nonnull HttpClientBuilder input) {
                                SettingManager settingManager = applicationContext.getBean(SettingManager.class);
                                Lib.net.setupProxy(settingManager, input);
                                input.setRetryHandler(new DefaultHttpRequestRetryHandler());
                                return null;
                            }
                        });
                if (httpResponse.getStatusCode() != HttpStatus.OK) {
                    // never mind, just log it
                    Log.warning(Geonet.CSW_HARVEST, "WARNING: Failed to send HarvestResponse to responseHandler " + responseHandler + ", HTTP status is " + httpResponse.getStatusText());
                }
            } catch (IOException x) {
                // never mind, just log it
                Log.warning(Geonet.CSW_HARVEST, "WARNING: " + x.getMessage() + " (this exception is swallowed)");
                x.printStackTrace();
View Full Code Here


    try {
        // Connect
            final GeonetHttpRequestFactory requestFactory = context.getBean(GeonetHttpRequestFactory.class);
            final ClientHttpResponse httpResponse = requestFactory.execute(req, new Function<HttpClientBuilder, Void>() {
                @Nullable
                @Override
                public Void apply(@Nullable HttpClientBuilder input) {
                    // set proxy from settings manager
                    Lib.net.setupProxy(context, input);
                    return null//To change body of implemented methods use File | Settings | File Templates.
                }
            });

            if(log.isDebugEnabled()) {
                log.debug("   Get " + httpResponse.getStatusCode());
            }

      if (httpResponse.getStatusCode() == HttpStatus.OK) {
          // Save image document to temp directory
        // TODO: Check OGC exception
                OutputStream fo = null;
                InputStream in = null;
               
                try {
                    fo = new FileOutputStream (dir + filename);
                    in = httpResponse.getBody();
                    BinaryFile.copy (in,fo);
                } finally {
                    IOUtils.closeQuietly(in);
                    IOUtils.closeQuietly(fo);
                }
View Full Code Here

      m.addHeader(new BasicScheme().authenticate(new UsernamePasswordCredentials(username, password), m));
    } catch (AuthenticationException a) {
      Log.warning(LOGGER_NAME, "Failed to add the authentication Header, error is: " + a.getMessage());
    };

        final ClientHttpResponse httpResponse = factory.execute(m, new UsernamePasswordCredentials(username, password), AuthScope.ANY);

        try {
            status = httpResponse.getRawStatusCode();
            if(Log.isDebugEnabled(LOGGER_NAME)) {
                Log.debug(LOGGER_NAME, "status:" + status);
            }
            if (saveResponse) {
                this.response = IOUtils.toString(httpResponse.getBody());
            }
        }finally {
            httpResponse.close();
        }


    return status;
  }
View Full Code Here

  protected final Element executeAndReadResponse(HttpRequestBase httpMethod) throws IOException, BadXmlResponseEx
  {


        final ClientHttpResponse httpResponse = doExecute(httpMethod);

        if (httpResponse.getRawStatusCode() > 399) {
            throw new BadServerResponseEx(httpResponse.getStatusText() +
                    " -- URI: " + httpMethod.getURI() +
                    " -- Response Code: " + httpResponse.getRawStatusCode());
        }

        byte[] data = null;

    try {
        data = IOUtils.toByteArray(httpResponse.getBody());
      return Xml.loadStream(new ByteArrayInputStream(data));
    }

    catch(JDOMException e)
    {
View Full Code Here

    InputStream  is = null;
    OutputStream os = null;

    try
    {
            final ClientHttpResponse httpResponse = doExecute(httpMethod);

      is = httpResponse.getBody();
      os = new FileOutputStream(outFile);
     
      BinaryFile.copy(is, os);

      return outFile;
View Full Code Here

        assertEquals(new MediaType("application", "pdf"), response.getHeaders().getContentType());
        assertTrue(response.getBody().read() >= 0);
    }

    private String getDefaultAppDefaultRequestSample() throws IOException, URISyntaxException, JSONException {
        ClientHttpResponse exampleResp = getPrintRequest(MapPrinterServlet.EXAMPLE_REQUEST_URL, HttpMethod.GET).execute();
        JSONObject examples = new JSONObject(new String(ByteStreams.toByteArray(exampleResp.getBody()), "UTF-8"));
        return examples.getString((String) examples.keys().next());
    }
View Full Code Here

    }

    private void waitUntilDoneOrError(String ref) throws Exception {
        boolean done = false;
        do {
            ClientHttpResponse response = null;

            try {
                ClientHttpRequest request = getPrintRequest(
                        MapPrinterServlet.STATUS_URL + "/" + ref + ".json", HttpMethod.GET);
                response = request.execute();
                final JSONObject statusResult = new JSONObject(
                        getBodyAsText(response));
                done = statusResult.getBoolean(MapPrinterServlet.JSON_DONE);

                if (!done) {
                    if (statusResult.has(MapPrinterServlet.JSON_ERROR)) {
                        done = true;
                    } else {
                        Thread.sleep(500);
                    }
                }
            } catch(Exception exc) {
                done = true;
            } finally {
                if (response != null) {
                    response.close();
                }
            }
        } while(!done);
    }
View Full Code Here

            } catch (URISyntaxException e) {
                uri = new File(styleRef).toURI();
            }

            final ClientHttpRequest request = clientHttpRequestFactory.createRequest(uri, HttpMethod.GET);
            final ClientHttpResponse response = closer.register(request.execute());
            statusCode = response.getStatusCode();
            input = ByteStreams.toByteArray(response.getBody());
        } catch (Exception e) {
            return Optional.absent();
        } finally {
            closer.close();
        }
View Full Code Here

TOP

Related Classes of org.springframework.http.client.ClientHttpResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.