users@wadl.java.net

Re: Problems catching 401 faults

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Mon, 11 Aug 2008 13:54:39 -0400

I wonder if the underlying HttpURLConnection isn't allowing access to
the response body for 401 status since it tries to handle that status
code itself. If that is the case then you might need to use a
different status code or use:

http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLConnection.html#setAllowUserInteraction(boolean)

To allow the URLConnection to open a dialog instead.

Marc.

On Aug 7, 2008, at 1:37 PM, Jorge L Williams wrote:

>
> I'm specifying faults in my WADL like this:
>
> <fault status="401" mediaType="text/xml"
> element="imom:webserviceFault">
> <doc>
> Bad credentials, you are not authorized to make this
> request.
> </doc>
> </fault>
> <fault status="404" mediaType="text/xml"
> element="imom:webserviceFault">
> <doc>
> Fault if the radar cannot be found
> </doc>
> </fault>
>
> In the generated code, I have no problems catching 404 faults. They
> do indeed raise a WebserviceFaultException. However, when I
> generated a 401 fault by passing bad credentials I get a different
> exception:
>
> [java] Exception in thread "main"
> java.lang.IllegalArgumentException: is parameter must not be null
> [java] at
> javax
> .xml
> .bind
> .helpers
> .AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:179)
> [java] at
> org.jvnet.ws.wadl.util.JAXBDispatcher.doGET(JAXBDispatcher.java:84)
> [java] at gov.inel.ecsi.j2ee.imomrestservices.Endpoint
> $Radar.getAsRadarInformationValueObjectList(Endpoint.java:315)
> [java] at
> gov
> .inel
> .ecsi.j2ee.imomrestservices.TestClient.testRadar(TestClient.java:270)
> [java] at
> gov.inel.ecsi.j2ee.imomrestservices.TestClient.main(TestClient.java:
> 104)
>
> I've confirmed that the server is generating a 401 fault code and
> that it is sending an imom:webserviceFault element. This looks like
> a bug to me, I guess I could go around it by catching an
> IllegalArgumentException and treating it like a 401 error -- but
> this doesn't seem right.
>
> Am I missing something?
>
> -jOrGe W.

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.