Package org.apache.http

Examples of org.apache.http.HttpEntity


                             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);
      oBody.close();         
        } else {
          aRetVal = null;
        }// fi       
View Full Code Here


      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);
      oBody.close();
      sRetVal = new String(aRetVal, sEncoding);
        } else {
          sRetVal = "";
View Full Code Here

          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);
            }
          });

          inputStream = responseEntity.getContent();
          outputStream = new BufferedOutputStream(new FileOutputStream(file));

          long bytes = 0;
          for (int numBytes = inputStream.read(buffer); numBytes != -1; numBytes = inputStream.read(buffer)) {
            if (_cancelled) {
View Full Code Here

    try {
      // prepare POST body
      String body = methodCall(method, params);

      // set POST body
      HttpEntity entity = new StringEntity(body);
      postMethod.setEntity(entity);

      // This code slightly tweaked from the code by erickok in issue #6
      // Force preemptive authentication
      // This makes sure there is an 'Authentication: ' header being send before trying and failing and retrying
      // by the basic authentication mechanism of DefaultHttpClient
      if(this.httpPreAuth == true) {
        String auth = this.username + ":" + this.password;
        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);
     
      // lets start pulling...
      pullParser.nextTag();
      pullParser.require(XmlPullParser.START_TAG, null, Tag.METHOD_RESPONSE);
     
      pullParser.nextTag(); // either Tag.PARAMS (<params>) or Tag.FAULT (<fault>) 
      String tag = pullParser.getName();
      if (tag.equals(Tag.PARAMS)) {
        // normal response
        pullParser.nextTag(); // Tag.PARAM (<param>)
        pullParser.require(XmlPullParser.START_TAG, null, Tag.PARAM);
        pullParser.nextTag(); // Tag.VALUE (<value>)
        // no parser.require() here since its called in XMLRPCSerializer.deserialize() below
       
        // deserialize result
        Object obj = iXMLRPCSerializer.deserialize(pullParser);
        entity.consumeContent();
        return obj;
      } else
      if (tag.equals(Tag.FAULT)) {
        // fault response
        pullParser.nextTag(); // Tag.VALUE (<value>)
        // no parser.require() here since its called in XMLRPCSerializer.deserialize() below

        // deserialize fault result
        Map<String, Object> map = (Map<String, Object>) iXMLRPCSerializer.deserialize(pullParser);
        String faultString = (String) map.get(Tag.FAULT_STRING);
        int faultCode = (Integer) map.get(Tag.FAULT_CODE);
        entity.consumeContent();
        throw new XMLRPCFault(faultString, faultCode);
      } else {
        entity.consumeContent();
        throw new XMLRPCException("Bad tag <" + tag + "> in XMLRPC response - neither <params> nor <fault>");
      }
    } catch (XMLRPCException e) {
      // catch & propagate XMLRPCException/XMLRPCFault
      throw e;
View Full Code Here

                            this.target,
                            httpget);
                    if (this.forceClose) {
                        httpget.abort();
                    } else {
                        HttpEntity entity = response.getEntity();
                        if (entity != null) {
                            entity.consumeContent();
                        }
                    }
                }
            } catch (Exception ex) {
                this.exception = ex;
View Full Code Here

                    ManagedClientConnection conn = (ManagedClientConnection) this.context.getAttribute(
                            ExecutionContext.HTTP_CONNECTION);
                   
                    this.context.setAttribute("r" + r, conn.getState());
                   
                    HttpEntity entity = response.getEntity();
                    if (entity != null) {
                        entity.consumeContent();
                    }
                }
               
            } catch (Exception ex) {
                this.exception = ex;
View Full Code Here

            connreq.getConnection(250, TimeUnit.MILLISECONDS);
            fail("ConnectionPoolTimeoutException should have been thrown");
        } catch (ConnectionPoolTimeoutException expected) {
        }
       
        HttpEntity e = response.getEntity();
        assertNotNull(e);
        e.consumeContent();
       
        // Expect one connection in the pool
        assertEquals(1, mgr.getConnectionsInPool());

        // Make sure one connection is available
View Full Code Here

            connreq.getConnection(250, TimeUnit.MILLISECONDS);
            fail("ConnectionPoolTimeoutException should have been thrown");
        } catch (ConnectionPoolTimeoutException expected) {
        }
       
        HttpEntity e = response.getEntity();
        assertNotNull(e);
        ByteArrayOutputStream outsteam = new ByteArrayOutputStream();
        e.writeTo(outsteam);
       
        // Expect one connection in the pool
        assertEquals(1, mgr.getConnectionsInPool());

        // Make sure one connection is available
View Full Code Here

            connreq.getConnection(250, TimeUnit.MILLISECONDS);
            fail("ConnectionPoolTimeoutException should have been thrown");
        } catch (ConnectionPoolTimeoutException expected) {
        }
       
        HttpEntity e = response.getEntity();
        assertNotNull(e);
        httpget.abort();
       
        // Expect zero connections in the pool
        assertEquals(0, mgr.getConnectionsInPool());
View Full Code Here

            connreq.getConnection(250, TimeUnit.MILLISECONDS);
            fail("ConnectionPoolTimeoutException should have been thrown");
        } catch (ConnectionPoolTimeoutException expected) {
        }
       
        HttpEntity e = response.getEntity();
        assertNotNull(e);
        // Read the content
        try {
            EntityUtils.toByteArray(e);
            fail("MalformedChunkCodingException should have been thrown");
View Full Code Here

TOP

Related Classes of org.apache.http.HttpEntity

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.