当前位置: 首页>>代码示例>>Java>>正文


Java Response.returnResponse方法代码示例

本文整理汇总了Java中org.apache.http.client.fluent.Response.returnResponse方法的典型用法代码示例。如果您正苦于以下问题:Java Response.returnResponse方法的具体用法?Java Response.returnResponse怎么用?Java Response.returnResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.client.fluent.Response的用法示例。


在下文中一共展示了Response.returnResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCustomStatus

import org.apache.http.client.fluent.Response; //导入方法依赖的package包/类
@Test
 public void testCustomStatus()
 {
  Choir testChoir = new Choir();
  
  Response result = TestUtility.postGetResponse(choirBase + "nameOfChoirBlocking", testChoir.toJson(false));
  
  HttpResponse response = null;
  
  try {
	  response = result.returnResponse();
} catch (IOException e1) {
	e1.printStackTrace();
}

assertTrue(response.getStatusLine().getStatusCode() == 400);

assertTrue(response.getStatusLine().getReasonPhrase().equals("Choir Name is required!"));  
 }
 
开发者ID:SalimCastellanos,项目名称:CarmenRest-VertX,代码行数:20,代码来源:RestResponseTests.java

示例2: testCustomHeaders

import org.apache.http.client.fluent.Response; //导入方法依赖的package包/类
@Test
 public void testCustomHeaders()
 {
  Choir testChoir = new Choir();
  		  
  Response result = TestUtility.postGetResponse(choirBase + "nameOfChoirHeaders", testChoir.toJson(false));
  
  HttpResponse response = null;
  
  try {
	  response = result.returnResponse();
} catch (IOException e1) {
	e1.printStackTrace();
}

// Normally would return plain text because the ResultType annotation is missing on the handling method
assertTrue(response.getHeaders("content-type")[0].getValue().equals("application/json; charset=utf-8"));  
 }
 
开发者ID:SalimCastellanos,项目名称:CarmenRest-VertX,代码行数:19,代码来源:RestResponseTests.java

示例3: getStatement

import org.apache.http.client.fluent.Response; //导入方法依赖的package包/类
@Override
public byte[] getStatement(AuthHeader authHeader, AccountStatement accountStatement) {
    Response response = null;
    
    try {
        response = Request.Post(apiUrl + "/accounts/account-statement")
                .addHeader(ACCEPT, MediaType.APPLICATION_JSON)
                .addHeader(CONTENT_TYPE, MediaType.APPLICATION_JSON)
                .addHeader(AUTHORIZATION, authHeader.getAuhorization())
                .addHeader(USER_AGENT, IMPLEMENTATION_NAME + "=" + VERSION)
                .bodyString(marshall(accountStatement), ContentType.APPLICATION_JSON)
                .execute();
        HttpResponse httpresponse = response.returnResponse();
        return EntityUtils.toByteArray(httpresponse.getEntity());
    } catch (IOException ex) {
        throw new WebApplicationException(ex);
    }
}
 
开发者ID:gopaycommunity,项目名称:gopay-java-api,代码行数:19,代码来源:HttpClientPaymentClientImpl.java

示例4: callSoapService

import org.apache.http.client.fluent.Response; //导入方法依赖的package包/类
public SoapRawClientResponse callSoapService(InputStream xmlFile) throws InternalBusinessException {
	SoapRawClientResponse rawSoapResponse = new SoapRawClientResponse();
	
	LOGGER.debug("Calling SoapService with POST on Apache HTTP-Client and configured URL: {}", soapServiceUrl);
	
	try {
		Response httpResponseContainer = Request
				.Post(soapServiceUrl)
				.bodyStream(xmlFile, contentTypeTextXmlUtf8())
				.addHeader("SOAPAction", "\"" + soapAction + "\"")
				.execute();
		
		HttpResponse httpResponse = httpResponseContainer.returnResponse();			
		rawSoapResponse.setHttpStatusCode(httpResponse.getStatusLine().getStatusCode());
		rawSoapResponse.setHttpResponseBody(XmlUtils.parseFileStream2Document(httpResponse.getEntity().getContent()));
		
	} catch (Exception exception) {
		throw new InternalBusinessException("Some Error accured while trying to Call SoapService for test: " + exception.getMessage());
	}		
	return rawSoapResponse;
}
 
