This week's giveaway is in the Spring forum.
We're giving away four copies of liveProject: Protecting User Data with Spring Security and OAuth2 and have Laurentiu Spilca on-line!
See this thread for details.
Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Invoking a https webservice

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to web service Can anyone give me a sample code for invoking https protocol enabled web service
 
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

This introduction to SAAJ talks about clients and services that use HTTPS, particularly using Tomcat as the container (towards the end of the document).
 
Ansari Raffik
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I use a simple http call in to invoke a https web service.
 
Ulf Dittmer
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For accessing an HTTPS URL an HTTP call will not suffice. How are you developing the client - are you actually using the java.net.HttpUrlConnection class? Then it might be as simple as replacing that with the javax.net.ssl.HttpsUrlConnection class.
 
Ansari Raffik
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I am using the java.net.HttpURLConnection class. In addition the service which i am calling has some digital certificates enabled.In that case will i have to make any configurations or modifications in my client.
 
Ulf Dittmer
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by "certificates enabled"? The server/service will need to have at least one certificate installed -as does the client-, or else the SSL connection will not work. Do you want to retrieve the server certificates on the client and do something with them?
 
Ansari Raffik
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually the scenario is like the client(say A) have to access a https url(say B) by passing some string.They have provided me the keystore file and with that i have to access the https url.B will actually validate the request which iam sending with the help of keystore and then if it ok B will call a web service (say C).

I just need a sample of the client to access the https url which is protected by a digital certificate(key pair value which has a public and private key. The public key is the one that is provided by B which is the keystore file)

sorry I may be poor in explaining things.

Thanks a lot...
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having similar issues at the moment, so hopefully by explaining my issue you get some traction too.

I'm new at web services stuff, but have built a simple client that will connect and get info from non-password protected http webservice.

What i need to do is connect to a password protected https webservice.

I've created all the stubs using WDSL2Java by downloading the WSDL then running :



Which all works perfectly.

My test http client is this :



Which works fine. I'm trying to adapt this code to work with a https service ..



I'ts bombed out in the /** **/ section. Nb 'Service' is a generated class stub and not part of any of the API's.

I've added the certificate to the store using:



And that works fine. So i believe i now have access to the webservice over https.

I'm now getting a http error 401 error as the web service also requires that i authenticate with a username/password.. which i can't work out how to do.

Any thoughts ?



-Mikey

[ March 28, 2007: Message edited by: Michael Dekmetzian ]
[ March 28, 2007: Message edited by: Michael Dekmetzian ]
 
Ulf Dittmer
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using HTTP authentication in WS is demonstrated here.
 
Michael Dekmetzian
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But it bombs out when creating the service, so i'm not sure where this code goes



I don't have a method to call at that point (as all i have is the ServiceFactory) ... i'm not sure where this info would go?

Thanks for the info regardless though
 
Michael Dekmetzian
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or are you saying i should utilise the SAAJClient in "What is the simplest possible Java client for a web service?" ?
 
Ulf Dittmer
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does "bomb out" mean - is there an exception? If so, what is it?
 
Michael Dekmetzian
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also just found this :



Here: http://www-128.ibm.com/developerworks/webservices/library/ws-sec1.html

The main thing i don't get about that one is how this connects with your 'stub' classes which define how you interact with the webservice... or do you not use them with these methods because you're using call.invoke?
 
Michael Dekmetzian
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf,

Bomb out - as per my first post, i'm getting a 401 error because i haven't authenticated. Previously when i didn't have the certificate installed, it wasn't letting me connect.

Cheers

-Michael
 
Ulf Dittmer
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The main thing i don't get about that one is how this connects with your 'stub' classes which define how you interact with the webservice... or do you not use them with these methods because you're using call.invoke?


Yes, you wouldn't use the stub classes - that code contains everything that's needed. It uses a different kind of API, which is dependent on Axis.

i'm getting a 401 error because i haven't authenticated.

String wsdlLoc = "https://SOMEURL/SalesServer/Service.asmx?WSDL";

QName serviceName = new QName("http://SOMURL/webservices", "Service");

ServiceFactory sFactory = ServiceFactory.newInstance( );

/**BOMBS OUT ON THIS LINE **/
javax.xml.rpc.Service service = sFactory.createService(new URL(wsdlLoc), serviceName);



In that case, save the WSDL to a local file, and then use a file:/// URL in the call to createService.
 
Michael Dekmetzian
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If i'm creating the service from a file (which does work), how does it know where the server actually exists?

The target namespace isn't the url of the dev server i'm connecting to.
 
Michael Dekmetzian
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Worked it out, you use the local file to load the wdsl, but define an endpoint in the stubs



 
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

Can you please answer some very basic questions of mine.

1) The WSDL location specified in the generated stubs, must be accessible from the client's machine. (What ever the case may be). Am i right?
2) The end point must be hittable from the client's machine.

Please let me know if the above 2 points I am saying are correct?

Actually, we have a WSDL posted on a HTTPS url. And the client says, they have protected it. And we are not able to open it in our browser.
So, can that be a reason I am not able to invoke the web service methods?

Regards
Yogesh
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic