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:de.fhg.fokus.nubomedia.paas.VNFRServiceImpl.java

/**
 * Registers a new App to the VNFR with a specific VNFR ID
 *    /*ww w . j a v  a2 s . c  o m*/
 * @param externalAppId - application identifier
 * @param points - capacity
 */
public ApplicationRecord registerApplication(String externalAppId, int points)
        throws NotEnoughResourcesException {
    try {
        if (serviceProfile == null) {
            logger.info("Service Profile not set. make sure the VNFR_ID, VNFM_IP and VNFM_PORT are available ");
            return null;
        }
        String URL = serviceProfile.getServiceApiUrl();
        ApplicationRecordBody bodyObj = new ApplicationRecordBody(externalAppId, points);
        Gson mapper = new GsonBuilder().create();
        String body = mapper.toJson(bodyObj, ApplicationRecordBody.class);

        logger.info("registering new application: \nURL: " + URL + "\n + " + body);
        HttpHeaders creationHeader = new HttpHeaders();
        creationHeader.add("Accept", "application/json");
        creationHeader.add("Content-type", "application/json");

        HttpEntity<String> registerEntity = new HttpEntity<String>(body, creationHeader);
        ResponseEntity response = restTemplate.exchange(URL, HttpMethod.POST, registerEntity, String.class);

        logger.info("response from VNFM " + response);
        HttpStatus status = response.getStatusCode();
        if (status.equals(HttpStatus.CREATED) || status.equals(HttpStatus.OK)) {
            logger.info("Deployment status: " + status + " response: " + response);
            ApplicationRecord responseBody = mapper.fromJson((String) response.getBody(),
                    ApplicationRecord.class);

            logger.info("returned object " + responseBody.toString());
            return responseBody;
        } else if (status.equals(HttpStatus.UNPROCESSABLE_ENTITY)) {

            throw new NotEnoughResourcesException("Not enough resource " + response.getBody());
        }
    } catch (NotEnoughResourcesException e) {
        logger.error(e.getMessage());
    } catch (RestClientException e) {
        logger.error("Error registering application to VNFR - " + e.getMessage());
    }
    return null;
}

From source file:org.cloudfoundry.identity.uaa.login.feature.AutologinIT.java

@Test
public void testAutologinFlow() throws Exception {
    webDriver.get(baseUrl + "/logout.do");

    HttpHeaders headers = getAppBasicAuthHttpHeaders();

    Map<String, String> requestBody = new HashMap<>();
    requestBody.put("username", testAccounts.getUserName());
    requestBody.put("password", testAccounts.getPassword());

    ResponseEntity<Map> autologinResponseEntity = restOperations.exchange(baseUrl + "/autologin",
            HttpMethod.POST, new HttpEntity<>(requestBody, headers), Map.class);
    String autologinCode = (String) autologinResponseEntity.getBody().get("code");

    String authorizeUrl = UriComponentsBuilder.fromHttpUrl(baseUrl).path("/oauth/authorize")
            .queryParam("redirect_uri", appUrl).queryParam("response_type", "code")
            .queryParam("scope", "openid").queryParam("client_id", "app").queryParam("code", autologinCode)
            .build().toUriString();// ww w .  jav a2 s  . c  om

    webDriver.get(authorizeUrl);

    webDriver.get(baseUrl);

    assertEquals(testAccounts.getUserName(), webDriver.findElement(By.cssSelector(".header .nav")).getText());
}

From source file:com.github.lynxdb.server.api.http.WebSecurityConfig.java

@Override
protected void configure(HttpSecurity http) throws Exception {

    http.csrf().disable();/*from   w w  w.  j av a2  s.  co m*/

    http.antMatcher("/api/**").authorizeRequests().antMatchers(HttpMethod.OPTIONS).permitAll()
            .antMatchers(EpAggregators.ENDPOINT, EpQuery.ENDPOINT, EpSuggest.ENDPOINT)
            .hasAnyRole(User.Rank.RO_USER.name(), User.Rank.RW_USER.name(), User.Rank.ADMIN.name())
            .antMatchers(HttpMethod.POST, EpPut.ENDPOINT)
            .hasAnyRole(User.Rank.RW_USER.name(), User.Rank.ADMIN.name())
            .antMatchers(EpUser.ENDPOINT, EpVhost.ENDPOINT).hasRole(User.Rank.ADMIN.name());

    http.httpBasic().realmName("Lynx");

    http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}

From source file:com.cloudera.nav.sdk.client.NavigatorPluginTest.java

