Quantcast
Channel: Apache Timeline
Viewing all articles
Browse latest Browse all 5648

Client keeps trying to authenticate after 401 response

$
0
0
I realize that this is not a CXF problem, but I use CXF for the server and
I hope somebody on the list may be able to help.

I have a Web Service built with CXF that works well. It is protected with
basic authentication that also works as intended. The problem happens when
the client uses the wrong credentials; the server keeps it out (good!) but
the client keeps misinterpreting the 401 response and trying again; in the
end, it complains that the server has redirected too many times and it
quits (See the stack traces below).

It looks like the culprit is HttpURLConnection, but I may be wrong. Does
anybody have any suggestions about how to avoid this redirect business and
to get either the 401 response or at least a meaningful error message?

Thanks!

Stack trace with a plain Java client:

Exception in thread "main" javax.xml.ws.WebServiceException: Failed to
access the WSDL at: http://localhost:8081/ws/TestService?wsdl. It failed
with:
Server redirected too many times (20).
at
com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:151)
at
com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:133)
at
com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:254)
at
com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:217)
at
com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:165)
at
com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)
at javax.xml.ws.Service.<init>(Service.java:56)
at javax.xml.ws.Service.create(Service.java:680)
at ws.test.client.TestServiceBaseClient.getProxy(TestBaseClient.java:66)
at ws.test.client.TestClient.main(TestClient.java:52)
Caused by: java.net.ProtocolException: Server redirected too many times
(20)
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1446)
at java.net.URL.openStream(URL.java:1010)
at
com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:793)
at
com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.resolveWSDL(RuntimeWSDLParser.java:251)
at
com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:118)
... 8 more

And with a CXF client:

Exception in thread "main" javax.xml.ws.WebServiceException:
org.apache.cxf.service.factory.ServiceConstructionException: Failed to
create service.
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:149)
at
org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:97)
at javax.xml.ws.Service.<init>(Service.java:77)
at javax.xml.ws.Service.create(Service.java:707)
at
ws.test.client.CxfTestClient.getTestService(CxfTestClient.java:88)
at ws.test.client.CxfTestClient.doRun(CxfTestClient.java:62)
at ws.test.client.CxfTestClient.main(CxfTestClient.java:111)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException:
Failed to create service.
at
org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:94)
at
org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:203)
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:147)
... 6 more
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR:
Problem parsing
'http://localhost:8081/ws/TestService?wsdl'.:
java.net.ProtocolException: Server redirected too many times (20)
at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at
org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:244)
at
org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:191)
at
org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:92)
... 8 more
Caused by: java.net.ProtocolException: Server redirected too many times
(20)
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1636)
at
org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at
org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
... 14 more

Viewing all articles
Browse latest Browse all 5648

Trending Articles