Example usage for org.springframework.http HttpMethod PUT

List of usage examples for org.springframework.http HttpMethod PUT

Introduction

In this page you can find the example usage for org.springframework.http HttpMethod PUT.

Prototype

HttpMethod PUT

To view the source code for org.springframework.http HttpMethod PUT.

Click Source Link

Usage

From source file:gateway.controller.ServiceController.java

/**
 * Updates an existing service with Piazza's Service Controller.
 * /*from   ww  w . j a  v a  2s .c o  m*/
 * @see http://pz-swagger.stage.geointservices.io/#!/Service/put_service
 * 
 * @param serviceId
 *            The Id of the service to update.
 * @param serviceData
 *            The service data to update the existing service with.
 * @param user
 *            The user submitting the request
 * @return 200 OK if success, or an error if exceptions occur.
 */
@RequestMapping(value = "/service/{serviceId}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Update Service Information", notes = "Updates Service Metadata, to the Service specified by Id.", tags = "Service")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Confirmation of Update.", response = SuccessResponse.class),
        @ApiResponse(code = 400, message = "Bad Request", response = ErrorResponse.class),
        @ApiResponse(code = 401, message = "Unauthorized", response = ErrorResponse.class),
        @ApiResponse(code = 404, message = "Not Found", response = ErrorResponse.class),
        @ApiResponse(code = 500, message = "Internal Error", response = ErrorResponse.class) })
public ResponseEntity<PiazzaResponse> updateService(
        @ApiParam(value = "The Id of the Service to Update.", required = true) @PathVariable(value = "serviceId") String serviceId,
        @ApiParam(value = "The Service Metadata. All properties specified in the Service data here will overwrite the existing properties of the Service.", required = true, name = "service") @RequestBody Service serviceData,
        Principal user) {
    try {
        // Log the request
        logger.log(String.format("User %s has requested Service update of %s",
                gatewayUtil.getPrincipalName(user), serviceId), PiazzaLogger.INFO);

        // Proxy the request to the Service Controller instance
        HttpHeaders theHeaders = new HttpHeaders();
        // headers.add("Authorization", "Basic " + credentials);
        theHeaders.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<Service> request = new HttpEntity<Service>(serviceData, theHeaders);
        try {
            return new ResponseEntity<PiazzaResponse>(restTemplate
                    .exchange(String.format("%s/%s/%s", SERVICECONTROLLER_URL, "service", serviceId),
                            HttpMethod.PUT, request, SuccessResponse.class)
                    .getBody(), HttpStatus.OK);
        } catch (HttpClientErrorException | HttpServerErrorException hee) {
            LOGGER.error("Error Updating Service", hee);
            return new ResponseEntity<PiazzaResponse>(
                    gatewayUtil.getErrorResponse(hee.getResponseBodyAsString()), hee.getStatusCode());
        }
    } catch (Exception exception) {
        String error = String.format("Error Updating Service %s Info for user %s: %s", serviceId,
                gatewayUtil.getPrincipalName(user), exception.getMessage());
        LOGGER.error(error, exception);
        logger.log(error, PiazzaLogger.ERROR);
        return new ResponseEntity<PiazzaResponse>(new ErrorResponse(error, "Gateway"),
                HttpStatus.INTERNAL_SERVER_ERROR);

    }
}

From source file:com.appglu.impl.UserTemplateTest.java

@Test
public void writeData() {
    mockServer.expect(requestTo("http://localhost/appglu/v1/users/me/data")).andExpect(method(HttpMethod.PUT))
            .andExpect(content().string(compactedJson("data/user_data")))
            .andExpect(header(UserSessionPersistence.X_APPGLU_SESSION_HEADER, "sessionId"))
            .andRespond(withStatus(HttpStatus.OK).headers(responseHeaders));

    Assert.assertFalse(appGluTemplate.isUserAuthenticated());
    Assert.assertNull(appGluTemplate.getAuthenticatedUser());

    appGluTemplate.setUserSessionPersistence(new LoggedInUserSessionPersistence("sessionId", new User("test")));

    Assert.assertTrue(appGluTemplate.isUserAuthenticated());
    Assert.assertNotNull(appGluTemplate.getAuthenticatedUser());

    Map<String, Object> data = new HashMap<String, Object>();
    data.put("entryOne", "valueOne");

    Map<String, Object> entryTwo = new HashMap<String, Object>();
    entryTwo.put("data", "test");
    entryTwo.put("moreData", "test");

    Map<String, Object> nested = new HashMap<String, Object>();
    nested.put("value", 1);
    entryTwo.put("nestedData", nested);

    data.put("entryTwo", entryTwo);
    data.put("entryThree", new int[] { 1, 2, 3 });

    userOperations.writeData(data);/*w w w.  j  a  va  2 s  .  c om*/

    mockServer.verify();
}

From source file:com.sitewhere.rest.service.SiteWhereClient.java

@Override
public DeviceLocation associateAlertWithDeviceLocation(String alertId, String locationId)
        throws SiteWhereException {
    Map<String, String> vars = new HashMap<String, String>();
    vars.put("locationId", locationId);
    vars.put("alertId", alertId);
    String url = getBaseUrl() + "locations/{locationId}/alerts/{alertId}";
    return sendRest(url, HttpMethod.PUT, null, DeviceLocation.class, vars);
}

From source file:com.brightcove.zencoder.client.ZencoderClient.java

/**
 * If a job has failed processing you may request that it be attempted again.
 *
 * @see https://app.zencoder.com/docs/api/jobs/resubmit
 * @param id// www  .  j a  va2s  . c  om
 * @throws ZencoderClientException
 */
