eclipse-ee4j / jersey

Eclipse Jersey Project - Read our Wiki:
https://github.com/eclipse-ee4j/jersey/wiki
Other
690 stars 353 forks source link

LoggingFeature doesn't increment the sequence number #3410

Open jerseyrobot opened 8 years ago

jerseyrobot commented 8 years ago

It's always 1 < or 1 >

Affected Versions

[2.23.1]

jerseyrobot commented 6 years ago
jerseyrobot commented 8 years ago

@glassfishrobot Commented Reported by adrianboimvaser

jerseyrobot commented 8 years ago

@glassfishrobot Commented adrianboimvaser said: A new LoggingInterceptor is created for every log entry.

jerseyrobot commented 8 years ago

@glassfishrobot Commented @pavelbucek said: Can you please provide reproducible testcase?

I just tested that by modifying HelloWorldTest#testConnection to:

@Test
    public void testConnection() {
        Invocation.Builder request = target().register(LoggingFeature.class).path(ROOT_PATH).request("text/plain");
        Response response = request.get();
        response = request.get();
        assertEquals(200, response.getStatus());
    }

and it produced

Jul 19, 2016 12:10:35 AM org.glassfish.jersey.test.grizzly.GrizzlyTestContainerFactory$GrizzlyTestContainer <init>
INFO: Creating GrizzlyTestContainer configured at the base URI http://localhost:9998/ Jul 19, 2016 12:10:37 AM org.glassfish.grizzly.http.server.NetworkListener start
INFO: Started listener bound to [localhost:9998]
Jul 19, 2016 12:10:37 AM org.glassfish.grizzly.http.server.HttpServer start
INFO: [HttpServer] Started.
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
Jul 19, 2016 12:10:38 AM org.glassfish.jersey.logging.LoggingInterceptor log
INFO: 1 * Server has received a request on thread grizzly-http-server-0
1 > GET http://localhost:9998/helloworld 1 > accept: text/plain
1 > accept-encoding: gzip,deflate
1 > connection: Keep-Alive
1 > host: localhost:9998
1 > user-agent: Jersey/2.24-SNAPSHOT (Apache HttpClient 4.5)

Jul 19, 2016 12:10:38 AM org.glassfish.jersey.logging.LoggingInterceptor log
INFO: 1 * Server responded with a response on thread grizzly-http-server-0
1 < 200
1 < Content-Type: text/plain
Hello World!

Jul 19, 2016 12:10:38 AM org.glassfish.jersey.logging.LoggingInterceptor log
INFO: 2 * Server has received a request on thread grizzly-http-server-1
2 > GET http://localhost:9998/helloworld 2 > accept: text/plain
2 > accept-encoding: gzip,deflate
2 > connection: Keep-Alive
2 > host: localhost:9998
2 > user-agent: Jersey/2.24-SNAPSHOT (Apache HttpClient 4.5)

Jul 19, 2016 12:10:38 AM org.glassfish.jersey.logging.LoggingInterceptor log
INFO: 2 * Server responded with a response on thread grizzly-http-server-1
2 < 200
2 < Content-Type: text/plain
Hello World!

Jul 19, 2016 12:10:38 AM org.glassfish.grizzly.http.server.NetworkListener shutdownNow
INFO: Stopped listener bound to [localhost:9998]

which seems to be OK..

jerseyrobot commented 8 years ago

@glassfishrobot Commented adrianboimvaser said: Happened with client in a multi-threaded environment. Where can I find HelloWorldTest?

jerseyrobot commented 8 years ago

@glassfishrobot Commented adrianboimvaser said: Should I stop using a shared Client and create a new one for each request in a new thread? That's clearly against the recommendations in the docs:

* Clients are heavy-weight objects that manage the client-side communication
 * infrastructure. Initialization as well as disposal of a {@code Client} instance
 * may be a rather expensive operation. It is therefore advised to construct only
 * a small number of {@code Client} instances in the application. Client instances
 * must be {@link #close() properly closed} before being disposed to avoid leaking
 * resources.
jerseyrobot commented 8 years ago

@glassfishrobot Commented @pavelbucek said: Have I suggested that somewhere? (I don't really see where did you came to a conclusion that not using shared client will resolve the issue. I used it for my testing..).

HelloWorldTest is located in HelloWorld example:

https://github.com/jersey/jersey/blob/master/examples/helloworld/src/test/java/org/glassfish/jersey/examples/helloworld/HelloWorldTest.java

jerseyrobot commented 8 years ago

@glassfishrobot Commented adrianboimvaser said: No, sorry, I didn't mean to offend you.

jerseyrobot commented 8 years ago

@glassfishrobot Commented @pavelbucek said: no need for apologies, nothing happened.

If you could construct reproducible testcase, it would help greatly, since I don't see what you see. I even tried to execute second request in other thread and it still works as expected.

(for the reference:

@Test
    public void testConnection() throws InterruptedException {
        final Invocation.Builder request = target().register(
new LoggingFeature(Logger.getAnonymousLogger(), Level.INFO, LoggingFeature.DEFAULT_VERBOSITY,
   LoggingFeature.DEFAULT_MAX_ENTITY_SIZE)).path(ROOT_PATH).request("text/plain");
        Response response = request.get();
        final CountDownLatch countDownLatch = new CountDownLatch(1);
        new Thread() {
            @Override
            public void run() {
System.out.println("test!");
System.out.println("status: " + request.get().getStatus());
countDownLatch.countDown();
            }
        }.start();

        countDownLatch.await();
        assertEquals(200, response.getStatus());
    }

)

jerseyrobot commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA JERSEY-3138