POJO web services basic auth failing
thinksteep Sep 14, 2012 6:06 PMHi Community, I am having strange issue in accessing WSDL protected by basic authentication through java web service client.
I am able to access the WSDL through browser. It is prompting for user/password. With the userID/pwd, authentication succeds and able to see WSDL.
When I try to do same using Java client it is failing with 401 response code. Any input would be really appreciated.
JBoss application-roles.properties has guest role assigned to userID.
Client
URL url = new URL(WS_URL);
QName qname = new QName("http://namespace/", "MyService");
Service service = Service.create(url, qname);
Connections port = service.getPort(MyService.class);
BindingProvider bp = (BindingProvider) port;
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "userID");
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pwd");
Exception:
Exception in thread "main" javax.xml.ws.WebServiceException: Failed to access the WSDL at: http://mymachine:8080/myapp/MyService?wsdl. It failed with:
Server returned HTTP response code: 401 for URL: http://mymachine:8080/myapp/MyService?wsdl.
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:57)
at javax.xml.ws.Service.create(Service.java:687)
at apiservicetest.ServicePerformanceTester.main(ServicePerformanceTester.java:29)
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://mymachine:8080/myapp/MyService?wsdl
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1313)
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)
... 7 more
Java Result: 1
I have POJO Service
@WebService(serviceName = "MyService")
public class MyService{
//Webmethods.
}
web.xml
<security-constraint>
<web-resource-collection>
<web-resource-name>All resources</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>guest</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<description>desc</description>
<role-name>guest</role-name>
</security-role>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>realm</realm-name>
</login-config>
jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<security-domain>other</security-domain>
</jboss-web>
Standalone-full.xml
<security-domains>
<security-domain name="other" cache-type="default">
<authentication>
<login-module code="Remoting" flag="optional">
<module-option name="password-stacking" value="useFirstPass"/>
</login-module>
<login-module code="RealmUsersRoles" flag="required">
<module-option name="usersProperties" value="${jboss.server.config.dir}/application-users.properties"/>
<module-option name="rolesProperties" value="${jboss.server.config.dir}/application-roles.properties"/>
<module-option name="realm" value="ApplicationRealm"/>
<module-option name="password-stacking" value="useFirstPass"/>
</login-module>
</authentication>
</security-domain>