Search in sources :

Example 1 with HttpPatch

use of org.apache.hc.client5.http.classic.methods.HttpPatch in project LinkAgent by shulieTech.

the class HttpClientv5MethodInterceptor method getParameters.

private Map getParameters(HttpRequest httpRequest) {
    URI uri = null;
    try {
        uri = httpRequest.getUri();
    } catch (URISyntaxException e) {
        logger.error("获取不到url", e);
    }
    if (httpRequest instanceof HttpGet) {
        HttpGet httpGet = (HttpGet) httpRequest;
        return toMap(uri.getQuery());
    }
    if (httpRequest instanceof HttpPost) {
        HttpPost httpPost = (HttpPost) httpRequest;
        HttpEntity httpEntity = httpPost.getEntity();
        Map parameters = toMap(uri.getQuery());
        InputStream in = null;
        try {
            in = httpEntity.getContent();
            parameters.putAll(toMap(toString(in)));
        } catch (Throwable t) {
        } finally {
            if (in != null) {
                try {
                    in.reset();
                } catch (IOException e) {
                }
            }
        }
        return parameters;
    }
    if (httpRequest instanceof HttpPut) {
        HttpPut httpPut = (HttpPut) httpRequest;
        HttpEntity httpEntity = httpPut.getEntity();
        Map parameters = toMap(uri.getQuery());
        InputStream in = null;
        try {
            in = httpEntity.getContent();
            parameters.putAll(toMap(toString(in)));
        } catch (Throwable t) {
        } finally {
            if (in != null) {
                try {
                    in.reset();
                } catch (IOException e) {
                }
            }
        }
        return parameters;
    }
    if (httpRequest instanceof HttpDelete) {
        HttpDelete httpDelete = (HttpDelete) httpRequest;
        return toMap(uri.getQuery());
    }
    if (httpRequest instanceof HttpHead) {
        HttpHead httpHead = (HttpHead) httpRequest;
        return toMap(uri.getQuery());
    }
    if (httpRequest instanceof HttpOptions) {
        HttpOptions httpOptions = (HttpOptions) httpRequest;
        return toMap(uri.getQuery());
    }
    if (httpRequest instanceof HttpTrace) {
        HttpTrace httpTrace = (HttpTrace) httpRequest;
        return toMap(uri.getQuery());
    }
    if (httpRequest instanceof HttpPatch) {
        HttpPatch httpPatch = (HttpPatch) httpRequest;
        HttpEntity httpEntity = httpPatch.getEntity();
        Map parameters = toMap(uri.getQuery());
        InputStream in = null;
        try {
            in = httpEntity.getContent();
            parameters.putAll(toMap(toString(in)));
        } catch (Throwable t) {
        } finally {
            if (in != null) {
                try {
                    in.reset();
                } catch (IOException e) {
                }
            }
        }
        return parameters;
    }
    return Collections.EMPTY_MAP;
}
Also used : HttpPost(org.apache.hc.client5.http.classic.methods.HttpPost) HttpEntity(org.apache.hc.core5.http.HttpEntity) HttpDelete(org.apache.hc.client5.http.classic.methods.HttpDelete) InputStream(java.io.InputStream) HttpGet(org.apache.hc.client5.http.classic.methods.HttpGet) HttpOptions(org.apache.hc.client5.http.classic.methods.HttpOptions) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) HttpPut(org.apache.hc.client5.http.classic.methods.HttpPut) HttpHead(org.apache.hc.client5.http.classic.methods.HttpHead) HttpPatch(org.apache.hc.client5.http.classic.methods.HttpPatch) HttpTrace(org.apache.hc.client5.http.classic.methods.HttpTrace) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 HttpDelete (org.apache.hc.client5.http.classic.methods.HttpDelete)1 HttpGet (org.apache.hc.client5.http.classic.methods.HttpGet)1 HttpHead (org.apache.hc.client5.http.classic.methods.HttpHead)1 HttpOptions (org.apache.hc.client5.http.classic.methods.HttpOptions)1 HttpPatch (org.apache.hc.client5.http.classic.methods.HttpPatch)1 HttpPost (org.apache.hc.client5.http.classic.methods.HttpPost)1 HttpPut (org.apache.hc.client5.http.classic.methods.HttpPut)1 HttpTrace (org.apache.hc.client5.http.classic.methods.HttpTrace)1 HttpEntity (org.apache.hc.core5.http.HttpEntity)1