我正在开发一个应该在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容器中尝试相同的事情时(我使用的是使用OSGi的felix实现的karaf)。它不起作用!并告诉我这个例外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");
}
}
如何使此代码生效?