Это почти дубликат , но я нахожу ответ по этой ссылке несколько нелегитимным, потому что программа была исправлена путем изменения запроса на получение запроса на публикацию с путем '.... / получить».
Я получаю сообщение об ошибке ниже. Я не знаю, что я должен искать, чтобы исправить эту ошибку. Ни один из файлов, упомянутых в ошибке, не был написан мной, и я предполагаю, что это файлы в пакетах, которые я установил.
Другие решения рекомендовали включить строку import org.springframework.context.ApplicationContext или обновить мой проект maven . Я помню, как где-то читал, что мне может понадобиться установить переменную CATALINA_HOME, которую я установил в моем bashrc, и это тоже не сработало. Использование mvn dependency resolve
с последующим mvn clean install
и обновление моего проекта maven также не работали.
Я хотел бы знать, как узнать, где мне следует искать, основываясь на этой ошибке. Я не знаю, что это говорит мне, кроме того, что где-то есть незаконный аргумент и что заголовок заканчивается.
Ошибка возникает, когда я перезагружаю свой сервер Tomcat в Eclipse.
UPDATE
Я закончил тем, что бросил этот проект и начал новый проект, используя вместо этого javaspark. Мне все еще интересно, что люди говорят о том, как они будут отлаживать это. Для меня почти нет ничего интуитивного в сообщении об ошибке, которое мне было дано, и единственное, что я могу сделать, - это провести более общее исследование maven и CATALINA, чтобы лучше понять их, но я сомневаюсь, что это приведет к очевидные для меня ошибки.
С чисто теоретической точки зрения, какими будут ваши первые шаги после прочтения этих ошибок (кроме копирования и вставки ошибки в поисковую систему).
Error
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>