Thursday, November 26, 2009

JAX-WS Fighting with com.sun.xml.ws.server.UnsupportedMediaException

So I was running a JAX-WS stub from my application and kept getting this exception:


Exception: ------
com.sun.xml.ws.server.UnsupportedMediaException: Unsupported Content-Type: text/html; charset=ISO-8859-1 Supported ones are: [text/xml]
at com.sun.xml.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:295)
...


Its pretty obvious to see that the webservice is expecting XML/SOAP back as a response but instead is getting HTML. It could be the firewall, our authenitication layer, a DNS error, a reverse proxy error, an application server error page... anything really.


What a terrible exception. Worse yet, as I am using the JAX-WS framework, there was no real way to find out what the html was in the response, or so I though. I spent more than a few hours trying to find out how. Finally, I found this little nugget... When starting up your application server java process, pass this in as a VM argument:


-Dcom.sun.xml.ws.transport.http.client.HttpTransportPipe.dump="true"

Now the response is spit out to stdout! Hope this helps anyone fighting the same problems.

Cheers,

Yeuker

Wednesday, November 25, 2009

Getting the proxied object from a dynamic spring proxy

In a project I am currently working on, we are using Spring-AOP. Spring's AOP implementation 'transparently' proxies objects to facilitate its AOP implementation. You have the choice of CGLIB proxies (class based proxying) or JDK Dynamic Proxies (interface base proxying). Either one is fine... but there came a time when my proxied object didn't quite behave like the object it was proxying. I was trying to get a hibernate DataSource object from a SessionFactory using this code:

DataSource ds = SessionFactoryUtils.getDataSource(sf);

Unforunately, because my SessionFactory is a proxy object, this code was returning null... still not sure why. I knew it worked with the 'un-proxied' SessionFactory, so needed to get access to it. If you are ever in this bind, here is a snippit that will work:

public T getTargetObject(Object proxy, Class targetClass) throws Exception {
if (AopUtils.isJdkDynamicProxy(proxy) && proxy instanceof Advised) {
return (T) ((Advised)proxy).getTargetSource().getTarget();
} else {
return (T) proxy;
}
}

Hope this helps! Any comments, please post'em.

Cheers,

Yeuker