@RequestMapping("/{userPseudo}/validateStep4")
  public ResponseEntity<Void> validateStep4(
      @PathVariable("userPseudo") String userPseudo,
      @RequestParam("userHostAndPort") String userHostAndPort) {
    log.info("Validation step 4 for player {} with data {}", userPseudo, userHostAndPort);

    ResponseEntity<Void> result = new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);

    String url = "http://" + userHostAndPort + "/zen/env";

    ResponseEntity<String> responseEntityShouldFail =
        restTemplate.exchange(
            url, HttpMethod.GET, new HttpEntity<>(new HttpHeaders()), String.class);

    byte[] encodedAuth = Base64.encodeBase64("zenika:technozaure".getBytes());
    String authHeader = "Basic " + new String(encodedAuth);

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.set("Authorization", authHeader);
    HttpEntity<String> entity = new HttpEntity<>(headers);

    ResponseEntity<String> responseEntityShouldSucceed =
        restTemplate.exchange(url, HttpMethod.GET, entity, String.class);

    if (responseEntityShouldFail.getStatusCode() != HttpStatus.OK
        && responseEntityShouldSucceed.getStatusCode() == HttpStatus.OK) {
      gameStepRepository.save(new GameStep(userPseudo, Step._4));
      result = new ResponseEntity<Void>(HttpStatus.OK);
      broadcastGameStatus();
    }

    return result;
  }
 @Test
 public void accept() {
   MediaType mediaType1 = new MediaType("text", "html");
   MediaType mediaType2 = new MediaType("text", "plain");
   List<MediaType> mediaTypes = new ArrayList<MediaType>(2);
   mediaTypes.add(mediaType1);
   mediaTypes.add(mediaType2);
   headers.setAccept(mediaTypes);
   assertEquals("Invalid Accept header", mediaTypes, headers.getAccept());
   assertEquals("Invalid Accept header", "text/html, text/plain", headers.getFirst("Accept"));
 }
 /**
  * Retrieve the attribute of an entity
  *
  * @param entityId the entity ID
  * @param type optional entity type to avoid ambiguity when multiple entities have the same ID,
  *     null or zero-length for empty
  * @param attributeName the attribute name
  * @return
  */
 public ListenableFuture<String> getAttributeValueAsString(
     String entityId, String type, String attributeName) {
   UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
   builder.path("v2/entities/{entityId}/attrs/{attributeName}/value");
   addParam(builder, "type", type);
   HttpHeaders httpHeaders = cloneHttpHeaders();
   httpHeaders.setAccept(Collections.singletonList(MediaType.TEXT_PLAIN));
   return adapt(
       request(
           HttpMethod.GET,
           builder.buildAndExpand(entityId, attributeName).toUriString(),
           httpHeaders,
           null,
           String.class));
 }
Ejemplo n.º 4
0
  public List<Trainee> getTrainees() {
    RestTemplate restTemplate = new RestTemplate();

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.add("X-Parse-Application-Id", "EobLmBPuMPa7y2eZ5yt4ELaWEeEJUprGKrx78zDz");
    headers.add("X-Parse-REST-API-Key", "EnT6MvmYC5cK6lH6iBZ0eu3AcBUm5npvdlkdZYxV");
    HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);

    final String uri = "https://api.parse.com/1/classes/Trainee";
    ResponseEntity<TraineeList> trainees =
        restTemplate.exchange(uri, HttpMethod.GET, entity, TraineeList.class);

    return trainees.getBody().getTrainees();
  }
 private Ngsi2Client() {
   // set default headers for Content-Type and Accept to application/JSON
   httpHeaders = new HttpHeaders();
   httpHeaders.setContentType(MediaType.APPLICATION_JSON);
   httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
 }