Android HttpEntityEnclosingRequest - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android HttpEntityEnclosingRequest class.

This code example shows how to use the following methods:setEntity, releaseConnection
            final FileBody fileBody = new FileBody( file );
 
            final MultipartEntity entity = new MultipartEntity();
            entity.addPart( file.getName(), fileBody );
             
            final HttpPut httpPut = new HttpPut();
            httpPut.setEntity( entity );
             
            Object response = httpJSONAPI( httpPut, getUpdateURI( appName ) );
             
            if( response instanceof JSONObject )
            { 
                JSONObject json = (JSONObject)response;
                 
                if( isSuccess( json ))
                { 
                    System.out.println( "updateApplication: success." ); //$NON-NLS-1$
                } 
                else 
                { 

7
CodeRank
This code example shows how to use the following methods:setEntity
        return request;
    } 
 
    public void receiveRequestEntity(final HttpEntityEnclosingRequest request)
            throws HttpException, IOException { 
        Args.notNull(request, "HTTP request");
        ensureOpen(); 
        final HttpEntity entity = prepareInput(request);
        request.setEntity(entity);
    } 
 
    public void sendResponseHeader(final HttpResponse response)
            throws HttpException, IOException { 
        Args.notNull(response, "HTTP response");
        ensureOpen(); 
        this.responseWriter.write(response);
        onResponseSubmitted(response);
        if (response.getStatusLine().getStatusCode() >= 200) {
            incrementResponseCount(); 
        } 
6
CodeRank
This code example shows how to use the following methods:getEntity
        incrementRequestCount(); 
    } 
 
    public void sendRequestEntity(final HttpEntityEnclosingRequest request)
            throws HttpException, IOException { 
        Args.notNull(request, "HTTP request");
        ensureOpen(); 
        final HttpEntity entity = request.getEntity();
        if (entity == null) {
            return; 
        } 
        final OutputStream outstream = prepareOutput(request);
        entity.writeTo(outstream);
        outstream.close();
    } 
 
    public HttpResponse receiveResponseHeader() throws HttpException, IOException {
        ensureOpen(); 
        final HttpResponse response = this.responseParser.parse();
        onResponseReceived(response);
6
CodeRank
This code example shows how to use the following methods:setEntity, addHeader
                connReuseStrategy,
                responseFactory,
                handlerResolver);
        final HttpCoreContext context = HttpCoreContext.create();
        final HttpServerConnection conn = Mockito.mock(HttpServerConnection.class);
        final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
        final InputStream instream = Mockito.mock(InputStream.class);
        final InputStreamEntity entity = new InputStreamEntity(instream, -1);
        request.setEntity(entity);
 
        Mockito.when(conn.receiveRequestHeader()).thenReturn(request);
        final HttpResponse resp100 = new BasicHttpResponse(HttpVersion.HTTP_1_1, 100, "Continue");
        Mockito.when(responseFactory.newHttpResponse(HttpVersion.HTTP_1_1, 100, context)).thenReturn(resp100);
        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        Mockito.when(responseFactory.newHttpResponse(HttpVersion.HTTP_1_1, 200, context)).thenReturn(response);
        Mockito.when(connReuseStrategy.keepAlive(response, context)).thenReturn(Boolean.FALSE);
 
        httpservice.handleRequest(conn, context);
 

6
CodeRank
This code example shows how to use the following methods:setEntity, setParams
			// Set up the POST request 
			HttpPost postRequest = getPost(data);
 
			// Do the request 
			HttpClient client = new DefaultHttpClient();
			HttpResponse response = client.execute(postRequest);
			 
			// Package the returned JSON into a SpeechResponse 
			SpeechResponse speechResponse = packageResponse(response);
			 
			// Close the stream 
			//response.getEntity().getContent().close(); 
 
			return speechResponse;
 
		} catch (FileNotFoundException ex) {
			ex.printStackTrace();
		} catch (IOException ioe) {
			ioe.printStackTrace();
		} catch(Exception e){  //TODO Remove Pokemon

6
CodeRank
This code example shows how to use the following methods:setEntity
 
	public void uploadMachine(Machine m, String uri) {
 
		try { 
			HttpClient httpclient = new DefaultHttpClient();
			HttpPost httppost = new HttpPost(uri);
			httppost.setEntity(m.makeJSON());
			HttpResponse response = httpclient.execute(httppost);
			HttpEntity entity = response.getEntity();
 
			Log.d("HTTP", "HTTP: OK");
		} catch (Exception e) {
			Log.e("HTTP", "Error in http connection " + e.toString());
		} 
 
	} 
 
	/** 
	 * Known issues: duplicate key errors when you run the same code twice with 
	 * the same id 
5
CodeRank
This code example shows how to use the following methods:setEntity, addHeader
        final HttpProcessor httprocessor = Mockito.mock(HttpProcessor.class);
        final HttpClientConnection conn = Mockito.mock(HttpClientConnection.class);
        final HttpRequestExecutor executor = new HttpRequestExecutor();
 
        final HttpCoreContext context = HttpCoreContext.create();
        final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
        final HttpEntity entity = Mockito.mock(HttpEntity.class);
        request.setEntity(entity);
 
        executor.preProcess(request, httprocessor, context);
        Mockito.verify(httprocessor).process(request, context);
 
        Mockito.when(conn.receiveResponseHeader()).thenReturn(
                new BasicHttpResponse(HttpVersion.HTTP_1_1, 101, "OK"));
        Mockito.when(conn.isResponseAvailable(Mockito.anyInt())).thenReturn(Boolean.TRUE);
 
        try { 
            executor.execute(request, conn, context);
            Assert.fail("ProtocolException should have been thrown");
6
CodeRank
This code example shows how to use the following methods:setEntity, abort
	} 
 
	public static InputStream doPost(String url, Map<String, String> m, File file) throws ClientProtocolException,
			IOException { 
		HttpClient httpclient = new DefaultHttpClient(cm, params);
		HttpPost httpost = new HttpPost(url);
		MultipartEntity reqEntity = new MultipartEntity();
		FileBody fileBody = new FileBody(file);
		reqEntity.addPart("fileBody", fileBody);
		getNameValuePair(reqEntity, m);
		httpost.setEntity(reqEntity);
		HttpResponse res = httpclient.execute(httpost);
		InputStream in = null;
		if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
			HttpEntity resEntity = res.getEntity();
			if (resEntity != null) {
				in = resEntity.getContent();
			} 
		} else { 
			httpost.abort();

5
CodeRank
This code example shows how to use the following methods:setEntity
	} 
 
	public HttpResponse multipartRequest(String uri, String filePath,
			ProgressListener listener) throws ClientProtocolException,
			IOException { 
		HttpEntityEnclosingRequest request = new HttpPost(uri);
		FileBody bin = new FileBody(new File(filePath));
		// putSouthBoundHeader(request, "multipart/form-data"); 
		putNorthBoundHeader(request);
		Util.printRequest(request);
 
		// Header[] headers = request.getAllHeaders(); 
		// Log.d(TAG, "request call"); 
		// for(int i = 0; i < headers.length; i++) { 
		// Header h = headers[i]; 
		// Log.d(TAG, "Header - " + h.getName() + ":" + h.getValue()); 
		// } 
 
		CountingMultipartEntity reqEntity = new CountingMultipartEntity(
				listener);

5
CodeRank
This code example shows how to use the following methods:getEntity
        verify(consumer, times(1)).buildResult(context);
    } 
 
    @Test 
    public void testResponseProcessingWithException() throws Exception { 
        when(request.getEntity()).thenReturn(new StringEntity("stuff"));
        final RuntimeException ooopsie = new RuntimeException();
        when(consumer.buildResult(context)).thenThrow(ooopsie);
 
        consumer.requestReceived(request);
        consumer.consumeContent(decoder, ioctrl);
        consumer.requestCompleted(context);
 
        verify(consumer).releaseResources();
        Assert.assertTrue(consumer.isDone());
        Assert.assertSame(ooopsie, consumer.getException());
    } 
 
    @Test 
    public void testClose() throws Exception { 
5
CodeRank

Related Android HttpEntityEnclosingRequest Questions & Answers:

See Code Examples for Android HttpEntityEnclosingRequest Methods: