1

我正在开发一个应该在 OSGi 容器中运行的客户端。我正在使用由 cxf-codegen-plugin 生成的存根。以下独立应用程序工作正常:

  public class MyClient {

    public static void main(String args[]) throws java.lang.Exception{

        String endpointT = "http://myService/endpoint/";

        MyServicess = new MyService( );
        MyServicePortType port = ss.MyServicePort();
        BindingProvider provider = (BindingProvider) port;
        Client client = ClientProxy.getClient(port);

        client.getRequestContext().put(Message.ENDPOINT_ADDRESS, endpointT) ;

        System.out.println("Invoking findEventManager...");

        System.out.println(port.callService());



    }
}

当我在 OSGi 容器中尝试同样的事情时(我正在使用 karaf,它使用 OSGi 的 felix 实现)。它不起作用!并告诉我这个例外javax.xml.ws.WebServiceException: Could not find wsdl:binding operation info for web method callService.。代码如下所示:

@Component(name="RemoteExample", immediate=true)
@Service
public class RemoteExampleImpl extends Thread implements IRemoteExample  {

    private Boolean running =false;
    @Activate
    protected void activate(ComponentContext context)  {
        running =true;
        this.start();
    }

     public void run() {

         boolean cont = true;

         while (cont && running) {
             String endpointT = "http://myService/endpoint/";

            MyServicess = new MyService( );
            MyServicePortType port = ss.MyServicePort();
            BindingProvider provider = (BindingProvider) port;
            Client client = ClientProxy.getClient(port);

            client.getRequestContext().put(Message.ENDPOINT_ADDRESS, endpointT) ;

            System.out.println("Invoking findEventManager...");

            System.out.println(port.callService());
         }
     }

    @Deactivate
    protected void deactivate(ComponentContext context) {
        running = false;
        mLogger.info("LocalExampleImpl deactivated");
    }
}

我怎样才能使这段代码工作?

4

0 回答 0