List of usage examples for org.apache.commons.httpclient.methods PostMethod PostMethod
public PostMethod(String paramString)
From source file:com.wandisco.s3hdfs.rewrite.redirect.Redirect.java
HttpMethod getHttpMethod(String scheme, String host, int port, String op, String userName, String uri, HTTP_METHOD method) {//from ww w . ja va 2s . co m if (!uri.startsWith(WEBHDFS_PREFIX)) uri = ADD_WEBHDFS(uri); String url = scheme + "://" + host + ":" + port + uri + "?user.name=" + userName + "&op=" + op; switch (method) { case GET: return new GetMethod(url); case PUT: return new PutMethod(url); case POST: return new PostMethod(url); case DELETE: return new DeleteMethod(url); case HEAD: return new HeadMethod(url); default: return null; } }
From source file:dk.dma.epd.common.prototype.shoreservice.RouteHttp.java
public void init(int timeout) { httpClient = new HttpClient(); method = new PostMethod(url); HttpConnectionManagerParams params = httpClient.getHttpConnectionManager().getParams(); // params.setSoTimeout(readTimeout); // params.setConnectionTimeout(connectionTimeout); params.setSoTimeout(timeout);/* w ww . j a va 2s .co m*/ params.setConnectionTimeout(timeout); method.setRequestHeader("User-Agent", USER_AGENT); method.setRequestHeader("Connection", "close"); method.addRequestHeader("Accept", "text/*"); method.addRequestHeader("Content-Type", "text/xml"); // TODO if compress response // method.addRequestHeader("Accept-Encoding", "gzip"); }
From source file:com.zimbra.cs.account.auth.HostedAuth.java
/** * zmprov md test.com zimbraAuthMech 'custom:hosted http://auth.customer.com:80' * //ww w . j a va2 s . co m * This custom auth module takes arguments in the following form: * {URL} [GET|POST - default is GET] [encryption method - defautl is plain] [auth protocol - default is imap] * e.g.: http://auth.customer.com:80 GET **/ public void authenticate(Account acct, String password, Map<String, Object> context, List<String> args) throws Exception { HttpClient client = ZimbraHttpConnectionManager.getExternalHttpConnMgr().newHttpClient(); HttpMethod method = null; String targetURL = args.get(0); /* if (args.size()>2) { authMethod = args.get(2); } if (args.size()>3) { authMethod = args.get(3); }*/ if (args.size() > 1) { if (args.get(1).equalsIgnoreCase("GET")) method = new GetMethod(targetURL); else method = new PostMethod(targetURL); } else method = new GetMethod(targetURL); if (context.get(AuthContext.AC_ORIGINATING_CLIENT_IP) != null) method.addRequestHeader(HEADER_CLIENT_IP, context.get(AuthContext.AC_ORIGINATING_CLIENT_IP).toString()); if (context.get(AuthContext.AC_REMOTE_IP) != null) method.addRequestHeader(HEADER_X_ZIMBRA_REMOTE_ADDR, context.get(AuthContext.AC_REMOTE_IP).toString()); method.addRequestHeader(HEADER_AUTH_USER, acct.getName()); method.addRequestHeader(HEADER_AUTH_PASSWORD, password); AuthContext.Protocol proto = (AuthContext.Protocol) context.get(AuthContext.AC_PROTOCOL); if (proto != null) method.addRequestHeader(HEADER_AUTH_PROTOCOL, proto.toString()); if (context.get(AuthContext.AC_USER_AGENT) != null) method.addRequestHeader(HEADER_AUTH_USER_AGENT, context.get(AuthContext.AC_USER_AGENT).toString()); try { HttpClientUtil.executeMethod(client, method); } catch (HttpException ex) { throw AuthFailedServiceException.AUTH_FAILED(acct.getName(), acct.getName(), "HTTP request to remote authentication server failed", ex); } catch (IOException ex) { throw AuthFailedServiceException.AUTH_FAILED(acct.getName(), acct.getName(), "HTTP request to remote authentication server failed", ex); } finally { if (method != null) method.releaseConnection(); } int status = method.getStatusCode(); if (status != HttpStatus.SC_OK) { throw AuthFailedServiceException.AUTH_FAILED(acct.getName(), "HTTP request to remote authentication server failed. Remote response code: " + Integer.toString(status)); } String responseMessage; if (method.getResponseHeader(HEADER_AUTH_STATUS) != null) { responseMessage = method.getResponseHeader(HEADER_AUTH_STATUS).getValue(); } else { throw AuthFailedServiceException.AUTH_FAILED(acct.getName(), "Empty response from remote authentication server."); } if (responseMessage.equalsIgnoreCase(AUTH_STATUS_OK)) { return; } else { throw AuthFailedServiceException.AUTH_FAILED(acct.getName(), responseMessage); } }
From source file:com.zimbra.cs.store.triton.TritonIncomingOutputStream.java
private void sendHttpData() throws IOException { HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient(); PostMethod post;/*from ww w .jav a 2 s . co m*/ boolean started = false; if (uploadUrl.isInitialized()) { started = true; post = new PostMethod(baseUrl + uploadUrl); } else { post = new PostMethod(baseUrl + "/blob"); } try { ZimbraLog.store.info("posting to %s", post.getURI()); HttpClientUtil.addInputStreamToHttpMethod(post, new ByteArrayInputStream(baos.toByteArray()), baos.size(), "application/octet-stream"); post.addRequestHeader(TritonHeaders.CONTENT_LENGTH, baos.size() + ""); post.addRequestHeader(TritonHeaders.HASH_TYPE, hashType.toString()); post.addRequestHeader("Content-Range", "bytes " + written.longValue() + "-" + (written.longValue() + baos.size() - 1) + "/*"); if (serverToken.getToken() != null) { post.addRequestHeader(TritonHeaders.SERVER_TOKEN, serverToken.getToken()); } int statusCode = HttpClientUtil.executeMethod(client, post); if (statusCode == HttpStatus.SC_OK) { handleResponse(post); } else if (!started && statusCode == HttpStatus.SC_SEE_OTHER) { started = true; uploadUrl.setUploadUrl(post.getResponseHeader(TritonHeaders.LOCATION).getValue()); handleResponse(post); } else { throw new IOException("Unable to append, bad response code " + statusCode); } } finally { post.releaseConnection(); } baos = new ByteArrayOutputStream(LC.triton_upload_buffer_size.intValue()); }
From source file:br.org.acessobrasil.silvinha.autenticador.AutenticadorConector.java
public boolean autenticarLogin(Login login) { boolean autenticado = false; HttpClient client = new HttpClient(); PostMethod method = new PostMethod(url); NameValuePair x1 = new NameValuePair("x1", login.getUser()); NameValuePair x2 = new NameValuePair("x2", login.getPass()); method.setRequestBody(new NameValuePair[] { x1, x2 }); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); try {/* ww w . ja v a 2s . co m*/ int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { log.error("Method failed: " + method.getStatusLine()); } // Read the response body. byte[] responseBody = method.getResponseBody(); String rb = new String(responseBody).trim(); // Deal with the response. if (rb.startsWith("OK")) { autenticado = true; String[] rbLines = rb.split("\n"); Token.setUrl(rbLines[1]); } } catch (HttpException he) { log.error("Fatal protocol violation: " + he.getMessage(), he); } catch (IOException ioe) { log.error("Fatal transport error: " + ioe.getMessage(), ioe); } finally { /* * Release the connection. */ method.releaseConnection(); } return autenticado; }
From source file:com.apatar.core.ApatarHttpClient.java
public String sendPostHttpQuery(String url, HashMap<String, String> params) throws IOException { int size = params.size(); Part[] parts = new Part[size]; int i = 0;/*from w w w. j a v a 2 s . c om*/ for (String param : params.keySet()) { parts[i++] = new StringPart(param, params.get(param)); } PostMethod method = new PostMethod(url); method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams())); return sendHttpQuery(method); }
From source file:com.voa.weixin.task.UpdateFileTask.java
@Override public void run() { logger.debug("updatefile url :" + this.url); generateUrl();//from ww w . jav a2s .c o m PostMethod filePost = new PostMethod(url); try { Part[] parts = { new FilePart(updateFile.getName(), updateFile) }; filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); int status = client.executeMethod(filePost); WeixinResult result = new WeixinResult(); if (status == 200) { String responseStr = filePost.getResponseBodyAsString(); logger.debug(responseStr); result.setJson(responseStr); } else { result.setErrMsg("uplaod file weixin request error , http status : " + status); } callbackWork(result); } catch (Exception e) { e.printStackTrace(LogUtil.getErrorStream(logger)); throw new WorkException("update file error.", e); } finally { filePost.releaseConnection(); } }
From source file:es.carebear.rightmanagement.client.RestClient.java
public void authTest() throws IOException { HttpClient client = new HttpClient(); PostMethod deleteMethod = new PostMethod(getServiceBaseURI() + "/client/users/change/allowed/" + "Paul"); deleteMethod.addParameter("authName", "Admin"); deleteMethod.addParameter("rigthTarget", "User"); deleteMethod.addParameter("rightMask", "DELETE"); int responseCode = client.executeMethod(deleteMethod); System.out.println(responseCode); }
From source file:net.mumie.cocoon.msg.AbstractPostMessage.java
/** * Sends this message./*from w w w. ja v a 2s . co m*/ */ public boolean send() { final String METHOD_NAME = "send"; this.logDebug(METHOD_NAME + " 1/3: Started"); boolean success = true; MessageDestinationTable destinationTable = null; SimpleHttpClient httpClient = null; try { // Init services: destinationTable = (MessageDestinationTable) this.serviceManager.lookup(MessageDestinationTable.ROLE); httpClient = (SimpleHttpClient) this.serviceManager.lookup(SimpleHttpClient.ROLE); // Get destination: MessageDestination destination = destinationTable.getDestination(this.destinationName); // Create and setup a Http Post method object: PostMethod method = new PostMethod(destination.getURL()); DefaultMethodRetryHandler retryHandler = new DefaultMethodRetryHandler(); retryHandler.setRequestSentRetryEnabled(false); retryHandler.setRetryCount(3); method.setMethodRetryHandler(retryHandler); // Set login name and password: method.addParameter("name", destination.getLoginName()); method.addParameter("password", destination.getPassword()); // Specific setup: this.init(method, destination); // Execute method: try { if (httpClient.executeMethod(method) != HttpStatus.SC_OK) { this.logError(METHOD_NAME + ": Failed to send message: " + method.getStatusLine()); success = false; } String response = new String(method.getResponseBody()); if (response.trim().startsWith("ERROR")) { this.logError(METHOD_NAME + ": Failed to send message: " + response); success = false; } this.logDebug(METHOD_NAME + " 2/3: response = " + response); } finally { method.releaseConnection(); } } catch (Exception exception) { this.logError(METHOD_NAME, exception); success = false; } finally { if (httpClient != null) this.serviceManager.release(httpClient); if (destinationTable != null) this.serviceManager.release(destinationTable); } this.logDebug(METHOD_NAME + " 3/3: Done. success = " + success); return success; }
From source file:de.bermuda.arquillian.example.ContentTypeProxyTest.java
private PostMethod postRequest(String body, String localPath) { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod(BASE_URL + "/proxy" + localPath); try {// w w w . j av a2 s .c o m StringRequestEntity entity = new StringRequestEntity(body, "application/soap+xml", "UTF-8"); postMethod.setRequestEntity(entity); } catch (IOException e) { Assert.assertTrue("Catched IOException", false); } try { int status = client.executeMethod(postMethod); Assert.assertEquals("Expected OK", status, HttpStatus.SC_OK); } catch (HttpException e) { Assert.assertFalse("HttpException", true); } catch (IOException e) { Assert.assertFalse("IOException", true); } return postMethod; }