List of usage examples for org.apache.http.client.methods HttpUriRequest getMethod
String getMethod();
From source file:com.uwindsor.elgg.project.http.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { boolean retry; Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (executionCount > maxRetries) { // Do not retry if over max retry count retry = false;/*w ww.j av a 2 s . c o m*/ } else if (exceptionBlacklist.contains(exception.getClass())) { // immediately cancel retry if the error is blacklisted retry = false; } else if (exceptionWhitelist.contains(exception.getClass())) { // immediately retry if error is whitelisted retry = true; } else if (!sent) { // for most other errors, retry only if request hasn't been fully sent yet retry = true; } else { // resend all idempotent requests HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); String requestType = currentReq.getMethod(); if (!requestType.equals("POST")) { retry = true; } else { // otherwise do not retry retry = false; } } if (retry) { SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { exception.printStackTrace(); } return retry; }
From source file:net.netheos.pcsapi.request.CResponse.java
public CResponse(HttpUriRequest request, HttpResponse response) { method = request.getMethod(); uri = request.getURI();//from w ww . ja v a2 s . com status = response.getStatusLine().getStatusCode(); entity = response.getEntity(); String tmp = null; if (entity != null && entity.getContentType() != null) { tmp = entity.getContentType().getValue(); } contentType = tmp; tmp = response.getStatusLine().getReasonPhrase(); if (tmp == null || tmp.isEmpty()) { tmp = "No reason specified"; } reason = tmp; headers = new Headers(response.getAllHeaders()); }
From source file:cn.caimatou.canting.utils.http.asynchttp.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { boolean retry = true; Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (executionCount > maxRetries) { // Do not retry if over max retry count retry = false;// www . j a v a 2 s . c om } else if (isInList(exceptionBlacklist, exception)) { // immediately cancel retry if the error is blacklisted retry = false; } else if (isInList(exceptionWhitelist, exception)) { // immediately retry if error is whitelisted retry = true; } else if (!sent) { // for most other errors, retry only if request hasn't been fully sent yet retry = true; } if (retry) { // resend all idempotent requests HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); String requestType = currentReq.getMethod(); retry = !requestType.equals("POST"); } if (retry) { SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { exception.printStackTrace(); } return retry; }
From source file:org.apache.hadoop.gateway.ha.dispatch.DefaultHaDispatchTest.java
@Test public void testConnectivityFailover() throws Exception { String serviceName = "OOZIE"; HaDescriptor descriptor = HaDescriptorFactory.createDescriptor(); descriptor.addServiceConfig(//from www. j a v a 2 s . c o m HaDescriptorFactory.createServiceConfig(serviceName, "true", "1", "1000", "2", "1000", null, null)); HaProvider provider = new DefaultHaProvider(descriptor); URI uri1 = new URI("http://unreachable-host"); URI uri2 = new URI("http://reachable-host"); ArrayList<String> urlList = new ArrayList<String>(); urlList.add(uri1.toString()); urlList.add(uri2.toString()); provider.addHaService(serviceName, urlList); FilterConfig filterConfig = EasyMock.createNiceMock(FilterConfig.class); ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class); EasyMock.expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes(); EasyMock.expect(servletContext.getAttribute(HaServletContextListener.PROVIDER_ATTRIBUTE_NAME)) .andReturn(provider).anyTimes(); BasicHttpParams params = new BasicHttpParams(); HttpUriRequest outboundRequest = EasyMock.createNiceMock(HttpRequestBase.class); EasyMock.expect(outboundRequest.getMethod()).andReturn("GET").anyTimes(); EasyMock.expect(outboundRequest.getURI()).andReturn(uri1).anyTimes(); EasyMock.expect(outboundRequest.getParams()).andReturn(params).anyTimes(); HttpServletRequest inboundRequest = EasyMock.createNiceMock(HttpServletRequest.class); EasyMock.expect(inboundRequest.getRequestURL()).andReturn(new StringBuffer(uri2.toString())).once(); EasyMock.expect(inboundRequest.getAttribute("dispatch.ha.failover.counter")).andReturn(new AtomicInteger(0)) .once(); EasyMock.expect(inboundRequest.getAttribute("dispatch.ha.failover.counter")).andReturn(new AtomicInteger(1)) .once(); HttpServletResponse outboundResponse = EasyMock.createNiceMock(HttpServletResponse.class); EasyMock.expect(outboundResponse.getOutputStream()) .andAnswer(new IAnswer<SynchronousServletOutputStreamAdapter>() { @Override public SynchronousServletOutputStreamAdapter answer() throws Throwable { return new SynchronousServletOutputStreamAdapter() { @Override public void write(int b) throws IOException { throw new IOException("unreachable-host"); } }; } }).once(); EasyMock.replay(filterConfig, servletContext, outboundRequest, inboundRequest, outboundResponse); Assert.assertEquals(uri1.toString(), provider.getActiveURL(serviceName)); DefaultHaDispatch dispatch = new DefaultHaDispatch(); dispatch.setHttpClient(new DefaultHttpClient()); dispatch.setHaProvider(provider); dispatch.setServiceRole(serviceName); dispatch.init(); long startTime = System.currentTimeMillis(); try { dispatch.executeRequest(outboundRequest, inboundRequest, outboundResponse); } catch (IOException e) { //this is expected after the failover limit is reached } long elapsedTime = System.currentTimeMillis() - startTime; Assert.assertEquals(uri2.toString(), provider.getActiveURL(serviceName)); //test to make sure the sleep took place Assert.assertTrue(elapsedTime > 1000); }
From source file:com.elephant.http.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { boolean retry = true; Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (executionCount > maxRetries) { // Do not retry if over max retry count retry = false;/*from w w w. j a v a 2 s . co m*/ } else if (isInList(exceptionBlacklist, exception)) { // immediately cancel retry if the error is blacklisted retry = false; } else if (isInList(exceptionWhitelist, exception)) { // immediately retry if error is whitelisted retry = true; } else if (!sent) { // for most other errors, retry only if request hasn't been fully // sent yet retry = true; } if (retry) { // resend all idempotent requests HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); String requestType = currentReq.getMethod(); retry = !requestType.equals("POST"); } if (retry) { SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { exception.printStackTrace(); } return retry; }
From source file:com.vmware.photon.controller.nsxclient.RestClientTest.java
@Test public void testSendGet() { ArgumentCaptor<HttpUriRequest> argumentCaptor = setup(RestClient.Method.GET, null); HttpUriRequest request = argumentCaptor.getValue(); assertNotNull(request);//from w ww . j a va2s.c om assertTrue(request.getMethod().equalsIgnoreCase(RestClient.Method.GET.toString())); assertEquals(request.getURI().toString(), target + path); }
From source file:com.vmware.photon.controller.nsxclient.RestClientTest.java
@Test public void testPerformDelete() { ArgumentCaptor<HttpUriRequest> argumentCaptor = setup(RestClient.Method.DELETE, null); HttpUriRequest request = argumentCaptor.getValue(); assertNotNull(request);//from w w w. j a v a 2 s. c om assertTrue(request.getMethod().equalsIgnoreCase(RestClient.Method.DELETE.toString())); assertEquals(request.getURI().toString(), target + path); }
From source file:org.metaeffekt.dcc.agent.DccRequestBuilderTest.java
@Test public void version() { HttpUriRequest request = builder.createRequest("version", null); assertCommonParts(request);//from w w w . j a v a 2 s . c om assertEquals("GET", request.getMethod()); assertEquals("/dcc/version", request.getURI().getPath()); }
From source file:org.metaeffekt.dcc.agent.DccRequestBuilderTest.java
@Test public void clean() { HttpUriRequest request = builder.createRequest("clean", "depId"); assertCommonParts(request);//from w ww. j a va 2 s . c o m assertEquals("PUT", request.getMethod()); assertEquals("/dcc/depId/clean", request.getURI().getPath()); }