Ljudevit
Ljudevit

Reputation: 368

Slow initialization of apache cxf client

I'm using wsdl2java generated classes and this code:

MyService f = new MyService();
MyServicePortType type = f.getMyServicePortType();

Each of these calls is taking up to 30 seconds. Why is that?

Upvotes: 6

Views: 3793

Answers (2)

Cec
Cec

Reputation: 1816

I owe you a great debt since I have been struggling with this for days and your answer pointed me in the right direction.

Indeed w3.org URLs take ages to respond, however there is actually no reason why a SOAP client generated from a WSDL should still need to parse the WSDL at runtime.

In fact it does not, however default generated construstors force that.

I've discovered that it's possible to skip this by instantiating the service port in a different way and specify the service endpoint via request context as follows:

// creating the service this way passes null as the wsdlLocation, preventing the runtime resolution and parsing of the wsdl
Service service =  ZefixService.create(ZefixService.SERVICE);

ZefixServicePortType zefixServicePort = service.getPort(ZefixServicePortType.class);


Map<String, Object> requestContext = ((BindingProvider) zefixServicePort).getRequestContext();
// because we create the service without the wsdl location, we need to specify the service base url ourselves
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, Configuration.get(Constants.API_BASE_URI_PROPERTY));
requestContext.put(BindingProvider.USERNAME_PROPERTY, Configuration.get(Constants.USER_PROPERTY));
requestContext.put(BindingProvider.PASSWORD_PROPERTY, Configuration.get(Constants.PASSWORD_PROPERTY));

return zefixServicePort;

I hope this turns useful for you and others in the future.

Thanks again

Upvotes: 0

Ljudevit
Ljudevit

Reputation: 368

After hours of googling and tinkering the problem was in how scheme files were referenced: although WSDL and XSD were locally stored there was still some referenced to w3.org that looked like this:

<!DOCTYPE schema PUBLIC "-//W3C//DTD XMLSchema 200102//EN" "http://www.w3.org/2001/XMLSchema.dtd" [...

<import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd" />

w3.org server was resposing super-slowly hence the slow initialization of my client.

I have changed the reference to local:

<import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd" />

Upvotes: 8

Related Questions