private Map xfServices = new ConcurrentHashMap();
public XFireServiceUnit(XFireComponent component, String serviceUnitName, String serviceUnitRootPath) throws Exception {
super(component, serviceUnitName, serviceUnitRootPath);
for (Iterator iter = services.iterator(); iter.hasNext();) {
EndpointSpec es = (EndpointSpec) iter.next();
Service svc = component.getFactory().create(es.getPojo().getClass());
component.getXFire().getServiceRegistry().register(svc);
component.getXFire().getTransportManager().disableAll(svc.getName());
Transport jbiT = component.getXFire().getTransportManager().getTransport(JbiTransport.JBI_BINDING);
component.getXFire().getTransportManager().enable(jbiT, svc.getName());
QName serviceName = svc.getServiceInfo().getName();
String endpointName = null;
if (es.getServiceName() == null) {
es.setServiceName(serviceName);
} else if (!es.getServiceName().equals(serviceName)) {
logger.warn("The service name defined in the wsdl (" + serviceName +
") does not match the service name defined in the endpoint spec (" + es.getServiceName() +
"). WSDL description may be unusable.");
}
// put service description
try {
SourceTransformer st = new SourceTransformer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
component.getXFire().generateWSDL(svc.getName(), baos);
Node node = st.toDOMNode(new StreamSource(new ByteArrayInputStream(baos.toByteArray())));
Definition d = WSDLFactory.newInstance().newWSDLReader().readWSDL(null, (Document) node);
javax.wsdl.Service service = d.getService(serviceName);
if (service != null) {
if (service.getPorts().values().size() == 1) {
endpointName = ((Port) service.getPorts().values().iterator().next()).getName();
// Check if this is the same as defined in endpoint spec
if (es.getEndpointName() == null) {
es.setEndpointName(endpointName);
} else if (!es.getEndpointName().equals(endpointName)) {
logger.warn("The endpoint name defined in the wsdl (" + endpointName +
") does not match the endpoint name defined in the endpoint spec (" + es.getEndpointName() +
"). WSDL description may be unusable.");
}
}
}
if (es.getEndpointName() == null) {
throw new IllegalArgumentException("endpointName should be provided on the endpointSpec");
}
component.setServiceDescription(es.getServiceName(), es.getEndpointName(), (Document) node);
if (logger.isDebugEnabled()) {
logger.debug("WSDL: " + st.toString(node));
}
} catch (Exception e) {
logger.warn("Could not set endpoint description", e);