Cómo obtener los registros de jersey en el servidor?


Estoy usando jersey para un DESCANSO WS. ¿Cómo puedo habilitar los registros de Jersey en el lado del servidor?

Larga historia: Obtengo una excepción en el lado del cliente, pero no veo nada en los registros de tomcat [Ni siquiera llega a mi método]. Dado que el seguimiento de la pila está diciendo "toReturnValue", obtuvo algo del servidor. Pero no se lo que dijo el servidor.

Exception in thread "main" java.lang.IllegalArgumentException: source parameter must not be null
 at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:98)
        at com.sun.xml.internal.ws.message.AbstractMessageImpl.readPayloadAsJAXB(AbstractMessageImpl.java:100)
        **at com.sun.xml.internal.ws.client.dispatch.JAXBDispatch.toReturnValue(JAXBDispatch.java:74)**
        at com.sun.xml.internal.ws.client.dispatch.DispatchImpl.doInvoke(DispatchImpl.java:191)
        at com.sun.xml.internal.ws.client.dispatch.DispatchImpl.invoke(DispatchImpl.java:195)
 38
Author: SANN3, 2010-02-25

5 answers

Si desea activar el registro en el lado del servidor, debe registrar el filtro de jersey LoggingFilter (en el lado del contenedor).

Este filtro registrará los encabezados de solicitud/respuesta y las entidades.

Esto es lo que necesita agregar a su clase ResourceConfig:

@ApplicationPath("/")
public class MyApplication extends ResourceConfig {

    public MyApplication() {
        // Resources.
        packages(MyResource.class.getPackage().getName());

        register(LoggingFilter.class);    
    }
}

Tenga en cuenta que el mismo filtro también funciona en el lado del cliente.

Client client = Client.create();
client.addFilter(new LoggingFilter());
 58
Author: Brian Clozel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-04-12 10:10:51

Jersey 2 ha quedado obsoleto LoggingFilter y ahora necesitas usar LoggingFeature. Para usarlo con un cliente puede usar la siguiente snipette:

this.client = ClientBuilder
            .newBuilder()
            .property(LoggingFeature.LOGGING_FEATURE_VERBOSITY_CLIENT, LoggingFeature.Verbosity.PAYLOAD_ANY)
            .property(LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_CLIENT, "WARNING")
            .build();

Y en el lado del servidor:

ResourceConfig config = new ResourceConfig(HelloWorldResource.class);
config.register(LoggingFeature.class);
 21
Author: Art,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-10-21 21:50:53

Jersey 2.0 utiliza org.glassfish.jersey.filter.LoggingFilter
Puede conectarlo con la ayuda de web.xml

<!-- Register my custom provider (not needed if it's in my.package) AND LoggingFilter. -->
        <init-param>
            <param-name>jersey.config.server.provider.classnames</param-name>
            <param-value>org.glassfish.jersey.filter.LoggingFilter</param-value>
        </init-param>

Se pueden encontrar más explicaciones aquí

Upd:

Después de la versión 2.23 LoggingFilter está obsoleto y debe utilizarse LoggingFeature. Puede encontrar más información en documentación oficial

 7
Author: lanwen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-17 15:24:01

Para Jersey 1.2 agregue la siguiente entrada en web.xml dentro de la etiqueta servlet:

    <init-param>
        <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
        <param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
    </init-param>
 6
Author: eeezyy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-07 10:53:01

¿Podría mostrarnos su código de cliente y decirnos también sobre la solicitud?

Esta excepción parece apuntar al paso de desmarcamiento de JAXB. Aparentemente recibiste algo de XML de tu API REST, pero no obtienes lo que estás esperando.

Tal vez el XSD que está utilizando para marshalling/unmarshalling está desactualizado o simplemente está mal.
Tal vez usted está tratando de obtener la entidad equivocada de la respuesta.

Prueba estos pasos y danos más detalles sobre tu problema:

Obtener el XML de la respuesta

Usando un cliente REST como Client REST simple (una extensión de Chrome), o tu código:

Builder builder = webResource.path("/yourapi/").accept("application/xml");

// get the client response
ClientResponse response = builder.get(ClientResponse.class);

// log the HTTP Status
logger.log("HTTP Status: " + response.getStatus());

// bypass the jaxb step and get the full response
// MyResource myResource = response.getEntity(MyResource.class);
String myResource = response.getEntity(String.class);
logger.log(myResource);

Valida este XML con el XSD que estás usando

Esta prueba debería fallar (si tengo razón).

 3
Author: Brian Clozel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-11-23 08:02:30