Pass non-success response codes through federated client.
This commit is contained in:
		
							parent
							
								
									74f71fd8a6
								
							
						
					
					
						commit
						2f85cd214e
					
				|  | @ -35,11 +35,7 @@ import org.whispersystems.textsecuregcm.entities.AccountCount; | |||
| import org.whispersystems.textsecuregcm.entities.AttachmentUri; | ||||
| import org.whispersystems.textsecuregcm.entities.ClientContact; | ||||
| import org.whispersystems.textsecuregcm.entities.ClientContacts; | ||||
| import org.whispersystems.textsecuregcm.entities.IncomingMessage; | ||||
| import org.whispersystems.textsecuregcm.entities.IncomingMessageList; | ||||
| import org.whispersystems.textsecuregcm.entities.MessageResponse; | ||||
| import org.whispersystems.textsecuregcm.entities.PreKey; | ||||
| import org.whispersystems.textsecuregcm.entities.RelayMessage; | ||||
| import org.whispersystems.textsecuregcm.entities.UnstructuredPreKeyList; | ||||
| import org.whispersystems.textsecuregcm.util.Base64; | ||||
| 
 | ||||
|  | @ -69,7 +65,6 @@ public class FederatedClient { | |||
|   private static final String USER_COUNT_PATH     = "/v1/federation/user_count"; | ||||
|   private static final String USER_TOKENS_PATH    = "/v1/federation/user_tokens/%d"; | ||||
|   private static final String RELAY_MESSAGE_PATH  = "/v1/federation/messages/%s/%s"; | ||||
|   private static final String PREKEY_PATH         = "/v1/federation/key/%s"; | ||||
|   private static final String PREKEY_PATH_DEVICE  = "/v1/federation/key/%s/%s"; | ||||
|   private static final String ATTACHMENT_URI_PATH = "/v1/federation/attachment/%d"; | ||||
| 
 | ||||
|  | @ -96,34 +91,36 @@ public class FederatedClient { | |||
|       WebResource resource = client.resource(peer.getUrl()) | ||||
|                                    .path(String.format(ATTACHMENT_URI_PATH, attachmentId)); | ||||
| 
 | ||||
|       return resource.accept(MediaType.APPLICATION_JSON) | ||||
|       ClientResponse response = resource.accept(MediaType.APPLICATION_JSON) | ||||
|                                         .header("Authorization", authorizationHeader) | ||||
|                      .get(AttachmentUri.class) | ||||
|                      .getLocation(); | ||||
|                                         .get(ClientResponse.class); | ||||
| 
 | ||||
|       if (response.getStatus() < 200 || response.getStatus() >= 300) { | ||||
|         throw new WebApplicationException(clientResponseToResponse(response)); | ||||
|       } | ||||
| 
 | ||||
|       return response.getEntity(AttachmentUri.class).getLocation(); | ||||
| 
 | ||||
|     } catch (UniformInterfaceException | ClientHandlerException e) { | ||||
|       logger.warn("Bad URI", e); | ||||
|       throw new IOException(e); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   public Optional<PreKey> getKey(String destination)  { | ||||
|     try { | ||||
|       WebResource resource = client.resource(peer.getUrl()).path(String.format(PREKEY_PATH, destination)); | ||||
|       return Optional.of(resource.accept(MediaType.APPLICATION_JSON) | ||||
|                                  .header("Authorization", authorizationHeader) | ||||
|                                  .get(PreKey.class)); | ||||
|     } catch (UniformInterfaceException | ClientHandlerException e) { | ||||
|       logger.warn("PreKey", e); | ||||
|       return Optional.absent(); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   public Optional<UnstructuredPreKeyList> getKeys(String destination, String device) { | ||||
|     try { | ||||
|       WebResource resource = client.resource(peer.getUrl()).path(String.format(PREKEY_PATH_DEVICE, destination, device)); | ||||
|       return Optional.of(resource.accept(MediaType.APPLICATION_JSON) | ||||
| 
 | ||||
|       ClientResponse response = resource.accept(MediaType.APPLICATION_JSON) | ||||
|                                         .header("Authorization", authorizationHeader) | ||||
|                                  .get(UnstructuredPreKeyList.class)); | ||||
|                                         .get(ClientResponse.class); | ||||
| 
 | ||||
|       if (response.getStatus() < 200 || response.getStatus() >= 300) { | ||||
|         throw new WebApplicationException(clientResponseToResponse(response)); | ||||
|       } | ||||
| 
 | ||||
|       return Optional.of(response.getEntity(UnstructuredPreKeyList.class)); | ||||
| 
 | ||||
|     } catch (UniformInterfaceException | ClientHandlerException e) { | ||||
|       logger.warn("PreKey", e); | ||||
|       return Optional.absent(); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Moxie Marlinspike
						Moxie Marlinspike