You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by hackmgnt <zi...@gmail.com> on 2013/05/02 13:41:58 UTC
Re: Retrive WSDL using basic authentication
Hello,
I have tried what you explained on above but still didn't work. Here's my
code:
import java.util.Arrays;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.CXFBusFactory;
import org.apache.cxf.configuration.security.AuthorizationPolicy;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transport.http.HTTPConduitConfigurer;
public class Authorization {
public static void main(String[] args) throws Exception {
String wsdl = "http://localhost/WebService/Service?wsdl";
String username = "user";
String password = "password";
String method = "foo";
Bus bus = CXFBusFactory.getThreadDefaultBus();
MyHTTPConduitConfigurer conf = new MyHTTPConduitConfigurer(username,
password);
bus.setExtension(conf, MyHTTPConduitConfigurer.class);
JaxWsDynamicClientFactory dcf =
JaxWsDynamicClientFactory.newInstance(bus);
Client client = dcf.createClient(wsdl);
Object[] res = client.invoke(method);
System.out.println(Arrays.deepToString(res));
}
}
class MyHTTPConduitConfigurer implements HTTPConduitConfigurer {
private final String username;
private final String password;
public MyHTTPConduitConfigurer(String username, String password) {
this.username = username;
this.password = password;
}
@Override
public void configure(String name, String address, HTTPConduit c) {
System.out.println("AuthorizationHTTPConduitConfigurer.configure()");
AuthorizationPolicy ap = new AuthorizationPolicy();
ap.setUserName(username);
ap.setPassword(password);
c.setAuthorization(ap);
}
}
and the result:
Exception in thread "main"
org.apache.cxf.service.factory.ServiceConstructionException: Failed to
create service.
at
org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:86)
at
org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:292)
at
org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:235)
at
org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:228)
at
org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:183)
at com.ssms.raps.atom.Authorization.main(Authorization.java:27)
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR:
Problem parsing 'http://192.168.200.221/WebService/Service1.asmx?wsdl'.:
java.io.IOException: Server returned HTTP response code: 401 for URL:
http://192.168.200.221/WebService/Service1.asmx?wsdl
at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(WSDLReaderImpl.java:2198)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:2390)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:2422)
at
org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:262)
at
org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:205)
at
org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:84)
... 5 more
Caused by: java.io.IOException: Server returned HTTP response code: 401 for
URL: http://192.168.200.221/WebService/Service1.asmx?wsdl
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1403)
at
com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:654)
at
com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:189)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:783)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:748)
at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
at
com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:239)
at
com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:288)
at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(WSDLReaderImpl.java:2188)
... 10 more
note that
System.out.println("AuthorizationHTTPConduitConfigurer.configure()") in
MyHTTPConduitConfigurer didn't print.
Am I missing something here?
--
View this message in context: http://cxf.547215.n5.nabble.com/Retrive-WSDL-using-basic-authentication-tp5724416p5727057.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Retrive WSDL using basic authentication
Posted by "zynick." <zi...@gmail.com>.
after reading the source, i found the solution:
bus.setExtension(conf, *HTTPConduitConfigurer.class*);
took me some time to found this.. should have smell the code earlier :)
--
View this message in context: http://cxf.547215.n5.nabble.com/Retrive-WSDL-using-basic-authentication-tp5724416p5727406.html
Sent from the cxf-user mailing list archive at Nabble.com.