托管独立Web服务不需要存根类吗?我们不需要服务器来托管Web服务吗?

时间:2014-01-27 15:46:43

标签: java web-services soap stub

1)我一直致力于Web服务,并且正在关注

http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example-document-style/

http://theopentutorials.com/examples/java-ee/jax-ws/create-and-consume-web-service-using-jax-ws/

所以这里他们使用wsgen为服务创建存根。

但我试过了,我能够在没有存根的情况下做到...... 我在这里有代码https://github.com/HarishAtGitHub/doc/tree/master/soapws%20without%20stub

那么不再需要存根吗? 或者是内部完成的存根创建?

2)我假设webservice托管需要一台服务器。但是使用我在上面提供的github链接中的代码,我可以独立托管它。什么是独立的意思?

我们不需要服务器吗?

1 个答案:

答案 0 :(得分:0)

我通过调试找到答案并进入jdk

1)存根创建在内部完成

2)是的,它需要一台服务器。它在内部使用HttpServer执行此操作。

Web服务在http服务器内部运行的证据是什么?

在EnpointImpl中有一个代码片段

 // See if HttpServer implementation is available
    try {
        Class.forName("com.sun.net.httpserver.HttpServer");
    } catch (Exception e) {
        throw new UnsupportedOperationException("Couldn't load light weight http server", e);
    }

所以如果没有HttpServer,他们将退出发布

所以这证明他们内部的某个地方正在使用HttpServer

在EnpointImpl.createEndpoint里面,他们得到了一些容器

container = getContainer();

原来是com.sun.xml.internal.ws.transport.http.server.ServerContainer

他们正在检查是否提供了wsdl EnpointImpl.java

/**
 * Gets wsdl from @WebService or @WebServiceProvider
 */
private @Nullable SDDocumentSource getPrimaryWsdl() {
    // Takes care of @WebService, @WebServiceProvider's wsdlLocation
    EndpointFactory.verifyImplementorClass(implClass);
    String wsdlLocation = EndpointFactory.getWsdlLocation(implClass);
    if (wsdlLocation != null) {
        ClassLoader cl = implClass.getClassLoader();
        URL url = cl.getResource(wsdlLocation);
        if (url != null) {
            return SDDocumentSource.create(url);
        }
        throw new ServerRtException("cannot.load.wsdl", wsdlLocation);
    }
    return null;
}

在我们的例子中我们没有wsdl,我们只有服务类

他们在哪里创建http服务器? com.sun.xml.internal.ws.transport.http.server.ServerMgr 这个班 /**  *管理JAXWS运行时创建的所有WebService HTTP服务器。  *  * @author Jitendra Kotamraju  * /

from EnpointImpl.publish()
((HttpEndpoint) actualEndpoint).publish(address);

因为端点存在于HttpEndpoint中,现在

它转到HttpEndpoint.publish() 在这个HttpEndpoint.publish()

里面
httpContext = ServerMgr.getInstance().createContext(address);

https://upsource.jetbrains.com/lib/view/jdk7u10/com/sun/xml/internal/ws/transport/http/server/ServerMgr.java;nav:1535:1548:focused) 在com.sun.xml.internal.ws.transport.http.server.ServerMgr的createContext中 他们正在创建HttpServer

server = HttpServer.create(inetAddress, 0);                             server.setExecutor(Executors.newCachedThreadPool());
String path = url.toURI().getPath();
logger.fine("Creating HTTP Context at = "+path);
HttpContext context = server.createContext(path);
server.start();
logger.fine("HTTP server started = "+inetAddress);
state = new ServerState(server);
servers.put(inetAddress, state);
return context;

所以这是运行服务的HttpServer ......。

相关问题