List of usage examples for org.apache.commons.httpclient.methods OptionsMethod setFollowRedirects
@Override public void setFollowRedirects(boolean followRedirects)
From source file:com.sun.faban.driver.transport.hc3.ApacheHC3Transport.java
/** * Makes a OPTIONS request to the URL. Reads data back and returns the data * read. Note that this method only works with text data as it does the * byte-to-char conversion. This method will return null for responses * with binary MIME types. The addTextType(String) method is used to * register additional MIME types as text types. Use getContentSize() to * obtain the bytes of binary data read. * * @param url The URL to read from/* ww w . ja va 2 s. c o m*/ * @param headers The request headers, or null * @return The StringBuilder buffer containing the resulting document * @throws java.io.IOException */ public StringBuilder optionsURL(String url, Map<String, String> headers) throws IOException { OptionsMethod method = new OptionsMethod(url); method.setFollowRedirects(followRedirects); setHeaders(method, headers); try { responseCode = hc.executeMethod(method); buildResponseHeaders(method); return fetchResponse(method); } finally { method.releaseConnection(); } }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Execute OPTIONS method for the given path. * * @param path the server relative path of the resource to request * @return true if the method is succeeded. * @exception HttpException/*www .j a va 2 s. c o m*/ * @exception IOException * @see #getAllowedMethods() */ public boolean optionsMethod(String path) throws HttpException, IOException { setClient(); OptionsMethod method; if (path.trim().equals("*")) method = new OptionsMethod("*"); else method = new OptionsMethod(URIUtil.encodePath(path)); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); generateAdditionalHeaders(method); int statusCode = client.executeMethod(method); setStatusCode(statusCode); if (statusCode >= 200 && statusCode < 300) { // check if the specific method is possbile allowedMethods = method.getAllowedMethods(); // check WebDAV capabilities. davCapabilities = method.getDavCapabilities(); return true; } return false; }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Execute OPTIONS method for the given http URL. * * @param httpURL the http URL./* w w w. j a va2 s .co m*/ * @return the allowed methods and capabilities. * @exception HttpException * @exception IOException */ public Enumeration optionsMethod(HttpURL httpURL) throws HttpException, IOException { HttpClient client = getSessionInstance(httpURL, true); OptionsMethod method = new OptionsMethod(httpURL.getEscapedPath()); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); generateAdditionalHeaders(method); client.executeMethod(method); Vector options = new Vector(); int statusCode = method.getStatusLine().getStatusCode(); if (statusCode >= 200 && statusCode < 300) { // check if the specific method is possbile Enumeration allowedMethods = method.getAllowedMethods(); while (allowedMethods.hasMoreElements()) { options.addElement(allowedMethods.nextElement()); } // check WebDAV capabilities. Enumeration davCapabilities = method.getDavCapabilities(); while (davCapabilities.hasMoreElements()) { options.addElement(davCapabilities.nextElement()); } Enumeration responses = method.getResponses(); if (responses.hasMoreElements()) { ResponseEntity response = (ResponseEntity) responses.nextElement(); Enumeration workspaces = response.getWorkspaces(); String sResult = ""; while (workspaces.hasMoreElements()) { sResult += workspaces.nextElement().toString(); } Enumeration histories = response.getHistories(); while (histories.hasMoreElements()) { sResult += histories.nextElement().toString(); } // Set status code for this resource. if ((thisResource == true) && (response.getStatusCode() > 0)) setStatusCode(response.getStatusCode()); thisResource = false; options.addElement(sResult); } } return options.elements(); }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Execute OPTIONS method for the given http URL, DELTAV * * @param httpURL the http URL.//from w ww.j a v a 2s . c om * @return the allowed methods and capabilities. * @exception HttpException * @exception IOException */ public Enumeration optionsMethod(HttpURL httpURL, int type) throws HttpException, IOException { HttpClient client = getSessionInstance(httpURL, true); OptionsMethod method = new OptionsMethod(httpURL.getEscapedPath(), type); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); generateAdditionalHeaders(method); client.executeMethod(method); Vector options = new Vector(); int statusCode = method.getStatusLine().getStatusCode(); if (statusCode >= 200 && statusCode < 300) { Enumeration responses = method.getResponses(); if (responses.hasMoreElements()) { ResponseEntity response = (ResponseEntity) responses.nextElement(); // String sResult=""; if (type == OPTIONS_WORKSPACE) { Enumeration workspaces = response.getWorkspaces(); while (workspaces.hasMoreElements()) { options.add(workspaces.nextElement().toString()); } } else if (type == OPTIONS_VERSION_HISTORY) { Enumeration histories = response.getHistories(); while (histories.hasMoreElements()) { options.add(histories.nextElement().toString()); } } // Set status code for this resource. if ((thisResource == true) && (response.getStatusCode() > 0)) setStatusCode(response.getStatusCode()); thisResource = false; // options.addElement(sResult); } } return options.elements(); }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Execute OPTIONS method for the given path. * * @param path the server relative path of the resource to request * @return the allowed methods and capabilities. * @exception HttpException/*from w w w . j av a2 s. c om*/ * @exception IOException * @see #getAllowedMethods() */ public Enumeration optionsMethod(String path, int type) throws HttpException, IOException { setClient(); OptionsMethod method = new OptionsMethod(URIUtil.encodePath(path), type); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); generateAdditionalHeaders(method); client.executeMethod(method); Vector options = new Vector(); int statusCode = method.getStatusLine().getStatusCode(); if (statusCode >= 200 && statusCode < 300) { Enumeration responses = method.getResponses(); if (responses.hasMoreElements()) { ResponseEntity response = (ResponseEntity) responses.nextElement(); // String sResult=""; if (type == OPTIONS_WORKSPACE) { Enumeration workspaces = response.getWorkspaces(); while (workspaces.hasMoreElements()) { options.add(workspaces.nextElement().toString()); } } else if (type == OPTIONS_VERSION_HISTORY) { Enumeration histories = response.getHistories(); while (histories.hasMoreElements()) { options.add(histories.nextElement().toString()); } } // Set status code for this resource. if ((thisResource == true) && (response.getStatusCode() > 0)) setStatusCode(response.getStatusCode()); thisResource = false; // options.addElement(sResult); } } return options.elements(); }