本文介绍了从浏览器调用REST Web服务URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经部署了简单的REST界面。可以说我的REST服务部署在以下上下文路径中:
I have deployed simple REST interface. Lets say my REST service is deployed in this context path:
http://localhost:8080/Engine/services/Evaluation
然后我这样调用URL:
Then I invoke URL like this:
http://localhost:8080/Engine/services/Evaluation?_wadl
我可以看到XML输出:
I can see the XML output:
<application>
<grammars/>
<resources base="http://localhost:8080/Engine/services/Evaluation">
<resource path="/Evaluation/">
<resource path="initializeEvaluation/{localeCode}">
<param name="localeCode" style="template" type="xs:string"/>
<method name="GET">
<request>
<representation mediaType="application/octet-stream"/>
</request>
<response>
<representation mediaType="application/json"/>
</response>
</method>
</resource>
</resource>
</resources>
</application>
问题是如何使用浏览器中的URL调用方法?
The question is how to call the method with the URL from the browser?
我尝试输入:
http://localhost:8080/Engine/services/Evaluation/initializeEvaluation?localeCode=en-GB
但是我有:
2013-01-30 11:22:13,477 [http-bio-8080-exec-3] WARN JAXRSInInterceptor - No root resource matching request path /Engine/services/Evaluation/initializeEvaluation has been found, Relative Path: /initializeEvaluation. Please enable FINE/TRACE log level for more details.
2013-01-30 11:22:13,479 [http-bio-8080-exec-3] WARN WebApplicationExceptionMapper - javax.ws.rs.NotFoundException
我在REST上是一个新手,但据我了解,URL应该像上面一样。为什么然后我又变得异常?
I am very new at REST but as far as I understand the URL should be like above. Why then I am getting and exception?
我的Java接口:
@Path("/Evaluation/")
@Produces(MediaType.APPLICATION_JSON)
public interface EvaluationService {
@GET
@Path("initializeEvaluation/{localeCode}")
EvaluationStatus initializeEvaluation(ClientType client, @PathParam("localeCode") String localeCode)
throws EvaluationException;
}
我正在使用Apache CXF 2.7.0,JDK 1.7, Tomcat 7。
I am using Apache CXF 2.7.0, JDK 1.7, Tomcat 7.
推荐答案
这是路径参数。因此,我认为该网址应为:
It's a path param. Thus, I believe the URL should be:
http://localhost:8080/Engine/services/Evaluation/initializeEvaluation/en-GB
这篇关于从浏览器调用REST Web服务URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!