2012-04-20 14 views
12

Jestem nowy na Jetty, próbowałem uruchomić program przykładowy tutaj "http://www.codeproject.com/Articles/128145/Run-Jetty-Web-Server-Within-Your-Application" ale mam komunikat o błędzie na mojej stronie "http://localhost:8585/runJetty/"Jetty: HTTP ERROR: 503/Usługa niedostępna

"HTTP ERROR: 503 
Problem accessing /runJetty/. Reason: 
    Service Unavailable 
-------------------------------------------------------------------------------- 
Powered by Jetty:// " 

Error log dostaję od Eclipse:

2012-04-20 11:14:32.522:INFO:oejs.Server:jetty-8.1.3.v20120416 
2012-04-20 11:14:32.617:WARN:oejx.XmlParser:[email protected]:/C:/Users/***/workspace/Test/WEB-INF/web.xml line:1 col:7 : org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed. 
2012-04-20 11:14:32.617:WARN:oejw.WebAppContext:Failed startup of context o.e.j.w.WebAppContext{/runJetty,file:/C:/Users/***/workspace/Test/} 
org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed. 
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) 
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source) 
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) 
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source) 
at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanPIData(Unknown Source) 
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanPIData(Unknown Source) 
at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanPI(Unknown Source) 
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source) 
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source) 
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source) 
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) 
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) 
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) 
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) 
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source) 
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) 
at javax.xml.parsers.SAXParser.parse(Unknown Source) 
at org.eclipse.jetty.xml.XmlParser.parse(XmlParser.java:199) 
at org.eclipse.jetty.xml.XmlParser.parse(XmlParser.java:215) 
at org.eclipse.jetty.webapp.Descriptor.parse(Descriptor.java:60) 
at org.eclipse.jetty.webapp.WebDescriptor.parse(WebDescriptor.java:143) 
at org.eclipse.jetty.webapp.MetaData.setWebXml(MetaData.java:165) 
at org.eclipse.jetty.webapp.WebXmlConfiguration.preConfigure(WebXmlConfiguration.java:55) 
at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:417) 
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:453) 
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59) 
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:224) 
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:167) 
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59) 
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:90) 
at org.eclipse.jetty.server.Server.doStart(Server.java:262) 
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59) 
at blog.runjetty.server.JettyServer.start(JettyServer.java:22) 
at blog.runjetty.ui.listener.ServerStartStopActionListner.actionPerformed(ServerStartStopActionListner.java:38) 
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) 
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) 
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) 
at javax.swing.DefaultButtonModel.setPressed(Unknown Source) 
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) 
at java.awt.Component.processMouseEvent(Unknown Source) 
at javax.swing.JComponent.processMouseEvent(Unknown Source) 
at java.awt.Component.processEvent(Unknown Source) 
at java.awt.Container.processEvent(Unknown Source) 
at java.awt.Component.dispatchEventImpl(Unknown Source) 
at java.awt.Container.dispatchEventImpl(Unknown Source) 
at java.awt.Component.dispatchEvent(Unknown Source) 
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) 
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) 
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) 
at java.awt.Container.dispatchEventImpl(Unknown Source) 
at java.awt.Window.dispatchEventImpl(Unknown Source) 
at java.awt.Component.dispatchEvent(Unknown Source) 
at java.awt.EventQueue.dispatchEventImpl(Unknown Source) 
at java.awt.EventQueue.access$000(Unknown Source) 
at java.awt.EventQueue$1.run(Unknown Source) 
at java.awt.EventQueue$1.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) 
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) 
at java.awt.EventQueue$2.run(Unknown Source) 
at java.awt.EventQueue$2.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) 
at java.awt.EventQueue.dispatchEvent(Unknown Source) 
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) 
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
at java.awt.EventDispatchThread.run(Unknown Source) 
2012-04-20 11:14:32.648:INFO:oejs.AbstractConnector:Started [email protected]:8585 

mój plik xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" 
version="2.4"> 
    <welcome-file-list> 
     <welcome-file>page/index.jsp</welcome-file> 
    </welcome-file-list> 
</web-app> 

My JSP fil E

<%@ page language="java" contentType="text/html; charset=ISO-8859-1 pageEncoding="ISO-8859-1"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01  Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
     <title>Embedding Jetty</title> 
    </head> 
    <body> 
     <h2>Running Jetty web server from our application!!</h2> 
    </body> 
</html> 
+0

zamieścić swoje web.xml –

+0

przywracana do pierwotnego pytania. Jeśli masz inne pytanie, proszę * nie * zastępuj go tym. Po prostu zadaj nowe pytanie. Ponadto, jeśli odpowiedź pomogła Ci rozwiązać problem, zaakceptuj go, klikając znacznik wyboru. –

Odpowiedz

4

