org.eclipse.jetty.client.api.Response类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(178)

本文整理了Java中org.eclipse.jetty.client.api.Response类的一些代码示例,展示了Response类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response类的具体详情如下:
包路径:org.eclipse.jetty.client.api.Response
类名称:Response

Response介绍

[英]Response represents a HTTP response and offers methods to retrieve status code, HTTP version and headers.

Response objects are passed as parameters to Response.Listener callbacks, or as future result of Request#send().

Response objects do not contain getters for the response content, because it may be too large to fit into memory. The response content should be retrieved via Response.Listener#onContent(Response,ByteBuffer), or via utility classes such as BufferingResponseListener.
[中]

代码示例

代码示例来源:origin: apache/incubator-druid

"success",
success
&& result.getResponse().getStatus() == Status.OK.getStatusCode()

代码示例来源:origin: spring-projects/spring-framework

@Override
public void onHeaders(Response response) {
  if (logger.isTraceEnabled()) {
    // Convert to HttpHeaders to avoid "\n"
    logger.trace("XHR receive headers: " + toHttpHeaders(response.getHeaders()));
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void onBegin(Response response) {
  if (response.getStatus() != 200) {
    HttpStatus status = HttpStatus.valueOf(response.getStatus());
    response.abort(new HttpServerErrorException(status, "Unexpected XHR receive status"));
  }
}

代码示例来源:origin: jersey/jersey

private static ClientResponse translateResponse(final ClientRequest jerseyRequest,
                        final org.eclipse.jetty.client.api.Response jettyResponse,
                        final NonBlockingInputStream entityStream) {
  final ClientResponse jerseyResponse = new ClientResponse(Statuses.from(jettyResponse.getStatus()), jerseyRequest);
  processResponseHeaders(jettyResponse.getHeaders(), jerseyResponse);
  jerseyResponse.setEntityStream(entityStream);
  return jerseyResponse;
}

代码示例来源:origin: airlift/airlift

@Override
public synchronized void onHeaders(Response response)
{
  long length = response.getHeaders().getLongField(HttpHeader.CONTENT_LENGTH.asString());
  if (length > maxLength) {
    response.abort(new ResponseTooLargeException());
  }
}

代码示例来源:origin: org.apache.cayenne/cayenne-client-jetty

@Override
public InputStream sendMessage(byte[] message) throws IOException {
  try {
    Request request = httpClient.newRequest(url)
        .method(HttpMethod.POST)
        .header(HttpHeader.CONTENT_TYPE, "application/octet-stream")
        .header(HttpHeader.ACCEPT_ENCODING, "gzip")
        .content(new BytesContentProvider(message));
    addSessionCookie(request);
    InputStreamResponseListener listener = new InputStreamResponseListener();
    request.send(listener);
    /**
     * Waits for the given timeout for the response to be available, then returns it.
     * The wait ends as soon as all the HTTP headers have been received, without waiting for the content.
     */
    Response response = listener.get(readTimeout, TimeUnit.SECONDS);
    if (response.getStatus() >= 300) {
      throw new IOException(
          "Did not receive successful HTTP response: status code = " + response.getStatus() +
              ", status message = [" + response.getReason() + "]");
    }
    return listener.getInputStream();
  } catch (Exception e) {
    if (e instanceof InterruptedException) {
      Thread.currentThread().interrupt();
    }
    throw new IOException("Exception while sending message", e);
  }
}

代码示例来源:origin: org.eclipse.jetty/jetty-client

Request request = response.getRequest();
HttpFields headers = response.getHeaders();
long length = headers.getLongField(HttpHeader.CONTENT_LENGTH.asString());
if (HttpMethod.HEAD.is(request.getMethod()))
if (length > maxLength)
  response.abort(new IllegalArgumentException("Buffering capacity " + maxLength + " exceeded"));
  return;

代码示例来源:origin: isucon/isucon5-qualify

public void isStatus(int status) {
 if (response.getStatus() != status) {
  addViolation(String.format("パス '%s' へのレスポンスコード %d が期待されていましたが %d でした", response.getRequest().getPath(), status, response.getStatus()));
 }
}

代码示例来源:origin: org.eclipse.jetty/jetty-proxy

protected void onServerResponseHeaders(HttpServletRequest clientRequest, HttpServletResponse proxyResponse, Response serverResponse)
  for (HttpField field : serverResponse.getHeaders())
        .append(" ").append(serverResponse.getReason()).append(System.lineSeparator());
    for (String headerName : proxyResponse.getHeaderNames())
        serverResponse,
        System.lineSeparator(),
        serverResponse.getHeaders().toString().trim(),
        System.lineSeparator(),
        builder);

代码示例来源:origin: isucon/isucon5-qualify

public void isContentLength(long bytes) {
 String value = response.getHeaders().get("Content-Length");
 if (value == null) {
  addViolation(String.format("リクエストパス %s に対して Content-Length がありませんでした", response.getRequest().getPath()));
 } else if (Long.parseLong(value) == bytes) {
  // ok
 } else {
  addViolation(String.format("パス %s に対するレスポンスのサイズが正しくありません: %s bytes", response.getRequest().getPath(), value));
 }
}

代码示例来源:origin: spring-projects/spring-framework

@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);
    }
  }
}

