从浏览器调用REST Web服务URL

时间:2013-01-30 11:27:01

标签: java web-services rest tomcat cxf

我已经部署了简单的REST接口。让我们说我的REST服务部署在这个上下文路径中:

http://localhost:8080/Engine/services/Evaluation

然后我调用这样的URL:

http://localhost:8080/Engine/services/Evaluation?_wadl

我可以看到XML输出:

<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调用方法?

我试图输入:

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应该如上所述。为什么然后我得到和例外?

我的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。

3 个答案:

答案 0 :(得分:2)

这是一个路径参数。因此,我认为URL应该是:

http://localhost:8080/Engine/services/Evaluation/initializeEvaluation/en-GB

答案 1 :(得分:0)

使用RestClient插件,让您的生活更轻松。

答案 2 :(得分:0)

你的@Path注释中缺少一个/。

@Path("/initializeEvaluation/{localeCode}")