1
2
3
4
5
6
7
8 package it.imolinfo.jbi4corba.jbi.endpoint;
9
10 import it.imolinfo.jbi4corba.Logger;
11 import it.imolinfo.jbi4corba.LoggerFactory;
12 import it.imolinfo.jbi4corba.exception.Jbi4CorbaDeployException;
13 import it.imolinfo.jbi4corba.exception.Jbi4CorbaException;
14 import it.imolinfo.jbi4corba.jbi.Messages;
15 import it.imolinfo.jbi4corba.jbi.component.runtime.RuntimeContext;
16 import it.imolinfo.jbi4corba.jbi.cxf.CXFUtils;
17 import it.imolinfo.jbi4corba.jbi.processor.ProviderExchangeProcessor;
18 import it.imolinfo.jbi4corba.webservice.descriptor.ProviderServiceDescriptor;
19 import it.imolinfo.jbi4corba.webservice.runtime.ProviderServiceCreator;
20
21 import java.io.BufferedReader;
22 import java.io.ByteArrayInputStream;
23 import java.io.ByteArrayOutputStream;
24 import java.io.File;
25 import java.io.FileReader;
26 import java.io.FileWriter;
27 import java.io.IOException;
28 import java.lang.reflect.InvocationTargetException;
29 import java.lang.reflect.Method;
30 import java.rmi.RMISecurityManager;
31 import java.util.Map;
32 import java.util.Properties;
33
34 import java.util.logging.Level;
35 import javax.jbi.messaging.MessageExchange.Role;
36 import javax.wsdl.WSDLException;
37 import javax.xml.namespace.QName;
38 import javax.xml.parsers.DocumentBuilder;
39 import javax.xml.parsers.DocumentBuilderFactory;
40 import javax.xml.parsers.ParserConfigurationException;
41 import javax.xml.transform.Transformer;
42 import javax.xml.transform.TransformerConfigurationException;
43 import javax.xml.transform.TransformerException;
44 import javax.xml.transform.TransformerFactory;
45 import javax.xml.transform.dom.DOMSource;
46 import javax.xml.transform.stream.StreamResult;
47
48 import org.apache.cxf.endpoint.Endpoint;
49 import org.apache.cxf.service.Service;
50 import org.apache.cxf.service.model.EndpointInfo;
51 import org.omg.CORBA.Any;
52 import org.omg.CORBA.NamedValue;
53 import org.omg.CORBA.ORB;
54 import org.omg.CORBA.Object;
55 import org.omg.CORBA.Request;
56 import org.omg.CORBA.TypeCode;
57 import org.omg.CORBA.ORBPackage.InvalidName;
58 import org.omg.CORBA.SystemException;
59 import org.omg.CORBA.portable.ValueFactory;
60 import org.omg.CosNaming.NamingContextExt;
61 import org.omg.CosNaming.NamingContextExtHelper;
62 import org.omg.CosNaming.NamingContextPackage.CannotProceed;
63 import org.omg.CosNaming.NamingContextPackage.NotFound;
64 import org.w3c.dom.Document;
65 import org.xml.sax.SAXException;
66
67
68
69
70 @SuppressWarnings("unchecked")
71 public class ProviderEndpoint extends Jbi4CorbaEndpoint {
72
73
74 private static final long serialVersionUID = -7829120677780408268L;
75
76
77
78
79 private static final Logger LOG = LoggerFactory
80 .getLogger(ProviderEndpoint.class);
81
82
83
84
85 private static final Messages MESSAGES = Messages
86 .getMessages(ProviderEndpoint.class);
87
88 private ProviderServiceDescriptor serviceDescriptor;
89
90
91 private Service cxfService;
92
93
94 private Endpoint cxfEndpoint;
95
96 private ORB orb;
97
98
99
100
101 private Class helperClass;
102
103
104
105
106 private Method narrowMethod;
107
108 private String iorCorbaObject;
109
110 private final String IOREXT=".ior";
111
112
113
114
115
116
117
118
119
120
121
122 public ProviderEndpoint(QName serviceName, String endpointName,
123 ProviderServiceDescriptor serviceDescriptor)
124 throws Jbi4CorbaException {
125 super(serviceName, endpointName);
126 this.serviceDescriptor = serviceDescriptor;
127 this.setExchangeProcessor(new ProviderExchangeProcessor(this));
128 this.serviceDescriptor.setEndpoint(this);
129 }
130
131
132
133
134 public Service getCXFService() {
135 return cxfService;
136 }
137
138
139
140
141 public Endpoint getCXFEndpoint() {
142 return cxfEndpoint;
143 }
144
145
146
147
148 public String getIorCorbaObject() {
149 return iorCorbaObject;
150 }
151
152
153
154
155 public void setIorCorbaObject(String iorCorbaObject) {
156 this.iorCorbaObject = iorCorbaObject;
157 }
158
159
160
161
162
163
164
165
166
167 public Role getRole() {
168 return Role.PROVIDER;
169 }
170
171
172
173
174
175
176 public void activate() throws Jbi4CorbaException {
177 LOG.debug(">>>>> activate - begin");
178
179 initOrb();
180 try {
181 locateCorbaService();
182 } catch (Jbi4CorbaException e) {
183
184
185 String msg = MESSAGES
186 .getString(
187 "CRB000145_Unable_to_retrive_object_using_locateCorbaService",
188 new java.lang.Object[] { e });
189 LOG.warn(msg);
190 }
191 LOG.debug("<<<<< activate - end");
192 }
193
194
195
196
197
198
199
200 public void deactivate() throws Jbi4CorbaException {
201 stopCorbaOrb();
202 }
203
204
205
206
207
208
209
210 public void registerService() throws Jbi4CorbaDeployException {
211 LOG.debug("registering service for service descriptor: "
212 + serviceDescriptor);
213
214 serviceDescriptor.setComponentRootPath(RuntimeContext.getInstance()
215 .getComponentContext().getInstallRoot());
216
217
218 ProviderServiceCreator serviceCreator = new ProviderServiceCreator();
219 try {
220 cxfService = serviceCreator.createService(serviceDescriptor, this
221 .getServiceName());
222 LOG.debug("CXF Service Gnerator >>>> " + this.getServiceName());
223
224 this.setServiceDescription(CXFUtils.getAbstractWSDLDocument(cxfService));
225 EndpointInfo cxfei = CXFUtils.getEndpointInfo(cxfService);
226 cxfEndpoint = CXFUtils.getEndpoint(cxfService, cxfei);
227 } catch (Jbi4CorbaException ex) {
228 String msg = MESSAGES.getString(
229 "CRB000146_Error_in_service_creation",
230 new java.lang.Object[] { ex.getMessage() });
231 LOG.error(msg, ex);
232 throw new Jbi4CorbaDeployException(msg, ex);
233 } catch (IOException ex) {
234 String msg = MESSAGES.getString(
235 "CRB000146_Error_in_service_creation",
236 new java.lang.Object[] { ex.getMessage() });
237 LOG.error(msg, ex);
238 throw new Jbi4CorbaDeployException(msg, ex);
239 } catch (WSDLException ex) {
240 String msg = MESSAGES.getString(
241 "CRB000146_Error_in_service_creation",
242 new java.lang.Object[] { ex.getMessage() });
243 LOG.error(msg, ex);
244 throw new Jbi4CorbaDeployException(msg, ex);
245 }
246
247 DOMSource domSource = new DOMSource(generateWsdl(cxfService));
248
249 String wsdlFilename = null;
250 wsdlFilename = serviceDescriptor.getWsdlRootDirectory() + "/"
251 + cxfService.getName().getLocalPart() + ".wsdl.debug.cxf";
252
253 LOG.debug("CRB000127_Producing_service_wsdl_to",
254 new java.lang.Object[] { wsdlFilename });
255 FileWriter fr;
256 try {
257 fr = new FileWriter(wsdlFilename);
258 } catch (IOException e) {
259 String msg = MESSAGES.getString(
260 "CRB000105_Unable_to_open_filename", wsdlFilename, e
261 .getMessage());
262
263 LOG.error(msg, e);
264 throw new Jbi4CorbaDeployException(msg, e);
265 }
266 StreamResult streamResult = new StreamResult(fr);
267 TransformerFactory transformerFactory = TransformerFactory
268 .newInstance();
269 Transformer transformer;
270 try {
271 transformer = transformerFactory.newTransformer();
272 } catch (TransformerConfigurationException e) {
273 String msg = MESSAGES.getString(
274 "CRB000106_Unable_to_create_default_transformer",
275 transformerFactory, e.getMessage());
276
277 LOG.error(msg, e);
278 throw new Jbi4CorbaDeployException(msg, e);
279 }
280 try {
281 transformer.transform(domSource, streamResult);
282 } catch (TransformerException e) {
283 String msg = MESSAGES.getString(
284 "CRB000107_Unable_to_create_transform", domSource,
285 streamResult, transformer, e.getMessage());
286
287 LOG.error(msg, e);
288 throw new Jbi4CorbaDeployException(msg, e);
289 }
290 try {
291 fr.close();
292 } catch (IOException e) {
293 String msg = MESSAGES.getString(
294 "CRB000108_Unable_to_close_fileWriter", fr, e.getMessage());
295
296 LOG.error(msg, e);
297 throw new Jbi4CorbaDeployException(msg, e);
298 }
299 }
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314 protected Document generateWsdl(Service cxfService)
315 throws Jbi4CorbaDeployException {
316
317 ByteArrayOutputStream baos = new ByteArrayOutputStream();
318
319 try {
320 CXFUtils.writeDefinitionOnOutputStream(cxfService, baos);
321 } catch (WSDLException ex) {
322 String msg = MESSAGES.getString("CRB000147_Error_in_WSDL_creation",
323 new java.lang.Object[] { ex.getMessage() });
324 LOG.warn(msg, ex);
325 }
326
327 LOG.debug(">>>>> generateWsdl - begin");
328
329 if (LOG.isDebugEnabled()) {
330
331 LOG.debug("cxfService:" + cxfService);
332
333 LOG.debug("WSDL:\n------------------\n" + baos.toString()
334 + "\n------------------");
335 }
336
337
338
339
340 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
341 factory.setNamespaceAware(true);
342
343 DocumentBuilder documentBuilder;
344 try {
345 documentBuilder = factory.newDocumentBuilder();
346 } catch (ParserConfigurationException e) {
347 String msg = MESSAGES.getString(
348 "CRB000128_Unable_to_create_documentBuilder", factory, e
349 .getMessage());
350
351 LOG.error(msg, e);
352 throw new Jbi4CorbaDeployException(msg, e);
353 }
354
355 ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
356 Document doc;
357 try {
358
359 doc = documentBuilder.parse(bais);
360
361 } catch (SAXException e) {
362 String m = MESSAGES.getString("CRB000129_Unable_to_parse_document",
363 bais, documentBuilder, e.getMessage());
364
365 LOG.error(m, e);
366 throw new Jbi4CorbaDeployException(m, e);
367 } catch (IOException e) {
368 String m = MESSAGES.getString("CRB000129_Unable_to_parse_document",
369 bais, documentBuilder, e.getMessage());
370
371 LOG.error(m, e);
372 throw new Jbi4CorbaDeployException(m, e);
373 }
374
375 LOG.debug("<<<<< generateWsdl - end");
376 return doc;
377 }
378
379
380
381
382 public ProviderServiceDescriptor getServiceDescriptor() {
383 return serviceDescriptor;
384 }
385
386
387
388
389
390 public void setServiceDescriptor(ProviderServiceDescriptor serviceDescriptor) {
391 this.serviceDescriptor = serviceDescriptor;
392 }
393
394
395
396
397 private void stopCorbaOrb() {
398 orb.shutdown(true);
399 }
400
401
402
403
404
405
406 private void initOrb() throws Jbi4CorbaException {
407
408 LOG.debug(">>>>> initOrb - begin");
409 ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
410 Thread.currentThread().setContextClassLoader(
411
412 serviceDescriptor.getOriginalClassLoader());
413 if (serviceDescriptor != null) {
414 debugProperties(serviceDescriptor.getOrbProperties());
415 }
416
417 try {
418 LOG.debug("locating service for serviceDescriptor: "
419 + serviceDescriptor);
420
421 orb = ORB.init((String[]) null, serviceDescriptor
422 .getOrbProperties());
423
424 LOG.debug("orb: " + orb + " created for service: "
425 + serviceDescriptor);
426
427
428 Map<String, java.lang.Object> map = serviceDescriptor
429 .getValueTypeIdAndInstance();
430
431 if (map == null || map.size() == 0) {
432 LOG
433 .debug("CRB000130_No_value_type_factory_to_register_using_the_ORB");
434 } else {
435 LOG.debug("ValueTypeFactoryMap.size=" + map.size());
436
437
438 for (String id : map.keySet()) {
439 ValueFactory vf = (ValueFactory) map.get(id);
440
441 LOG.debug("Provider. Registering a ValueType Factory. id="
442 + id + "; instance=" + vf);
443
444 ((org.omg.CORBA_2_3.ORB) orb)
445 .register_value_factory(id, vf);
446
447 }
448 }
449
450
451
452
453
454
455 helperClass = serviceDescriptor.getCorbaHelperClass();
456
457
458
459 String helperClassName = helperClass.getName();
460 helperClass = serviceDescriptor.getOriginalClassLoader().loadClass(
461 helperClassName);
462 LOG.debug("Helper class loader: "
463 + helperClass.getClass().getName());
464 narrowMethod = getNarrowMethod(helperClass);
465
466 } catch (ClassNotFoundException ex) {
467 java.util.logging.Logger
468 .getLogger(ProviderEndpoint.class.getName()).log(
469 Level.SEVERE, null, ex);
470 String msg = MESSAGES.getString("CRB000152_Error_in_initializing_the_ORB");
471 LOG.error(msg, ex.getMessage());
472
473 } finally {
474 Thread.currentThread().setContextClassLoader(oldCL);
475 LOG.debug("<<<<< initOrb - end");
476 }
477 }
478
479
480
481
482
483
484 public void locateCorbaService() throws Jbi4CorbaException {
485
486 ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
487 Thread.currentThread().setContextClassLoader(
488
489 serviceDescriptor.getOriginalClassLoader());
490 try {
491 LOG.debug(">>>>> locateCorbaService - begin");
492
493
494
495
496
497
498 java.lang.Object retrievedObject = null;
499 Object corbaObjectReference = null;
500
501
502 LOG.debug("CRB000140_LocalizationType",
503 new java.lang.Object[] { serviceDescriptor
504 .getLocalizationType() });
505
506 if (ProviderServiceDescriptor.NAMESERVICE
507 .equalsIgnoreCase(serviceDescriptor.getLocalizationType())) {
508
509 retrievedObject = localizationViaNameService();
510
511 corbaObjectReference = getCorbaObjectReference(helperClass,
512 narrowMethod, retrievedObject);
513
514 } else if (ProviderServiceDescriptor.CORBALOC
515 .equalsIgnoreCase(serviceDescriptor.getLocalizationType())) {
516
517 retrievedObject = localizationViaCorbaloc();
518
519 corbaObjectReference = getCorbaObjectReference(helperClass,
520 narrowMethod, retrievedObject);
521 } else if (ProviderServiceDescriptor.CORBANAME
522 .equalsIgnoreCase(serviceDescriptor.getLocalizationType())) {
523
524 retrievedObject = localizationViaCorbaname();
525
526 corbaObjectReference = getCorbaObjectReference(helperClass,
527 narrowMethod, retrievedObject);
528 } else if (ProviderServiceDescriptor.IOR
529 .equalsIgnoreCase(serviceDescriptor.getLocalizationType())) {
530
531 retrievedObject = localizationViaIOR();
532
533 corbaObjectReference = getCorbaObjectReference(helperClass,
534 narrowMethod, retrievedObject);
535 }
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555 serviceDescriptor.setCorbaObjectReference(corbaObjectReference);
556 LOG.debug("service reference found: " + corbaObjectReference);
557 if (corbaObjectReference != null) {
558 LOG.debug("service reference classloader: "
559 + corbaObjectReference.getClass().getClassLoader());
560 }
561
562 } finally {
563 Thread.currentThread().setContextClassLoader(oldCL);
564 }
565 LOG.debug("<<<<< locateCorbaService - end");
566 }
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583 protected Object getCorbaObjectReference(Class helperClass,
584 Method narrowMethod, java.lang.Object retrievedObject)
585 throws Jbi4CorbaException {
586
587 LOG.debug("helperClass=" + helperClass + "; narrowMethod="
588 + narrowMethod + "; retrievedObject=" + retrievedObject);
589
590 Object corbaObjectReference = null;
591 try {
592
593 Object retrievedObjectAsCorbaObject = (Object) retrievedObject;
594
595 corbaObjectReference = (Object) narrowMethod.invoke(helperClass,
596 retrievedObjectAsCorbaObject);
597
598 } catch (IllegalArgumentException e) {
599 java.lang.Object[] args = new java.lang.Object[] {
600 "IllegalArgumentException", retrievedObject, e.getMessage() };
601
602 LOG.error("CRB000135_Exception_calling_narrow_method", args, e);
603 throw new Jbi4CorbaException(
604 "CRB000135_Exception_calling_narrow_method", args, e);
605 } catch (IllegalAccessException e) {
606 java.lang.Object[] args = new java.lang.Object[] {
607 "IllegalAccessException", retrievedObject, e.getMessage() };
608
609 LOG.error("CRB000135_Exception_calling_narrow_method", args, e);
610 throw new Jbi4CorbaException(
611 "CRB000135_Exception_calling_narrow_method", args, e);
612 } catch (InvocationTargetException e) {
613 Throwable target = e.getTargetException();
614
615 LOG.error("CRB000135_Exception_calling_narrow_method",
616 new java.lang.Object[] { "InvocationTargetException",
617 retrievedObject, e.getMessage() }, e);
618 LOG.error("CRB000136_Real_error_message_is",
619 new java.lang.Object[] { target.getMessage() }, target);
620 throw new Jbi4CorbaException(
621 "CRB000135_Exception_calling_narrow_method",
622 new java.lang.Object[] { "Exception", retrievedObject,
623 target.getMessage() }, target);
624 }
625
626 LOG.debug("corbaObjectReference=" + corbaObjectReference);
627 return corbaObjectReference;
628 }
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644 protected java.lang.Object ejbLocalization(Class helperClass,
645 Method extractMethod, Method narrowMethod, Method typeMethod)
646 throws Jbi4CorbaException {
647
648 java.lang.Object retrievedObject = null;
649 SecurityManager oldSecurityManager = System.getSecurityManager();
650 try {
651
652 System.setSecurityManager(new RMISecurityManager());
653
654 Object ejbHome = orb.string_to_object(serviceDescriptor
655 .getCorbaServiceName());
656
657 Any result = orb.create_any();
658 NamedValue resultVal = orb.create_named_value("result", result,
659 org.omg.CORBA.ARG_OUT.value);
660 Request createRequest = ejbHome._create_request(null, "create", orb
661 .create_list(0), resultVal);
662 TypeCode resultTypeCode;
663
664 try {
665 resultTypeCode = (TypeCode) typeMethod.invoke(helperClass,
666 new java.lang.Object[] {});
667
668 } catch (IllegalArgumentException e) {
669 java.lang.Object[] args = new java.lang.Object[] {
670 "IllegalArgumentException", retrievedObject,
671 e.getMessage() };
672
673 LOG.error("CRB000135_Exception_calling_typeMethod", args, e);
674 throw new Jbi4CorbaException(
675 "CRB000135_Exception_calling_typeMethod", args, e);
676 } catch (IllegalAccessException e) {
677 java.lang.Object[] args = new java.lang.Object[] {
678 "IllegalAccessException", retrievedObject,
679 e.getMessage() };
680
681 LOG.error("CRB000135_Exception_calling_typeMethod", args, e);
682 throw new Jbi4CorbaException(
683 "CRB000135_Exception_calling_extractMethod", args, e);
684 } catch (InvocationTargetException e) {
685 Throwable target = e.getTargetException();
686
687 LOG.error("CRB000135_Exception_calling_typeMethod",
688 new java.lang.Object[] { "InvocationTargetException",
689 retrievedObject, e.getMessage() }, e);
690 LOG.error("CRB000136_Real_error_message_is",
691 new java.lang.Object[] { target.getMessage() }, target);
692 throw new Jbi4CorbaException(
693 "CRB000135_Exception_calling_typeMethod",
694 new java.lang.Object[] { "Exception", retrievedObject,
695 target.getMessage() }, target);
696 }
697
698 createRequest.set_return_type(resultTypeCode);
699 createRequest.invoke();
700 result = createRequest.return_value();
701
702
703 try {
704
705 retrievedObject = extractMethod.invoke(helperClass,
706 new java.lang.Object[] { result });
707
708 } catch (IllegalArgumentException e) {
709 java.lang.Object[] args = new java.lang.Object[] {
710 "IllegalArgumentException", retrievedObject,
711 e.getMessage() };
712
713 LOG.error("CRB000135_Exception_calling_extractMethod", args, e);
714 throw new Jbi4CorbaException(
715 "CRB000135_Exception_calling_extractMethod", args, e);
716 } catch (IllegalAccessException e) {
717 java.lang.Object[] args = new java.lang.Object[] {
718 "IllegalAccessException", retrievedObject,
719 e.getMessage() };
720
721 LOG.error("CRB000135_Exception_calling_extractMethod", args, e);
722 throw new Jbi4CorbaException(
723 "CRB000135_Exception_calling_extractMethod", args, e);
724 } catch (InvocationTargetException e) {
725 Throwable target = e.getTargetException();
726
727 LOG.error("CRB000135_Exception_calling_extractMethod",
728 new java.lang.Object[] { "InvocationTargetException",
729 retrievedObject, e.getMessage() }, e);
730 LOG.error("CRB000136_Real_error_message_is",
731 new java.lang.Object[] { target.getMessage() }, target);
732 throw new Jbi4CorbaException(
733 "CRB000135_Exception_calling_extractMethod",
734 new java.lang.Object[] { "Exception", retrievedObject,
735 target.getMessage() }, target);
736 }
737 } finally {
738 System.setSecurityManager(oldSecurityManager);
739 }
740
741 return retrievedObject;
742 }
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781 protected java.lang.Object localizationViaCorbaloc()
782 throws Jbi4CorbaException {
783
784 String corbalocUrl = serviceDescriptor.getCorbaServiceName();
785 LOG.debug("corbalocUrl=" + corbalocUrl);
786
787 if (corbalocUrl == null || "".equals(corbalocUrl)) {
788 LOG.error("CRB000141_CorbalocURL_NotFound");
789 throw new Jbi4CorbaException("CRB000141_CorbalocURL_NotFound");
790 }
791
792 java.lang.Object retrievedObject = orb.string_to_object(corbalocUrl);
793 LOG.debug("retrievedObject=" + retrievedObject);
794
795 return retrievedObject;
796 }
797
798
799
800
801
802
803
804 protected java.lang.Object localizationViaCorbaname()
805 throws Jbi4CorbaException {
806
807 String corbanameUrl = serviceDescriptor.getCorbaServiceName();
808 LOG.debug("corbanameUrl=" + corbanameUrl);
809
810 if (corbanameUrl == null || "".equals(corbanameUrl)) {
811 LOG.error("CRB000142_CorbanameURL_NotFound");
812 throw new Jbi4CorbaException("CRB000142_CorbanameURL_NotFound");
813 }
814
815 java.lang.Object retrievedObject = orb.string_to_object(corbanameUrl);
816 LOG.debug("retrievedObject=" + retrievedObject);
817
818 if (retrievedObject == null) {
819 String msg = MESSAGES.getString(
820 "CRB000148_Unable_to_retrived_object_using_corbaname",
821 new java.lang.Object[] { corbanameUrl });
822 LOG.error(msg);
823 throw new Jbi4CorbaDeployException(msg);
824
825 }
826
827 return retrievedObject;
828 }
829
830
831
832
833
834
835
836
837
838
839
840 public java.lang.Object getCorbaObjectReference(String ior)
841 throws Jbi4CorbaException {
842
843 LOG.debug("File.IOR=" + ior);
844
845 if (ior == null || "".equals(ior)) {
846 LOG.error("CRB000143_IOR_NotFound");
847 throw new Jbi4CorbaException("CRB000143_IOR_NotFound");
848 }
849
850 java.lang.Object retrievedObject = null;
851
852 try {
853 retrievedObject = getNarrowMethod(helperClass).invoke(helperClass,
854 orb.string_to_object(ior));
855
856
857
858
859 } catch (IllegalAccessException e) {
860 String msg = MESSAGES
861 .getString("CRB000153_Error_in_getting_corba_object_reference");
862 LOG.error(msg, e);
863 throw new Jbi4CorbaException(e);
864 } catch (InvocationTargetException e) {
865 String msg = MESSAGES
866 .getString("CRB000153_Error_in_getting_corba_object_reference");
867 LOG.error(msg, e);
868 throw new Jbi4CorbaException(e);
869 }
870
871 return retrievedObject;
872 }
873
874
875
876
877
878
879
880 protected java.lang.Object localizationViaIOR() throws Jbi4CorbaException {
881 String filename = serviceDescriptor.getCorbaServiceName();
882 LOG.debug("filename=" + filename);
883
884 if (filename == null || "".equals(filename)) {
885 LOG.error("CRB000143_IOR_NotFound");
886 throw new Jbi4CorbaException("CRB000143_IOR_NotFound");
887 }
888
889 File iorFile = new File(filename);
890
891 if( iorFile.exists() && iorFile.isDirectory()){
892
893 filename=iorFile.getAbsolutePath()+File.separator+serviceDescriptor.getPortTypeName().getLocalPart()+IOREXT;
894 iorFile = new File(filename);
895 LOG.debug("IOR Localization is a directory, search for file --> "+filename);
896 }
897
898 if (!iorFile.exists()) {
899 LOG.error("CRB000143_IOR_NotFound");
900 throw new Jbi4CorbaException("CRB000143_IOR_NotFound");
901 }
902
903 String ior = readIorFromFile(filename);
904 LOG.debug("File.IOR=" + ior);
905
906 if (ior == null || "".equals(ior)) {
907 LOG.error("CRB000143_IOR_NotFound");
908 throw new Jbi4CorbaException("CRB000143_IOR_NotFound");
909 }
910
911 java.lang.Object retrievedObject = orb.string_to_object(ior);
912 LOG.debug("retrievedObject=" + retrievedObject);
913
914 return retrievedObject;
915 }
916
917
918
919
920
921
922
923
924
925 protected String readIorFromFile(String filename) throws Jbi4CorbaException {
926 String ior = null;
927 BufferedReader br = null;
928 try {
929 br = new BufferedReader(new FileReader(filename));
930
931 ior = br.readLine();
932 } catch (IOException e) {
933 java.lang.Object[] args = { filename };
934 LOG.error("CRB000144_ReadingFileError", args, e);
935 throw new Jbi4CorbaException("CRB000144_ReadingFileError", args, e);
936 }
937
938 return ior;
939 }
940
941
942
943
944
945
946
947
948 protected java.lang.Object localizationViaNameService()
949 throws Jbi4CorbaException {
950
951
952 org.omg.CORBA.Object objRef;
953
954
955 try {
956
957 objRef = orb
958 .resolve_initial_references(ProviderServiceDescriptor.NAMESERVICE);
959
960 } catch (InvalidName e) {
961 java.lang.Object[] args = new java.lang.Object[] {
962 ProviderServiceDescriptor.NAMESERVICE, orb, e.getMessage() };
963
964 LOG.error("CRB000131_Invalid_initial_reference_name", args, e);
965 throw new Jbi4CorbaException(
966 "CRB000131_Invalid_initial_reference_name", args, e);
967 } catch (SystemException se) {
968
969 java.lang.Object[] args = new java.lang.Object[] {
970 ProviderServiceDescriptor.NAMESERVICE, orb, se.getMessage() };
971 LOG.error("CRB000131_Invalid_initial_reference_name", args, se);
972 throw new Jbi4CorbaException(
973 "CRB000131_Invalid_initial_reference_name", args, se);
974 }
975
976
977
978 NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
979 LOG.debug("name service: " + ncRef);
980 if (ncRef == null) {
981 throw new Jbi4CorbaException("CRB000132_Name_service_context_null");
982 }
983
984
985 java.lang.Object retrievedObject = null;
986 try {
987
988 retrievedObject = ncRef.resolve_str(serviceDescriptor
989 .getCorbaServiceName());
990
991 } catch (NotFound e) {
992 java.lang.Object[] args = new java.lang.Object[] { "NotFound",
993 serviceDescriptor.getCorbaServiceName(), ncRef,
994 e.getMessage() };
995
996 LOG.error("CRB000134_Exception_retrieving_corba_object_reference",
997 args, e);
998 throw new Jbi4CorbaException(
999 "CRB000134_Exception_retrieving_corba_object_reference",
1000 args, e);
1001
1002 } catch (CannotProceed e) {
1003 java.lang.Object[] args = new java.lang.Object[] { "CannotProceed",
1004 serviceDescriptor.getCorbaServiceName(), ncRef,
1005 e.getMessage() };
1006
1007 LOG.error("CRB000134_Exception_retrieving_corba_object_reference",
1008 args, e);
1009 throw new Jbi4CorbaException(
1010 "CRB000134_Exception_retrieving_corba_object_reference",
1011 args, e);
1012
1013 } catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
1014 java.lang.Object[] args = new java.lang.Object[] { "InvalidName",
1015 serviceDescriptor.getCorbaServiceName(), ncRef,
1016 e.getMessage() };
1017
1018 LOG.error("CRB000134_Exception_retrieving_corba_object_reference",
1019 args, e);
1020 throw new Jbi4CorbaException(
1021 "CRB000134_Exception_retrieving_corba_object_reference",
1022 args, e);
1023 }
1024
1025 LOG.debug("retrievedObject=" + retrievedObject);
1026 return retrievedObject;
1027 }
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040 protected Method getNarrowMethod(Class helperClass)
1041 throws Jbi4CorbaException {
1042
1043 Method _narrowMethod;
1044 try {
1045
1046 _narrowMethod = helperClass
1047 .getDeclaredMethod("narrow", Object.class);
1048
1049 } catch (SecurityException e) {
1050 java.lang.Object[] args = new java.lang.Object[] {
1051 "SecurityException", helperClass, e.getMessage() };
1052
1053 LOG.error("CRB000133_Exception_retrieving_narrow_method", args, e);
1054 throw new Jbi4CorbaException(
1055 "CRB000133_Exception_retrieving_narrow_method", args, e);
1056 } catch (NoSuchMethodException e) {
1057 java.lang.Object[] args = new java.lang.Object[] {
1058 "NoSuchMethodException", helperClass, e.getMessage() };
1059
1060 LOG.error("CRB000133_Exception_retrieving_narrow_method", args, e);
1061 throw new Jbi4CorbaException(
1062 "CRB000133_Exception_retrieving_narrow_method", args, e);
1063 }
1064
1065 return _narrowMethod;
1066 }
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076 protected Method getExtractMethod(Class helperClass)
1077 throws Jbi4CorbaException {
1078
1079 Method extractMethod = null;
1080
1081 try {
1082
1083 extractMethod = helperClass.getDeclaredMethod("extract", Any.class);
1084
1085 } catch (SecurityException e) {
1086 java.lang.Object[] args = new java.lang.Object[] {
1087 "SecurityException", helperClass, e.getMessage() };
1088 LOG.error("CRB000133_Exception_retrieving_extractMethod", args, e);
1089 throw new Jbi4CorbaException(
1090 "CRB000133_Exception_retrieving_extractMethod", args, e);
1091 } catch (NoSuchMethodException e) {
1092 java.lang.Object[] args = new java.lang.Object[] {
1093 "NoSuchMethodException", helperClass, e.getMessage() };
1094 LOG.error("CRB000133_Exception_retrieving_extractMethod", args, e);
1095 throw new Jbi4CorbaException(
1096 "CRB000133_Exception_retrieving_extractMethod", args, e);
1097 }
1098
1099 return extractMethod;
1100 }
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110 protected Method getTypeMethod(Class helperClass) throws Jbi4CorbaException {
1111 Method typeMethod = null;
1112
1113 try {
1114
1115 typeMethod = helperClass.getDeclaredMethod("type");
1116
1117 } catch (SecurityException e) {
1118 java.lang.Object[] args = new java.lang.Object[] {
1119 "SecurityException", helperClass, e.getMessage() };
1120 LOG.error("CRB000133_Exception_retrieving_typeMethod", args, e);
1121 throw new Jbi4CorbaException(
1122 "CRB000133_Exception_retrieving_typeMethod", args, e);
1123 } catch (NoSuchMethodException e) {
1124 java.lang.Object[] args = new java.lang.Object[] {
1125 "NoSuchMethodException", helperClass, e.getMessage() };
1126 LOG.error("CRB000133_Exception_retrieving_typeMethod", args, e);
1127 throw new Jbi4CorbaException(
1128 "CRB000133_Exception_retrieving_typeMethod", args, e);
1129 }
1130
1131 return typeMethod;
1132 }
1133
1134
1135
1136
1137
1138
1139 private void debugProperties(Properties prop) {
1140 if (!LOG.isDebugEnabled()) {
1141
1142 return;
1143 }
1144
1145 if (prop == null || prop.size() == 0) {
1146 LOG.debug("No properties found.");
1147 return;
1148 }
1149
1150 for (java.lang.Object k : prop.keySet()) {
1151 LOG.debug("Properties[" + k + "]=" + prop.getProperty((String) k));
1152 }
1153
1154 }
1155
1156
1157
1158
1159
1160
1161
1162
1163 public void unregisterService() throws Jbi4CorbaException {
1164
1165 LOG.info("CRB000150_Service_unregistered", new java.lang.Object[] {
1166 this.getServiceName(), this.getEndpointName() });
1167 }
1168
1169
1170
1171
1172
1173
1174
1175 public void validate() throws Jbi4CorbaException {
1176
1177 }
1178
1179
1180
1181
1182
1183 public ORB getOrb() {
1184 return orb;
1185 }
1186
1187 }