JBIEndpointManagerpublic class JBIEndpointManager extends Object Class to manage enabling and disabling of endpoints in NMR. It uses
EndpointHelper to manage the endpoints. |
Fields Summary |
---|
private RegistryManager | registryManager | private final Logger | logger | private com.sun.enterprise.jbi.serviceengine.util.soap.StringTranslator | translator |
Constructors Summary |
---|
JBIEndpointManager()
registryManager = new RegistryManager();
translator = new StringTranslator(this.getClass().getPackage().getName(),
this.getClass().getClassLoader());
|
Methods Summary |
---|
private void | createEndpoint(com.sun.enterprise.deployment.WebServiceEndpoint endpoint, DescriptorEndpointInfo ep)Create a WSEndpoint and add it to the EndpointRegistry. The
JBIAdapterBuilder will later use this endpoint to create a JBIAdapter.
This code is copied from JAXWSServlet.registerEndpoint() with the
following changes-
--> Container is null as there is no need for security and
monitoring pipes
--> No ServletAdapter is created and only WSEndpoints are created
--> No updates are made to JAXWSAdapterRegistry. A different registry
specific to Java EE service engine is used.
Related Issue: 6519371.
BundleDescriptor bundledesc = endpoint.getBundleDescriptor();
ClassLoader cl = bundledesc.getClassLoader();
// set the app classloader to be used while creating the WSEndpoint
ClassLoader origCl = Utility.setContextClassLoader(cl);
try {
WsUtil wsu = new WsUtil();
Class serviceEndpointClass =
Class.forName(endpoint.getServletImplClass(), true, cl);
// Get the proper binding using BindingID
String givenBinding = endpoint.getProtocolBinding();
// Get list of all wsdls and schema
SDDocumentSource primaryWsdl = null;
Collection docs = null;
if(endpoint.getWebService().hasWsdlFile()) {
BaseManager mgr;
if(bundledesc.getApplication().isVirtual()) {
mgr = DeploymentServiceUtils.getInstanceManager(DeployableObjectType.WEB);
} else {
mgr = DeploymentServiceUtils.getInstanceManager(DeployableObjectType.APP);
}
String deployedDir =
mgr.getLocation(bundledesc.getApplication().getRegistrationName());
File pkgedWsdl;
if(deployedDir != null) {
if(bundledesc.getApplication().isVirtual()) {
pkgedWsdl = new File(deployedDir+File.separator+
endpoint.getWebService().getWsdlFileUri());
} else {
pkgedWsdl = new File(deployedDir+File.separator+
bundledesc.getModuleDescriptor().getArchiveUri().replaceAll("\\.", "_") +
File.separator + endpoint.getWebService().getWsdlFileUri());
}
} else {
pkgedWsdl = new File(endpoint.getWebService().getWsdlFileUrl().getFile());
}
if(pkgedWsdl.exists()) {
primaryWsdl = SDDocumentSource.create(pkgedWsdl.toURL());
docs = wsu.getWsdlsAndSchemas(pkgedWsdl);
}
}
// Get catalog info
java.net.URL catalogURL = null;
File catalogFile = new File(bundledesc.getDeploymentDescriptorDir() +
File.separator + "jax-ws-catalog.xml");
if(catalogFile.exists()) {
catalogURL = catalogFile.toURL();
}
// Create Binding and set service side handlers on this binding
// MTOMFeature mtom = new MTOMFeature(wsu.setMtom(endpoint));
WSBinding binding = BindingID.parse(givenBinding).createBinding();
wsu.configureJAXWSServiceHandlers(endpoint, givenBinding, binding);
WSEndpoint wsep = WSEndpoint.create(
serviceEndpointClass, // The endpoint class
false, // we do not want JAXWS to process @HandlerChain
null, // the invoker interface
endpoint.getServiceName(), // the service QName
endpoint.getWsdlPort(), // the port
null, // Container is used to set custom security/monitoring pipe
binding, // Derive binding
primaryWsdl, // primary WSDL
docs, // Collection of imported WSDLs and schema
catalogURL
);
EndpointHelper epHelper = EndpointHelper.getInstance();
epHelper.registerEndpoint(endpoint);
registryManager.getSEEndpoint(ep).setWsep(wsep);
} finally {
Utility.setContextClassLoader(origCl);
}
| void | removeAllEndpoints(java.lang.String su_Name)Clear the registry. This will be called during service unit undeployment.
registryManager.removeAllConsumerEP(su_Name);
registryManager.removeAllProviderEP(su_Name);
registryManager.removeServiceUnit(su_Name);
| void | startAllEndpoints(java.lang.String su_Name)Start all the endpoints specified in jbi.xml. In case of consumer just
the state variable is set to started. For providers all the endpoints are
activated in NMR.
EndpointHelper epHelper = EndpointHelper.getInstance();
for (DescriptorEndpointInfo ep : registryManager.getAllConsumerEP(su_Name))
ep.setStarted(true);
for (DescriptorEndpointInfo ep : registryManager.getAllProviderEP(su_Name)) {
if(registryManager.getSEEndpoint(ep)==null) {
WebServiceEndpoint endpoint = registryManager.getWSEndpoint(ep, su_Name);
if(endpoint == null)
throw new Exception(
translator.getString("serviceengine.endpoint_mismatch",
ep.getServiceName().getLocalPart(),
su_Name));
createEndpoint(endpoint, ep);
}
ep.setStarted(true);
// now activate the endpoint in NMR
epHelper.enableEndpoint(ep.getServiceName(), ep.getEndpointName());
}
| void | stopAllEndpoints(java.lang.String su_Name)Disable the endpoints enabled in during start
EndpointHelper epHelper = EndpointHelper.getInstance();
for (DescriptorEndpointInfo ep : registryManager.getAllConsumerEP(su_Name))
ep.setStarted(false);
for (DescriptorEndpointInfo ep : registryManager.getAllProviderEP(su_Name)) {
ep.setStarted(false);
// now de-activate the endpoint in NMR
epHelper.disableEndpoint(ep.getServiceName(), ep.getEndpointName());
}
| void | storeAllEndpoints(java.lang.String appLocation, java.lang.String su_Name)Parse the jbi.xml file and read enpoint information. Store this
information in the EndpointRegistry. JBIDescriptorReader is used to
read jbi.xml. It creates a list of DescriptorEndpointInfo objects
corresponding to the endpoints specified in the jbi.xml
If there is any exception while parsing jbi.xml then deployment of the
service unit will be stopped.
InputStream jbi_xml = null;
try {
if(new File(appLocation).isDirectory()) {
jbi_xml = new FileInputStream(appLocation +
File.separator +
"META-INF" +
File.separator +
"jbi.xml");
} else {
ZipFile zipFile = new ZipFile(appLocation);
for (Enumeration e = zipFile.entries(); e.hasMoreElements();) {
ZipEntry zipEntry = (ZipEntry) e.nextElement();
if("META-INF/jbi.xml".equals(zipEntry.getName())) {
jbi_xml = zipFile.getInputStream(zipEntry);
break;
}
}
}
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(false);
Document doc = factory.newDocumentBuilder().parse(jbi_xml);
JBIDescriptorReader reader = new JBIDescriptorReader(su_Name);
reader.init(doc);
registryManager.addAllEndpointInfo(reader.getEndpoints());
registryManager.addServiceUnit(su_Name);
} catch (Exception e) {
String exceptionText =
translator.getString("serviceengine.jbixml_readerror",su_Name);
logger.log(Level.SEVERE,exceptionText,e);
throw new Exception(exceptionText, e);
} finally {
if(jbi_xml!=null)
jbi_xml.close();
}
|
|