tcl = this.getClass().getClassLoader();
ServiceFactory factory = ServiceFactory.newInstance();
javax.xml.rpc.Service service = null;
// Service Interface
RefAddr tmp = ref.get(ServiceRef.SERVICE_INTERFACE);
String serviceInterface = null;
if (tmp != null)
serviceInterface = (String) tmp.getContent();
// WSDL
tmp = ref.get(ServiceRef.WSDL);
String wsdlRefAddr = null;
if (tmp != null)
wsdlRefAddr = (String) tmp.getContent();
// PortComponent
Hashtable<String,QName> portComponentRef =
new Hashtable<String,QName>();
// Create QName object
QName serviceQname = null;
tmp = ref.get(ServiceRef.SERVICE_LOCAL_PART);
if (tmp != null) {
String serviceLocalPart = (String) tmp.getContent();
tmp = ref.get(ServiceRef.SERVICE_NAMESPACE);
if (tmp == null) {
serviceQname = new QName(serviceLocalPart);
} else {
String serviceNamespace = (String) tmp.getContent();
serviceQname = new QName(serviceNamespace,
serviceLocalPart);
}
}
Class<?> serviceInterfaceClass = null;
// Create service object
if (serviceInterface == null) {
if (serviceQname == null) {
throw new NamingException
("Could not create service-ref instance");
}
try {
if (wsdlRefAddr == null) {
service = factory.createService( serviceQname );
} else {
service = factory.createService( new URL(wsdlRefAddr),
serviceQname );
}
} catch (Exception e) {
NamingException ex = new NamingException
("Could not create service");
ex.initCause(e);
throw ex;
}
} else {
// Loading service Interface
try {
serviceInterfaceClass = tcl.loadClass(serviceInterface);
} catch(ClassNotFoundException e) {
NamingException ex = new NamingException
("Could not load service Interface");
ex.initCause(e);
throw ex;
}
if (serviceInterfaceClass == null) {
throw new NamingException
("Could not load service Interface");
}
try {
if (wsdlRefAddr == null) {
if (!Service.class.isAssignableFrom(serviceInterfaceClass)) {
throw new NamingException
("service Interface should extend javax.xml.rpc.Service");
}
service = factory.loadService( serviceInterfaceClass );
} else {
service = factory.loadService( new URL(wsdlRefAddr),
serviceInterfaceClass,
new Properties() );
}
} catch (Exception e) {
NamingException ex = new NamingException
("Could not create service");
ex.initCause(e);
throw ex;
}
}
if (service == null) {
throw new NamingException
("Cannot create service object");
}
serviceQname = service.getServiceName();
serviceInterfaceClass = service.getClass();
if (wsdlRefAddr != null) {
try {
WSDLFactory wsdlfactory = WSDLFactory.newInstance();
WSDLReader reader = wsdlfactory.newWSDLReader();
reader.setFeature("javax.wsdl.importDocuments", true);
Definition def = reader.readWSDL((new URL(wsdlRefAddr)).toExternalForm());
javax.wsdl.Service wsdlservice = def.getService(serviceQname);
@SuppressWarnings("unchecked") // Can't change the API
Map<String,?> ports = wsdlservice.getPorts();
Method m = serviceInterfaceClass.getMethod("setEndpointAddress",
new Class[] { java.lang.String.class,
java.lang.String.class });
for (Iterator<String> i = ports.keySet().iterator(); i.hasNext();) {
String portName = i.next();
Port port = wsdlservice.getPort(portName);
String endpoint = getSOAPLocation(port);
m.invoke(service, new Object[] {port.getName(), endpoint });
portComponentRef.put(endpoint, new QName(port.getName()));
}
} catch (Exception e) {
NamingException ex = new NamingException
("Error while reading Wsdl File");
ex.initCause(e);
throw ex;
}
}
ServiceProxy proxy = new ServiceProxy(service);
// Use port-component-ref
for (int i = 0; i < ref.size(); i++)
if (ServiceRef.SERVICEENDPOINTINTERFACE.equals(ref.get(i).getType())) {
String serviceendpoint = "";
String portlink = "";
serviceendpoint = (String) ref.get(i).getContent();
if (ServiceRef.PORTCOMPONENTLINK.equals(ref.get(i + 1).getType())) {
i++;
portlink = (String) ref.get(i).getContent();
}
portComponentRef.put(serviceendpoint, new QName(portlink));
}
proxy.setPortComponentRef(portComponentRef);
// Instantiate service with proxy class
Class<?>[] interfaces = null;
Class<?>[] serviceInterfaces = serviceInterfaceClass.getInterfaces();
interfaces = new Class[serviceInterfaces.length + 1];
for (int i = 0; i < serviceInterfaces.length; i++) {
interfaces[i] = serviceInterfaces[i];
}
interfaces[interfaces.length - 1] = javax.xml.rpc.Service.class;
Object proxyInstance = null;
try {
proxyInstance = Proxy.newProxyInstance(tcl, interfaces, proxy);
} catch (IllegalArgumentException e) {
proxyInstance = Proxy.newProxyInstance(tcl, serviceInterfaces, proxy);
}
// Use handler
if (((ServiceRef) ref).getHandlersSize() > 0) {
HandlerRegistry handlerRegistry = service.getHandlerRegistry();
ArrayList<String> soaproles = new ArrayList<String>();
while (((ServiceRef) ref).getHandlersSize() > 0) {
HandlerRef handlerRef = ((ServiceRef) ref).getHandler();
HandlerInfo handlerInfo = new HandlerInfo();
// Loading handler Class
tmp = handlerRef.get(HandlerRef.HANDLER_CLASS);
if ((tmp == null) || (tmp.getContent() == null))
break;
Class<?> handlerClass = null;
try {
handlerClass = tcl.loadClass((String) tmp.getContent());
} catch(ClassNotFoundException e) {
break;
}
// Load all datas relative to the handler : SOAPHeaders, config init element,