List of usage examples for org.apache.commons.httpclient.methods PutMethod PutMethod
public PutMethod()
From source file:org.eclipse.swordfish.internal.resolver.backend.base.impl.HttpClientProxy.java
protected HttpMethod getMethod(Method method) { HttpMethod result = null;/*from ww w .j a v a 2 s . co m*/ if (method.equals(Method.GET)) { result = new GetMethod(); } else if (method.equals(Method.POST)) { result = new PostMethod(); } else if (method.equals(Method.DELETE)) { result = new DeleteMethod(); } else if (method.equals(Method.PUT)) { result = new PutMethod(); } return result; }
From source file:org.eclipse.swordfish.plugins.resolver.proxy.impl.HttpCilentProxy.java
private HttpMethodBase getMethod(Method method) { HttpMethodBase result = null;/*from ww w. j a v a 2 s. co m*/ if (method.equals(Method.GET)) { result = new GetMethod(); } else if (method.equals(Method.POST)) { result = new PostMethod(); } else if (method.equals(Method.DELETE)) { result = new DeleteMethod(); } else if (method.equals(Method.PUT)) { result = new PutMethod(); } return result; }
From source file:org.elasticsearch.hadoop.rest.commonshttp.CommonsHttpTransport.java
@Override public Response execute(Request request) throws IOException { HttpMethod http = null;// w w w. j a v a2s . c o m switch (request.method()) { case DELETE: http = new DeleteMethodWithBody(); break; case HEAD: http = new HeadMethod(); break; case GET: http = (request.body() == null ? new GetMethod() : new GetMethodWithBody()); break; case POST: http = new PostMethod(); break; case PUT: http = new PutMethod(); break; default: throw new EsHadoopTransportException("Unknown request method " + request.method()); } CharSequence uri = request.uri(); if (StringUtils.hasText(uri)) { http.setURI(new URI(escapeUri(uri.toString(), settings.getNetworkSSLEnabled()), false)); } // NB: initialize the path _after_ the URI otherwise the path gets reset to / http.setPath(prefixPath(request.path().toString())); try { // validate new URI uri = http.getURI().toString(); } catch (URIException uriex) { throw new EsHadoopTransportException("Invalid target URI " + request, uriex); } CharSequence params = request.params(); if (StringUtils.hasText(params)) { http.setQueryString(params.toString()); } ByteSequence ba = request.body(); if (ba != null && ba.length() > 0) { if (!(http instanceof EntityEnclosingMethod)) { throw new IllegalStateException(String.format("Method %s cannot contain body - implementation bug", request.method().name())); } EntityEnclosingMethod entityMethod = (EntityEnclosingMethod) http; entityMethod.setRequestEntity(new BytesArrayRequestEntity(ba)); entityMethod.setContentChunked(false); } // when tracing, log everything if (log.isTraceEnabled()) { log.trace(String.format("Tx %s[%s]@[%s][%s] w/ payload [%s]", proxyInfo, request.method().name(), httpInfo, request.path(), request.body())); } long start = System.currentTimeMillis(); try { client.executeMethod(http); } finally { stats.netTotalTime += (System.currentTimeMillis() - start); } if (log.isTraceEnabled()) { Socket sk = ReflectionUtils.invoke(GET_SOCKET, conn, (Object[]) null); String addr = sk.getLocalAddress().getHostAddress(); log.trace(String.format("Rx %s@[%s] [%s-%s] [%s]", proxyInfo, addr, http.getStatusCode(), HttpStatus.getStatusText(http.getStatusCode()), http.getResponseBodyAsString())); } // the request URI is not set (since it is retried across hosts), so use the http info instead for source return new SimpleResponse(http.getStatusCode(), new ResponseInputStream(http), httpInfo); }
From source file:org.httpobjects.proxy.Proxy.java
@Override public Response put(Request req) { PutMethod m = new PutMethod(); setRequestRepresentation(req, m); return proxyRequest(req, m); }
From source file:org.mule.module.activiti.action.PerformTaskOperationAction.java
public PutMethod getMethod() { return new PutMethod(); }
From source file:org.mule.module.activiti.action.remote.PerformTaskOperationAction.java
/** * {@inheritDoc} */ public PutMethod getMethod() { return new PutMethod(); }
From source file:org.nuxeo.ecm.core.opencmis.impl.client.protocol.http.HttpURLConnection.java
protected HttpMethod newMethod(String name) { if ("GET".equals(name)) { return new GetMethod(); }//from w ww. ja va 2s. c o m if ("POST".equals(name)) { return new PostMethod(); } if ("DELETE".equals(name)) { return new DeleteMethod(); } if ("PUT".equals(name)) { return new PutMethod(); } throw new UnsupportedOperationException("Unsupported method " + name); }
From source file:org.talend.mdm.bulkload.client.BulkloadClientUtil.java
public static void bulkload(String url, String cluster, String concept, String datamodel, boolean validate, boolean smartpk, boolean insertonly, InputStream itemdata, String username, String password, String transactionId, String sessionId, String universe, String tokenKey, String tokenValue) throws Exception { HostConfiguration config = new HostConfiguration(); URI uri = new URI(url, false, "UTF-8"); //$NON-NLS-1$ config.setHost(uri);/*from w ww . j a v a 2s .co m*/ NameValuePair[] parameters = { new NameValuePair("cluster", cluster), //$NON-NLS-1$ new NameValuePair("concept", concept), //$NON-NLS-1$ new NameValuePair("datamodel", datamodel), //$NON-NLS-1$ new NameValuePair("validate", String.valueOf(validate)), //$NON-NLS-1$ new NameValuePair("action", "load"), //$NON-NLS-1$ //$NON-NLS-2$ new NameValuePair("smartpk", String.valueOf(smartpk)), //$NON-NLS-1$ new NameValuePair("insertonly", String.valueOf(insertonly)) }; //$NON-NLS-1$ HttpClient client = new HttpClient(); String user = universe == null || universe.trim().length() == 0 ? username : universe + "/" + username; //$NON-NLS-1$ client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password)); HttpClientParams clientParams = client.getParams(); clientParams.setAuthenticationPreemptive(true); clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES); PutMethod putMethod = new PutMethod(); // This setPath call is *really* important (if not set, request will be sent to the JBoss root '/') putMethod.setPath(url); String responseBody; try { // Configuration putMethod.setRequestHeader("Content-Type", "text/xml; charset=utf8"); //$NON-NLS-1$ //$NON-NLS-2$ if (transactionId != null) { putMethod.setRequestHeader("transaction-id", transactionId); //$NON-NLS-1$ } if (sessionId != null) { putMethod.setRequestHeader("Cookie", STICKY_SESSION + "=" + sessionId); //$NON-NLS-1$ //$NON-NLS-2$ } if (tokenKey != null && tokenValue != null) { putMethod.setRequestHeader(tokenKey, tokenValue); } putMethod.setQueryString(parameters); putMethod.setContentChunked(true); // Set the content of the PUT request putMethod.setRequestEntity(new InputStreamRequestEntity(itemdata)); client.executeMethod(config, putMethod); responseBody = putMethod.getResponseBodyAsString(); if (itemdata instanceof InputStreamMerger) { ((InputStreamMerger) itemdata).setAlreadyProcessed(true); } } catch (Exception e) { throw new RuntimeException(e); } finally { putMethod.releaseConnection(); } int statusCode = putMethod.getStatusCode(); if (statusCode >= 500) { throw new BulkloadException(responseBody); } else if (statusCode >= 400) { throw new BulkloadException("Could not send data to MDM (HTTP status code: " + statusCode + ")."); //$NON-NLS-1$ //$NON-NLS-2$ } }
From source file:org.tuckey.web.filters.urlrewrite.RequestProxy.java
private static HttpMethod setupProxyRequest(final HttpServletRequest hsRequest, final URL targetUrl) throws IOException { final String methodName = hsRequest.getMethod(); final HttpMethod method; if ("POST".equalsIgnoreCase(methodName)) { PostMethod postMethod = new PostMethod(); InputStreamRequestEntity inputStreamRequestEntity = new InputStreamRequestEntity( hsRequest.getInputStream()); postMethod.setRequestEntity(inputStreamRequestEntity); method = postMethod;/*from w w w.j a va 2 s . c om*/ } else if ("GET".equalsIgnoreCase(methodName)) { method = new GetMethod(); } else if ("PUT".equalsIgnoreCase(methodName)) { PutMethod putMethod = new PutMethod(); InputStreamRequestEntity inputStreamRequestEntity = new InputStreamRequestEntity( hsRequest.getInputStream()); putMethod.setRequestEntity(inputStreamRequestEntity); method = putMethod; } else if ("DELETE".equalsIgnoreCase(methodName)) { method = new DeleteMethod(); } else { log.warn("Unsupported HTTP method requested: " + hsRequest.getMethod()); return null; } method.setFollowRedirects(false); method.setPath(targetUrl.getPath()); method.setQueryString(targetUrl.getQuery()); Enumeration e = hsRequest.getHeaderNames(); if (e != null) { while (e.hasMoreElements()) { String headerName = (String) e.nextElement(); if ("host".equalsIgnoreCase(headerName)) { //the host value is set by the http client continue; } else if ("content-length".equalsIgnoreCase(headerName)) { //the content-length is managed by the http client continue; } else if ("accept-encoding".equalsIgnoreCase(headerName)) { //the accepted encoding should only be those accepted by the http client. //The response stream should (afaik) be deflated. If our http client does not support //gzip then the response can not be unzipped and is delivered wrong. continue; } else if (headerName.toLowerCase().startsWith("cookie")) { //fixme : don't set any cookies in the proxied request, this needs a cleaner solution continue; } Enumeration values = hsRequest.getHeaders(headerName); while (values.hasMoreElements()) { String headerValue = (String) values.nextElement(); log.info("setting proxy request parameter:" + headerName + ", value: " + headerValue); method.addRequestHeader(headerName, headerValue); } } } if (log.isInfoEnabled()) log.info("proxy query string " + method.getQueryString()); return method; }