List of usage examples for org.apache.commons.httpclient.methods PutMethod PutMethod
public PutMethod(String paramString)
From source file:org.eclipse.smarthome.io.net.http.HttpUtil.java
/** * Factory method to create a {@link HttpMethod}-object according to the * given String <code>httpMethod</codde> * //ww w . jav a2 s . c o m * @param httpMethodString the name of the {@link HttpMethod} to create * @param url * * @return an object of type {@link GetMethod}, {@link PutMethod}, * {@link PostMethod} or {@link DeleteMethod} * @throws IllegalArgumentException if <code>httpMethod</code> is none of * <code>GET</code>, <code>PUT</code>, <code>POST</POST> or <code>DELETE</code> */ public static HttpMethod createHttpMethod(String httpMethodString, String url) { if ("GET".equals(httpMethodString)) { return new GetMethod(url); } else if ("PUT".equals(httpMethodString)) { return new PutMethod(url); } else if ("POST".equals(httpMethodString)) { return new PostMethod(url); } else if ("DELETE".equals(httpMethodString)) { return new DeleteMethod(url); } else { throw new IllegalArgumentException("given httpMethod '" + httpMethodString + "' is unknown"); } }
From source file:org.eclipse.swordfish.registry.tooling.popup.actions.UploadJob.java
@Override @SuppressWarnings("unchecked") public IStatus run(IProgressMonitor monitor) { IStatus status = Status.OK_STATUS;/*w ww . jav a 2s .com*/ monitor.beginTask(JOB_NAME, structuredSelection.size()); try { HttpClient httpClient = new HttpClient(); HttpMethodRetryHandler retryhandler = new HttpMethodRetryHandler() { /** * {@inheritDoc} */ public boolean retryMethod(final HttpMethod method, final IOException exception, int executionCount) { return false; } }; final String serviceRegistryURL = Activator.getDefault().getPreferenceStore() .getString(PreferenceConstants.REGISTRY_URL); Iterator selectedObjects = structuredSelection.iterator(); while (selectedObjects.hasNext()) { Object element = selectedObjects.next(); if (element instanceof IFile) { IFile file = (IFile) element; setName(JOB_NAME + ": " + file.getName()); monitor.subTask("Processing " + file.getName()); PutMethod putMethod = new PutMethod(serviceRegistryURL + "/" + file.getName()); putMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryhandler); RequestEntity entity = new InputStreamRequestEntity(file.getContents()); putMethod.setRequestEntity(entity); try { int statusCode = httpClient.executeMethod(putMethod); if (statusCode != HttpStatus.SC_OK) { status = new Status(IStatus.ERROR, Activator.getId(), "Error in Service Registry Upload: [" + statusCode + "] " + putMethod.getStatusText()); break; } status = new Status(IStatus.INFO, Activator.getId(), "Response from the Registry: " + putMethod.getResponseBodyAsString()); Activator.getDefault().getLog().log(status); } finally { // Release the connection. putMethod.releaseConnection(); } } monitor.worked(1); } } catch (Exception e) { status = new Status(IStatus.ERROR, Activator.getId(), IStatus.ERROR, e.getClass().getName() + " : " + e.getMessage(), e); } finally { monitor.done(); } return status; }
From source file:org.eclipse.swordfish.tools.deployer.SwordfishClientCommandProvider.java
private PutMethod createPutRequest(String ius, String operation, String profile) { PutMethod putMethod = new PutMethod(targetHost + servletPath + "/" + repository); putMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryhandler); putMethod.setRequestHeader(new Header(IU_OPERATION, operation)); String[] iuList = ius.split(","); for (int i = 0; i < iuList.length; i++) { putMethod.setRequestHeader(new Header(IU_ID + i, iuList[i])); }// w w w . jav a2 s . c om if ((profile != null) && !("".equals(profile))) { putMethod.setRequestHeader(new Header(IU_TARGET_PROFILE, profile)); } return putMethod; }
From source file:org.eclipse.winery.highlevelrestapi.HighLevelRestApi.java
/** * This method implements the HTTP Put Method * // w ww .j ava 2 s.c o m * @param uri Resource URI * @param requestPayload Content which has to be put into the Resource * @return ResponseCode of HTTP Interaction */ @SuppressWarnings("deprecation") public static HttpResponseMessage Put(String uri, String requestPayload, String acceptHeaderValue) { PutMethod method = new PutMethod(uri); // requestPayload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + // requestPayload; HighLevelRestApi.setAcceptHeader(method, acceptHeaderValue); method.setRequestBody(requestPayload); HttpResponseMessage responseMessage = LowLevelRestApi.executeHttpMethod(method); // kill <?xml... in front of response HighLevelRestApi.cleanResponseBody(responseMessage); return responseMessage; }
From source file:org.ednovo.gooru.application.converter.GooruImageUtil.java
public boolean resizeImageByDimensions(String srcFilePath, String targetFolderPath, String filenamePrefix, String dimensions, String resourceGooruOid, String sessionToken, String thumbnail) { try {//from w w w . j a v a2s . c o m logger.debug(" src : {} /= target : {}", srcFilePath, targetFolderPath); String[] imageDimensions = dimensions.split(","); if (filenamePrefix == null) { filenamePrefix = StringUtils.substringAfterLast(srcFilePath, "/"); if (filenamePrefix.contains(".")) { filenamePrefix = StringUtils.substringBeforeLast(filenamePrefix, "."); } } for (String dimension : imageDimensions) { String[] xy = dimension.split(X); int width = Integer.valueOf(xy[0]); int height = Integer.valueOf(xy[1]); resizeImageByDimensions(srcFilePath, width, height, targetFolderPath + filenamePrefix + "-" + dimension + "." + getFileExtenstion(srcFilePath)); } try { HttpClient client = new HttpClient(); HttpMethod method = new PutMethod("http://" + propertyMap.get(SERVER_PATH) + "/" + propertyMap.get(REST_END_POINT) + "/media/resource/thumbnail?sessionToken=" + sessionToken + "&resourceGooruOid=" + resourceGooruOid + "&thumbnail=" + thumbnail); client.executeMethod(method); } catch (Exception ex) { logger.error("something went wrong while making rest api call", ex); } return true; } catch (Exception ex) { logger.error("Multiple scaling of image failed for src : " + srcFilePath + " : ", ex); return false; } }
From source file:org.ednovo.gooru.converter.service.ConversionServiceImpl.java
public List<String> resizeImageByDimensions(String srcFilePath, String targetFolderPath, String filenamePrefix, String dimensions, String resourceGooruOid, String sessionToken, String thumbnail, String apiEndPoint) { String imagePath = null;/*from www . j a v a 2s.co m*/ List<String> list = new ArrayList<String>(); try { logger.debug(" src : {} /= target : {}", srcFilePath, targetFolderPath); String[] imageDimensions = dimensions.split(","); if (filenamePrefix == null) { filenamePrefix = StringUtils.substringAfterLast(srcFilePath, "/"); if (filenamePrefix.contains(".")) { filenamePrefix = StringUtils.substringBeforeLast(filenamePrefix, "."); } } for (String dimension : imageDimensions) { String[] xy = dimension.split(X); int width = Integer.valueOf(xy[0]); int height = Integer.valueOf(xy[1]); imagePath = resizeImageByDimensions(srcFilePath, width, height, targetFolderPath + filenamePrefix + "-" + dimension + "." + getFileExtenstion(srcFilePath)); list.add(imagePath); } try { JSONObject json = new JSONObject(); json.put(RESOURCE_GOORU_OID, resourceGooruOid); json.put(THUMBNAIL, thumbnail); JSONObject jsonAlias = new JSONObject(); jsonAlias.put(MEDIA, json); String jsonString = jsonAlias.toString(); StringRequestEntity requestEntity = new StringRequestEntity(jsonString, APP_JSON, "UTF-8"); HttpClient client = new HttpClient(); PutMethod postmethod = new PutMethod( apiEndPoint + "/media/resource/thumbnail?sessionToken=" + sessionToken); postmethod.setRequestEntity(requestEntity); client.executeMethod(postmethod); } catch (Exception ex) { logger.error("rest api call failed!", ex.getMessage()); } } catch (Exception ex) { logger.error("Multiple scaling of image failed for src : " + srcFilePath + " : ", ex); } return list; }
From source file:org.elasticsearch.hadoop.rest.RestClient.java
public void putMapping(String index, String mapping, byte[] bytes) { // create index first (if needed) - it might return 403 execute(new PutMethod(index), false); // create actual mapping PutMethod put = new PutMethod(mapping); put.setRequestEntity(new ByteArrayRequestEntity(bytes)); execute(put);//from w ww .j av a 2s . co m }
From source file:org.entando.entando.plugins.jpoauthclient.aps.system.httpclient.OAuthHttpClient.java
@Override public HttpResponseMessage execute(HttpMessage request, Map<String, Object> parameters) throws IOException { final String method = request.method; final String url = request.url.toExternalForm(); final InputStream body = request.getBody(); final boolean isDelete = DELETE.equalsIgnoreCase(method); final boolean isPost = POST.equalsIgnoreCase(method); final boolean isPut = PUT.equalsIgnoreCase(method); byte[] excerpt = null; HttpMethod httpMethod;/*from w ww .ja v a 2 s . co m*/ if (isPost || isPut) { EntityEnclosingMethod entityEnclosingMethod = isPost ? new PostMethod(url) : new PutMethod(url); if (body != null) { ExcerptInputStream e = new ExcerptInputStream(body); String length = request.removeHeaders(HttpMessage.CONTENT_LENGTH); entityEnclosingMethod.setRequestEntity((length == null) ? new InputStreamRequestEntity(e) : new InputStreamRequestEntity(e, Long.parseLong(length))); excerpt = e.getExcerpt(); } httpMethod = entityEnclosingMethod; } else if (isDelete) { httpMethod = new DeleteMethod(url); } else { httpMethod = new GetMethod(url); } for (Map.Entry<String, Object> p : parameters.entrySet()) { String name = p.getKey(); String value = p.getValue().toString(); if (FOLLOW_REDIRECTS.equals(name)) { httpMethod.setFollowRedirects(Boolean.parseBoolean(value)); } else if (READ_TIMEOUT.equals(name)) { httpMethod.getParams().setIntParameter(HttpMethodParams.SO_TIMEOUT, Integer.parseInt(value)); } } for (Map.Entry<String, String> header : request.headers) { httpMethod.addRequestHeader(header.getKey(), header.getValue()); } HttpClient client = this._clientPool.getHttpClient(new URL(httpMethod.getURI().toString())); client.executeMethod(httpMethod); return new HttpMethodResponse(httpMethod, excerpt, request.getContentCharset()); }
From source file:org.entando.entando.plugins.jpoauthclient.aps.system.services.client.ProviderConnectionManager.java
private String invokePostPutMethod(String url, boolean isPost, String body, Properties parameters, MediaType mediaType) {/*from www . java 2 s .c o m*/ String result = null; EntityEnclosingMethod method = null; try { HttpClient client = new HttpClient(); if (isPost) { method = new PostMethod(url); } else { method = new PutMethod(url); } this.addQueryString(method, parameters); method.setRequestBody(body); method.setRequestHeader("Content-type", mediaType.toString() + "; charset=UTF-8"); client.executeMethod(method); byte[] responseBody = method.getResponseBody(); result = new String(responseBody); } catch (Throwable t) { _logger.error("Error invoking Post or put Method", t); } finally { if (null != method) { method.releaseConnection(); } } return result; }
From source file:org.exist.netedit.NetEditApplet.java
/** * Upload file to server /* w ww . j ava 2s . c om*/ * @param file uploaded file * @param uploadTo URL of remote doc to upload * @throws HttpException * @throws IOException */ public void upload(File file, String uploadTo) throws HttpException, IOException { PutMethod put = new PutMethod(uploadTo); useCurrentSession(put); InputStream is = new FileInputStream(file); RequestEntity entity = new InputStreamRequestEntity(is); put.setRequestEntity(entity); http.executeMethod(put); is.close(); put.releaseConnection(); }