try
{
Reference ref = (Reference)obj;
// Unmarshall the ServiceRefMetaData
UnifiedServiceRefMetaData serviceRef = null;
RefAddr metaRefAddr = ref.get(ServiceReferenceable.SERVICE_REF_META_DATA);
ByteArrayInputStream bais = new ByteArrayInputStream((byte[])metaRefAddr.getContent());
try
{
ObjectInputStream ois = new ObjectInputStream(bais);
serviceRef = (UnifiedServiceRefMetaData)ois.readObject();
ois.close();
}
catch (IOException ex)
{
NamingException ne = new NamingException("Cannot unmarshall service ref meta data");
ne.setRootCause(ex);
throw ne;
}
// Unmarshall the WSSecurityConfiguration
WSSecurityConfiguration securityConfig = null;
RefAddr wsseRefAddr = ref.get(ServiceReferenceable.SECURITY_CONFIG);
if (wsseRefAddr != null)
{
bais = new ByteArrayInputStream((byte[])wsseRefAddr.getContent());
try
{
ObjectInputStream ois = new ObjectInputStream(bais);
securityConfig = (WSSecurityConfiguration)ois.readObject();
ois.close();
}
catch (IOException e)
{
throw new NamingException("Cannot unmarshall security config, cause: " + e.toString());
}
}
ServiceImpl jaxrpcService = null;
URL wsdlLocation = serviceRef.getWsdlLocation();
if (wsdlLocation != null)
{
if (log.isDebugEnabled())
log.debug("Create jaxrpc service from wsdl");
// Create the actual service object
QName serviceName = serviceRef.getServiceQName();
JavaWsdlMapping javaWsdlMapping = getJavaWsdlMapping(serviceRef);
jaxrpcService = new ServiceImpl(serviceName, wsdlLocation, javaWsdlMapping, securityConfig, serviceRef);
}
else
{
if (log.isDebugEnabled())
log.debug("Create jaxrpc service with no wsdl");
jaxrpcService = new ServiceImpl(new QName(Constants.NS_JBOSSWS_URI, "AnonymousService"));
}
ServiceMetaData serviceMetaData = jaxrpcService.getServiceMetaData();
// Set any service level properties
if (serviceRef.getCallProperties().size() > 0)
{
Properties callProps = new Properties();
serviceMetaData.setProperties(callProps);
for (UnifiedCallPropertyMetaData prop : serviceRef.getCallProperties())
callProps.setProperty(prop.getPropName(), prop.getPropValue());
}
// The web service client using a port-component-link, the contet is the URL to
// the PortComponentLinkServlet that will return the actual endpoint address
RefAddr pcLinkRef = ref.get(ServiceReferenceable.PORT_COMPONENT_LINK);
if (pcLinkRef != null)
{
String pcLink = (String)pcLinkRef.getContent();
log.debug("Resolving port-component-link: " + pcLink);
// First try to obtain the endpoint address loacally
String endpointAddress = null;
try
{
SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
EndpointRegistry epRegistry = spiProvider.getSPI(EndpointRegistryFactory.class).getEndpointRegistry();
Endpoint endpoint = epRegistry.resolve( new PortComponentResolver(pcLink) );
if (endpoint == null)
throw new WSException("Cannot resolve port-component-link: " + pcLink);
ServerEndpointMetaData sepMetaData = endpoint.getAttachment(ServerEndpointMetaData.class);
endpointAddress = sepMetaData.getEndpointAddress();
}
catch (Throwable ex)
{
// ignore, we are probably a remote client
}
// We may be remote in the esoteric case where an appclient uses the port-comonent-link feature
if (endpointAddress == null)
{
String servletPath = (String)ref.get(ServiceReferenceable.PORT_COMPONENT_LINK_SERVLET).getContent();
servletPath += "?pcLink=" + URLEncoder.encode(pcLink, "UTF-8");
InputStream is = new URL(servletPath).openStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
endpointAddress = br.readLine();
is.close();
}
if (log.isDebugEnabled())
log.debug("Resolved to: " + endpointAddress);
if (serviceMetaData.getEndpoints().size() == 1)
{
EndpointMetaData epMetaData = serviceMetaData.getEndpoints().get(0);
epMetaData.setEndpointAddress(endpointAddress);
}
else
{
log.warn("Cannot set endpoint address for port-component-link, unsuported number of endpoints");
}
}
narrowPortSelection(serviceRef, serviceMetaData);
/********************************************************
* Setup the Proxy that implements the service-interface
********************************************************/
// load the service interface class
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
Class siClass = contextCL.loadClass(serviceRef.getServiceInterface());
if (Service.class.isAssignableFrom(siClass) == false)
throw new JAXRPCException("The service interface does not implement javax.xml.rpc.Service: " + siClass.getName());
// load all service endpoint interface classes
for (UnifiedPortComponentRefMetaData pcr : serviceRef.getPortComponentRefs())
{
String seiName = pcr.getServiceEndpointInterface();
if (seiName != null)
{
Class seiClass = contextCL.loadClass(seiName);