简体   繁体   English

请求的资源不可用 jax-rs 服务

[英]Requested resource not available jax-rs service

I wrote a jax-rs service using jersey, and the class is as follows,我用jersey写了一个jax-rs服务,类如下,

I want to define the url for the following like this,我想为以下内容定义网址,

One to get the reports by passing parameters一种通过参数获取报表

http://localhost:8085/DiginReport/rs/Reports/getreport/ {test1:value,test2:value} http://localhost:8085/DiginReport/rs/Reports/getreport/ {test1:value,test2:value}

One to start the Engine:一启动引擎:

http://localhost:8085/DiginReport/rs/Reports/start http://localhost:8085/DiginReport/rs/Reports/start

 @Path("Reports")
public class ReportService {

    @GET
    @Path("/getreport}/{parameters}")
    @Produces(MediaType.TEXT_PLAIN)
    public Response getReport(@PathParam("reportName") String reportName,@PathParam("parameters") String parameters) throws KettleXMLException, KettleMissingPluginsException, JSONException, UnknownParamException {
        JSONArray jsonarr;
        return Response.status(200).entity("ok").build();
    }


    @GET
    @Path("{start}")
    @Produces(MediaType.TEXT_PLAIN)
    public Response startEngine(@PathParam("start") String command) {
        return Response.status(200).entity("ok").build();
    }
}

When i type this in url , it says resource not avaliable, http://localhost:8085/DiginReport/rs/Reports/start当我在 url 中输入它时,它说资源不可用, http://localhost:8085/DiginReport/rs/Reports/start

Try the following code.试试下面的代码。

I would also consider the following things:我还会考虑以下几点:

Pass Json data as application/json instead of string as path parameter (note that you need to escape.将 Json 数据作为application/json而不是 string 作为路径参数传递(注意你需要转义。

Use another method than GET to start the engine (eg POST ), since get should be only used to retrieve data.使用GET以外的其他方法来启动引擎(例如POST ),因为 get 应该只用于检索数据。

Use resources within the URL instead of start or getreports .使用 URL 中的资源而不是startgetreports

@Path("Reports")
public class ReportService {

    @GET
    @Path("/getreport/{parameters}")
    @Produces(MediaType.TEXT_PLAIN)
    public Response getReport(@PathParam("parameters") String parameters) throws KettleXMLException, KettleMissingPluginsException, JSONException, UnknownParamException {
        JSONArray jsonarr;
        return Response.status(200).entity("ok").build();
    }


    @GET
    @Path("/start")
    @Produces(MediaType.TEXT_PLAIN)
    public Response startEngine() {
        return Response.status(200).entity("ok").build();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM