Android StringEntity - 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 StringEntity class.

This code example shows how to use the following methods:
    public PersitingActorTestCase<T> given(String httpResponseBody) {
        httpResponse = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("http", 1, 1),
                200, "OK")); 
        StringEntity entity = null;
        try { 
            entity = new StringEntity(httpResponseBody);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } 
        httpResponse.setEntity(entity);
        return this;
    } 
 
    public PersitingActorTestCase<T> whenReceived() { 
        actor.onResponseReceived(httpResponse);
        return this;
    } 
 
    public void inserts(List<Pair<Uri, ContentValues>> values) {
        assertEquals(values.size(), resolver.operations.size());
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
		return null; 
	} 
 
    private void putUrl(String url, String data) throws Exception {
        HttpPut put = new HttpPut(url);
        put.setEntity(new StringEntity(data));
        HttpResponse response = executeRequest(put);
    } 
 
	protected HttpResponse executeRequest(HttpUriRequest request)
			throws ClientProtocolException, IOException { 
		DefaultHttpClient httpClient = new DefaultHttpClient();
		HttpResponse response = null;
		int retries = 3;
 
		while (retries-- > 0) {
			this.signRequest(request);
			response = httpClient.execute(request);
			int statusCode = response.getStatusLine().getStatusCode();
			if (statusCode == 400 || statusCode == 401) {
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
            public void handle( 
                    HttpRequest request,
                    HttpResponse response,
                    HttpContext context) throws HttpException, IOException {
                 String uri = request.getRequestLine().getUri();
                 response.setEntity(new StringEntity(uri));
            } 
        }); 
 
        mServer.start();
        mServerUrl = "http://localhost:" + mServer.getPort() + "/";
    } 
 
    protected void tearDown() throws Exception { 
        if (mServer != null) mServer.shutdown();
    } 
 
    @LargeTest 
    public void testThreadCheck() throws Exception { 
        ContentResolver resolver = getContext().getContentResolver();
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getContentType
	protected <T> T doPost(String url, String postBody, ResponseHandler<T> responseHandler) {
		HttpPost request = new HttpPost(url);
		HttpEntity entity;
 
		try { 
			entity = new StringEntity(postBody);
		} 
		catch (UnsupportedEncodingException e) {
			Log.e("Couldn't encode params", e);
			return null; 
		} 
 
		Header header = entity.getContentType();
		if (header != null) {
			request.addHeader(header);
		} 
 
		request.setEntity(entity);
 
		Log.i("Request URL: " + url);
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setContentType
	} 
 
	private void setEntity(HttpEntityEnclosingRequest request, String body, String contentType) {
		StringEntity entity;
		try { 
			entity = new StringEntity(body, CHARSET);
		} catch (UnsupportedEncodingException e) {
			throw new RedmineInternalError("Required charset " + CHARSET
					+ " is not supported", e);
		} 
		entity.setContentType(contentType);
		request.setEntity(entity);
	} 
 
	@SuppressWarnings("unchecked") 
	private <T> EntityConfig<T> getConfig(Class<?> class1) {
		final EntityConfig<?> guess = OBJECT_CONFIGS.get(class1);
		if (guess == null)
			throw new RedmineInternalError("Unsupported class " + class1);
		return (EntityConfig<T>) guess;
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setContentType
        if (authAttribute == null || (authAttribute instanceof Boolean && ((Boolean) authAttribute).booleanValue())) {
            getResponse(request, response, context);
            return; 
        } 
 
        AbstractHttpEntity entity = new StringEntity("401 Unauthorized");
        entity.setContentType("text/plain");
        response.setEntity(entity);
        response.setStatusCode(401);
    } 
 
    /** 
     * This method is only called if the authentication was successful. 
     * It can be used like the original 
     * {@link #handle(HttpRequest, HttpResponse, HttpContext)} method. 
     */ 
    protected abstract void getResponse(HttpRequest request, HttpResponse response, HttpContext context);
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
		CloseableHttpClient client = HttpClientBuilder.create().build();
		CloseableHttpResponse response = null;
		try { 
			HttpPost post = new HttpPost("http://localhost:9998/controller/router");
 
			StringEntity postEntity = new StringEntity("{\"action\":\"" + action + "\",\"method\":\"" + method
					+ "\",\"data\":[],\"type\":\"rpc\",\"tid\":1}", "UTF-8"); 
			post.setEntity(postEntity);
			post.setHeader("Content-Type", "application/json; charset=UTF-8");
 
			response = client.execute(post);
			HttpEntity entity = response.getEntity();
			assertThat(entity).isNotNull();
			String responseString = EntityUtils.toString(entity);
 
			assertThat(responseString).isNotNull();
			assertThat(responseString).startsWith("[").endsWith("]");
 
			ObjectMapper mapper = new ObjectMapper();
			Map<String, Object> rootAsMap = mapper.readValue(responseString.substring(1, responseString.length() - 1),
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setContentType
     * @throws UnsupportedEncodingException if unsupported 
     */ 
    public static StringEntity setMessageBody(final String content) throws UnsupportedEncodingException
    { 
        if (content == null || content.isEmpty()) throw new UnsupportedOperationException("Content is required.");
        return new StringEntity(content,UTF_8_ENCODING);
    } 
 
    /** 
     * Populate HTTP message call with given content. 
     *  
     * @param json {@link JSONObject} content 
     * @return {@link StringEntity} content. 
     * @throws UnsupportedEncodingException if unsupported 
     */ 
    public static StringEntity setMessageBody(final JSONObject json) throws UnsupportedEncodingException
    { 
        if (json == null || json.toString().isEmpty())
            throw new UnsupportedOperationException("JSON Content is required.");
 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
                     
                    ByteArrayEntity outgoing = new ByteArrayEntity(data);
                    outgoing.setChunked(false);
                    response.setEntity(outgoing);
                } else { 
                    StringEntity outgoing = new StringEntity("No content"); 
                    response.setEntity(outgoing);
                } 
            } 
             
        }); 
         
        this.server.start();
         
        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
        HttpHost host = new HttpHost("localhost", this.server.getPort());
         
        try { 
            for (int r = 0; r < reqNo; r++) {
                if (!conn.isOpen()) {
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
 
	protected static void sendListenerTelemetry(ListenerTelemetry l) {
		String putURL = _habitat_url + _habitat_db + "/" + HabitatInterface.getUUID();
		StringEntity stringdata = null;
		try { 
			stringdata = new StringEntity(l.getJSON());
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} 
		HttpEntity data = (HttpEntity) stringdata;
 
		SimpleHttp.put(putURL, data);
	} 
} 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android StringEntity Questions & Answers:

See Code Examples for Android StringEntity Methods: