当您将containt类型设置为mediatype.application_xml时,apachi tomcat report 500 erorr

uidvcgyl  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(221)

我正在使用appachi tomcat 10.0、jakarta jersey 3.0.2和eclipse 2021-03
我创建了动态web项目ib eclipse,创建了如下所示的web服务代码,同时返回对象,因为应用程序xml服务器给出了500个错误。

HTTP Status 500 – Internal Server Error

Type Status Report

Message Internal Server Error

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Apache Tomcat/10.0.6

服务器日志如下所示

May 29, 2021 7:10:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version name:   Apache Tomcat/10.0.6
May 29, 2021 7:10:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          May 8 2021 15:24:15 UTC
May 29, 2021 7:10:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version number: 10.0.6.0
May 29, 2021 7:10:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Windows 10
May 29, 2021 7:10:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            10.0
May 29, 2021 7:10:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
May 29, 2021 7:10:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             C:\Users\ranadhirw\.p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_15.0.2.v20210201-0955\jre
May 29, 2021 7:10:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           15.0.2+7-27
May 29, 2021 7:10:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
May 29, 2021 7:10:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         D:\eclipse-workspace-new\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
May 29, 2021 7:10:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         C:\Program Files\Apache Software Foundation\Tomcat 10.0
May 29, 2021 7:10:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=D:\eclipse-workspace-new\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
May 29, 2021 7:10:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 10.0
May 29, 2021 7:10:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=D:\eclipse-workspace-new\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
May 29, 2021 7:10:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
May 29, 2021 7:10:22 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -XX:+ShowCodeDetailsInExceptionMessages
May 29, 2021 7:10:22 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [C:\Users\ranadhirw\.p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_15.0.2.v20210201-0955\jre\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Users/ranadhirw/.p2/pool/plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_15.0.2.v20210201-0955/jre/bin/server;C:/Users/ranadhirw/.p2/pool/plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_15.0.2.v20210201-0955/jre/bin;C:\Python\Python39\Scripts\;C:\Python\Python39\;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\ranadhirw\AppData\Local\Microsoft\WindowsApps;;C:\Users\ranadhirw\OneDrive\Desktop;;.]
May 29, 2021 7:10:23 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
May 29, 2021 7:10:24 PM org.apache.catalina.startup.Catalina load
INFO: Server initialization in [1888] milliseconds
May 29, 2021 7:10:24 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Catalina]
May 29, 2021 7:10:24 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet engine: [Apache Tomcat/10.0.6]
May 29, 2021 7:10:29 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
May 29, 2021 7:10:31 PM org.glassfish.jersey.server.wadl.WadlFeature configure
WARNING: JAXBContext implementation could not be found. WADL feature is disabled.
May 29, 2021 7:10:32 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
May 29, 2021 7:10:32 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in [8217] milliseconds
Hi I am Here
Hi 3 I am Here

休息很好。 enter code here book.java

package book;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/book")
public class Book {
/*
    @GET
    @Produces(MediaType.TEXT_XML)
    public String sayHello() {

        String response = "<?xml version='1.0' ?>"+
                            "<hello> Hello XML </hello>";

        return response;
    }
    */
    @GET
    @Produces(MediaType.APPLICATION_XML)
    public BookDesc getBookDetails() {

        System.out.println("Hi I am Here");

        BookDesc b1 = new BookDesc();
        b1.setName("Java");
        b1.setPrice(400);
        System.out.println("Hi 3 I am Here");
        return b1;
    }

}

bookdesc.java

package book;

import jakarta.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class BookDesc {

    private String name;
    private int price;

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getPrice() {
        return price;
    }
    public void setPrice(int price) {
        this.price = price;
    }
}

wen.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
  <display-name>WSdemo</display-name>
    <servlet>
        <servlet-name>javaws</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>book</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>javaws</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>  
</web-app>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题