Package org.apache.http.entity

Examples of org.apache.http.entity.StringEntity


   
    @Test
    public void testPostConsumerUniqueResponseCode() throws Exception {
        HttpPost post = new HttpPost("http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customersUniqueResponseCode");
        post.addHeader("Accept" , "text/xml");
        StringEntity entity = new StringEntity(POST_REQUEST, "ISO-8859-1");
        entity.setContentType("text/xml; charset=ISO-8859-1");
        post.setEntity(entity);
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(post);
View Full Code Here


        auth.signRequest(get, null);
      return get;
    } else if (endpoint.getHttpMethod().equalsIgnoreCase(HttpPost.METHOD_NAME) ) {
      HttpPost post = new HttpPost(url);

      post.setEntity(new StringEntity(endpoint.getPostParamString(), Constants.DEFAULT_CHARSET));
      post.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
      if (auth != null)
        auth.signRequest(post, endpoint.getPostParamString());

      return post;
View Full Code Here

            request.addHeader("rest-dspace-token", token);


            Community community = form(Community.class).bindFromRequest().get();

            StringEntity communityEntity = new StringEntity("{\"name\":\""+ community.name +"\"}");

            request.setEntity(communityEntity);
            Logger.info("ready");
            HttpResponse response = httpClient.execute(request);
View Full Code Here

            //{"email":"admin@dspace.org","password":"s3cret"}
            //StringEntity params =new StringEntity("{\"email\":\"admin@dspace.org\",\"password\":\"s3cret\"} ");
            DynamicForm requestData = Form.form().bindFromRequest();
            String email = requestData.get("email");
            String password = requestData.get("password");
            StringEntity params =new StringEntity("{\"email\":\"" + email + "\",\"password\":\"" + password + "\"}");
            request.addHeader("content-type", "application/json");
            request.setEntity(params);
            HttpResponse response = httpClient.execute(request);

            if(response.getStatusLine().getStatusCode() == 200) {
View Full Code Here

        Logger.info("EditCommunity json: " + Json.toJson(this).toString());
        ObjectNode jsonObjectNode = Json.newObject().put("name", this.name).put("copyrightText", this.copyrightText)
                .put("introductoryText", this.introductoryText)
                .put("shortDescription", this.shortDescription)
                .put("sidebarText", this.sidebarText);
        StringEntity stringEntity = new StringEntity(jsonObjectNode.toString());
        Logger.info("EditCommunity certain attributes: " + jsonObjectNode.toString());

        request.setEntity(stringEntity);
        HttpResponse httpResponse = httpClient.execute(request);
        RestResponse restResponse = new RestResponse();
View Full Code Here

      }

      if (requestMethod.equals("POST")) {
        HttpPost httpPost = new HttpPost(uri);
        httpPost.setHeader("Accept", acceptType);
        httpPost.setEntity(new StringEntity(body));
        return httpPost;
      }

      if (requestMethod.equals("PATCH")) {
        HttpPatch httpPatch = new HttpPatch(uri);
        httpPatch.setHeader("Accept", acceptType);
        httpPatch.setEntity(new StringEntity(body));
        return httpPatch;
      }

      if (requestMethod.equals("DELETE")) {
        HttpDelete httpDelete = new HttpDelete(uri);
        httpDelete.setHeader("Accept", acceptType);
        return httpDelete;
      }

      if (requestMethod.equals("PUT")) {
        HttpPut httpPut = new HttpPut(uri);
        httpPut.setHeader("Accept", acceptType);
        httpPut.setEntity(new StringEntity(body));
        return httpPut;
      }

      if (requestMethod.equals("HEAD")) {
        return new HttpHead(uri);
View Full Code Here

        when(httpClientResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 500, "Server Error"));
        when(httpClientResponse.getAllHeaders()).thenReturn(new org.apache.http.Header[]{
                new BasicHeader("header_name", "header_value"),
                new BasicHeader("Set-Cookie", "cookie_name=cookie_value")
        });
        when(httpClientResponse.getEntity()).thenReturn(new StringEntity("some_other_body"));

        // when
        HttpResponse httpResponse = new ApacheHttpClientToMockServerResponseMapper().mapApacheHttpClientResponseToMockServerResponse(httpClientResponse, false);

        // then
View Full Code Here

                new BasicHeader("header_name", "header_value"),
                new BasicHeader("Content-Encoding", "gzip"),
                new BasicHeader("Content-Length", "1024"),
                new BasicHeader("Transfer-Encoding", "chunked")
        });
        when(httpClientResponse.getEntity()).thenReturn(new StringEntity(""));

        // when
        HttpResponse httpResponse = new ApacheHttpClientToMockServerResponseMapper().mapApacheHttpClientResponseToMockServerResponse(httpClientResponse, false);

        // then
View Full Code Here

                new BasicHeader("Set-Cookie", "=invalid"),
                new BasicHeader("Set-Cookie", "valid_name="),
                new BasicHeader("Set-Cookie", "invalid"),
                new BasicHeader("Set-Cookie", "")
        });
        when(httpClientResponse.getEntity()).thenReturn(new StringEntity(""));

        // when
        HttpResponse httpResponse = new ApacheHttpClientToMockServerResponseMapper().mapApacheHttpClientResponseToMockServerResponse(httpClientResponse, false);

        // then
View Full Code Here

    */
   @Test
   public void testOutboundRewritingSimpleString() throws Exception
   {
      String url = "/encoding.html?param=foo";
      String rewritten = post("/outbound", new StringEntity(url));

      assertThat(rewritten, is("/encoding/foo"));
   }
View Full Code Here

TOP

Related Classes of org.apache.http.entity.StringEntity

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.