List of usage examples for org.apache.http.client.methods HttpRequestBase getURI
public URI getURI()
From source file:eionet.webq.xforms.XFormsHTTPRequestAuthHandlerImplTest.java
private void assertThatRequestIsNotChanged(HttpRequestBase httpRequest, String requestUri) { assertThat(httpRequest.getURI().toString(), startsWith(requestUri)); assertThat(httpRequest.getHeaders("Authorization").length, equalTo(0)); }
From source file:com.gsma.mobileconnect.impl.GetOperatorSelectionURLTest.java
@Test public void getOperatorSelectionURL_shouldCreateExpectedRequest() throws DiscoveryException, IOException, RestException { // GIVEN//from w ww .ja v a 2 s . co m RestClient mockedRestClient = mock(RestClient.class); final CaptureHttpRequestBase captureHttpRequestBase = new CaptureHttpRequestBase(); final RestResponse restResponse = new RestResponse("", 0, null, ""); TimeoutOptions options = new TimeoutOptions(); options.setTimeout(333); doAnswer(new Answer() { public Object answer(InvocationOnMock invocationOnMock) throws Throwable { Object[] args = invocationOnMock.getArguments(); HttpRequestBase requestBase = (HttpRequestBase) args[0]; captureHttpRequestBase.setValue(requestBase); return restResponse; } }).when(mockedRestClient).callRestEndPoint(any(HttpRequestBase.class), any(HttpClientContext.class), eq(options.getTimeout()), Matchers.<List<KeyValuePair>>any()); IDiscovery discovery = Factory.getDiscovery(null, mockedRestClient); Config config = new Config(); CaptureDiscoveryResponse captureDiscoveryResponse = new CaptureDiscoveryResponse(); String expectedURL = "http://discovery.sandbox.mobileconnect.io/v2/discovery?Manually-Select=true&Using-Mobile-Data=false&Redirect_URL=http%3A%2F%2Flocalhost%3A8080%2Fmobileconnect"; String expectedAccept = "application/json"; // WHEN discovery.getOperatorSelectionURL(config, Config.REDIRECT_URL, options, captureDiscoveryResponse); // THEN HttpRequestBase capturedRequest = captureHttpRequestBase.getValue(); assertEquals(expectedURL, capturedRequest.getURI().toString()); assertEquals(expectedAccept, capturedRequest.getFirstHeader("accept").getValue()); }
From source file:com.polydeucesys.eslogging.testutils.MockClosableHttpAsyncClient.java
public String getLastRequestContent() { String retval = ""; if (savedRequest instanceof HttpEntityEnclosingRequestBase) { HttpEntityEnclosingRequestBase lastPost = (HttpEntityEnclosingRequestBase) savedRequest; try {//from w w w . j ava 2 s. c o m retval = EntityUtils.toString(lastPost.getEntity(), StandardCharsets.UTF_8); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { HttpRequestBase rb = (HttpRequestBase) savedRequest; retval = rb.getURI().toASCIIString(); } return retval; }
From source file:org.commonjava.couch.io.CouchHttpClient.java
public void executeHttp(final HttpRequestBase request, final Integer expectedStatus, final Object failureMessage) throws CouchDBException { final String url = request.getURI().toString(); try {//from w w w. j a va 2s. co m final HttpResponse response = client.execute(request); final StatusLine statusLine = response.getStatusLine(); if (expectedStatus != null && statusLine.getStatusCode() != expectedStatus) { final HttpEntity entity = response.getEntity(); final CouchError error = serializer.toError(entity); throw new CouchDBException("%s: %s.\nHTTP Response: %s\nError: %s", failureMessage, url, statusLine, error); } } catch (final UnsupportedEncodingException e) { throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage()); } catch (final ClientProtocolException e) { throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage()); } catch (final IOException e) { throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage()); } finally { cleanup(request); } }
From source file:org.commonjava.couch.io.CouchHttpClient.java
public HttpResponse executeHttpWithResponse(final HttpRequestBase request, final Integer expectedStatus, final Object failureMessage) throws CouchDBException { final String url = request.getURI().toString(); boolean failed = false; try {//from ww w . j a v a2s. c o m final HttpResponse response = client.execute(request); final StatusLine statusLine = response.getStatusLine(); if (expectedStatus != null && statusLine.getStatusCode() != expectedStatus) { final HttpEntity entity = response.getEntity(); final CouchError error = serializer.toError(entity); throw new CouchDBException("%s: %s.\nHTTP Response: %s\nError: %s", failureMessage, url, statusLine, error); } return response; } catch (final UnsupportedEncodingException e) { failed = true; throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage()); } catch (final ClientProtocolException e) { failed = true; throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage()); } catch (final IOException e) { failed = true; throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage()); } finally { if (failed) { cleanup(request); } } }
From source file:org.fao.geonet.kernel.harvest.harvester.csw.CswHarvesterIntegrationTest.java
protected void mockHttpRequests(MockRequestFactoryGeonet bean) { final MockXmlRequest cswServerRequest = new MockXmlRequest(HOST, PORT, PROTOCOL); cswServerRequest.when(CAPABILITIES_URL).thenReturn(fileStream("capabilities.xml")); final String queryString = "?request=GetRecordById&service=CSW&version=2.0.2&outputSchema=" + getOutputSchema() + "&elementSetName=full&id="; cswServerRequest.when(REQUEST + queryString + "7e926fbf-00fb-4ff5-a99e-c8576027c4e7") .thenReturn(fileStream("GetRecordById-7e926fbf-00fb-4ff5-a99e-c8576027c4e7.xml")); cswServerRequest.when(REQUEST + queryString + "da165110-88fd-11da-a88f-000d939bc5d8") .thenReturn(fileStream("GetRecordById-da165110-88fd-11da-a88f-000d939bc5d8.xml")); cswServerRequest.when(new Predicate<HttpRequestBase>() { @Override/*from ww w . j a v a2 s .c o m*/ public boolean apply(@Nullable HttpRequestBase input) { final boolean isHttpPost = input instanceof HttpPost; final boolean correctPath = input.getURI().toString().startsWith(REQUEST); if (!correctPath) { return false; } String request, typeNames, elementSetName; final boolean noQueryFilter; if (isHttpPost) { final Element xml; try { xml = Xml.loadStream(((HttpPost) input).getEntity().getContent()); } catch (Throwable e) { return false; } request = xml.getName(); final Element queryEl = xml.getChild("Query", Csw.NAMESPACE_CSW); typeNames = queryEl.getAttributeValue("typeNames"); elementSetName = queryEl.getChild("ElementSetName", Csw.NAMESPACE_CSW).getText(); noQueryFilter = queryEl.getChildren().size() == 1; } else { final String[] params = input.getURI().getQuery().split("\\&"); Map<String, String> paramMap = Maps.newHashMap(); for (String param : params) { final String[] split = param.split("="); String key = split[0].toLowerCase(); String value = ""; if (split.length > 1) { value = split[1]; } paramMap.put(key, value); } request = paramMap.get("request"); typeNames = paramMap.get("typenames"); elementSetName = paramMap.get("elementsetname"); noQueryFilter = paramMap.get("query") == null || paramMap.get("query").isEmpty(); } final boolean isGetRecords = "GetRecords".equalsIgnoreCase(request); final boolean correctTypeNames = typeNames.contains("gmd:MD_Metadata") || typeNames.contains("csw:Record"); final boolean isSummary = elementSetName.equals("summary"); return isGetRecords && correctTypeNames && isSummary && noQueryFilter; } }).thenReturn(fileStream("getRecords.xml")); bean.registerRequest(true, HOST, PORT, PROTOCOL, cswServerRequest); bean.registerRequest(true, null, -1, PROTOCOL, cswServerRequest); }
From source file:org.artifactory.repo.remote.browse.S3RepositoryBrowserTest.java
@BeforeMethod public void beforeTestMethod() { HttpExecutor httpExecutor = new HttpExecutor() { @Override/*www .ja va 2 s . c o m*/ public CloseableHttpResponse executeMethod(HttpRequestBase method) throws IOException { log.info("Executing " + method.getURI() + " on dummy S3 repo!"); return client.execute(method); } }; s3Browser = new S3RepositoryBrowser(httpExecutor); }
From source file:org.commonjava.couch.io.CouchHttpClient.java
public <T> T executeHttpAndReturn(final HttpRequestBase request, final ResponseHandlerWithError<T> handler, final Object failureMessage) throws CouchDBException { final String url = request.getURI().toString(); try {/*from w w w. j a v a 2 s. c o m*/ final T result = client.execute(request, handler); if (result == null && handler.getError() != null) { throw handler.getError(); } return result; } catch (final UnsupportedEncodingException e) { throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage()); } catch (final ClientProtocolException e) { throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage()); } catch (final IOException e) { throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage()); } finally { cleanup(request); } }
From source file:org.wise.vle.domain.webservice.http.impl.HttpRestTransportImpl.java
private void logRequest(HttpRequestBase request, String bodyData) { if (logger.isInfoEnabled()) { logger.info(request.getMethod() + ": " + request.getURI()); if (bodyData != "") logger.info(request.getMethod() + ": " + bodyData); }/*from w w w. j av a2s .co m*/ }
From source file:org.plos.crepo.dao.ContentRepoBaseDao.java
protected CloseableHttpResponse executeRequest(HttpRequestBase request, ErrorType errorType) { CloseableHttpResponse response;/*from w w w . j a v a 2s . c o m*/ try { response = accessConfig.open(request); } catch (IOException e) { getLog().error("Error handling the response, uri: " + request.getURI().toString() + " repoMessage: ", e); throw new ContentRepoException.ContentRepoExceptionBuilder(errorType).baseException(e) .url(request.getURI().toString()).build(); } try { final int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_NOT_FOUND) { throw new NotFoundException(HttpResponseUtil.getErrorMessage(response)); } else if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED) { final String cause = HttpResponseUtil.getErrorMessage(response); getLog().error("uri: " + request.getURI().toString() + " repoMessage: " + cause); throw new ContentRepoException.ContentRepoExceptionBuilder(errorType) .url(request.getURI().toString()).repoMessage(cause).build(); } return response; } catch (RuntimeException e) { IOUtils.closeQuietly(response); request.releaseConnection(); throw e; } }