开发者

java InvocationTargetException when calling Web Service from Applet

开发者 https://www.devze.com 2023-02-05 07:53 出处:网络
I have a locally hosted web service that I want to call from an applet.I\'ve created the necessary service handling code using wsimport and the service wsdl.I\'ve tested that the java client and .Net

I have a locally hosted web service that I want to call from an applet. I've created the necessary service handling code using wsimport and the service wsdl. I've tested that the java client and .Net service work correctly from my IDE.

So I bundle up the code and sign it and put it in a web page. I call the applet from javascript. I've added a helloWorld() method to confirm that the applet loads and JS can access it. When I call the web service the code does not catch any exceptions. Instead the page gets an error. When I check to see what it is it's a target invocation exception.

I added some sys out calls and it's dying here:

ServiceEndpoint authService = new ServiceEndpoint(
   new URL(serviceURL),
   new QName(serviceNamespace, serviceName)

The class that it's calling was created using wsimport. The serviceName etc are strings that are passed. When I look at the generated code for this class it instantiates its super class javax开发者_如何学编程.xml.ws.Service.

I'm stumped. Could it be that the javax.xml.ws.Service is not availabel to browsers? I would think there would be a class not found exception in that case.

Thanks for any help.


I found the issue but it brings me to a new question. First, the answer. I needed to wrap my call to the web service in:

AccessController.doPrivileged(new PrivilegedAction<Object>()
{
  public Object run()
  {
    try
    {
       // Do my stuff here
    }
  }
}

What I don't understand is why. The web service that I am calling resides on the same server as the applet is loaded from. Is it possible that the wsimport generated classes that I use to access the web service are doing something I'm not aware of?

Happy I found a work around, not happy that I don't understand why.

Any thoughts or illuminations would be fantastic.

Thanks

0

精彩评论

暂无评论...
验证码 换一张
取 消