users@jax-rpc.java.net

Java application trying to connect to remote web service via SSL

From: Kwan Hon Luen <hon_luen_at_YAHOO.COM>
Date: Wed, 30 Oct 2002 10:35:58 +0800

Hi all,

I have a problem here:
A java client application (not a servlet, just pure console) trying to connect to remote web service via SSL.

I can just this java console client to connect via non-SSL port. What modification do I have to make to both the web service and the client, in order to connect via SSL? I have checked out the Sun web service tutorial, but not relevant, since I am using a java console client here, and not a servlet.

Can someone help?

~honluen


--------------------------------------------------------------------------------

On the web service machine,

This is the config.xml which I use xrpcc to build the web service.

<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">

  <service name="HelloService"
 targetNamespace="http://192.168.168.88/HelloService.wsdl"
 typeNamespace="http://192.168.168.88/HelloService/HelloService/type"
 packageName="hello">

 <interface
  name="hello.HelloIF"
  servantName="hello.HelloImpl"/>
  </service>
</configuration>

This is the web.xml which I use to deploy the web service on tomcat server.

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">

<web-app>
  <display-name>Hello World Application</display-name>
  <description>A Java application containing a simple JAX-RPC endpoint</description>
  <session-config>
    <session-timeout>60</session-timeout>
  </session-config>

  <security-constraint>
    <web-resource-collection>
      <web-resource-name>helloservice</web-resource-name>
      <url-pattern>/endpoint*</url-pattern>
      <http-method>GET</http-method>
      <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
      <role-name>manager</role-name>
    </auth-constraint>
  </security-constraint>
  <login-config>
    <auth-method>BASIC</auth-method>
  </login-config>

  <servlet>
      <servlet-name>JAXRPCEndpoint</servlet-name>
      <display-name>JAXRPCEndpoint</display-name>
      <description>Endpoint for Hello Service</description>
      <servlet-class>com.sun.xml.rpc.server.http.JAXRPCServlet</servlet-class>
      <init-param>
           <param-name>configuration.file</param-name>
           <param-value>/WEB-INF/HelloService_Config.properties</param-value>
      </init-param>
      <load-on-startup>0</load-on-startup>
  </servlet>

  <servlet-mapping>
      <servlet-name>JAXRPCEndpoint</servlet-name>
      <url-pattern>/endpoint/*</url-pattern>
  </servlet-mapping>

  <session-config>
      <session-timeout>60</session-timeout>
  </session-config>
</web-app>


--------------------------------------------------------------------------------


On the client machine,

This is the config.xml which i use xrpcc to generate the client stubs. Is there any wrong here? since I should be accessing via https://192.168.168.88:443/helloservice/endpoint?WSDL, but that gives me errors.

<?xml version="1.0" encoding="UTF-8"?>
<configuration
  xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
  <wsdl location="http://192.168.168.88:8080/helloservice/endpoint?WSDL"
       packageName="hello"/>
</configuration>

This is the client code, which I suspect is not very correct.

package hello;

import javax.xml.rpc.Stub;

public class HelloClient {
    public static void main(String[] args) {

        String trustStore = "f:/SSL/client.keystore";
        String trustStorePassword = "12345678";
        String username = "honluen";
        String password = "12345678";
  
  try {
            HelloIF_Stub stub = (HelloIF_Stub)(new HelloService_Impl().getHelloIFPort());

            System.setProperty("javax.net.ssl.trustStore",
                trustStore);
            System.setProperty("javax.net.ssl.trustStorePassword",
               trustStorePassword);
            stub._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY,
                username);
            stub._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY,
                password);
    
    HelloIF_Stub hello = (HelloIF_Stub)stub;
            System.out.println(hello.sayHello("DSSS!"));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}


--------------------------------------------------------------------------------