Some of the utilities used for the Oracle SOA Suite 10g to 11g Migration.
I thought of sharing the pre and post migration utilities, we had used in our project.Hope this may help somebody looking for the migration utilities.
Pre-Migration:
MigrationTask.java
import java.io.*;
import java.util.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import javax.xml.xpath.*;
import org.w3c.dom.*;
public class MigrationTask {
public MigrationTask() { }
static FilenameFilter filterPreferences = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.equals("bpel.xml");
}
};
static FilenameFilter bpelProcess = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.matches(".*.bpel");
}
};
//Remove the empty spaces in the preference name in bpel.xml and
//chanage corresponding preference name in bpel file
public static void updatePreferences(String baseDir) throws Exception {
File[] fileList =
listFilesAsArray(new File(baseDir), filterPreferences, true);
for (int i = 0; i < fileList.length; i++) {
DocumentBuilderFactory docBuilderFactory =
DocumentBuilderFactory.newInstance();
docBuilderFactory.setNamespaceAware(true);
File f = fileList[i];
String fileName = f.getAbsolutePath();
// System.out.println(fileName);
Document document =
docBuilderFactory.newDocumentBuilder().parse(fileName);
String bpelFolder =
fileName.substring(0, fileName.lastIndexOf("\\"));
NodeList nodeList =
executeXPath(document, "//preferences/property");
File[] fileListBpel =
listFilesAsArray(new File(bpelFolder), bpelProcess, false);
for (int j = 0; j < nodeList.getLength(); j++) {
Node node =
nodeList.item(j).getAttributes().getNamedItem("name");
String preferenceValue = node.getNodeValue();
if (isSpaceAvilable(preferenceValue) &&
fileListBpel.length > 0) {
System.out.println(fileListBpel[0].getName());
String newpreferenceValue =
preferenceValue.replaceAll(" ", "");
node.setNodeValue(newpreferenceValue);
replaceStringInFile(fileListBpel[0], preferenceValue,
newpreferenceValue, "Pre");
}
}
Source source = new DOMSource(document);
File file = new File(fileList[i].getAbsolutePath());
Result result = new StreamResult(file);
Transformer xformer =
TransformerFactory.newInstance().newTransformer();
xformer.setOutputProperty(OutputKeys.INDENT, "yes");
xformer.transform(source, result);
}
}
public static NodeList executeXPath(Document doc, String xpathStr) {
XPath xpath = null;
NodeList value = null;
try {
XPathFactory xpathFactory = XPathFactory.newInstance();
xpath = xpathFactory.newXPath();
XPathExpression expr = xpath.compile(xpathStr);
value = (NodeList)expr.evaluate(doc, XPathConstants.NODESET);
return value;
} catch (XPathExpressionException e) {
System.err.println("Exception while processing xpath ::" +
e.getMessage());
} catch (Exception e) {
System.err.println("Exception while processing xpath ::" +
e.getMessage());
}
return null;
}
public static boolean isSpaceAvilable(String preference) {
return preference.contains(" ");
}
public static void main(String[] args) throws Exception {
if (args[1].equals("updatePreferences")) {
updatePreferences(args[0]);
}
}
public static File[] listFilesAsArray(File directory,
FilenameFilter filter,
boolean recurse) throws Exception {
Collection<File> files = listFiles(directory, filter, recurse);
File[] arr = new File[files.size()];
return files.toArray(arr);
}
public static Collection<File> listFiles(File directory,
FilenameFilter filter,
boolean recurse) throws Exception {
Vector<File> files = new Vector<File>();
File[] entries = directory.listFiles();
for (File entry : entries) {
if (filter == null || filter.accept(directory, entry.getName())) {
files.add(entry);
}
if (recurse && entry.isDirectory()) {
files.addAll(listFiles(entry, filter, recurse));
}
}
return files;
}
public static void replaceStringInFile(File file, String searchText,
String replaceText,
String replacementtype) {
try {
FileInputStream fstream = new FileInputStream(file);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String fileName = file.getAbsolutePath();
String strLine;
StringBuffer sb = new StringBuffer();
while ((strLine = br.readLine()) != null) {
// if(strLine.contains(searchText)){
Pattern p = Pattern.compile(searchText);
Matcher m = p.matcher(strLine);
if (m.find()) {
strLine = strLine.replace(searchText, replaceText);
}
sb.append(strLine);
sb.append("\n");
}
in.close();
FileOutputStream fos = new FileOutputStream(fileName);
BufferedWriter out = new BufferedWriter(new FileWriter(fileName));
String outText = sb.toString();
out.write(outText);
out.close();
} catch (Exception e) { //Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
java MigrationTask <10g codebase location > updatePreferences
Post-Migration:
The setTitle method used in 10g will be changed to setCompositeInstanceTitle - the title set by setTitle method in 11g can't be used in em console to track the instance.
MigrationTaskes.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<project name="migrationTask" default="Migration" basedir=".">
<property environment="env"/>
<target name="Migration">
<replace dir="${CodeBaseDir}" token="com.oracle.bpel.xml.xpath" value="oracle.fabric.common.xml.xpath">
<include name="**/*.java"/>
</replace>
<replace dir="${CodeBaseDir}" token="com.collaxa.common.util.Base64Decoder" value="oracle.soa.common.util.Base64Decoder">
<include name="**/*.bpel"/>
</replace>
<replace dir="${CodeBaseDir}" token="http://host:port/orabpel/xmllib/Schemas/Common1.xsd" value="oramds:/apps/EAIMetaData/schemas/Common1.xsd">
<include name="**/*.xsd"/>
<include name="**/*.wsdl"/>
</replace>
<replace dir="${CodeBaseDir}" token="http://host:port/orabpel/xmllib/Schemas/Common2.xsd" value="oramds:/apps/EAIMetaData/schemas/Common2.xsd">
<include name="**/*.xsd"/>
<include name="**/*.wsdl"/>
</replace>
<replace dir="${CodeBaseDir}" token="setTitle" value="setCompositeInstanceTitle">
<include name="**/*.bpel"/>
</replace>
</project>
Use the below comment to execute the script
ant -buildfile MigrationTaskes.xml –DcodeBaseDir <Migrated Codebase>
Ant script to migrate the DVM to 11g format:
MigrateDVM.xml<project name="Rename" basedir="." default="rename">
<target name="rename">
<move todir="D:\11g\DVM " includeemptydirs="false">
<fileset dir="D:\10g\DVM">
<include name="**/*.xml"/>
</fileset>
<mapper type="glob" from="*.xml" to="*.dvm"/>
</move>
</target>
<target name="to11G">
<fileset dir=" D:\11g\DVM " id="dvm">
<include name="**/*.dvm" />
</fileset>
<replaceregexp match="isNew="true"" replace="xmlns="http://xmlns.oracle.com/dvm"">
<fileset refid="dvm" />
</replaceregexp>
<replaceregexp match="isNew="null"" replace="xmlns="http://xmlns.oracle.com/dvm"">
<fileset refid="dvm" />
</replaceregexp>
</target>
</project>
Use the below comment to execute the script - Change the DVM path before executing the script.
ant -buildfile MigrateDVM.xml rename
ant -buildfile MigrateDVMxml to11G
No comments:
Post a Comment