Where do I verify the load path for my REST webser

2019-08-09 13:14发布

问题:

I have just finished coding webservices. I need to be able to debug the webservice load path. When I sudo restart service tomcat7, the /var/log/tomcat7/catalina.2014-09-29.log provides us with the package path for the webservice

INFO: Scanning for root resource and provider classes in the packages:
  com.swipex.backend.webservices

INFO: Root resource classes found:
  class com.swipex.backend.webservices.Registration
  class com.swipex.backend.webservices.Activation

When I run the junit test code to call these webservices, on running I get /var/log/tomcat7/localhost_access_log.2014-09-29.txt

"POST /SwipeXBackEnd/backend/Activation/Request HTTP/1.1" 404 1049

web.xml

    <xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>de.vogella.jersey.jaxb</display-name>
    <servlet>
        <servlet-name>SwipeXBackendServices</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.swipex.backend.webservices</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>SwipeXBackendServices</servlet-name>
        <url-pattern>/backend/*</url-pattern>
    </servlet-mapping>
</web-app>

Calling http://localhost:8080/SwipeXBackEnd/backend/Activation/Request from junit, I get

com.sun.jersey.api.client.UniformInterfaceException: POST http://localhost:8080/SwipeXBackEnd/backend/Activation/Request returned a response status of 304 Not Modified

Calling http://localhost:8080/Activation/Request from junit, I get

com.sun.jersey.api.client.UniformInterfaceException: POST http://localhost:8080/Activation/Request returned a response status of 404 Not Found

Is there a log file that verifies if the path /SwipeXBackEnd/backend/Activation/Request is correct for class com.swipex.backend.webservices.Activation

回答1:

I was not able to find any log file that has the load path defined. I surely hope someone can point it out. But I did find that the log4j prints into catalina.out. This is good enough to know for now, since this is where we can check if our load path got access via a junit test.

Junit Test

ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);

    //
    // Activation Service
    //
    URI url = UriBuilder.fromUri(
        "http://" + Globals.SERVER + ":" + Globals.PORT
            + "/MyCompanyBackend/Activate/Device").build();
    WebResource service = client.resource(url);
    System.out.println(url);
    // Get the data ready
    CDeviceDetails newDevice = new CDeviceDetails(all parameters here);
    String deviceUniqueIdentity = service.type(MediaType.APPLICATION_JSON)
        .post(String.class, newDevice);
    assertNotNull(deviceUniqueIdentity);
    System.out.println("Activation Passed " + deviceUniqueIdentity);

catalina.out : Here al log4j are printed

catalina.2014.. date : Here if your webservices load, you will notice something like this.

INFO: Root resource classes found:
  class com.yourpath.backend.webservices.Registration
  class com.yourpath.backend.webservices.Activation

Here you will also notice errors on the webserivces when you restart tomcat.

SEVERE: The web application [/MyCompanyBackend] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@e08586]) and a value of type [com.sun.jersey.server.impl.application.WebApplicationContext] (value [com.sun.jersey.server.impl.application.WebApplicationContext@81bfd8]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.This is very likely to create a memory leak.

localhost.2014-date : Here if there is a load issue, you will notice some errors.