Java: using endpoint to publish webservice to tomcat server
Asked Answered
Z

3

11

i am creating a simple SOAP web service. i am to ensure that it runs on a tomcat web service.

im trying to implement this with JAX-WS (see code)

my question is: does the Endpoint.publish use the tomcat server to host this or is it a mini glassfish kind of server?

should i be extending UnicastRemoveObject or something similiar instead?

ideally it would be able to be packaged into a .WAR and dropped in the directory and just work.

It doesn't seem to work with my installed tomcat server as is because it says the port is already in use. I'm using Ubuntu karmic with the tomcat6 package installed, it could also be my user doesnt have permissions to publish to the running tomcat on 8080

i hope this question is clear enough

sample code:

@WebService
public class UserAttributes {
    public static void main(String[] args) {
        UserAttributes instance = new UserAttributes();
        Endpoint.publish("http://localhost:8082/WebServices/userattributes", 
            instance);
    }

    public string Hello() {
       return "Hello World";
    }
}
Zajac answered 18/1, 2010 at 1:54 Comment(2)
The default JAX-WS implementation in the JDK uses a minimal NIO-based web server.Maple
Thank you! is there any way to target it to an already running tomcat server?Zajac
L
25

Does Endpoint.publish use the tomcat server to host this or is it a mini glassfish kind of server?

JAX-WS RI Endpoint.publish API uses by default a light-weight HTTP server implementation that is included in Sun's Java SE 6. So no, it does not use an embedded GlassFish nor an embedded Tomcat and even less your existing Tomcat install: it uses an embedded container i.e. something running inside the same JVM. Just FYI, it is however possible to plug other implementations as long as they provide a Service Provider Implementation (SPI). For example, Jetty 6 does so, see J2se6HttpServerSPI. But I'm not going to cover all the details here :)

It doesn't seem to work with my installed tomcat server as is because it says the port is already in use.

As I said above, the Enpoint.publish API doesn't use your existing Tomcat install. It uses its own server and allows you to deploy your web service without having to package and deploy your app. It is especially useful during development (as it speeds up things). Actually, it's extremely handy.

Now, if you have a Tomcat server running on port 8082 and if you try to publish your Endpoint using the same port, things won't work as you noticed. Use a different (and unused) port during development.

And if you want to deploy your web services to your existing Tomcat install, then you'll have to package them in a war and to deploy this war on Tomcat. But this is totally different and doesn't have anything to do with using the Endpoint.publish API.

Levitate answered 18/1, 2010 at 3:15 Comment(1)
well explanation .Hexapody
D
1

Very interesting. It seems to me that the embedded server also contains a soap engine to process the soap messages sent to that port. Is this also an embedded soap engine or is it using one of the popular soap engines (axis2,cxf,metro)

Dhumma answered 12/10, 2010 at 19:12 Comment(0)
S
0

Endpoint.publish() doesn't publish the web service to server instance. If you want to publish end point to web server then it has to be packaged into a WAR using ws gen tool and then be deployed to web server.

Endpoint.publish() publishes the endpoint to run time instance of JVM without creating a server instance. It is very much useful when unit testing a web service using the client test class created using JAX-WS.

Sturm answered 14/6, 2020 at 17:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.