You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by Winston Lee <yi...@yahoo.com> on 2002/08/13 17:39:17 UTC
Graphic User Interface in Soap Client
Hi,
I tried to use JApplet as client side User Graphic Interface, when I
used the soap method in the applet, there is an org/apache/rpcmessage
error. Then, I tried to use JFrame to replace it.
Here is my code, there is still a nullpointerError. Some one can help
me or tell me some useful example links, or code?
I also tried to run soap-2_3/sample/bidbuy example, this is the only
GUI example I could find. When I ran it, there are always errors.
I know someone can help me
// TestActionEvent.java: Test ActionEvent
package myframe.test;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import org.apache.soap.Constants;
import org.apache.soap.SOAPException;
import org.apache.soap.Envelope;
import org.apache.soap.Fault;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Response;
import org.apache.soap.rpc.Parameter;
public class TestActionEvent extends JFrame
implements ActionListener
{
// Create two buttons
private JButton jbtOk = new JButton("OK");
private JButton jbtCancel = new JButton("Cancel");
HelloWorldClient hello;
/**Default constructor*/
public TestActionEvent()
{
// Set the window title
setTitle("TestActionEvent");
// Set FlowLayout manager to arrange the components
// inside the frame
getContentPane().setLayout(new FlowLayout());
// Add buttons to the frame
getContentPane().add(jbtOk);
getContentPane().add(jbtCancel);
// Register listeners
jbtOk.addActionListener(this);
jbtCancel.addActionListener(this);
}
public String sendBack(){
return "Hello Wei Li!";
}
/**Main method*/
public static void main(String[] args)
{
TestActionEvent frame = new TestActionEvent();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
frame.setVisible(true);
}
/**This method will be invoked when a button is clicked*/
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == jbtOk)
{
try{
hello.caller = "You are a good guy !";
hello.receiver = hello.getSoap( hello.caller );
System.out.println("This is" + hello.receiver );
}catch(Exception eee){
System.err.println("first----" + eee );
}
}
else if (e.getSource() == jbtCancel)
{
try{
hello.caller = "You are a bad guy !";
hello.receiver = hello.getSoap( hello.caller );
System.out.println("This is not" + hello.receiver );
}catch(Exception eee){
System.err.println("Second-----" + eee );
}
}
}
}
package myframe.test;
import java.net.URL;
import java.util.Vector;
import java.util.Arrays;
import org.apache.soap.Constants;
import org.apache.soap.SOAPException;
import org.apache.soap.Envelope;
import org.apache.soap.Fault;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Response;
import org.apache.soap.rpc.Parameter;
public class HelloWorldClient {
static String caller;
static String receiver;
public String getSoap(String args) throws Exception {
String methodName = "com.lesavon.test.HelloWorldClient.main";
String url = "http://localhost:8080/HelloWorld/rpcrouter";
String uri = "urn:helloworld"; // must match HelloWorld.xml
String remoteMethod = "getMessage";
TestActionEvent event = new TestActionEvent();
receiver = args;
Call call = new Call();
caller = event.sendBack();
Parameter param = new Parameter("caller", caller.getClass(),
caller,
Constants.NS_URI_SOAP_ENC);
call.setTargetObjectURI(uri);
call.setMethodName(remoteMethod);
call.setParams(new Vector(Arrays.asList(new Parameter[] {
param
})));
Response resp = call.invoke(new URL(url), "");
// Check the response.
if (resp.generatedFault()) {
Fault fault = resp.getFault();
throw new SOAPException(fault.getFaultCode(),fault.getFaultString());
} else {
//if (resp.getReturnValue() != null) {
Object result = resp.getReturnValue().getValue();
return (String)result;
//}
}
}
}
---------------------------------
Do You Yahoo!?
HotJobs, a Yahoo! service - Search Thousands of New Jobs