2016-08-05 8 views
0

나는 PodList라는 복잡한 객체를 반환 내 저지 응용 프로그램에서 간단한 방법이 있습니다Jackson을 사용하여 JSON을 반환하면 Grizzly가 "요청 실패"500을 반환하는 이유는 무엇입니까?

@GET 
 
\t @Produces(MediaType.APPLICATION_JSON) 
 
\t @Path("/x") 
 
\t public PodList getPods(){ 
 
\t \t try (KubernetesClient client = new DefaultKubernetesClient();) { \t 
 
\t \t \t PodList pl = client.pods().list(); 
 
\t \t \t ObjectMapper om = new ObjectMapper(); 
 
\t \t \t try { 
 
\t \t \t \t String x = om.writeValueAsString(pl); 
 
\t \t \t \t System.out.println(x); 
 
\t \t \t } catch (JsonProcessingException ex) { 
 
\t \t \t \t Logger.getLogger(CatalogEndPoint.class.getName()). 
 
\t \t \t \t \t \t log(Level.SEVERE, null, ex); 
 
\t \t \t } 
 
\t \t \t return pl; 
 
\t \t } \t 
 
\t }

예외가 catch 블록에서 잡은없고 내가 인쇄물을보고, 그래서 나는 확신한다 Jackson은이 유형을 직렬화 할 수 있습니다. 내가 서버 추적을 활성화

 final ResourceConfig rc = new ResourceConfig(); 
 
     rc.packages(CatalogEndPoint.class.getPackage().getName()); 
 
     rc.register(JacksonFeature.class); 
 
\t \t rc.property("jersey.config.server.tracing.type", "ALL"); 
 
\t \t rc.property("jersey.config.server.tracing.threshold", "VERBOSE");

주 만 쓸모가 내 그리즐리 설정 코드에서

, 나는이 작업을 수행 할 확신합니다. CatalogEndPoint 리소스에서 "/ x"경로를 쳤을 때 아무 것도 추적하지 않습니다.

#logging.properties file. 
 
# "handlers" specifies a comma separated list of log Handler 
 
# classes. These handlers will be installed during VM startup. 
 
# Note that these classes must be on the system classpath. 
 
# By default we only configure a ConsoleHandler, which will only 
 
# show messages at the INFO and above levels. 
 

 
\t handlers= java.util.logging.ConsoleHandler 
 

 
# Default global logging level. 
 
# This specifies which kinds of events are logged across 
 
# all loggers. For any given facility this global level 
 
# can be overriden by a facility-specific level. 
 
# Note that the ConsoleHandler also has a separate level 
 
# setting to limit messages printed to the console. 
 
.level=ALL 
 
com.sun.jersey.level=ALL 
 

 

 
# Limit the messages that are printed on the console to INFO and above. 
 

 
    java.util.logging.ConsoleHandler.level = ALL 
 
    java.util.logging.ConsoleHandler.formatter = 
 
            java.util.logging.SimpleFormatter

그런 다음 마지막으로 내가 스택 추적을

INE: service exception 
 
org.glassfish.jersey.server.ContainerException: java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.type.TypeFactory.constructType(Ljava/lang/reflect/Type;Ljava/lang/Class;)Lcom/fasterxml/jackson/databind/JavaType; 
 
\t at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer$ResponseWriter.rethrow(GrizzlyHttpContainer.java:324) 
 
\t at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer$ResponseWriter.failure(GrizzlyHttpContainer.java:306) 
 
\t at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:509) 
 
\t at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:334) 
 
\t at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) 
 
\t at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) 
 
\t at org.glassfish.jersey.internal.Errors.process(Errors.java:315) 
 
\t at org.glassfish.jersey.internal.Errors.process(Errors.java:297) 
 
\t at org.glassfish.jersey.internal.Errors.process(Errors.java:267) 
 
\t at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) 
 
\t at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) 
 
\t at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) 
 
\t at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:384) 
 
