Example usage for org.apache.commons.httpclient HttpMethod getName

List of usage examples for org.apache.commons.httpclient HttpMethod getName

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpMethod getName.

Prototype

public abstract String getName();

Source Link

Usage

From source file:net.oauth.client.httpclient3.HttpMethodResponse.java

/**
 * Construct an OAuthMessage from the HTTP response, including parameters
 * from OAuth WWW-Authenticate headers and the body. The header parameters
 * come first, followed by the ones from the response body.
 *///  w w w.  ja  v a 2  s  .c  o m
public HttpMethodResponse(HttpMethod method, byte[] requestBody, String requestEncoding) throws IOException {
    super(method.getName(), new URL(method.getURI().toString()));
    this.method = method;
    this.requestBody = requestBody;
    this.requestEncoding = requestEncoding;
    this.headers.addAll(getHeaders());
}

From source file:net.sf.sail.webapp.domain.webservice.http.impl.HttpRestTransportImpl.java

private void logRequest(HttpMethod method, String bodyData) throws URIException {
    if (logger.isInfoEnabled()) {
        logger.info(method.getName() + ": " + method.getURI());
        if (bodyData != "")
            logger.info(method.getName() + ": " + bodyData);
    }/*from  ww  w . ja  va 2s  . c o  m*/
}

From source file:com.mosso.client.cloudfiles.FilesResponse.java

/**
 * @param method The HttpMethod that generated this response
 *///w w  w .j  a v a 2  s  . co  m
public FilesResponse(HttpMethod method) {
    httpmethod = method;

    if (logger.isDebugEnabled()) {
        logger.debug("Request Method: " + method.getName());
        logger.debug("Request Path: " + method.getPath());
        logger.debug("Status Line: " + getStatusLine());
        Header[] reqHeaders = method.getRequestHeaders();
        for (Header rH : reqHeaders)
            logger.debug(rH.toExternalForm());

        Header[] responseHeaders = getResponseHeaders();
        for (int i = 0; i < responseHeaders.length; i++)
            logger.debug(responseHeaders[i]);
    }
}

From source file:com.springsource.insight.plugin.apache.http.hc3.HttpClientExecutionCollectionAspectTest.java

private void assertRequestDetails(String uri, OperationMap details, HttpMethod method, boolean checkHeaders) {
    assertEquals("Mismatched method", method.getName(), details.get("method"));
    assertEquals("Mismatched URI", HttpClientExecutionCollectionAspect.getUri(method),
            details.get(OperationFields.URI));
    assertEquals("Mismatched protocol", HttpClientExecutionCollectionAspect.createVersionValue(method),
            details.get("protocol"));
    if (checkHeaders) {
        assertHeadersContents(uri, "request", details, method, true);
    }//w  w  w  . j ava2s  . com
}

From source file:com.zimbra.cs.dav.client.WebDavClient.java

private void logRequestInfo(HttpMethod method, String body) throws IOException {
    if (!mDebugEnabled) {
        return;/* w  ww.j a v a 2 s.  co  m*/
    }
    StringBuilder reqLog = new StringBuilder();
    reqLog.append("WebDAV request:\n").append(method.getName()).append(" ").append(method.getURI().toString());
    reqLog.append('\n');
    Header headers[] = method.getRequestHeaders();
    if (headers != null && headers.length > 0) {
        for (Header hdr : headers) {
            String hdrName = hdr.getName();
            reqLog.append(hdrName).append('=');
            if (hdrName.contains("Auth") || (hdrName.contains(HttpHeaders.COOKIE))) {
                reqLog.append("*** REPLACED ***\n");
            } else {
                reqLog.append(hdr.getValue()).append('\n');
            }
        }
    }
    if (Strings.isNullOrEmpty(body) || !ZimbraLog.dav.isTraceEnabled()) {
        ZimbraLog.dav.debug(reqLog.toString());
    } else {
        ZimbraLog.dav.debug("%s\n%s", reqLog.toString(), body);
    }
}

From source file:eu.alefzero.webdav.WebdavClient.java

