List of usage examples for org.apache.commons.httpclient.methods PostMethod FORM_URL_ENCODED_CONTENT_TYPE
String FORM_URL_ENCODED_CONTENT_TYPE
To view the source code for org.apache.commons.httpclient.methods PostMethod FORM_URL_ENCODED_CONTENT_TYPE.
Click Source Link
From source file:org.nunux.poc.portal.ProxyServlet.java
/** * Performs an HTTP POST request/*from w w w .j a v a 2 s .co m*/ * * @param httpServletRequest The {@link HttpServletRequest} object passed in * by the servlet engine representing the client request to be proxied * @param httpServletResponse The {@link HttpServletResponse} object by * which we can send a proxied response to the client */ @Override public void doPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException { // Create a standard POST request String contentType = httpServletRequest.getContentType(); String destinationUrl = this.getProxyURL(httpServletRequest); debug("POST Request URL: " + httpServletRequest.getRequestURL(), " Content Type: " + contentType, " Destination URL: " + destinationUrl); PostMethod postMethodProxyRequest = new PostMethod(destinationUrl); // Forward the request headers setProxyRequestHeaders(httpServletRequest, postMethodProxyRequest); setProxyRequestCookies(httpServletRequest, postMethodProxyRequest); // Check if this is a mulitpart (file upload) POST if (ServletFileUpload.isMultipartContent(httpServletRequest)) { this.handleMultipartPost(postMethodProxyRequest, httpServletRequest); } else { if (contentType == null || PostMethod.FORM_URL_ENCODED_CONTENT_TYPE.equals(contentType)) { this.handleStandardPost(postMethodProxyRequest, httpServletRequest); } else { this.handleContentPost(postMethodProxyRequest, httpServletRequest); } } // Execute the proxy request this.executeProxyRequest(postMethodProxyRequest, httpServletRequest, httpServletResponse); }
From source file:org.phenotips.integration.lims247.internal.DefaultLimsServer.java
@Override public boolean checkToken(String token, String username, String pn) { PostMethod method = null;// w w w . ja v a 2s .c o m try { String checkURL = getTokenCheckURL(pn, getXContext()); if (StringUtils.isNotBlank(checkURL)) { method = new PostMethod(checkURL); String body = String.format("%s=%s&%s=%s", USERNAME_KEY, URLEncoder.encode(username, XWiki.DEFAULT_ENCODING), TOKEN_KEY, URLEncoder.encode(token, XWiki.DEFAULT_ENCODING)); method.setRequestEntity(new StringRequestEntity(body, PostMethod.FORM_URL_ENCODED_CONTENT_TYPE, XWiki.DEFAULT_ENCODING)); this.client.executeMethod(method); String response; try { response = method.getResponseBodyAsString(128); } catch (HttpContentTooLargeException ex) { response = method.getResponseBodyAsString(); this.logger.warn("LIMS token check returned wrong response: {} - [{}]", ex.getMessage(), response); } JSONObject responseJSON = (JSONObject) JSONSerializer.toJSON(response); boolean success = responseJSON.getBoolean("success"); if (success) { this.logger.debug("Successfully authenticated user [{}] on LIMS instance [{}] using token [{}]", username, pn, token); return true; } else { this.logger.warn("Failed to authenticate user [{}] on LIMS instance [{}] using token [{}]", username, pn, token); } } } catch (Exception ex) { this.logger.warn("Failed to check LIMS authentication token [{}] on server [{}]: {}", token, pn, ex.getMessage(), ex); } finally { if (method != null) { method.releaseConnection(); } } return false; }
From source file:slash.navigation.rest.HttpRequest.java
public void setBody(String body) { try {// w w w .j a v a 2 s . c o m ((EntityEnclosingMethod) method).setRequestEntity( new StringRequestEntity(body, PostMethod.FORM_URL_ENCODED_CONTENT_TYPE, Helper.UTF8_ENCODING)); } catch (UnsupportedEncodingException e) { log.severe("Cannot set body: " + e.getMessage()); } }