List of usage examples for org.springframework.http HttpMethod PUT
HttpMethod PUT
To view the source code for org.springframework.http HttpMethod PUT.
Click Source Link
From source file:io.seldon.client.services.ApiServiceImpl.java
private Object performPut(final String endpointUrl, ResourceBean resourceBean) { logger.info("* PUT Endpoint: " + endpointUrl); if (token == null) { ResourceBean r = getToken();//from w w w . java 2s . c o m if (r instanceof ErrorBean) return r; } String url = endpointUrl + "&oauth_token=" + token; RestTemplate template = createRestTemplate(); logger.debug("* PUTting: " + resourceBean); logger.debug("** Endpoint: " + url); // API return types for posts vary: Map on success, ErrorBean on failure -- we're forced to use Object here: //template.put(url, resourceBean); HttpEntity<ResourceBean> entity = new HttpEntity<ResourceBean>(resourceBean); ResponseEntity<Object> responseEntity = null; try { responseEntity = template.exchange(url, HttpMethod.PUT, entity, Object.class); } catch (ResourceAccessException e) { if (e.getCause() instanceof SocketTimeoutException) { return createTimeoutBean(); } } Object body = responseEntity.getBody(); logger.debug("PUT response: " + body); if (body instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) body; String response = (String) map.get("response"); String errorMessage = (String) map.get("error_msg"); // if this is an error bean if (response == null && errorMessage != null) { response = errorMessage; } if (response != null) { // not great; some posts return response maps, some return resource beans if (!response.equals("ok")) { if (response.equals("Token expired")) { logger.debug("Token expired; acquiring a fresh one..."); ResourceBean r = getToken(); if (r instanceof ErrorBean) return r; return performPut(endpointUrl, resourceBean); } else { return new ErrorBean(map); } } } } return body; }
From source file:net.slkdev.swagger.confluence.service.impl.XHtmlToConfluenceServiceImpl.java
private void updatePage(final ConfluencePage page, final Map<String, ConfluenceLink> confluenceLinkMap) { final SwaggerConfluenceConfig swaggerConfluenceConfig = SWAGGER_CONFLUENCE_CONFIG.get(); final URI targetUrl = UriComponentsBuilder.fromUriString(swaggerConfluenceConfig.getConfluenceRestApiUrl()) .path(String.format("/content/%s", page.getId())).build().toUri(); final HttpHeaders httpHeaders = buildHttpHeaders(swaggerConfluenceConfig.getAuthentication()); final JSONObject postVersionObject = new JSONObject(); postVersionObject.put("number", page.getVersion() + 1); final String formattedXHtml = reformatXHtml(page.getXhtml(), confluenceLinkMap); final JSONObject postBody = buildPostBody(page.getAncestorId(), page.getConfluenceTitle(), formattedXHtml); postBody.put(ID, page.getId());/* ww w . j av a 2s .c o m*/ postBody.put("version", postVersionObject); final HttpEntity<String> requestEntity = new HttpEntity<>(postBody.toJSONString(), httpHeaders); LOG.debug("UPDATE PAGE REQUEST: {}", postBody); final HttpEntity<String> responseEntity = restTemplate.exchange(targetUrl, HttpMethod.PUT, requestEntity, String.class); LOG.debug("UPDATE PAGE RESPONSE: {}", responseEntity.getBody()); final Integer pageId = getPageIdFromResponse(responseEntity); page.setAncestorId(pageId); }
From source file:com.jaspersoft.android.sdk.client.JsRestClient.java
/** * Runs the report and generates the specified output. The response contains report descriptor * with the ID of the saved output for downloading later with a GET request. * * @param resourceDescriptor resource descriptor of this report * @param format The format of the report output. Possible values: PDF, HTML, XLS, RTF, CSV, * XML, JRPRINT. The Default is PDF. * @return ReportDescriptor/*ww w. j a va2s. com*/ * @throws RestClientException thrown by RestTemplate whenever it encounters client-side HTTP errors */ public ReportDescriptor getReportDescriptor(ResourceDescriptor resourceDescriptor, String format) throws RestClientException { String fullUri = restServicesUrl + REST_REPORT_URI + resourceDescriptor.getUriString() + "?IMAGES_URI=./&RUN_OUTPUT_FORMAT={format}"; HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAccept(singletonList(MediaType.TEXT_XML)); HttpEntity<ResourceDescriptor> requestEntity = new HttpEntity<ResourceDescriptor>(resourceDescriptor, requestHeaders); ResponseEntity<ReportDescriptor> entity = restTemplate.exchange(fullUri, HttpMethod.PUT, requestEntity, ReportDescriptor.class, format); return entity.getBody(); }
From source file:org.cloudfoundry.client.lib.rest.CloudControllerClientImpl.java
private CloudResources getKnownRemoteResources(ApplicationArchive archive) throws IOException { CloudResources archiveResources = new CloudResources(archive); String json = JsonUtil.convertToJson(archiveResources); HttpHeaders headers = new HttpHeaders(); headers.setContentType(JsonUtil.JSON_MEDIA_TYPE); HttpEntity<String> requestEntity = new HttpEntity<String>(json, headers); ResponseEntity<String> responseEntity = getRestTemplate().exchange(getUrl("/v2/resource_match"), HttpMethod.PUT, requestEntity, String.class); List<CloudResource> cloudResources = JsonUtil.convertJsonToCloudResourceList(responseEntity.getBody()); return new CloudResources(cloudResources); }
From source file:org.cloudfoundry.client.lib.rest.CloudControllerClientImpl.java
@Override public StartingInfo startApplication(String appName) { CloudApplication app = getApplication(appName); if (app.getState() != CloudApplication.AppState.STARTED) { HashMap<String, Object> appRequest = new HashMap<String, Object>(); appRequest.put("state", CloudApplication.AppState.STARTED); HttpEntity<Object> requestEntity = new HttpEntity<Object>(appRequest); ResponseEntity<String> entity = getRestTemplate().exchange(getUrl("/v2/apps/{guid}?stage_async=true"), HttpMethod.PUT, requestEntity, String.class, app.getMeta().getGuid()); HttpHeaders headers = entity.getHeaders(); // Return a starting info, even with a null staging log value, as a non-null starting info // indicates that the response entity did have headers. The API contract is to return starting info // if there are headers in the response, null otherwise. if (headers != null && !headers.isEmpty()) { String stagingFile = headers.getFirst("x-app-staging-log"); if (stagingFile != null) { try { stagingFile = URLDecoder.decode(stagingFile, "UTF-8"); } catch (UnsupportedEncodingException e) { logger.error("unexpected inability to UTF-8 decode", e); }/*from w w w . j a va2 s.co m*/ } // Return the starting info even if decoding failed or staging file is null return new StartingInfo(stagingFile); } } return null; }
From source file:com.sitewhere.rest.client.SiteWhereClient.java
@Override public DeviceSpecification updateDeviceSpecification(String token, DeviceSpecificationCreateRequest request) throws SiteWhereException { Map<String, String> vars = new HashMap<String, String>(); vars.put("token", token); return sendRest(getBaseUrl() + "specifications/{token}", HttpMethod.PUT, null, DeviceSpecification.class, vars);/*from w w w . j a va 2s .c om*/ }
From source file:com.sitewhere.rest.client.SiteWhereClient.java
@Override public DeviceGroupElementSearchResults addDeviceGroupElements(String groupToken, List<DeviceGroupElementCreateRequest> elements) throws SiteWhereException { Map<String, String> vars = new HashMap<String, String>(); vars.put("token", groupToken); return sendRest(getBaseUrl() + "devicegroups/{token}/elements", HttpMethod.PUT, elements, DeviceGroupElementSearchResults.class, vars); }
From source file:com.vmware.bdd.cli.rest.RestClient.java
/** * process requests with query parameters * * @param id//from w ww . ja v a2s . c om * @param path * the rest url * @param verb * the http method * @param queryStrings * required query strings * @param prettyOutput * output callback */ public void actionOps(final String id, final String path, final HttpMethod verb, final Map<String, String> queryStrings, PrettyOutput... prettyOutput) { checkConnection(); try { if (verb == HttpMethod.PUT) { ResponseEntity<String> response = restActionOps(path, id, queryStrings); if (!validateAuthorization(response)) { return; } processResponse(response, HttpMethod.PUT, prettyOutput); } else { throw new Exception(Constants.HTTP_VERB_ERROR); } } catch (Exception e) { throw new CliRestException(CommandsUtils.getExceptionMessage(e)); } }
From source file:com.vmware.bdd.cli.rest.RestClient.java
private ResponseEntity<String> restActionOps(String path, String id, Map<String, String> queryStrings) { String targetUri = hostUri + Constants.HTTPS_CONNECTION_API + path + "/" + id; if (queryStrings != null) { targetUri = targetUri + buildQueryStrings(queryStrings); }/*ww w . ja v a2s .c o m*/ HttpHeaders headers = buildHeaders(); HttpEntity<String> entity = new HttpEntity<String>(headers); return client.exchange(targetUri, HttpMethod.PUT, entity, String.class); }