Showing posts with label axis. Show all posts
Showing posts with label axis. Show all posts

Tuesday, November 25, 2008

Axis: Creating Stub with custom WSDD file

And here is another Axis (1.4) tip:

In order to create a stub with a custom WSDD file you'll need to do the following:

import org.apache.axis.configuration.FileProvider;
import java.io.File;
import java.io.InputStream;
.
.
InputStream is = new FileInputStream(new File("D:/custom-client-config.wsdd"));
MyServiceLocator locator = new MyServiceLocator(new FileProvider(is));


Pay Attention!


In the client side there is a bug in parsing wsdd: when the handlers are configured in the service flow and service contains additional configuration (e.g. provider, style, user, mappings, etc.), the handler will not run. This happens since client configuration does not contain className with the service implementation class.

It's possible to put "dummy" class name. But the better solution is to configure handler in the global flow.

Thursday, April 3, 2008

Configuring HTTP Proxy in Java

Sometime ago I needed to configure a proxy for an example applications that has used both Axis, Axis2 and JAX-WS as SOAP Engines.

Usually to configure proxy you need to define the following system properties, when you start a JVM:
-Dhttp.proxySet=true -Dhttp.proxyHost=<host> -Dhttp.proxyPort=<port>


But unfortunately it doesn't always work. Actually it did work only for Axis.
So here are the solutions that worked:

In Axis2 it's possible to add the following code to the client that will copy proxy settings from system properties:
ServiceClient serviceClient = stub._getServiceClient();
Options options = serviceClient.getOptions();
if (System.getProperty("http.proxySet", "false").equals("true")) {
ProxyProperties proxyProperties = new ProxyProperties();
proxyProperties.setProxyName(System.getProperty("http.proxyHost"));
proxyProperties.setProxyPort(Integer.parseInt(System.getProperty("http.proxyPort")));
// set username and password if you need them
options.setProperty(HTTPConstants.PROXY, proxyProperties);
}


In JAX-WS you may set the proxy in the code:
if (System.getProperty("http.proxySet", "false").equals("true")) {
ProxySelector.setDefault(new ProxySelector() {

@Override
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
throw new RuntimeException("Proxy connect failed", ioe);
}

@Override
public List select(URI uri) {
return Arrays.asList(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort")))));
}
});


Recommended Reading

1. Effective Java (2nd Edition)
2. Java™ Puzzlers: Traps, Pitfalls, and Corner Cases
3. Mort