2015-02-01 10 views
7

Sto cercando di seguire la documentazione Jersey per consentire un non-200 risposta in caso di errore (https://jersey.java.net/documentation/latest/representations.html#d0e3586)Jersey MessageBodyWriter non trovato per il tipo di supporto = text/plain

mio codice è simile:

@POST 
@Produces(MediaType.TEXT_PLAIN) 
@Consumes(MediaType.APPLICATION_FORM_URLENCODED) 
public ResponseBuilder getData(@FormParam("one") String one,@FormParam("two") String two,@FormParam("three") String three) { 
    if(one.isEmpty() || two.isEmpty() || three.isEmpty()) { 
     logger.error("Missing params for getData"); 
     throw new WebApplicationException(501); 
    } 
    return Response.ok(); 
} 
} 

Questo produce purtroppo il seguente errore:

[2015-02-01T16: 13: 02.157 + 0000] [GlassFish 4.1] [GRAVE] [] [org.glassfish.jersey.message.internal.WriterInterceptorExecutor ] [tid: _ThreadID = 27 _ThreadName = http-listener-1 (2)] [timeMillis: 1422807182157] [levelValue: 1000] [[ MessageBodyWriter non trovato per tipo di supporto = text/plain, type = class org.glassfish.jersey.message.internal.OutboundJaxrsResponse $ Builder , genericType = classe javax.ws.rs.core.Response $ ResponseBuilder.]]

risposta

6

il problema è il tipo di ritorno del metodo. Deve essere Response anziché ResponseBuilder.

modificare il codice al seguente e dovrebbe funzionare:

@POST 
@Produces(MediaType.TEXT_PLAIN) 
@Consumes(MediaType.APPLICATION_FORM_URLENCODED) 
public Response getData(@FormParam("one") String one,@FormParam("two") String two,@FormParam("three") String three) { 
    if(one.isEmpty() || two.isEmpty() || three.isEmpty()) { 
     logger.error("Missing params for getData"); 
     throw new WebApplicationException(501); 
    } 
    return Response.ok(); 
} 
+0

Oh mi sento così stupido in questo momento! –

+0

Nel caso in cui non aiuta. Ritorno alla risposta. –

Problemi correlati