【问题标题】:Are no stub classes needed to host a standalone webservice ? don't we need a server to host a webservice?是否不需要存根类来托管独立的 Web 服务?我们不需要服务器来托管网络服务吗?
【发布时间】:2014-01-27 15:46:43
【问题描述】:

1) 我一直在从事网络服务工作,并且正在关注

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) 我假设网络服务托管需要一个服务器。但是使用上面提供的 github 链接中的代码,我可以独立托管它。独立是什么意思?

我们不需要服务器吗?

【问题讨论】:

    标签: java web-services soap stub


    【解决方案1】:

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

    1) 存根创建在内部完成

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

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

    在EnpointImpl中有一个代码sn -p

     // 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 ....

    【讨论】:

      猜你喜欢
      • 2013-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-13
      • 1970-01-01
      相关资源
      最近更新 更多