如何解释错误“ java.lang.IllegalArgumentException:java.text.ParseException:标头结尾”

时间:2019-01-03 14:42:00

标签: java rest http tomcat jersey

This is almost a duplicate,但我发现该链接上的答案有点不合理,因为该程序是通过将get请求更改为带有路径'.... / get'的发布请求来解决的。

我收到以下错误。我不知道基于此错误应该解决什么。错误中提到的文件均不是我写的,我认为它们是我已安装的软件包中的文件。

其他解决方案建议我添加行import org.springframework.context.ApplicationContextupdate my maven project。我记得在某处读过我可能需要设置我的batarc中设置的CATALINA_HOME变量,但这也没有用。使用mvn dependency resolve后跟mvn clean install并更新我的Maven项目也不起作用。

我想知道如何根据此错误找出应该看的地方。我不知道它在告诉我什么,除了某个地方存在一些非法论点并且某些标题结束。

当我在Eclipse中重新启动tomcat服务器时,发生错误。

enter image description here


更新

我最终放弃了这个项目,而是使用javaspark开始了一个新项目。我仍然很好奇人们对于如何调试它不得不说些什么。对我来说,几乎没有关于错误消息的直觉,我唯一能想到的就是对Maven和CATALINA进行更一般的研究,以更好地理解它们,但是我怀疑这样做会否对我来说显而易见的错误。

从严格的理论角度来看,读取这些错误之后的第一步是什么(将错误复制并粘贴到搜索引擎中除外)。


错误

Jan. 03, 2019 8:19:09 A.M. org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
java.lang.IllegalArgumentException: java.text.ParseException: End of header
    at com.sun.jersey.core.header.MediaTypes.createQualitySourceMediaTypes(MediaTypes.java:289)
    at com.sun.jersey.core.header.MediaTypes.createQualitySourceMediaTypes(MediaTypes.java:274)
    at com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.addProduces(IntrospectionModeller.java:173)
    at com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.workOutSubResourceMethodsList(IntrospectionModeller.java:344)
    at com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.createResource(IntrospectionModeller.java:128)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.getAbstractResource(WebApplicationImpl.java:769)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.createAbstractResourceModelStructures(WebApplicationImpl.java:1595)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1356)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:180)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:799)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:795)
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790)
    at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:509)
    at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:339)
    at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:394)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:577)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1123)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1078)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:971)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4849)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5165)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1382)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1372)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:907)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:831)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1382)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1372)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:907)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:423)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:933)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:637)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:350)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)
Caused by: java.text.ParseException: End of header
    at com.sun.jersey.core.header.reader.HttpHeaderReaderImpl.getNextCharacter(HttpHeaderReaderImpl.java:168)
    at com.sun.jersey.core.header.reader.HttpHeaderReaderImpl.next(HttpHeaderReaderImpl.java:129)
    at com.sun.jersey.core.header.reader.HttpHeaderListAdapter.next(HttpHeaderListAdapter.java:111)
    at com.sun.jersey.core.header.reader.HttpHeaderListAdapter.next(HttpHeaderListAdapter.java:98)
    at com.sun.jersey.core.header.reader.HttpHeaderReader.nextToken(HttpHeaderReader.java:100)
    at com.sun.jersey.core.header.QualitySourceMediaType.valueOf(QualitySourceMediaType.java:87)
    at com.sun.jersey.core.header.reader.HttpHeaderReader$5.create(HttpHeaderReader.java:360)
    at com.sun.jersey.core.header.reader.HttpHeaderReader$5.create(HttpHeaderReader.java:358)
    at com.sun.jersey.core.header.reader.HttpHeaderReader.readList(HttpHeaderReader.java:481)
    at com.sun.jersey.core.header.reader.HttpHeaderReader.readList(HttpHeaderReader.java:473)
    at com.sun.jersey.core.header.reader.HttpHeaderReader.readAcceptableList(HttpHeaderReader.java:461)
    at com.sun.jersey.core.header.reader.HttpHeaderReader.readQualitySourceMediaType(HttpHeaderReader.java:365)
    at com.sun.jersey.core.header.reader.HttpHeaderReader.readQualitySourceMediaType(HttpHeaderReader.java:373)
    at com.sun.jersey.core.header.MediaTypes.createQualitySourceMediaTypes(MediaTypes.java:287)
    ... 53 more

