本文介绍了我在哪里验证REST Web服务的加载路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚完成了webservices的编码。我需要能够调试webservice加载路径。当我 sudo重启服务tomcat7 时, /var/log/tomcat7/catalina.2014-09-29.log 为我们提供了web服务的包路径

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

当我运行junit测试代码来调用这些webservices时,在运行时我得到 /var/log/tomcat7/localhost_access_log.2014-09-29.txt

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>

调用 http:// localhost:8080 / SwipeXBackEnd / backend / Activation /从junit请求,我得到

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

从junit调用 http:// localhost:8080 /激活/请求,我得到

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

是否有一个日志文件来验证路径 / SwipeXBackEnd / backend / Activation / Request 是否正确for class com.swipex.backend.webservices.Activation

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

推荐答案

我无法找到任何已定义加载路径的日志文件。我当然希望有人能指出来。但我确实发现log4j打印到catalina.out。这已经足够了解,因为我们可以通过junit测试检查我们的加载路径是否可以访问。

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测试

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 :这里打印了log4j

catalina.out : Here al log4j are printed

catalina.2014 .. date :如果您的网络服务加载,您会注意到这样的事情。

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

在重启tomcat时,您还会注意到webserivces上的错误。

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 :如果出现负载问题,你会发现一些错误。

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

这篇关于我在哪里验证REST Web服务的加载路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 04:08