users@wadl.java.net

Re: Problems catching 401 faults

From: Jorge L Williams <Jorge.Williams_at_inl.gov>
Date: Tue, 12 Aug 2008 06:06:23 -0600

I don't think changing the status code is the right thing to do.

If I understand what you're saying regarding URLConnection change I would
have to make this on the DSDispatcher and the JAXBDispatcher classes is
that right? Or is there some other way to do this?

I usually try to stay away from HttpURLConnection because it tends to be
quirky and it lacks features. Usually I use HttpClient (
http://hc.apache.org/httpclient-3.x/). Say I wanted to drop the java.net
stuff and replace it with HttpClient.

1) Will you guys be open to that?
2) Would this change just affect the Dispatcher classes?

Thanks,

jOrGe W.




Marc Hadley <Marc.Hadley_at_Sun.COM>
Sent by: Marc.Hadley_at_Sun.COM
08/11/2008 11:54 AM
Please respond to
users_at_wadl.dev.java.net


To
users_at_wadl.dev.java.net
cc

Subject
Re: Problems catching 401 faults






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.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_wadl.dev.java.net
For additional commands, e-mail: users-help_at_wadl.dev.java.net