Jan. 03, 2019 8:19:09 A.M. org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet [Jersey Web Application] in web application [/RestServer] threw load() exception
java.text.ParseException: End of header
    at com.sun.jersey.core.header.reader.HttpHeaderReaderImpl.getNextCharacter(HttpHeaderReaderImpl.java:168)
    at com.sun.jersey.core.header.reader.HttpHeaderReaderImpl.next(HttpHeaderReaderImpl.java:129)
    at com.sun.jersey.core.header.reader.HttpHeaderListAdapter.next(HttpHeaderListAdapter.java:111)
    at com.sun.jersey.core.header.reader.HttpHeaderListAdapter.next(HttpHeaderListAdapter.java:98)
    at com.sun.jersey.core.header.reader.HttpHeaderReader.nextToken(HttpHeaderReader.java:100)
    at com.sun.jersey.core.header.QualitySourceMediaType.valueOf(QualitySourceMediaType.java:87)
    at com.sun.jersey.core.header.reader.HttpHeaderReader$5.create(HttpHeaderReader.java:360)
    at com.sun.jersey.core.header.reader.HttpHeaderReader$5.create(HttpHeaderReader.java:358)
    at com.sun.jersey.core.header.reader.HttpHeaderReader.readList(HttpHeaderReader.java:481)
    at com.sun.jersey.core.header.reader.HttpHeaderReader.readList(HttpHeaderReader.java:473)
    at com.sun.jersey.core.header.reader.HttpHeaderReader.readAcceptableList(HttpHeaderReader.java:461)
    at com.sun.jersey.core.header.reader.HttpHeaderReader.readQualitySourceMediaType(HttpHeaderReader.java:365)
    at com.sun.jersey.core.header.reader.HttpHeaderReader.readQualitySourceMediaType(HttpHeaderReader.java:373)
    at com.sun.jersey.core.header.MediaTypes.createQualitySourceMediaTypes(MediaTypes.java:287)
    at com.sun.jersey.core.header.MediaTypes.createQualitySourceMediaTypes(MediaTypes.java:274)
    at com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.addProduces(IntrospectionModeller.java:173)
    at com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.workOutSubResourceMethodsList(IntrospectionModeller.java:344)
    at com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.createResource(IntrospectionModeller.java:128)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.getAbstractResource(WebApplicationImpl.java:769)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.createAbstractResourceModelStructures(WebApplicationImpl.java:1595)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1356)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:180)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:799)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:795)
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790)
    at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:509)
    at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:339)
    at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:394)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:577)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1123)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1078)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:971)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4849)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5165)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1382)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1372)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:907)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:831)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1382)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1372)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:907)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:423)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:933)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:637)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:350)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)

