Java 类org.apache.commons.httpclient.methods.OptionsMethod 实例源码

项目:class-guard    文件:CommonsClientHttpRequestFactory.java   
/**
 * Create a Commons HttpMethodBase object for the given HTTP method
 * and URI specification.
 * @param httpMethod the HTTP method
 * @param uri the URI
 * @return the Commons HttpMethodBase object
 */
protected HttpMethodBase createCommonsHttpMethod(HttpMethod httpMethod, String uri) {
    switch (httpMethod) {
        case GET:
            return new GetMethod(uri);
        case DELETE:
            return new DeleteMethod(uri);
        case HEAD:
            return new HeadMethod(uri);
        case OPTIONS:
            return new OptionsMethod(uri);
        case POST:
            return new PostMethod(uri);
        case PUT:
            return new PutMethod(uri);
        case TRACE:
            return new TraceMethod(uri);
        case PATCH:
            throw new IllegalArgumentException(
                    "HTTP method PATCH not available before Apache HttpComponents HttpClient 4.2");
        default:
            throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
    }
}
项目:bdbadmin    文件:BdbClient.java   
public Category map(IdProof assertion) throws ServiceException {
    try {
        OptionsMethod method = new OptionsMethod(baseUrl);
        method.setRequestHeader(AuthenticationHeader.HEADER_NAME, AuthenticationHeader.encode(assertion));

        int result = httpClient.executeMethod(method);
        if (result != 200) {
            throw new ServiceException(result);
        }
        else {
            Unmarshaller u = context.createUnmarshaller();
            return (Category)u.unmarshal(method.getResponseBodyAsStream());
        }
    }
    catch (Exception ex) {
        throw new ServiceFailure(ex);
    }
}
项目:bdbadmin    文件:BdbClient.java   
public EntryInfo entryInfo(IdProof assertion, String path) throws ServiceException {
    try {
        OptionsMethod method = new OptionsMethod(baseUrl + "/" + path);
        method.setRequestHeader(AuthenticationHeader.HEADER_NAME, AuthenticationHeader.encode(assertion));

        int result = httpClient.executeMethod(method);
        if (result != 200) {
            throw new ServiceException(result);
        }
        else {
            Unmarshaller u = context.createUnmarshaller();
            return (EntryInfo)u.unmarshal(method.getResponseBodyAsStream());
        }
    }
    catch (Exception ex) {
        throw new ServiceFailure(ex);
    }
}
项目:oscm    文件:ResponseHandlerFactory.java   
/**
 * Checks the method being received and created a 
 * suitable ResponseHandler for this method.
 * 
 * @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;
}
项目:alfresco-remote-api    文件:PublicApiHttpClient.java   
public HttpResponse options(final RequestContext rq, Binding cmisBinding, String version, String cmisOperation) throws IOException
{
    RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), cmisBinding, version, cmisOperation, null);
    String url = endpoint.getUrl();

    OptionsMethod req = new OptionsMethod(url.toString());
    return submitRequest(req, rq);
}
项目:development    文件:ResponseHandlerFactory.java   
/**
 * Checks the method being received and created a 
 * suitable ResponseHandler for this method.
 * 
 * @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;
}
项目:Tank    文件:TankHttpClient3.java   
@Override
public void doOptions(BaseRequest request) {
    OptionsMethod httpoptions = new OptionsMethod(request.getRequestUrl());
    // Multiple calls can be expensive, so get it once
    String requestBody = request.getBody();
    String type = request.getHeaderInformation().get("Content-Type");
    if (StringUtils.isBlank(type)) {
        request.getHeaderInformation().put("Content-Type", "application/json");
    }
    sendRequest(request, httpoptions, requestBody);
}
项目:ShoppingMall    文件:CommonsClientHttpRequestFactory.java   
/**
 * Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
 * @param httpMethod the HTTP method
 * @param uri the URI
 * @return the Commons HttpMethodBase object
 */
