From cefd0bf46d9e3fe9897fa6bb15e87b8f4bc3928b Mon Sep 17 00:00:00 2001 From: Patient NTUMBA <patient.ntumba@inria.fr> Date: Wed, 8 Feb 2017 15:32:27 +0100 Subject: [PATCH] Update to support multi BindingCOmponent in tomcat --- .../vsb/artifact/generators/WarGenerator.java | 2 +- .../generated/BCSoapSubcomponentEndpoint.java | 34 ----------------- .../setinvaddrclient/BaseServiceClient.java | 10 ++--- .../vsb/gmdl/utils/Constants.java | 13 +++++-- .../vsb/gmdl/utils/PathResolver.java | 28 ++++++++++++-- .../gm/protocols/rest/BcRestSubcomponent.java | 4 +- .../gm/protocols/soap/BcSoapGenerator.java | 7 +++- .../vsb/java2wsdl/Java2WSDL.java | 23 ++++++----- vsb-manager/pom.xml | 2 - .../chorevolution/vsb/manager/VsbManager.java | 38 +++++++++++-------- .../vsb/manager/VsbManagerTest.java | 2 +- 11 files changed, 84 insertions(+), 79 deletions(-) delete mode 100644 bc-manager/src/main/java/eu/chorevolution/vsb/bindingcomponent/generated/BCSoapSubcomponentEndpoint.java diff --git a/bc-generators/artifact-generators/src/main/java/eu/chorevolution/vsb/artifact/generators/WarGenerator.java b/bc-generators/artifact-generators/src/main/java/eu/chorevolution/vsb/artifact/generators/WarGenerator.java index e4ec4fff..77403140 100644 --- a/bc-generators/artifact-generators/src/main/java/eu/chorevolution/vsb/artifact/generators/WarGenerator.java +++ b/bc-generators/artifact-generators/src/main/java/eu/chorevolution/vsb/artifact/generators/WarGenerator.java @@ -119,7 +119,7 @@ public class WarGenerator { + File.separator + "src" + File.separator + "main" + File.separator + "webapp" + File.separator + "service.wsdl"); */ - String path1 = Constants.wsdlDestination +File.separator+ "service.wsdl"; + String path1 = Constants.wsdlDestination +File.separator+Constants.wsdlName+".wsdl"; //String osAppropriatePath = System.getProperty( "os.name" ).contains( "indow" ) ? path_new.substring(1) : path_new; Path path = Paths.get(path1); diff --git a/bc-manager/src/main/java/eu/chorevolution/vsb/bindingcomponent/generated/BCSoapSubcomponentEndpoint.java b/bc-manager/src/main/java/eu/chorevolution/vsb/bindingcomponent/generated/BCSoapSubcomponentEndpoint.java deleted file mode 100644 index 9601ab15..00000000 --- a/bc-manager/src/main/java/eu/chorevolution/vsb/bindingcomponent/generated/BCSoapSubcomponentEndpoint.java +++ /dev/null @@ -1,34 +0,0 @@ - -package eu.chorevolution.vsb.bindingcomponent.generated; - -import java.util.ArrayList; -import java.util.List; -import javax.jws.WebMethod; -import javax.jws.WebService; -import eu.chorevolution.vsb.gm.protocols.builders.ResponseBuilder; -import eu.chorevolution.vsb.gm.protocols.primitives.BcGmSubcomponent; -import eu.chorevolution.vsb.gmdl.utils.Data; - - -/** - * This class was generated by the CHOReVOLUTION BindingComponent Generator using com.sun.codemodel 2.6 - * - */ -@WebService(serviceName = "BCSoapSubcomponentEndpoint", targetNamespace = "eu.chorevolution.vsb.bindingcomponent.generated") -public class BCSoapSubcomponentEndpoint { - - private final BcGmSubcomponent apiRef; - - public BCSoapSubcomponentEndpoint(BcGmSubcomponent apiRef) { - this.apiRef = apiRef; - } - - @WebMethod - public RESPONSEROOT getWeather(REQUESTROOT RequestRoot) { - List<Data<?>> datas = new ArrayList<Data<?>>(); - datas.add(new Data<REQUESTROOT>("RequestRoot", "REQUESTROOT", true, RequestRoot, "BODY")); - String serializedResponseRoot = this.apiRef.mgetTwowaySync("getWeather", datas); - return ResponseBuilder.unmarshalObject("application/json", serializedResponseRoot, RESPONSEROOT.class); - } - -} diff --git a/examples-for-test/set-inv-addr-client/src/main/java/eu/chorevolution/vsb/examplesfortest/setinvaddrclient/BaseServiceClient.java b/examples-for-test/set-inv-addr-client/src/main/java/eu/chorevolution/vsb/examplesfortest/setinvaddrclient/BaseServiceClient.java index 3a261da9..b2fd3be2 100644 --- a/examples-for-test/set-inv-addr-client/src/main/java/eu/chorevolution/vsb/examplesfortest/setinvaddrclient/BaseServiceClient.java +++ b/examples-for-test/set-inv-addr-client/src/main/java/eu/chorevolution/vsb/examplesfortest/setinvaddrclient/BaseServiceClient.java @@ -15,15 +15,15 @@ public class BaseServiceClient { String bc = "http://localhost:8891/BaseService/setinvaddr"; List<String> urls = new ArrayList<String>(); BaseService service; - try { + try{ + service = (BaseService) (Base.getPort("BaseService", bd_wsdl, bc, BaseService.class)); - urls.add("http://93.62.202.227/"); + urls.add("http://jinx.viktoria.chalmers.se:3004/"); service.setInvocationAddress("dest_role_test", "dest_name_test", urls); - } catch (IOException e) { + + }catch (IOException e){ // TODO Auto-generated catch block e.printStackTrace(); } - } - } diff --git a/gmdl-utils/src/main/java/eu/chorevolution/vsb/gmdl/utils/Constants.java b/gmdl-utils/src/main/java/eu/chorevolution/vsb/gmdl/utils/Constants.java index e20fe920..92125a7f 100644 --- a/gmdl-utils/src/main/java/eu/chorevolution/vsb/gmdl/utils/Constants.java +++ b/gmdl-utils/src/main/java/eu/chorevolution/vsb/gmdl/utils/Constants.java @@ -4,13 +4,18 @@ public class Constants { public static String generatedCodePath; public static String configFilePath; - public static String intefaceDescriptionFilePath; + public static String interfaceDescriptionFilePath; + public static String wsdlDestination; public static String warDestination; + public static String warName; + public static String wsdlName; + public static String service_name; + public static String service_port; + public static String soap_service_name; + public static String dpws_service_name; public static String webapp_src_bc; public static String webapp_src_artifact; - public static String soap_service_name; public static String target_namespace; public static String target_namespace_path; - public static String dpws_service_name; - public static String wsdlDestination; + } \ No newline at end of file diff --git a/gmdl-utils/src/main/java/eu/chorevolution/vsb/gmdl/utils/PathResolver.java b/gmdl-utils/src/main/java/eu/chorevolution/vsb/gmdl/utils/PathResolver.java index c0e59c99..ffaa396c 100644 --- a/gmdl-utils/src/main/java/eu/chorevolution/vsb/gmdl/utils/PathResolver.java +++ b/gmdl-utils/src/main/java/eu/chorevolution/vsb/gmdl/utils/PathResolver.java @@ -7,8 +7,10 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.JarURLConnection; +import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; +import java.net.URLClassLoader; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Files; @@ -55,7 +57,7 @@ public class PathResolver { * * @param classname a given class name * @param fileName a given filename - * @return class path to string of a class name given in param + * @return class path to string of a class name given in param */ public static String myFilePath(Class className, String fileName){ @@ -70,10 +72,10 @@ public class PathResolver { return ""; } - if (res.toString().startsWith("jar:")) { + if (res.toString().startsWith("jar:")){ + try { - java.io.InputStream input = className.getClassLoader().getResourceAsStream(fileName); file = File.createTempFile("tempfile", "."+fileNameExtension); OutputStream out = new FileOutputStream(file); @@ -331,4 +333,24 @@ public class PathResolver { } } + public static void setClassPath(String generatedClasspath){ + + File classpathFile = new File(generatedClasspath); + + try { + new URLClassLoader(((URLClassLoader) ClassLoader.getSystemClassLoader()).getURLs()) { + @Override + public void addURL(URL url) { + super.addURL(url); + } + }.addURL(classpathFile.toURI().toURL()); + + } catch (MalformedURLException e1){ + + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + } + } diff --git a/protocol-pool/gm-rest/src/main/java/eu/chorevolution/vsb/gm/protocols/rest/BcRestSubcomponent.java b/protocol-pool/gm-rest/src/main/java/eu/chorevolution/vsb/gm/protocols/rest/BcRestSubcomponent.java index 840f9978..0b5fdcdf 100644 --- a/protocol-pool/gm-rest/src/main/java/eu/chorevolution/vsb/gm/protocols/rest/BcRestSubcomponent.java +++ b/protocol-pool/gm-rest/src/main/java/eu/chorevolution/vsb/gm/protocols/rest/BcRestSubcomponent.java @@ -154,9 +154,9 @@ public class BcRestSubcomponent extends BcGmSubcomponent { System.out.println("Destination: " + destination); System.out.println("Scope: " + scope); System.out.println("Datas: " + datas); - Request request = RestRequestBuilder.buildRestGetRequest(destination, scope, datas); +// Request request = RestRequestBuilder.buildRestGetRequest(destination, scope, datas); // TODO change API to find out the verb of the scope -// Request request = RestRequestBuilder.buildRestPostRequest(destination, scope, datas); + Request request = RestRequestBuilder.buildRestPostRequest(destination, scope, datas); printermsg = (request.toString()); System.out.println(" request.toString() "+request.toString()); System.out.println(" request.getEntityAsText() "+request.getEntityAsText()); diff --git a/protocol-pool/gm-soap/src/main/java/eu/chorevolution/vsb/gm/protocols/soap/BcSoapGenerator.java b/protocol-pool/gm-soap/src/main/java/eu/chorevolution/vsb/gm/protocols/soap/BcSoapGenerator.java index 3e9c7747..9eb667b2 100644 --- a/protocol-pool/gm-soap/src/main/java/eu/chorevolution/vsb/gm/protocols/soap/BcSoapGenerator.java +++ b/protocol-pool/gm-soap/src/main/java/eu/chorevolution/vsb/gm/protocols/soap/BcSoapGenerator.java @@ -34,15 +34,17 @@ import eu.chorevolution.vsb.java2wsdl.Java2WSDL; // TODO: refactor, clean & clear as much as possible... public class BcSoapGenerator extends BcSubcomponentGenerator { + private final String classComment = "This class was generated by the CHOReVOLUTION BindingComponent Generator using com.sun.codemodel 2.6"; public BcSoapGenerator(GmServiceRepresentation serviceRepresentation, BcConfiguration bcConfiguration) { super(serviceRepresentation, bcConfiguration); } - private void includePackageReference(String attrType, JCodeModel codeModel) { + private void includePackageReference(String attrType, JCodeModel codeModel){ int firstBracket = attrType.indexOf("<"); - if (firstBracket != -1) { + if (firstBracket != -1){ + System.out.println("trying " + attrType.substring(0, firstBracket)); JClass dataClass = codeModel.ref(attrType.substring(0, firstBracket)); includePackageReference(attrType.substring(firstBracket + 1, attrType.length() - 1), codeModel); @@ -104,6 +106,7 @@ public class BcSoapGenerator extends BcSubcomponentGenerator { // if complex type, generate its definition if (!attr.isPrimitiveType()) { + this.generatePojo(attr); } } diff --git a/protocol-pool/gm-soap/src/main/java/eu/chorevolution/vsb/java2wsdl/Java2WSDL.java b/protocol-pool/gm-soap/src/main/java/eu/chorevolution/vsb/java2wsdl/Java2WSDL.java index d6d903f9..43d983c6 100644 --- a/protocol-pool/gm-soap/src/main/java/eu/chorevolution/vsb/java2wsdl/Java2WSDL.java +++ b/protocol-pool/gm-soap/src/main/java/eu/chorevolution/vsb/java2wsdl/Java2WSDL.java @@ -21,6 +21,9 @@ package eu.chorevolution.vsb.java2wsdl; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; import java.util.Map; import org.apache.axis2.description.java2wsdl.Java2WSDLConstants; @@ -37,6 +40,7 @@ import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import eu.chorevolution.vsb.gmdl.utils.Constants; +import eu.chorevolution.vsb.gmdl.utils.PathResolver; public class Java2WSDL { private static Log log = LogFactory.getLog(Java2WSDL.class); @@ -74,6 +78,7 @@ public class Java2WSDL { public void generateWSDL() { String configPath = Constants.configFilePath; + System.out.println(" configPath "+configPath); JSONParser parser = new JSONParser(); JSONObject jsonObject = null; @@ -84,23 +89,20 @@ public class Java2WSDL { e.printStackTrace(); } - String generatedCodePath = Constants.generatedCodePath; - String target_namespace = Constants.target_namespace; + String service_name = Constants.soap_service_name; - // String subcomponentAddress = Constants.soap_service_name; - - System.out.println("target_namespace + service_name "+target_namespace + "." + service_name+" -- "+Constants.generatedCodePath+"/"+Constants.target_namespace_path); - + + String[] arguments = {//"-o", generatedCodePath, - "-of", "service.wsdl", + "-of", Constants.wsdlName+".wsdl", "-sn", service_name, "-stn", "eu.chorevolution.vsb.bindingcomponent.generated", //"bc.dtsgoogle.bcs.vsb.chorevolution.eu", eu.chorevolution.vsb.bindingcomponent.generated "-tn", "eu.chorevolution.vsb.bindingcomponent.generated", //"-tp", "eu", "-o", Constants.generatedCodePath, - "-cp", new File(Constants.generatedCodePath+File.separator+Constants.target_namespace_path).getAbsolutePath(), - "-cn",target_namespace + "." + service_name, // - "-l", "http://localhost:8073/" + service_name, + "-cp", new File(Constants.generatedCodePath).getAbsolutePath(), + "-cn",Constants.target_namespace+"."+service_name, // + "-l", "http://localhost:"+Constants.service_port+"/" + service_name, "-ptn", service_name, "-p2n", "[all, eu.chorevolution.vsb.bindingcomponent.generated]", "-st", "document", @@ -137,6 +139,7 @@ public class Java2WSDL { } public static void printUsage() { + System.out.println("Usage: java2wsdl [options] -cn <fully qualified class name>"); System.out.println("\nwhere [options] include:"); System.out.println(" -o <output location> output directory"); diff --git a/vsb-manager/pom.xml b/vsb-manager/pom.xml index 6bc53aee..d3c8776a 100644 --- a/vsb-manager/pom.xml +++ b/vsb-manager/pom.xml @@ -11,8 +11,6 @@ <packaging>jar</packaging> <description>vsb-manager expose a REST interface to generate a Binding-Component WAR based on the description (GMDL) of the system (client, server, publisher, consumer etc.) to bind</description> - - <repositories> <!-- REST library: Restlet --> <repository> diff --git a/vsb-manager/src/main/java/eu/chorevolution/vsb/manager/VsbManager.java b/vsb-manager/src/main/java/eu/chorevolution/vsb/manager/VsbManager.java index 7bd99084..eb5546d8 100644 --- a/vsb-manager/src/main/java/eu/chorevolution/vsb/manager/VsbManager.java +++ b/vsb-manager/src/main/java/eu/chorevolution/vsb/manager/VsbManager.java @@ -24,6 +24,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Locale; +import java.util.Random; import java.util.Scanner; import javax.tools.JavaCompiler; @@ -175,14 +176,19 @@ public class VsbManager { private void setConstants(String interfaceDescriptionPath) { + Random rand = new Random(); + Constants.service_port = String.valueOf(rand.nextInt(5999 - 5000 + 1) + 5000); + String[] interfaceDescFileNameComponents = interfaceDescriptionPath.split("\\."); + String[] interfaceDescFileNameTab = interfaceDescFileNameComponents[0].split("\\"+File.separator); + Constants.service_name = interfaceDescFileNameTab[interfaceDescFileNameTab.length-1].replace("[\\w\\s\\-\\_\\<.*?>]", ""); Constants.generatedCodePath = PathResolver.createTempDir(); Class[] classe = {BcManagerRestService.class}; Constants.configFilePath = PathResolver.myFilePath(BcManagerRestService.class,"config.json"); - Constants.intefaceDescriptionFilePath = interfaceDescriptionPath; + Constants.interfaceDescriptionFilePath = interfaceDescriptionPath; String bc_generators_copy = Constants.generatedCodePath+File.separator + "bc-generators"; // Test if class is running from jar or from class file. @@ -198,20 +204,21 @@ public class VsbManager { PathResolver.copyFolder(new File(".." + File.separator + "bc-generators").getAbsolutePath(), bc_generators_copy); } - + Constants.webapp_src_bc = new File(bc_generators_copy+ File.separator + "webapp-bc-generator" + File.separator + "src" + File.separator + "main" + File.separator + "webapp").getAbsolutePath(); Constants.webapp_src_artifact = new File(bc_generators_copy + File.separator + "artifact-generators" + File.separator + "src" + File.separator + "main" + File.separator + "webapp").getAbsolutePath(); - Constants.warDestination = new File(Constants.generatedCodePath + File.separator + "test.war").getAbsolutePath(); + Constants.warName = "war"+Constants.service_name+"BC"; + Constants.wsdlName = "wsdl"+Constants.service_name+"BC"; + Constants.warDestination = new File(Constants.generatedCodePath + File.separator +Constants.warName+".war").getAbsolutePath(); Constants.target_namespace = "eu.chorevolution.vsb.bindingcomponent.generated"; Constants.target_namespace_path = Constants.target_namespace.replace(".", File.separator); - Constants.soap_service_name = "BCSoapSubcomponentEndpoint"; - Constants.dpws_service_name = "BCDPWSSubcomponentEndpoint"; + Constants.soap_service_name = "BC"+Constants.service_name+"SoapEndpoint"; + Constants.dpws_service_name = "BC"+Constants.service_name+"DPWSEndpoint"; Constants.wsdlDestination = new File(Constants.generatedCodePath).getAbsolutePath(); - } @@ -219,7 +226,7 @@ public class VsbManager { if(!isInterfaceDescriptionFile(interfaceDescriptionPath)){ - System.err.println("Interface Description file not found or not good extension file"); + System.err.println("Interface Description file not found or not good file extension"); System.exit(0); } @@ -322,22 +329,21 @@ public class VsbManager { File sourceDir = new File(strSourceDir); - System.out.println(" sourceDir.getAbsolutePath() "+sourceDir.getAbsolutePath()); + List<JavaFileObject> javaObjects = scanRecursivelyForJavaFiles(sourceDir, fileManager); - if (javaObjects.size() == 0) { + if(javaObjects.size() == 0){ + System.out.println("There are no source files to compile in " + sourceDir.getAbsolutePath()); } File classDir = new File(Constants.generatedCodePath); - // Array of imported classes Class[] classes = new Class[]{ BcManagerRestService.class, BcGmSubcomponent.class,BcGmSubcomponent.class, BcRestSubcomponent.class, BcSoapSubcomponent.class,ServiceDescriptionParser.class,BcConfiguration.class - }; @@ -354,13 +360,15 @@ public class VsbManager { try { for (JavaFileObject jfo : fileManager.list(StandardLocation.CLASS_OUTPUT, "",Collections.singleton(JavaFileObject.Kind.CLASS), true)) { + System.out.println(jfo.getName()); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } - + + PathResolver.setClassPath(Constants.generatedCodePath); soapGenerator.generateWSDL(); } generateBindingComponentClass(gmServiceRepresentation, busProtocol); @@ -389,7 +397,7 @@ public class VsbManager { private static List<JavaFileObject> scanRecursivelyForJavaFiles(File dir, StandardJavaFileManager fileManager) { List<JavaFileObject> javaObjects = new LinkedList<JavaFileObject>(); File[] files = dir.listFiles(); - for (File file : files) { + for (File file : files){ if (file.isDirectory()) { javaObjects.addAll(scanRecursivelyForJavaFiles(file, fileManager)); } @@ -477,7 +485,7 @@ public class VsbManager { JClass serviceDescriptionClass = jCodeModel.ref(ServiceDescriptionParser.class); - String interfaceDescriptionPath = Constants.intefaceDescriptionFilePath; + String interfaceDescriptionPath = Constants.interfaceDescriptionFilePath; String extension = ""; String[] interfaceDescPieces = interfaceDescriptionPath.split("\\."); @@ -710,7 +718,7 @@ public class VsbManager { jsonObject.put("target_namespace", Constants.target_namespace); jsonObject.put("service_name", Constants.soap_service_name); jsonObject.put("service_name", Constants.soap_service_name); - jsonObject.put("subcomponent_port", "5224"); + jsonObject.put("subcomponent_port", Constants.service_port); jsonObject.put("subcomponent_address","http://localhost"); jsonObject.put("invocation_address","http://localhost"); } diff --git a/vsb-manager/src/test/java/eu/chorevolution/vsb/manager/VsbManagerTest.java b/vsb-manager/src/test/java/eu/chorevolution/vsb/manager/VsbManagerTest.java index 9b671860..f9a912ff 100644 --- a/vsb-manager/src/test/java/eu/chorevolution/vsb/manager/VsbManagerTest.java +++ b/vsb-manager/src/test/java/eu/chorevolution/vsb/manager/VsbManagerTest.java @@ -14,7 +14,7 @@ public class VsbManagerTest{ public static void main(String[] args) { - String interfaceDescriptionPath = "PATH_TO_YOUR_GIDL"; + String interfaceDescriptionPath = "/home/pntumba/inria_code/doc/accidents.gidl"; generateWarFile(interfaceDescriptionPath); // generateWarBytes(interfaceDescriptionPath); -- GitLab