2010-09-16 52 views
1

如何在JAX-RS服务中获取XML和/或URL(字符串)?在JAX-RS服务中获取XML

例如在GET方法URL

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

和POST方法XML

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

回答

3

这工作我用的球衣。添加一个变量;

@Context private UriInfo uriInfo;

..你的资源类。这将提供给资源方法。您可以致电

uriInfo.getRequestURI()

示例;

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>"; 
    } 
} 

编辑: 你可能需要用注释您@Consumes(MediaType.APPLICATION_XML) POST方法来获取发布的数据。

相关问题