@Test
 public void shouldReturnAppNoOnPostInRSEndpoint() {
   RestTemplate rt = new RestTemplate();
   rt.setMessageConverters(converters);
   ResponseEntity<String> res =
       rt.postForEntity(RS_APPLICATION_URL, "T_APPLICATION_APPCD", String.class);
   String appNo = res.getBody();
   System.out.println(appNo);
   assertThat("Created object shouldnt be null", appNo, is(notNullValue()));
 }
Ejemplo n.º 2
0
  @Override
  public Purchase createPurchase(Purchase purchase) {
    ResponseEntity<Purchase> responseEntity =
        restTemplate.postForEntity(urlCreatePurchase, purchase, Purchase.class);

    if (responseEntity.getStatusCode() != HttpStatus.OK) {
      throw new RequestException("Could not create new purchase");
    }

    return responseEntity.getBody();
  }
Ejemplo n.º 3
0
  /**
   * Para funcionar este teste precisa adicionar uma foto que tenha no computador e que altere no
   * arquivo application.properties a pasta na chave "pasta.upload"
   */
  @Test
  public void testA_uploadPost() {

    MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
    parts.add("id", "1");
    parts.add("file", new FileSystemResource("C:\\Users\\Mineiro\\Downloads\\foto1.jpg"));

    ResponseEntity<ProdutoJson> response =
        template.postForEntity(host + "/fotos/upload", parts, ProdutoJson.class);
    assertEquals(HttpStatus.OK, response.getStatusCode());
  }
 @Override
 public void sendInvalidFailureRecord(final InvalidFailedCallReports invalidFailedCallReports) {
   String url =
       String.format("%s?%s=%s", obdProperties.getFailureReportUrl(), "msisdn", "{msisdn}");
   HashMap<String, String> urlVariables =
       new HashMap<String, String>() {
         {
           put("msisdn", formatInvalidFailureRecordRequestParam(invalidFailedCallReports));
         }
       };
   restTemplate.postForEntity(url, "", String.class, urlVariables);
 }
Ejemplo n.º 5
0
  @Override
  @Nullable
  protected ResponseEntity doInBackground(Void... params) {
    try {
      HttpHeaders headers = new HttpHeaders();
      headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
      HttpEntity<String> request = new HttpEntity<>(headers);

      RestTemplate restTemplate = new RestTemplate();
      restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
      restTemplate.getMessageConverters().add(new FormHttpMessageConverter());
      ResponseEntity response = restTemplate.postForEntity(host, request, ResponseEntity.class);
      return response;
    } catch (Exception e) {
      Log.e("Http Request Exception", e.getMessage(), e);
    }
    return null;
  }
Ejemplo n.º 6
0
 @Test
 public void testRegisterValid() {
   MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
   map.add("name", "John");
   map.add("email", "*****@*****.**");
   map.add("password", "pass1234");
   map.add("confirmPassword", "pass1234");
   map.add("dateOfBirth", "05-04-1970");
   HttpHeaders headers = new HttpHeaders();
   headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
   HttpEntity<MultiValueMap<String, String>> entity =
       new HttpEntity<MultiValueMap<String, String>>(map, headers);
   ResponseEntity<String> register =
       template.postForEntity(getBasePath() + "/register", entity, String.class);
   assertThat(register.getStatusCode()).isEqualTo(HttpStatus.FOUND);
   assertThat(register.getHeaders().get("Location").isEmpty()).isFalse();
   assertThat(register.getHeaders().get("Location").get(0)).endsWith("/home");
 }
Ejemplo n.º 7
0
 @Override
 public void updateIndex(final String json) {
   final HttpHeaders headers = new HttpHeaders();
   headers.setContentType(MediaType.APPLICATION_JSON);
   final HttpEntity<String> entity = new HttpEntity<String>(json, headers);
   try {
     final ResponseEntity<String> response =
         solrRestTemplate.postForEntity(solrUpdateUrl, entity, String.class);
     final HttpStatus statusCode = response.getStatusCode();
     if (statusCode != HttpStatus.OK) {
       LOG.error(
           "Error updating solr index, status code {}. Response body {}",
           statusCode,
           response.getBody());
     }
   } catch (final Exception ex) {
     LOG.error("Exception updating solr index {}", ex.getMessage());
   }
 }
  public void createRecord(RaceActivityRecordDTO record, RaceEventData data) {
    documentStore.store(data);
    record.setDataReference(data.getId());

    try {
      ResponseEntity<RaceActivityRecordDTO> response =
          restTemplate.postForEntity(analyticsUrl, record, RaceActivityRecordDTO.class);
      logger.info("Posted race activity record.");
      if (response.getStatusCode() != HttpStatus.CREATED) {
        logger.error(
            "HTTP Error: {}. Couldn't post race activity record.", response.getStatusCode());
      }
    } catch (Exception e) {
      logger.error(
          "Exception: {} {}. Couldn't post race activity record to {}.",
          e.getClass().getSimpleName(),
          e.getMessage(),
          analyticsUrl);
    }
  }
 public ResponseEntity<Object> doPost(String url, Object request, Class<Object> responseType) {
   return connection.postForEntity(url, request, responseType);
 }
 private ResponseEntity<Application> registerApp(
     Application app, EmbeddedWebApplicationContext context) {
   int port = context.getEmbeddedServletContainer().getPort();
   return template.postForEntity(
       "http://localhost:" + port + "/api/applications", app, Application.class);
 }
Ejemplo n.º 11
-1
  @Override
  public void onApplicationEvent(final ContextRefreshedEvent arg0) {

    final RegisterServiceDTO dto = new RegisterServiceDTO();
    dto.setName("spahl_haug_dice_v1");
    dto.setDescription("DiceService von Louisa Spahl und Torben Haug");
    dto.setService("dice");
    try {
      SSLUtil.turnOffSslChecking();
      dto.setUri(
          "http://" + getLocalHostLANAddress().getHostAddress() + ":" + getServerPort() + "/dice");
    } catch (final UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (final KeyManagementException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (final NoSuchAlgorithmException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    final RestTemplate restTemplate = new RestTemplate();
    final String base64Creds = "YWJxMzI5OkRLR1JIZDIwMTUy";
    final HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic " + base64Creds);
    final HttpEntity<RegisterServiceDTO> request = new HttpEntity<RegisterServiceDTO>(dto, headers);
    final ResponseEntity<ResponseRegisterServiceDTO> registerServiceDTO =
        restTemplate.postForEntity(
            "https://vs-docker.informatik.haw-hamburg.de/ports/8053/services",
            request,
            ResponseRegisterServiceDTO.class);
    System.out.println(registerServiceDTO.getBody().get_uri());
    Main.setServiceID(registerServiceDTO.getBody().get_uri());
  }