开发者ID:jonashackt,项目名称:tutorial-soap-spring-boot-cxf,代码行数:22,代码来源:SoapRawClient.java

示例5: execute

import org.apache.http.client.fluent.Response; //导入方法依赖的package包/类
@Override
public void execute() {
    try {
        Response response = retryGet(new ResponseGetter(remotePageUrl), NO_OF_RETRIES, RETRY_WAIT_TIME);
        HttpResponse httpResponse = response.returnResponse();
        assertEquals("http error code does not match", httpErrorCode, httpResponse.getStatusLine().getStatusCode());
        if (contentFragment != null) {
            HttpEntity entity = httpResponse.getEntity();
            if (entity == null) {
                throw new IllegalStateException("Response contains no content");
            }
            try (InputStream is = entity.getContent()) {
                byte[] bytes = IOUtils.toByteArray(is);
                String pageContent = new String(bytes, Charset.defaultCharset());
                assertNotNull("page content is empty", pageContent);
                log.debug("\n" + head(pageContent, NO_OF_LINES_TO_LOG));
                assertTrue(String.format("page content '%s' does not contain '%s'", pageContent, contentFragment), pageContent.contains(contentFragment));
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:tdomzal,项目名称:junit-docker-rule,代码行数:24,代码来源:AssertHtml.java

示例6: call_availableAndUnavailable_api

import org.apache.http.client.fluent.Response; //导入方法依赖的package包/类
@Test
public void call_availableAndUnavailable_api() throws Exception {
    // Set the endpoint as down
    api.getProxy().getEndpoints().iterator().next().setStatus(Endpoint.Status.DOWN);

    Request request = Request.Get("http://localhost:8082/test/my_team");
    Response response = request.execute();
    HttpResponse returnResponse = response.returnResponse();

    assertEquals(HttpStatus.SC_SERVICE_UNAVAILABLE, returnResponse.getStatusLine().getStatusCode());

    // Set the endpoint as up
    api.getProxy().getEndpoints().iterator().next().setStatus(Endpoint.Status.UP);

    Request request2 = Request.Get("http://localhost:8082/test/my_team");
    Response response2 = request2.execute();
    HttpResponse returnResponse2 = response2.returnResponse();

    assertEquals(HttpStatus.SC_OK, returnResponse2.getStatusLine().getStatusCode());
}
 
开发者ID:gravitee-io,项目名称:gravitee-gateway,代码行数:21,代码来源:ServiceUnavailableTest.java

示例7: main

import org.apache.http.client.fluent.Response; //导入方法依赖的package包/类
public static void main(String[] args) throws UnsupportedCharsetException, ClientProtocolException, JSONException,
        IOException {
    Response response = Request
            .Post(FOX_SERVICE)
            .addHeader("Content-type", "application/json")
            .addHeader("Accept-Charset", "UTF-8")
            .body(new StringEntity(
                    new JSONObject()
                            .put("input",
                                    "Brian Banner is a fictional villain from the Marvel Comics Universe created by Bill Mantlo and Mike Mignola and first appearing in print in late 1985.")
                            .put("type", "text").put("task", "ner").put("output", "JSON-LD").toString(),
                    ContentType.APPLICATION_JSON)).execute();

    HttpResponse httpResponse = response.returnResponse();
    HttpEntity entry = httpResponse.getEntity();

    String content = IOUtils.toString(entry.getContent(), "UTF-8");
    System.out.println(content);
}
 
开发者ID:dice-group,项目名称:Cetus,代码行数:20,代码来源:FoxBasedTypeSearcher.java

示例8: call_get_query_with_multiple_parameter_values_ordered

import org.apache.http.client.fluent.Response; //导入方法依赖的package包/类
@Test
@Ignore
public void call_get_query_with_multiple_parameter_values_ordered() throws Exception {
    String query = "country=fr&type=MAG&country=es";

    URI target = new URIBuilder("http://localhost:8082/test/my_team")
            .addParameter("country", "fr")
            .addParameter("type", "MAG")
            .addParameter("country", "es")
            .build();

    Response response = Request.Get(target).execute();

    HttpResponse returnResponse = response.returnResponse();
    assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode());

    String responseContent = StringUtils.copy(returnResponse.getEntity().getContent());
    assertEquals(query, responseContent);
}
 
开发者ID:gravitee-io,项目名称:gravitee-gateway,代码行数:20,代码来源:QueryParametersTest.java

示例9: call_case2_chunked

import org.apache.http.client.fluent.Response; //导入方法依赖的package包/类
@Test
public void call_case2_chunked() throws Exception {
    String testCase = "case2";

    InputStream is = this.getClass().getClassLoader().getResourceAsStream(testCase + "/request_content.json");
    Request request = Request.Post("http://localhost:8082/test/my_team?case=" +  testCase)
            .bodyStream(is, ContentType.APPLICATION_JSON);

    try {
        Response response = request.execute();

        HttpResponse returnResponse = response.returnResponse();
        assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode());
        assertEquals(HttpHeadersValues.TRANSFER_ENCODING_CHUNKED, returnResponse.getFirstHeader(HttpHeaders.TRANSFER_ENCODING).getValue());

        String responseContent = StringUtils.copy(returnResponse.getEntity().getContent());
        assertEquals(652051, responseContent.length());
    } catch (Exception e) {
        e.printStackTrace();
        assertTrue(false);
    }
}
 
开发者ID:gravitee-io,项目名称:gravitee-gateway,代码行数:23,代码来源:PostContentGatewayTest.java

示例10: call_case3_raw

import org.apache.http.client.fluent.Response; //导入方法依赖的package包/类
@Test
public void call_case3_raw() throws Exception {
    String testCase = "case3";

    InputStream is = this.getClass().getClassLoader().getResourceAsStream(testCase + "/request_content.json");
    Request request = Request.Post("http://localhost:8082/test/my_team?mode=chunk&case=" +  testCase)
            .bodyStream(is, ContentType.APPLICATION_JSON);

    try {
        Response response = request.execute();

        HttpResponse returnResponse = response.returnResponse();
        assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode());

        // Set chunk mode in request but returns raw because of the size of the content
        assertEquals(null, returnResponse.getFirstHeader(HttpHeaders.TRANSFER_ENCODING));

        String responseContent = StringUtils.copy(returnResponse.getEntity().getContent());
        assertEquals(70, responseContent.length());
    } catch (Exception e) {
        e.printStackTrace();
        assertTrue(false);
    }
}
 
开发者ID:gravitee-io,项目名称:gravitee-gateway,代码行数:25,代码来源:PostContentGatewayTest.java

示例11: delete

import org.apache.http.client.fluent.Response; //导入方法依赖的package包/类
protected boolean delete(String deleteJobUrl) throws IOException {
    boolean rc = false;
    String sReturn = "";

    Request request = Request
            .Delete(deleteJobUrl)
            .addHeader(AUTH.WWW_AUTH_RESP, getAuthorization())
            .useExpectContinue();

    Response response = executor.execute(request);
    HttpResponse hResponse = response.returnResponse();
    int rcResponse = hResponse.getStatusLine().getStatusCode();

    if (HttpStatus.SC_OK == rcResponse) {
        sReturn = EntityUtils.toString(hResponse.getEntity());
        rc = true;
    } else {
        rc = false;
    }
    traceLog.finest("Request: [" + deleteJobUrl + "]");
    traceLog.finest(rcResponse + ": " + sReturn);
    return rc;
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:24,代码来源:AbstractStreamingAnalyticsConnection.java

示例12: createBucket

import org.apache.http.client.fluent.Response; //导入方法依赖的package包/类
private void createBucket() throws IOException {
    // create db
    Response resp = adminExecutor.execute(Request.Put(dbTmpUri)
            .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));

    HttpResponse httpResp = resp.returnResponse();
    assertNotNull(httpResp);
    StatusLine statusLine = httpResp.getStatusLine();

    assertNotNull(statusLine);
    assertEquals("check status code", HttpStatus.SC_CREATED, statusLine.getStatusCode());

    // create bucket
    String bucketUrl = dbTmpUri + "/" + BUCKET + ".files/";
    resp = adminExecutor.execute(Request.Put(bucketUrl)
            .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));

    httpResp = resp.returnResponse();
    assertNotNull(httpResp);
    statusLine = httpResp.getStatusLine();

    assertNotNull(statusLine);
    assertEquals("check status code", HttpStatus.SC_CREATED, statusLine.getStatusCode());
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:25,代码来源:GetFileHandlerIT.java

示例13: createFilePut

import org.apache.http.client.fluent.Response; //导入方法依赖的package包/类
private void createFilePut(String id) throws UnknownHostException, IOException {
    String bucketUrl = dbTmpUri + "/" + BUCKET + ".files/" + id;

    InputStream is = GetFileHandlerIT.class.getResourceAsStream("/" + FILENAME);

    HttpEntity entity = MultipartEntityBuilder
            .create()
            .addBinaryBody("file", is, ContentType.create("application/octet-stream"), FILENAME)
            .addTextBody("metadata", "{\"type\": \"documentation\"}")
            .build();

    Response resp = adminExecutor.execute(Request.Put(bucketUrl)
            .body(entity));

    HttpResponse httpResp = resp.returnResponse();
    assertNotNull(httpResp);

    StatusLine statusLine = httpResp.getStatusLine();

    assertNotNull(statusLine);
    assertEquals("check status code", HttpStatus.SC_CREATED, statusLine.getStatusCode());
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:23,代码来源:GetFileHandlerIT.java

示例14: testGetMetricsForUnknownCollection

import org.apache.http.client.fluent.Response; //导入方法依赖的package包/类
@Test
public void testGetMetricsForUnknownCollection() throws Exception {
    Response resp = adminExecutor.execute(Request.Get(metricsUnknownCollectionUri));

    HttpResponse httpResp = resp.returnResponse();
    assertNotNull(httpResp);
    HttpEntity entity = httpResp.getEntity();
    assertNotNull(entity);
    StatusLine statusLine = httpResp.getStatusLine();
    assertNotNull(statusLine);

    //configuration says: it is not activated for collections, so it should return 404, default restheart answer
    assertEquals("check status code", HttpStatus.SC_NOT_FOUND, statusLine.getStatusCode());
    assertNotNull("content type not null", entity.getContentType());
    assertEquals("check content type", "application/hal+json", entity.getContentType().getValue());
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:17,代码来源:GetMetricsIT.java

示例15: checkResponse

import org.apache.http.client.fluent.Response; //导入方法依赖的package包/类
private <T> HttpResponse checkResponse(Response response) {
  HttpResponse httpResponse;
  try {
    httpResponse = response.returnResponse();
  } catch (IOException e) {
    throw new OrionConnectorException("Could not obtain HTTP response", e);
  }

  if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
    throw new OrionConnectorException(
        "Failed with HTTP error code : " + httpResponse.getStatusLine().getStatusCode());
  }
  return httpResponse;
}
 
开发者ID:usmanullah,项目名称:kurento-testing,代码行数:15,代码来源:OrionConnector.java


注:本文中的org.apache.http.client.fluent.Response.returnResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。