2010-09-16 8 views
1

Comment puis-je obtenir du code XML et/ou une URL (chaîne) dans le service JAX-RS?Obtention de code XML dans le service JAX-RS

Par exemple dans l'URL de la méthode GET

@GET 
@Produces("application/xml; charset=UTF-8") 
public JaxrsPriceWrapper getPrice(@QueryParam("firstId"), @QueryParam("materialId"),...) { 
    //here I would like to get whole URL 
} 

et dans la méthode POST XML

@POST 
public JaxrsOrderWrapper insertOrder(OrderJaxrsVO jaxrsVO) { 
    //here the XML 
} 

Répondre

3

Cela fonctionne pour moi en utilisant Jersey. Ajouter une variable

@Context private UriInfo uriInfo;

.. à votre classe de ressources. Cela sera rendu disponible aux méthodes de ressources. Vous pouvez ensuite appeler

uriInfo.getRequestURI().

Exemple;

import javax.ws.rs.GET; 
import javax.ws.rs.Path; 
import javax.ws.rs.Produces; 
import javax.ws.rs.core.Context; 
import javax.ws.rs.core.MediaType; 
import javax.ws.rs.core.UriInfo; 

@Path("/jerseytest") 
public class Server 
{ 
    @Context private UriInfo uriInfo; 

    @GET 
    @Produces(MediaType.APPLICATION_XML) 
    public String get() 
    { 
     System.out.println("jerseytest called: URI = " + uriInfo.getRequestUri()); 

     return "<response>hello world</response>"; 
    } 
} 

Edit: Vous avez probablement besoin d'annoter votre méthode POST avec @Consumes(MediaType.APPLICATION_XML) pour obtenir les données affichées.