如何停止Web服务端点?

时间:2014-10-08 15:47:06

标签: java web-services

我知道我需要使用端点调用stop()方法。 但我不知道怎么称呼它。

这是我的代码

public class Publish {

    public static void main(String[] args) {

        String address = "http://localhost:8483/cal";
        Object implementor =  new CalWebserviceImpl();

        Endpoint endpoint = Endpoint.publish(address, implementor);
        System.out.println(endpoint.isPublished());

        endpoint.stop();


    } // main
}

这是我得到的错误:

线程“main”中的异常com.sun.xml.internal.ws.server.ServerRtException:服务器运行时错误:java.net.BindException:已在使用的地址:bind     在com.sun.xml.internal.ws.transport.http.server.ServerMgr.createContext(ServerMgr.java:117)

我假设我收到错误消息,因为我在尝试(重新)发布端点之前停止它。

我尝试创建一个新的端点引用并使用它来阻止它。

        Endpoint ep = Endpoint.create(implementor);
        ep.stop();

但是我收到了同样的错误消息。

我只是不清楚如何调用stop()服务。请指教。谢谢!

修改:

这是另一次不成功的尝试:

package com.website.test;
import javax.xml.ws.Endpoint;

public class Unpublish {

    Endpoint ep = null;

    public static void main(String[] args) {

        Unpublish up = new Unpublish();
        up.run();

    } // main


     public void run(){      
            String address = "http://localhost:8483/cal";
            Object implementor =  new CalWebserviceImpl();  
            // my service is already running, I believe it's publish here that's causing the issue       
            ep = Endpoint.publish(address, implementor);

            startWebService();          
   }

    private void startWebService() {

        if(ep.isPublished()){           
            System.out.println("Endpoint webservice is running!");
        }
        else{
            ep.stop();
            System.out.println("Endpoint webservice stopped!");
        }

    }

}

0 个答案:

没有答案