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.sf.j2ep.model.AllowedMethodHandler.java

/**
 * Checks the method to see if it's allowed
 * /*from  w  ww .  j av a2s . c om*/
 * @param method The method that is checked
 * @return true if the method is allowed, false otherwise
 * @see AllowedMethodHandler#methodAllowed(String)
 */
public static boolean methodAllowed(HttpMethod method) {
    return methodAllowed(method.getName());
}

From source file:net.sf.j2ep.factories.ResponseHandlerFactory.java

/**
 * Checks the method being received and created a 
 * suitable ResponseHandler for this method.
 * //from   w  w  w  .  j a  va  2 s . c  om
 * @param method Method to handle
 * @return The handler for this response
 * @throws MethodNotAllowedException If no method could be choose this exception is thrown
 */
public static ResponseHandler createResponseHandler(HttpMethod method) throws MethodNotAllowedException {
    if (!AllowedMethodHandler.methodAllowed(method)) {
        throw new MethodNotAllowedException(
                "The method " + method.getName()
                        + " is not in the AllowedHeaderHandler's list of allowed methods.",
                AllowedMethodHandler.getAllowHeader());
    }

    ResponseHandler handler = null;
    if (method.getName().equals("OPTIONS")) {
        handler = new OptionsResponseHandler((OptionsMethod) method);
    } else if (method.getName().equals("GET")) {
        handler = new GetResponseHandler((GetMethod) method);
    } else if (method.getName().equals("HEAD")) {
        handler = new HeadResponseHandler((HeadMethod) method);
    } else if (method.getName().equals("POST")) {
        handler = new PostResponseHandler((PostMethod) method);
    } else if (method.getName().equals("PUT")) {
        handler = new PutResponseHandler((PutMethod) method);
    } else if (method.getName().equals("DELETE")) {
        handler = new DeleteResponseHandler((DeleteMethod) method);
    } else if (method.getName().equals("TRACE")) {
        handler = new TraceResponseHandler((TraceMethod) method);
    } else {
        throw new MethodNotAllowedException("The method " + method.getName()
                + " was allowed by the AllowedMethodHandler, not by the factory.", handledMethods);
    }

    return handler;
}

From source file:com.cloud.utils.net.HTTPUtils.java

/**
 * @param httpClient//from   w w  w .  j  a  v a  2 s  . c  o  m
 * @param httpMethod
 * @return
 *          Returns the HTTP Status Code or -1 if an exception occurred.
 */
public static int executeMethod(HttpClient httpClient, HttpMethod httpMethod) {
    // Execute GetMethod
    try {
        return httpClient.executeMethod(httpMethod);
    } catch (IOException e) {
        LOGGER.warn("Exception while executing HttpMethod " + httpMethod.getName() + " on URL "
                + httpMethod.getPath());
        return -1;
    }
}

From source file:com.feilong.tools.net.httpclient3.HttpClientUtil.java

/**
 * ?log./*from w w w.  j  a  v a2  s .c o m*/
 * 
 * @param httpMethod
 *            the http method
 * @return the http method attribute map for log
 */
private static Map<String, Object> getHttpMethodRequestAttributeMapForLog(HttpMethod httpMethod) {
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    try {
        map.put("httpMethod.getName()", httpMethod.getName());
        map.put("httpMethod.getURI()", httpMethod.getURI().toString());
        map.put("httpMethod.getPath()", httpMethod.getPath());
        map.put("httpMethod.getQueryString()", httpMethod.getQueryString());

        map.put("httpMethod.getRequestHeaders()", httpMethod.getRequestHeaders());

        map.put("httpMethod.getDoAuthentication()", httpMethod.getDoAuthentication());
        map.put("httpMethod.getFollowRedirects()", httpMethod.getFollowRedirects());
        map.put("httpMethod.getHostAuthState()", httpMethod.getHostAuthState().toString());

        // HttpMethodParams httpMethodParams = httpMethod.getParams();
        // map.put("httpMethod.getParams()", httpMethodParams);
        map.put("httpMethod.getProxyAuthState()", httpMethod.getProxyAuthState().toString());

    } catch (Exception e) {
        log.error(e.getClass().getName(), e);
    }
    return map;
}

From source file:fr.cls.atoll.motu.library.cas.HttpClientCAS.java

public static String debugHttpMethod(HttpMethod method) {
    StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append("\nName:");
    stringBuffer.append(method.getName());
    stringBuffer.append("\n");
    stringBuffer.append("\nPath:");
    stringBuffer.append(method.getPath());
    stringBuffer.append("\n");
    stringBuffer.append("\nQueryString:");
    stringBuffer.append(method.getQueryString());
    stringBuffer.append("\n");
    stringBuffer.append("\nUri:");
    try {/*from   w w w. j  a v a2  s.c  o  m*/
        stringBuffer.append(method.getURI().toString());
    } catch (URIException e) {
        // Do nothing
    }
    stringBuffer.append("\n");
    HttpMethodParams httpMethodParams = method.getParams();
    stringBuffer.append("\nHttpMethodParams:");
    stringBuffer.append(httpMethodParams.toString());

    return stringBuffer.toString();

}

From source file:com.comcast.cats.service.util.HttpClientUtil.java

