This tiny post reminds me the exact reason why I started this blog. I want to collect the things I learned using SOA.
It took me a long time to figure out this tidbit with XSLT before, but I just spent half a day to re-figure it out again.
In my XSLT I need to calculate the duration based on two dateTime fields. So I used this expression:
<xsl:variable name="dur">
<xsl:value-of select="xsd:dateTime($endDt)-xsd:dateTime($stDt)"/>
</xsl:variable>
However, with JDEV 11g, the default XSLT stylesheet version is "1.0". The above expression doesn't work with "1.0". I have to change the version to "2.0". That's all. With that, "dur" will have a value like "PT2H5M". Then you can maniplate it.
Now I have recorded it here, so I don't have spend another 5 hours to "re-discover" it next time.
Thursday, September 15, 2011
Tuesday, September 13, 2011
Tweaking auto-generated XSLT may result in "Element not found" error
I have a JDEV generated XSLT like below.
<?xml version="1.0" encoding="UTF-8" ?>
<?oracle-xsl-mapper
<!-- SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY. -->
<mapSources>
<source type="WSDL">
<schema location="../BPELProcess1.wsdl"/>
<rootElement name="process" namespace="http://xmlns.oracle.com/test/testImdXform/BPELProcess1"/>
</source>
</mapSources>
<mapTargets>
<target type="XSD">
<schema location="../xsd/D1_InitialLoadIMD.xsd"/>
<rootElement name="D1-InitialLoadIMD" namespace="http://oracle.com/D1-InitialLoadIMD.xsd"/>
</target>
</mapTargets>
<!-- GENERATED BY ORACLE XSL MAPPER 11.1.1.5.0(build 110418.1550.0174) AT [TUE SEP 13 15:55:59 MST 2011]. -->
?>
<xsl:stylesheet version="1.0"
...
xmlns:ns1="http://oracle.com/D1-InitialLoadIMD.xsd"
...>
<xsl:template match="/">
<ns1:D1-InitialLoadIMD>
<ns1:version>
<xsl:value-of select="/client:process/client:input"/>
</ns1:version>
</ns1:D1-InitialLoadIMD>
</xsl:template>
</xsl:stylesheet>
Looking at the file, it is very tempting to replace "ns1" with default namespace, i.e. xmlns="http://oracle.com/D1-InitialLoadIMD.xsd", then get rid of "ns1" from the file.
The result may look clean.
<xsl:stylesheet version="1.0"
...
xmlns="http://oracle.com/D1-InitialLoadIMD.xsd"
...>
<xsl:template match="/">
<D1-InitialLoadIMD>
<version>
<xsl:value-of select="/client:process/client:input"/>
</version>
</D1-InitialLoadIMD>
</xsl:template>
</xsl:stylesheet>
However, this is a fatal attraction. Even though the content should be technically equivalent, but I got an "Line Number:(13) : Error: "D1-InitialLoadIMD" Element not Found in Target Schema".
It cost me a few hours to sort it out. The morale of the story, be careful when you mess up the namespace with the auto-generated XSLT.
<?xml version="1.0" encoding="UTF-8" ?>
<?oracle-xsl-mapper
<!-- SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY. -->
<mapSources>
<source type="WSDL">
<schema location="../BPELProcess1.wsdl"/>
<rootElement name="process" namespace="http://xmlns.oracle.com/test/testImdXform/BPELProcess1"/>
</source>
</mapSources>
<mapTargets>
<target type="XSD">
<schema location="../xsd/D1_InitialLoadIMD.xsd"/>
<rootElement name="D1-InitialLoadIMD" namespace="http://oracle.com/D1-InitialLoadIMD.xsd"/>
</target>
</mapTargets>
<!-- GENERATED BY ORACLE XSL MAPPER 11.1.1.5.0(build 110418.1550.0174) AT [TUE SEP 13 15:55:59 MST 2011]. -->
?>
<xsl:stylesheet version="1.0"
...
xmlns:ns1="http://oracle.com/D1-InitialLoadIMD.xsd"
...>
<xsl:template match="/">
<ns1:D1-InitialLoadIMD>
<ns1:version>
<xsl:value-of select="/client:process/client:input"/>
</ns1:version>
</ns1:D1-InitialLoadIMD>
</xsl:template>
</xsl:stylesheet>
Looking at the file, it is very tempting to replace "ns1" with default namespace, i.e. xmlns="http://oracle.com/D1-InitialLoadIMD.xsd", then get rid of "ns1" from the file.
The result may look clean.
<xsl:stylesheet version="1.0"
...
xmlns="http://oracle.com/D1-InitialLoadIMD.xsd"
...>
<xsl:template match="/">
<D1-InitialLoadIMD>
<version>
<xsl:value-of select="/client:process/client:input"/>
</version>
</D1-InitialLoadIMD>
</xsl:template>
</xsl:stylesheet>
However, this is a fatal attraction. Even though the content should be technically equivalent, but I got an "Line Number:(13) : Error: "D1-InitialLoadIMD" Element not Found in Target Schema".
It cost me a few hours to sort it out. The morale of the story, be careful when you mess up the namespace with the auto-generated XSLT.
Wednesday, August 31, 2011
Replace / rename namespace in OSB
I have an input schema without a name space, like <a><b><c>blah</c></b></a>.
I need to convert it into <a xmlns="http://x.y.com/z"><b><c>blah</c></b></a>. Beware this is equavilant to <foo:a xmlns:foo="http://x.y.com/z"><foo:b><foo:c>blah</foo:c><./foo:b></foo:a>
I have tried various ways, including use "fn-bea:serialize($arg-items)" and "contact()", just couldn't make it work. I found my solution by browsing online. then trial and error.
First of all, you can always use XSLT to transalte to new namespace. But I want to use the built-in activites to do it.
My answer is to use "rename" activity.
In my case, I put in
XPath: ".//*"
In Variable: myVar (which contains the source XML)
localname: (leave it empty)
Namespace: http://x.y.com/z"
This will take care of all elements of <b> and down. So you I have to do another rename, just for <a> (If you are wondering, I actually tried XPath: "//*". It didn't work).
So for the 2nd rename:
XPath: "."
In Variable: myVar (which contains the source XML)
localname: (leave it empty)
Namespace: http://x.y.com/z"
I'm quite sure you can do (or leave xpath as ".")
XPath: "./a"
In Variable: myVar (which contains the source XML)
localname: a
Namespace: http://x.y.com/z"
I need to convert it into <a xmlns="http://x.y.com/z"><b><c>blah</c></b></a>. Beware this is equavilant to <foo:a xmlns:foo="http://x.y.com/z"><foo:b><foo:c>blah</foo:c><./foo:b></foo:a>
I have tried various ways, including use "fn-bea:serialize($arg-items)" and "contact()", just couldn't make it work. I found my solution by browsing online. then trial and error.
First of all, you can always use XSLT to transalte to new namespace. But I want to use the built-in activites to do it.
My answer is to use "rename" activity.
In my case, I put in
XPath: ".//*"
In Variable: myVar (which contains the source XML)
localname: (leave it empty)
Namespace: http://x.y.com/z"
This will take care of all elements of <b> and down. So you I have to do another rename, just for <a> (If you are wondering, I actually tried XPath: "//*". It didn't work).
So for the 2nd rename:
XPath: "."
In Variable: myVar (which contains the source XML)
localname: (leave it empty)
Namespace: http://x.y.com/z"
I'm quite sure you can do (or leave xpath as ".")
XPath: "./a"
In Variable: myVar (which contains the source XML)
localname: a
Namespace: http://x.y.com/z"
Monday, August 29, 2011
An Oracle standard DB install issue with OracleMTSRecoveryService
I got too busy with work, lots things happened that I should post it here. Let me start with a small one.
During Oracle 11g DB (standard version) install, I run into an error, "Error in starting the service. The service OracleMTSRecoveryService was not found".
If I check the service panel, i can see this:
I ignored it a few times. Then I decided to take a closer look and found a work around. here is my solution.
When this error box pops up, keep it there. Fire up regedit go to "computer\hkey_local_machine\system\controlset001\service\OracleMTSRecoveryService". Double click on ImagePath, then change the path to where your Oracle is actually installed.
In my case, the ImagePath has a value of
C:\Oracle\product\11.2.0\dbhome_1\bin\omtsreco.exe "OracleMTSRecoveryService"
I had to change it to:
C:\app\myaccount\product\11.2.0\dbhome_1\bin\omtsreco.exe "OracleMTSRecoveryService"
then click on "retry". that solved my problem.
You may need to look around to see where your DB is actually installed. By defatul, it is installed under "c:\app\yourAcctName".
During Oracle 11g DB (standard version) install, I run into an error, "Error in starting the service. The service OracleMTSRecoveryService was not found".
If I check the service panel, i can see this:
I ignored it a few times. Then I decided to take a closer look and found a work around. here is my solution.
When this error box pops up, keep it there. Fire up regedit go to "computer\hkey_local_machine\system\controlset001\service\OracleMTSRecoveryService". Double click on ImagePath, then change the path to where your Oracle is actually installed.
In my case, the ImagePath has a value of
C:\Oracle\product\11.2.0\dbhome_1\bin\omtsreco.exe "OracleMTSRecoveryService"
I had to change it to:
C:\app\myaccount\product\11.2.0\dbhome_1\bin\omtsreco.exe "OracleMTSRecoveryService"
then click on "retry". that solved my problem.
You may need to look around to see where your DB is actually installed. By defatul, it is installed under "c:\app\yourAcctName".
Tuesday, June 7, 2011
Download and install workflow-001-DemoCommunitySeedApp.zip
Just bought Getting Started with Oracle BPM Suite 11gR1 - a hands-on tutorial. Quite disappointed with the install instructions!
First of all, the download links are all broken. I managed to get the demo file from here
https://soasamples.samplecode.oracle.com/files/documents/660/881/workflow-001-DemoCommunitySeedApp.zip
Then when I tried to follow the README and to install it, I have to do the following for my local install:
1. edit setAntEnv.bat,
set JAVA_HOME=C:\Oracle\Middleware\jdk1.6.0_25
set MW_HOME=C:\oracle\Middleware
2. ant seedDemoUsers -Dbea.home=C:/Oracle/Middleware/ -Doracle.home=C:/Oracle/Middleware/Oracle_SOA1 -Dtarget=soa_server1 -Dadmin.url=t3://localhost:7001 -Dserver.url=http:///localhost:8001 -Dadmin.name=weblogic -Dadmin.pwd=welcome1
Basically, MW_HOME is "C:/Oracle/Middleware/Oracle_SOA1" and BEA_HOME is "C:/Oracle/Middleware" for me.
Just between 1 and 2, mw_home suddenly means different things. Go figure.
First of all, the download links are all broken. I managed to get the demo file from here
https://soasamples.samplecode.oracle.com/files/documents/660/881/workflow-001-DemoCommunitySeedApp.zip
Then when I tried to follow the README and to install it, I have to do the following for my local install:
1. edit setAntEnv.bat,
set JAVA_HOME=C:\Oracle\Middleware\jdk1.6.0_25
set MW_HOME=C:\oracle\Middleware
2. ant seedDemoUsers -Dbea.home=C:/Oracle/Middleware/ -Doracle.home=C:/Oracle/Middleware/Oracle_SOA1 -Dtarget=soa_server1 -Dadmin.url=t3://localhost:7001 -Dserver.url=http:///localhost:8001 -Dadmin.name=weblogic -Dadmin.pwd=welcome1
Basically, MW_HOME is "C:/Oracle/Middleware/Oracle_SOA1" and BEA_HOME is "C:/Oracle/Middleware" for me.
Just between 1 and 2, mw_home suddenly means different things. Go figure.
Tuesday, April 5, 2011
Base64 Code Snippets for OSB and BPEL
This post applies to SOA suite 11.1.1.3.
I need to decode a base64 payload in my OSB proxy service. Here is a native solution that I came up with:
1. The java source:
I need to decode a base64 payload in my OSB proxy service. Here is a native solution that I came up with:
1. The java source:
//import org.apache.xerces.impl.dv.util.*;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.*;
public class MyBase64
{
public static String decode(String x)
{
try {
String path = "file:///"+System.getenv("ALSB_HOME") + "/../modules/com.bea.core.apache.xercesImpl_2.8.1.jar";
URL[] urls = new URL[] { new URL(path) };
ClassLoader loader = new URLClassLoader(urls);
Class<?> cls = loader.loadClass("org.apache.xerces.impl.dv.util.Base64");
Method theMethod = cls.getMethod("decode", String.class);
return new String( (byte[])theMethod.invoke(null, x));
}
catch(Exception e)
{
e.printStackTrace();
return "decode failed";
}
}
public static void main(String args[])
{
System.out.println(decode("Zm9vIGJhciBhbmQgY2FyIHRyeSBhZ2Fpbg=="));
}
}
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.*;
public class MyBase64
{
public static String decode(String x)
{
try {
String path = "file:///"+System.getenv("ALSB_HOME") + "/../modules/com.bea.core.apache.xercesImpl_2.8.1.jar";
URL[] urls = new URL[] { new URL(path) };
ClassLoader loader = new URLClassLoader(urls);
Class<?> cls = loader.loadClass("org.apache.xerces.impl.dv.util.Base64");
Method theMethod = cls.getMethod("decode", String.class);
return new String( (byte[])theMethod.invoke(null, x));
}
catch(Exception e)
{
e.printStackTrace();
return "decode failed";
}
}
public static void main(String args[])
{
System.out.println(decode("Zm9vIGJhciBhbmQgY2FyIHRyeSBhZ2Fpbg=="));
}
}
2. complie java source (you need to add C:\Oracle\Middleware\modules\com.bea.core.apache.xercesImpl_2.8.1.jar to your compiler classpath, your path maybe different)
3. jar it up
4. add jar to your osb project. (In your project, choose "Create Resource", select "JAR" under "Utility")
4. use in your java callout
Here is a BPEL snippet to encode base64
<bpelx:exec name="base64EncodeTemp" version="1.5" language="java">
<![CDATA[
String sTemp = (String)getVariableData("temp");
addAuditTrailEntry("Covert Temp to Byte Array : \n" + sTemp);
byte[] bTemp = new byte[sTemp.length() / 2];
for (int i = 0; i < bTemp.length; i++) {
bTemp[i] = (byte) Integer.parseInt(sTemp.substring(i*2, (i*2)+2), 16);
}
sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
String encodedTemp = encoder.encodeBuffer(bTemp);
setVariableData("temp", encodedTemp);]]>
</bpelx:exec>
Here is a BPEL snippet to encode base64
<bpelx:exec name="base64EncodeTemp" version="1.5" language="java">
<![CDATA[
String sTemp = (String)getVariableData("temp");
addAuditTrailEntry("Covert Temp to Byte Array : \n" + sTemp);
byte[] bTemp = new byte[sTemp.length() / 2];
for (int i = 0; i < bTemp.length; i++) {
bTemp[i] = (byte) Integer.parseInt(sTemp.substring(i*2, (i*2)+2), 16);
}
sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
String encodedTemp = encoder.encodeBuffer(bTemp);
setVariableData("temp", encodedTemp);]]>
</bpelx:exec>
Monday, April 4, 2011
OSB complains JCA class cannot be found
Recently I experienced some problems with OSB complaining about JCA class cannot be found. My SOA suite version is 11.1.1.3.
As I work on OSB JCA DB adapters, all of a sudden I see errors like the following:
Invalid JCA transport endpoint configuration, exception: javax.resource.ResourceException: Cannot locate Java class oracle.tip.adapter.db.DBWriteInteractionSpec
Invalid JCA transport endpoint configuration, exception: javax.resource.ResourceException: Cannot locate Java class oracle.tip.adapter.db.DBActivationSpec
This initially gives me the impression that someone touched the startup script that messed up the classpath. So I modified the startup script to hard code the jar files in the classpath. That didn’t really solve the problem.
After sifting through log files and comparing config.xml, I noticed that my OSB server is missing from the DB adapter deployment target list.
<app-deployment>
<name>DbAdapter</name>
<target>AdminServer,osb_server1,soa_server1</target>
…
</app-deployment>
You can either edit your config.xml file to add it back in. Or go to weblogic console -> deployments -> DbAdapter -> Targets and make sure “osb_server1” is checked.
I think there is a bug that can cause this to happen. I don’t have an exact way to reproduce it. As you work on OSB JCA adapter services, this error may creep up on you.
Subscribe to:
Posts (Atom)


