RESTLET:运行restful时,我的JAX-WS连接被阻止

时间:2014-03-25 15:58:03

标签: jax-ws restlet

使用最新的restlet框架(Java SE)以及Jax-WS(也只是在Java SE中),与restful服务的连接工作正常,但是与WS端的连接从不建立连接,客户端始终报告错误。一旦我停止了宁静的一面,一切都恢复正常。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

解决了我的问题,这里没有问题。但是,如果有人感兴趣,这是我的测试java,以证明它工作正常......

  public class Example
  {
     public static void main(String[] args) throws Exception {
        Example example = new Example();
        /* Start Restful */
        example.startRestful();
        /* Start JAX-WS */
        example.startJAXWS();
     }

     public void startRestful() throws Exception {
        // create a new Component
        Component component = new Component();
        // add a new HTTP server listening on port specified
        component.getServers().add(Protocol.HTTP, 9998);
        // attach the manager
        component.getDefaultHost().attach("/abc", new RestfulRouter(new Restful()));
        // start the component  
        component.start();
     }

     public void startJAXWS() throws Exception {
        Endpoint.publish("http://localhost:9999/ws/hello", new HelloWorld());
     }

     @WebService
     public class HelloWorld
     {
        @WebMethod
        public String sayHelloWorld(String name) {
           System.out.println("JAX-WS working");
           return "Hello World " + name;
        }
     }

     public class RestfulRouter extends Application
     {
        private Restful webService;

        public RestfulRouter(Restful webService) {
           this.webService = webService;
        }

        @Override
        public Restlet createInboundRoot() {
            // create a router Restlet that routes each call to the console
            Router router = new Router(getContext());
            // attach the route to the webService Restlet 
            router.attachDefault(webService);
            return router;
        }
     }

     public class Restful extends Restlet
     {
        @Override
        public void handle(final Request request, final Response response)  
        {
           String name = request.getResourceRef().getQueryAsForm().getFirstValue("name");  
           System.out.println("Restful working");
           response.setEntity(name, MediaType.TEXT_PLAIN);
        }
     }
  }