Search in sources :

Example 1 with OptionsMethod

use of org.apache.commons.httpclient.methods.OptionsMethod in project lobcder by skoulouzis.

the class WebDAVTest method testOptions.

// http://greenbytes.de/tech/webdav/rfc5842.html#rfc.section.8.1
@Test
public void testOptions() throws HttpException, IOException {
    OptionsMethod options = new OptionsMethod(uri.toASCIIString());
    int status = client.executeMethod(options);
    assertEquals(HttpStatus.SC_OK, status);
    // List allow = Arrays.asList(options.getAllowedMethods());
    Enumeration allowedMethods = options.getAllowedMethods();
    ArrayList<String> allow = new ArrayList<String>();
    while (allowedMethods.hasMoreElements()) {
        String method = (String) allowedMethods.nextElement();
        System.out.println("Allowed Methods: " + method);
        allow.add(method);
    }
    /*
         * The BIND method for is creating multiple bindings to the same
         * resource. Creating a new binding to a resource causes at least one
         * new URI to be mapped to that resource. Servers are required to ensure
         * the integrity of any bindings that they allow to be created. Milton
         * dosn't support that yet
         */
    // assertTrue("DAV header should include 'bind' feature", options.hasComplianceClass("bind"));
    // assertTrue("Allow header should include BIND method", allow.contains("BIND"));
    // assertTrue("Allow header should include REBIND method", allow.contains("REBIND"));
    // assertTrue("Allow header should include UNBIND method", allow.contains("UNBIND"));
    assertTrue("Allow header should include COPY method", allow.contains("COPY"));
    assertTrue("Allow header should include DELETE method", allow.contains("DELETE"));
    assertTrue("Allow header should include MKCOL method", allow.contains("MKCOL"));
    assertTrue("Allow header should include PROPFIND method", allow.contains("PROPFIND"));
    assertTrue("Allow header should include GET method", allow.contains("GET"));
    assertTrue("Allow header should include HEAD method", allow.contains("HEAD"));
    assertTrue("Allow header should include PROPPATCH method", allow.contains("PROPPATCH"));
    assertTrue("Allow header should include OPTIONS method", allow.contains("OPTIONS"));
    assertTrue("Allow header should include MOVE method", allow.contains("MOVE"));
    assertTrue("Allow header should include PUT method", allow.contains("PUT"));
    assertTrue("Allow header should include POST method", allow.contains("POST"));
    assertTrue("Allow header should include UNLOCK method", allow.contains("UNLOCK"));
    assertTrue("Allow header should include LOCK method", allow.contains("LOCK"));
}
Also used : OptionsMethod(org.apache.commons.httpclient.methods.OptionsMethod) Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with OptionsMethod

use of org.apache.commons.httpclient.methods.OptionsMethod in project fabric8 by jboss-fuse.

the class ProxyServlet method doOptions.

@Override
protected void doOptions(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
    ProxyDetails proxyDetails = createProxyDetails(httpServletRequest, httpServletResponse);
    if (!proxyDetails.isValid()) {
        noMappingFound(httpServletRequest, httpServletResponse);
    } else {
        OptionsMethod optionsMethodProxyRequest = new OptionsMethod(proxyDetails.getStringProxyURL());
        setProxyRequestHeaders(proxyDetails, httpServletRequest, optionsMethodProxyRequest);
        executeProxyRequest(proxyDetails, optionsMethodProxyRequest, httpServletRequest, httpServletResponse);
    }
}
Also used : OptionsMethod(org.apache.commons.httpclient.methods.OptionsMethod)

Example 3 with OptionsMethod

use of org.apache.commons.httpclient.methods.OptionsMethod in project jaggery by wso2.

the class XMLHttpRequestHostObject method send.

