Example usage for org.springframework.http HttpMethod POST

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

Introduction

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

Prototype

HttpMethod POST

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

Click Source Link

Usage

From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java

@Test
public void testAddRegistration_OK() throws Exception {

    mockServer.expect(requestTo(baseURL + "/v2/registrations")).andExpect(method(HttpMethod.POST))
            .andExpect(header("Content-Type", MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.duration").value("PT1M")).andRespond(withNoContent());

    Registration registration = new Registration();
    registration.setDuration("PT1M");
    registration.setCallback(new URL("http://localhost:1234"));
    Metadata metadata = new Metadata("example");
    registration.addMetadata("provider", metadata);
    SubjectEntity subjectEntity = new SubjectEntity();
    subjectEntity.setType(Optional.of("Room"));
    SubjectRegistration subjectRegistration = new SubjectRegistration(Collections.singletonList(subjectEntity),
            Collections.singletonList("humidity"));
    registration.setSubject(subjectRegistration);
    ngsiClient.addRegistration(registration).get();
}

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

/**
 * Creates a Zencoder Account.//from   w w w. j  a  va  2 s  .c  o  m
 * New accounts will be created under the Test (Free) plan.
 * NOTE: A password will be generated and returned if not specified.
 *
 * @see https://app.zencoder.com/docs/api/accounts/create
 * @see http://zencoder.com/en/terms
 * @param account The account to create.
 * @return The created account with it's API key and password.
 * @throws ZencoderClientException
 */
public ZencoderAccount createAccount(ZencoderAccount account) throws ZencoderClientException {
    String url = api_url + "/account";

    String body = null;
    try {
        body = mapper.writeValueAsString(account);

    } catch (Exception e) {
        throw new ZencoderClientException("Unable to serialize ZencoderAccount as JSON", e);
    }

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

    ResponseEntity<String> response = null;
    try {
        response = rt.exchange(url, HttpMethod.POST, entity, String.class, new HashMap<String, Object>());

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

    ZencoderAccount zencoderAccountResponse = null;
    try {
        zencoderAccountResponse = mapper.readValue(response.getBody(), ZencoderAccount.class);

    } catch (Exception e) {
        throw new ZencoderClientException("Unable to deserialize ZencoderAccount as JSON", e);
    }
    return zencoderAccountResponse;
}

From source file:org.cbioportal.session_service.SessionServiceTest.java

private ResponseEntity<String> addData(String source, String type, String data) throws Exception {
    HttpEntity<String> entity = prepareData(data);
    return template.exchange(base.toString() + source + "/" + type + "/", HttpMethod.POST, entity,
            String.class);
}

From source file:com.orange.ngsi2.client.Ngsi2Client.java

/**
 * Create a new subscription/*from  w w w.ja v a  2s  . co m*/
 * @param subscription the Subscription to add
 * @return subscription Id
 */
public ListenableFuture<String> addSubscription(Subscription subscription) {
    ListenableFuture<ResponseEntity<Void>> s = request(HttpMethod.POST,
            UriComponentsBuilder.fromHttpUrl(baseURL).path("v2/subscriptions").toUriString(), subscription,
            Void.class);
    return new ListenableFutureAdapter<String, ResponseEntity<Void>>(s) {
        @Override
        protected String adapt(ResponseEntity<Void> result) throws ExecutionException {
            return extractId(result);
        }
    };
}

From source file:com.orange.ngsi.client.NgsiRestClientTest.java

@Test
public void testAppendContextSubscription_JSON() throws Exception {
    String responseBody = json(jsonConverter, createSubscribeContextResponseTemperature());

    mockServer.expect(requestTo(baseUrl + "/ngsi10/contextSubscriptions/")).andExpect(method(HttpMethod.POST))
            .andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));

    SubscribeContextResponse response = ngsiRestClient
            .appendContextSubscription(baseUrl, null, createSubscribeContextTemperature()).get();

    this.mockServer.verify();

    assertNotNull(response);//from w  ww .  jav a  2  s.  co  m
    assertNull(response.getSubscribeError());
    assertNotNull(response.getSubscribeResponse());
    assertEquals("12345678", response.getSubscribeResponse().getSubscriptionId());
    assertEquals("P1M", response.getSubscribeResponse().getDuration());
}

From source file:access.deploy.Deployer.java

/**
 * Executes the POST request to GeoServer to create the FeatureType as a Layer.
 * //w  ww.j  a va 2s  .c om
 * @param featureType
 *            The JSON Payload of the POST request
 * @return The HTTP Status code of the request to GeoServer for adding the layer. GeoServer will typically not
 *         return any payload in the response, so the HTTP Status is the best we can do in order to check for
 *         success.
 * @throws GeoServerException
 */
private HttpStatus postGeoServerFeatureType(String restURL, String featureType) throws GeoServerException {
    // Construct the URL for the Service
    String url = String.format("%s%s", accessUtilities.getGeoServerBaseUrl(), restURL);
    LOGGER.info("Attempting to push a GeoServer Featuretype {} to URL {}", featureType, url);

    // Create the Request template and execute
    authHeaders.setContentType(MediaType.APPLICATION_XML);
    HttpEntity<String> request = new HttpEntity<>(featureType, authHeaders.get());

    ResponseEntity<String> response = null;
    try {
        pzLogger.log(String.format("Creating GeoServer Feature Type for Resource %s", url),
                Severity.INFORMATIONAL, new AuditElement(ACCESS, "createGeoServerFeatureType", url));
        response = restTemplate.exchange(url, HttpMethod.POST, request, String.class);
    } catch (Exception exception) {
        String error = String.format("There was an error creating the Coverage Layer to URL %s with errors %s",
                url, exception.getMessage());
        pzLogger.log(error, Severity.ERROR,
                new AuditElement(ACCESS, "failedToCreateGeoServerFeatureType", url));
        LOGGER.error(error, exception);
        throw new GeoServerException(error);
    }

    // Return the HTTP Status
    return response.getStatusCode();
}

From source file:com.orange.ngsi2.client.Ngsi2Client.java

/**
 * Update, append or delete multiple entities in a single operation
 * @param bulkUpdateRequest a BulkUpdateRequest with an actionType and a list of entities to update
 * @return Nothing on success//from   w  ww  . java  2s.c  o m
 */
public ListenableFuture<Void> bulkUpdate(BulkUpdateRequest bulkUpdateRequest) {
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
    builder.path("v2/op/update");
    return adapt(request(HttpMethod.POST, builder.toUriString(), bulkUpdateRequest, Void.class));
}

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

private DataloadProcess postProcess(DataloadProcess process, File processData, URI postUri) {
    File tempFile = createTempFile("process", ".zip");

    try (FileOutputStream output = new FileOutputStream(tempFile)) {
        ZipHelper.zip(processData, output);
    } catch (IOException e) {
        throw new GoodDataException("Unable to zip process data", e);
    }//from   w  ww . j a  v a 2 s .c o m

    Object processToSend;
    HttpMethod method = HttpMethod.POST;
    if (tempFile.length() > MAX_MULTIPART_SIZE) {
        try {
            process.setPath(dataStoreService.getUri(tempFile.getName()).getPath());
            dataStoreService.upload(tempFile.getName(), new FileInputStream(tempFile));
            processToSend = process;
            if (DataloadProcess.TEMPLATE.matches(postUri.toString())) {
                method = HttpMethod.PUT;
            }
        } catch (FileNotFoundException e) {
            throw new GoodDataException("Unable to access zipped process data at " + tempFile.getAbsolutePath(),
                    e);
        }
    } else {
        final MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>(2);
        parts.add("process", process);
        final HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MEDIA_TYPE_ZIP);
        parts.add("data", new HttpEntity<>(new FileSystemResource(tempFile), headers));
        processToSend = parts;
    }

    try {
        final ResponseEntity<DataloadProcess> response = restTemplate.exchange(postUri, method,
                new HttpEntity<>(processToSend), DataloadProcess.class);
        if (response == null) {
            throw new GoodDataException("Unable to post dataload process. No response returned from API.");
        }
        return response.getBody();
    } catch (GoodDataException | RestClientException e) {
        throw new GoodDataException("Unable to post dataload process.", e);
    } finally {
        deleteTempFile(tempFile);
    }
}

From source file:com.orange.ngsi2.client.Ngsi2Client.java

/**
 * Query multiple entities in a single operation
 * @param bulkQueryRequest defines the list of entities, attributes and scopes to match entities
 * @param orderBy an optional list of attributes to order the entities (null or empty for none)
 * @param offset an optional offset (0 for none)
 * @param limit an optional limit (0 for none)
 * @param count true to return the total number of matching entities
 * @return a paginated list of entities//from w  w w  . j a  va2 s. c  o  m
 */
public ListenableFuture<Paginated<Entity>> bulkQuery(BulkQueryRequest bulkQueryRequest,
        Collection<String> orderBy, int offset, int limit, boolean count) {
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
    builder.path("v2/op/query");
    addPaginationParams(builder, offset, limit);
    addParam(builder, "orderBy", orderBy);
    if (count) {
        addParam(builder, "options", "count");
    }
    return adaptPaginated(request(HttpMethod.POST, builder.toUriString(), bulkQueryRequest, Entity[].class),
            offset, limit);
}