I am using wsdl2java to generate my java stub code for a web service.
I know it has been a bug since 1.4 that a wsdl source that requires HTTP basic auth could not be accessed. You will receive a 401 error because authorization was denied and there is no way to specify credentials.
Does anyone know if this issue was resolved or has someone a workaround for this? I could setup a proxyy server probably, but this is too much hassle for me, I am seeking something simple :)
you can try as this
...
serviceStub = new TestBeanServiceStub("<WEB SERVICE URL>"); // Set your value
HttpTransportProperties.Authenticator basicAuthenticator = new HttpTransportProperties.Authenticator();
List<String> authSchemes = new ArrayList<String>();
authSchemes.add(Authenticator.BASIC);
basicAuthenticator.setAuthSchemes(authSchemes);
basicAuthenticator.setUsername("<UserName>"); // Set your value
basicAuthenticator.setPassword("<Password>"); // Set your value
basicAuthenticator.setPreemptiveAuthentication(true);
serviceStub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, basicAuthenticator);
serviceStub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, "false");
...
As a workaround, I downloaded the wsdl file manually (using my browser) and saved it along with my code, and pointed wsdl2java to my local copy.
You can pass username and password in URL like this: http://username:password#example.com/wsdl
It works for me in axis: 1.7.9
Related
I created the jar from the WSDL for my client using the wsdl2java command. Now, I need to know how I can authenticate my client in order to complete an operation?
I am using CXF 2.7.16. I created my service using the generated class MyApp_Service, I am struggling with this. Isn't there a simple way to tell my client the credentials it should use to gain access to the web service?
I read about the Spring configuration, however I am unable to figure out if it applies to my case and how if yes. I tried to cast the MyApp_Service class to BindingProvider in order to use the method which consist to put the USERNAME and PASSWORD properties in the context with a value. However, MyApp_Service cannot be cast to BindingProvider.
This is my first web service client application ever. So, any help will be welcomed.
Update 2015-05-28: I tried to define the AuthenticationPolicy but is seems not working. Here is the code:
Client client = JaxWsDynamicClientFactory.newInstance().createClient(wsdlUrl);
ClientImpl clt = (ClientImpl) client;
HTTPConduit cc = (HTTPConduit) clt.getConduit();
org.apache.cxf.configuration.security.ObjectFactory secOF = new org.apache.cxf.configuration.security.ObjectFactory();
AuthorizationPolicy ap = secOF.createAuthorizationPolicy();
ap.setUserName(usagerWS);
ap.setPassword(mdpWS);
ap.setAuthorizationType("Basic");
cc.setAuthorization(ap);
Sniffing with WireShark, the Authorization header is clearly missing in the HTTP request.
What is missing?
Problem solved, here is the solution:
MyApp_Service service = new MyApp_Service(wsdlUrl, new QName(namespace, serviceName));
MyApp port = service.getMyApp();
// Set credentials
Map<String, Object> reqCtxt = ((javax.xml.ws.BindingProvider) port).getRequestContext();
reqCtxt.put(javax.xml.ws.BindingProvider.USERNAME_PROPERTY, username);
reqCtxt.put(javax.xml.ws.BindingProvider.PASSWORD_PROPERTY, password);
No more usage of the dynamic client. Only the classes generated with wsdl2java are used.
I want to export data from VersionOne into my own Java application. Please help me retrieve this data from it. I used the following code but it is not working.
V1APIConnector dataConnector = new V1APIConnector("http://www10.v1host.com/loxvo/rest-1.v1/", "username", "password");
V1APIConnector metaConnector = new V1APIConnector("http://www10.v1host.com/loxvo/meta.v1/");
metaModel = new MetaModel(metaConnector);
services = new Services(metaModel, dataConnector);
It seems there is some problem from with my URL. Please tell me what will be proper URL here as my company URL is https://www10.v1host.com/loxvo/
You have the correct form of the URL in your post, but not in your sample code. All hosted instances use https as you have shown at the end, but your code has http. While a browser will simply accept a redirect and take you from http to https, the API Client code does not; it simply fails to establish a connection.
1) Hello I am trying to use the admin services to create an Proxy inside the ESB.
So I have exposed the admin services (Hidden=false)
I have imported the WSDl in my Java project https://localhost:8243/services/ProxyServiceAdmin?wsdl
But I cannot workout how to call the method addProxy am I using the wrong admin service? Please help with an example of consuming this method.
ProxyServiceAdmin ps = new ProxyServiceAdmin();
ps.addProxy(); //wrong
2) I have a proxy defined as a one-line String, like
String xmlproxy="<?xml version='1.0' encoding='UTF-8'?><proxy xmlns='http://ws.apache.org/ns/synapse' name='MyProxy1' transports='https' startOnLoad='true' trace='disable'> <target inSequence='sequence1'>...."
Is it possible to add this Proxy by calling some method of the admin services?
thanks a lot for your attention!
EDIT I had a look at the WSDL "ProxyServiceAdmin?wsdl"
it says <wsdl:operation name="addProxy"><http:operation location="addProxy"/><wsdl:input><mime:content type="text/xml" part="parameters"/></wsdl:input><wsdl:output><mime:content type="text/xml" part="parameters"/></wsdl:output>
so it is there, but why I cannot call it? Why my code does not work as a normal Web Service would? Really, please help. I don't get what i am doing wrong...
ProxyServiceAdmin ps = new ProxyServiceAdmin();
ps.addProxy(); //not recognized as an operation of ProxyServiceAdmin even if it is in the wsdl
You simply have to use "org.wso2.carbon.proxyadmin.stub.ProxyServiceAdminStub" to ad proxy by admin services
Please have a look at following code and comments inline.
String endPoint = *<your backend service url>* +"ProxyServiceAdmin";
proxyServiceAdminStub = new ProxyServiceAdminStub(endPoint);
You have to authenticate your service stub before make any use of it
CarbonUtils.setBasicAccessSecurityHeaders(userName, password,
proxyServiceAdminStub._getServiceClient());
Need to generate ProxyData object of your proxy as synaps xml
String[] transport = {"http", "https"};
ProxyData data = new ProxyData();
data.setName(proxyName);
data.setWsdlURI(*<url to your WSDL>*);
data.setTransports(transport);
data.setStartOnLoad(true);
data.setEndpointXML("<endpoint xmlns=\"http://ws.apache.org/ns/synapse\"><address uri=\"" + serviceEndPoint + "\" /></endpoint>");
data.setEnableSecurity(true);
proxyServiceAdminStub.addProxy(data);
Thank You,
Dharshana
please find the sample to create a proxy using admin service here. I added Darshana's code to a complete example.
This is the JSP page is used for creating a pass through proxy. You can fill your proxy data similar to that. if you browse the other jsps you can find similar logics used for different proxy templates. Here you can find the complete module, both UI and Service code.
I can call NetDocuments SOAP API by C# as following:
// Authenticate to the NetDocuments directory service
ndDir.Directory ndDirectory = new ndDir.Directory();
ndDirectory.CookieContainer = new System.Net.CookieContainer(); // enable cookie handling
ndDirectory.Login( username, password );
// Connect to the NetDocuments storage service
ndStor.storage ndStorage = new ndStor.storage();
ndStorage.CookieContainer = ndDirectory.CookieContainer; // share cookies with the directory service
XmlNode searchRes = ndStorage.Search( criteria, attrList );
However, when I call NetDocuments SOAP API by java with Axis 1.4, I receive error: "No authentication session. The authentication session has timed out or was not established prior to this call."
DirectorySoapStub stubDir = new DirectorySoapStub(new URL("https://vault.netvoyage.com/ndApi/directory.asmx"), new DirectoryLocator());
StorageSoapStub stubSto = new StorageSoapStub(new URL("https://vault.netvoyage.com/ndApi/storage.asmx"), new StorageLocator());
stubSto.setMaintainSession(true);
stubDir.login(username, password);
javax.xml.soap.MimeHeaders mhds = stubDir._getCall().getMessageContext().getCurrentMessage().getMimeHeaders();
java.util.Iterator iterator = mhds.getAllHeaders();
while (iterator.hasNext()) {
javax.xml.soap.MimeHeader mhd = (javax.xml.soap.MimeHeader)iterator.next();
if ("set-cookie".indexOf(mhd.getName()) >= 0) {
stubSto._setProperty(mhd.getName(), mhd.getValue());
}
}
stubSto.search(criteria, attrList);
Is there similar thing of CookieContainer in Java? How can I call NetDocuments SOAP API by java with Axis 1.4?
I realise this question was posted a while ago, but I've been able to get this working in the past by using the JAX-RPC plugin that comes with NetBeans. The version of NetBeans I used was v6.8 (I think that the JAX-RPC plugin is not included in newer versions of NetBeans as JAX-RPC isn't widely used anymore). I remember struggling to get anything working when I tried to use Axis, though that was more than likely due to me not being familiar enough with it.
I can't remember all the steps necessary, but you can point the JAX-RPC plugin at the WSDL for NetDocuments and all the classes needed for calling the API are then set up for you.
To handle authentication correctly, it was necessary to set the SESSION_MAINTAIN_PROPERTY on the DirectorySoap_Stub and StorageSoap_Stub classes to true - this instructs them to maintain a session once you have logged in. See e.g. http://docs.oracle.com/cd/E19575-01/821-0177/fxybb/index.html for info on SESSION_MAINTAIN_PROPERTY
Additionally, when you login via the DirectorySoap object, if you then want to use the methods of StorageSoap you need to let the StorageSoap object know the cookie that you are using in the DirectorySoap session.
To do this I implemented a javax.xml.rpc.handler.Handler that stores the CookieJar from the DirectorySoap session (property "com.sun.xml.rpc.client.http.CookieJar" on the request MessageContext) and sets that CookieJar on the same property of requests of the StorageSoap session.
Hopefully that's useful to anyone with similar SOAP issues...
Cheers
My problem is I get error while trying to get request token from Yahoo. The error says Im missing oauth_callback parameter and yes I miss it because I dont need it. Ive read I need to set it to "oob" value if I dont want to use it(desktop app). And I did that but to no avail. If I set it to null the same happens. Im using OAuth for java: http://oauth.googlecode.com/svn/code/java/core/
OAuthServiceProvider serviceProvider = new OAuthServiceProvider("https://api.login.yahoo.com/oauth/v2/get_request_token",
"https://api.login.yahoo.com/oauth/v2/request_auth",
"https://api.login.yahoo.com/oauth/v2/get_token");
OAuthConsumer consumer = new OAuthConsumer("oob", consumerKey, consumerSecret, serviceProvider);
OAuthAccessor accessor = new OAuthAccessor(consumer);
OAuthClient client = new OAuthClient(new HttpClient4());
OAuthMessage response = client.getRequestTokenResponse(accessor, OAuthMessage.POST, null);
System.out.println(response.getBodyAsStream());
Have you tried using Scribe?
I also had problems with OAuth java libs so I developed that one. It's pretty much cross provider and better documented than the one you're using.
If it does not work with Yahoo you can easily extend it creating your own Provider
Hope that helps!
there is a problem in the java OAuthMassage class, I resolved it by adding to addRequiredParameters method thie line
if (pMap.get(OAuth.OAUTH_CALLBACK) == null) {
addParameter(OAuth.OAUTH_CALLBACK, consumer.callbackURL);
}
if you still have this problem I can help you: rbouadjenek#gmail.com
I haven't used that library, but it looks like it isn't properly handling the callback URL. Since OAuth 1.0a (http://oauth.net/advisories/2009-1/ and http://oauth.net/core/1.0a/), the callback URL needs to be sent in the first call to get the request token (not in the client-side call to authorise it), and it seems that this library hasn't been updated to do this (at least from looking at the code). I assume that Yahoo requires the parameter to be there.
Not sure if the original problem was ever solved, but wanted to point to a new Java OAuth SDK that Yahoo released last week:
http://developer.yahoo.net/blog/archives/2010/07/yos_sdk_for_java.html
Developers trying to access Yahoo's services via OAuth with Java may find parts of this SDK helpful.