View Single Post
Old Jun 23rd, 2006, 2:08 PM   #4
melisand
Newbie
 
Join Date: Jun 2006
Location: Lisbon, Portugal
Posts: 2
Rep Power: 0 melisand is on a distinguished road
package samples.dspace;

import java.io.*;
import java.util.*;
import java.net.*;
import org.w3c.dom.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;

public class Client{

   public Client(){}

    public void chamada(String c){
	
	URL url=null;

	try{
	    url = new URL("http://localhost:8082/soap/servlet/rpcrouter");
	}catch(Exception e){
	    e.printStackTrace();
	}

	Call call=new Call();

	//Name of the service

	call.setTargetObjectURI("urn:DSpaceTest");

//name of the method
	call.setMethodName("teste");
	call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
	Vector params = new Vector();

	//Declaracao dos parametros

	params.addElement(new Parameter("teste",String.class,c,null));
	call.setParams(params);

	System.out.println("call object: "+call);

	//Fazer a chamada
	Response resp=null;

	try{
	    System.out.println("Going to call invoke(url, \"\")");
	    resp=call.invoke(url, "");

	}catch(SOAPException e){

	    System.err.println("Caught an exception "+e.getFaultCode()+ "," + e.getMessage());
	    System.exit(-1);
	}

	//Devolve resposta

	if(!resp.generatedFault()){
	    Parameter ret = resp.getReturnValue();
	    Object value=ret.getValue();
	    System.out.println(value);
	}
	else{
	    Fault fault = resp.getFault();
	    System.err.println("Generated fault: ");
	    System.out.println("Fault Code = "+fault.getFaultCode());
	    //	    System.out.println("Fault Code = "+fault.toString());
	    System.out.println("Fault String = "+ fault.getFaultString());
	}
	System.out.println("\n FINISHING...");

    }


    public static void main(String args[]){

	Cliente cliente=new Cliente();
	cliente.chamada("dora");
	}
}
__________________
D.P.
melisand is offline   Reply With Quote