java - (Java) 同时发布 Web Service Endpoint 和 Http Server?

标签 java web-services httpserver

我能够自己独立运行一个 WebService 和一个 httpServer,但是当我同时运行它们时,网络服务 wsdl 网址不再有效。我希望这样做,这样我就可以从 javascript 调用 Web 服务到相同的 URL,而不会出现跨源问题。

这可能吗?

public class Main {
    public static void main(String[] args) throws Exception {
        int port = 8888;
        /* This works without httpServer running */
        Endpoint.publish("http://localhost:" + port + "/ws/someService", new SomeService());
        /* This works without Endpoint running */
        HttpServer httpServer = HttpServer.create(new InetSocketAddress(port), 0); 
        httpServer.createContext("/someHandler", new SomeHandler());
    }   
}

最佳答案

尝试使用不同的端口。例如,如果您将 8888 用作 Endpoint,则将 8890 或其他名称用于 HttpServer。

EndPoint 使用嵌入式 HTTP 服务器实现,它作为 Java 的一部分包含在内。 因此,您实质上是在尝试在同一个端口上使用两个不同的 HTTP 服务器,我认为这是行不通的。您应该使用不同的端口来完成这项工作。

关于java - (Java) 同时发布 Web Service Endpoint 和 Http Server?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53741167/

相关文章:

java - 使用 Jersey 制作 favicon.ico

html - 为什么服务器返回的 HTML 页面没有在浏览器中呈现

delphi - 无法从 delphi 中的 TIdHTTP 连接到 TIdHTTPServer

java - 无法向我的 JFrame 添加面板(背景)

Java同步语句

android - 在 Internet 上发布我的 RESTful Web 服务

java - IBM WebSphere 8.5 Liberty Profile 不支持 Jax-ws

java - 从 FXML Controller 中的其他类调用方法

java - 写入文件时如何考虑JSON结构

php - Zend_HTTP_Client 不会让我发布任何数据