Package HTTPClient

Examples of HTTPClient.HTTPResponse


     */
    private static InputStream getInputStream(HTTPConnection httpConnection, String path, int tries) throws IOException {
        while(true) {
            try {
                amazonRequestRate.passThrough();
                HTTPResponse response = httpConnection.Get(path);
                if(response.getStatusCode() != 200) throw new IOException("Unexpected status code " + response.getStatusCode());
                return response.getInputStream();
            } catch(ModuleException e) {
                tries--;
                if(tries <= 0) {
                    IOException ioException = new IOException();
                    ioException.initCause(e);
View Full Code Here


            public void run() {
                try {
                    // do the request
                    final String path = "/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=10GN481Z3YQ4S67KNSG2&Operation=ItemLookup&ResponseGroup=ItemAttributes&ItemId=" + asin;
                    amazonRequestRate.passThrough();
                    HTTPResponse response = httpConnection.Get(path);
                    // tell someone else to handle the response
                    enqueue(responseQueue, new ItemReceiver(remainingRetries, asin, response));

                } catch (IOException e) {
                    handleError(remainingRetries, asin, e);
View Full Code Here

      }

      // connect and post
      HTTPConnection httpConnection = getHTTPConnection(url);

      HTTPResponse httpResponse;
      if (xmlRqst != null && xmlRqst.length() > MP_FORM_DATA_TRESHOLD)
      {
        // multipart form data (faster?)
        NVPair[] ct_hdr = new NVPair[1];
        byte[] data = Codecs.mpFormDataEncode(formData,null,ct_hdr);
        httpResponse = httpConnection.Post(url.getFile(),data,ct_hdr);
      }
      else
      {
        // urlencoded (slow?)
        httpResponse = httpConnection.Post(url.getFile(),formData);
      }

      if (httpResponse.getStatusCode() >= 200 && httpResponse.getStatusCode() < 300)
      {
        // ok
        sessionData = httpResponse.getHeader("XMLDispatcher-SessionData");
        return getResponseText(httpResponse);
       }
      else
      {
        // error
        if (httpResponse.getStatusCode() == 510)
        {
          // xmldispatcher error
          RplyEnvelopeError error = ErrorMarshallerXML.unmarshallError(getResponseText(httpResponse));
          XMLDispatcherException exception = error.getException();
          if (exception instanceof XMLDispatcherAppException)
          {
            throw (XMLDispatcherAppException)exception;
          }
          else if (exception instanceof XMLDispatcherUserException)
          {
            throw (XMLDispatcherUserException)exception;
          }
          else
          {
            throw (XMLDispatcherSystemException)exception;
          }
        }
        else
        {
          // any other error
          throw new XMLDispatcherCommException("HTTP error " +
                                               httpResponse.getStatusCode() +
                                               ": " +
                                               httpResponse.getReasonLine());
        }
      }
    }
    catch(ModuleException e)
    {
View Full Code Here

  URI url = new URI(args[0]);

  DefaultAuthHandler.setAuthorizationPrompter(new MyAuthPrompter(pa_name, pa_pass));
  HTTPConnection con = new HTTPConnection(url);
  HTTPResponse   rsp = con.Head(url.getPathAndQuery());

  int sts = rsp.getStatusCode();
  if (sts < 300)
      System.out.println("No authorization required to access " + url);
  else if (sts >= 400  &&  sts != 401  &&  sts != 407)
      System.out.println("Error trying to access " + url + ":\n" + rsp);
    }
View Full Code Here

    }

    @RunRate(50)
    @Test
    public void doTest() throws Exception {
      HTTPResponse result = request.GET("http://www.naver.com");
      if (result.getStatusCode() != 200) {
        grinder.getStatistics().getForLastTest().setSuccess(false);
      } else {
        grinder.getStatistics().getForLastTest().setSuccess(true);
      }
    }
View Full Code Here

    @Test
    @RunRate(10)
    public void doTest2() throws Exception {
      grinder.getStatistics().setDelayReports(true);
      HTTPResponse result = request.GET("http://www.google.co.kr");
      if (result.getStatusCode() != 200) {
        grinder.getStatistics().getForLastTest().setSuccess(false);
      } else {
        grinder.getStatistics().getForLastTest().setSuccess(true);
      }
    }
View Full Code Here

    String data = "";

    try {
      HTTPConnection con = new HTTPConnection(host);
      HTTPResponse rsp = con.Get(path);
      // Call getText to block the connection until it gets the whole page.
      rsp.getText();
      byte[] bytes = rsp.getData();

      // Create decoder for ISO-8859-2
      Charset cset = Charset.forName(charset);
      CharsetDecoder decoder = cset.newDecoder();
View Full Code Here

            throw new IOException(uri);
        }
        final URL url = new URL(uri);
        final HTTPConnection httpConnection = new HTTPConnection(url);
        try {
            final HTTPResponse resp = httpConnection.Get(m.group(1));
            return resp.getText();
        } catch (ModuleException e) {
            throw new IOException(e.toString());
        } catch (ParseException e) {
            throw new IOException(e.toString());
        }
View Full Code Here

TOP

Related Classes of HTTPClient.HTTPResponse

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.