Właściwie to rozwiązałem problem. Uruchomiłem go za pomocą wtyczki eclipse.

  1. nie mam lib JDK w moim Eclipse, dlatego komunikat zachować pokazując, że muszę zainstalować pełny pakiet JDK, to jest główny powód.

  2. Zainstalowałem dwie wersje wtyczki do mola, która jest pomostem jetty7 i pomostem8. Myślę, że kłócą się ze sobą lub coś takiego, więc usunąłem jetty7 i działa!

+0

Miałem trochę podobny problem, z jakiegoś (teraz nieznanego) powodu dodałem tomcat jasper-kompilator do mojego pom dla konfiguracji testu i zastanawiałem się, dlaczego nie zaczął z tego samego ustawienia, jak zwykle. Wyrzuciłem to i zadziałało jak czar później. – Martin

7

2012-04-20 11:14:32.617:WARN:oejx.XmlParser:[email protected]:/C:/Users/***/workspace/Test/WEB-INF/web.xml line:1 col:7 : org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.

zalogować mówi, że web.xml jest źle sformułowany. Wiersz 1, kolumna 7. Może to być UTF-8 Byte-Order-Marker Spróbuj sprawdzić, czy twój plik XML jest dobrze sformułowany i nie ma LM. Java nie używa LM.

+0

Bez web.xml nikt nie może pomóc. –

+0

Umieściłem na nim zarówno mój plik xml i jsp, dzięki! – huao

+0

@huao, jeśli jego odpowiedź pomogła, powinieneś to zaakceptować. Naciśnij znacznik wyboru. – sharakan

0

Miałem ten sam problem. Rozwiązałem go, usuwając podział wiersza z pliku xml. Zrobiłem

<operationBindings> 
    <OperationBinding> 
     <operationType>update</operationType> 
     <operationId>makePdf</operationId> 
     <serverObject> 
      <className>com.myclass</className> 
      <lookupStyle>new</lookupStyle> 
     </serverObject> 
     <serverMethod>makePdf</serverMethod> 
    </OperationBinding> 
</operationBindings> 

zamiast ...

<serverObject> 
      <className>com.myclass 
</className> 
      <lookupStyle>new</lookupStyle> 
</serverObject> 
1

Żadna z tych odpowiedzi pracował dla mnie.

musiałem usunąć wszystkich wdrożonych aplikacji Java Web:

  • Windows/show View/Inne ...
  • Przejdź do folderu z serwerem i wybierz "Serwery"
  • prawym przyciskiem myszy na J2EE Podgląd na localhost
  • Kliknij na Dodaj i usuń ... kliknij przycisk Usuń wszystko

Następnie uruchomić projekt na serwerze

Błąd zniknął!

Będziesz musiał zatrzymać serwer przed wdrożeniem innego projektu, ponieważ nie zostanie znaleziony przez serwer. W przeciwnym razie pojawi się błąd 404:

0

Usuń/Usuń projekt z obszaru roboczego. i ponownie zaimportuj projekt do obszaru roboczego. Ta metoda zadziałała dla mnie.

0

Nauka servletu kontra huśtawka pomoże. Uzyskaj dane z wychylnym api:

@POST 
@Path(“/e”) 
@Produces(MediaType.APPLICATION_JSON) 
@Consumes(MediaType.APPLICATION_JSON) 

public Response api1(String requestJson, public Response api1(String requestJson,         @Context HttpHeaders httpHeaders) 

{ 

String h1 = httpHeaders.getHeaderString(“h1”); 

switch (h1) { 

case “1”: { 

if (h1 != null) { 

if (validateJsonSyntax(requestJson)) { 

ObjectMapper objectMapper = new ObjectMapper();        try { 

Object1 obj = objectMapper.readValue(requestJson, json1.class);  return Response.status(Response.Status.ACCEPTED).build();        } 

catch (Exception e) { 

return Response.status(Response.Status.BAD_REQUEST).build();        } 

} 

} 
} 
break; 

default:   {   }   break; 
}  return Response.status(Response.Status.BAD_REQUEST).build(); 

} 

Uzyskaj dane z HttpServet teleskopowe:

public class c1 extends HttpServlet { 

@Override 
protected void doPost(HttpServletRequest request, HttpServletResponse response) 
throws ServletException, IOException { 

//super.doPost(request, response); 

String h1 = request.getHeader(“h1”); 
String h2 = request.getHeader(“h2”); 

switch (h1) { 

case “one”: { 

if (h2 != null) { 
InputStream inStrReqBody = request.getInputStream(); 
if (inStrReqBody != null) { 
String strReqBody = IOUtils.toString(inStrReqBody, 
request.getCharacterEncoding()); 
if (validateJsonSyntax(strReqBody)) { 
ObjectMapper objectMapper = new ObjectMapper(); 
try { 
Object1 obj1 = objectMapper.readValue(strReqBody, VNFCatalogResponse.class); 
response.setStatus(HttpServletResponse.SC_ACCEPTED); 
} catch (Exception e) { 
\ 
response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 

} 
} 
} 
} 
} 

} 
} 

więcej szczegółów na http://writeulearn.com/jetty-handler-swing-handler-differences/