public void resubmitJob(String id) throws ZencoderClientException {
    String url = api_url + "/jobs/" + id + "/resubmit.json";

    HttpHeaders headers = getHeaders();
    @SuppressWarnings("rawtypes")
    HttpEntity entity = new HttpEntity<String>("", headers);

    try {
        rt.exchange(url, HttpMethod.PUT, entity, String.class, new HashMap<String, Object>());

    } catch (HttpClientErrorException hcee) {
        throw new ZencoderClientException(hcee.getResponseBodyAsString(), hcee);
    }
}

From source file:com.gooddata.dataload.processes.ProcessService.java

/**
 * Update the given schedule//from  ww  w . ja v  a2 s .  c om
 *
 * @param schedule to update
 * @return updated Schedule
 * @throws ScheduleNotFoundException when the schedule doesn't exist
 */
public Schedule updateSchedule(Schedule schedule) {
    notNull(schedule, "schedule");
    notNull(schedule.getUri(), "schedule.uri");

    final String uri = schedule.getUri();
    try {
        final ResponseEntity<Schedule> response = restTemplate.exchange(uri, HttpMethod.PUT,
                new HttpEntity<>(schedule), Schedule.class);
        if (response == null) {
            throw new GoodDataException("Unable to update schedule. No response returned from API.");
        }
        return response.getBody();
    } catch (GoodDataRestException e) {
        if (HttpStatus.NOT_FOUND.value() == e.getStatusCode()) {
            throw new ScheduleNotFoundException(uri, e);
        } else {
            throw e;
        }
    } catch (RestClientException e) {
        throw new GoodDataException("Unable to get schedule " + uri, e);
    }
}

From source file:org.zalando.boot.etcd.EtcdClientTest.java

@Test
public void putDir() throws EtcdException {
    server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample"))
            .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT))
            .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED))
            .andExpect(MockRestRequestMatchers.content().string("dir=true")).andRespond(
                    MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_delete.json"),
                            MediaType.APPLICATION_JSON));

    EtcdResponse response = client.putDir("sample");
    Assert.assertNotNull("response", response);

    server.verify();/* w w  w .  ja  va  2  s .  co m*/
}

From source file:com.citrix.g2w.webdriver.dependencies.AccountServiceQAIImpl.java

/**
 * Method to enable or disable content sharing for an account.
 * //from  w w w .j a  v  a2s .  c  o m
 * @param accountKey
 *            (user account key)
 * @param enable
 *            (user enable)
 */
@Override
public void setContentSharingForAccount(final Long accountKey, final boolean enable) {
    HttpEntity httpEntity = new HttpEntity("{\"contentsharingenabled\":" + enable + "}",
            this.accountSvcHeaders);
    this.restTemplate.exchange(this.accountSvcUrl + "/accounts/" + accountKey + "/products/g2w", HttpMethod.PUT,
            httpEntity, null);
}

From source file:com.brightcove.zencoder.client.ZencoderClient.java

/**
 * If you wish to cancel a job that has not yet finished processing.
 *
 * @see https://app.zencoder.com/docs/api/jobs/cancel
 * @param id/*from  w  ww.j  av  a 2 s . c  om*/
 * @throws ZencoderClientException
 */
public void cancelJob(String id) throws ZencoderClientException {
    String url = api_url + "/jobs/" + id + "/cancel.json";

    HttpHeaders headers = getHeaders();
    @SuppressWarnings("rawtypes")
    HttpEntity entity = new HttpEntity<String>("", headers);

    try {
        rt.exchange(url, HttpMethod.PUT, entity, String.class, new HashMap<String, Object>());

    } catch (HttpClientErrorException hcee) {
        throw new ZencoderClientException(hcee.getResponseBodyAsString(), hcee);
    }
}

From source file:com.appglu.impl.UserTemplateTest.java

@Test
public void writeDataUnauthorized() {
    mockServer.expect(requestTo("http://localhost/appglu/v1/users/me/data")).andExpect(method(HttpMethod.PUT))
            .andExpect(content().string(compactedJson("data/user_data_single_entry")))
            .andExpect(header(UserSessionPersistence.X_APPGLU_SESSION_HEADER, "sessionId"))
            .andRespond(withStatus(HttpStatus.UNAUTHORIZED).body(compactedJson("data/user_unauthorized"))
                    .headers(responseHeaders));

    Assert.assertFalse(appGluTemplate.isUserAuthenticated());
    Assert.assertNull(appGluTemplate.getAuthenticatedUser());

    appGluTemplate.setUserSessionPersistence(new LoggedInUserSessionPersistence("sessionId", new User("test")));

    Assert.assertTrue(appGluTemplate.isUserAuthenticated());
    Assert.assertNotNull(appGluTemplate.getAuthenticatedUser());

    try {/*from w w  w . j  a v a  2s  .  c  om*/
        HashMap<String, Object> data = new HashMap<String, Object>();
        data.put("key", "value");

        userOperations.writeData(data);
        Assert.fail("An unauthorized response should throw an AppGluHttpUserUnauthorizedException exception");
    } catch (AppGluHttpUserUnauthorizedException e) {

    }

    Assert.assertFalse(appGluTemplate.isUserAuthenticated());
    Assert.assertNull(appGluTemplate.getAuthenticatedUser());

    mockServer.verify();
}

From source file:org.zalando.boot.etcd.EtcdClientTest.java

@Test
public void putDirWithSetTtl() throws EtcdException {
    server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample"))
            .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT))
            .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED))
            .andExpect(MockRestRequestMatchers.content().string("dir=true&ttl=60")).andRespond(
                    MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_delete.json"),
                            MediaType.APPLICATION_JSON));

    EtcdResponse response = client.putDir("sample", 60);
    Assert.assertNotNull("response", response);

    server.verify();//from   w  ww .  j  a  va 2  s.  co m
}