Пример #1
0
 private HttpHeaders defaultHeaders() {
   return Builders.httpHeadersBuilder()
       .add("x-msg-secret-key", Constants.getMsgSecretKey())
       .add("x-tenant-id", String.valueOf(tenantService.getCurrentTenant().getId()))
       .add("content-type", MediaType.APPLICATION_FORM_URLENCODED_VALUE)
       .build();
 }
Пример #2
0
 @Override
 public void changeOwner(long roomId, long ownerId) throws MessageException {
   try {
     MultiValueMap<String, Object> params =
         Builders.multiValueMapBuilder().add("ownerId", String.valueOf(ownerId)).build();
     HttpEntity<?> entity = new HttpEntity<Object>(params, defaultHeaders());
     Map<String, String> urlVars = Maps.newHashMap();
     urlVars.put("id", String.valueOf(roomId));
     restTemplate.exchange(URL_ROOM, HttpMethod.GET, entity, Map.class, urlVars);
   } catch (Exception e) {
     throw new MessageException(e);
   }
 }
Пример #3
0
 public Room createRoom(String subject, long ownerId, List<Long> occupantIds, boolean special) {
   try {
     HttpHeaders headers = defaultHeaders();
     MultiValueMap<String, Object> params =
         Builders.multiValueMapBuilder()
             .add("subject", subject)
             .add("ownerId", String.valueOf(ownerId))
             .add("occupantIds", Joiner.on(',').join(occupantIds))
             .add("special", String.valueOf(special))
             .build();
     HttpEntity<?> entity = new HttpEntity<Object>(params, headers);
     HttpEntity<Room> response =
         restTemplate.exchange(URL_ROOMS, HttpMethod.POST, entity, Room.class, params);
     return response.getBody();
   } catch (Exception e) {
     throw new MessageException(e);
   }
 }
Пример #4
0
 public void addOccupants(long roomId, List<Long> occupantIds) {
   try {
     // headers
     HttpHeaders headers = defaultHeaders();
     // body参数
     MultiValueMap<String, Object> params =
         Builders.multiValueMapBuilder()
             .add("occupantIds", Joiner.on(',').join(occupantIds))
             .build();
     HttpEntity<?> entity = new HttpEntity<Object>(params, headers);
     // url参数
     Map<String, String> urlVars = Maps.newHashMap();
     urlVars.put("id", String.valueOf(roomId));
     restTemplate.exchange(URL_OCCUPANTS, HttpMethod.POST, entity, Map.class, urlVars);
   } catch (Exception e) {
     throw new MessageException(e);
   }
 }