Package org.apache.http

Examples of org.apache.http.HttpResponse


               appName + SEPARATOR + servletClass.getSimpleName(), URLEncodedUtils.format(params, "UTF-8"), null);
         final HttpGet request = new HttpGet(uri);

         // Execute the request
         log.info("Executing request to: " + request.getURI());
         final HttpResponse response = client.execute(request);
         final HttpEntity entity = response.getEntity();
         if (entity == null)
         {
            TestCase.fail("Request returned no entity");
         }
View Full Code Here


               appName + SEPARATOR + servletClass.getSimpleName(), null, null);
         final HttpGet request = new HttpGet(uri);

         // Execute the request
         log.info("Executing request to: " + request.getURI());
         final HttpResponse response = client.execute(request);
         final HttpEntity entity = response.getEntity();
         if (entity == null)
         {
            TestCase.fail("Request returned no entity");
         }
View Full Code Here

   {
      String uri = request.getUri();
      final HttpRequestBase httpMethod = createHttpMethod(uri, request.getHttpMethod());
      loadHttpMethod(request, httpMethod);

      final HttpResponse res = httpClient.execute(httpMethod);

      BaseClientResponse response = new BaseClientResponse(new BaseClientResponseStreamFactory()
      {
         InputStream stream;

         public InputStream getInputStream() throws IOException
         {
            if (stream == null)
            {
               HttpEntity entity = res.getEntity();
               if (entity == null) return null;
               stream = new SelfExpandingBufferredInputStream(entity.getContent());
            }
            return stream;
         }

         public void performReleaseConnection()
         {
            // Apache Client 4 is stupid,  You have to get the InputStream and close it if there is an entity
            // otherwise the connection is never released.  There is, of course, no close() method on response
            // to make this easier.
            try
            {
               if (stream != null)
               {
                  stream.close();
               }
               else
               {
                  InputStream is = getInputStream();
                  if (is != null)
                  {
                     is.close();
                  }
               }
            }
            catch (Exception ignore)
            {
            }
         }
      }, this);
      response.setStatus(res.getStatusLine().getStatusCode());
      response.setHeaders(extractHeaders(res));
      response.setProviderFactory(request.getProviderFactory());
      return response;
   }
View Full Code Here

    oHttpCli.getCredentialsProvider().setCredentials(new AuthScope(oUrl.getHost(), AuthScope.ANY_PORT, realm()),
                             new UsernamePasswordCredentials(user(), password()));       
      HttpGet oGet = null;
      try {
        oGet = new HttpGet(sFilePath);     
        HttpResponse oResp = oHttpCli.execute(oGet);
        HttpEntity oEnty = oResp.getEntity();
        int nLen = (int) oEnty.getContentLength();
        if (nLen>0) {
          aRetVal = new byte[nLen];
          InputStream oBody = oEnty.getContent();
      oBody.read(aRetVal,0,nLen);
View Full Code Here

                             new UsernamePasswordCredentials(user(), password()));       
      HttpGet oGet = null;
      try {

        oGet = new HttpGet(sFilePath);     
        HttpResponse oResp = oHttpCli.execute(oGet);
        HttpEntity oEnty = oResp.getEntity();
        int nLen = (int) oEnty.getContentLength();
        if (nLen>0) {
          byte[] aRetVal = new byte[nLen];
          InputStream oBody = oEnty.getContent();
      oBody.read(aRetVal,0,nLen);
View Full Code Here

        nameValuePairs.add(new BasicNameValuePair("username", _username));
        nameValuePairs.add(new BasicNameValuePair("action", _action));
        nameValuePairs.add(new BasicNameValuePair("version", Main.VERSION));
        req.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse resp = HttpXmlUtils.getHttpClient().execute(req);
        InputStream content = resp.getEntity().getContent();
        String line = new BufferedReader(new InputStreamReader(content)).readLine();
        assert "success".equals(line);
        logger.debug("Usage logger response: {}", line);
      } catch (Exception e) {
        logger.warn("Could not dispatch usage log for action: {} ({})", _action, e.getMessage());
View Full Code Here

  public static Element getRootNode(HttpClient httpClient, String url) throws InvalidHttpResponseException {
    logger.info("getRootNode({})", url);
    try {
      HttpGet method = new HttpGet(url);
      HttpResponse response = httpClient.execute(method);
      int statusCode = response.getStatusLine().getStatusCode();
      if (statusCode != 200) {
        logger.error("Response status code was: {} (url={})", statusCode, url);
        throw new InvalidHttpResponseException(url, response);
      }
      InputStream inputStream = response.getEntity().getContent();
      Document document = createDocumentBuilder().parse(inputStream);
      return (Element) document.getFirstChild();
    } catch (Exception e) {
      if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
View Full Code Here

        final HttpClient httpClient = HttpXmlUtils.getHttpClient();
        final HttpGet method = new HttpGet(url);

        if (!_cancelled) {
          final HttpResponse response = httpClient.execute(method);

          if (response.getStatusLine().getStatusCode() != 200) {
            throw new InvalidHttpResponseException(url, response);
          }

          final HttpEntity responseEntity = response.getEntity();
          final long expectedSize = responseEntity.getContentLength();
          publish(new Task() {
            @Override
            public void execute() throws Exception {
              _downloadProgressWindow.setExpectedSize(file, expectedSize);
View Full Code Here

        postMethod.addHeader("Authorization", "Basic " + Base64Coder.encode(auth.getBytes()).toString());
      }
     
      //Log.d(Tag.LOG, "ros HTTP POST");
      // execute HTTP POST request
      HttpResponse response = client.execute(postMethod);
      //Log.d(Tag.LOG, "ros HTTP POSTed");

      // check status code
      int statusCode = response.getStatusLine().getStatusCode();
      //Log.d(Tag.LOG, "ros status code:" + statusCode);
      if (statusCode != HttpStatus.SC_OK) {
        throw new XMLRPCException("HTTP status code: " + statusCode + " != " + HttpStatus.SC_OK);
      }

      // parse response stuff
      //
      // setup pull parser
      XmlPullParser pullParser = XmlPullParserFactory.newInstance().newPullParser();
      entity = response.getEntity();
      Reader reader = new InputStreamReader(new BufferedInputStream(entity.getContent()));
// for testing purposes only
// reader = new StringReader("<?xml version='1.0'?><methodResponse><params><param><value>\n\n\n</value></param></params></methodResponse>");
      pullParser.setInput(reader);
     
View Full Code Here

    //if we do not set the content type to JSON, the client will use
    //ISO-8859-1 as the charset. JSON standard does not support this.
    input.setContentType("application/json");
    postRequest.setEntity(input);

    HttpResponse response = httpClient.execute(postRequest);

    Assert.assertEquals(HttpServletResponse.SC_OK,
            response.getStatusLine().getStatusCode());
    Transaction tx = channel.getTransaction();
    tx.begin();
    Event e = channel.take();
    Assert.assertNotNull(e);
    Assert.assertEquals("b", e.getHeaders().get("a"));
View Full Code Here

TOP

Related Classes of org.apache.http.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.