1
2
3
4
5
6
7
8 package it.imolinfo.jbi4corba.jbi.component;
9
10 import it.imolinfo.jbi4corba.Logger;
11 import it.imolinfo.jbi4corba.LoggerFactory;
12 import it.imolinfo.jbi4corba.exception.ClassGenerationException;
13 import it.imolinfo.jbi4corba.exception.Jbi4CorbaDeployException;
14 import it.imolinfo.jbi4corba.exception.Jbi4CorbaException;
15 import it.imolinfo.jbi4corba.exception.Jbi4CorbaRuntimeException;
16 import it.imolinfo.jbi4corba.jbi.JbiServiceDescriptor;
17 import it.imolinfo.jbi4corba.jbi.Messages;
18 import it.imolinfo.jbi4corba.jbi.component.runtime.ComponentRuntime;
19 import it.imolinfo.jbi4corba.jbi.component.runtime.DefaultServiceUnitManager;
20 import it.imolinfo.jbi4corba.jbi.component.runtime.RuntimeConfiguration;
21 import it.imolinfo.jbi4corba.jbi.component.runtime.RuntimeContext;
22 import it.imolinfo.jbi4corba.jbi.component.runtime.RuntimeHelper;
23 import it.imolinfo.jbi4corba.jbi.endpoint.ConsumerEndpoint;
24 import it.imolinfo.jbi4corba.jbi.endpoint.Jbi4CorbaEndpoint;
25 import it.imolinfo.jbi4corba.jbi.endpoint.ProviderEndpoint;
26 import it.imolinfo.jbi4corba.jbi.wsdl.Jbi4CorbaAddress;
27 import it.imolinfo.jbi4corba.jbi.wsdl.Jbi4CorbaBinding;
28 import it.imolinfo.jbi4corba.jbi.wsdl.Jbi4CorbaExtPreprocessDeserializer;
29 import it.imolinfo.jbi4corba.jbi.wsdl.Jbi4CorbaExtension;
30 import it.imolinfo.jbi4corba.jbi.wsdl.Jbi4CorbaExtensionRegistry;
31 import it.imolinfo.jbi4corba.jbi.wsdl.Jbi4CorbaExtensionUtils;
32 import it.imolinfo.jbi4corba.utils.HelperFileUtil;
33 import it.imolinfo.jbi4corba.webservice.descriptor.ConsumerServiceDescriptor;
34 import it.imolinfo.jbi4corba.webservice.descriptor.ProviderServiceDescriptor;
35 import it.imolinfo.jbi4corba.webservice.generator.ChildFirstClassLoader;
36 import it.imolinfo.jbi4corba.webservice.generator.ClientCorbaClassesHolder;
37 import it.imolinfo.jbi4corba.webservice.generator.ProviderServiceClassesGenerator;
38
39 import java.io.File;
40 import java.io.FileWriter;
41 import java.io.IOException;
42 import java.io.StringWriter;
43 import java.net.URLClassLoader;
44 import java.util.ArrayList;
45 import java.util.HashMap;
46 import java.util.Hashtable;
47 import java.util.List;
48 import java.util.Map;
49 import java.util.Properties;
50 import java.util.logging.Level;
51
52 import javax.jbi.JBIException;
53 import javax.jbi.management.DeploymentException;
54 import javax.jbi.servicedesc.ServiceEndpoint;
55 import javax.management.MBeanException;
56 import javax.wsdl.Binding;
57 import javax.wsdl.Definition;
58 import javax.wsdl.PortType;
59 import javax.wsdl.Service;
60 import javax.wsdl.WSDLException;
61 import javax.wsdl.extensions.ExtensionRegistry;
62 import javax.wsdl.factory.WSDLFactory;
63 import javax.wsdl.xml.WSDLReader;
64 import javax.wsdl.xml.WSDLWriter;
65 import javax.xml.namespace.QName;
66 import javax.xml.parsers.DocumentBuilder;
67 import javax.xml.parsers.DocumentBuilderFactory;
68 import javax.xml.parsers.ParserConfigurationException;
69 import javax.xml.transform.OutputKeys;
70 import javax.xml.transform.Transformer;
71 import javax.xml.transform.dom.DOMSource;
72 import javax.xml.transform.stream.StreamResult;
73
74 import org.apache.xml.resolver.CatalogManager;
75 import org.apache.xml.resolver.tools.CatalogResolver;
76 import org.xml.sax.EntityResolver;
77
78 import com.ibm.wsdl.Constants;
79 import com.sun.jbi.eManager.provider.EndpointStatus;
80 import com.sun.jbi.eManager.provider.StatusProviderHelper;
81 import com.sun.jbi.eManager.provider.StatusReporting;
82 import com.sun.jbi.management.descriptor.ConfigurationException;
83 import com.sun.jbi.management.descriptor.EndpointIdentifier;
84 import com.sun.jbi.management.descriptor.SUDescriptorSupport;
85 import com.sun.wsdl4j.ext.impl.WSDLFactoryEx;
86 import com.sun.wsdl4j.ext.impl.WSDLReaderEx;
87 import it.imolinfo.jbi4corba.jbi.wsdl.Jbi4CorbaIDLEntry;
88 import java.util.Arrays;
89 import java.util.Map.Entry;
90 import java.util.Set;
91 import javax.wsdl.Port;
92 import javax.wsdl.extensions.ExtensibilityElement;
93 import org.apache.commons.io.FileUtils;
94
95
96
97
98
99
100
101 public class Jbi4CorbaSUManager extends DefaultServiceUnitManager {
102
103
104 private static final Logger LOG = LoggerFactory.getLogger(Jbi4CorbaSUManager.class);
105
106
107
108 private static final Messages MESSAGES = Messages.getMessages(Jbi4CorbaSUManager.class);
109
110 private List<Jbi4CorbaEndpoint> deployedEndpoints = new ArrayList<Jbi4CorbaEndpoint>();
111
112 private List<Jbi4CorbaEndpoint> activatedEndpoints = new ArrayList<Jbi4CorbaEndpoint>();
113
114 private Jbi4CorbaLifeCycle lifeCycle = null;
115 private TransformerPool mTransformerPool;
116 private RuntimeConfiguration runtimeConfiguration;
117
118 private Hashtable<String, List<ClientCorbaClassesHolder>> classesTable;
119 private URLClassLoader tmpURLclassLoader = null;
120 private ChildFirstClassLoader tmpOriginaclassLoader = null;
121
122
123
124
125
126
127 public Jbi4CorbaSUManager(ComponentRuntime ctx) {
128 super(ctx);
129 this.lifeCycle = (Jbi4CorbaLifeCycle) ctx.getLifeCycle();
130 mTransformerPool = new TransformerPool();
131 classesTable = new Hashtable<String, List<ClientCorbaClassesHolder>>();
132 }
133
134
135
136
137
138
139
140
141
142
143
144
145
146 public String deploy(String suName, String suZipPath) throws DeploymentException {
147
148 final String taskName = "deploy";
149 boolean isSuccess = true;
150
151 LOG.info("CRB000214_Deploying_the_su_in_SA",
152 new java.lang.Object[]{suName, suZipPath});
153
154
155
156 String retMsg = createComponentTaskResultXML(taskName, isSuccess);
157
158 return retMsg;
159 }
160
161
162
163
164
165
166
167
168
169
170 public void start(String serviceUnitName) throws javax.jbi.management.DeploymentException {
171
172 LOG.debug("Starting the serviceUnit: " + serviceUnitName);
173 LOG.debug("Deployed Endpoints number: " + deployedEndpoints.size());
174
175
176 for (Jbi4CorbaEndpoint endpoint : deployedEndpoints) {
177
178 LOG.debug("endpoint.getSuName():" + endpoint.getSuName());
179 if (endpoint.getSuName().equals(serviceUnitName)) {
180 try {
181
182 LOG.debug("Registering the service: " + endpoint.getServiceName());
183 endpoint.registerService();
184
185
186 endpoint.activate();
187
188
189 LOG.debug("Activating the service for the bus: " + endpoint.getServiceName());
190 activateEndpoint(endpoint);
191
192 activatedEndpoints.add(endpoint);
193
194 } catch (Jbi4CorbaException e) {
195 LOG.error(e.getMessage());
196 throw new DeploymentException(e);
197
198 }
199 }
200 }
201
202 }
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218 public String undeploy(String serviceUnitName, String suZipPath)
219 throws DeploymentException {
220 final String taskName = "undeploy";
221
222
223 List<String> keys = new ArrayList<String>();
224
225 for (String key : classesTable.keySet()) {
226 if (key.startsWith(serviceUnitName)) {
227 keys.add(key);
228 }
229 }
230 for (String key : keys) {
231 classesTable.remove(key);
232 }
233
234
235 boolean isSuccess = true;
236
237 String retMsg = createComponentTaskResultXML(taskName, isSuccess);
238 return retMsg;
239 }
240
241
242
243
244
245
246
247 public void stop(String serviceUnitName)
248 throws javax.jbi.management.DeploymentException {
249
250 List<Jbi4CorbaEndpoint> endpointsToRemove = new ArrayList<Jbi4CorbaEndpoint>();
251
252
253 for (Jbi4CorbaEndpoint corbaEndpoint : activatedEndpoints) {
254 if (corbaEndpoint.getSuName().equals(serviceUnitName)) {
255 try {
256
257
258 corbaEndpoint.deactivate();
259
260 deactivateEndpoint(corbaEndpoint);
261
262 endpointsToRemove.add(corbaEndpoint);
263
264 } catch (Jbi4CorbaException e) {
265 LOG.error(e.getMessage());
266 throw new DeploymentException(e);
267
268 }
269 }
270 }
271 activatedEndpoints.removeAll(endpointsToRemove);
272 }
273
274
275
276
277
278
279
280
281
282
283
284
285
286 public void init(String serviceUnitName, String serviceUnitRootPath)
287 throws javax.jbi.management.DeploymentException {
288
289 final StatusProviderHelper statusProviderHelper = lifeCycle.getStatusProviderHelper();
290 try {
291
292
293 deployedEndpoints.addAll(processDeploy(serviceUnitName, serviceUnitRootPath, statusProviderHelper));
294 LOG.debug("Init: do nothing");
295 } catch (Exception ex) {
296
297 LOG.error("Failed to Deploy Service Unit:" + serviceUnitName + "\n" + ex, ex);
298
299 throw new DeploymentException(ex);
300 }
301
302 }
303
304
305
306
307
308
309
310 public void shutDown(String serviceUnitName)
311 throws javax.jbi.management.DeploymentException {
312
313
314 List<Jbi4CorbaEndpoint> deployedEndpointsToRemove = new ArrayList<Jbi4CorbaEndpoint>();
315
316 for (Jbi4CorbaEndpoint corbaEndpoint : deployedEndpoints) {
317 if (corbaEndpoint.getSuName().equals(serviceUnitName)) {
318 deployedEndpointsToRemove.add(corbaEndpoint);
319 }
320 }
321
322 deployedEndpoints.removeAll(deployedEndpointsToRemove);
323 }
324
325
326
327
328
329
330 public Jbi4CorbaEndpoint getStartedEndpoint(ServiceEndpoint endpoint) {
331 LOG.debug("Activated endpoint size: " + activatedEndpoints.size());
332 return getEndpointFromList(endpoint, activatedEndpoints);
333 }
334
335
336
337
338
339
340 public Jbi4CorbaEndpoint getDeployedEndpoint(ServiceEndpoint endpoint) {
341 LOG.debug("Deployed endpoint size: " + activatedEndpoints.size());
342 return getEndpointFromList(endpoint, deployedEndpoints);
343 }
344
345 private boolean containsTrueCorbaWsdl(File file, EntityResolver resolver, Map envVariableMap) throws WSDLException {
346 final WSDLFactoryEx wsdlFactory = new WSDLFactoryEx();
347 final WSDLReaderEx reader = wsdlFactory.newWSDLReaderEx();
348 reader.setEntityResolver(resolver);
349 reader.setFeature(Constants.FEATURE_VERBOSE, true);
350 reader.setFeature(Constants.FEATURE_IMPORT_DOCUMENTS, true);
351 reader.setExtensionRegistry(new Jbi4CorbaExtensionRegistry(envVariableMap));
352
353 final Definition def = reader.readWSDL(file.getAbsolutePath());
354 Map serviceMap = def.getServices();
355 LOG.debug("servizi: " + Arrays.toString(serviceMap.keySet().toArray()));
356 for (Entry entry : (Set<Entry>) serviceMap.entrySet()) {
357 Service service = (Service) entry.getValue();
358 for (Entry portEntry : (Set<Entry>) service.getPorts().entrySet()) {
359 Port port=(Port)portEntry.getValue();
360 List extElems = port.getExtensibilityElements();
361 LOG.debug("extensibility elements: " + Arrays.toString(extElems.toArray()));
362 for (ExtensibilityElement extensibilityElement : (List<ExtensibilityElement>) extElems) {
363 if (Jbi4CorbaAddress.class.isInstance(extensibilityElement)) {
364 return true;
365 }
366 }
367 }
368 }
369 return false;
370 }
371
372
373
374
375
376
377
378 private Jbi4CorbaEndpoint getEndpointFromList(ServiceEndpoint endpoint, List<Jbi4CorbaEndpoint> endpointList) {
379
380 for (Jbi4CorbaEndpoint corbaEndpoint : endpointList) {
381 LOG.debug("Looking for: " + endpoint.getServiceName() + "|" + endpoint.getEndpointName());
382
383
384 if ((corbaEndpoint.getServiceName().equals(endpoint.getServiceName())) &&
385 (corbaEndpoint.getEndpointName().equals(endpoint.getEndpointName()))) {
386 LOG.debug("getEndpointFromList: Returning:" + corbaEndpoint);
387 LOG.debug("getEndpointFromList: with service description:" + corbaEndpoint.getServiceDescription());
388 return corbaEndpoint;
389 }
390
391 }
392 LOG.debug("getEndpointFromList: Returning null");
393
394
395 return null;
396 }
397
398 private JbiServiceDescriptor getJbidesc(EndpointIdentifier epDesc, List<JbiServiceDescriptor> jbdescs) {
399 for (int i = 0; i < jbdescs.size(); i++) {
400 QName intname = new QName(jbdescs.get(i).getServiceNameSpace(), jbdescs.get(i).getServiceName());
401 if (epDesc.getInterfaceName().equals(intname)) {
402 return jbdescs.get(i);
403 }
404 }
405 return jbdescs.get(0);
406 }
407
408 private ProviderServiceDescriptor getProviderdesc(List<ProviderServiceDescriptor> psdesc, String serviceName) {
409 for (int i = 0; i < psdesc.size(); i++) {
410
411 if (psdesc.get(i).getServiceName().equals(serviceName)) {
412 return psdesc.get(i);
413 }
414 }
415 LOG.debug("getProviderdesc: Returning null");
416 return null;
417 }
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432 private List<Jbi4CorbaEndpoint> processDeploy(String suName, String suZipPath, final StatusProviderHelper statusProviderHelper)
433 throws DeploymentException, IOException, Jbi4CorbaRuntimeException, ClassGenerationException {
434
435 final File suDir = new File(suZipPath);
436
437
438 List<Jbi4CorbaSUInfo> jbisuInfo = new ArrayList<Jbi4CorbaSUInfo>();
439 List<JbiServiceDescriptor> jbdescs = getJbiDescriptors(suName, suZipPath, jbisuInfo);
440
441 List<Jbi4CorbaEndpoint> endpoints = new ArrayList<Jbi4CorbaEndpoint>();
442
443 ProviderServiceClassesGenerator serviceClassesGenerator = new ProviderServiceClassesGenerator();
444
445 File rootDir = null;
446 if (jbdescs.size() > 0) {
447 rootDir = new File(
448 suZipPath + File.separator + jbdescs.get(0).hashCode());
449
450
451 boolean resultMk = rootDir.mkdir();
452 if (!resultMk) {
453 throw new DeploymentException(MESSAGES.getString(
454 "CRB000201_Unable_to_create_working_directory",
455 rootDir.getAbsolutePath()));
456 } else {
457 LOG.debug("created working directory:" + rootDir.getAbsolutePath());
458 }
459
460 }
461
462 List<ProviderServiceDescriptor> psdesc = null;
463
464
465
466 if (rootDir != null) {
467 psdesc = getProviderServiceDescriptor(suName, jbdescs, suZipPath, serviceClassesGenerator, rootDir);
468 }
469
470 Jbi4CorbaEndpoint corbaEndpoint = null;
471 LOG.debug("The SU dir path is: " + suDir.getAbsolutePath());
472
473 final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
474
475 docBuilderFactory.setNamespaceAware(true);
476
477 DocumentBuilder documentBuilder = null;
478
479 try {
480 documentBuilder = docBuilderFactory.newDocumentBuilder();
481 } catch (ParserConfigurationException ex) {
482 String msg = MESSAGES.getString("CRB000216_Failure_in_creating_document_builder",
483 new Object[]{ex.getMessage()});
484 LOG.error(msg, ex);
485 throw new DeploymentException(msg, ex);
486 }
487
488
489 EndpointIdentifier epDesc;
490 File matchedWSDL;
491 Definition matchedDef;
492
493 for (int i = 0; i < jbdescs.size(); i++) {
494
495 epDesc = jbisuInfo.get(i).getEpIdentifier();
496 matchedWSDL = jbisuInfo.get(i).getMatchedWSDL();
497 matchedDef = jbisuInfo.get(i).getMatchedDef();
498
499
500 rootDir = new File(
501 suZipPath + File.separator + jbdescs.get(i).hashCode());
502
503
504 if (epDesc.isProvider()) {
505
506
507 corbaEndpoint = generateProvider(suZipPath,
508 epDesc,
509 getJbidesc(epDesc, jbdescs),
510 getProviderdesc(psdesc, jbdescs.get(i).getServiceName()),
511 rootDir);
512
513 } else {
514
515
516
517 ConsumerServiceDescriptor consumerServiceDescriptor = getConsumerServiceDescriptor(epDesc, jbdescs.get(i), rootDir);
518 consumerServiceDescriptor.setServiceWSDLDefinition(matchedDef);
519 String endpointNameLocalPart = QName.valueOf(epDesc.getEndpointName()).getLocalPart();
520 corbaEndpoint = new ConsumerEndpoint(epDesc.getServiceName(), endpointNameLocalPart, consumerServiceDescriptor);
521 }
522
523
524 if (statusProviderHelper != null) {
525 StatusReporting reporting = statusProviderHelper.getStatusReporter();
526 String uniqueName = null;
527
528 uniqueName = corbaEndpoint.getUniqueName();
529 if (epDesc.isProvider()) {
530 reporting.addProvisioningEndpoint(uniqueName);
531 } else {
532 reporting.addConsumingEndpoint(uniqueName);
533 }
534 EndpointStatus stat = reporting.getEndpointStatus(uniqueName);
535 corbaEndpoint.setEndpointStatus(stat);
536 } else {
537 LOG.warn("StatusProviderHelper is null.StatusReporting not created.");
538 }
539
540
541 corbaEndpoint.setDefinition(matchedDef);
542 corbaEndpoint.setState(Jbi4CorbaEndpoint.SHUTDOWN);
543 corbaEndpoint.setSuName(suName);
544 corbaEndpoint.setSuManager(this);
545 corbaEndpoint.setEndpointWSDL(matchedWSDL);
546
547 if (corbaEndpoint != null) {
548 try {
549
550
551
552 endpoints.add(corbaEndpoint);
553
554 populateEndpointWSDLInfo(corbaEndpoint.getEndpointStatus(), corbaEndpoint);
555 } catch (Exception ex) {
556 java.util.logging.Logger.getLogger(Jbi4CorbaSUManager.class.getName()).log(Level.SEVERE, null, ex);
557 }
558 } else {
559 LOG.debug("CorbaEndpoint is Null");
560 }
561 }
562
563 return endpoints;
564 }
565
566 @SuppressWarnings("unchecked")
567 public Map<String, String[]> parseForEnvironmentVariables(String suPath, Map<String, String[]> envVariableMap)
568 throws Jbi4CorbaRuntimeException {
569
570 Map<String, String[]> envVariables =
571 new HashMap<String, String[]>(envVariableMap);
572
573 File catalog = new File(suPath +
574 File.separator + "meta-inf" + File.separator +
575 "catalog.xml");
576
577 EntityResolver resolver = null;
578
579 if (catalog.exists()) {
580 CatalogManager catalogManager = new CatalogManager();
581 catalogManager.setCatalogFiles(catalog.getAbsolutePath());
582 catalogManager.setRelativeCatalogs(true);
583 catalogManager.setUseStaticCatalog(false);
584 resolver = new CatalogResolver(catalogManager);
585 }
586
587 for (File file : listWSDLFiles(new File(suPath))) {
588 try {
589 envVariables.putAll(readWSDLForEnvVariables(file, resolver, envVariables));
590 } catch (WSDLException ex) {
591 String msg = MESSAGES.getString("CRB000233_Error_in_parsing_environment_variables");
592 LOG.error(msg, ex.getMessage());
593 throw new Jbi4CorbaRuntimeException(ex);
594 }
595
596 }
597
598 return envVariables;
599 }
600
601 @SuppressWarnings("unchecked")
602 private Map readWSDLForEnvVariables(File f, EntityResolver resolver, Map<String, String[]> envVariableMap)
603 throws WSDLException {
604
605 WSDLFactoryEx wsdlFactory = new WSDLFactoryEx();
606 WSDLReaderEx reader = wsdlFactory.newWSDLReaderEx();
607 reader.setEntityResolver(resolver);
608 Jbi4CorbaExtPreprocessDeserializer preProcessDeserializer = new Jbi4CorbaExtPreprocessDeserializer(envVariableMap);
609 reader.setExtensionRegistry(new Jbi4CorbaExtensionRegistry(preProcessDeserializer));
610 reader.readWSDL(f.getAbsolutePath());
611 return preProcessDeserializer.getEnvVariableMap();
612 }
613
614 @SuppressWarnings("unchecked")
615 private Definition readWSDL(File f, EntityResolver resolver, Map envVariableMap)
616 throws WSDLException {
617
618 final WSDLFactoryEx wsdlFactory = new WSDLFactoryEx();
619 final WSDLReaderEx reader = wsdlFactory.newWSDLReaderEx();
620 reader.setEntityResolver(resolver);
621 reader.setFeature(Constants.FEATURE_VERBOSE, false);
622 reader.setFeature(Constants.FEATURE_IMPORT_DOCUMENTS, true);
623 reader.setExtensionRegistry(new Jbi4CorbaExtensionRegistry(envVariableMap));
624 LOG.debug("Extension QName: " + Jbi4CorbaExtension.NS_URI_JBI4CORBA);
625 final Definition def = reader.readWSDL(f.getAbsolutePath());
626 return def;
627
628 }
629
630
631
632
633
634
635 private void activateEndpoint(final Jbi4CorbaEndpoint endpoint) throws Jbi4CorbaDeployException {
636
637 LOG.debug("Activating endpoint: " + endpoint.getUniqueName());
638
639 if (activatedEndpoints.indexOf(endpoint) != -1) {
640 String msg = MESSAGES.getString("CRB000220_Failed_to_deploy_endpoint_because_already_registered",
641 new Object[]{endpoint.getUniqueName()});
642 LOG.error(msg);
643 throw new Jbi4CorbaDeployException(msg);
644 }
645 try {
646 QName serviceName = (QName) endpoint.getServiceName();
647 ServiceEndpoint serviceEndpoint = RuntimeHelper.getComponentContext().activateEndpoint(endpoint.getServiceName(), endpoint.getEndpointName());
648
649 endpoint.setServiceEndpoint(serviceEndpoint);
650 LOG.info("CRB000221_Endpoint_activated",
651 new Object[]{serviceName});
652 endpoint.setState(Jbi4CorbaEndpoint.RUNNING);
653
654 } catch (final JBIException me) {
655 String msg = MESSAGES.getString("CRB000222_Cannot_activate_endpoint",
656 new Object[]{endpoint.getServiceName()}, new Object[]{me.getMessage()});
657 LOG.error(msg, me);
658 throw new Jbi4CorbaDeployException(msg, me);
659 }
660 }
661
662
663
664
665
666
667 public void deactivateEndpoint(final Jbi4CorbaEndpoint endpoint) throws Jbi4CorbaDeployException {
668 LOG.debug("Deactivating endpoint: " + endpoint.getUniqueName());
669
670 if (!activatedEndpoints.contains(endpoint)) {
671 String msg = MESSAGES.getString("CRB000223_Endpoint_not_active",
672 new Object[]{endpoint.getUniqueName()});
673 LOG.error(msg);
674 throw new Jbi4CorbaDeployException(msg);
675 } else {
676 try {
677 RuntimeHelper.getComponentContext().deactivateEndpoint(endpoint.getServiceEndpoint());
678 LOG.debug("Endpoint " + endpoint.getServiceEndpoint() + " deactivated");
679 endpoint.setState(Jbi4CorbaEndpoint.STOPPED);
680 } catch (JBIException me) {
681 String msg = MESSAGES.getString("CRB000224_Cannot_deactivate_endpoint",
682 new Object[]{endpoint.getServiceName()}, new Object[]{me.getMessage()});
683 LOG.error(msg, me);
684 throw new Jbi4CorbaDeployException(msg, me);
685 }
686 }
687
688 }
689
690
691
692
693
694
695 private List<File> listWSDLFiles(final File currentDir) {
696 final List<File> cumulativeResults = new ArrayList<File>();
697 final File[] filesInCurrentDir = currentDir.listFiles();
698
699 for (File element : filesInCurrentDir) {
700
701 if (element.isFile()) {
702
703 if (element.getName().toLowerCase().endsWith(".wsdl")) {
704 cumulativeResults.add(element);
705 }
706 } else if (element.isDirectory()) {
707 final List<File> wsdlsInSubDirectories = listWSDLFiles(element);
708 cumulativeResults.addAll(wsdlsInSubDirectories);
709 }
710 }
711 return cumulativeResults;
712 }
713
714
715
716
717
718
719
720
721
722
723
724 FileToDefinitionInfo[] readAllDefinitions(final File dir)
725 throws DeploymentException {
726
727 final CatalogManager catalogManager = new CatalogManager();
728 catalogManager.setCatalogFiles(dir.getAbsolutePath() +
729 File.separator + "xml-catalog.xml");
730 catalogManager.setRelativeCatalogs(true);
731
732 final EntityResolver resolver = new CatalogResolver(catalogManager);
733
734 final List<File> wsdls = listWSDLFiles(dir);
735
736
737
738
739
740 List<FileToDefinitionInfo> fileToDefsList = new ArrayList<FileToDefinitionInfo>();
741
742 if (wsdls.size() > 0) {
743
744
745 for (File file : wsdls) {
746 Definition def = null;
747 try {
748 LOG.debug("esamino il file: " + file.getName() + " per vedere se è un vero wsdl corba ... ");
749 boolean isTrueCorba = containsTrueCorbaWsdl(file, resolver, runtimeConfiguration.retrieveApplicationVariablesMap());
750 LOG.debug("esaminato il file: " + file.getName() + " è un vero wsdl corba: " + isTrueCorba);
751 if (isTrueCorba) {
752 def = readWSDL(file, resolver, runtimeConfiguration.retrieveApplicationVariablesMap());
753 fileToDefsList.add(new FileToDefinitionInfo(file, def));
754 }
755 } catch (WSDLException e) {
756 String msg = MESSAGES.getString("CRB000225_Error_in_reading_wsdl_file",
757 new Object[]{e.getMessage()});
758 LOG.error(msg, e);
759 throw new DeploymentException(msg, e);
760 }
761
762 }
763 }
764
765 return fileToDefsList.toArray(new FileToDefinitionInfo[fileToDefsList.size()]);
766 }
767
768
769
770
771
772
773
774 public static Definition readWsdl(final File f) throws WSDLException {
775 final WSDLFactory wsdlFactory = WSDLFactory.newInstance();
776 ExtensionRegistry registry = wsdlFactory.newPopulatedExtensionRegistry();
777 final WSDLReader reader = wsdlFactory.newWSDLReader();
778 reader.setFeature(Constants.FEATURE_VERBOSE, false);
779 reader.setFeature(Constants.FEATURE_IMPORT_DOCUMENTS, true);
780 Jbi4CorbaExtension.register(registry);
781 LOG.debug("Extension QName: " + Jbi4CorbaExtension.NS_URI_JBI4CORBA);
782 reader.setExtensionRegistry(registry);
783 final Definition def = reader.readWSDL(f.getAbsolutePath());
784 return def;
785 }
786
787
788
789
790 static class FileToDefinitionInfo {
791
792
793 private File mFile;
794
795 private Definition mDefinition;
796
797
798
799
800
801
802
803 FileToDefinitionInfo(final File file, final Definition definition) {
804 mFile = file;
805 mDefinition = definition;
806 }
807
808
809
810
811
812
813 public File getFile() {
814 return mFile;
815 }
816
817
818
819
820
821
822 public Definition getDefinition() {
823 return mDefinition;
824 }
825 }
826
827
828
829
830
831
832 public Jbi4CorbaLifeCycle getLifeCycle() {
833 return lifeCycle;
834 }
835
836
837
838
839
840
841
842 public void setLifeCycle(Jbi4CorbaLifeCycle lifeCycle) {
843 this.lifeCycle = lifeCycle;
844 }
845
846
847
848
849
850
851 public List<Jbi4CorbaEndpoint> getDeployedEndpoints() {
852 return deployedEndpoints;
853 }
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872 protected JbiServiceDescriptor createServiceDescriptor(
873 Service service,
874 Binding binding,
875 PortType portType,
876 Jbi4CorbaAddress addressExtension,
877 Jbi4CorbaBinding bindingExtension,
878 String role,
879 String rootPath) throws DeploymentException {
880
881 JbiServiceDescriptor serviceDescriptor = new JbiServiceDescriptor();
882
883 LOG.debug("Creating a JbiServiceDescriptor ... ");
884
885
886
887 boolean idlFirstConsumer = (JbiServiceDescriptor.CONSUMER.equals(role) &&
888 !bindingExtension.getJbi4CorbaDLEntryList().isEmpty());
889
890 if (JbiServiceDescriptor.PROVIDER.equals(role) || idlFirstConsumer) {
891
892
893
894
895
896
897
898 String idlFileName = null;
899
900 for (Jbi4CorbaIDLEntry jbi4CorbaIDLEntry : bindingExtension.getJbi4CorbaDLEntryList()) {
901
902
903
904 String idl = jbi4CorbaIDLEntry.getIDL();
905 String fileName = jbi4CorbaIDLEntry.getIdlFilename();
906 String relativePath = jbi4CorbaIDLEntry.getRelativePath();
907 boolean root = jbi4CorbaIDLEntry.isRoot();
908 if (root) {
909 idlFileName = fileName;
910 relativePath = ".";
911 }
912
913 LOG.debug("processing ideEntry: " + jbi4CorbaIDLEntry.getRelativePath() + File.separator + jbi4CorbaIDLEntry.getIdlFilename());
914
915 String idlAbsoluteFileName = rootPath + File.separator + relativePath + File.separator + fileName;
916
917
918 LOG.debug("CRB000203_Producing_idl_file_to", new Object[]{idlAbsoluteFileName});
919 FileWriter fr;
920 try {
921 File file = new File(idlAbsoluteFileName);
922 File dir = new File(rootPath + File.separator + relativePath);
923
924 if (!file.exists()) {
925 if (!dir.exists()) {
926 LOG.debug("creating directory: " + dir.getAbsolutePath());
927 FileUtils.forceMkdir(dir);
928 }
929 file.createNewFile();
930 fr = new FileWriter(file);
931 fr.write(idl);
932 fr.close();
933 }
934 } catch (IOException e) {
935 String msg = MESSAGES.getString(
936 "CRB000204_Unable_to_open_filename",
937 idlAbsoluteFileName, e.getMessage());
938 LOG.error(msg, e);
939 throw new DeploymentException(msg, e);
940 }
941
942 }
943
944 if (idlFileName == null) {
945 String msg = MESSAGES.getString("CRB000236_No_Root_IDL_Entry_Defined");
946 LOG.error(msg);
947 throw new DeploymentException(msg);
948 }
949
950
951
952 serviceDescriptor.setIdlFileName(idlFileName);
953 serviceDescriptor.setIdlFileNameDirectory(rootPath);
954
955 serviceDescriptor.setPortTypeName(portType.getQName());
956
957 } else if (JbiServiceDescriptor.CONSUMER.equals(role)) {
958
959 } else {
960
961 LOG.error("CRB000205_Invalid_role=", role);
962 throw new DeploymentException(
963 MESSAGES.getString("CRB000205_Invalid_role=", role));
964 }
965
966
967 serviceDescriptor.setRole(role);
968
969
970 serviceDescriptor.setServiceNameSpace(service.getQName().getNamespaceURI());
971 serviceDescriptor.setServiceName(service.getQName().getLocalPart());
972
973
974 if (addressExtension != null) {
975 serviceDescriptor.setCorbaServiceName(addressExtension.getName());
976 serviceDescriptor.setLocalizationType(
977 addressExtension.getLocalizationType());
978 serviceDescriptor.setOrbProperties(addressExtension.getOrbProperties());
979 serviceDescriptor.setPersistent(addressExtension.isPeristent());
980 }
981
982
983 LOG.debug("Created a JbiServiceDescriptor=" + serviceDescriptor);
984 return serviceDescriptor;
985 }
986
987
988
989
990
991
992
993 private ConsumerServiceDescriptor getConsumerServiceDescriptor(
994 EndpointIdentifier epDesc,
995 JbiServiceDescriptor jbiServiceDescriptor,
996 File rootDir) {
997
998
999 ConsumerServiceDescriptor consumerServiceDescriptor = new ConsumerServiceDescriptor();
1000
1001 consumerServiceDescriptor.setRootPath(
1002 rootDir.getAbsolutePath());
1003 consumerServiceDescriptor.setServiceName(
1004 jbiServiceDescriptor.getServiceName());
1005 consumerServiceDescriptor.setCorbaServiceName(
1006 jbiServiceDescriptor.getCorbaServiceName());
1007
1008 LOG.debug("Consumer CORBA name:" + consumerServiceDescriptor.getCorbaServiceName());
1009
1010 consumerServiceDescriptor.setOrbProperties(
1011 jbiServiceDescriptor.getOrbProperties());
1012 consumerServiceDescriptor.setLocalizationType(
1013 jbiServiceDescriptor.getLocalizationType());
1014 consumerServiceDescriptor.setPersistent(jbiServiceDescriptor.isPersistent());
1015
1016
1017 consumerServiceDescriptor.setTargetEndpoint(epDesc.getEndpointName());
1018 consumerServiceDescriptor.setTargetInterfaceName(epDesc.getInterfaceName());
1019 consumerServiceDescriptor.setTargetService(epDesc.getServiceName());
1020
1021 consumerServiceDescriptor.setJbiServiceDescriptor(jbiServiceDescriptor);
1022
1023 return consumerServiceDescriptor;
1024
1025 }
1026
1027 private void populateEndpointWSDLInfo(EndpointStatus endpointStatus, Jbi4CorbaEndpoint endpoint) throws Exception {
1028
1029 Transformer transformer = mTransformerPool.retrieve();
1030 if (endpointStatus != null) {
1031 WSDLFactory wsdlFactory = (WSDLFactory) WSDLFactory.newInstance();
1032 @SuppressWarnings("unused")
1033 WSDLWriter writer = (WSDLWriter) wsdlFactory.newWSDLWriter();
1034
1035 transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
1036 transformer.setOutputProperty(OutputKeys.INDENT, "yes");
1037 StringWriter sw = new StringWriter();
1038 StreamResult result = new StreamResult(sw);
1039 DOMSource source = new DOMSource(endpoint.getServiceDescription());
1040 transformer.transform(source, result);
1041 endpointStatus.setWSDLDefinition(sw.toString());
1042
1043 mTransformerPool.relinquish(transformer);
1044 }
1045
1046 }
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056 @SuppressWarnings("unchecked")
1057 private List<JbiServiceDescriptor> getJbiDescriptors(String suName, String suZipPath, List<Jbi4CorbaSUInfo> infolist) throws DeploymentException {
1058
1059
1060 List<JbiServiceDescriptor> descList = new ArrayList<JbiServiceDescriptor>();
1061
1062 final File suDir = new File(suZipPath);
1063 LOG.info("SERVICE UNIT DIRECTORY" + suDir.getAbsolutePath());
1064
1065
1066 if (runtimeConfiguration == null) {
1067 runtimeConfiguration = lifeCycle.getRuntimeConfiguration();
1068 }
1069
1070
1071
1072 Map<String, String[]> envVariableMap =
1073 parseForEnvironmentVariables(suZipPath, runtimeConfiguration.retrieveApplicationVariablesMap());
1074 if (envVariableMap.size() > runtimeConfiguration.countVariables()) {
1075
1076
1077 try {
1078 runtimeConfiguration.updateApplicationVariablesMap(envVariableMap);
1079 } catch (MBeanException e) {
1080 String msg = MESSAGES.getString("CRB000234_Error_in_populating_the_application_variables");
1081 LOG.error(msg, e.getMessage());
1082 throw new Jbi4CorbaRuntimeException(e);
1083 }
1084 }
1085
1086
1087
1088
1089 final FileToDefinitionInfo[] fileToDefs = readAllDefinitions(suDir);
1090
1091
1092
1093 if (SUDescriptorSupport.TEMP_SWITCH_ENABLE_JBI_ROUTING) {
1094 LOG.debug("About to parse jbi.xml to resolve service end point in path:" + suDir.getAbsolutePath());
1095
1096 EndpointIdentifier[] svcs = null;
1097
1098 SUDescriptorSupport descSupport = null;
1099
1100 try {
1101 descSupport = new SUDescriptorSupport(
1102 suDir.getAbsolutePath());
1103
1104
1105 svcs = descSupport.getServices();
1106 } catch (ConfigurationException ex) {
1107 String msg = MESSAGES.getString("CRB000217_Failure_in_getting_service_description",
1108 new Object[]{ex.getMessage()});
1109 LOG.error(msg, ex);
1110
1111 }
1112
1113
1114 final int len = svcs.length;
1115
1116 Map appConfigObjectMap = new HashMap();
1117 if (runtimeConfiguration != null) {
1118 appConfigObjectMap = runtimeConfiguration.retrieveApplicationConfigurationsMap();
1119 }
1120
1121 LOG.debug("Found " + svcs.length + " endpoint declared in the jbi.xml");
1122
1123
1124 for (int i = 0; i < len; i++) {
1125 Definition matchedDef = null;
1126 File matchedWSDL = null;
1127
1128 Jbi4CorbaBinding corbaBinding = null;
1129 Jbi4CorbaAddress corbaAddress = null;
1130
1131
1132 EndpointIdentifier epDesc = svcs[i];
1133
1134 String configName = epDesc.getApplicationConfigurationName();
1135 LOG.debug("Retrieved Application configuration Object name " + configName + " from Endpoint");
1136
1137
1138
1139 LOG.debug("Retrieved Application configuration Object name " + configName + " from Endpoint");
1140
1141
1142 if (configName != null && !"".equals(configName) &&
1143 !appConfigObjectMap.containsKey(configName)) {
1144 appConfigObjectMap.put(configName, new String[3]);
1145 }
1146 String appconfigLocalizationType = null;
1147 String appconfigaddressName = null;
1148 String appconfigOrb = null;
1149 if (configName != null && !"".equals(configName)) {
1150
1151
1152
1153 String[] values = (String[]) appConfigObjectMap.get(configName);
1154 if (values != null) {
1155
1156 appconfigLocalizationType = values[0];
1157 appconfigaddressName = values[1];
1158 appconfigOrb = values[2];
1159
1160 LOG.debug("The values of " + configName + " Application Configuration Object are " + appconfigLocalizationType + ", " + appconfigaddressName + ", " + appconfigOrb);
1161 }
1162
1163 }
1164
1165
1166 for (FileToDefinitionInfo element : fileToDefs) {
1167
1168
1169 corbaBinding = Jbi4CorbaExtensionUtils.getCorbaBinding(element.getDefinition(), epDesc.getServiceName().toString(), epDesc.getEndpointName());
1170
1171 if (corbaBinding != null) {
1172 matchedDef = element.getDefinition();
1173
1174
1175 matchedWSDL = element.getFile();
1176
1177 break;
1178 }
1179
1180 }
1181
1182 corbaAddress = Jbi4CorbaExtensionUtils.getCorbaAddress(
1183 matchedDef, epDesc.getServiceName().toString(),
1184 epDesc.getEndpointName());
1185
1186 if (corbaAddress != null) {
1187
1188 if (appconfigLocalizationType != null && !appconfigLocalizationType.equals("")) {
1189 LOG.debug("Replacing Localization Type " + corbaAddress.getLocalizationType() + " with " + appconfigLocalizationType);
1190 corbaAddress.setLocalizationType(appconfigLocalizationType);
1191 }
1192 if (appconfigaddressName != null && !appconfigaddressName.equals("")) {
1193 LOG.debug("Replacing Address Name " + corbaAddress.getName() + " with " + appconfigaddressName);
1194 corbaAddress.setName(appconfigaddressName);
1195 }
1196
1197
1198 /
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265 private Jbi4CorbaEndpoint generateProvider(String suZipPath, EndpointIdentifier epDesc,
1266 JbiServiceDescriptor jbiServiceDescriptors, ProviderServiceDescriptor serviceDescriptor, File rootDir)
1267 throws IOException, DeploymentException {
1268
1269
1270
1271 final String endpointNameLocalPart = QName.valueOf(epDesc.getEndpointName()).getLocalPart();
1272
1273 Jbi4CorbaEndpoint corbaEndpoint = null;
1274
1275 ProviderServiceDescriptor providerServiceDescriptor = null;
1276
1277 providerServiceDescriptor = serviceDescriptor;
1278
1279
1280 try {
1281 corbaEndpoint = new ProviderEndpoint(epDesc.getServiceName(), endpointNameLocalPart, providerServiceDescriptor);
1282 } catch (Jbi4CorbaException e1) {
1283 String msg = MESSAGES.getString("CRB000235_Fail_to_generate_corba_endpoint");
1284 LOG.error(msg, e1.getMessage());
1285
1286 throw new DeploymentException(e1);
1287 }
1288
1289 return corbaEndpoint;
1290
1291
1292 }
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310 private List<ProviderServiceDescriptor> getProviderServiceDescriptor(String suName,
1311 List<JbiServiceDescriptor> jbiServiceDescriptor,
1312 String serviceUnitRootPath,
1313 ProviderServiceClassesGenerator serviceClassesGenerator,
1314 File rootDir) throws ClassGenerationException, IOException,
1315 DeploymentException {
1316
1317 List<ProviderServiceDescriptor> providerServiceDescriptorList = new ArrayList<ProviderServiceDescriptor>();
1318 /
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483