Invoke web service method inside Java Applet
I succesfully builded a simple Java Web Service (as examp开发者_开发技巧le you can refer to the "Building simple web service" )
In Eclipse is easy to create a web service client by using the "Java Web Service Proxy technique" indicated in the tutorial.
I want to run a Java Applet that do the same things of the java client application: access the web service, invoke the methods and return the results.
When i run the code by Eclipse (right click > "run as Java Applet..") everything works fine.. when i run the applet in a simple html page the applet start but goes in deadlock: No exceptions are thrown, and the process is blocked without doing anything on the line that create the MyWebServiceProxy class, invoking the default constructor.
Can anyone help me in this?
I paste here some code to Let you understand better what i'm doing inside the applet:
public class SimpleWSApplet extends Applet {
public void paint(Graphics g)
{
String msg = "Applet initialized";
int i = 1;
g.drawString(msg, 20, 20*i++);
msg = "Error in applet";
try {
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress("http://localhost:8080/AppletWSTest/services/SimpleWS");
call.setOperationName(new QName("http://soapinterop.org/", "getMessage"));
msg = (String)call.invoke(new Object[]{});
} catch (Exception e) {
e.printStackTrace();
msg = "Error: "+e.getMessage();
}
g.drawString(msg, 20, 20*i++);
//g.drawString(executeInvocation(msg), 20, 20*i++);
}
}
Obviously my web service is called "SimpleWS" and the method that i invoke is called "getMessage", it takes no arguments, and returns a String.
Please help me..
As you know, java applets are executed in a sandbox. By default, applets don't have any access to any web resource except from their original servers. Only signed applets can access such kind of resources. Therefore, you should sign your applet.
精彩评论