Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

java - Requested resource not available jax-rs service

I wrote a jax-rs service using jersey, and the class is as follows,

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}

One to start the Engine:

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

Use another method than GET to start the engine (e.g. POST), since get should be only used to retrieve data.

Use resources within the URL instead of start or getreports.

@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();
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...