List of usage examples for org.apache.http.client.methods HttpOptions HttpOptions
public HttpOptions(final String uri)
From source file:at.bitfire.davdroid.webdav.DavRedirectStrategyTest.java
public void testNonRedirection() throws Exception { HttpUriRequest request = new HttpOptions(TestConstants.roboHydra); HttpResponse response = httpClient.execute(request); assertFalse(strategy.isRedirected(request, response, null)); }
From source file:com.starbucks.apps.HttpUtils.java
public static HttpInvocationContext doOptions(String url) throws IOException { HttpUriRequest request = new HttpOptions(url); return invoke(request, null, null); }
From source file:com.woonoz.proxy.servlet.HttpOptionsRequestHandler.java
@Override protected HttpRequestBase createHttpRequestBase(URI targetUri) { return new HttpOptions(targetUri); }
From source file:com.servoy.extensions.plugins.http.OptionsRequest.java
public OptionsRequest(String url, DefaultHttpClient hc, IClientPluginAccess plugin) { super(url, hc, new HttpOptions(url), plugin); }
From source file:org.dojotoolkit.zazl.internal.XMLHttpRequestUtils.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static String xhrRequest(String shrDataString) { InputStream is = null;/*from w w w .jav a 2 s .c o m*/ String json = null; try { logger.logp(Level.FINER, XMLHttpRequestUtils.class.getName(), "xhrRequest", "shrDataString [" + shrDataString + "]"); Map<String, Object> xhrData = (Map<String, Object>) JSONParser.parse(new StringReader(shrDataString)); String url = (String) xhrData.get("url"); String method = (String) xhrData.get("method"); List headers = (List) xhrData.get("headers"); URL requestURL = createURL(url); URI uri = new URI(requestURL.toString()); HashMap httpMethods = new HashMap(7); httpMethods.put("DELETE", new HttpDelete(uri)); httpMethods.put("GET", new HttpGet(uri)); httpMethods.put("HEAD", new HttpHead(uri)); httpMethods.put("OPTIONS", new HttpOptions(uri)); httpMethods.put("POST", new HttpPost(uri)); httpMethods.put("PUT", new HttpPut(uri)); httpMethods.put("TRACE", new HttpTrace(uri)); HttpUriRequest request = (HttpUriRequest) httpMethods.get(method.toUpperCase()); if (request.equals(null)) { throw new Error("SYNTAX_ERR"); } for (Object header : headers) { StringTokenizer st = new StringTokenizer((String) header, ":"); String name = st.nextToken(); String value = st.nextToken(); request.addHeader(name, value); } HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(request); Map headerMap = new HashMap(); HeaderIterator headerIter = response.headerIterator(); while (headerIter.hasNext()) { Header header = headerIter.nextHeader(); headerMap.put(header.getName(), header.getValue()); } int status = response.getStatusLine().getStatusCode(); String statusText = response.getStatusLine().toString(); is = response.getEntity().getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; StringBuffer sb = new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line); sb.append('\n'); } Map m = new HashMap(); m.put("status", new Integer(status)); m.put("statusText", statusText); m.put("responseText", sb.toString()); m.put("headers", headerMap.toString()); StringWriter w = new StringWriter(); JSONSerializer.serialize(w, m); json = w.toString(); logger.logp(Level.FINER, XMLHttpRequestUtils.class.getName(), "xhrRequest", "json [" + json + "]"); } catch (Throwable e) { logger.logp(Level.SEVERE, XMLHttpRequestUtils.class.getName(), "xhrRequest", "Failed request for [" + shrDataString + "]", e); } finally { if (is != null) { try { is.close(); } catch (IOException e) { } } } return json; }
From source file:org.apache.vysper.xmpp.extension.xep0124.inttests.DefaultAllowedOriginIntegrationTest.java
@Test public void optionsAccessControlAllowOrigin() throws Exception { HttpResponse response = httpclient.execute(new HttpOptions(getServerUrl())); Assert.assertEquals(0, response.getHeaders("Access-Control-Allow-Origin").length); }
From source file:at.bitfire.davdroid.webdav.DavRedirectStrategyTest.java
public void testDefaultRedirection() throws Exception { final String newLocation = "/new-location"; HttpContext context = HttpClientContext.create(); HttpUriRequest request = new HttpOptions(TestConstants.roboHydra.resolve("redirect/301?to=" + newLocation)); HttpResponse response = httpClient.execute(request, context); assertTrue(strategy.isRedirected(request, response, context)); HttpUriRequest redirected = strategy.getRedirect(request, response, context); assertEquals(TestConstants.roboHydra.resolve(newLocation), redirected.getURI()); }
From source file:nl.surfnet.coin.selenium.CorsHeaderTestSelenium.java
@Test public void preflight() throws Exception { HttpClient client = new DefaultHttpClient(); HttpUriRequest req = new HttpOptions(getApiBaseUrl() + OS_URL); req.setHeader("Origin", "localhost"); client.execute(req, new ResponseHandler<Object>() { @Override// w w w .java 2 s . c o m public Object handleResponse(HttpResponse response) throws ClientProtocolException, IOException { assertThat("response header Access-Control-Allow-Methods should contain 'GET'", response.getFirstHeader("Access-Control-Allow-Methods").getValue(), containsString("GET")); assertThat("No content should be served on a preflight request", response.getEntity().getContentLength(), equalTo(0L)); return null; } }); }
From source file:com.rackspacecloud.blueflood.outputs.handlers.HttpOptionsHandlerIntegrationTest.java
@Test public void testHttpEventsQueryHandlerOptions() throws Exception { // test query .../events/getEvents for CORS support HttpOptions httpOptions = new HttpOptions(getQueryEventsURI(tenantId)); HttpResponse response = client.execute(httpOptions); assertCorsResponseHeaders(response, allowedOrigins, allowedHeaders, allowedMethods, allowedMaxAge); }