代码示例来源:origin: org.eclipse.jetty/jetty-client

@Override
public String getReason()
{
  return response.getReason();
}

代码示例来源:origin: konsoletyper/teavm

void send(Response response) {
    if (sent) {
      return;
    }
    sent = true;
    resp.setStatus(response.getStatus());
    for (HttpField field : response.getHeaders()) {
      if (field.getName().toLowerCase().equals("location")) {
        String value = field.getValue();
        if (value.startsWith(proxyUrl)) {
          String relLocation = value.substring(proxyUrl.length());
          resp.addHeader(field.getName(), "http://localhost:" + port + proxyPath + relLocation);
          continue;
        }
      }
      resp.addHeader(field.getName(), field.getValue());
    }
  }
}

代码示例来源:origin: com.proofpoint.platform/http-client

@Override
public synchronized void onHeaders(Response response)
{
  long length = response.getHeaders().getLongField(HttpHeader.CONTENT_LENGTH.asString());
  if (length > maxLength) {
    response.abort(new ResponseTooLargeException());
  }
}

代码示例来源:origin: org.eclipse.jetty.websocket/websocket-client

int responseStatusCode = response.getStatus();
String responseLine = responseStatusCode + " " + response.getReason();

代码示例来源:origin: isucon/isucon5-final

public boolean isStatus(int status) {
  if (response.getStatus() != status) {
    String msg = "パス '%s' へのレスポンスコード %d が期待されていましたが %d でした";
    addViolation(String.format(msg, response.getRequest().getPath(), status, response.getStatus()));
    return wrap(false);
  }
  return wrap(true);
}

代码示例来源:origin: isucon/isucon5-final

public boolean isContentLength(long bytes) {
  String value = response.getHeaders().get("Content-Length");
  if (value == null) {
    addViolation(String.format("リクエストパス %s に対して Content-Length がありませんでした", response.getRequest().getPath()));
    return wrap(false);
  } else if (Long.parseLong(value) == bytes) {
    return wrap(true);
  } else {
    addViolation(String.format("パス %s に対するレスポンスのサイズが正しくありません: %s bytes", response.getRequest().getPath(), value));
    return wrap(false);
  }
}

代码示例来源:origin: org.eclipse.jetty/jetty-client

@Override
public boolean abort(Throwable cause)
{
  return response.abort(cause);
}

代码示例来源:origin: airlift/airlift

@Override
public String getStatusMessage()
{
  return response.getReason();
}

代码示例来源:origin: org.eclipse.jetty/jetty-client

@Override
public boolean accept(Request request, Response response)
{
  return response.getStatus() == HttpStatus.UNAUTHORIZED_401;
}

相关文章