本文整理了Java中org.apache.http.HttpRequest.getRequestLine()
方法的一些代码示例,展示了HttpRequest.getRequestLine()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.getRequestLine()
方法的具体详情如下:
包路径:org.apache.http.HttpRequest
类名称:HttpRequest
方法名:getRequestLine
[英]Returns the request line of this request.
[中]返回此请求的请求行。
代码示例来源:origin: robolectric/robolectric
@Override
public boolean matches(HttpRequest request) {
return request.getRequestLine().getMethod().equals(method) &&
request.getRequestLine().getUri().equals(uri);
}
}
代码示例来源:origin: robolectric/robolectric
@Override
public boolean matches(HttpRequest request) {
return request.getRequestLine().getUri().equals(uri);
}
}
代码示例来源:origin: openzipkin/brave
@Override public String method(HttpRequest request) {
return request.getRequestLine().getMethod();
}
代码示例来源:origin: robolectric/robolectric
@Override
public boolean matches(HttpRequest request) {
return request.getRequestLine().getMethod().equals(method) &&
uriRegex.matcher(request.getRequestLine().getUri()).matches();
}
}
代码示例来源:origin: openzipkin/brave
@Override public String path(HttpRequest request) {
String result = request.getRequestLine().getUri();
int queryIndex = result.indexOf('?');
return queryIndex == -1 ? result : result.substring(0, queryIndex);
}
代码示例来源:origin: robovm/robovm
/**
* Decide whether a response comes with an entity.
* The implementation in this class is based on RFC 2616.
* Unknown methods and response codes are supposed to
* indicate responses with an entity.
* <br/>
* Derived executors can override this method to handle
* methods and response codes not specified in RFC 2616.
*
* @param request the request, to obtain the executed method
* @param response the response, to obtain the status code
*/
protected boolean canResponseHaveBody(final HttpRequest request,
final HttpResponse response) {
if ("HEAD".equalsIgnoreCase(request.getRequestLine().getMethod())) {
return false;
}
int status = response.getStatusLine().getStatusCode();
return status >= HttpStatus.SC_OK
&& status != HttpStatus.SC_NO_CONTENT
&& status != HttpStatus.SC_NOT_MODIFIED
&& status != HttpStatus.SC_RESET_CONTENT;
}
代码示例来源:origin: square/okhttp
private static Request transformRequest(HttpRequest request) {
Request.Builder builder = new Request.Builder();
RequestLine requestLine = request.getRequestLine();
String method = requestLine.getMethod();
builder.url(requestLine.getUri());
代码示例来源:origin: robolectric/robolectric
private static Map<String, String> parseParamsForGet(HttpRequest request) {
Uri uri = Uri.parse(request.getRequestLine().getUri());
Set<String> paramNames = uri.getQueryParameterNames();
LinkedHashMap<String, String> map = new LinkedHashMap<>();
for (String paramName : paramNames) {
map.put(paramName, uri.getQueryParameter(paramName));
}
return map;
}
}
代码示例来源:origin: code4craft/webmagic
@Override
public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
URI uri = getLocationURI(request, response, context);
String method = request.getRequestLine().getMethod();
if ("post".equalsIgnoreCase(method)) {
try {
HttpRequestWrapper httpRequestWrapper = (HttpRequestWrapper) request;
httpRequestWrapper.setURI(uri);
httpRequestWrapper.removeHeaders("Content-Length");
return httpRequestWrapper;
} catch (Exception e) {
logger.error("强转为HttpRequestWrapper出错");
}
return new HttpPost(uri);
} else {
return new HttpGet(uri);
}
}
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public void process(HttpResponse response, HttpContext context) throws HttpException, IOException {
// Avoid work if TRACE is not enabled for this class
if (logger.isTraceEnabled()) {
final StatusLine statusLine = response.getStatusLine();
final HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
final HttpRequest httpRequest = (HttpRequest) context
.getAttribute(HttpCoreContext.HTTP_REQUEST);
final RequestLine request = httpRequest.getRequestLine();
logger.trace("[{} {}]: {} {}{}",
statusLine.getStatusCode(),
statusLine.getReasonPhrase(),
request.getMethod(),
targetHost.toURI(),
request.getUri()
);
}
}
}
代码示例来源:origin: fabric8io/docker-maven-plugin
private static URI getUri(HttpRequest request) {
String hostName = request.getFirstHeader("host").getValue();
String requestTarget = request.getRequestLine().getUri();
URI requestUri = createUri(hostName, requestTarget);
return requestUri.normalize();
}
代码示例来源:origin: fabric8io/docker-maven-plugin
AwsSigner4Request(String region, String service, HttpRequest request, Date signingTime) {
this.region = region;
this.service = service;
this.request = request;
signingDateTime = getSigningDateTime(request, signingTime);
signingDate = signingDateTime.substring(0, 8);
scope = signingDate + '/' + region + '/' + service + "/aws4_request";
method = request.getRequestLine().getMethod();
uri = getUri(request);
Map<String, String> headers = getOrderedHeadersToSign(request.getAllHeaders());
signedHeaders = StringUtils.join(headers.keySet(), ';');
canonicalHeaders = canonicalHeaders(headers);
}
代码示例来源:origin: robolectric/robolectric
@Override
public boolean matches(HttpRequest request) {
URI uri = URI.create(request.getRequestLine().getUri());
if (method != null && !method.equals(request.getRequestLine().getMethod())) {
return false;
代码示例来源:origin: robolectric/robolectric
@Override
public boolean matches(HttpRequest request) {
return request.getRequestLine().getUri().equals("http://matching.uri");
}
}, new TestHttpResponse(200, "a cheery response body"));
代码示例来源:origin: zhegexiaohuozi/SeimiCrawler
@Override
public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
URI uri = getLocationURI(request, response, context);
String method = request.getRequestLine().getMethod();
if (HttpPost.METHOD_NAME.equalsIgnoreCase(method)&& request instanceof HttpRequestWrapper) {
HttpRequestWrapper httpRequestWrapper = (HttpRequestWrapper) request;
httpRequestWrapper.setURI(uri);
httpRequestWrapper.removeHeaders("Content-Length");
return httpRequestWrapper;
} else {
return getRedirect(request,response,context);
}
}
}
代码示例来源:origin: spring-projects/spring-data-elasticsearch
@Override
public void process(HttpRequest request, HttpContext context) throws IOException {
String logId = (String) context.getAttribute(RestClients.LOG_ID_ATTRIBUTE);
if (logId == null) {
logId = ClientLogger.newLogId();
context.setAttribute(RestClients.LOG_ID_ATTRIBUTE, logId);
}
if (request instanceof HttpEntityEnclosingRequest && ((HttpEntityEnclosingRequest) request).getEntity() != null) {
HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) request;
HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
entity.writeTo(buffer);
if (!entity.isRepeatable()) {
entityRequest.setEntity(new ByteArrayEntity(buffer.toByteArray()));
}
ClientLogger.logRequest(logId, request.getRequestLine().getMethod(), request.getRequestLine().getUri(), "",
() -> new String(buffer.toByteArray()));
} else {
ClientLogger.logRequest(logId, request.getRequestLine().getMethod(), request.getRequestLine().getUri(), "");
}
}
代码示例来源:origin: openzipkin/brave
@Override public String url(HttpRequest request) {
if (request instanceof HttpRequestWrapper) {
HttpRequestWrapper wrapper = (HttpRequestWrapper) request;
HttpHost target = wrapper.getTarget();
if (target != null) return target.toURI() + wrapper.getURI();
}
return request.getRequestLine().getUri();
}
代码示例来源:origin: Nike-Inc/wingtips
@Override
public @Nullable String getRequestHttpMethod(@Nullable HttpRequest request) {
if (request == null) {
return null;
}
return request.getRequestLine().getMethod();
}
代码示例来源:origin: robolectric/robolectric
public HttpResponse emulateRequest(HttpHost httpHost, HttpRequest httpRequest, HttpContext httpContext, RequestDirector requestDirector) throws HttpException, IOException {
if (logHttpRequests) {
System.out.println(" <-- " + httpRequest.getRequestLine());
}
HttpResponse httpResponse = findResponse(httpRequest);
if (logHttpRequests) {
System.out.println(" --> " + (httpResponse == null ? null : httpResponse.getStatusLine().getStatusCode()));
}
if (httpResponse == null) {
throw new RuntimeException("Unexpected call to execute, no pending responses are available. See Robolectric.addPendingResponse(). Request was: " +
httpRequest.getRequestLine().getMethod() + " " + httpRequest.getRequestLine().getUri());
} else {
HttpParams params = httpResponse.getParams();
if (HttpConnectionParams.getConnectionTimeout(params) < 0) {
throw new ConnectTimeoutException("Socket is not connected");
} else if (HttpConnectionParams.getSoTimeout(params) < 0) {
throw new ConnectTimeoutException("The operation timed out");
}
}
addRequestInfo(new HttpRequestInfo(httpRequest, httpHost, httpContext, requestDirector));
addHttpResponse(httpResponse);
return httpResponse;
}
public boolean hasPendingResponses() {
代码示例来源:origin: marytts/marytts
/**
* The entry point of all HttpRequestHandlers. When this method returns, the response is sent to the client. We override this
* here to show how simple a processing we are doing for file requests.
*/
@Override
public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) {
String uri = request.getRequestLine().getUri();
if (uri.startsWith("/")) {
uri = uri.substring(1);
}
if (uri.equals(""))
uri = "index.html";
logger.debug("File requested: " + uri);
if (validFiles.contains(uri)) {
try {
sendResourceAsStream(uri, response);
} catch (IOException ioe) {
logger.debug("Cannot send file", ioe);
MaryHttpServerUtils.errorInternalServerError(response, "Cannot send file", ioe);
}
} else {
MaryHttpServerUtils.errorFileNotFound(response, uri);
}
}
内容来源于网络,如有侵权,请联系作者删除!