끝에 Quickstart Archetype을 사용하여 Jersey Moxy 서비스를 만들고 있습니다. 내 코드가 잘 작동하고 일부 JSON 반환 할 수 있습니다. 그러나 내가 개발할 때 요청 처리기가 지원되지 않는 유형을 가지고 있다고 말하면 실수를하면 빈 500 응답이 표시되어 디버깅이 어려워집니다. 내가 @XmlElementRef로 잘못 속성을 장식 예를 들어, 내가 좋아하는 응답을 얻을 것이다 :Grizzly Jersey는 예외를 삼키고 있습니다.
$ curl -i http://localhost:8080/myapp/test
HTTP/1.1 500 Internal Server Error
Date: Thu, 05 Sep 2013 10:27:55 GMT
Connection: close
Content-Length: 0
아무 잘못없는 경우 역할을 할 서버 :
Sep 5, 2013 11:27:46 AM org.glassfish.grizzly.http.server.HttpServer start
INFO: [HttpServer] Started.
Jersey app started with WADL available at http://localhost:8080/application.wadl
Hit enter to stop it...
내가 로그 설정을 사용하여 시도 다음을 포함하는 파일 :
-Djava.util.logging.config.file=log.conf
이렇게하면 많은 출력이 생성되지만 어떤 종류의 예외도 표시되지 않습니다.
그리즐리 설정을 살펴 보았지만 우아한 오류 처리 기능을 해제 할 방법을 찾을 수 없습니다. 이상적으로 나는 예외를 던질 서버를 싶습니다. 제가 누락 된 것에 대한 제안은 있습니까? 내가 사용
전체 원형 생성 : 감사
mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-grizzly2 \
-DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \
-DgroupId=com.myapp -DartifactId=yarese-service -Dpackage=com.myapp \
-DarchetypeVersion=2.2
제안
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.moxy.json.MoxyJsonConfig;
import org.glassfish.jersey.server.ResourceConfig;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.net.URI;
import java.util.*;
public class Main {
// Base URI the Grizzly HTTP server will listen on
public static final String BASE_URI = "http://localhost:8080/";
/**
* Starts Grizzly HTTP server exposing JAX-RS resources defined in this application.
* @return Grizzly HTTP server.
*/
public static HttpServer startServer() {
// create a resource config that scans for JAX-RS resources and providers
// in com.myapp package
final ResourceConfig rc = new ResourceConfig().packages("com.myapp").registerInstances(new JsonMoxyConfigurationContextResolver());
// create and start a new instance of grizzly http server
// exposing the Jersey application at BASE_URI
return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
}
/**
* Main method.
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
final HttpServer server = startServer();
System.out.println(String.format("Jersey app started with WADL available at "
+ "%sapplication.wadl\nHit enter to stop it...", BASE_URI));
System.in.read();
server.stop();
}
@Provider
final static class JsonMoxyConfigurationContextResolver implements ContextResolver<MoxyJsonConfig> {
@Override
public MoxyJsonConfig getContext(Class<?> objectType) {
final MoxyJsonConfig configuration = new MoxyJsonConfig();
Map<String, String> namespacePrefixMapper = new HashMap<String, String>(1);
namespacePrefixMapper.put("http://www.w3.org/2001/XMLSchema-instance", "xsi");
configuration.setNamespacePrefixMapper(namespacePrefixMapper);
configuration.setNamespaceSeparator(':');
return configuration;
}
}
}
이 코드는 여기에 예제와 거의 동일합니다 :
여기 내 주요 코드입니다 받았습니다.
"... 나는 @XmlElementRef로 잘못 속성을 장식하면 ..."저도 같은 문제를 가지고 있었다. 로깅이 끝났다고해도 JAXB 어노테이션의 문제점을 정확히 알지 못했습니다. [이 저지 문제] (https://java.net/jira/browse/JERSEY-2321)를 열었습니다. –