本文整理汇总了Java中org.apache.http.client.fluent.Response类的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于org.apache.http.client.fluent包,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: put
import org.apache.http.client.fluent.Response; //导入依赖的package包/类
/**
* Send PUT request with authorization header
* @param url - The url of the POST request
* @param auth - String for authorization header
* @param putData - The body of the PUT
*/
public Response put(String url, String auth, JsonJavaObject putData) throws URISyntaxException, IOException, JsonException {
URI normUri = new URI(url).normalize();
Request putRequest = Request.Put(normUri);
//Add auth header
if(StringUtil.isNotEmpty(auth)) {
putRequest.addHeader("Authorization", auth);
}
//Add put data
String putDataString = JsonGenerator.toJson(JsonJavaFactory.instanceEx, putData);
if(putData != null) {
putRequest = putRequest.bodyString(putDataString, ContentType.APPLICATION_JSON);
}
Response response = executor.execute(putRequest);
return response;
}
示例2: 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!"));
}
示例3: 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"));
}
示例4: sendRequestToOrion
import org.apache.http.client.fluent.Response; //导入依赖的package包/类
/**
* Sends a request to Orion
*
* @param ctxElement
* The context element
* @param path
* the path from the context broker that determines which "operation"will be executed
* @param responseClazz
* The class expected for the response
* @return The object representing the JSON answer from Orion
* @throws OrionConnectorException
* if a communication exception happens, either when contacting the context broker at
* the given address, or obtaining the answer from it.
*/
private <E, T> T sendRequestToOrion(E ctxElement, String path, Class<T> responseClazz) {
String jsonEntity = gson.toJson(ctxElement);
log.debug("Send request to Orion: {}", jsonEntity);
Request req = Request.Post(this.orionAddr.toString() + path)
.addHeader("Accept", APPLICATION_JSON.getMimeType())
.bodyString(jsonEntity, APPLICATION_JSON).connectTimeout(5000).socketTimeout(5000);
Response response;
try {
response = req.execute();
} catch (IOException e) {
throw new OrionConnectorException("Could not execute HTTP request", e);
}
HttpResponse httpResponse = checkResponse(response);
T ctxResp = getOrionObjFromResponse(httpResponse, responseClazz);
log.debug("Sent to Orion. Obtained response: {}", httpResponse);
return ctxResp;
}
示例5: getVisualRecog
import org.apache.http.client.fluent.Response; //导入依赖的package包/类
public ArrayList<String[]> getVisualRecog(String imageUrl) throws JsonException, URISyntaxException, IOException {
String apiKey = bluemixUtil.getApiKey();
String getUrl = bluemixUtil.getBaseUrl().replace("https:", "http:") + CLASSIFY_API + "?url=" + imageUrl + "&api_key=" + apiKey + "&version=" + VERSION;
Response response = rest.get(getUrl);
//Convert the response into JSON data
String content = EntityUtils.toString(response.returnResponse().getEntity());
JsonJavaObject jsonData = rest.parse(content);
//Retrieve the list of highest matching classifiers and associated confidences
ArrayList<String[]> tags = getSuggestedTags(jsonData);
if(tags != null && tags.size() > 0) {
return tags;
}
return null;
}
示例6: post
import org.apache.http.client.fluent.Response; //导入依赖的package包/类
/**
* Send POST request with authorization header and additional headers
* @param url - The url of the POST request
* @param auth - String for authorization header
* @param headers - Hashmap of headers to add to the request
* @param postData - The body of the POST
* @return the Response to the POST request
*/
public Response post(String url, String auth, HashMap<String, String> headers, JsonJavaObject postData) throws JsonException, IOException, URISyntaxException {
URI normUri = new URI(url).normalize();
Request postRequest = Request.Post(normUri);
//Add all headers
if(StringUtil.isNotEmpty(auth)) {
postRequest.addHeader("Authorization", auth);
}
if(headers != null && headers.size() > 0){
for (Map.Entry<String, String> entry : headers.entrySet()) {
postRequest.addHeader(entry.getKey(), entry.getValue());
}
}
String postDataString = JsonGenerator.toJson(JsonJavaFactory.instanceEx, postData);
Response response = executor.execute(postRequest.bodyString(postDataString, ContentType.APPLICATION_JSON));
return response;
}
示例7: refundPayment
import org.apache.http.client.fluent.Response; //导入依赖的package包/类
@Override
public PaymentResult refundPayment(AuthHeader authHeader, Long id, Long amount) {
Response response = null;
try {
response = Request.
Post(apiUrl + "/payments/payment/" + id + "/refund")
.addHeader(ACCEPT, MediaType.APPLICATION_JSON)
.addHeader(CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED)
.addHeader(AUTHORIZATION, authHeader.getAuhorization())
.addHeader(USER_AGENT, IMPLEMENTATION_NAME + "=" + VERSION)
.bodyString("amount=" + amount, ContentType.APPLICATION_JSON)
.execute();
} catch (IOException ex) {
throw new WebApplicationException(ex);
}
return unMarshall(response, PaymentResult.class);
}
示例8: createRecurrentPayment
import org.apache.http.client.fluent.Response; //导入依赖的package包/类
@Override
public Payment createRecurrentPayment(AuthHeader authHeader, Long id, NextPayment createPayment) {
Response response = null;
try {
response = Request.
Post(apiUrl + "/payments/payment/" + id + "/create-recurrence")
.addHeader(ACCEPT, MediaType.APPLICATION_JSON)
.addHeader(CONTENT_TYPE, MediaType.APPLICATION_JSON)
.addHeader(AUTHORIZATION, authHeader.getAuhorization())
.addHeader(USER_AGENT, IMPLEMENTATION_NAME + "=" + VERSION)
.bodyString(marshall(createPayment), ContentType.TEXT_XML)
.execute();
} catch (IOException ex) {
throw new WebApplicationException(ex);
}
return unMarshall(response, Payment.class);
}
示例9: voidRecurrence
import org.apache.http.client.fluent.Response; //导入依赖的package包/类
@Override
public PaymentResult voidRecurrence(AuthHeader authHeader, Long id) {
Response response = null;
try {
response = Request.
Post(apiUrl + "/payments/payment/" + id + "/void-recurrence")
.addHeader(ACCEPT, MediaType.APPLICATION_JSON)
.addHeader(CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED)
.addHeader(AUTHORIZATION, authHeader.getAuhorization())
.addHeader(USER_AGENT, IMPLEMENTATION_NAME + "=" + VERSION)
.execute();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
return unMarshall(response, PaymentResult.class);
}
示例10: capturePayment
import org.apache.http.client.fluent.Response; //导入依赖的package包/类
@Override
public PaymentResult capturePayment(AuthHeader authHeader, Long id) {
Response response = null;
try {
response = Request.
Post(apiUrl + "/payments/payment/" + id + "/capture")
.addHeader(ACCEPT, MediaType.APPLICATION_JSON)
.addHeader(CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED)
.addHeader(AUTHORIZATION, authHeader.getAuhorization())
.addHeader(USER_AGENT, IMPLEMENTATION_NAME + "=" + VERSION)
.execute();
} catch (IOException ex) {
throw new WebApplicationException(ex);
}
return unMarshall(response, PaymentResult.class);
}
示例11: voidAuthorization
import org.apache.http.client.fluent.Response; //导入依赖的package包/类
@Override
public PaymentResult voidAuthorization(AuthHeader authHeader, Long id) {
Response response = null;
try {
response = Request.
Post(apiUrl + "/payments/payment/" + id + "/void-authorization")
.addHeader(ACCEPT, MediaType.APPLICATION_JSON)
.addHeader(CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED)
.addHeader(AUTHORIZATION, authHeader.getAuhorization())
.addHeader(USER_AGENT, IMPLEMENTATION_NAME + "=" + VERSION)
.execute();
} catch (IOException ex) {
throw new WebApplicationException(ex);
}
return unMarshall(response, PaymentResult.class);
}
示例12: getPayment
import org.apache.http.client.fluent.Response; //导入依赖的package包/类
@Override
public Payment getPayment(AuthHeader authHeader, Long id) {
Response response = null;
try {
response = Request.Get(apiUrl + "/payments/payment/" + id)
.addHeader(ACCEPT, MediaType.APPLICATION_JSON)
.addHeader(CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED)
.addHeader(AUTHORIZATION, authHeader.getAuhorization())
.addHeader(USER_AGENT, IMPLEMENTATION_NAME + "=" + VERSION)
.execute();
} catch (IOException ex) {
throw new WebApplicationException(ex);
}
return unMarshall(response, Payment.class);
}
示例13: getPaymentInstruments
import org.apache.http.client.fluent.Response; //导入依赖的package包/类
@Override
public PaymentInstrumentRoot getPaymentInstruments(AuthHeader authHeader, Long goId, Currency currency) {
Response response = null;
try {
response = Request.Get(apiUrl + "/eshops/eshop/" + goId + "/payment-instruments/" + currency)
.addHeader(ACCEPT, MediaType.APPLICATION_JSON)
.addHeader(AUTHORIZATION, authHeader.getAuhorization())
.addHeader(USER_AGENT, IMPLEMENTATION_NAME + "=" + VERSION)
.execute();
} catch (IOException ex) {
throw new WebApplicationException(ex);
}
return unMarshall(response, PaymentInstrumentRoot.class);
}
示例14: findEETReceiptsByFilter
import org.apache.http.client.fluent.Response; //导入依赖的package包/类
@Override
public List<EETReceipt> findEETReceiptsByFilter(@BeanParam AuthHeader authHeader, EETReceiptFilter filter) {
Response response = null;
try {
response = Request.Post(apiUrl + "/eet-receipts")
.addHeader(ACCEPT, MediaType.APPLICATION_JSON)
.addHeader(CONTENT_TYPE, MediaType.APPLICATION_JSON)
.addHeader(AUTHORIZATION, authHeader.getAuhorization())
.addHeader(USER_AGENT, IMPLEMENTATION_NAME + "=" + VERSION)
.bodyString(marshall(filter), ContentType.APPLICATION_JSON)
.execute();
} catch (IOException ex) {
throw new WebApplicationException(ex);
}
return unMarshallComplexResponse(response, new TypeReference<List<EETReceipt>>() {});
}
示例15: getEETReceiptByPaymentId
import org.apache.http.client.fluent.Response; //导入依赖的package包/类
@Override
public List<EETReceipt> getEETReceiptByPaymentId(@BeanParam AuthHeader authHeader, Long id) {
Response response = null;
try {
response = Request.Get(apiUrl + "/payments/payment/" + id + "/eet-receipts")
.addHeader(ACCEPT, MediaType.APPLICATION_JSON)
.addHeader(CONTENT_TYPE, MediaType.APPLICATION_JSON)
.addHeader(AUTHORIZATION, authHeader.getAuhorization())
.addHeader(USER_AGENT, IMPLEMENTATION_NAME + "=" + VERSION)
.execute();
} catch (IOException ex) {
throw new WebApplicationException(ex);
}
return unMarshallComplexResponse(response, new TypeReference<List<EETReceipt>>() {});
}