\t at org.glassfish.grizzly.http.server.HttpHandler$1.run(HttpHandler.java:224) 
 
\t at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591) 
 
\t at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571) 
 
\t at java.lang.Thread.run(Thread.java:745) 
 
Caused by: java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.type.TypeFactory.constructType(Ljava/lang/reflect/Type;Ljava/lang/Class;)Lcom/fasterxml/jackson/databind/JavaType; 
 
\t at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector._fullSerializationType(JaxbAnnotationIntrospector.java:1465) 
 
\t at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector._findContentAdapter(JaxbAnnotationIntrospector.java:1401) 
 
\t at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector.findSerializationContentConverter(JaxbAnnotationIntrospector.java:804) 
 
\t at com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair.findSerializationContentConverter(AnnotationIntrospectorPair.java:372) 
 
\t at com.fasterxml.jackson.databind.ser.std.StdSerializer.findConvertingContentSerializer(StdSerializer.java:417) 
 
\t at com.fasterxml.jackson.databind.ser.std.MapSerializer.createContextual(MapSerializer.java:346) 
 
\t at com.fasterxml.jackson.databind.SerializerProvider.handlePrimaryContextualization(SerializerProvider.java:928) 
 
\t at com.fasterxml.jackson.databind.ser.AnyGetterWriter.resolve(AnyGetterWriter.java:89) 
 
\t at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.resolve(BeanSerializerBase.java:350) 
 
\t at com.fasterxml.jackson.databind.ser.SerializerCache.addAndResolveNonTypedSerializer(SerializerCache.java:197) 
 
\t at com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1177) 
 
\t at com.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:490) 
 
\t at com.fasterxml.jackson.databind.SerializerProvider.findTypedValueSerializer(SerializerProvider.java:688) 
 
\t at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:107) 
 
\t at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1428) 
 
\t at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:930) 
 
\t at com.fasterxml.jackson.jaxrs.base.ProviderBase.writeTo(ProviderBase.java:650) 
 
\t at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265) 
 
\t at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250) 
 
\t at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) 
 
\t at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:106) 
 
\t at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) 
 
\t at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:86) 
 
\t at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) 
 
\t at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1130) 
 
\t at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:711) 
 
\t at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:444) 
 
\t at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:434) 
 
\t at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:329) 
 
\t ... 13 more

+0

아마도 컴파일 타임과 런타임 환경 사이의 라이브러리 버전 차이 일 것입니다. –

답변

0

아마 볼 수 있습니다 : 그럼, 내가 한 것은 설치에 자바 logging.properties 파일이었다 컴파일 시간과 런타임 환경 간의 라이브러리 버전 차이.

메시지는 컴파일 된 코드는 방법을 클래스 com.fasterxml.jackson.databind.type.TypeFactory에서

constructType(Type t, Class c) 

를 호출하는 시도라고하지만 그 방법은 존재하지 않습니다. 성공적으로 컴파일되었으므로 해당 메소드가있는 라이브러리 버전에 대해 컴파일했지만 런타임에 사용 가능한 버전에서는 사용할 수 없습니다.

0

내 프로젝트의 Maven pom.xml에는 Jackson의 종속성이 명시 적으로 포함되어있었습니다. 이것은 잭슨 저지의 버전이 예상했던 것 사이의 버전 불일치를 초래했기 때문에 잘못된 행동이었습니다. 참조 Should we use jersey-media-json-jackson or jackson-jaxrs-json-provider in Jersey 2.5.1?

을 : : 또한

<dependency> 
     <groupId>org.glassfish.jersey.media</groupId> 
     <artifactId>jersey-media-json-jackson</artifactId> 
    </dependency> 

참조 :이 솔루션은 내 치어에서이 종속성을 포함하는 대신 잭슨 버전 자신을 선택하는 노력에 의해 저지 사용할 잭슨의 버전을 결정하도록했다 Spring 4.2.3 and fasterxml Jackson 2.7.0 are incompatible