Java Code Examples for org.apache.http.RequestLine#getMethod()

The following examples show how to use org.apache.http.RequestLine#getMethod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApacheHttpClientAspect.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@OnBefore
public static @Nullable TraceEntry onBefore(ThreadContext context,
        @BindParameter @Nullable HttpHost hostObj,
        @BindParameter @Nullable HttpRequest request) {
    if (request == null) {
        return null;
    }
    RequestLine requestLine = request.getRequestLine();
    if (requestLine == null) {
        return null;
    }
    String method = requestLine.getMethod();
    if (method == null) {
        method = "";
    } else {
        method += " ";
    }
    String host = hostObj == null ? "" : hostObj.toURI();
    String uri = requestLine.getUri();
    if (uri == null) {
        uri = "";
    }
    return context.startServiceCallEntry("HTTP", method + Uris.stripQueryString(uri),
            MessageSupplier.create("http client request: {}{}{}", method, host, uri),
            timerName);
}
 
Example 2
Source File: TestHttpHandler.java    From deprecated-security-advanced-modules with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
	RequestLine requestLine = request.getRequestLine();
	this.method = requestLine.getMethod();
	this.uri = requestLine.getUri();

	HttpEntity entity = null;
	if (request instanceof HttpEntityEnclosingRequest) {
		entity = ((HttpEntityEnclosingRequest) request).getEntity();
		body = EntityUtils.toString(entity, StandardCharsets.UTF_8);
	}
}
 
Example 3
Source File: HttpAsyncRequestProducerWrapper.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Override
public HttpRequest generateRequest() throws IOException, HttpException {
    // first read the volatile, span will become visible as a result
    HttpRequest request = delegate.generateRequest();

    if (request != null) {
        RequestLine requestLine = request.getRequestLine();
        if (requestLine != null) {
            String method = requestLine.getMethod();
            span.withName(method).appendToName(" ");
            span.getContext().getHttp().withMethod(method).withUrl(requestLine.getUri());
        }
        span.propagateTraceContext(request, headerSetter);
    }

    HttpHost host = getTarget();
    //noinspection ConstantConditions
    if (host != null) {
        String hostname = host.getHostName();
        if (hostname != null) {
            span.appendToName(hostname);
            HttpClientHelper.setDestinationServiceDetails(span, host.getSchemeName(), hostname, host.getPort());
        }
    }

    //noinspection ConstantConditions
    return request;
}
 
Example 4
Source File: AbstractHttpRequestInterceptor.java    From sofa-tracer with Apache License 2.0 5 votes vote down vote up
public void appendHttpClientRequestSpanTags(HttpRequest httpRequest,
                                            SofaTracerSpan httpClientSpan) {
    if (httpClientSpan == null) {
        return;
    }
    if (this.appName == null) {
        this.appName = SofaTracerConfiguration.getProperty(
            SofaTracerConfiguration.TRACER_APPNAME_KEY, StringUtils.EMPTY_STRING);
    }
    //lazy init
    RequestLine requestLine = httpRequest.getRequestLine();
    String methodName = requestLine.getMethod();
    //appName
    httpClientSpan.setTag(CommonSpanTags.LOCAL_APP,
        this.appName == null ? StringUtils.EMPTY_STRING : this.appName);
    //targetAppName
    httpClientSpan.setTag(CommonSpanTags.REMOTE_APP,
        this.targetAppName == null ? StringUtils.EMPTY_STRING : this.targetAppName);
    if (httpRequest instanceof HttpRequestWrapper) {
        HttpRequestWrapper httpRequestWrapper = (HttpRequestWrapper) httpRequest;
        httpClientSpan.setTag(CommonSpanTags.REQUEST_URL, httpRequestWrapper.getOriginal()
            .getRequestLine().getUri());
    } else {
        httpClientSpan.setTag(CommonSpanTags.REQUEST_URL, requestLine.getUri());
    }
    //method
    httpClientSpan.setTag(CommonSpanTags.METHOD, methodName);
    //length
    if (httpRequest instanceof HttpEntityEnclosingRequest) {
        HttpEntityEnclosingRequest httpEntityEnclosingRequest = (HttpEntityEnclosingRequest) httpRequest;
        HttpEntity httpEntity = httpEntityEnclosingRequest.getEntity();
        httpClientSpan.setTag(CommonSpanTags.REQ_SIZE,
            httpEntity == null ? -1 : httpEntity.getContentLength());
    }
    //carrier
    this.processHttpClientRequestCarrier(httpRequest, httpClientSpan);
}
 
Example 5
Source File: UpnpHttpRequestFactory.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public HttpRequest newHttpRequest(final RequestLine requestline)
        throws MethodNotSupportedException {
    if (requestline == null) {
        throw new IllegalArgumentException("Request line may not be null");
    }
    String method = requestline.getMethod();
    String uri = requestline.getUri();
    return newHttpRequest(method, uri);
}
 
Example 6
Source File: UpnpHttpRequestFactory.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public HttpRequest newHttpRequest(final RequestLine requestline)
        throws MethodNotSupportedException {
    if (requestline == null) {
        throw new IllegalArgumentException("Request line may not be null");
    }
    String method = requestline.getMethod();
    String uri = requestline.getUri();
    return newHttpRequest(method, uri);
}
 
Example 7
Source File: ApacheHttpAsyncClientAspect.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@OnBefore
public static @Nullable AsyncTraceEntry onBefore(ThreadContext context,
        @BindParameter @Nullable HttpHost hostObj,
        @BindParameter @Nullable HttpRequest request,
        @BindParameter ParameterHolder<FutureCallback<HttpResponse>> callback) {
    if (request == null) {
        return null;
    }
    RequestLine requestLine = request.getRequestLine();
    if (requestLine == null) {
        return null;
    }
    String method = requestLine.getMethod();
    if (method == null) {
        method = "";
    } else {
        method += " ";
    }
    String host = hostObj == null ? "" : hostObj.toURI();
    String uri = requestLine.getUri();
    if (uri == null) {
        uri = "";
    }
    AsyncTraceEntry asyncTraceEntry = context.startAsyncServiceCallEntry("HTTP",
            method + Uris.stripQueryString(uri),
            MessageSupplier.create("http client request: {}{}{}", method, host, uri),
            timerName);
    callback.set(ExecuteAdvice.createWrapper(context, callback, asyncTraceEntry));
    return asyncTraceEntry;
}
 
Example 8
Source File: HttpRequestParcel.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public HttpRequestParcel(HttpUriRequest request) {
    RequestLine line = request.getRequestLine();
    uri = line.getUri();
    method = line.getMethod();
    headers = new Bundle();
    for (Header header : request.getAllHeaders()) {
        headers.putString(header.getName(), header.getValue());
    }
    params = new Bundle();
    entity = null;
    files = new Bundle();
}
 
Example 9
Source File: DispatchRequestFactory.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public HttpRequest newHttpRequest(RequestLine requestLine)
        throws MethodNotSupportedException {
    String method = requestLine.getMethod();
    String uri = requestLine.getUri();
    return this.newHttpRequest(method, uri);
}
 
Example 10
Source File: HttpRequestBuilder.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public HttpRequest newHttpRequest(RequestLine requestLine)
        throws MethodNotSupportedException {
    String method = requestLine.getMethod();
    String uri = requestLine.getUri();
    return newHttpRequest(method, uri);
}