public static synchronized Object getForObject(String uri, Map<String, String> paramMap) {
    Object responseObject = new Object();

    HttpMethod httpMethod = new GetMethod(uri);

    if ((null != paramMap) && (!paramMap.isEmpty())) {
        httpMethod.setQueryString(getNameValuePair(paramMap));
    }/*from   w  w  w.  j a v  a  2s  .c o m*/

    Yaml yaml = new Yaml();

    HttpClient client = new HttpClient();
    InputStream responseStream = null;
    Reader inputStreamReader = null;

    try {
        int responseCode = client.executeMethod(httpMethod);

        if (HttpStatus.SC_OK != responseCode) {
            logger.error("[ REQUEST  ] " + httpMethod.getURI().toString());
            logger.error("[ METHOD   ] " + httpMethod.getName());
            logger.error("[ STATUS   ] " + responseCode);
        } else {
            logger.trace("[ REQUEST  ] " + httpMethod.getURI().toString());
            logger.trace("[ METHOD   ] " + httpMethod.getName());
            logger.trace("[ STATUS   ] " + responseCode);
        }

        responseStream = httpMethod.getResponseBodyAsStream();
        inputStreamReader = new InputStreamReader(responseStream, VideoRecorderServiceConstants.UTF);
        responseObject = yaml.load(inputStreamReader);
    } catch (IOException ioException) {
        ioException.printStackTrace();
    } finally {
        cleanUp(inputStreamReader, responseStream, httpMethod);
    }

    return responseObject;
}

From source file:com.comcast.cats.service.util.HttpClientUtil.java

public static synchronized Object postForObject(String uri, Map<String, String> paramMap) {
    Object responseObject = new Object();

    HttpMethod httpMethod = new PostMethod(uri);

    if ((null != paramMap) && (!paramMap.isEmpty())) {
        httpMethod.setQueryString(getNameValuePair(paramMap));
    }// w  w  w . j  a va  2s. c  o m

    Yaml yaml = new Yaml();

    HttpClient client = new HttpClient();
    InputStream responseStream = null;
    Reader inputStreamReader = null;

    try {
        int responseCode = client.executeMethod(httpMethod);

        if (HttpStatus.SC_OK != responseCode) {
            logger.error("[ REQUEST  ] " + httpMethod.getURI().toString());
            logger.error("[ METHOD   ] " + httpMethod.getName());
            logger.error("[ STATUS   ] " + responseCode);
        } else {
            logger.trace("[ REQUEST  ] " + httpMethod.getURI().toString());
            logger.trace("[ METHOD   ] " + httpMethod.getName());
            logger.trace("[ STATUS   ] " + responseCode);
        }

        responseStream = httpMethod.getResponseBodyAsStream();
        inputStreamReader = new InputStreamReader(responseStream, VideoRecorderServiceConstants.UTF);
        responseObject = yaml.load(inputStreamReader);
    } catch (IOException ioException) {
        ioException.printStackTrace();
    } finally {
        cleanUp(inputStreamReader, responseStream, httpMethod);
    }

    return responseObject;
}

From source file:com.comcast.cats.service.util.HttpClientUtil.java

public static synchronized Object deleteForObject(String uri, Map<String, String> paramMap) {
    Object responseObject = new Object();

    HttpMethod httpMethod = new DeleteMethod(uri);

    if ((null != paramMap) && (!paramMap.isEmpty())) {
        httpMethod.setQueryString(getNameValuePair(paramMap));
    }// ww  w. ja  v  a 2  s  .com

    Yaml yaml = new Yaml();

    HttpClient client = new HttpClient();
    InputStream responseStream = null;
    Reader inputStreamReader = null;

    try {
        int responseCode = client.executeMethod(httpMethod);

        if (HttpStatus.SC_OK != responseCode) {
            logger.error("[ REQUEST  ] " + httpMethod.getURI().toString());
            logger.error("[ METHOD   ] " + httpMethod.getName());
            logger.error("[ STATUS   ] " + responseCode);
        } else {
            logger.trace("[ REQUEST  ] " + httpMethod.getURI().toString());
            logger.trace("[ METHOD   ] " + httpMethod.getName());
            logger.trace("[ STATUS   ] " + responseCode);
        }

        responseStream = httpMethod.getResponseBodyAsStream();
        inputStreamReader = new InputStreamReader(responseStream, VideoRecorderServiceConstants.UTF);
        responseObject = yaml.load(inputStreamReader);
    } catch (IOException ioException) {
        ioException.printStackTrace();
    } finally {
        cleanUp(inputStreamReader, responseStream, httpMethod);
    }

    return responseObject;
}

From source file:com.google.jstestdriver.server.gateway.GatewayMethodTest.java

public void testGetNameAndGetUri() throws Exception {
    HttpMethod method = new GatewayMethod("GET", "http://www.google.com/search");
    assertEquals("GET", method.getName());
    assertEquals("http://www.google.com/search", method.getURI().toString());
}

From source file:net.oauth.client.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.
 *//* www .  jav  a  2 s  .c o m*/
public HttpMethodResponse(HttpMethod method) throws IOException {
    super(method.getName(), method.getURI().toString(), NO_PARAMETERS);
    this.method = method;
    try {
        addParameters(getResponseParameters());
    } catch (Exception ignored) {
    }
}