ServerInRest.java

    package serverPackage;

    import java.io.IOException;
    import java.util.LinkedList;

    import javax.ws.rs.GET;
    import javax.ws.rs.POST;
    import javax.ws.rs.PUT;
    import javax.ws.rs.Path;
    import javax.ws.rs.PathParam;
    import javax.ws.rs.Produces;
    import javax.ws.rs.core.Response;
    import javax.ws.rs.core.MediaType;

    import org.json.JSONObject;
    import org.json.simple.parser.JSONParser;
    import org.springframework.web.bind.annotation.RequestHeader;
    import org.springframework.context.ApplicationContext;


    @Path("/serverinrest")
    public class ServerInRest {

        //All the chatrooms available on this server
        protected LinkedList<MyChatroom> chatRooms = new LinkedList<MyChatroom>();  //All the chatrooms on this Server. This chatrooms list and the userlist and messagelist in the chatrooms are the only stateful part of this server.

        /*
         * Constructor for the server. Initializes the Chatroom list and JSON parser
         */
        public ServerInRest() {
            chatRooms = new LinkedList<MyChatroom>();
        }

        /*  Receives a message that is stored in the chatrooms messages list, and sends this message to all users in that chatroom.
         *  @Param user The user who is sending the message
         *  @Param room The room the message is to be sent to
         *  @Param message The message to be sent
         */
        @Path("/message")
        @PUT
        @Produces("Application/Json")
        public JSONObject message(@RequestHeader("user") String user, @RequestHeader("room") String room, @RequestHeader("message") String message) throws IOException {
            String header = "Message";
            String response = "Sent";
            MyChatroom c = this.roomObject(room);
            c.addMessage(message, user);
            return conToJson(header,response);
        }

        /*  Removes a user named in the user list of the chatroom
         *  @Param user The user to be removed
         *  @Param room The room the user will be removed from
         */
        @Path("/leave")
        @PUT
        @Produces("application/xml")
        public JSONObject leaveRoom(@RequestHeader("user") String user, @RequestHeader("room") String room) throws IOException {
            String header = "Left Room";
            String response = room;
            MyChatroom c = this.roomObject(room);
            c.removeUser(user);
            return conToJson(header, response);
        }

        /*  Adds a user to the user list of the chatroom
         *  @Param user The user to be added
         *  @Param room The room the user will be added to
         */
        @Path("/join")
        @PUT
        @Produces("application/")
        public JSONObject joinRoom(@RequestHeader("user") String user, @RequestHeader("room") String room){
            String header = "Joined Room";
            String response = room;
            MyChatroom c = this.roomObject(room);
            c.addUser(user);
            return conToJson(header, response);
        }

        /* Creates a room for this server and adds it to the servers room list
         * @Param room The name of the room
         */
        @Path("{r}")
        @POST
        @Produces("application/json")
        public String createRooms(@RequestHeader("room") String room){
            String header = "Created_room";
            String response = room;
            MyChatroom c = new MyChatroom(room);
            chatRooms.add(c);
            return "Created room" + response;//conToJson(header, response);
        }

        /* Lists the names of all the rooms on this server
         * @return A string containing the names of all the rooms
         */
        @GET
        @Produces("application/json") 
        public JSONObject listRooms(@RequestHeader("user") String room) {
            print("test1");
            String rooms = "Available_Rooms\n"; //% is used to determine if there needs to be user input or not
            for (int j = 0; j < chatRooms.size(); j++) {
                rooms = rooms + chatRooms.get(j).getName() + "\n";
            }
            print("test3");
            return conToJson("Rooms",rooms);
        }

        /* Takes a room name and returns the room object with that name
         * @param room: A string containing the name of the chatroom
         * @return A chatroom containing the same name as name
         */
        private MyChatroom roomObject(String room) {
            for (int i = 0; i < chatRooms.size(); i++) {
                MyChatroom c = chatRooms.get(i);
                if (c.getName().equals(room)) {
                    return c;
                }
            }
            return null;
        }

        /**
         * Lazy form of printing a string
         * @param x The string to be printed
         */
        private void print(String x) {
            System.out.println(x);
        }

        /* Returns a JSONObject representation of a string
         * @Param response: A string 
         * @Return A JSON representation of response
         */
        private JSONObject conToJson(String header, String response) {
            JSONObject j;
            try {
                j = new JSONObject();
                j.put(header,response);
            } catch (Exception e) {
                System.out.println("test0");
                return null;
            }
            return j;
        }

    }

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>RestServer</groupId>
  <artifactId>RestServer</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.1</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
        </configuration>
      </plugin>

    </plugins>
  </build>
  <dependencies>
        <dependency>
            <groupId>asm</groupId>
            <artifactId>asm</artifactId>
            <version>3.3.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-bundle</artifactId>
            <version>1.19.4</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20170516</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.19.4</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-core</artifactId>
            <version>1.19.4</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.6</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.3.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.2.11</version>
        </dependency>
        <dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.2.11</version>
</dependency>

    </dependencies>
</project>

0 个答案:

没有答案