private void assertModelRegistration() {
    RestTemplate mockTemplate = mock(RestTemplate.class);
    NavApiCient client = spy(plugin.getClient());
    when(plugin.getClient()).thenReturn(client);
    when(client.newRestTemplate()).thenReturn(mockTemplate);
    MetadataModel mockResponse = new MetadataModel();
    Map<String, Collection<String>> mockErrs = Maps.newHashMap();
    mockErrs.put("model1", Sets.newHashSet("msg1", "msg2"));
    when(mockTemplate.exchange(eq(plugin.getClient().getApiUrl() + "/models"), eq(HttpMethod.POST),
            any(HttpEntity.class), eq(MetadataModel.class)))
                    .thenReturn(new ResponseEntity<>(mockResponse, HttpStatus.OK));
    MetadataModel response = plugin.registerModel(TestMClass.class);
    assertEquals(mockResponse, response);
}

From source file:com.garyclayburg.UserRestSmokeTest.java

@Test
public void testHalJsonApache() throws Exception {
    RestTemplate rest = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
    SimpleUser user1 = new SimpleUser();
    user1.setFirstname("Tommy");
    user1.setLastname("Deleteme");
    user1.setId("112" + (int) (Math.floor(Math.random() * 10000)));

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Content-Type", "application/hal+json");
    //        HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
    HttpEntity<?> requestEntity = new HttpEntity(user1, requestHeaders);

    ResponseEntity<SimpleUser> simpleUserResponseEntity = rest.exchange(
            "http://" + endpoint + "/audited-users/auditedsave", HttpMethod.POST, requestEntity,
            SimpleUser.class);

    //        ResponseEntity<SimpleUser> userResponseEntity =
    //            rest.postForEntity("http://" + endpoint + "/audited-users/auditedsave",user1,SimpleUser.class);
    log.info("got a response");
    MatcherAssertionErrors.assertThat(simpleUserResponseEntity.getStatusCode(),
            Matchers.equalTo(HttpStatus.OK));

}

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

@Test(expected = HttpServerErrorException.class)
public void notifyContextRequestWith500() throws Exception {

    mockServer.expect(requestTo(baseUrl + "/ngsi10/notifyContext")).andExpect(method(HttpMethod.POST))
            .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));

    ngsiClient.notifyContext(baseUrl, null, createNotifyContextTempSensor(0)).get();
}

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

@Test(expected = HttpServerErrorException.class)
public void queryContextRequestWith500() throws Exception {

    mockServer.expect(requestTo(baseUrl + "/ngsi10/queryContext")).andExpect(method(HttpMethod.POST))
            .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));

    ngsiClient.queryContext(baseUrl, null, createQueryContextTemperature()).get();
}

From source file:org.openbaton.nse.beans.connectivitymanageragent.ConnectivityManagerRequestor.java

public QosAdd setQoS(QosAdd qosRequest) {

    logger.debug("SENDING REQUEST FOR " + mapper.toJson(qosRequest, QosAdd.class));
    String url = configuration.getBaseUrl() + "/qoses";
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<String> setEntity = new HttpEntity<>(mapper.toJson(qosRequest, QosAdd.class), headers);
    logger.debug("SENDING QOS " + mapper.toJson(qosRequest, QosAdd.class));
    ResponseEntity<String> insert = template.exchange(url, HttpMethod.POST, setEntity, String.class);

    logger.debug("Setting of QoS has produced http status:" + insert.getStatusCode() + " with body: "
            + insert.getBody());//ww w. j ava  2 s  . co m

    if (!insert.getStatusCode().is2xxSuccessful()) {
        return null;
    } else {
        QosAdd result = mapper.fromJson(insert.getBody(), QosAdd.class);
        logger.debug(
                "RESULT IS " + insert.getStatusCode() + " with body " + mapper.toJson(result, QosAdd.class));
        return result;
    }
}

From source file:com.may.ple.parking.gateway.activity.GateInActivity.java

@Override
public boolean onLongClick(View v) {

    if (v.getId() == R.id.show) {
        if (licenseNo == null || licenseNo.trim().length() == 0)
            return false;

        show.setBackgroundResource(R.drawable.text_show_sent);
        show.setTextColor(Color.parseColor("#000000"));

        if (isCheckOut) {
            Intent returnIntent = new Intent();
            returnIntent.putExtra("result", licenseNo);
            setResult(RESULT_OK, returnIntent);
            finish();//from   www  .j a  v a  2  s . c  o  m
            return true;
        }

        VehicleSaveCriteriaReq req = new VehicleSaveCriteriaReq();
        req.licenseNo = licenseNo;
        req.deviceId = ApplicationScope.getInstance().deviceId;
        req.gateName = gateName;

        service.send(1, req, VehicleSaveCriteriaResp.class, "/restAct/vehicle/saveVehicleParking",
                HttpMethod.POST);
        spinner.show();
    } else {
        licenseNo = "";
        show.setText(licenseNo);
    }
    return true;
}