public void applyConfiguration() throws Exception { LOG.debug("Applying configuration"); // just in case... validateSdkDirectory(); // new data service's lib directory File libOutDir = new File(getServiceInformation().getBaseDirectory(), "lib"); File tempLibDir = new File(getServiceInformation().getBaseDirectory(), "temp"); tempLibDir.mkdir(); String projectName = getDeployPropertiesFromSdkDir() .getProperty(SDK41StyleConstants.DeployProperties.PROJECT_NAME); File remoteClientDir = new File( sdkDirectory, "output" + File.separator + projectName + File.separator + "package" + File.separator + "remote-client"); File localClientDir = new File( sdkDirectory, "output" + File.separator + projectName + File.separator + "package" + File.separator + "local-client"); // wrap up the remote-client config files as a jar file so it'll be on the classpath // local client stuff might be added by the API Type configuration step LOG.debug("Creating a jar to contain the remote configuration of the caCORE SDK system"); File remoteConfigDir = new File(remoteClientDir, "conf"); String remoteConfigJarName = projectName + "-remote-config.jar"; File remoteConfigJar = new File(tempLibDir, remoteConfigJarName); JarUtilities.jarDirectory(remoteConfigDir, remoteConfigJar); // also jar up the local-client config files LOG.debug("Creating a jar to contain the local configuration of the caCORE SDK system"); File localConfigDir = new File(localClientDir, "conf"); String localConfigJarName = projectName + "-local-config.jar"; File localConfigJar = new File(tempLibDir, localConfigJarName); JarUtilities.jarDirectory(localConfigDir, localConfigJar); // set the config jar in the shared configuration SharedConfiguration.getInstance().setRemoteConfigJarFile(remoteConfigJar); SharedConfiguration.getInstance().setLocalConfigJarFile(localConfigJar); // get a list of jars found in GLOBUS_LOCATION/lib File globusLocation = new File(System.getenv(GLOBUS_LOCATION_ENV)); File globusLib = new File(globusLocation, "lib"); File[] globusJars = globusLib.listFiles(new FileFilters.JarFileFilter()); Set<String> globusJarNames = new HashSet<String>(); for (File jar : globusJars) { globusJarNames.add(jar.getName()); } Set<String> serviceJarNames = new HashSet<String>(); for (File jar : libOutDir.listFiles(new FileFilters.JarFileFilter())) { serviceJarNames.add(jar.getName()); } // get the application name final String applicationName = getDeployPropertiesFromSdkDir() .getProperty(SDK41StyleConstants.DeployProperties.PROJECT_NAME); // copy in libraries from the remote lib dir that DON'T collide with Globus's LOG.debug("Copying libraries from remote client directory"); File[] remoteLibs = new File(remoteClientDir, "lib").listFiles(new FileFilters.JarFileFilter()); for (File lib : remoteLibs) { String libName = lib.getName(); if (!globusJarNames.contains(libName) && !libName.startsWith("caGrid-CQL-cql.1.0-")) { File libOutput = new File(libOutDir, libName); Utils.copyFile(lib, libOutput); LOG.debug(libName + " copied to the service"); } } LOG.debug("Copying libraries from the local client directory"); File localLibDir = new File(localClientDir, "lib"); File[] localLibs = localLibDir.listFiles(); for (File lib : localLibs) { String name = lib.getName(); boolean ok = true; // is the jar one that is known to conflict with caGrid or Globus? ok = !(name.equals("axis.jar") || name.startsWith("commons-collections") || name.startsWith("commons-logging") || name.startsWith("commons-discovery") || name.startsWith("log4j")); // is the jar already copied into the service if (ok && serviceJarNames.contains(name)) { ok = false; } // is the jar one of the caGrid 1.2 jars? if (ok && name.startsWith("caGrid-") && name.endsWith("-1.2.jar")) { if (!name.startsWith("caGrid-sdkQuery4-")) { ok = false; } } // is the jar in the globus lib dir? if (ok && !globusJarNames.contains(name)) { File libOutput = new File(libOutDir, name); Utils.copyFile(lib, libOutput); LOG.debug(name + " copied to the service"); } } // set the application name service property setCql1ProcessorProperty(SDK41QueryProcessor.PROPERTY_APPLICATION_NAME, applicationName, false); setCql2ProcessorProperty( SDK41CQL2QueryProcessor.PROPERTY_APPLICATION_NAME, applicationName, false); // grab the castor marshalling and unmarshalling xml mapping files // from the config dir and copy them into the service's package structure try { LOG.debug("Copying castor marshalling and unmarshalling files"); File marshallingMappingFile = new File(remoteConfigDir, CastorMappingUtil.CASTOR_MARSHALLING_MAPPING_FILE); File unmarshallingMappingFile = new File(remoteConfigDir, CastorMappingUtil.CASTOR_UNMARSHALLING_MAPPING_FILE); // copy the mapping files to the service's source dir + base package name String marshallOut = CastorMappingUtil.getMarshallingCastorMappingFileName(getServiceInformation()); String unmarshallOut = CastorMappingUtil.getUnmarshallingCastorMappingFileName(getServiceInformation()); Utils.copyFile(marshallingMappingFile, new File(marshallOut)); Utils.copyFile(unmarshallingMappingFile, new File(unmarshallOut)); } catch (IOException ex) { ex.printStackTrace(); CompositeErrorDialog.showErrorDialog( "Error copying castor mapping files", ex.getMessage(), ex); } // set up the shared configuration SharedConfiguration.getInstance().setSdkDirectory(getSdkDirectory()); SharedConfiguration.getInstance().setServiceInfo(getServiceInformation()); SharedConfiguration.getInstance().setSdkDeployProperties(getDeployPropertiesFromSdkDir()); }
private void editWsddForCastorMappings(ServiceInformation info) throws Exception { // change out the domain model validator class CommonTools.setServiceProperty( info.getServiceDescriptor(), DataServiceConstants.DOMAIN_MODEL_VALIDATOR_CLASS, ISODomainModelValidator.class.getName(), false); String mainServiceName = info.getIntroduceServiceProperties() .getProperty(IntroduceConstants.INTRODUCE_SKELETON_SERVICE_NAME); ServiceType mainService = CommonTools.getService(info.getServices(), mainServiceName); String servicePackageName = mainService.getPackageName(); String packageDir = servicePackageName.replace('.', File.separatorChar); // find the client source directory, where the client-config will be located File clientConfigFile = new File( info.getBaseDirectory(), "src" + File.separator + packageDir + File.separator + "client" + File.separator + "client-config.wsdd"); LOG.debug("Editing client config wsdd at " + clientConfigFile.getAbsolutePath()); if (!clientConfigFile.exists()) { throw new CodegenExtensionException( "Client config file " + clientConfigFile.getAbsolutePath() + " not found!"); } // find the server-config.wsdd, located in the service's root directory File serverConfigFile = new File(info.getBaseDirectory(), "server-config.wsdd"); LOG.debug("Editing server config wsdd at " + serverConfigFile.getAbsolutePath()); if (!serverConfigFile.exists()) { throw new CodegenExtensionException( "Server config file " + serverConfigFile.getAbsolutePath() + " not found!"); } // edit the marshaling castor mapping to avoid serializing associations File castorMappingFile = new File(CastorMappingUtil.getMarshallingCastorMappingFileName(info)); if (castorMappingFile.exists()) { String marshallingXmlText = Utils.fileToStringBuffer(castorMappingFile).toString(); String editedMarshallingText = CastorMappingUtil.removeAssociationMappings(marshallingXmlText); String editedMarshallingFileName = CastorMappingUtil.getEditedMarshallingCastorMappingFileName(info); Utils.stringBufferToFile(new StringBuffer(editedMarshallingText), editedMarshallingFileName); // edit the unmarshaling castor mapping to avoid deserializing associations String unmarshallingXmlText = Utils.fileToStringBuffer( new File(CastorMappingUtil.getUnmarshallingCastorMappingFileName(info))) .toString(); String editedUnmarshallingText = CastorMappingUtil.removeAssociationMappings(unmarshallingXmlText); String editedUnmarshallingFileName = CastorMappingUtil.getEditedUnmarshallingCastorMappingFileName(info); Utils.stringBufferToFile( new StringBuffer(editedUnmarshallingText), editedUnmarshallingFileName); // set properties in the client to use the edited marshaler WsddUtil.setGlobalClientParameter( clientConfigFile.getAbsolutePath(), SDK43EncodingUtils.CASTOR_MARSHALLER_PROPERTY, CastorMappingUtil.getEditedMarshallingCastorMappingName(info)); // and the edited unmarshaler WsddUtil.setGlobalClientParameter( clientConfigFile.getAbsolutePath(), SDK43EncodingUtils.CASTOR_UNMARSHALLER_PROPERTY, CastorMappingUtil.getEditedUnmarshallingCastorMappingName(info)); // set properties in the server to use the edited marshaler WsddUtil.setServiceParameter( serverConfigFile.getAbsolutePath(), info.getServices().getService(0).getName(), SDK43EncodingUtils.CASTOR_MARSHALLER_PROPERTY, CastorMappingUtil.getEditedMarshallingCastorMappingName(info)); // and the edited unmarshaler WsddUtil.setServiceParameter( serverConfigFile.getAbsolutePath(), info.getServices().getService(0).getName(), SDK43EncodingUtils.CASTOR_UNMARSHALLER_PROPERTY, CastorMappingUtil.getEditedUnmarshallingCastorMappingName(info)); } else { LOG.debug( "Castor mapping file " + castorMappingFile.getAbsolutePath() + " not found... this is OK if you're using JaxB serialization"); } }