本文整理汇总了Java中org.eclipse.jetty.client.api.Response类的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于org.eclipse.jetty.client.api包,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onProxyResponseFailure
import org.eclipse.jetty.client.api.Response; //导入依赖的package包/类
@Override
protected void onProxyResponseFailure(final HttpServletRequest clientRequest, final HttpServletResponse proxyResponse,
final Response serverResponse, final Throwable failure) {
_log.warn(failure.toString());
if (proxyResponse.isCommitted()) {
// Parent behavior
super.onProxyResponseFailure(clientRequest, proxyResponse, serverResponse, failure);
} else {
proxyResponse.resetBuffer();
if (failure instanceof TimeoutException) {
proxyResponse.setStatus(HttpServletResponse.SC_GATEWAY_TIMEOUT);
} else {
// Unavailable business server as JSON response
proxyResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
proxyResponse.setContentType("application/json");
try {
proxyResponse.getOutputStream().write("{\"code\":\"business-down\"}".getBytes(StandardCharsets.UTF_8));
} catch (final IOException ioe) {
_log.warn("Broken proxy stream", ioe);
}
}
proxyResponse.setHeader(HttpHeader.CONNECTION.asString(), HttpHeaderValue.CLOSE.asString());
final AsyncContext asyncContext = clientRequest.getAsyncContext();
asyncContext.complete();
}
}
示例2: onResponseContent
import org.eclipse.jetty.client.api.Response; //导入依赖的package包/类
@Override
protected void onResponseContent(final HttpServletRequest request, final HttpServletResponse response, final Response proxyResponse,
final byte[] buffer, final int offset, final int length, final Callback callback) {
final int plainStatus = needPlainPageErrorStatus(request, proxyResponse.getStatus());
if (plainStatus == 0) {
super.onResponseContent(request, response, proxyResponse, buffer, offset, length, callback);
} else {
try {
// Standard 404/... page, abort the original response
final RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/" + plainStatus + ".html");
dispatcher.forward(getRoot(request), response);
callback.succeeded();
} catch (final Exception e) {
callback.failed(e);
}
}
}
示例3: getTransactions
import org.eclipse.jetty.client.api.Response; //导入依赖的package包/类
public Map<String, Transaction> getTransactions(String accountId, int offset, int transactionsPerRequest, boolean ignoreException)
{
Map<String, Transaction> transactionLookup = null;
try
{
InputStreamResponseListener listener = new InputStreamResponseListener();
Request request = httpClient.POST(BURST_API_URL)
.param("requestType", "getAccountTransactions")
.param("firstIndex", String.valueOf(offset))
.param("lastIndex", String.valueOf(offset + transactionsPerRequest))
.param("account", accountId);
request.send(listener);
Response response = listener.get(BurstcoinFaucetProperties.getConnectionTimeout(), TimeUnit.MILLISECONDS);
transactionLookup = handleGetTransactionsResponse(listener, response, ignoreException);
}
catch(Exception e)
{
LOG.warn("Error: Failed to 'getAccountTransactions' for accountId '" + accountId + "' : " + e.getMessage());
}
return transactionLookup;
}
示例4: onContent
import org.eclipse.jetty.client.api.Response; //导入依赖的package包/类
@Override
public void onContent(Response response, ByteBuffer buffer) {
while (true) {
if (this.sockJsSession.isDisconnected()) {
if (logger.isDebugEnabled()) {
logger.debug("SockJS sockJsSession closed, closing response.");
}
response.abort(new SockJsException("Session closed.", this.sockJsSession.getId(), null));
return;
}
if (buffer.remaining() == 0) {
break;
}
int b = buffer.get();
if (b == '\n') {
handleFrame();
}
else {
this.outputStream.write(b);
}
}
}
示例5: onProxyResponseFailure
import org.eclipse.jetty.client.api.Response; //导入依赖的package包/类
protected void onProxyResponseFailure(HttpServletRequest clientRequest, HttpServletResponse proxyResponse, Response serverResponse, Throwable failure) {
// if (_log.isDebugEnabled())
_log.info(getRequestId(clientRequest) + " proxying failed", failure);
if (proxyResponse.isCommitted()) {
try {
// Use Jetty specific behavior to close connection.
proxyResponse.sendError(-1);
// AsyncContext asyncContext = clientRequest.getAsyncContext();
// asyncContext.complete();
}
catch (IOException x) {
if (_log.isDebugEnabled())
_log.debug(getRequestId(clientRequest) + " could not close the connection", failure);
}
}
else {
proxyResponse.resetBuffer();
int status = failure instanceof TimeoutException ? HttpStatus.GATEWAY_TIMEOUT_504 : HttpStatus.BAD_GATEWAY_502;
sendProxyResponseError(clientRequest, proxyResponse, status);
}
}
示例6: createRestException
import org.eclipse.jetty.client.api.Response; //导入依赖的package包/类
@Override
protected SalesforceException createRestException(Response response, InputStream responseContent) {
// this must be of type Error
try {
final Error error = unmarshalResponse(responseContent, response.getRequest(), Error.class);
final RestError restError = new RestError();
restError.setErrorCode(error.getExceptionCode());
restError.setMessage(error.getExceptionMessage());
return new SalesforceException(Arrays.asList(restError), response.getStatus());
} catch (SalesforceException e) {
String msg = "Error un-marshaling Salesforce Error: " + e.getMessage();
return new SalesforceException(msg, e);
}
}
示例7: accept
import org.eclipse.jetty.client.api.Response; //导入依赖的package包/类
@Override
public boolean accept(Request request, Response response) {
HttpConversation conversation = ((SalesforceHttpRequest) request).getConversation();
Integer retries = (Integer) conversation.getAttribute(AUTHENTICATION_RETRIES_ATTRIBUTE);
// is this an authentication response for a previously handled conversation?
if (conversation.getAttribute(AUTHENTICATION_REQUEST_ATTRIBUTE) != null
&& (retries == null || retries <= maxAuthenticationRetries)) {
return true;
}
final int status = response.getStatus();
// handle UNAUTHORIZED and BAD_REQUEST for Bulk API,
// the actual InvalidSessionId Bulk API error is checked and handled in the listener
// also check retries haven't exceeded maxAuthenticationRetries
return (status == HttpStatus.UNAUTHORIZED_401 || status == HttpStatus.BAD_REQUEST_400)
&& (retries == null || retries <= maxAuthenticationRetries);
}
示例8: onResponseContent
import org.eclipse.jetty.client.api.Response; //导入依赖的package包/类
@Override
protected void onResponseContent(HttpServletRequest request, HttpServletResponse response, Response proxyResponse,
byte[] buffer, int offset, int length, Callback callback) {
// フィルタークラスで必要かどうかを判別後、必要であれば内容をキャプチャする
// 注意: 1回のリクエストで複数回の応答が帰ってくるので全ての応答をキャプチャする必要がある
if (Filter.isNeed(request.getServerName(), response.getContentType())) {
ByteArrayOutputStream stream = (ByteArrayOutputStream) request.getAttribute(Filter.RESPONSE_BODY);
if (stream == null) {
stream = new ByteArrayOutputStream();
request.setAttribute(Filter.RESPONSE_BODY, stream);
}
// ストリームに書き込む
stream.write(buffer, offset, length);
}
super.onResponseContent(request, response, proxyResponse, buffer, offset, length, callback);
}
示例9: testGetAccessTokenRequester
import org.eclipse.jetty.client.api.Response; //导入依赖的package包/类
@Test
public void testGetAccessTokenRequester()
{
ArgumentCaptor<Jetty92SingleRequester> jetty92SingleRequesterArgumentCaptor = ArgumentCaptor.forClass(Jetty92SingleRequester.class);
Mockito.when(mockJetty92.requestWithRetry(Mockito.any(StringJetty92ResponseEntityReader.class), jetty92SingleRequesterArgumentCaptor.capture())).thenReturn("{\"access_token\": \"access_token\"}");
String accessToken = marketoBaseRestClient.getAccessToken();
Assert.assertEquals("access_token", accessToken);
Jetty92SingleRequester value = jetty92SingleRequesterArgumentCaptor.getValue();
HttpClient client = Mockito.mock(HttpClient.class);
Response.Listener listener = Mockito.mock(Response.Listener.class);
Request mockRequest = Mockito.mock(Request.class);
Mockito.when(client.newRequest(Mockito.eq(IDENTITY_END_POINT + MarketoRESTEndpoint.ACCESS_TOKEN.getEndpoint()))).thenReturn(mockRequest);
Request request1 = Mockito.mock(Request.class);
Mockito.when(mockRequest.method(Mockito.eq(HttpMethod.GET))).thenReturn(request1);
value.requestOnce(client, listener);
Mockito.verify(request1, Mockito.times(1)).param(Mockito.eq("client_id"), Mockito.eq("clientId"));
Mockito.verify(request1, Mockito.times(1)).param(Mockito.eq("client_secret"), Mockito.eq("clientSecret"));
Mockito.verify(request1, Mockito.times(1)).param(Mockito.eq("grant_type"), Mockito.eq("client_credentials"));
Assert.assertTrue(value.toRetry(createHttpResponseException(502)));
}
示例10: testSetStatus
import org.eclipse.jetty.client.api.Response; //导入依赖的package包/类
@Test
public void testSetStatus() throws Throwable {
requestAction(new Action<ServerHttpExchange>() {
@Override
public void on(ServerHttpExchange http) {
http.setStatus(HttpStatus.NOT_FOUND).end();
}
});
client.newRequest(uri()).send(new Response.Listener.Adapter() {
@Override
public void onSuccess(Response response) {
threadAssertEquals(response.getStatus(), 404);
resume();
}
});
await();
}
示例11: testSetHeader
import org.eclipse.jetty.client.api.Response; //导入依赖的package包/类
@Test
public void testSetHeader() throws Throwable {
requestAction(new Action<ServerHttpExchange>() {
@Override
public void on(ServerHttpExchange http) {
http.setHeader("A", "A").setHeader("B", Arrays.asList("B1", "B2")).end();
}
});
client.newRequest(uri()).send(new Response.Listener.Adapter() {
@Override
public void onSuccess(Response res) {
HttpFields headers = res.getHeaders();
threadAssertTrue(headers.getFieldNamesCollection().containsAll(Arrays.asList("A", "B")));
threadAssertEquals(headers.get("A"), "A");
threadAssertEquals(headers.get("B"), "B1, B2");
resume();
}
});
await();
}
示例12: testEnd
import org.eclipse.jetty.client.api.Response; //导入依赖的package包/类
@Test
public void testEnd() throws Throwable {
requestAction(new Action<ServerHttpExchange>() {
@Override
public void on(ServerHttpExchange http) {
http.end();
}
});
client.newRequest(uri()).send(new Response.Listener.Adapter() {
@Override
public void onSuccess(Response response) {
resume();
}
});
await();
}
示例13: onResponseComplete
import org.eclipse.jetty.client.api.Response; //导入依赖的package包/类
public void onResponseComplete(Throwable exn, Response response) {
totalContext.stop();
inflight.dec();
if (exn != null) {
requestException.mark();
} else {
switch (javax.ws.rs.core.Response.Status.Family.familyOf(response.getStatus())) {
case SUCCESSFUL:
request2xx.mark();
break;
case SERVER_ERROR:
request5xx.mark();
break;
case CLIENT_ERROR:
request4xx.mark();
break;
default:
requestOtherStatus.mark();
}
}
}
示例14: error
import org.eclipse.jetty.client.api.Response; //导入依赖的package包/类
private RuntimeException error(Request req, boolean uriIsSecret, Response res)
{
if (HttpStatus.isClientError(res.getStatus())) {
switch (res.getStatus()) {
case HttpStatus.REQUEST_TIMEOUT_408:
case HttpStatus.TOO_MANY_REQUESTS_429:
// Retry these.
return new RuntimeException("Failed HTTP request: " + requestStatus(req, res, uriIsSecret));
default:
// 4xx: The request is invalid for this resource. Fail hard without retrying.
return new TaskExecutionException("HTTP 4XX Client Error: " + requestStatus(req, res, uriIsSecret));
}
}
else if (res.getStatus() >= 500 && res.getStatus() < 600) {
// 5xx: Server Error. This is hopefully ephemeral.
return ephemeralError("HTTP 5XX Server Error: " + requestStatus(req, res, uriIsSecret));
}
else {
// Unknown status code. Treat as an ephemeral error.
return ephemeralError("Unexpected HTTP status: " + requestStatus(req, res, uriIsSecret));
}
}
示例15: fromUrl
import org.eclipse.jetty.client.api.Response; //导入依赖的package包/类
public static BloomFilter fromUrl(String url) throws Exception
{
log.info("Loading bloom filter from " + url);
Request request = BloomFilterScalarFunctions.HTTP_CLIENT.newRequest(url);
request.method("GET");
InputStreamResponseListener listener = new InputStreamResponseListener();
request.send(listener);
// Wait for the response headers to arrive
Response response = listener.get(10, TimeUnit.SECONDS);
// Look at the response
if (response.getStatus() == 200) {
// Use try-with-resources to close input stream.
try (InputStream responseContent = listener.getInputStream()) {
byte[] bytes = ByteStreams.toByteArray(responseContent);
return newInstance(bytes);
}
}
log.warn("Non-200 response status " + response.getStatus());
return null;
}