List of usage examples for org.apache.http.client.methods HttpRequestBase getURI
public URI getURI()
From source file:com.epam.ngb.cli.manager.command.handler.http.CommonHTTPCommandHandlerTest.java
@Test public void getRequestType() throws Exception { AbstractHTTPCommandHandler handler = createFileRegCommandHandler(serverParameters, COMMAND); String requestUrl = String.format(handler.getRequestUrl(), REF_ID); HttpRequestBase post = handler.getRequest(requestUrl); Assert.assertTrue(post instanceof HttpPost); Assert.assertEquals(serverParameters.getServerUrl() + requestUrl, post.getURI().toString()); }
From source file:com.thoughtworks.go.agent.service.TokenRequesterTest.java
@Test public void shouldGetTokenFromServer() throws Exception { final ArgumentCaptor<HttpRequestBase> argumentCaptor = ArgumentCaptor.forClass(HttpRequestBase.class); final CloseableHttpResponse httpResponse = mock(CloseableHttpResponse.class); when(agentRegistry.uuid()).thenReturn("agent-uuid"); when(httpClient.execute(any(HttpRequestBase.class))).thenReturn(httpResponse); when(httpResponse.getEntity()).thenReturn(new StringEntity("token-from-server")); when(httpResponse.getStatusLine())/*from w w w .j a v a 2s .c o m*/ .thenReturn(new BasicStatusLine(new ProtocolVersion("https", 1, 2), SC_OK, null)); final String token = tokenRequester.getToken(); verify(httpClient).execute(argumentCaptor.capture()); final HttpRequestBase requestBase = argumentCaptor.getValue(); final List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(requestBase.getURI(), StandardCharsets.UTF_8.name()); assertThat(token, is("token-from-server")); assertThat(findParam(nameValuePairs, "uuid").getValue(), is("agent-uuid")); }
From source file:com.ksc.http.apache.client.impl.ApacheDefaultHttpRequestFactoryTest.java
@Test public void uri_resourcepath_escapes_double_slash() throws IOException, URISyntaxException { final Request<Object> request = newDefaultRequest(HttpMethodName.GET); request.setResourcePath("//foo"); request.setEndpoint(new URI(ENDPOINT)); HttpRequestBase requestBase = requestFactory.create(request, settings); URI expectredUri = requestBase.getURI(); Assert.assertEquals("/%2Ffoo", expectredUri.getRawPath()); }
From source file:com.ksc.http.apache.client.impl.ApacheDefaultHttpRequestFactoryTest.java
@Test public void query_parameters_in_uri_for_all_non_post_requests() throws IOException, URISyntaxException { final Request<Object> request = newDefaultRequest(HttpMethodName.GET); request.withParameter("foo", "bar"); HttpRequestBase requestBase = requestFactory.create(request, settings); Assert.assertEquals("foo=bar", requestBase.getURI().getQuery()); }
From source file:com.machinepublishers.jbrowserdriver.CookieStore.java
public void addCsrfHeaders(Settings settings, HttpRequestBase req) { final String reqHost = canonicalHost(req.getURI().getHost()); final String reqPath = canonicalPath(req.getURI().getPath()); final boolean reqSecure = isSecure(req.getURI().getScheme()); List<Cookie> list;/* w w w .ja va 2 s.c o m*/ synchronized (store) { list = store.getCookies(); } String csrfToken = null; for (Cookie cookie : list) { if ((!cookie.isSecure() || reqSecure) && reqHost.endsWith(canonicalHost(cookie.getDomain())) && reqPath.startsWith(canonicalPath(cookie.getPath()))) { if (SettingsManager.settings().getCsrfResponseToken() != null && cookie.getName().equalsIgnoreCase(SettingsManager.settings().getCsrfResponseToken())) { csrfToken = cookie.getValue(); break; } } } if (csrfToken != null) { req.addHeader(SettingsManager.settings().getCsrfRequestToken(), csrfToken); } }
From source file:com.hpe.application.automation.tools.pc.MockPcRestProxyBadResponses.java
@Override protected HttpResponse executeRequest(HttpRequestBase request) throws PcException, ClientProtocolException, IOException { HttpResponse response = null;// ww w . ja v a2s . c om String requestUrl = request.getURI().toString(); if (requestUrl.equals( String.format(AUTHENTICATION_LOGIN_URL, PcTestBase.WEB_PROTOCOL, PcTestBase.PC_SERVER_NAME))) { throw new PcException(PcTestBase.pcAuthenticationFailureMessage); } else if (requestUrl.equals(String.format(getBaseURL() + "/%s", RUNS_RESOURCE_NAME))) { throw new PcException(PcTestBase.pcNoTimeslotExceptionMessage); } else if (requestUrl .equals(String.format(getBaseURL() + "/%s/%s", RUNS_RESOURCE_NAME, PcTestBase.RUN_ID_WAIT))) { response = getOkResponse(); response.setEntity( new StringEntity(PcTestBase.runResponseEntity.replace("*", runState.next().value()))); if (!runState.hasNext()) runState = initializeRunStateIterator(); } else if (requestUrl.equals(String.format(getBaseURL() + "/%s/%s/%s", RUNS_RESOURCE_NAME, PcTestBase.RUN_ID, RESULTS_RESOURCE_NAME))) { response = getOkResponse(); response.setEntity(new StringEntity(PcTestBase.emptyResultsEntity)); } else if (requestUrl.equals(String.format(getBaseURL() + "/%s/%s/%s", RUNS_RESOURCE_NAME, PcTestBase.RUN_ID, PcTestBase.STOP_MODE))) { throw new PcException(PcTestBase.pcStopNonExistRunFailureMessage); } if (response == null) throw new PcException( String.format("%s %s is not recognized by PC Rest Proxy", request.getMethod(), requestUrl)); return response; }
From source file:mobi.jenkinsci.ci.client.JenkinsHttpClient.java
public HttpResponse execute(final HttpRequestBase req) throws IOException { LOG.debug("Executing '" + req.getMethod() + " " + req.getURI() + "'"); if (!(httpClient instanceof JenkinsFormAuthHttpClient) && config.getUsername() != null && config.getUsername().trim().length() > 0) { ensurePreemptiveAuthRequest(req); }// ww w.j a v a 2 s .com HttpResponse response = httpContext == null ? httpClient.execute(req) : httpClient.execute(req, httpContext); if (response == null) { throw new IOException("Cannot contact URL " + req.getURI()); } final int responseStatus = response.getStatusLine().getStatusCode(); if ((responseStatus == HttpURLConnection.HTTP_UNAUTHORIZED || responseStatus == HttpURLConnection.HTTP_FORBIDDEN)) { req.releaseConnection(); httpClient = new JenkinsFormAuthHttpClient(httpClientFactory.getHttpClient(), config.getUrl(), config.getUsername(), config.getPassword(), req.getFirstHeader(Constants.X_AUTH_OTP_HEADER) != null ? req.getFirstHeader(Constants.X_AUTH_OTP_HEADER).getValue() : null); response = httpClient.execute(req); httpContext = null; } return elaborateResponse(response); }
From source file:com.github.mjeanroy.junit.servers.client.impl.apache_http_client.ApacheHttpRequestTest.java
@Override protected void checkQueryParam(HttpRequest httpRequest, String name, String value) throws Exception { Map<String, String> queryParams = extract(httpRequest, "queryParams"); assertThat(queryParams).contains(entry(name, value)); reset(client);/*w w w. ja v a2s . c om*/ when(client.execute(any(HttpRequestBase.class))).thenReturn(mock(CloseableHttpResponse.class)); httpRequest.execute(); ArgumentCaptor<HttpRequestBase> rqCaptor = ArgumentCaptor.forClass(HttpRequestBase.class); verify(client).execute(rqCaptor.capture()); HttpRequestBase rq = rqCaptor.getValue(); String uri = rq.getURI().toString(); assertThat(uri).matches("(.*)\\?(([a-z0-9]*)=(([a-z0-9]*))(&?))+").contains(name + "=" + value); }
From source file:com.threatconnect.sdk.conn.HttpRequestExecutor.java
/** * Execute an HTTP request and return the raw input stream. <i>Caller is responsible for closing InputStream.</i> * * @param path url to issue request to/*from www .ja va2 s . c o m*/ * @return raw input stream from response * @throws IOException On error */ @Override public InputStream executeDownloadByteStream(String path) throws IOException { if (this.conn.getConfig() == null) { throw new IllegalStateException("Can't execute HTTP request when configuration is undefined."); } InputStream stream = null; String fullPath = this.conn.getConfig().getTcApiUrl() + path.replace("/api/", "/"); logger.trace("Calling GET: " + fullPath); HttpRequestBase httpBase = getBase(fullPath, HttpMethod.GET); String headerPath = httpBase.getURI().getRawPath() + "?" + httpBase.getURI().getRawQuery(); ConnectionUtil.applyHeaders(this.conn.getConfig(), httpBase, httpBase.getMethod(), headerPath, conn.getConfig().getContentType(), ContentType.APPLICATION_OCTET_STREAM.toString()); logger.trace("Request: " + httpBase.getRequestLine()); logger.trace("Headers: " + Arrays.toString(httpBase.getAllHeaders())); CloseableHttpResponse response = this.conn.getApiClient().execute(httpBase); logger.trace(response.getStatusLine().toString()); HttpEntity entity = response.getEntity(); if (entity != null) { stream = entity.getContent(); logger.trace(String.format("Result stream size: %d, encoding: %s", entity.getContentLength(), entity.getContentEncoding())); } return stream; }
From source file:net.oauth.client.httpclient4.HttpMethodResponse.java
/** * Construct an OAuthMessage from the HTTP response, including parameters * from OAuth WWW-Authenticate headers and the body. The header parameters * come first, followed by the ones from the response body. *///from w ww . j av a2s. c o m public HttpMethodResponse(HttpRequestBase request, HttpResponse response, byte[] requestBody, String requestEncoding) throws IOException { super(request.getMethod(), new URL(request.getURI().toString())); this.httpRequest = request; this.httpResponse = response; this.requestBody = requestBody; this.requestEncoding = requestEncoding; this.headers.addAll(getHeaders()); }