带有Gradle设置的泽西岛产生http 500内部服务器错误

时间:2018-11-02 22:22:22

标签: java eclipse gradle jersey jersey-client

我正在尝试使我的第一个球衣JAX-RS示例使用gradle在Eclipse中运行。我已经在这里找到许多有关http500主题的信息,但是我的情况有些不同。在我看来,错误消息本身并不是很有帮助,为什么抛出该错误消息。在其他示例中,产生了较大的堆栈跟踪。 当我的ToDo对象已经创建并由 ToDoResource 返回时,抛出错误。非常感谢您的帮助。

堆栈跟踪

Exception in thread "main" javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
    at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:1098)
    at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:883)
    at org.glassfish.jersey.client.JerseyInvocation.lambda$invoke$1(JerseyInvocation.java:767)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:316)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:298)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:229)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:414)
    at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:765)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:428)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:324)
    at xxx.yyy.firstwebapp.client.TodoTest.main(TodoTest.java:27)

REST客户端

public class TodoTest {
    public static void main(String[] args) {
        ClientConfig config = new ClientConfig();
        Client client = ClientBuilder.newClient(config);

        WebTarget target = client.target(getBaseURI());
        try {
            String xmlAppResponse = target.path("rest").path("todo").request()
                    .accept(MediaType.APPLICATION_XML).get(String.class);
            System.out.println(xmlAppResponse);       
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}

构建Gradle设置

apply plugin: 'java'
apply plugin: 'war' 
apply plugin: 'com.bmuschko.tomcat'
apply plugin: 'eclipse-wtp'
project.webAppDirName = 'WebContent'
repositories {
    mavenCentral()      
}
dependencies {  
    ...
    compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.27'
    compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.27'
    compile 'javax.activation:activation:1.1'
}...

java类

@Path("/todo")
public class ToDoResource {

    @GET
    @Produces(MediaType.APPLICATION_XML)
    public ToDo getXML() {
        System.out.println("getXML() started");
        ToDo todo = new ToDo();
        System.out.println("Todo created");
        todo.setSummary("Application XML Todo Summary");
        System.out.println("Summary set");
        todo.setDescription("Application XML Todo Description");
        System.out.println("Description  set");
        return todo;   
    }
}

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class ToDo {     
    private String summary;     
    private String description;

    public ToDo() { }

    public String getSummary() {
        return summary;
    }
    public void setSummary(String summary) {
        this.summary = summary;
    }
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
}

0 个答案:

没有答案