Jetty服务器显示System.err

时间:2018-02-16 21:19:50

标签: java android jetty embedded-jetty

我在Android 6中运行Jetty server 7。它会侦听自定义的传入HTTP方法。

然而,在ADB日志中,它显示了一个特殊的System.err。关于它的信息不多。

02-17 02:33:31.461 12626 12626 W System.err: 2018-02-17 02:33:31.461:INFO:oejs.Server:jetty-7.x.y-SNAPSHOT
02-17 02:33:31.496 12626 12626 W System.err: 2018-02-17 02:33:31.495:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8082

这是什么错误。

这是代码实现,部分。 Complete MainActivity here

public class HelloWorld extends AbstractHandler
{
    @Override
    public void handle( String target,
                        Request baseRequest,
                        HttpServletRequest request,
                        HttpServletResponse response ) throws IOException,
                                                      ServletException
    {
        // Declare response encoding and types
        try {
            response.setContentType("text/html; charset=utf-8");
            // Declare response status code
            response.setStatus(HttpServletResponse.SC_OK);

            // Write back response
            response.getWriter().println("Hello World");
        } catch (UnsupportedEncodingException ec) {
            Log.w("JettyTest", "There is a UnsupportedEncodingException");
            Log.w("JettyTest", ec);
        }

        // Inform jetty that this request has now been handled
        baseRequest.setHandled(true);

        String requestMethod = baseRequest.getMethod().toUpperCase();

        StringBuffer jb = new StringBuffer();
        String line = null;

        Map<String, String> map = new HashMap<String, String>();

        try {

            switch (requestMethod) {

                case "POST":
                    // do post logic
                    Log.w("JettyTest", "Handle POST request");
                    break;

                case "NOTIFY":
                    // do notify logic
                    Log.w("JettyTest", "Handle NOTIFY request");

                    Enumeration headerNames = request.getHeaderNames();
                    while (headerNames.hasMoreElements()) {
                        String key = (String) headerNames.nextElement();
                        String value = request.getHeader(key);                        
                        map.put(key, value);

                    }                 

                    for (String key : map.keySet()) {
                        System.out.println(key + ": " + map.get(key));
                        Log.w("JettyTest", key + ": " + map.get(key));
                    }

                    Log.w("JettyTest", "Remote: "+request.getRemoteHost()+":"+request.getRemotePort());

                    BufferedReader reader = request.getReader();
                    while ((line = reader.readLine()) != null)
                        jb.append(line);

                    Log.w("JettyTest", jb.toString());
                    break;

                case "GET":
                    // do get logic
                    Log.w("JettyTest", "Handle GET request");
                    break;

                default:
                    // do default
                    Log.w("JettyTest", "NOT IMPLEMENTED");

            }

        } catch (Exception e) {
            Log.w("JettyTest", "Server error within handle method.");
            Log.w("JettyTest",e);
        }
    }
} // end HelloWorld

完成ADB日志

02-17 02:33:31.154 21021 21792 I ActivityManager: Start proc 12626:com.example.arjun.hellotest/u0a239 for activity com.example.arjun.hellotest/.MainActivity
02-17 02:33:31.160 12626 12626 I art     : Late-enabling -Xcheck:jni
02-17 02:33:31.198 12626 12626 D TidaProvider: TidaProvider()
02-17 02:33:31.228 22074 22141 D WtProcessController: set foreground process size 1 pid:12626pacakgeName:com.example.arjun.hellotest
02-17 02:33:31.262 12626 12626 W System  : ClassLoader referenced unknown path: /data/app/com.example.arjun.hellotest-1/lib/arm64
02-17 02:33:31.307 12626 12626 W art     : Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
02-17 02:33:31.441 12626 12626 I art     : Rejecting re-init on previously-failed class java.lang.Class<org.eclipse.jetty.util.log.JettyAwareLogger>
02-17 02:33:31.442 12626 12626 I art     : Rejecting re-init on previously-failed class java.lang.Class<org.eclipse.jetty.util.log.JettyAwareLogger>
02-17 02:33:31.461 12626 12626 W System.err: 2018-02-17 02:33:31.461:INFO:oejs.Server:jetty-7.x.y-SNAPSHOT
02-17 02:33:31.496 12626 12626 W System.err: 2018-02-17 02:33:31.495:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8082
02-17 02:33:31.526 12626 12673 D OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
02-17 02:33:31.536 12626 12626 D ActivityThreadInjector: clearCachedDrawables.
02-17 02:33:31.625 12626 12673 I Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.UM.5.3_RB1.06.00.01.211.056_msm8937_64_refs/tags/AU_LINUX_ANDROID_LA.UM.5.3_RB1.06.00.01.211.056__release_AU (I48a9d37399)
02-17 02:33:31.625 12626 12673 I Adreno-EGL: OpenGL ES Shader Compiler Version: XE031.08.00.00
02-17 02:33:31.625 12626 12673 I Adreno-EGL: Build Date: 10/18/16 Tue
02-17 02:33:31.625 12626 12673 I Adreno-EGL: Local Branch: 
02-17 02:33:31.625 12626 12673 I Adreno-EGL: Remote Branch: refs/tags/AU_LINUX_ANDROID_LA.UM.5.3_RB1.06.00.01.211.056
02-17 02:33:31.625 12626 12673 I Adreno-EGL: Local Patches: NONE
02-17 02:33:31.625 12626 12673 I Adreno-EGL: Reconstruct Branch: NOTHING
02-17 02:33:31.633 12626 12673 I OpenGLRenderer: Initialized EGL, version 1.4
02-17 02:33:31.672 12626 12673 E HAL     : Dawei load: module=/system/lib64/hw/gralloc.msm8937.so
02-17 02:33:31.681 12626 12673 E HAL     : Dawei load: module=/system/lib64/hw/gralloc.msm8937.so
02-17 02:33:53.361 12626 12661 W JettyTest: Handle GET request

Build.gradle我有implementation 'org.eclipse.jetty:jetty-webapp:7.6.21.v20160908'

1 个答案:

答案 0 :(得分:1)

这些事件显示在System.err

您在Jetty中配置了默认日志记录,通过System.err实现写入StdErrLog

您可能希望为Jetty编写自己的Logger接口以供使用。

您可能需要查看古代i-jetty代码库,了解有关如何执行此操作的一些想法。

例如:https://github.com/jetty-project/i-jetty/blob/master/i-jetty/i-jetty-server/src/main/java/org/mortbay/ijetty/log/AndroidLog.java

  

注意:i-jetty是针对Jetty 7, which is now EOL (End of Life)构建的。不建议在公共互联网上使用Jetty 7,特别是使用SSL / TLS。