@Override
public int executeMethod(HttpMethod method) throws IOException, HttpException {
    boolean customRedirectionNeeded = false;
    try {//  w  ww . j a va2s. c  om
        method.setFollowRedirects(mFollowRedirects);
    } catch (Exception e) {
        if (mFollowRedirects)
            Log_OC.d(TAG, "setFollowRedirects failed for " + method.getName()
                    + " method, custom redirection will be used");
        customRedirectionNeeded = mFollowRedirects;
    }
    if (mSsoSessionCookie != null && mSsoSessionCookie.length() > 0) {
        method.setRequestHeader("Cookie", mSsoSessionCookie);
    }
    int status = super.executeMethod(method);
    int redirectionsCount = 0;
    while (customRedirectionNeeded && redirectionsCount < MAX_REDIRECTIONS_COUNT
            && (status == HttpStatus.SC_MOVED_PERMANENTLY || status == HttpStatus.SC_MOVED_TEMPORARILY
                    || status == HttpStatus.SC_TEMPORARY_REDIRECT)) {

        Header location = method.getResponseHeader("Location");
        if (location != null) {
            Log_OC.d(TAG, "Location to redirect: " + location.getValue());
            method.setURI(new URI(location.getValue(), true));
            status = super.executeMethod(method);
            redirectionsCount++;

        } else {
            Log_OC.d(TAG, "No location to redirect!");
            status = HttpStatus.SC_NOT_FOUND;
        }
    }

    return status;
}

From source file:edu.utah.further.core.ws.HttpResponseTo.java

/**
 * Copy-constructor from an {@link HttpMethod}.
 * //from w w w .jav a 2  s . com
 * @param method
 *            method to copy fields from
 */
public HttpResponseTo(final HttpMethod method) throws IOException {
    this.httpMethod = edu.utah.further.core.api.ws.HttpMethod.valueOf(method.getName());
    this.statusLine = method.getStatusLine();

    for (final Header header : method.getResponseHeaders()) {
        this.responseHeaders.addHeader(new Header(header.getName(), header.getValue()));
    }

    this.path = method.getPath();
    this.queryString = method.getQueryString();
    this.responseBody = method.getResponseBody();
    setParams(method.getParams());
}

From source file:ar.com.zauber.commons.web.proxy.HttpClientRequestProxy.java

/**
 * @see AbstractController#handleRequestInternal(HttpServletRequest,
 *      HttpServletResponse)//w  ww  . j  av a 2 s.c om
 *      @throws Exception .
 */
public final void handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response)
        throws Exception {

    final URLResult r = urlRequestMapper.getProxiedURLFromRequest(request);
    if (r.hasResult()) {
        final HttpMethod method = buildRequest(request, r);
        InputStream is = null;
        try {
            // Entity enclosing requests cannot be redirected 
            // without user intervention according to RFC 2616
            if (!method.getName().equalsIgnoreCase("post") && !method.getName().equalsIgnoreCase("put")) {
                method.setFollowRedirects(followRedirects);
            }
            httpClient.executeMethod(method);
            updateResponseCode(request, response, method);
            proxyHeaders(response, method);
            addOtherHeaders(response, method);

            is = method.getResponseBodyAsStream();

            if (is != null) {
                if (contentTransformer.getContentType() != null) {
                    response.setContentType(contentTransformer.getContentType());
                }

                try {
                    String uri = request.getPathInfo();
                    // When using this component as a Filter,  the path info
                    // can be null, but the same information is available at
                    // getServletPath
                    if (uri == null) {
                        uri = request.getServletPath();
                    }

                    contentTransformer.transform(is, response.getOutputStream(),
                            new InmutableContentMetadata(uri, getContentType(method), method.getStatusCode()));
                } finally {
                    is.close();
                }
            }
        } catch (final ConnectException e) {
            onConnectionException(request, response, method, e);
        } finally {
            if (is != null) {
                is.close();
            }
            method.releaseConnection();
        }
    } else {
        onNoMapping(request, response);
    }
}

From source file:com.intuit.tank.httpclient3.TankHttpClient3.java

