如何在Jetty上运行SOAP Web服务?

5
我很难将SOAP Web服务在我的嵌入式Jetty服务器上运行。
我遵循了这篇德语教程(当然没有成功):http://www.torsten-horn.de/techdocs/jee-jax-ws.htm#Deployment-im-Webserver 相关的代码片段如下:
Endpoint ep = Endpoint.publish( url, new BuecherServiceImpl() );
int anzahlBuecherResult = TestWsClient.test( "WsMitEndpointIntegrTest", url, 4000000000L, anzahlBuecher, true );


public static int test( String testName, String url, long startIsbn, int anzahlBuecher, boolean trace ) throws Exception
{
  BuecherServiceIntf buecherService;
  if( url.equalsIgnoreCase( "direkt" ) ) {
     buecherService = new BuecherServiceImpl();
  } else {
     System.out.println( testName + ": " + url );
     Service service = null;
     int timeoutSekunden = 20;
     while( service == null ) {
        try {
           //here the Exception occurs, maybe because of a wrong qname
           service = Service.create(
                 new URL( url + "?wsdl" ),
                 new QName( "http://soap.apachecxf/" , "BuecherServiceImplService" ) );
        } catch( WebServiceException ex ) {
           if( timeoutSekunden-- <= 0 ) throw ex;
           try { Thread.sleep( 1000 ); } catch( InterruptedException e ) {/*ok*/}
        }
     }
     buecherService = service.getPort( BuecherServiceIntf.class );
  }

sun-jaxws.xml

<endpoints version="2.0" xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime">

<endpoint name="BuecherService" implementation="soap.apachecxf.BuecherServiceImpl" url-pattern="/ws/BuecherService" />

</endpoints>

有人能在这里提供帮助吗?


晚了点,但或许这可以帮到你:[http://stackoverflow.com/questions/36418158/embedded-jetty-adding-context-after-starting-jetty-server/38530242#38530242](请查看第二个代码清单)。 - DBE
1个回答

0

您可以通过覆盖默认的HttpServerProvider属性来运行嵌入式Jetty的SOAP Web服务。请确保已将jetty-http-spi jar文件添加到类路径中。

System.setProperty("com.sun.net.httpserver.HttpServerProvider", "org.eclipse.jetty.http.spi.JettyHttpServerProvider");

org.eclipse.jetty.http.spi.JettyHttpServerProvider是由Jetty提供的Java HTTP Server SPI实现

您可以通过查看服务器响应头来验证运行的服务器是否为Jetty。 这段代码对我有效。

public static void main(String[] args) throws Exception {
    ContentWsImplement contentImplement = new ContentWsImplement();
    System.setProperty("com.sun.net.httpserver.HttpServerProvider", "org.eclipse.jetty.http.spi.JettyHttpServerProvider");
    Endpoint.publish("http://0.0.0.0:8000/services/getcontent", contentImplement);
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接