HttpEntityEnclosingRequest setEntity - top ranked examples from Open Source projects

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

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:setEntity
            FileBody fileBody = new FileBody( new File( absolutePath ) );
             
            MultipartEntity entity = new MultipartEntity();
            entity.addPart( "deployWar", fileBody ); //$NON-NLS-1$
             
            HttpPost httpPost = new HttpPost();
            httpPost.setEntity( entity );
             
            Object response = httpJSONAPI( httpPost, getDeployURI(appName) );
             
            if( response instanceof JSONObject )
            { 
                JSONObject json = (JSONObject) response;
 
                if( isSuccess( json ) )
                { 
                    System.out.println( "installApplication: Sucess.\n\n" ); //$NON-NLS-1$
                } 
                else 
                { 
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, 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, 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, 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
	} 
 
	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:setEntity
public class UploadImgTest { 
 
    @Test 
    public void uploadImgTest() throws IOException { 
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost("http://localhost:8080/api/1/img/234324234");
 
        MultipartEntity entity = new MultipartEntity();
 
        entity.addPart("file", new ByteArrayBody("simple test".getBytes(),"test"));
        //entity.addPart("file", new FileBody(new File("d:/1.jpg"))); 
 
        post.setEntity(entity);
 
        HttpResponse response = client.execute(post);
        Assert.assertNotNull(response);
    } 
} 
5
CodeRank
This code example shows how to use the following methods:setEntity
	public static void httpPost(){ 
 
		try { 
 
			HttpClient client = new DefaultHttpClient();
			HttpPost post = new HttpPost("http://10.0.2.2:4567/upload");
 
			MultipartEntity content = new MultipartEntity();
			ContentBody audio = new FileBody(new File(Environment.getExternalStorageDirectory()+"/teste.mp3"));
			content.addPart("audio", audio);
			 
			// Commom String Field 
			//content.addPart("AnyID", new StringBody("Strign")); 
 
			post.setEntity(content);
			ResponseHandler<String> responseHandler = new BasicResponseHandler();
			Log.d("Fail", client.execute(post,responseHandler));
			 
		}catch (IOException e) {
			Log.d("Fail", "\n\n\nfail\n\n\n");

5
CodeRank
setEntity Method Overview
Hands the entity to the request.
See Code Examples for other Android HttpEntityEnclosingRequest Methods: