This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Web Services and the fly likes JAX-WS can't connect to server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "JAX-WS can Watch "JAX-WS can New topic
Author

JAX-WS can't connect to server

Marek Krokosinski
Ranch Hand

Joined: Jun 10, 2011
Posts: 64
Hello.

I have a problem with my JAX WS Client-server connection. So I want to connect to the database through webservice using hibernate. So I have something like this:

I run WSserver which is on external machine, server connects to database which is on the same machine as WS Server. I run client from my pc and there is exception



On my external server I have same java version, same tomcat, everything is the same. When I had a test client, (simple hello world) it worked fine, I had the connection. When I have added the part with hibernate and database, I've got the error like above.
Any ideas what can couse that error? You want me to post source code?

Best regards.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
How about a firewall?

What is the URL you are using? Did you use "localhost" when client and server were on the same machine?

Bill
Marek Krokosinski
Ranch Hand

Joined: Jun 10, 2011
Posts: 64
To connect to external server i use http://ip.address:8080/WebServiceServer/WebServiceSvr?wsdl

On localhost it also doesn't work. URL is almost the same (ip.address is switched to localhost).

I think it's not a firewall because when I will delete the method which should get data from database it works fine (hello world is working).


On localhost I have tested the Hibernate connection (I created class with main method and I made some request to that external database, I have ran it as java application) and it also worked fine. So from localhost when I run the java app with that Hibernate files I can connect to database on external server.
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 640
did you check your server logs after you put database code? may be there are errors while deploying the application so webservice is not deployed at all?

check the ouput of http://ip.address:8080/WebServiceServer/WebServiceSvr?wsdl on browser when you have hello world code and then again after deploying database code.

-P


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Marek Krokosinski
Ranch Hand

Joined: Jun 10, 2011
Posts: 64
Application deploys correctly, server logs are empty.

I can see the wsdl after entering my server address. And I can enter on it when hello world method is added, and when helloworld and the database method are.added It works, XML file is always displayed.

Maybe I will tell one more thing. Server is always online, like I said. When I run client and I try to use both of these methods, I get an exception. When I will comment on client the part which tries to use the WebMethod which connects to database, client connects with WS Server and it gets response from helloworld method. So maybe problem is with client? The method which connects to the database is first method which I have ever wrote for webservice, so there is big chance that I made that wrong...
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 640
well, in development phase of my web service I always use some tool for client, like SOAP UI for jax-ws and/or RestClient for Jax-RS. for simple reason it helps me to narrow down the problem.
once my web service gives expected result using these tools, I am sure my web service is working fine then I go for developing client (if required) so any issue here after is (always) related to client.

so if possible for you, try to use SOAP UI and see if you can access both methods without error.
If not then one way is to narrow down the problem is to invoke getDataFromDb from helloworld in server and invoke only hellowWorld from client.
so steps are

Modify Server HelloWorld method to invoke getDataFromDb (I assume both are in same class so it will be local call)
Modify Client and comment the call of getDataFromDb.

if this works fine, i.e getDataFromDb is success then yes there is something wrong with the way you are invoking it from client.
Marek Krokosinski
Ranch Hand

Joined: Jun 10, 2011
Posts: 64
Praful Thakare wrote:well, in development phase of my web service I always use some tool for client, like SOAP UI for jax-ws and/or RestClient for Jax-RS. for simple reason it helps me to narrow down the problem.
once my web service gives expected result using these tools, I am sure my web service is working fine then I go for developing client (if required) so any issue here after is (always) related to client.

so if possible for you, try to use SOAP UI and see if you can access both methods without error.
If not then one way is to narrow down the problem is to invoke getDataFromDb from helloworld in server and invoke only hellowWorld from client.
so steps are

Modify Server HelloWorld method to invoke getDataFromDb (I assume both are in same class so it will be local call)
Modify Client and comment the call of getDataFromDb.

if this works fine, i.e getDataFromDb is success then yes there is something wrong with the way you are invoking it from client.


I will look on that soapUI, and when I will get back home, I will try to modify the HelloWorld method.

thank you for your time, I will post my results.
Marek Krokosinski
Ranch Hand

Joined: Jun 10, 2011
Posts: 64
Ok I have installed the trial version of soapUI. I made test like here http://www.soapui.org/Functional-Testing/functional-testing.html

and when I created new project from wsdl, I get all methods.
Hello world works fine, but of course in getDataFromDb throws errors. The text from "AUT" tab is SOAP RESPONSE VALID and RESPONSE SLA VALID. HelloWorld and getdataFromDb are shining on green color, but the response from getDataFromDb is not correct.
I don't know exactly how to debug it but in XSD there is:



in table 1 I have: Cannot open connection

In RAW tab;

Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 640
as I suspected, its problem with you connection to database.

since the soap is showing green for getData means the call is successful and since there was error at server, instead of normal response , fault is returned.
Inspect your server logs, you will find the cause of connection error, look for sqlExceptionsin logs


-P
Marek Krokosinski
Ranch Hand

Joined: Jun 10, 2011
Posts: 64
Thank you very much Praful Thakare. Earlier I was looking only on tomcat-XXX logs, but this time the error was in catalina-XXX log file. Application couldn't connect to database (It was rejected by mysql security file), after reconfiguration of MYSQL security settings everything works perfectly ! And thanks for soapUI tool, I think that It will be very useful for me.
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 640
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JAX-WS can't connect to server