Invoking Soap service fails in java, works in soapui - java

I'm trying to consume a soap service in java.
If I import the wsdl url in SOAPUI, I get the :java.net.ConnectException connection timed out exception.
I saved the WSDL to a file and successfully inported it into SOAPUI.
In SOAPUI, I'm able to consume it.
In java however, i still get the java.net.ConnectException connection timed out exception
when trying to consume it, having tried with a number of different libraries that work on other webservices in the same network.
I've also tried putting my entreprise proxy in java with no effect.
However, if i put a local proxy, like Fiddler, in front of java, I cat invoke the webservice successfully. The server where it's hosted has ping (ICMP) blocked.
Event if I make a simple get for the WSDl address I get the java.net.ConnectException connection timed out exception.
Does anyone have any suggestions on how to troubleshoot this?

Related

WSO2 API Manager Connection Error , "Error occurred while sending the HEAD request to the given endpoint url"

I'm trying to configure the WSO2 API Manager. (version - v4.0.0)
When I try to create REST API and point to the endpoints I"m getting a Connection error message for the given endpoints. I have hosted the API Manager and the back end services on the same server(backend services are running on the tomcat application on the same server in port 8080)
API Manager Log produces the following message :
ERROR {org.wso2.carbon.apimgt.rest.api.publisher.v1.impl.ApisApiServiceImpl} - Error occurred while sending the HEAD request to the given endpoint url: org.apache.commons.httpclient.ConnectTimeoutException: The host did not accept the connection within timeout of 4000 ms
would really like to what has caused the issue.
P.S: I can access the backend services directly without any connection issues using a REST client.
It's difficult to answer the question without knowing the exact details of your deployment and the backend. But let me try. Here is what I think is happening. As you can clearly see, the error is a connection timeout The host did not accept the connection within timeout of 4000 ms.
Let me explain what happens when you click on the Check Endpoint Status button. When you click on the Check Endpoint Status button, the Browser is not directly sending a request to the Backend to validate it. The Backend URL will be passed to the APIM Server, and the Server will perform the validation by sending an HTTP HEAD request to the BE service.
So there can be two causes. First may be your backend doesn't know how to handle a HEAD request which is preventing it from accepting the request. But given the error indicated it's a network issue, I doubt it even reached the BE.
The second one is, that your Backend is not accessible from the place API Manager is running. If you are running API Manager on Server A and trying to access API Manager via browser from Server B(Local Machine). Although you can access the BE from Server B may be from Server A it's not accessible. When I say BE is not accessible from API Manager server, it means it's not accessible with the same URL that was used in API Manager. It doesn't really matter if it runs in the same Server if you are using a different DNS other than localhost to access it. So go to the server API Manager is running and send a request using the same URL that was used in API Manager and see whether it's accessible from there.
First try doing a curl request by login into the server where APIM is running (not from your local machine). Maybe due to some firewall rules within the server, the hostname given in the URL may not be accessible. Also, try sending a HEAD request as well. You might be able to get some idea why this is happening

How to handle occasional SocketException: Unexpected end of file from server?

I have a REST service that calls another remote service.
Most of the time the communication works fine, but occasionally, I encounter
org.apache.cxf.jaxrs.client.ClientWebApplicationException:
org.apache.cxf.interceptor.Fault: Could not send Message.
org.apache.cxf.interceptor.Fault: Could not send Message.
SocketException invoking https://url: Unexpected end of file from server
I did some research and found it's the remote server shut down the connection unexpectedly.
It really puzzles me, because everything (input, header, etc) is the same and I was testing with a small amount of requests only like (50-100), I have tried both in sequence and in parallel, only a few will encounter this issue.
Why would this happen? Do I have to ask the remote server to reconfigure, or do I have to implement a retry pattern in my service in this case?
Any hint?
Thanks
P.S
I am using
org.apache.cxf.jaxrs.client.WebClient
to invoke the remote service. Will it make any difference if I switch to HttpClient?

Getting java.net.ConnectException : Connection refused

I looked for solutions on SO for this but none of them seem to apply to my case. So here goes:
I have an application that needs to make a service call to a third party domain. I am using jersey client to make this service call. The code for making this call is
ClientResponse resp = resourceWithParams.
header("Authorization", getAccessKeyId() + ":" +
hmacSha1.toUpperCase()).
post(ClientResponse.class,"");
where resourceWithParams is the jersey web resource. Note that even though its is a POST, the web service is expecting a query string and empty body. It might be questionable design but that is what we have to work with.
This setup is working just fine on my local machine as well as on our preprod server. However on our production servers it gives an exception:
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused
There are a couple of points below that might be helpful in pointing me in the right direction:
1) We get a valid response when we use curl on the prod server command line to send a request to the web service so seems like there are no firewall issues. This is happening only when we try it through the web application, i.e. through the java code using jersey client.
2) There are no proxies set up on the prod servers
3) Works fine from localhost.
4) The Rest webservice uses https and the correct certificates are installed on our server which is proved by the fact that curling the webservice on prod works fine.
Any ideas on what the issue might be and where we should start looking?
EDIT:
As mentioned we were using https to connect to the webservice. If we use http instead, it does seem to be working.
I suggest you set up a tcpdump session to see where the connection refused is coming from. In particular, see what the source IP and destination IP addresses are, for both the successful connections and the unsuccessful ones.
There are two possibilities the above is designed to test for:
You say you're not using proxy servers, but Java actually has a separate proxy configuration from the rest of the system, so it may be that your Java is configured to use a non-functional proxy server.
Your Java system could be sending requests using a different source IP address to the one that your curl is using.

Apache xml-rpc client and server implementation

I have been trying to figure out how to implement a simple xml rpc server and client with apache xml-rpc (http://ws.apache.org/xmlrpc/) but i haven't been successfull. I implemented a server and a client as specified here in the section Webserver: http://ws.apache.org/xmlrpc/server.html
The only thing i did differently was this "phm.addHandler("Calculator",org.apache.xmlrpc.demo.Calculator.class);" instead of this "phm.load(Thread.currentThread().getContextClassLoader(), "MyHandlers.properties");". When i start the server it start properly but I can't see the service when running netstat. Then when I run a request from the client it fails because it cannot find the class to call (i.e. the client doesn't really connect to the server). I have also observed that the client can start (not sending any requests) without any errors even when the server is not running.
Anyone have any ideas. I'm really lost.
Are you trying to run both client and server on the same computer? ...that may be the reason for netstat not working. (It cannot sniff packets on the loopback address.)
If you're still interested I can post a working example.

How to debug tomcat webservice?

I'm running two instances of tomcat on the same machine for 2 parts of a web application(client app and server app). the client has no datastore and uses the server to interact with the database. The server app uses a wsdl web service to listen for GET requests from the client. I get an invalid login everytime I try to login through the client app. If I try to access the LoginService via browser directly I get this error from the catalina logs.
[PhaseInterceptorChain:369] Interceptor for {http://ws.myoscar_server.oscarehr.org/}LoginWsService has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: No such operation: (HTTP GET PATH_INFO: /myoscar_server/LoginService)
I'm not sure what you mean by "everytime i try to login." I think the error you see in the catalina logs is just saying that you are hitting the web service that is listening for only POST requests, but with a browser, you are sending a GET request. That error might be throwing you off. I would first use something like Firefox Poster to send a POST request to your service and see what the real error is.

Categories