有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Jetty embedded作为web服务的SPI提供程序不会向客户端发送webfault

我正在做一个项目,在这个项目中,我有一个嵌入式jetty服务器来提供html管理页面,我需要集成一些web服务。我使用jax ws和javax xml注释构建这些服务,并使用jetty SPI实现(jetty-jaxws2-SPI)替换默认的HttpServerProvider:

...
System.setProperty("com.sun.net.httpserver.HttpServerProvider","org.eclipse.jetty.jaxws2spi.JettyHttpServerProvider");
HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress(serverPort),0);
...
HttpContext httpContext = httpsServer.createContext("/ws/myservice");
Endpoint endpoint = Endpoint.create(new AuthenticateImpl());
endpoint.publish(httpContext);
...

web服务工作得很好,但是当我抛出webfault异常时,客户端只获得HTTP 200结果代码,没有正文内容。 我将httpserverprovider切换回默认实现,并将错误正确地发送到客户端

我认为jetty-jaxws2-spi实现中缺少了一些东西,但不知道是什么

有什么想法吗

更新: 这似乎是JAVA版本和JAX libs之间的兼容性问题

在Approved dir中使用java7、jaxb api和jaxb impl(2.1.12),我得到:

java.lang.ExceptionInInitializerError
at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:254)
at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:85)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:626)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:585)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:570)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:467)
at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:299)
at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:593)
at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(WSHttpHandler.java:95)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(WSHttpHandler.java:80)
at org.eclipse.jetty.jaxws2spi.JAXWS2ContextHandler.doScope(JAXWS2ContextHandler.java:75)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:247)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
at org.eclipse.jetty.server.Server.handle(Server.java:346)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:589)
at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1065)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:823)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:214)
at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:411)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:535)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:529)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to com.sun.xml.internal.bind.api.JAXBRIContext
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.<clinit>(SOAPFaultBuilder.java:550)
... 25 more

并导致默认http响应(200)

更新2

当我从我认可的目录中删除jaxb impl和jaxb api时,webfault可以正常工作。 但如果我这样做,我就无法从jersey获得自然的JSON符号,JAXB2.1.12是必需的。 该死的


共 (1) 个答案

  1. # 1 楼答案

    已解决

    在我的目录中添加JAX-WSRI2.1.7和JAXB2.1.12 JAR