@Override public HTTPResponse post( final URL url, final InputStream postContent, final String postContentType) throws IOException { PostMethod postMethod = new PostMethod(url.toExternalForm()); postMethod.setDoAuthentication(user != null && password != null); if (postContentType != null) { postMethod.setRequestHeader("Content-type", postContentType); } RequestEntity requestEntity = new InputStreamRequestEntity(postContent); postMethod.setRequestEntity(requestEntity); int responseCode = client.executeMethod(postMethod); if (200 != responseCode) { postMethod.releaseConnection(); throw new IOException( "Server returned HTTP error code " + responseCode + " for URL " + url.toExternalForm()); } return new HttpMethodResponse(postMethod); }
@Override public HTTPResponse post( final URL url, final InputStream postContent, final String postContentType) throws IOException { PostMethod postMethod = new PostMethod(url.toExternalForm()); postMethod.setDoAuthentication(user != null && password != null); if (tryGzip) { postMethod.setRequestHeader("Accept-Encoding", "gzip"); } if (postContentType != null) { postMethod.setRequestHeader("Content-type", postContentType); } RequestEntity requestEntity = new InputStreamRequestEntity(postContent); postMethod.setRequestEntity(requestEntity); int responseCode = executeMethod(postMethod); if (200 != responseCode) { postMethod.releaseConnection(); throw new IOException( "Server returned HTTP error code " + responseCode + " for URL " + url.toExternalForm()); } return new HttpMethodResponse(postMethod); }
public static boolean logout(ReviewboardConnection con, HttpClient http) { PostMethod post = new PostMethod(con.getReviewboardURL() + "api/json/accounts/logout/"); post.setDoAuthentication(true); try { int response = http.executeMethod(post); return response == 200; } catch (Exception e) { //ignore return false; } finally { post.releaseConnection(); } }
public String postXml(String url, String xmlEntiry) { PostMethod post = new PostMethod(url); try { post.setDoAuthentication(authEnabled); RequestEntity entity = new StringRequestEntity(xmlEntiry, null, null); post.setRequestEntity(entity); return execute(post); } catch (Exception e) { throw new RuntimeException(e); } finally { post.releaseConnection(); } }
@Override public HTTPResponse post( final URL url, final InputStream postContent, final String postContentType) throws IOException { PostMethod postMethod = new PostMethod(url.toExternalForm()); postMethod.setDoAuthentication(user != null && password != null); if (postContentType != null) { postMethod.setRequestHeader("Content-type", postContentType); } RequestEntity requestEntity = new InputStreamRequestEntity(postContent); postMethod.setRequestEntity(requestEntity); int responseCode = client.executeMethod(postMethod); if (200 != responseCode) { postMethod.releaseConnection(); throw new IOException( "Server returned HTTP error code " + responseCode + " for URL " + url.toExternalForm()); } return new HttpMethodResponse(postMethod); }
public String postXml(String url, String xmlEntiry) { PostMethod post = new PostMethod(url); try { post.setDoAuthentication(authEnabled); RequestEntity entity = new StringRequestEntity(xmlEntiry, null, null); post.setRequestEntity(entity); addHeader(post, headerMap); return execute(post); } catch (Exception e) { throw new RuntimeException(e); } finally { post.releaseConnection(); } }
public boolean postComment(ReviewboardConnection con, String url, String msg, boolean shipIt, boolean markdown) throws IOException { ensureAuthentication(con, http); String postUrl = con.buildApiUrl(url, "reviews"); PostMethod post = new PostMethod(postUrl); post.setDoAuthentication(true); NameValuePair[] data = { new NameValuePair("body_top", msg), new NameValuePair("public", "true"), new NameValuePair("ship_it", String.valueOf(shipIt)) }; if (markdown) { List<NameValuePair> l = new LinkedList<NameValuePair>(Arrays.asList(data)); l.add(new NameValuePair("body_top_text_type", "markdown")); l.add(new NameValuePair("text_type", "markdown")); //some Reviewboard versions require it data = l.toArray(new NameValuePair[l.size()]); } post.setRequestBody(data); int response; try { response = http.executeMethod(post); } finally { post.releaseConnection(); } return response == 200; }
throws AppFactoryException { PostMethod buildMethod = new PostMethod(buildUrl); buildMethod.setDoAuthentication(true); if (queryParameters != null) { buildMethod.setQueryString(queryParameters);
@Override public HTTPResponse post( final URL url, final InputStream postContent, final String postContentType) throws IOException { PostMethod postMethod = new PostMethod(url.toExternalForm()); postMethod.setDoAuthentication(user != null && password != null); if (tryGzip) { postMethod.setRequestHeader("Accept-Encoding", "gzip"); } if (postContentType != null) { postMethod.setRequestHeader("Content-type", postContentType); } RequestEntity requestEntity = new InputStreamRequestEntity(postContent); postMethod.setRequestEntity(requestEntity); int responseCode = executeMethod(postMethod); if (200 != responseCode) { postMethod.releaseConnection(); throw new IOException( "Server returned HTTP error code " + responseCode + " for URL " + url.toExternalForm()); } return new HttpMethodResponse(postMethod); }
httpClient.getState().setCredentials(new AuthScope(proxyServer, proxyPort), new UsernamePasswordCredentials(username, password)); httpPostMethod.setDoAuthentication(true);
post.setDoAuthentication(true); int responseCode = httpClient.executeMethod(post); final String responseBody;
post.setDoAuthentication(true); post.addParameter("os_username", confluence.getCredentials().username); post.addParameter("os_password", confluence.getCredentials().password);
@NotNull private static Map<String, URL> resolveUploadUrls(@NotNull final AgentRunningBuild build, @NotNull final Collection<String> s3ObjectKeys) throws IOException { BuildAgentConfiguration agentConfiguration = build.getAgentConfiguration(); String targetUrl = agentConfiguration.getServerUrl() + HTTP_AUTH + ARTEFACTS_S3_UPLOAD_PRESIGN_URLS_HTML; int connectionTimeout = agentConfiguration.getServerConnectionTimeout(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(build.getAccessUser(), build.getAccessCode()); HttpClient httpClient = HttpUtil.createHttpClient(connectionTimeout, new URL(targetUrl), credentials); PostMethod post = new PostMethod(targetUrl); post.addRequestHeader("User-Agent", "TeamCity Agent"); post.setRequestEntity(new StringRequestEntity(S3PreSignUrlHelper.writeS3ObjectKeys(s3ObjectKeys), APPLICATION_XML, UTF_8)); post.setDoAuthentication(true); int responseCode = httpClient.executeMethod(post); if (responseCode != 200) { LOG.debug("Failed resolving S3 pre-signed URL for build " + build.describe(false) + " . Response code " + responseCode); return Collections.emptyMap(); } return S3PreSignUrlHelper.readPreSignUrlMapping(post.getResponseBodyAsString()); }
post.setDoAuthentication(true); post.addParameter("os_username", confluence.getCredentials().username); post.addParameter("os_password", confluence.getCredentials().password);
private SAML2ResponseMessage sendAssertionRequest(UsernamePasswordCredential cred, String request, PostMethod method) throws ServiceException { String username = cred.getUsername(); String password = new String(cred.getPassword()); m_client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); m_client.getParams().setAuthenticationPreemptive(true); method.setDoAuthentication(true); try { method.setRequestEntity(new StringRequestEntity(request, "application/vnd.paos+xml", XML_CHARSET)); m_client.executeMethod(method); InputStream responseStream = method.getResponseBodyAsStream(); return SAML2ResponseMessage.createFromSOAPMessage(new InputStreamReader(responseStream, method .getResponseCharSet())); } catch (Exception e) { throw new ServiceException("Could not request SAML response", ServiceException.SERVICE_ERROR, e); } finally { method.releaseConnection(); } }
@Test public void testProvider1() throws Exception { HttpClient httpClient = new HttpClient(); Credentials credentials = new UsernamePasswordCredentials("admin1", "admin1"); httpClient.getState().setCredentials(AuthScope.ANY, credentials); httpClient.getParams().setAuthenticationPreemptive(true); PostMethod postMethod = new PostMethod("http://localhost:" + httpPort1.getNumber()); postMethod.setDoAuthentication(true); postMethod.setRequestEntity(new StringRequestEntity("hello", "text/html", "UTF-8")); assertEquals(HttpStatus.SC_OK, httpClient.executeMethod(postMethod)); assertEquals("hello", postMethod.getResponseBodyAsString()); credentials = new UsernamePasswordCredentials("asdf", "asdf"); httpClient.getState().setCredentials(AuthScope.ANY, credentials); assertEquals(HttpStatus.SC_UNAUTHORIZED, httpClient.executeMethod(postMethod)); credentials = new UsernamePasswordCredentials("admin2", "admin2"); httpClient.getState().setCredentials(AuthScope.ANY, credentials); assertEquals(HttpStatus.SC_UNAUTHORIZED, httpClient.executeMethod(postMethod)); }
@Test public void testProvider2() throws Exception { HttpClient httpClient = new HttpClient(); Credentials credentials = new UsernamePasswordCredentials("admin2", "admin2"); httpClient.getState().setCredentials(AuthScope.ANY, credentials); httpClient.getParams().setAuthenticationPreemptive(true); PostMethod postMethod = new PostMethod("http://localhost:" + httpPort2.getNumber()); postMethod.setDoAuthentication(true); postMethod.setRequestEntity(new StringRequestEntity("hello", "text/html", "UTF-8")); assertEquals(HttpStatus.SC_OK, httpClient.executeMethod(postMethod)); assertEquals("hello", postMethod.getResponseBodyAsString()); credentials = new UsernamePasswordCredentials("asdf", "asdf"); httpClient.getState().setCredentials(AuthScope.ANY, credentials); assertEquals(HttpStatus.SC_UNAUTHORIZED, httpClient.executeMethod(postMethod)); credentials = new UsernamePasswordCredentials("admin", "admin"); httpClient.getState().setCredentials(AuthScope.ANY, credentials); assertEquals(HttpStatus.SC_UNAUTHORIZED, httpClient.executeMethod(postMethod)); }
@Test public void testMultipleProviders() throws Exception { HttpClient httpClient = new HttpClient(); Credentials credentials = new UsernamePasswordCredentials("admin1", "admin1"); httpClient.getState().setCredentials(AuthScope.ANY, credentials); httpClient.getParams().setAuthenticationPreemptive(true); PostMethod postMethod = new PostMethod("http://localhost:" + httpPort3.getNumber()); postMethod.setDoAuthentication(true); postMethod.setRequestEntity(new StringRequestEntity("hello", "text/html", "UTF-8")); assertEquals(HttpStatus.SC_OK, httpClient.executeMethod(postMethod)); assertEquals("hello", postMethod.getResponseBodyAsString()); credentials = new UsernamePasswordCredentials("asdf", "asdf"); httpClient.getState().setCredentials(AuthScope.ANY, credentials); assertEquals(HttpStatus.SC_UNAUTHORIZED, httpClient.executeMethod(postMethod)); credentials = new UsernamePasswordCredentials("admin2", "admin2"); httpClient.getState().setCredentials(AuthScope.ANY, credentials); assertEquals(HttpStatus.SC_OK, httpClient.executeMethod(postMethod)); assertEquals("hello", postMethod.getResponseBodyAsString()); }