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

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

Introduction

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

Prototype

public abstract String getPath();

Source Link

Usage

From source file:net.sourceforge.jwbf.actions.HttpActionClient.java

/**
 * //  w  w w  .ja  va  2 s.co m
 * @param a
 *            a
 * @return message, never null
 * @throws ActionException
 *             on problems with http, cookies and io
 * @throws ProcessException on inner problems
 */
public String performAction(ContentProcessable a) throws ActionException, ProcessException {

    List<HttpMethod> msgs = a.getMessages();
    String out = "";
    Iterator<HttpMethod> it = msgs.iterator();
    while (it.hasNext()) {
        HttpMethod e = it.next();
        if (path.length() > 1) {

            e.setPath(path + e.getPath());
            LOG.debug("path is: " + e.getPath());

        }
        try {
            if (e instanceof GetMethod) {

                out = get(e, a);

            } else {
                out = post(e, a);
            }
        } catch (IOException e1) {
            throw new ActionException(e1);
        }

    }
    return out;

}

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

/**
 * @param method The HttpMethod that generated this response
 *///from   w  w  w. j ava  2 s .c o  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.cerema.cloud2.lib.common.OwnCloudClient.java

/**
 * Requests the received method./*from ww  w . j av a 2s  .  c o  m*/
 *
 * 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;
    }
}

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

/**
 * Copy-constructor from an {@link HttpMethod}.
 * //from w  w w .  j  av a 2 s  .  c  o  m
 * @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:com.basho.riak.client.RiakObject.java

String getBasePathFromHttpMethod(HttpMethod httpMethod) {
    if (httpMethod == null || httpMethod.getPath() == null)
        return "";

    String path = httpMethod.getPath();
    int idx = path.length() - 1;

    // ignore any trailing slash
    if (path.endsWith("/")) {
        idx--;/*from w ww .j av a2  s .co m*/
    }

    // trim off last two path components
    idx = path.lastIndexOf('/', idx);
    idx = path.lastIndexOf('/', idx - 1);

    if (idx <= 0)
        return "";

    return path.substring(0, idx);
}

From source file:com.dtolabs.client.utils.BaseFormAuthenticator.java

/**
 * Return true if the result from the get method indicates re-authentication is needed
 *
 * @param resultCode result code/*from w w w.  j a  v a  2s  .c  om*/
 * @param method     request
 *
 * @return true if re-authentication is needed
 */
public boolean needsReAuthentication(final int resultCode, final HttpMethod method) {
    if (resultCode >= 300 && resultCode < 400 && method.getResponseHeader("Location") != null) {
        final String loc = method.getResponseHeader("Location").getValue();
        final int logNdx = loc.indexOf(LOGIN_PAGE);
        final int qNdx = loc.indexOf("?");
        if (logNdx >= 0 && (qNdx < 0 || logNdx < qNdx)) {
            //if "user/login" is in the location and is not after query part of URL
            //reset session cookie then return true
            ClientState.resetHttpState();
            return true;
        }
    } else if (HttpStatus.SC_OK == resultCode) {
        final String loc = method.getPath();
        final int logNdx = loc.indexOf(LOGIN_PAGE);
        final int qNdx = loc.indexOf("?");
        if (logNdx >= 0 && (qNdx < 0 || logNdx < qNdx)) {
            //if "user/login" is in the location and is not after query part of URL
            //reset session cookie then return true
            ClientState.resetHttpState();
            return true;
        }
    }
    return false;
}

From source file:com.owncloud.android.lib.common.OwnCloudClient.java