private void send(Context cx, Object obj) throws ScriptException {
    final HttpMethodBase method;
    if ("GET".equalsIgnoreCase(methodName)) {
        method = new GetMethod(this.url);
    } else if ("HEAD".equalsIgnoreCase(methodName)) {
        method = new HeadMethod(this.url);
    } else if ("POST".equalsIgnoreCase(methodName)) {
        PostMethod post = new PostMethod(this.url);
        if (obj instanceof FormDataHostObject) {
            FormDataHostObject fd = ((FormDataHostObject) obj);
            List<Part> parts = new ArrayList<Part>();
            for (Map.Entry<String, String> entry : fd) {
                parts.add(new StringPart(entry.getKey(), entry.getValue()));
            }
            post.setRequestEntity(new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), post.getParams()));
        } else {
            String content = getRequestContent(obj);
            if (content != null) {
                post.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(content.getBytes())));
            }
        }
        method = post;
    } else if ("PUT".equalsIgnoreCase(methodName)) {
        PutMethod put = new PutMethod(this.url);
        String content = getRequestContent(obj);
        if (content != null) {
            put.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(content.getBytes())));
        }
        method = put;
    } else if ("DELETE".equalsIgnoreCase(methodName)) {
        method = new DeleteMethod(this.url);
    } else if ("TRACE".equalsIgnoreCase(methodName)) {
        method = new TraceMethod(this.url);
    } else if ("OPTIONS".equalsIgnoreCase(methodName)) {
        method = new OptionsMethod(this.url);
    } else {
        throw new ScriptException("Unknown HTTP method : " + methodName);
    }
    for (Header header : requestHeaders) {
        method.addRequestHeader(header);
    }
    if (username != null) {
        httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
    }
    this.method = method;
    final XMLHttpRequestHostObject xhr = this;
    if (async) {
        updateReadyState(cx, xhr, LOADING);
        final ContextFactory factory = cx.getFactory();
        final ExecutorService es = Executors.newSingleThreadExecutor();
        es.submit(new Callable() {

            public Object call() throws Exception {
                Context ctx = RhinoEngine.enterContext(factory);
                try {
                    executeRequest(ctx, xhr);
                } catch (ScriptException e) {
                    log.error(e.getMessage(), e);
                } finally {
                    es.shutdown();
                    RhinoEngine.exitContext();
                }
                return null;
            }
        });
    } else {
        executeRequest(cx, xhr);
    }
}
Also used : InputStreamRequestEntity(org.apache.commons.httpclient.methods.InputStreamRequestEntity) PostMethod(org.apache.commons.httpclient.methods.PostMethod) ArrayList(java.util.ArrayList) StringPart(org.apache.commons.httpclient.methods.multipart.StringPart) Callable(java.util.concurrent.Callable) ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) HeadMethod(org.apache.commons.httpclient.methods.HeadMethod) OptionsMethod(org.apache.commons.httpclient.methods.OptionsMethod) Context(org.mozilla.javascript.Context) DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) HttpMethodBase(org.apache.commons.httpclient.HttpMethodBase) TraceMethod(org.apache.commons.httpclient.methods.TraceMethod) MultipartRequestEntity(org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity) IOException(java.io.IOException) ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) ContextFactory(org.mozilla.javascript.ContextFactory) Header(org.apache.commons.httpclient.Header) ByteArrayInputStream(java.io.ByteArrayInputStream) StringPart(org.apache.commons.httpclient.methods.multipart.StringPart) Part(org.apache.commons.httpclient.methods.multipart.Part) GetMethod(org.apache.commons.httpclient.methods.GetMethod) ExecutorService(java.util.concurrent.ExecutorService) PutMethod(org.apache.commons.httpclient.methods.PutMethod) ScriptableObject(org.mozilla.javascript.ScriptableObject) Map(java.util.Map)

Example 4 with OptionsMethod

use of org.apache.commons.httpclient.methods.OptionsMethod in project openmeetings by apache.

the class AppointmentManager method testConnection.

/**
 * Tests if the Calendar's URL can be accessed, or not.
 *
 * @param client   Client which makes the connection.
 * @param calendar Calendar whose URL is to be accessed.
 * @return Returns true for HTTP Status 200, or 204, else false.
 */
public boolean testConnection(HttpClient client, OmCalendar calendar) {
    cleanupIdleConnections();
    OptionsMethod optionsMethod = null;
    try {
        String path = getPathfromCalendar(client, calendar);
        optionsMethod = new OptionsMethod(path);
        optionsMethod.setRequestHeader("Accept", "*/*");
        client.executeMethod(optionsMethod);
        int status = optionsMethod.getStatusCode();
        if (status == SC_OK || status == SC_NO_CONTENT) {
            return true;
        }
    } catch (IOException e) {
        log.error("Error executing OptionsMethod during testConnection.", e);
    } catch (Exception e) {
        // Should not ever reach here.
        log.error("Severe Error in executing OptionsMethod during testConnection.", e);
    } finally {
        if (optionsMethod != null) {
            optionsMethod.releaseConnection();
        }
    }
    return false;
}
Also used : OptionsMethod(org.apache.commons.httpclient.methods.OptionsMethod) IOException(java.io.IOException) IOException(java.io.IOException)

Example 5 with OptionsMethod

use of org.apache.commons.httpclient.methods.OptionsMethod in project alfresco-remote-api by Alfresco.

the class PublicApiHttpClient method options.

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);
}
Also used : OptionsMethod(org.apache.commons.httpclient.methods.OptionsMethod)

Aggregations

OptionsMethod (org.apache.commons.httpclient.methods.OptionsMethod)5 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Enumeration (java.util.Enumeration)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 ExecutorService (java.util.concurrent.ExecutorService)1 Header (org.apache.commons.httpclient.Header)1 HttpMethodBase (org.apache.commons.httpclient.HttpMethodBase)1 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)1 DeleteMethod (org.apache.commons.httpclient.methods.DeleteMethod)1 GetMethod (org.apache.commons.httpclient.methods.GetMethod)1 HeadMethod (org.apache.commons.httpclient.methods.HeadMethod)1 InputStreamRequestEntity (org.apache.commons.httpclient.methods.InputStreamRequestEntity)1 PostMethod (org.apache.commons.httpclient.methods.PostMethod)1 PutMethod (org.apache.commons.httpclient.methods.PutMethod)1 TraceMethod (org.apache.commons.httpclient.methods.TraceMethod)1 MultipartRequestEntity (org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity)1 Part (org.apache.commons.httpclient.methods.multipart.Part)1