cxf客户端代码中的port对象

时间:2018-06-13 06:48:02

标签: java soap cxf

我正在考虑重写cxf客户端代码:http://cxf.apache.org/docs/developing-a-consumer.html因为每次端口对象都没有真正快速重新创建。

如果我将此代码放在单例类中,是否有问题?例如,在多线程应用程序中。

URL wsdlURL;
File wsdlFile = new File(args[0]);
if (wsdlFile.exists()) {
  wsdlURL = wsdlFile.toURL();
} else {
  wsdlURL = new URL(args[0]);
}

System.out.println(wsdlURL);
SOAPService ss = new SOAPService(wsdlURL, SERVICE_NAME);
Greeter port = ss.getSoapPort();

例如这个类:

public class GreeterUtils {

   private static Greeter port = null;

   private WsUtils() {
   }

   public static Greeter getGreeterPort() {
    if(port != null){
        return port         
    }

    URL wsdlURL;
    File wsdlFile = new File(args[0]);
    if (wsdlFile.exists()) {
      wsdlURL = wsdlFile.toURL();
    } else {
      wsdlURL = new URL(args[0]);
    }

    System.out.println(wsdlURL);
    SOAPService ss = new SOAPService(wsdlURL, SERVICE_NAME);
    port = ss.getSoapPort();
    return port;
 }
}

感谢您的任何建议, 爱德华多

0 个答案:

没有答案