Alexander Kleinhans
Alexander Kleinhans

Reputation: 6258

(Java) Publish WebService Endpoint and HttpServer at the same time?

I'm able to independently run a WebService and an httpServer by themselves, but when I'm running both, the web-service wsdl url no longer works. I was hoping to do this so I could call web-services from javascript to the same URL without having cross origin issues.

Is this even possible?

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());
    }   
}

Upvotes: 2

Views: 257

Answers (1)

A_C
A_C

Reputation: 925

Try with different ports. For example, if you use 8888 for the Endpoint, use 8890 or something for the HttpServer.

The EndPoint uses an embedded HTTP Server implementation which is included as part of Java. So, you are essentially trying to use two different HTTP servers on the same port, which I think won't work. You should use different ports to make this work.

Upvotes: 1

Related Questions