1
2
3
4
5
6
7
8 package it.imolinfo.jbi4corba.webservice.generator;
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.Jbi4CorbaException;
14 import it.imolinfo.jbi4corba.jbi.JbiServiceDescriptor;
15 import it.imolinfo.jbi4corba.jbi.Messages;
16 import it.imolinfo.jbi4corba.jbi.cxf.CXFUtils;
17 import it.imolinfo.jbi4corba.utils.HelperFileUtil;
18 import it.imolinfo.jbi4corba.webservice.generator.bcm.AddExceptionSuperclass;
19 import it.imolinfo.jbi4corba.webservice.generator.bcm.RemoteEnhancerAdapter;
20 import it.imolinfo.jbi4corba.webservice.generator.bcm.UIDAdapter;
21 import it.imolinfo.jbi4corba.webservice.generator.bcm.ValueTypeAdapter;
22 import it.imolinfo.jbi4corba.webservice.generator.bcm.WsdlToCorbaAdapter;
23
24 import java.io.File;
25 import java.io.FileInputStream;
26 import java.io.FileNotFoundException;
27 import java.io.FileOutputStream;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.io.PrintWriter;
31 import java.io.StringWriter;
32 import java.net.MalformedURLException;
33 import java.net.URL;
34 import java.net.URLClassLoader;
35 import java.util.ArrayList;
36 import java.util.Arrays;
37 import java.util.Iterator;
38 import java.util.List;
39 import java.util.Map;
40 import java.util.Set;
41
42 import javax.wsdl.Definition;
43 import javax.wsdl.factory.WSDLFactory;
44 import javax.wsdl.xml.WSDLReader;
45 import javax.xml.namespace.QName;
46
47 import org.apache.commons.vfs.FileObject;
48 import org.apache.commons.vfs.FileSystemException;
49 import org.apache.commons.vfs.FileSystemManager;
50 import org.apache.commons.vfs.VFS;
51 import org.apache.cxf.service.model.OperationInfo;
52 import org.apache.cxf.service.model.ServiceInfo;
53 import org.apache.cxf.tools.common.ToolContext;
54 import org.apache.cxf.tools.wsdlto.WSDLToJava;
55 import org.apache.cxf.wsdl11.WSDLServiceBuilder;
56 import org.objectweb.asm.ClassAdapter;
57 import org.objectweb.asm.ClassReader;
58 import org.objectweb.asm.ClassVisitor;
59 import org.objectweb.asm.ClassWriter;
60 import org.objectweb.asm.util.CheckClassAdapter;
61 import org.objectweb.asm.util.TraceClassVisitor;
62
63 import com.ibm.wsdl.Constants;
64 import com.ibm.wsdl.factory.WSDLFactoryImpl;
65
66
67
68
69
70
71
72 public class ConsumerServiceClassesGenerator {
73
74
75
76
77 private static final Logger LOG
78 = LoggerFactory.getLogger(ConsumerServiceClassesGenerator.class);
79 private static final Messages MESSAGES =
80 Messages.getMessages(ConsumerServiceClassesGenerator.class);
81
82
83
84
85
86 public ConsumerServiceClassesGenerator() {
87
88 }
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112 public ServerCorbaClassesHolder generateConsumerServiceClasses(
113 String wsdlStringUrl,
114 String workdir,
115 String libDirName,
116 JbiServiceDescriptor jbiServiceDescriptor) throws ClassGenerationException {
117
118 LOG.debug(">>>>> generateConsumerServiceClasses - begin");
119
120
121
122
123 List<String> jars = Util.prepareClassPath(libDirName);
124
125
126
127
128 ServerCorbaClassesHolder s
129 = generateConsumerServiceClassesDirect(wsdlStringUrl, workdir, jars, jbiServiceDescriptor);
130
131 LOG.debug("<<<<< generateConsumerServiceClasses - end");
132 return s;
133 }
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411 private void copyXSDFile(String srcDir,File wsdlDirFile) throws ClassGenerationException{
412
413 List<File> xdsList = Util.findFilesFromSourceDirectory(srcDir, ".xsd");
414
415 for (File xsd : xdsList) {
416
417 LOG.debug("Copy XSD To " + wsdlDirFile.getPath() + "--->" + xsd.getName());
418 File out = new File(wsdlDirFile + File.separator + xsd.getName());
419 try {
420 HelperFileUtil.copyFile(xsd, out);
421 } catch (IOException ioe) {
422 String msg=MESSAGES.getString("CRB000500_Error_accessing_the_WSDL_directory");
423 LOG.error(msg, ioe);
424 throw new ClassGenerationException(msg, ioe);
425 }
426 }
427
428 }
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450 public ServerCorbaClassesHolder generateConsumerServiceClassesDirect(
451 String wsdlStringUrl,
452 String workdir,
453 List<String> jars,
454 JbiServiceDescriptor jbiServiceDescriptor) throws ClassGenerationException {
455
456
457
458
459
460 File wsdlDirFile = copyWsdlTo(workdir, wsdlStringUrl);
461
462
463 File f=new File(workdir);
464 String srcDir=f.getParent();
465
466
467
468 copyXSDFile(srcDir,f);
469 copyXSDFile(srcDir,wsdlDirFile);
470
471 String wsdlDirName = null;
472 try {
473 wsdlDirName = wsdlDirFile.getCanonicalPath();
474 } catch (IOException ioe) {
475 ioe.printStackTrace();
476 String msg = MESSAGES.getString("CRB000500_Error_accessing_the_WSDL_directory");
477 LOG.error(msg, ioe);
478 throw new ClassGenerationException(msg, ioe);
479 }
480
481
482 if (isIdlIncluded(jbiServiceDescriptor)) {
483 WsdlInformation wsdlInformation = extractWsdlInformation(getWsdlFileName(wsdlDirName));
484 return generateConsumerServiceClassesDirectFromIDL(wsdlDirFile,
485 jars, jbiServiceDescriptor, wsdlInformation);
486 } else {
487 return generateConsumerServiceClassesDirectFromWSDL(wsdlDirFile,
488 jars);
489 }
490 }
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514 public ServerCorbaClassesHolder generateConsumerServiceClassesDirectFromWSDL(
515 File wsdlDirFile,
516 List<String> jars) throws ClassGenerationException {
517
518 LOG.debug(">>>>> generateConsumerServiceClassesDirectWSDL - begin");
519
520 String wsdlDirName = null;
521 try {
522 wsdlDirName = wsdlDirFile.getCanonicalPath();
523 } catch (IOException ioe) {
524 ioe.printStackTrace();
525 String msg=MESSAGES.getString("CRB000500_Error_accessing_the_WSDL_directory");
526 LOG.error(msg, ioe);
527 throw new ClassGenerationException(msg, ioe);
528 }
529
530
531
532
533 copyOrbIrIdl(wsdlDirName);
534
535
536
537
538 String sourceDirName = mkdir(wsdlDirFile, "src");
539 final String classesDirName = mkdir(wsdlDirFile, "classes");
540
541
542
543
544 WsdlInformation wsdlInformation
545 = wsdlToJava(wsdlDirName, sourceDirName, jars);
546
547 List<QName> portTypeList = wsdlInformation.getPortTypeList();
548
549
550
551
552 javac(sourceDirName, classesDirName, jars);
553
554
555
556
557
558 String portTypeClassName
559 = findingPortTypeClassName(portTypeList, classesDirName);
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574 String remoteClassName = tweakInterfaceClasses(portTypeClassName,
575 classesDirName);
576
577
578
579
580 List<String> modifiedClassNames
581 = tweakValueType(remoteClassName, classesDirName);
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599 URLClassLoader urlClassLoader = getURLClassLoader(classesDirName);
600 LOG.debug("instantiate class loader ... done");
601
602
603
604
605 String newSourceCode
606 = Util.generateImplementationClass(urlClassLoader, remoteClassName, true);
607
608 String newSourcePath
609 = remoteClassName.replace('.', File.separatorChar) + "Impl";
610
611 LOG.debug("newSourcePath=["
612 + sourceDirName + File.separatorChar + newSourcePath + "]");
613
614 File newSourceFile
615 = Util.saveAsJavaSource(newSourceCode, sourceDirName, newSourcePath);
616
617 List<String> extra = new ArrayList<String>();
618 extra.add(classesDirName);
619
620 List<String> newSourceList = new ArrayList<String>();
621 newSourceList.add(newSourceFile.getAbsolutePath());
622 Util.compileJavaClasses(sourceDirName,
623 classesDirName,
624 newSourceList,
625 jars,
626 extra);
627
628 Util.compileRemoteClassesNoValueMethodsON(classesDirName,
629 remoteClassName + "Impl",
630 extra);
631
632 List<String> newPathList = add(classesDirName, modifiedClassNames);
633 Map<Long, String> uidMap
634 = Util.extractSerialVersionUid(classesDirName, newPathList);
635
636
637
638
639
640 tweakWsdlToCorba(modifiedClassNames, classesDirName);
641 LOG.debug("end creating java sources implementation for value types.");
642 tweakUID(uidMap);
643
644
645
646
647
648
649 int lastDot = remoteClassName.lastIndexOf(".");
650 String poaPackage = remoteClassName.substring(0, lastDot);
651 String poaName = "_" + remoteClassName.substring(lastDot + 1)
652 + "Impl_Tie";
653 String poaTie = poaPackage + "." + poaName;
654
655
656 QName serviceName
657 = extractServiceNameFromPortType(wsdlDirName, portTypeList.get(0));
658 String portTypePackage
659 = portTypeClassName.substring(0, portTypeClassName.lastIndexOf('.'));
660 QName portTypeName = portTypeList.get(0);
661
662
663 String serviceImpl = portTypePackage + "." + portTypeName.getLocalPart() + "CorbaInterfaceImpl";
664
665 LOG.debug("poaTie=" + poaTie + "; serviceImpl=" + serviceImpl);
666
667 ServerCorbaClassesHolder serverCorbaClassesHolder
668 = new ServerCorbaClassesHolder();
669
670
671
672
673 urlClassLoader = getURLClassLoader(classesDirName);
674 LOG.debug("instantiate class loader ... done");
675
676 setCorbaOperations(serverCorbaClassesHolder,
677 urlClassLoader,
678 remoteClassName);
679
680 setCorbaPOATie(serverCorbaClassesHolder, urlClassLoader, poaTie);
681
682 setCorbaImpl(serverCorbaClassesHolder,
683 urlClassLoader,
684 remoteClassName + "Impl");
685
686 setWebServiceInterface(serverCorbaClassesHolder,
687 urlClassLoader,
688 portTypeClassName);
689
690
691 serverCorbaClassesHolder.setUrlClassLoader(urlClassLoader);
692
693 setWebServiceImpl(serverCorbaClassesHolder,
694 urlClassLoader,
695 serviceImpl);
696
697 serverCorbaClassesHolder.setWsdlInformation(wsdlInformation);
698
699 LOG.debug("<<<<< generateConsumerServiceClasses - end");
700 return serverCorbaClassesHolder;
701 }
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718 public ServerCorbaClassesHolder generateConsumerServiceClassesDirectFromIDL(
719 File wsdlDirFile,
720 List<String> jars,
721 JbiServiceDescriptor jbiServiceDescriptor,
722 WsdlInformation wsdlInformation)
723 throws ClassGenerationException {
724
725 String wsdlDirName = null;
726 try {
727 wsdlDirName = wsdlDirFile.getCanonicalPath();
728 } catch (IOException ioe) {
729 ioe.printStackTrace();
730 String msg=MESSAGES.getString("CRB000500_Error_accessing_the_WSDL_directory");
731 LOG.error(msg, ioe);
732 throw new ClassGenerationException(msg, ioe);
733 }
734
735 ProviderServiceClassesGenerator serviceGenerator = new ProviderServiceClassesGenerator();
736 ArrayList<JbiServiceDescriptor> serviceDescriptorList=new ArrayList<JbiServiceDescriptor>();
737 ArrayList<String> portTypeNameList= new ArrayList<String>();
738 serviceDescriptorList.add(jbiServiceDescriptor);
739
740 portTypeNameList.add(wsdlInformation.getPortTypeList().get(0).getLocalPart());
741
742 List<ClientCorbaClassesHolder> classes = serviceGenerator.generateProviderServiceClasses(serviceDescriptorList, wsdlDirName, jars, portTypeNameList);
743
744 ServerCorbaClassesHolder serverCorbaClassesHolder = generateConsumerCorbaClassesHolder(wsdlDirName, jars, classes, serviceGenerator,jbiServiceDescriptor);
745 serverCorbaClassesHolder.setWsdlInformation(wsdlInformation);
746 serverCorbaClassesHolder.setGenerateClassesFromIDL(true);
747 return serverCorbaClassesHolder;
748
749 }
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765 public ServerCorbaClassesHolder generateConsumerCorbaClassesHolder(
766 String workdir,
767 List<String> jars,
768 List<ClientCorbaClassesHolder> classes,
769 ProviderServiceClassesGenerator serviceGenerator,
770 JbiServiceDescriptor jbidesc
771 )
772 throws ClassGenerationException
773 {
774
775 int index=0;
776 String workdirsrc = workdir + "/src";
777
778
779
780 String implementationDirClasses = workdir + "/origclasses";
781
782 String operationsClassNameFullName="";
783
784 String operationsClassName="";
785 try {
786
787 if(classes.size()>1){
788
789 for(int i=0;i<classes.size();i++){
790
791 String operationClassName=classes.get(i).getOperationsClass().getName();
792 LOG.debug("operationClassName: "+operationClassName);
793 int start=operationClassName.lastIndexOf(".")+1;
794 int end =operationClassName.lastIndexOf("Operations");
795 LOG.debug("Extracted string: "+operationClassName.substring(start, end));
796 LOG.debug("PortTypeLocalPart: "+jbidesc.getPortTypeName().getLocalPart());
797 if (jbidesc.getPortTypeName().getLocalPart().equals(operationClassName.substring(start, end))) {
798 operationsClassNameFullName = new File(implementationDirClasses+File.separator+operationClassName.replace(".", File.separator)+".class").getCanonicalPath();
799 LOG.debug("operationsClassFileNameFullName: "+operationsClassNameFullName+" index: "+i);
800
801
802
803
804 index=i;
805 break;
806 }
807 }
808 }
809 else{
810 String operationClassName=classes.get(0).getOperationsClass().getName();
811 operationsClassNameFullName = new File(implementationDirClasses+File.separator+operationClassName.replace(".", File.separator)+".class").getCanonicalPath();
812 index=0;
813 }
814 LOG.debug("Operation Class Name -->"+operationsClassNameFullName);
815 operationsClassName
816 = operationsClassNameFullName.substring(
817 implementationDirClasses.length() + 1,
818 operationsClassNameFullName.length() - ".class".length());
819 operationsClassName
820 = operationsClassName.replace('/', '.').replace('\\', '.');
821 LOG.debug("finding Operation classes - " + operationsClassName);
822 } catch (IOException e) {
823 Object[] args = new Object[] { classes.get(index).getOperationsClass().getName() };
824 LOG.error("CRB000503_Error_getting_name", args, e);
825 throw new ClassGenerationException(
826 "CRB000503_Error_getting_name", args, e);
827 }
828
829 String classRoot = operationsClassName.substring(0, operationsClassName.lastIndexOf("Operations"));
830 String poaTieClassName = classRoot + "POATie";
831 String helperClassName = classRoot + "Helper";
832
833
834
835
836
837 URLClassLoader urlClassLoader = serviceGenerator.getUrlClassLoader();
838
839 URLClassLoader originalClassLoader = serviceGenerator
840 .getOriginalClassLoader();
841
842 LOG.debug("Obtained class loaders (original and modified) ... done");
843
844
845
846
847 String serviceImplClassName = operationsClassName + "Impl";
848
849
850 String newSourceCode = Util.generateImplementationClass(originalClassLoader, operationsClassName, false);
851 String newSourcePath = operationsClassName.replace('.', File.separatorChar) + "Impl";
852 LOG.debug("newSourcePath=[" + implementationDirClasses + File.separatorChar + newSourcePath + "]");
853 File newSourceFile =
854 Util.saveAsJavaSource(newSourceCode, workdirsrc, newSourcePath);
855 List<String> extra = new ArrayList<String>();
856 extra.add(implementationDirClasses);
857
858 List<String> newSourceList = new ArrayList<String>();
859 newSourceList.add(newSourceFile.getAbsolutePath());
860
861 Util.compileJavaClasses(workdirsrc,
862 implementationDirClasses,
863 newSourceList,
864 jars,
865 extra);
866
867 LOG.debug("=======================================================================");
868 LOG.debug(" CONSUMER CLASS ASSOCIATION ");
869 LOG.debug("=======================================================================");
870 LOG.debug("Operation Class Name -->"+classes.get(index).getOperationsClass().getName());
871 LOG.debug("POA TIE NAME -->"+poaTieClassName);
872 LOG.debug("SERVICE CLASS NAME -->"+serviceImplClassName);
873 LOG.debug("=======================================================================");
874 LOG.debug(" END CONSUMER CLASS GENERATION ");
875 LOG.debug("=======================================================================");
876
877 ServerCorbaClassesHolder serverCorbaClassesHolder = new ServerCorbaClassesHolder();
878
879 setCorbaOperations(serverCorbaClassesHolder, originalClassLoader, operationsClassName);
880 setCorbaPOATie(serverCorbaClassesHolder, originalClassLoader, poaTieClassName);
881 setCorbaImpl(serverCorbaClassesHolder, originalClassLoader,serviceImplClassName);
882 setWebServiceInterface(serverCorbaClassesHolder, originalClassLoader,operationsClassName);
883 setCorbaHelper(serverCorbaClassesHolder, originalClassLoader, helperClassName);
884 serverCorbaClassesHolder.setUrlClassLoader(originalClassLoader);
885
886 serverCorbaClassesHolder.setWebServiceImpl(classes.get(index).getOperationsClass());
887
888 serverCorbaClassesHolder.setValueTypeIdAndInstance(classes.get(index).getValueTypeIdAndInstance());
889 serverCorbaClassesHolder.setMethodSignatures(classes.get(index).getMethodSignatures());
890 serverCorbaClassesHolder.setAllUniontypes(classes.get(index).getAllUnionTypesMap());
891 serverCorbaClassesHolder.setSubstitutedUnionFields(classes.get(index).getSubstitutedUnionFields());
892 serverCorbaClassesHolder.setAllInterfacetypes(classes.get(index).getAllInterafceTypesMap());
893 serverCorbaClassesHolder.setSubstitutedInterfaceFields(classes.get(index).getSubstitutedInterfaceFields());
894 serverCorbaClassesHolder.setAllIDLTypes(classes.get(index).getAllIDLTypes());
895 serverCorbaClassesHolder.setCorbaEnumMap(classes.get(index).getCorbaEnumMap());
896 serverCorbaClassesHolder.setIdToClassNameMap(classes.get(index).getIdToClassMap());
897 serverCorbaClassesHolder.setUrlClassLoader(urlClassLoader);
898 serverCorbaClassesHolder.setOriginalClassLoader(originalClassLoader);
899 serverCorbaClassesHolder.setTypeDefs(classes.get(index).getTypeDefs());
900
901 return serverCorbaClassesHolder;
902 }
903
904
905
906
907
908
909
910
911 private List<String> add(String dir, List<String> pathList) {
912 List<String> newPathList = new ArrayList<String>();
913
914 if (pathList == null || pathList.size() == 0) {
915 return newPathList;
916 }
917
918 String basedir = null;
919 if (dir == null) {
920 basedir = "";
921 } else {
922 basedir = dir;
923 }
924
925 for (String path : pathList) {
926 String np = basedir + File.separator
927 + path.replace('.', File.separatorChar)
928 + ".class";
929 newPathList.add(np);
930 LOG.debug("NEWPATH=" + np);
931 }
932 return newPathList;
933 }
934
935
936
937
938
939
940
941
942
943
944
945
946 private List<String> tweakValueType(String remoteClassName,
947 String classesDirName) throws ClassGenerationException {
948
949 LOG.debug("CRB000555_tweakValueType_begin");
950
951 List<String> javaClassNameOfTheModifiedClasses = new ArrayList<String>();
952
953 String cn = remoteClassName.replace('.', File.separator.charAt(0));
954
955 List<File> classList = new ArrayList<File>();
956 classList.add(new File(classesDirName + File.separator + cn));
957
958 Set<Class> classesToChange
959 = Util.findClassUsed(classesDirName, classList);
960
961
962 for (Class c : classesToChange) {
963
964 String className = classesDirName
965 + File.separator
966 + c.getName().replace('.', '/')
967 + ".class";
968 LOG.debug("CRB000556_tweakValueType_class", new Object[]{className});
969
970 javaClassNameOfTheModifiedClasses.add(c.getName());
971
972
973 ClassWriter cw = new ClassWriter(true);
974 ClassVisitor cc = new CheckClassAdapter(cw);
975 StringWriter sw = new StringWriter();
976 ClassVisitor tv = new TraceClassVisitor(cc, new PrintWriter(sw));
977
978 ClassAdapter cv = new ValueTypeAdapter(tv, cw, className);
979
980 ClassReader cr = Util.getAsmCLassReader(className);
981 LOG.debug("getAsmCLassReader ... done");
982
983
984 cr.accept(cv, true);
985 LOG.debug("ClassReader.accept ... done");
986
987 if (LOG.isDebugEnabled()) {
988 LOG.debug("output of tracer during creation of class: "
989 + className + "\n" + sw.toString());
990 }
991
992
993 byte [] newBytecode = cw.toByteArray();
994
995
996 String relativeFileName = className.replace('/', File.separatorChar);
997 Util.saveAsJavaClass(relativeFileName, newBytecode);
998 }
999
1000 LOG.debug("<<<<< tweakValueType - end");
1001 return javaClassNameOfTheModifiedClasses;
1002 }
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155 private void tweakWsdlToCorba(
1156 List<String> files,
1157 String classesDirName) throws ClassGenerationException {
1158
1159 LOG.debug(">>>>>>>>>> tweakAdapting - begin");
1160
1161 if (files == null || files.size() == 0) {
1162 LOG.debug("<<<<<<<<<< tweakAdapting - end."
1163 + "No files to manipulate.");
1164 return;
1165 }
1166
1167
1168
1169
1170 for (String vt : files) {
1171
1172
1173 String className = classesDirName
1174 + File.separator
1175 + vt.replace('.', '/')
1176 + ".class";
1177
1178 ClassWriter cw = new ClassWriter(true);
1179 ClassVisitor cc = new CheckClassAdapter(cw);
1180 StringWriter sw = new StringWriter();
1181 ClassVisitor tv = new TraceClassVisitor(cc, new PrintWriter(sw));
1182
1183 ClassAdapter cv
1184 = new WsdlToCorbaAdapter(tv, cw, className, classesDirName);
1185
1186 ClassReader cr = Util.getAsmCLassReader(className);
1187 LOG.debug("getAsmCLassReader ... done");
1188
1189 cr.accept(cv, true);
1190 LOG.debug("ClassReader.accept ... done");
1191
1192 LOG.debug("output of tracer during creation of class: "
1193 + className + "\n" + sw.toString());
1194
1195 byte [] newBytecode = cw.toByteArray();
1196
1197
1198 String relativeFileName = className.replace('/', File.separatorChar);
1199 Util.saveAsJavaClass(relativeFileName, newBytecode);
1200 }
1201
1202 LOG.debug("<<<<<<<<<< tweakAdapting - end");
1203 }
1204
1205 private void tweakUID(Map<Long, String> uidPathMap)
1206 throws ClassGenerationException {
1207
1208 LOG.debug(">>>>>>>>>> tweakUID - begin");
1209
1210 if (uidPathMap == null || uidPathMap.size() == 0) {
1211 LOG.debug("<<<<<<<<<< tweakUID - end."
1212 + "No files to manipulate.");
1213 return;
1214 }
1215
1216
1217
1218
1219 for (Long uid : uidPathMap.keySet()) {
1220
1221 String path = uidPathMap.get(uid);
1222 LOG.debug("tweakUID. path=" + path + "; uid=" + uid);
1223
1224 ClassWriter cw = new ClassWriter(true);
1225 ClassVisitor cc = new CheckClassAdapter(cw);
1226 StringWriter sw = new StringWriter();
1227 ClassVisitor tv = new TraceClassVisitor(cc, new PrintWriter(sw));
1228
1229 ClassAdapter cv = new UIDAdapter(tv, cw, uid);
1230
1231 ClassReader cr = Util.getAsmCLassReader(path);
1232 LOG.debug("tweakUID. getAsmCLassReader ... done");
1233
1234 cr.accept(cv, true);
1235 LOG.debug("tweakUID. ClassReader.accept ... done");
1236
1237 LOG.debug("tweakUID. output of tracer during creation of class: "
1238 + path + "\n" + sw.toString());
1239
1240 byte [] newBytecode = cw.toByteArray();
1241
1242
1243 Util.saveAsJavaClass(path, newBytecode);
1244 }
1245
1246 LOG.debug("<<<<<<<<<< tweakAdapting - end");
1247 }
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261 public List<String> copyIDLs(
1262 String classesDirName,
1263 String wsdlDirName,
1264 String remoteClassName) throws ClassGenerationException {
1265
1266 LOG.debug(">>>>> copyIDLs - begin");
1267
1268
1269
1270 String idlFilename = classesDirName + File.separator
1271 + remoteClassName.replace('.', File.separatorChar)
1272 + ".idl";
1273
1274 String destIdlFileName
1275 = wsdlDirName + File.separator
1276 + remoteClassName.substring(remoteClassName.lastIndexOf('.') + 1)
1277 + ".idl";
1278
1279 copyFile(idlFilename, destIdlFileName);
1280
1281 List<String> idls = null;
1282 try {
1283
1284 idls = Util.findIdlFiles(classesDirName);
1285
1286 } catch (Jbi4CorbaException e) {
1287 LOG.error(e.getMessage(), e);
1288 throw new ClassGenerationException(e.getMessage(),e);
1289 }
1290
1291
1292 File wf = new File(wsdlDirName);
1293 for (int i = 0; i < (idls == null ? 0 : idls.size()); i++) {
1294 LOG.debug("copying idls[" + i + "]=" + idls.get(i));
1295
1296 if (idls.get(i).equals(idlFilename)) {
1297
1298 LOG.debug("already copied:" + idls.get(i));
1299
1300 } else {
1301 String pkgAsDir = subBasedir(idls.get(i), classesDirName);
1302
1303 mkdir(wf, pkgAsDir);
1304
1305 String fn = pkgAsDir + File.separator
1306 + new File(idls.get(i)).getName();
1307
1308 copyFile(classesDirName + File.separator + fn,
1309 wsdlDirName + File.separator + fn);
1310 }
1311
1312 }
1313
1314 LOG.debug("<<<<< copyIDLs - end");
1315 return idls;
1316 }
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327 private String subBasedir(String fullFilename, String basedir) {
1328
1329 LOG.debug(">>>>> subBasedir - begin");
1330 String s = fullFilename.substring(basedir.length() + 1);
1331
1332 int limit = s.lastIndexOf(File.separator);
1333
1334 s = s.substring(0, limit);
1335
1336 LOG.debug("<<<<< subBasedir - end:" + s);
1337 return s;
1338 }
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349 private String findingPortTypeClassName(List<QName> portTypesList,
1350 String classesDirName) throws ClassGenerationException {
1351
1352 LOG.debug(">>>>> finding portTypeClassName - begin");
1353
1354 int size = (portTypesList == null) ? 0 : portTypesList.size();
1355 if (size != 1) {
1356 LOG.error("CRB000504_Expected_exactly_one_class", size);
1357 throw new ClassGenerationException(
1358 "CRB000504_Expected_exactly_one_class",
1359 new Object[] { size }, null);
1360 }
1361
1362 String c = portTypesList.get(0).getLocalPart() + ".class";
1363
1364
1365
1366
1367 List<File> portTypeClasses = Util.findFilesFromSourceDirectory(
1368 classesDirName, c);
1369
1370 if (portTypeClasses.size() != 1) {
1371 LOG.error("CRB000505_PortType_class_not_found", c);
1372 throw new ClassGenerationException(
1373 "CRB000505_PortType_class_not_found", new Object[] { c },
1374 null);
1375 } else {
1376 LOG.debug("PortType class not found:" + portTypeClasses.get(0));
1377 }
1378
1379 String portTypeClassName;
1380 try {
1381
1382 portTypeClassName = portTypeClasses.get(0).getCanonicalPath();
1383
1384 portTypeClassName
1385 = portTypeClasses.get(0).getCanonicalPath().substring(
1386 classesDirName.length() + 1,
1387 portTypeClassName.length() - ".class".length());
1388
1389 portTypeClassName
1390 = portTypeClassName.replace('/', '.').replace('\\', '.');
1391
1392 LOG.debug("finding PortType class - " + portTypeClassName);
1393 } catch (IOException e) {
1394 Object[] args = new Object[] { portTypeClasses.get(0) };
1395
1396 LOG.error("CRB000503_Error_getting_name", args, e);
1397 throw new ClassGenerationException(
1398 "CRB000503_Error_getting_name", args, e);
1399 }
1400
1401 LOG.debug("<<<<< finding portTypeClassName - end");
1402 return portTypeClassName;
1403 }
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414 private List<String> javac(
1415 String sourceDirName,
1416 String classesDirName,
1417 List<String> jarFilesName) throws ClassGenerationException {
1418
1419 LOG.debug(">>>>> javac - begin");
1420 List<String> sources;
1421 try {
1422
1423 sources = Util.findJavaSources(sourceDirName);
1424
1425 } catch (Jbi4CorbaException e) {
1426 Object[] args = new Object[] { sourceDirName, e.getMessage() } ;
1427
1428 String msg=MESSAGES.getString("CRB000501_Error_generating_sources_list",
1429 new java.lang.Object[] {args}, new java.lang.Object[] {e});
1430 LOG.error(msg);
1431 throw new ClassGenerationException(msg);
1432 }
1433 LOG.debug("compiling java classes - sources found");
1434
1435 Util.compileJavaClasses(sourceDirName,
1436 classesDirName,
1437 sources,
1438 jarFilesName,
1439 null);
1440
1441 LOG.debug("<<<<< javac - end");
1442 return sources;
1443 }
1444
1445
1446
1447
1448
1449
1450
1451
1452 private void setCorbaHelper(
1453 ServerCorbaClassesHolder serverCorbaClassesHolder,
1454 URLClassLoader urlClassLoader,
1455 String helper) throws ClassGenerationException {
1456
1457 LOG.debug(">>>>> setCorbaHelper - begin");
1458 try {
1459 serverCorbaClassesHolder.setCorbaHelper(
1460 urlClassLoader.loadClass(helper));
1461
1462 } catch (ClassNotFoundException e) {
1463 Object[] args
1464 = new Object[] { "setCorbaHelper", helper, urlClassLoader };
1465
1466 LOG.error("CRB000506_Error_during_method", args, e);
1467 throw new ClassGenerationException(
1468 "CRB000506_Error_during_method", args, e);
1469 }
1470 LOG.debug("<<<<< setCorbaHelper - end");
1471 }
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481 private void setWebServiceInterface(
1482 ServerCorbaClassesHolder serverCorbaClassesHolder,
1483 URLClassLoader urlClassLoader,
1484 String portType) throws ClassGenerationException {
1485
1486 LOG.debug(">>>>> setWebServiceInterface - begin");
1487 try {
1488 serverCorbaClassesHolder.setWebServiceInterface(
1489 urlClassLoader.loadClass(portType));
1490
1491 } catch (ClassNotFoundException e) {
1492 Object[] args = new Object[] {
1493 "setWebServiceInterface", portType, urlClassLoader };
1494
1495 LOG.error("CRB000506_Error_during_method", args, e);
1496 throw new ClassGenerationException(
1497 "CRB000506_Error_during_method", args, e);
1498 }
1499 LOG.debug("<<<<< setWebServiceInterface - end");
1500 }
1501
1502
1503
1504
1505
1506
1507
1508
1509 private void setWebServiceImpl(
1510 ServerCorbaClassesHolder serverCorbaClassesHolder,
1511 URLClassLoader urlClassLoader,
1512 String implClass) throws ClassGenerationException {
1513
1514 LOG.debug(">>>>> setWebServiceImpl - begin");
1515 try {
1516 serverCorbaClassesHolder.setWebServiceImpl(
1517 urlClassLoader.loadClass(implClass));
1518
1519 } catch (ClassNotFoundException e) {
1520
1521 Object[] args = new Object[] {
1522 "setWebServiceImplementation", implClass, urlClassLoader };
1523
1524 LOG.error("CRB000506_Error_during_method", args, e);
1525 throw new ClassGenerationException(
1526 "CRB000506_Error_during_method", args, e);
1527 }
1528 LOG.debug("<<<<< setWebServiceImplementation - end");
1529 }
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539 private void setCorbaPOATie(
1540 ServerCorbaClassesHolder serverCorbaClassesHolder,
1541 URLClassLoader urlClassLoader,
1542 String poaTie) throws ClassGenerationException {
1543
1544 LOG.debug(">>>>> setCorbaPOATie - begin");
1545 try {
1546
1547 serverCorbaClassesHolder.setCorbaPOATie(
1548 urlClassLoader.loadClass(poaTie));
1549
1550 } catch (ClassNotFoundException e) {
1551 Object[] args = new Object[] {
1552 "setCorbaPOATie", poaTie, urlClassLoader };
1553
1554 LOG.error("CRB000506_Error_during_method", args, e);
1555 throw new ClassGenerationException(
1556 "CRB000506_Error_during_method", args, e);
1557 }
1558 LOG.debug("<<<<< setCorbaPOATie - end");
1559 }
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569 private void setCorbaImpl(
1570 ServerCorbaClassesHolder serverCorbaClassesHolder,
1571 URLClassLoader urlClassLoader,
1572 String corbaImpl) throws ClassGenerationException {
1573
1574 LOG.debug(">>>>> setCorbaImpl - begin");
1575 try {
1576
1577 serverCorbaClassesHolder.setCorbaImplClass(
1578 urlClassLoader.loadClass(corbaImpl));
1579
1580 } catch (ClassNotFoundException e) {
1581 Object[] args = new Object[] {
1582 "setCorbaImpl", corbaImpl, urlClassLoader };
1583
1584 LOG.error("CRB000506_Error_during_method", args, e);
1585 throw new ClassGenerationException(
1586 "CRB000506_Error_during_method", args, e);
1587 }
1588 LOG.debug("<<<<< setCorbaImpl - end");
1589 }
1590
1591
1592
1593
1594
1595
1596
1597
1598 private void setCorbaOperations(
1599 ServerCorbaClassesHolder serverCorbaClassesHolder,
1600 URLClassLoader urlClassLoader,
1601 String operations) throws ClassGenerationException {
1602
1603 LOG.debug(">>>>> setCorbaOperations - begin");
1604 try {
1605 serverCorbaClassesHolder.setCorbaOperations(
1606 urlClassLoader.loadClass(operations));
1607
1608 } catch (ClassNotFoundException e) {
1609 Object[] args = new Object[] {
1610 "setCorbaOperations", operations, urlClassLoader };
1611
1612 LOG.debug("urlClassLoader.getURLs()="
1613 + Arrays.asList(urlClassLoader.getURLs()));
1614 LOG.error("CRB000506_Error_during_method", args, e);
1615 throw new ClassGenerationException(
1616 "CRB000506_Error_during_method", args, e);
1617 }
1618 LOG.debug("<<<<< setCorbaOperations - end");
1619 }
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668 private void copyOrbIrIdl(String wsdlDirName)
1669 throws ClassGenerationException {
1670
1671 LOG.debug(">>>>> copyOrbIrIdl - begin");
1672
1673
1674 InputStream orbis
1675 = this.getClass().getClassLoader().getResourceAsStream("orb.idl");
1676
1677 if (orbis == null) {
1678 LOG.error("CRB000508_Could_not_find_orb.idl_in_path");
1679 throw new ClassGenerationException(
1680 "CRB000508_Could_not_find_orb.idl_in_path");
1681 } else {
1682 LOG.debug("orbis not null ... orb.idl found");
1683 }
1684
1685 InputStream iris
1686 = this.getClass().getClassLoader().getResourceAsStream("ir.idl");
1687
1688 if (iris == null) {
1689 LOG.error("CRB000509_Could_not_find_ir.idl_in_path");
1690 throw new ClassGenerationException(
1691 "CRB000509_Could_not_find_ir.idl_in_path");
1692 } else {
1693 LOG.debug("iris not null ... ir.idl found");
1694 }
1695
1696 String orbFileName = wsdlDirName + File.separator + "orb.idl";
1697 String irFileName = wsdlDirName + File.separator + "ir.idl";
1698
1699 copyFile(orbis, orbFileName);
1700 copyFile(iris, irFileName);
1701
1702 LOG.debug("copyFile (orb.idl and ir.idl) to " + wsdlDirName + " ...ok");
1703
1704 LOG.debug("<<<<< copyOrbIrIdl - end");
1705 }
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718 private String tweakInterfaceClasses(
1719 String portTypeClassName,
1720 String classesDirName) throws ClassGenerationException {
1721
1722 LOG.debug(">>>>>>>>>> tweakInterfaceClasses - begin");
1723
1724 LOG.debug("remotizing class: " + portTypeClassName
1725 + " in dir: " + classesDirName);
1726
1727 ClassWriter cw = new ClassWriter(true);
1728 ClassVisitor cc = new CheckClassAdapter(cw);
1729 StringWriter sw = new StringWriter();
1730 ClassVisitor tv = new TraceClassVisitor(cc, new PrintWriter(sw));
1731
1732 RemoteEnhancerAdapter cv = new RemoteEnhancerAdapter(tv,
1733 getAsFullyQualifiedNameInternalForm(portTypeClassName));
1734
1735 LOG.debug("new ClassReader - Begin");
1736 ClassReader cr;
1737 try {
1738 cr = new ClassReader(new FileInputStream(getAsFileName(
1739 classesDirName, portTypeClassName, ".class")));
1740 } catch (IOException e) {
1741 Object[] args = new Object[] { portTypeClassName, classesDirName };
1742
1743 LOG.error("CRB000510_Could_not_instantiate_class_reader", args, e);
1744 throw new ClassGenerationException(
1745 "CRB000510_Could_not_instantiate_class_reader", args, e);
1746 }
1747 LOG.debug("new ClassReader - End");
1748
1749 cr.accept(cv, true);
1750
1751 LOG.debug("output of tracer during creation of class: "
1752 + portTypeClassName + "\n" + sw.toString());
1753
1754 byte [] newBytecode = cw.toByteArray();
1755
1756
1757 String relativeFileName
1758 = cv.getCompleteName().replace('/', File.separatorChar);
1759
1760 LOG.debug("relativeFileName=" + relativeFileName
1761 + "; cv.getCompleteName()=" + cv.getCompleteName());
1762
1763 Util.saveAsJavaClass(classesDirName + File.separator + relativeFileName
1764 + ".class", newBytecode);
1765
1766 String remoteClassName = cv.getCompleteName().replace('/', '.');
1767
1768 LOG.debug("<<<<<<<<<< tweakInterfaceClasses - end:" + remoteClassName);
1769 return remoteClassName;
1770 }
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783 private void copyFile(String sourceFileName,String destFileName)
1784 throws ClassGenerationException {
1785
1786 LOG.debug(">>>>>>>>>> copyFile(String, String) - begin");
1787
1788 LOG.debug("copying: " + sourceFileName + " to: " + destFileName);
1789
1790 FileInputStream is;
1791 try {
1792 is = new FileInputStream(sourceFileName);
1793 } catch (FileNotFoundException e) {
1794 Object[] args = new Object[] { sourceFileName, e.getMessage() };
1795
1796 LOG.error("CRB000511_Error_opening", args, e);
1797 throw new ClassGenerationException(
1798 "CRB000511_Error_opening", args, e);
1799 }
1800
1801 copyFile(is, destFileName);
1802 LOG.debug("<<<<<<<<<< copyFile(String, String) - end");
1803 }
1804
1805
1806
1807
1808
1809
1810 private void copyFile(InputStream sourceInputStream, String destFileName)
1811 throws ClassGenerationException {
1812
1813 LOG.debug(">>>>>>>>>> copyFile(InputStream, String) - begin");
1814
1815 FileOutputStream fos;
1816
1817 LOG.debug("copying: " + sourceInputStream + " to: " + destFileName);
1818 try {
1819
1820 fos = new FileOutputStream(new File(destFileName));
1821
1822 } catch (FileNotFoundException e) {
1823 Object[] args = new Object[] { destFileName, e.getMessage() };
1824
1825 LOG.error("CRB000512_Error_creating", args, e);
1826 throw new ClassGenerationException(
1827 "CRB000512_Error_creating", args, e);
1828 }
1829
1830 LOG.debug("FileUtil.copyInputStream");
1831
1832 try {
1833 Util.copyInputStream(sourceInputStream, fos);
1834 } catch (IOException e) {
1835 Object[] args = new Object[] {
1836 sourceInputStream, destFileName, e.getMessage() };
1837
1838 LOG.error("CRB000513_Error_copying_input_stream", args, e);
1839 throw new ClassGenerationException(
1840 "CRB000513_Error_copying_input_stream", args, e);
1841 }
1842
1843 LOG.debug("<<<<<<<<<< copyFile(InputStream, String) - end");
1844 }
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930 private FileSystemManager getFileSystemManager()
1931 throws ClassGenerationException {
1932
1933 try {
1934 return VFS.getManager();
1935 } catch (FileSystemException e) {
1936 Object[] args = new Object[] { e.getMessage() };
1937
1938 LOG.error("CRB000514_Error_inizializing_virtual_filesystem",
1939 args, e);
1940 throw new ClassGenerationException(
1941 "CRB000514_Error_inizializing_virtual_filesystem", args, e);
1942 }
1943 }
1944
1945
1946
1947
1948
1949
1950 private URLClassLoader getURLClassLoader(String classesDirName)
1951 throws ClassGenerationException {
1952
1953 LOG.debug(">>>>>>>>>> getURLClassLoader - begin");
1954
1955 URLClassLoader urlClassLoader = null;
1956 String protocol = null;
1957 try {
1958
1959 if (System.getProperty("os.name").indexOf("Win") >=0) {
1960 protocol = "file:///";
1961 } else {
1962 protocol = "file://";
1963 }
1964
1965 urlClassLoader = new URLClassLoader(
1966 new URL[] { new URL(protocol + classesDirName + "/") },
1967 this.getClass().getClassLoader());
1968
1969 LOG.debug("url classloader: "
1970 + Arrays.asList(urlClassLoader.getURLs()));
1971 } catch (MalformedURLException e) {
1972 Object[] args = new Object[] { protocol + classesDirName + "/" };
1973
1974 LOG.error("CRB000515_Could_not_instantiate_url_class_loader",
1975 args, e);
1976 throw new ClassGenerationException(
1977 "CRB000515_Could_not_instantiate_url_class_loader", args,
1978 e);
1979 }
1980
1981 LOG.debug("<<<<<<<<<< getURLClassLoader - end");
1982 return urlClassLoader;
1983 }
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997 private File copyWsdlTo(String workdir, String wsdlStringUrl)
1998 throws ClassGenerationException {
1999
2000 LOG.debug(">>>>>>>>>> copyWsdlTo - begin");
2001
2002 LOG.debug("workdir=" + workdir + "; wsdlStringUrl=" + wsdlStringUrl);
2003
2004 File workdirFile = new File(workdir);
2005 FileSystemManager fsManager = getFileSystemManager();
2006
2007 FileObject wsdlFile;
2008 try {
2009 wsdlFile = fsManager.resolveFile(wsdlStringUrl);
2010 } catch (FileSystemException e) {
2011 Object[] args = new Object[] { wsdlStringUrl, e.getMessage() };
2012
2013 LOG.error("CRB000516_Error_resolving_file", args, e);
2014 throw new ClassGenerationException(
2015 "CRB000516_Error_resolving_file", args, e);
2016 }
2017
2018 LOG.debug("wsdl location resolved");
2019
2020 InputStream wsdlInputStream;
2021 try {
2022 wsdlInputStream = wsdlFile.getContent().getInputStream();
2023 } catch (IOException e) {
2024 Object[] args = new Object[] { wsdlFile, e.getMessage() };
2025
2026 LOG.error("CRB000517_Error_opening_url_inputstream", args, e);
2027 throw new ClassGenerationException(
2028 "CRB000517_Error_opening_url_inputstream", args, e);
2029 }
2030
2031 LOG.debug("wsdl content extracted");
2032
2033 File wsdlDirFile;
2034 String wsdlDirName;
2035 try {
2036 wsdlDirFile = Util.createUniqueDirectory(workdirFile, "wsdl");
2037 wsdlDirName = wsdlDirFile.getCanonicalPath();
2038 } catch (IOException e) {
2039 Object[] args = new Object[] { e.getMessage() };
2040
2041 LOG.error("CRB000518_Error_creating_dir_for_wsdl", args, e);
2042 throw new ClassGenerationException(
2043 "CRB000518_Error_creating_dir_for_wsdl", args, e);
2044 }
2045
2046 LOG.debug("wsdl dir created:" + wsdlDirName);
2047
2048 String wsdlFileName = getWsdlFileName(wsdlDirName);
2049
2050 copyFile(wsdlInputStream, wsdlFileName);
2051
2052 LOG.debug("wsdl copied: " + wsdlFileName);
2053 LOG.debug("<<<<<<<<<< copyWsdlTo - end");
2054 return wsdlDirFile;
2055 }
2056
2057
2058
2059
2060
2061 private String getWsdlFileName(String wsdlDirName) {
2062 return wsdlDirName + File.separator + "service.wsdl";
2063 }
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075 private String mkdir(File basedir, String newdir)
2076 throws ClassGenerationException {
2077
2078 LOG.debug(">>>>> mkdir - begin");
2079
2080 File sourceDir = new File(basedir, newdir);
2081 Util.buildDirectory(sourceDir);
2082 String sourceDirName;
2083 try {
2084 sourceDirName = sourceDir.getCanonicalPath();
2085 } catch (IOException e) {
2086 Object[] args = new Object[] { sourceDir, e.getMessage() };
2087
2088 LOG.error("CRB000519_Error_getting_canonical_path", args, e);
2089 throw new ClassGenerationException(
2090 "CRB000519_Error_getting_canonical_path", args, e);
2091 }
2092
2093 LOG.debug("<<<<< mkdir - end. newdir=" + sourceDirName);
2094 return sourceDirName;
2095 }
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107 private WsdlInformation wsdlToJava(String wsdlDirName, String sourceDirName, List<String> jars)
2108 throws ClassGenerationException {
2109
2110 LOG.debug(">>>>> wsdlToJava - begin");
2111
2112 String wsdlFileName = getWsdlFileName(wsdlDirName);
2113
2114 ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
2115
2116 WsdlInformation wsdlInformation = null;
2117
2118 try {
2119
2120 org.apache.cxf.tools.plugin.ObjectFactory factory = new org.apache.cxf.tools.plugin.ObjectFactory();
2121 ClassLoader factoryClassLoader = factory.getClass().getClassLoader();
2122 Thread.currentThread().setContextClassLoader(factoryClassLoader);
2123
2124 WSDLToJava gen = new WSDLToJava();
2125
2126 String[] w2jArgs = new String[]{"-d", sourceDirName, wsdlFileName};
2127 gen.setArguments(w2jArgs);
2128 wsdlInformation = extractWsdlInformation(wsdlFileName);
2129
2130 LOG.debug("wsdlDirName=" + wsdlDirName
2131 + "; wsdlFileName=" + wsdlFileName
2132 + "; OutputDirectory=" + sourceDirName);
2133
2134 gen.run(new ToolContext());
2135
2136 } catch (Exception e) {
2137 e.printStackTrace();
2138 Object[] args = new Object[] { wsdlFileName, e.getMessage() };
2139
2140 LOG.error("CRB000520_Error_generating_source_file", args, e);
2141 throw new ClassGenerationException(
2142 "CRB000520_Error_generating_source_file", args, e);
2143 } finally {
2144
2145 Thread.currentThread().setContextClassLoader(oldClassLoader);
2146 }
2147
2148 LOG.debug("<<<<< wsdlToJava - end");
2149 return wsdlInformation;
2150 }
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161 private WsdlInformation extractWsdlInformation(String wsdlFileName)
2162 throws ClassGenerationException {
2163 LOG.debug(">>>>> extractWsdlInformation - begin");
2164
2165 WsdlInformation wi = new WsdlInformation();
2166
2167 try {
2168
2169
2170 CXFUtils.setupBus();
2171 WSDLServiceBuilder b = new WSDLServiceBuilder(CXFUtils.getBus());
2172
2173
2174 WSDLFactory wsdlFactory = WSDLFactory.newInstance();
2175 final WSDLReader reader = wsdlFactory.newWSDLReader();
2176 reader.setFeature(Constants.FEATURE_VERBOSE, false);
2177 reader.setFeature(Constants.FEATURE_IMPORT_DOCUMENTS, true);
2178
2179 final Definition def = reader.readWSDL(wsdlFileName);
2180
2181 List<ServiceInfo> serviceInfo = b.buildServices(def);
2182
2183 for (Object o : serviceInfo) {
2184 ServiceInfo sInfo = (ServiceInfo) o;
2185
2186
2187 QName pt = sInfo.getInterface().getName();
2188 wi.getPortTypeList().add(pt);
2189 LOG.debug("PortType[" + pt + "] in WsdlFile=" + wsdlFileName);
2190
2191 wi.getServiceAndPortType().put(sInfo.getName(), pt);
2192
2193 wi = findOperationByMEP(sInfo, pt, wi);
2194 }
2195
2196 } catch (Exception e) {
2197 LOG.error("CRB000521_Extracting_PortTypes_error", e);
2198 throw new ClassGenerationException(
2199 "CRB000521_Extracting_PortTypes_error", null, e);
2200 }
2201
2202 LOG.debug("<<<< extractWsdlInformation - end");
2203 return wi;
2204 }
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216 protected WsdlInformation findOperationByMEP(ServiceInfo serviceInfo,
2217 QName portType, WsdlInformation wi) {
2218
2219 if (wi == null) {
2220 wi = new WsdlInformation();
2221 }
2222 if (portType == null) {
2223 LOG.debug("No operations for a nillable PortType!");
2224 return wi;
2225 }
2226
2227
2228 List<QName> asyncList = new ArrayList<QName>();
2229 List<QName> syncList = new ArrayList<QName>();
2230 wi.getAsynchOperationMap().put(portType, asyncList);
2231 wi.getSynchOperationMap().put(portType, syncList);
2232
2233 if (serviceInfo == null) {
2234 LOG.debug("No operations for a nillable service!");
2235 return wi;
2236 }
2237
2238 Iterator opIterator
2239 = serviceInfo.getInterface().getOperations().iterator();
2240
2241 while (opIterator.hasNext()) {
2242 OperationInfo op = (OperationInfo) opIterator.next();
2243
2244
2245
2246
2247
2248
2249 LOG.debug("OperationInfo.isAsync:" + op.isOneWay()
2250 + "; OperationInfo.hasInput()=" + op.hasInput()
2251 + "; OperationInfo.hasOutput()=" + op.hasOutput());
2252
2253 if (! op.hasOutput()) {
2254 LOG.debug("Asynchronous Operation; operationName=" + op.getName());
2255
2256 wi.getAsynchOperationMap().get(portType).add(op.getName());
2257 } else {
2258 LOG.debug("Synchronous Operation; operationName=" + op.getName());
2259
2260 wi.getSynchOperationMap().get(portType).add(op.getName());
2261 }
2262 }
2263
2264 return wi;
2265 }
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278 private QName extractServiceNameFromPortType(String wsdlDirName, QName portType)
2279 throws ClassGenerationException {
2280 LOG.debug(">>>>> extractPortTypes - begin");
2281
2282 String wsdlFileName = getWsdlFileName(wsdlDirName);
2283 try {
2284
2285
2286 WSDLServiceBuilder b = new WSDLServiceBuilder(CXFUtils.getBus());
2287
2288
2289 WSDLFactory wsdlFactory = WSDLFactory.newInstance();
2290 final WSDLReader reader = ((WSDLFactoryImpl) wsdlFactory).newWSDLReader();
2291 reader.setFeature(Constants.FEATURE_VERBOSE, false);
2292 reader.setFeature(Constants.FEATURE_IMPORT_DOCUMENTS, true);
2293
2294 final Definition def = reader.readWSDL(wsdlFileName);
2295
2296 List<ServiceInfo> serviceInfo = b.buildServices(def);
2297
2298 for (Object o : serviceInfo) {
2299 QName pt = ((ServiceInfo) o).getInterface().getName();
2300 if (pt.equals(portType)) {
2301 QName serviceName = ((ServiceInfo) o).getName();
2302 LOG.debug("Service[" + serviceName + "] found in WsdlFile=" + wsdlFileName + " for portType:" + portType);
2303 return serviceName;
2304 }
2305 }
2306
2307 LOG.error("CRB000542_Error_during_service_name_lookup", String.valueOf(portType));
2308 throw new ClassGenerationException("CRB000542_Error_during_service_name_lookup", new Object[]{String.valueOf(portType)});
2309
2310 } catch (Exception e) {
2311 LOG.error("CRB000542_Error_during_service_name_lookup", e);
2312 throw new ClassGenerationException(
2313 "CRB000542_Error_during_service_name_lookup", null, e);
2314 }
2315 }
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325 private String getAsFileName(String basedir, String javaName, String ext) {
2326
2327 char sep = File.separator.charAt(0);
2328 basedir = basedir.replace('\\', sep).replace('/', sep);
2329
2330 return basedir + sep + javaName.replace('.', sep) + ext;
2331 }
2332
2333
2334
2335
2336
2337
2338 private String getAsFullyQualifiedNameInternalForm(String javaName) {
2339
2340 return javaName.replace('.', '/');
2341 }
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359 private void addExceptionSuperclass(List<String> exceptions, String classesDirName)
2360 throws ClassGenerationException {
2361
2362 for (int i = 0; i < exceptions.size(); i++) {
2363 String exception = exceptions.get(i);
2364 LOG.debug("Adding Exception superclass to exception: " + exception);
2365
2366 ClassWriter cw = new ClassWriter(true);
2367 ClassVisitor cc = new CheckClassAdapter(cw);
2368 StringWriter sw = new StringWriter();
2369 ClassVisitor tv = new TraceClassVisitor(cc, new PrintWriter(sw));
2370
2371 AddExceptionSuperclass cv = new AddExceptionSuperclass(tv);
2372
2373 ClassReader cr;
2374 try {
2375 cr = new ClassReader(new FileInputStream(getAsFileName(
2376 classesDirName, exception, ".class")));
2377 } catch (IOException e) {
2378 String msg=MESSAGES.getString("CRB000557_Failure_generating_ClassReader_in_addExceptionSuperclass",
2379 new Object[] {e.getMessage()});
2380 LOG.error(msg,e);
2381 throw new ClassGenerationException(msg,e);
2382
2383 }
2384 cr.accept(cv, true);
2385 byte[] newBytecode = cw.toByteArray();
2386
2387
2388 String relativeFileName = exception.replace('.', File.separatorChar);
2389 Util.saveAsJavaClass(classesDirName + File.separator +
2390 relativeFileName + ".class", newBytecode);
2391
2392 }
2393 }
2394
2395
2396
2397
2398
2399
2400
2401
2402 private boolean isEmpty(String str) {
2403 return ((str == null) || (str.trim().length() <= 0));
2404 }
2405
2406
2407
2408
2409
2410
2411
2412
2413 private boolean isIdlIncluded(JbiServiceDescriptor jbiServiceDescriptor)
2414 throws ClassGenerationException {
2415 boolean result = false;
2416
2417 if (jbiServiceDescriptor == null ||
2418 isEmpty(jbiServiceDescriptor.getIdlFileName()) ||
2419 isEmpty(jbiServiceDescriptor.getIdlFileNameDirectory())) {
2420 return false;
2421 }
2422
2423 String filepath = jbiServiceDescriptor.getIdlFileNameDirectory()
2424 + File.separator + jbiServiceDescriptor.getIdlFileName();
2425
2426 try {
2427 File idlFile = new File(filepath);
2428 if (idlFile.exists()) {
2429 String idl = HelperFileUtil.readFileAsString(idlFile).trim();
2430 result = (! isEmpty(idl));
2431 }
2432 } catch (Exception e) {
2433 Object[] args = new Object[] { filepath, e.getMessage() };
2434 LOG.error("CRB000512_Error_creating", args, e);
2435 throw new ClassGenerationException("CRB000512_Error_creating",
2436 args, e);
2437 }
2438 return result;
2439 }
2440 }