manash
manash

Reputation: 7106

Testing web service connectivity with CXF

I have a CXF web service that I use through a Swing client. First, I create a JaxWsProxyFactoryBean, then I create the JAX WS proxy. At this point, I want to test that the client can properly send a message to the web service. I understand that HTTP is a stateless protocol thus it does not use any connection at its layer. Until now, I've used a ping() method defined by the web service in order for the client to test connectivity.

What is the proper way to do that? I don't think adding a dummy method to the API just to allow testing connectivity is the best solution. Is there a CXF way to do that though the proxy?

Thanks

Upvotes: 2

Views: 2253

Answers (1)

Paulius Matulionis
Paulius Matulionis

Reputation: 23415

You have a couple of options to do so:

  1. I assume that your web service is SOAP web service, then you can issue a HTTP HEAD request for the WSDL document.
  2. Implement a special "ping" operation (SOAP) in the web service. (Probably you already have it)

If you choose first option - make a HTTP HEAD request you can use following code to achieve that:

public static boolean exists(String webServiceUrl){
    try {
        HttpURLConnection.setFollowRedirects(false);
        HttpURLConnection connection = (HttpURLConnection) new URL(webServiceUrl).openConnection();
        connection.setRequestMethod("HEAD");
        return connection.getResponseCode() == HttpURLConnection.HTTP_OK;
    } catch (Exception e) {      
        return false;
    }
}

If you are to perform HEAD request to your web service, this means that web service is accessible.

Upvotes: 2

Related Questions