2015-10-21 3 views
0

J'ai une méthode à Jersey ServletGestion des erreurs à Jersey API RESTful

@POST 
@Path("{type}:{bank_code}/accounts/{account}") 
@Consumes("application/x-www-form-urlencoded") 
@Produces("application/json") 
public String VerifyRecipient(MultivaluedMap<String,String> requestParamsPost, 
     @PathParam("type") String type, 
     @PathParam("bank_code") String bank_code, 
     @PathParam("account") String account) { 
    String ret=null; 
    Integer trxn_type_id=null; 
    this.logger = LogFactory.getLog(getClass()); 
    if(account==null){ 
     throw new WebApplicationException(Response.status(
       Response.Status.NOT_FOUND).type(
       MediaType.APPLICATION_JSON).entity(
       "Account is not found").build()); 

    } 

Si quelqu'un ne donne aucune valeur pour {compte} Je veux retourner un 404 non trouvé réponse JSON. Mais mon problème est quand il n'y a aucune valeur pour {compte} la demande n'atteint même pas ma méthode. Y a-t-il un moyen de gérer cela?

+0

La demande est faite comme: curl -i -X ​​POST -d "identifiant_initiateur = mobile_number: 9818526878 & customer_id = 8376118083" http: // localhost: 8080/eko/v1/banques/bank_id: 203/comptes/ne donnant aucune valeur pour le compte de paramètres – Nirmal

Répondre

0

Votre exemple est en train de frapper une URL différente - {type}:{bank_code}/accounts plutôt que {type}:{bank_code}/accounts/{account}. Si vous voulez un comportement sur mesure pour cela, vous devrez créer une autre méthode avec l'annotation @Path.