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
516 views
in Technique[技术] by (71.8m points)

jax rs - Is there a way to list available rest services on glassfish?

can't see where the error could be constructing the REST URL.

curl -X GET http://localhost:8080/julian/webapi/convert/2000-01-01-12-00-00
GlassFish Server Open Source Edition 5.1.0 - Error report

HTTP Status 404 - Not Found


type Status report

messageNot Found

descriptionThe requested resource is not available.


I made some changes to web.xml for it to be deployed successfully. Can't see where the error could be. Java file which constructs the REST URL.
@Path("/")
public class Julian {
    @GET
    @Produces("text/plain")
    @Path("convert/{inDate : .*}")
    public String convert(
            @PathParam("inDate") String inDate) {
            
        Function<Double,Integer> trunc = (d) ->
        d.intValue();
                
        // yyy-MM-dd-HH-mm-ss
        int inYear = Integer.parseInt(inDate.substring(0,4));
        int inMonth = Integer.parseInt(inDate.substring(5,7));
        int inDay = Integer.parseInt(inDate.substring(8,10));
        int inHour = Integer.parseInt(inDate.substring(11,13));
        int inMinute = Integer.parseInt(inDate.substring(14,16));
                
        double jd = 367 * inYear - trunc.apply(7.0 * (
                inYear + trunc.apply(inMonth+9.0)/12
                ) / 4)
                +trunc.apply(275.0 * inMonth / 9)
                + inDay
                + 1721013.5
                + 1.0 * (inHour + inMinute / 60.0) /24
                - 0.5*Math.signum(100*inYear + inMonth - 190002.5)
                +0.5;
        
        return "" + jd;
        
    }

}

WEB.XML

<web-app xmlns:xsi=
   "http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://xmlns.jcp.org/xml/ns/javaee"
 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
  http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0">
    
  <display-name>julian</display-name>
  <servlet>
  <servlet-name>Application</servlet-name>
  <servlet-class>javax.ws.rs.core.Application</servlet-class>
  </servlet>
  
  <servlet-mapping>
  <servlet-name>Application</servlet-name>
  <url-pattern>/webapi/*</url-pattern>
  </servlet-mapping>
    
</web-app>
question from:https://stackoverflow.com/questions/65886328/is-there-a-way-to-list-available-rest-services-on-glassfish

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

1 Reply

0 votes
by (71.8m points)
Waitting for answers

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

...