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"));
}
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);
}
}
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);
}
}
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;
}
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);
}
Aggregations