private void sendRequest(BaseRequest request, @Nonnull HttpMethod method, String requestBody) {
    String uri = null;/*w ww .j  a  v  a2s .co  m*/
    long waitTime = 0L;

    try {
        uri = method.getURI().toString();
        logger.debug(request.getLogUtil().getLogMessage(
                "About to " + method.getName() + " request to " + uri + " with requestBody  " + requestBody,
                LogEventType.Informational));
        List<String> cookies = new ArrayList<String>();
        if (httpclient != null && httpclient.getState() != null && httpclient.getState().getCookies() != null) {
            for (Cookie cookie : httpclient.getState().getCookies()) {
                cookies.add("REQUEST COOKIE: " + cookie.toExternalForm() + " (domain=" + cookie.getDomain()
                        + " : path=" + cookie.getPath() + ")");
            }
        }
        request.logRequest(uri, requestBody, method.getName(), request.getHeaderInformation(), cookies, false);
        setHeaders(request, method, request.getHeaderInformation());
        long startTime = System.currentTimeMillis();
        request.setTimestamp(new Date(startTime));
        httpclient.executeMethod(method);

        // read response body
        byte[] responseBody = new byte[0];
        // check for no content headers
        if (method.getStatusCode() != 203 && method.getStatusCode() != 202 && method.getStatusCode() != 204) {
            try {
                InputStream httpInputStream = method.getResponseBodyAsStream();
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                int curByte = httpInputStream.read();
                while (curByte >= 0) {
                    out.write(curByte);
                    curByte = httpInputStream.read();
                }
                responseBody = out.toByteArray();
            } catch (Exception e) {
                logger.warn("could not get response body: " + e);
            }
        }
        long endTime = System.currentTimeMillis();
        processResponse(responseBody, startTime, endTime, request, method.getStatusText(),
                method.getStatusCode(), method.getResponseHeaders(), httpclient.getState());
        waitTime = endTime - startTime;
    } catch (Exception ex) {
        logger.error(request.getLogUtil().getLogMessage(
                "Could not do " + method.getName() + " to url " + uri + " |  error: " + ex.toString(),
                LogEventType.IO), ex);
        throw new RuntimeException(ex);
    } finally {
        try {
            method.releaseConnection();
        } catch (Exception e) {
            logger.warn("Could not release connection: " + e, e);
        }
        if (method.getName().equalsIgnoreCase("post")
                && request.getLogUtil().getAgentConfig().getLogPostResponse()) {
            logger.info(request.getLogUtil()
                    .getLogMessage("Response from POST to " + request.getRequestUrl() + " got status code "
                            + request.getResponse().getHttpCode() + " BODY { " + request.getResponse().getBody()
                            + " }", LogEventType.Informational));
        }
    }
    if (waitTime != 0) {
        doWaitDueToLongResponse(request, waitTime, uri);
    }
}

From source file:com.cerema.cloud2.lib.common.OwnCloudClient.java

/**
 * Requests the received method.//w  ww  . ja  v a2s .  com
 *
 * Executes the method through the inherited HttpClient.executedMethod(method).
 *
 * @param method                HTTP method request.
 */
@Override
public int executeMethod(HttpMethod method) throws IOException {
    try {
        // Update User Agent
        HttpParams params = method.getParams();
        String userAgent = OwnCloudClientManagerFactory.getUserAgent();
        params.setParameter(HttpMethodParams.USER_AGENT, userAgent);

        Log_OC.d(TAG + " #" + mInstanceNumber, "REQUEST " + method.getName() + " " + method.getPath());

        //           logCookiesAtRequest(method.getRequestHeaders(), "before");
        //           logCookiesAtState("before");
        method.setFollowRedirects(false);

        int status = super.executeMethod(method);

        if (mFollowRedirects) {
            status = followRedirection(method).getLastStatus();
        }

        //           logCookiesAtRequest(method.getRequestHeaders(), "after");
        //           logCookiesAtState("after");
        //           logSetCookiesAtResponse(method.getResponseHeaders());

        return status;

    } catch (IOException e) {
        //Log_OC.d(TAG + " #" + mInstanceNumber, "Exception occurred", e);
        throw e;
    }
}