本文整理了Java中org.eclipse.jetty.client.api.Request
类的一些代码示例,展示了Request
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request
类的具体详情如下:
包路径:org.eclipse.jetty.client.api.Request
类名称:Request
[英]Request represents a HTTP request, and offers a fluent interface to customize various attributes such as the path, the headers, the content, etc.
You can create Request objects via HttpClient#newRequest(String) and you can send them using either #send() for a blocking semantic, or #send(Response.CompleteListener) for an asynchronous semantic.
[中]Request代表HTTP请求,并提供一个流畅的接口来定制各种属性,如路径、头、内容等。
您可以通过HttpClient#newRequest(String)创建请求对象,并可以使用#send()发送请求对象(用于阻塞语义),或使用#send(Response.CompleteListener)发送请求对象(用于异步语义)。
代码示例来源:origin: spring-projects/spring-framework
protected ResponseEntity<String> executeRequest(URI url, HttpMethod method,
HttpHeaders headers, @Nullable String body) {
Request httpRequest = this.httpClient.newRequest(url).method(method);
addHttpHeaders(httpRequest, headers);
if (body != null) {
httpRequest.content(new StringContentProvider(body));
}
ContentResponse response;
try {
response = httpRequest.send();
}
catch (Exception ex) {
throw new SockJsTransportFailureException("Failed to execute request to " + url, ex);
}
HttpStatus status = HttpStatus.valueOf(response.getStatus());
HttpHeaders responseHeaders = toHttpHeaders(response.getHeaders());
return (response.getContent() != null ?
new ResponseEntity<>(response.getContentAsString(), responseHeaders, status) :
new ResponseEntity<>(responseHeaders, status));
}
代码示例来源:origin: spring-projects/spring-framework
private static void addHttpHeaders(Request request, HttpHeaders headers) {
headers.forEach((key, values) -> {
for (String value : values) {
request.header(key, value);
}
});
}
代码示例来源:origin: xuxueli/xxl-job
httpClient = new HttpClient();
httpClient.setFollowRedirects(false); // Configure HttpClient, for example:
httpClient.start(); // Start HttpClient
Request request = httpClient.newRequest(param);
request.method(HttpMethod.GET);
request.timeout(5000, TimeUnit.MILLISECONDS);
ContentResponse response = request.send();
if (response.getStatus() != HttpStatus.OK_200) {
XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatus());
代码示例来源:origin: spring-projects/spring-framework
private void executeReceiveRequest(URI url, HttpHeaders headers, SockJsResponseListener listener) {
if (logger.isTraceEnabled()) {
logger.trace("Starting XHR receive request, url=" + url);
}
Request httpRequest = this.httpClient.newRequest(url).method(HttpMethod.POST);
addHttpHeaders(httpRequest, headers);
httpRequest.send(listener);
}
代码示例来源:origin: apache/incubator-druid
@Override
public void decorateProxyRequest(
HttpServletRequest clientRequest,
HttpServletResponse proxyResponse,
Request proxyRequest
)
{
Object cookieToken = clientRequest.getAttribute(SIGNED_TOKEN_ATTRIBUTE);
if (cookieToken != null && cookieToken instanceof String) {
log.debug("Found cookie token will attache it to proxyRequest as cookie");
String authResult = (String) cookieToken;
String existingCookies = proxyRequest.getCookies()
.stream()
.map(HttpCookie::toString)
.collect(Collectors.joining(";"));
proxyRequest.header(HttpHeader.COOKIE, Joiner.on(";").join(authResult, existingCookies));
}
}
代码示例来源:origin: apache/incubator-druid
@Override
protected void sendProxyRequest(
HttpServletRequest clientRequest,
HttpServletResponse proxyResponse,
Request proxyRequest
)
{
proxyRequest.timeout(httpClientConfig.getReadTimeout().getMillis(), TimeUnit.MILLISECONDS);
proxyRequest.idleTimeout(httpClientConfig.getReadTimeout().getMillis(), TimeUnit.MILLISECONDS);
clientRequest.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true); // auth is handled on the destination host
super.sendProxyRequest(clientRequest, proxyResponse, proxyRequest);
}
代码示例来源:origin: sixt/ja-micro
private boolean verifyRegistrationInConsul() {
String registryServer = serviceProps.getRegistryServer();
if (StringUtils.isBlank(registryServer)) {
return false;
}
String url = "http://" + registryServer + "/v1/catalog/service/" +
serviceProps.getServiceName();
try {
ContentResponse httpResponse = httpClient.newRequest(url).
method(HttpMethod.GET).header(HttpHeader.CONTENT_TYPE, "application/json").send();
if (httpResponse.getStatus() != 200) {
return false;
}
JsonArray pods = new JsonParser().parse(httpResponse.getContentAsString()).getAsJsonArray();
Iterator<JsonElement> iter = pods.iterator();
while (iter.hasNext()) {
JsonElement pod = iter.next();
String serviceId = pod.getAsJsonObject().get("ServiceID").getAsString();
if (serviceProps.getServiceInstanceId().equals(serviceId)) {
return true;
}
}
} catch (Exception ex) {
logger.warn("Caught exception verifying registration", ex);
}
return false;
}
代码示例来源:origin: org.infinispan/infinispan-server-rest
@Test
public void shouldConflictWhenTryingToReplaceExistingEntryUsingPost() throws Exception {
//given
putStringValueInCache("default", "test", "test");
//when
ContentResponse response = client
.POST(String.format("http://localhost:%d/rest/%s/%s", restServer().getPort(), "default", "test"))
.content(new StringContentProvider("Hey!"))
.header("Content-type", "text/plain;charset=UTF-8")
.send();
//then
ResponseAssertion.assertThat(response).isConflicted();
}
代码示例来源:origin: apache/incubator-druid
.newRequest(rewriteURI(request, server.getScheme(), server.getHost()))
.method(HttpMethod.DELETE)
.timeout(CANCELLATION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
broadcastReq.send(completeListener);
代码示例来源:origin: sixt/ja-micro
public Request newRequest(HttpClient httpClient) {
Request request = httpClient.newRequest(uri);
request.content(contentProvider).method(method);
for (String key : headers.keySet()) {
if (! "User-Agent".equals(key)) {
request.header(key, headers.get(key));
}
}
return request;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri,
Function<? super ClientHttpRequest, Mono<Void>> requestCallback) {
if (!uri.isAbsolute()) {
return Mono.error(new IllegalArgumentException("URI is not absolute: " + uri));
}
if (!this.httpClient.isStarted()) {
try {
this.httpClient.start();
}
catch (Exception ex) {
return Mono.error(ex);
}
}
JettyClientHttpRequest clientHttpRequest = new JettyClientHttpRequest(
this.httpClient.newRequest(uri).method(method.toString()), this.bufferFactory);
return requestCallback.apply(clientHttpRequest).then(Mono.from(
clientHttpRequest.getReactiveRequest().response((response, chunks) -> {
Flux<DataBuffer> content = Flux.from(chunks).map(this::toDataBuffer);
return Mono.just(new JettyClientHttpResponse(response, content));
})));
}
代码示例来源:origin: resteasy/Resteasy
final Request request = client.newRequest(invocation.getUri());
final CompletableFuture<T> future = new RequestFuture<T>(request);
request.method(invocation.getMethod());
invocation.getHeaders().asMap().forEach((h, vs) -> vs.forEach(v -> request.header(h, v)));
configureTimeout(request);
if (request.getAttributes().get(FOLLOW_REDIRECTS) == Boolean.FALSE) {
request.followRedirects(false);
request.content(new BytesContentProvider(os.toByteArray()));
request.send(new Response.Listener.Adapter() {
private ClientResponse cr;
private JettyResponseStream stream = new JettyResponseStream();
代码示例来源:origin: konsoletyper/teavm
Request proxyReq = httpClient.newRequest(sb.toString());
proxyReq.method(req.getMethod());
copyRequestHeaders(req, proxyReq::header);
proxyReq.content(new InputStreamContentProvider(req.getInputStream()));
HeaderSender headerSender = new HeaderSender(resp);
proxyReq.onResponseContent((response, responseContent) -> {
headerSender.send(response);
try {
proxyReq.send(result -> {
headerSender.send(result.getResponse());
async.complete();
代码示例来源:origin: jersey/jersey
private Request translateRequest(final ClientRequest clientRequest) {
final URI uri = clientRequest.getUri();
final Request request = client.newRequest(uri);
request.method(clientRequest.getMethod());
request.followRedirects(clientRequest.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, true));
final Object readTimeout = clientRequest.getConfiguration().getProperties().get(ClientProperties.READ_TIMEOUT);
if (readTimeout != null && readTimeout instanceof Integer && (Integer) readTimeout > 0) {
request.timeout((Integer) readTimeout, TimeUnit.MILLISECONDS);
}
return request;
}
代码示例来源:origin: isucon/isucon5-qualify
private Request createGetRequest(Session session, String path) {
Request req = client.newRequest(config.uri(path))
.method("GET")
.timeout(Config.GET_TIMEOUT, TimeUnit.MILLISECONDS);
session.writeCookie(req);
return req;
}
代码示例来源:origin: jersey/jersey
final ContentProvider entity = getStreamProvider(jerseyRequest);
if (entity != null) {
jettyRequest.content(entity);
if (throwable != null && throwable instanceof CancellationException) {
jettyRequest.abort(throwable);
jettyRequest.send(new Response.Listener.Adapter() {
代码示例来源:origin: apache/incubator-druid
proxyRequest.timeout(httpClientConfig.getReadTimeout().getMillis(), TimeUnit.MILLISECONDS);
proxyRequest.idleTimeout(httpClientConfig.getReadTimeout().getMillis(), TimeUnit.MILLISECONDS);
proxyRequest.content(new BytesContentProvider(avaticaQuery));
try {
byte[] bytes = objectMapper.writeValueAsBytes(query);
proxyRequest.content(new BytesContentProvider(bytes));
proxyRequest.getHeaders().put(HttpHeader.CONTENT_LENGTH, String.valueOf(bytes.length));
代码示例来源:origin: sixt/ja-micro
@Before
public void setup() throws Exception {
HttpClient httpClient = mock(HttpClient.class);
response = mock(ContentResponse.class);
when(response.getStatus()).thenReturn(200);
when(response.getContentAsString()).thenReturn(healthInfo);
HttpFields headers = new HttpFields();
headers.add(CONSUL_INDEX, "42");
when(response.getHeaders()).thenReturn(headers);
Request request = mock(Request.class);
when(httpClient.newRequest(anyString())).thenReturn(request);
when(request.send()).thenReturn(response);
props = new ServiceProperties();
props.addProperty(ServiceProperties.REGISTRY_SERVER_KEY, "localhost:1234");
worker = new RegistrationMonitorWorker(httpClient, props, mock(ServiceDependencyHealthCheck.class));
worker.setServiceName("foobar");
}
代码示例来源:origin: jersey/jersey
@Override
public ClientResponse apply(final ClientRequest jerseyRequest) throws ProcessingException {
final Request jettyRequest = translateRequest(jerseyRequest);
final Map<String, String> clientHeadersSnapshot = writeOutBoundHeaders(jerseyRequest.getHeaders(), jettyRequest);
final ContentProvider entity = getBytesProvider(jerseyRequest);
if (entity != null) {
jettyRequest.content(entity);
}
try {
final ContentResponse jettyResponse = jettyRequest.send();
HeaderUtils.checkHeaderChanges(clientHeadersSnapshot, jerseyRequest.getHeaders(),
JettyConnector.this.getClass().getName());
final javax.ws.rs.core.Response.StatusType status = jettyResponse.getReason() == null
? Statuses.from(jettyResponse.getStatus())
: Statuses.from(jettyResponse.getStatus(), jettyResponse.getReason());
final ClientResponse jerseyResponse = new ClientResponse(status, jerseyRequest);
processResponseHeaders(jettyResponse.getHeaders(), jerseyResponse);
try {
jerseyResponse.setEntityStream(new HttpClientResponseInputStream(jettyResponse));
} catch (final IOException e) {
LOGGER.log(Level.SEVERE, null, e);
}
return jerseyResponse;
} catch (final Exception e) {
throw new ProcessingException(e);
}
}
代码示例来源:origin: com.ovea.tajin.servers/tajin-server-jetty9
@Override
public void apply(Request request)
{
if (request.getURI().toString().startsWith(uri.toString()))
request.header(HttpHeader.AUTHORIZATION.asString(), value);
}
内容来源于网络,如有侵权,请联系作者删除!