@Override
public int executeMethod(HttpMethod method) throws IOException, HttpException {
    try { // just to log
        boolean customRedirectionNeeded = false;

        try {//w w  w.  j  ava2s. 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 if needed");
            */
            customRedirectionNeeded = mFollowRedirects;
        }

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

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

        int status = super.executeMethod(method);

        if (customRedirectionNeeded) {
            status = patchRedirection(status, method);
        }

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

        return status;

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

From source file:com.hp.alm.ali.rest.client.AliRestClient.java

private boolean tryLogin(ResultInfo resultInfo, HttpMethod method) {
    try {//from w ww  . j a  v  a  2  s.co m
        login();
        return true;
    } catch (HttpStatusBasedException e) {
        resultInfo.setHttpStatus(e.getHttpStatus());
        resultInfo.setReasonPhrase(e.getReasonPhrase());
        try {
            resultInfo.setLocation(e.getLocation() + " [on-behalf-of: " + method.getURI().toString() + "]");
        } catch (URIException e2) {
            resultInfo.setLocation(e.getLocation() + " [on-behalf-of: " + method.getPath() + "]");
        }
        return false;
    }
}

From source file:net.adamcin.httpsig.http.apache3.Http3SignatureAuthScheme.java

public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
    if (credentials instanceof SignerCredentials) {
        SignerCredentials creds = (SignerCredentials) credentials;
        String headers = this.getParameter(Constants.HEADERS);
        String algorithms = this.getParameter(Constants.ALGORITHMS);

        Challenge challenge = new Challenge(this.getRealm(), Constants.parseTokens(headers),
                Challenge.parseAlgorithms(algorithms));

        Signer signer = creds.getSigner();
        if (signer != null) {

            if (this.rotate) {
                this.rotate = false;
                if (!signer.rotateKeys(challenge, this.lastAuthz)) {
                    signer.rotateKeys(challenge);
                    return null;
                }/*from w  w w.  j a v a  2  s.  c  o  m*/
            }

            RequestContent.Builder sigBuilder = new RequestContent.Builder();

            sigBuilder.setRequestTarget(method.getName(),
                    method.getPath() + (method.getQueryString() != null ? "?" + method.getQueryString() : ""));

            for (Header header : method.getRequestHeaders()) {
                sigBuilder.addHeader(header.getName(), header.getValue());
            }

            if (sigBuilder.build().getDate() == null) {
                sigBuilder.addDateNow();
                method.addRequestHeader(Constants.HEADER_DATE, sigBuilder.build().getDate());
            }

            Authorization authorization = creds.getSigner().sign(sigBuilder.build());
            this.lastAuthz = authorization;
            if (authorization != null) {
                return authorization.getHeaderValue();
            }
        }
    }

    return null;
}

From source file:com.zenkey.net.prowser.Tab.java

/**************************************************************************
 * Writes tracing information that traces the request/response activity.
 * /* ww w .j  av a2s  .  c  om*/
 * @param traceLevel
 *        Indicates how much trace info to produce.
 * @param traceStream
 *        An output stream where trace statements will be written.
 * @param httpMethod
 *        The HttpMethod object of the request.
 */
private static void writeTrace(int traceLevel, PrintStream traceStream, HttpMethod httpMethod) {

    try {
        if (traceLevel >= TRACE_URI) {
            // Show trace output of the request URI
            traceStream
                    .println("-------------------------------------------------------------------------------");
            traceStream.println(httpMethod.getURI() + "\n");
        }

        if (traceLevel >= TRACE_REQUEST_RESPONSE_LINES) {
            // Show trace output of the HTTP request line
            traceStream.println(httpMethod.getName() + " " + httpMethod.getPath()
                    + (httpMethod.getQueryString() == null ? "" : "?" + httpMethod.getQueryString()) + " "
                    + httpMethod.getParams().getVersion().toString());
        }

        if (traceLevel >= TRACE_HEADERS) {
            // Show trace output of the HTTP request headers
            for (Header header : httpMethod.getRequestHeaders()) {
                traceStream.println(header.getName() + ": " + header.getValue());
            }
            // Show trace of request entity body
            if (httpMethod instanceof PostMethod) {
                NameValuePair[] parameters = ((PostMethod) httpMethod).getParameters();
                if (parameters != null) {
                    // StringBuffer parameterString = new StringBuffer();
                    // for (NameValuePair parameter : parameters) {
                    //       parameterString.append(parameter.getName() + "=" + parameter.getValue() + "&");
                    // }
                    // parameterString.deleteCharAt(parameterString.length() - 1);
                    String parameterString = new String(
                            ((ByteArrayRequestEntity) ((PostMethod) httpMethod).getRequestEntity())
                                    .getContent(),
                            "UTF-8");
                    traceStream.println("    |");
                    traceStream.println("    +-- " + parameterString);
                }
            }
            traceStream.println();
        }

        if (traceLevel >= TRACE_REQUEST_RESPONSE_LINES) {
            // Show trace output of the HTTP status line
            traceStream.println(httpMethod.getStatusLine().toString());
        }

        if (traceLevel >= TRACE_HEADERS) {
            // Show trace output of the HTTP response headers
            for (Header header : httpMethod.getResponseHeaders()) {
                traceStream.println(header.getName() + ": " + header.getValue());
            }
            traceStream.println();
        }

        if (traceLevel >= TRACE_BODY) {
            // Show trace output of the HTTP response body
            traceStream.println(httpMethod.getResponseBodyAsString());
            traceStream.println();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}