protected HttpMethodBase createCommonsHttpMethod(HttpMethod httpMethod, String uri) {
    switch (httpMethod) {
        case GET:
            return new GetMethod(uri);
        case DELETE:
            return new DeleteMethod(uri);
        case HEAD:
            return new HeadMethod(uri);
        case OPTIONS:
            return new OptionsMethod(uri);
        case POST:
            return new PostMethod(uri);
        case PUT:
            return new PutMethod(uri);
        case TRACE:
            return new TraceMethod(uri);
        default:
            throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
    }
}
项目:community-edition-old    文件:PublicApiHttpClient.java   
public HttpResponse options(final RequestContext rq, Binding cmisBinding, String version, String cmisOperation) throws IOException
{
    RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), cmisBinding, version, cmisOperation, null);
    String url = endpoint.getUrl();

    OptionsMethod req = new OptionsMethod(url.toString());
    return submitRequest(req, rq);
}
项目:J2EP    文件:AllowHeaderTest.java   
public void testSetAllowed() {
    String allow = "OPTIONS,PROPFIND,OP,PUT";
    AllowedMethodHandler.setAllowedMethods(allow);
    assertEquals("Checking that allow is set", allow, AllowedMethodHandler.getAllowHeader());

    assertTrue("Checking that OPTIONS is allowed", AllowedMethodHandler.methodAllowed("OPTIONS"));
    assertTrue("Checking that PROPFIND is allowed", AllowedMethodHandler.methodAllowed("PROPFIND"));
    assertTrue("Checking that OP is allowed", AllowedMethodHandler.methodAllowed("OP"));
    assertTrue("Checking that PUT is allowed", AllowedMethodHandler.methodAllowed("PUT"));
    assertFalse("Checking that PROP isn't allowed", AllowedMethodHandler.methodAllowed("PROP"));

    assertTrue("Checking OPTIONS method", AllowedMethodHandler.methodAllowed(new OptionsMethod()));
    assertFalse("Checking GET method", AllowedMethodHandler.methodAllowed(new GetMethod()));
}
项目:j2ep    文件:AllowHeaderTest.java   
public void testSetAllowed() {
    String allow = "OPTIONS,PROPFIND,OP,PUT";
    AllowedMethodHandler.setAllowedMethods(allow);
    assertEquals("Checking that allow is set", allow, AllowedMethodHandler.getAllowHeader());

    assertTrue("Checking that OPTIONS is allowed", AllowedMethodHandler.methodAllowed("OPTIONS"));
    assertTrue("Checking that PROPFIND is allowed", AllowedMethodHandler.methodAllowed("PROPFIND"));
    assertTrue("Checking that OP is allowed", AllowedMethodHandler.methodAllowed("OP"));
    assertTrue("Checking that PUT is allowed", AllowedMethodHandler.methodAllowed("PUT"));
    assertFalse("Checking that PROP isn't allowed", AllowedMethodHandler.methodAllowed("PROP"));

    assertTrue("Checking OPTIONS method", AllowedMethodHandler.methodAllowed(new OptionsMethod()));
    assertFalse("Checking GET method", AllowedMethodHandler.methodAllowed(new GetMethod()));
}
项目:flex-blazeds    文件:ResponseFilter.java   
protected void setupResponse(ProxyContext context)
{
    String method = context.getMethod();
    HttpMethodBase httpMethod = context.getHttpMethod();
    if (MessageIOConstants.METHOD_POST.equals(method))
    {
        writeResponse(context);
    }
    else if (ProxyConstants.METHOD_GET.equals(method))
    {
        writeResponse(context);
    }
    else if (ProxyConstants.METHOD_OPTIONS.equals(method))
    {
        OptionsMethod optionsMethod = (OptionsMethod)httpMethod;
        Enumeration options = optionsMethod.getAllowedMethods();
        if (options != null)
        {
            List ops = new ArrayList();
            while (options.hasMoreElements())
            {
                Object option = options.nextElement();
                ops.add(option);
            }
            Object[] o = ops.toArray();
            context.setResponse(o);
        }
    }
    else if (ProxyConstants.METHOD_TRACE.equals(method))
    {
        writeResponse(context);
    }
    else if (ProxyConstants.METHOD_DELETE.equals(method))
    {
        writeResponse(context);
    }
    else if (ProxyConstants.METHOD_HEAD.equals(method))
    {
        context.setResponse(context.getResponseHeaders());
    }
    else if (ProxyConstants.METHOD_PUT.equals(method))
    {
        writeResponse(context);
    }
}
项目:oscm    文件:OptionsResponseHandler.java   
/**
 * Constructor checking if we should handle the Allow header
 * ourself or respond with the backing servers header.
 * 
 * @param method The method for this response
 */
public OptionsResponseHandler(OptionsMethod method) {
    super(method);
    useOwnAllow = !method.hasBeenUsed();
}
项目:development    文件:OptionsResponseHandler.java   
/**
 * Constructor checking if we should handle the Allow header
 * ourself or respond with the backing servers header.
 * 
 * @param method The method for this response
 */
public OptionsResponseHandler(OptionsMethod method) {
    super(method);
    useOwnAllow = !method.hasBeenUsed();
}
项目:J2EP    文件:OptionsResponseHandler.java   
/**
 * Constructor checking if we should handle the Allow header
 * ourself or respond with the backing servers header.
 * 
 * @param method The method for this response
 */
public OptionsResponseHandler(OptionsMethod method) {
    super(method);
    useOwnAllow = !method.hasBeenUsed();
}
项目:j2ep    文件:OptionsResponseHandler.java   
/**
 * Constructor checking if we should handle the Allow header
 * ourself or respond with the backing servers header.
 * 
 * @param method The method for this response
 */
public OptionsResponseHandler(OptionsMethod method) {
    super(method);
    useOwnAllow = !method.hasBeenUsed();
}