2
回答
REST的复杂URL映射问题求助
滴滴云服务器,限时包月0.9元,为开发者而生>>>   
比如这样一个URL:

http://localhost:8080/rest/cxf/person/persons/1/hobby/2
我这样写为什么老是提示404 not found,特来求高人相助!!!!

//不配置@Produces则默认接口返回值数据的MIME类型是application/xml
@Path(value = "/person")  
@Produces({"application/xml"})
public interface PersonService {
/**
	 * @Title: queryHobbyOfPepole
	 * @Description: 返回某Person的某个爱好
	 * @param personId
	 * @param hobbyId
	 * @return
	 */
	@GET
	@Path("/persons/{personId}/hobby/{hobbyId}")
	public Hobby queryHobbyOfPepole(@PathParam("personId") int personId,@PathParam("hobbyId") int hobbyId);

}



下面是客户端调用代码:
@Test
	public void testGetHobby() {
		ClientConfig config = new DefaultClientConfig();  
        Client client = Client.create(config);
        WebResource service = client.resource(getBaseURI());
        String result = service
        	.path("person").path("persons").path("1")
        	.path("hobby").path("2")
        	.accept(MediaType.APPLICATION_XML)
        	.get(String.class);
        System.out.println(result.toString());
	}



下面是调用后返回的异常信息:
2013-12-26 18:13:23 org.apache.cxf.jaxrs.utils.JAXRSUtils findTargetMethod
警告: No operation matching request path "/rest/cxf/person/1/hobby/2" is found, Relative Path: /1/hobby/2, HTTP Method: GET, ContentType: */*, Accept: application/xml,. Please enable FINE/TRACE log level for more details.
2013-12-26 18:13:23 org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
警告: javax.ws.rs.ClientErrorException: HTTP 404 Not Found
	at org.apache.cxf.jaxrs.utils.JAXRSUtils.findTargetMethod(JAXRSUtils.java:540)
	at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:181)
	at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:86)
	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
	at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
	at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:287)
	at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:251)
	at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1088)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1024)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
	at org.eclipse.jetty.server.Server.handle(Server.java:370)
	at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
	at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971)
	at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1033)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
	at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:667)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
	at java.lang.Thread.run(Unknown Source)



举报
vnetoolxw
发帖于4年前 2回/4K+阅
顶部