users@jax-rpc.java.net

Dynamic Proxy Client and Authentication

From: Dang Thi Phuong Nhi <nhidtp_at_tekciz.com>
Date: Wed, 10 Aug 2005 21:18:34 +0700

Please help me!
This is my MathClient.java:

package dynamicproxy;

import java.net.URL;
import javax.xml.rpc.Service;
import javax.xml.rpc.JAXRPCException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceFactory;
import dynamicproxy.*;


public class MathClient {

   public static void main(String[] args) {
      try {
         String nameSpaceUri = "urn:Foo";
         String serviceName = "MyFirstService";
         String portName = "MathFacePort";

         // Specify the location of the WSDL file
         URL url = new URL("http://localhost:8081/math-service/math?WSDL");

         // Create an instance of service factory
         ServiceFactory serviceFactory = ServiceFactory.newInstance();

         // Create a service object to act as a factory for proxies.
         Service mathService = serviceFactory.createService(url,
                    new QName(nameSpaceUri, serviceName));

         // Create a proxy
         dynamicproxy.MathFace
                    myProxy = (dynamicproxy.MathFace) mathService.getPort(new
         QName(nameSpaceUri,
                    portName), dynamicproxy.MathFace.class);
         
          ((javax.xml.rpc.Stub)myProxy)._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY,"admin");
    ((javax.xml.rpc.Stub)myProxy)._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY,"phuongnhi");


         // Invoke the add method
         System.out.println(myProxy.add(23, 12));
      } catch (Exception ex) {
         ex.printStackTrace();
      }
   }
}

I've authenticate in dynamic proxy but it has some mistake when I execute it:

E:\Projects\client\dynamic-proxy>java -classpath %classpath%;build dynamicproxy.
MathClient
javax.xml.rpc.ServiceException: modeler error: failed to parse document at "http
://localhost:8081/math-service/math?WSDL": java.io.IOException: Server returned
HTTP response code: 401 for URL: http://localhost:8081/math-service/math?WSDL
        at com.sun.xml.rpc.client.dii.ConfiguredService.<init>(ConfiguredService
.java:60)
        at com.sun.xml.rpc.client.dii.ConfiguredService.<init>(ConfiguredService
.java:47)
        at com.sun.xml.rpc.client.ServiceFactoryImpl.createService(ServiceFactor
yImpl.java:37)
        at dynamicproxy.MathClient.main(MathClient.java:26)

E:\Projects\client\dynamic-proxy>

Please correct it for me.
Thank you very much indeed.
Sincerely

Dang Thi Phuong Nhi
Software Developer
---------------------------------
Technology Consultancy, Investment and Development Company Limited
Suite 1001, 10th Floor, Building 17T3 Trung Hoa - Nhan Chinh Area,
Tran Duy Hung Road, Cau Giay, Ha Noi.
Tel: +84 - 4 - 2510938
Fax: +84 - 4 - 2510939
Email: nhidtp_at_tekciz.com
Website: www.tekciz.com