diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/pom.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/pom.xml new file mode 100644 index 000000000..04d8b8ea2 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/pom.xml @@ -0,0 +1,43 @@ + + + + + + 4.0.0 + + open-jbi-components + ServiceEngine-Plugin-archetype + 1.0-SNAPSHOT + maven-archetype + + ServiceEngine-Plugin-archetype + + + + + org.apache.maven.archetype + archetype-packaging + 2.2 + + + + + + + maven-archetype-plugin + 2.2 + + + + + + Maven project Archtype for OpenESB Service Engine Netbeans Plugin + + http://open-esb.org + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/META-INF/maven/archetype-metadata.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 000000000..beba49420 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,81 @@ + + + + + + + + + deploy-plugin/nbproject + + **/*.xml + **/*.properties + + + + deploy-plugin/src + + **/*.html + **/*.java + **/*.xml + **/*.properties + + + + nbproject + + **/*.xml + **/*.properties + + + + nbproject/private + + **/*.xml + **/*.properties + + + + deploy-plugin + + **/*.xml + + + + deploy-plugin/src + + **/*.xsl + **/*.form + **/*.wsdl + **/*.png + **/*.AntBasedProjectType + **/*.CollocationQueryImplementation + + + + deploy-plugin + + **/*.mf + + + + + + build.xml + install-params.properties + m2nbbuild-impl.xml + m2nbbuild.properties + m2nbbuild.xml + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build.xml new file mode 100644 index 000000000..14afd1d29 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build.xml @@ -0,0 +1,72 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + Builds, tests, and runs the project ${artifactId}. + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/pom.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/pom.xml new file mode 100644 index 000000000..fb390739c --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/pom.xml @@ -0,0 +1,38 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + 4.0.0 + + ${package} + ${artifactId}-archetype + ${version} + maven-archetype + + ${artifactId}-archetype + + + + + org.apache.maven.archetype + archetype-packaging + 2.2 + + + + + + + maven-archetype-plugin + 2.2 + + + + + + Maven project for JBI Component that contains the + maven and netbeans build setup and component code to build and test the JBI Component. + + http://open-esb.org + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml new file mode 100644 index 000000000..4bcb4d7ee --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml @@ -0,0 +1,33 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml new file mode 100644 index 000000000..8b878c82f --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml @@ -0,0 +1,146 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + org.netbeans.modules.apisupport.project + + + serviceengine + + + + org.apache.tools.ant.module + + + + 3 + 3.27.0.2 + + + + org.jdesktop.layout + + + + 1 + 1.4 + + + + org.netbeans.modules.java.project + + + + 1 + 1.12 + + + + org.netbeans.modules.project.ant + + + + 1 + 1.16 + + + + org.netbeans.modules.projectapi + + + + 1 + 1.13 + + + + org.netbeans.modules.projectuiapi + + + + 1 + 1.24.0.6 + + + + org.netbeans.modules.queries + + + + 1 + 1.10 + + + + org.openide.actions + + + + 6.6.0.1 + + + + org.openide.awt + + + + 6.11.0.1 + + + + org.openide.dialogs + + + + 7.5 + + + + org.openide.execution + + + + 1.10 + + + + org.openide.filesystems + + + + 7.3 + + + + org.openide.loaders + + + + 6.5 + + + + org.openide.nodes + + + + 7.2.0.1 + + + + org.openide.util + + + + 7.9.0.1 + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test1Input.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test1Input.xml new file mode 100644 index 000000000..b50d82c16 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test1Input.xml @@ -0,0 +1,18 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + Srinivasan + Chikkala + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test2Input.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test2Input.xml new file mode 100644 index 000000000..947bb579c --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test2Input.xml @@ -0,0 +1,18 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + Srinivasan + Chikkala + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/build.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/build.xml new file mode 100644 index 000000000..5456aa8f2 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/build.xml @@ -0,0 +1,143 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.assembly.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml new file mode 100644 index 000000000..fd6c5a710 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml @@ -0,0 +1,47 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + ${symbol_dollar}{artifactId}_TestSA + This is a test Service Assembly to test Engine + + + + + ${symbol_dollar}{artifactId}_TestSUBC + This service unit enables soap inbound endpoint for a service in service engine + + + testSUBC.zip + sun-http-binding + + + + + ${symbol_dollar}{artifactId}_TestSUSE + This service unit enables greetings service provider in service engine + + + testSUSE.zip + ${symbol_dollar}{artifactId} + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml new file mode 100644 index 000000000..96e95745f --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml @@ -0,0 +1,77 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml new file mode 100644 index 000000000..251f4073e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml new file mode 100644 index 000000000..251f4073e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml new file mode 100644 index 000000000..75340ea7d --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml @@ -0,0 +1,77 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml new file mode 100644 index 000000000..1ce2022bf --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml new file mode 100644 index 000000000..1ce2022bf --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/build.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/build.xml new file mode 100644 index 000000000..12e9743bf --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/build.xml @@ -0,0 +1,11 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + Builds, tests, and runs the project ${artifactId}. + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/manifest.mf b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/manifest.mf new file mode 100644 index 000000000..7b9bf6601 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/manifest.mf @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: ${artifactId} +OpenIDE-Module-Layer: ${artifactId}/layer.xml +OpenIDE-Module-Localizing-Bundle: ${artifactId}/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml new file mode 100644 index 000000000..3b9e10fcc --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml @@ -0,0 +1,30 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/genfiles.properties b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/genfiles.properties new file mode 100644 index 000000000..fe0e275eb --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/genfiles.properties @@ -0,0 +1,11 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +build.xml.data.CRC32=10d1596b +build.xml.script.CRC32=11ff9e8e +build.xml.stylesheet.CRC32=a56c6a5b@2.50.1 +${symbol_pound} This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +${symbol_pound} Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=10d1596b +nbproject/build-impl.xml.script.CRC32=a0f936cd +nbproject/build-impl.xml.stylesheet.CRC32=68e521fc@2.50.1 diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/platform.properties b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/platform.properties new file mode 100644 index 000000000..7ac9923fb --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/platform.properties @@ -0,0 +1,4 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +nbplatform.active=default diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/private/platform-private.properties b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/private/platform-private.properties new file mode 100644 index 000000000..3ac32342a --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/private/platform-private.properties @@ -0,0 +1,4 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +user.properties.file=D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working57${symbol_escape}${symbol_escape}.netbeans${symbol_escape}${symbol_escape}openesb${symbol_escape}${symbol_escape}build.properties diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.properties b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.properties new file mode 100644 index 000000000..a5e2da3b1 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.properties @@ -0,0 +1,7 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +javac.compilerargs=-Xlint -Xlint:-serial +javac.source=1.5 +nbm.homepage=http://www.netbeans.org +nbm.module.author=logicoyparam diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml new file mode 100644 index 000000000..b830d1f94 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml @@ -0,0 +1,151 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + org.netbeans.modules.apisupport.project + + + ${artifactId} + + + + org.apache.tools.ant.module + + + + 3 + 3.27.0.2 + + + + org.jdesktop.layout + + + + 1 + 1.4 + + + + org.netbeans.modules.java.project + + + + 1 + 1.12 + + + + org.netbeans.modules.project.ant + + + + 1 + 1.16 + + + + org.netbeans.modules.projectapi + + + + 1 + 1.13 + + + + org.netbeans.modules.projectuiapi + + + + 1 + 1.24.0.6 + + + + org.netbeans.modules.queries + + + + 1 + 1.10 + + + + org.openide.actions + + + + 6.6.0.1 + + + + org.openide.awt + + + + 6.11.0.1 + + + + org.openide.dialogs + + + + 7.5 + + + + org.openide.execution + + + + 1.10 + + + + org.openide.filesystems + + + + 7.3 + + + + org.openide.loaders + + + + 6.5 + + + + org.openide.nodes + + + + 7.2.0.1 + + + + org.openide.util + + + + 7.9.0.1 + + + + org.openide.util.lookup + + + + 8.15.2 + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.spi.project.support.ant.AntBasedProjectType b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.spi.project.support.ant.AntBasedProjectType new file mode 100644 index 000000000..155f1a762 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.spi.project.support.ant.AntBasedProjectType @@ -0,0 +1 @@ +serviceengine.project.SEPluginProjectType diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.spi.queries.CollocationQueryImplementation b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.spi.queries.CollocationQueryImplementation new file mode 100644 index 000000000..9be0d09e9 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.spi.queries.CollocationQueryImplementation @@ -0,0 +1 @@ +org.netbeans.modules.compapp.projects.base.queries.SameDriveCollocationQuery diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/Bundle.properties b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/Bundle.properties new file mode 100644 index 000000000..3dfba410b --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/Bundle.properties @@ -0,0 +1,15 @@ +# binding component deployment plugin resource bundle +# binding deploy plugin +OpenIDE-Module-Name=JBI Deployment Plugin[${artifactId}] +# deployment plugin +OpenIDE-Module-Short-Description=Service engine deployment plugin for ${artifactId} +# deployment plugin for adding wsdl extensions related to the binding component to the wsdl editor +OpenIDE-Module-Long-Description=Deployment plugin for creating service units related to this service engine in composite application +# category +OpenIDE-Module-Display-Category=CAPS + +# plugin project template +Templates/Project/SOA/${artifactId}JBIModule.xml=${artifactId} JBI Module + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/layer.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/layer.xml new file mode 100644 index 000000000..b855204c4 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/layer.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/Bundle.properties b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/Bundle.properties new file mode 100644 index 000000000..7b3c45fe3 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/Bundle.properties @@ -0,0 +1,4 @@ +LBL_Node_Sources=Sources + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProject.java b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProject.java new file mode 100644 index 000000000..9f6059eee --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProject.java @@ -0,0 +1,408 @@ +/* + * SEPluginProject.java + * + */ +package net.openesb.component.${artifactId}.project; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.io.File; +import java.io.IOException; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import org.netbeans.api.project.FileOwnerQuery; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectInformation; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.api.project.Sources; +import org.netbeans.api.project.ant.AntArtifact; +import net.openesb.component.${artifactId}.project.customizer.SEPluginProjectCustomizerProvider; +import org.netbeans.spi.java.project.support.ui.BrokenReferencesSupport; +import org.netbeans.spi.project.AuxiliaryConfiguration; +import org.netbeans.spi.project.SubprojectProvider; +import org.netbeans.spi.project.ant.AntArtifactProvider; +import org.netbeans.spi.project.support.ant.AntProjectEvent; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.AntProjectListener; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; +import org.netbeans.spi.project.support.ant.ProjectXmlSavedHook; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.netbeans.spi.project.support.ant.ReferenceHelper; +import org.netbeans.spi.project.support.ant.SourcesHelper; +import org.netbeans.spi.project.ui.PrivilegedTemplates; +import org.netbeans.spi.project.ui.ProjectOpenedHook; +import org.netbeans.spi.project.ui.RecommendedTemplates; +import org.netbeans.spi.queries.FileBuiltQueryImplementation; +import org.netbeans.spi.queries.SharabilityQueryImplementation; +import org.openide.ErrorManager; +import org.openide.filesystems.FileObject; +import org.openide.util.Lookup; +import org.openide.util.Mutex; +import org.openide.util.NbBundle; +import org.openide.util.Utilities; +import org.openide.util.lookup.Lookups; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +/** + * + * @author chikkala + */ +public final class SEPluginProject implements Project, AntProjectListener { + + private static final Icon PROJECT_ICON = new ImageIcon(Utilities.loadImage(SEPluginProjectProperties.SE_PLUGIN_PROJECT_ICON_PATH)); // NOI18N + private AntProjectHelper helper; + private PropertyEvaluator evaluator; + private ReferenceHelper refHelper; + private GeneratedFilesHelper genFilesHelper; + private Lookup lookup; + + public SEPluginProject(AntProjectHelper helper) throws IOException { + this.helper = helper; + this.evaluator = createEvaluator(); + AuxiliaryConfiguration aux = helper.createAuxiliaryConfiguration(); + this.refHelper = new ReferenceHelper(helper, aux, helper.getStandardPropertyEvaluator()); + this.genFilesHelper = new GeneratedFilesHelper(helper); + this.lookup = createLookup(aux); + helper.addAntProjectListener(this); + } + + @Override + public String toString() { + return "SEPluginProject[" + getProjectDirectory() + "]"; // NOI18N + } + + public FileObject getProjectDirectory() { + return helper.getProjectDirectory(); + } + + public Lookup getLookup() { + return lookup; + } + + public void configurationXmlChanged(AntProjectEvent event) { + if (event.getPath().equals(AntProjectHelper.PROJECT_XML_PATH)) { + // Could be various kinds of changes, but name & displayName might have changed. + Info info = (Info) getLookup().lookup(ProjectInformation.class); + info.firePropertyChange(ProjectInformation.PROP_NAME); + info.firePropertyChange(ProjectInformation.PROP_DISPLAY_NAME); + } + //TODO: add other configuration xml change event handling code. + } + + public void propertiesChanged(AntProjectEvent event) { + //TODO: add property change event processing. + } + + public AntProjectHelper getAntProjectHelper() { + return helper; + } + + public ReferenceHelper getReferenceHelper() { + return this.refHelper; + } + + public PropertyEvaluator getEvaluator() { + return this.evaluator; + } + + /** + * Return configured project name. + */ + @SuppressWarnings(value = "unchecked") + public String getName() { + return (String) ProjectManager.mutex().readAccess(new Mutex.Action() { + public Object run() { + Element data = helper.getPrimaryConfigurationData(true); + + NodeList nl = data.getElementsByTagNameNS(SEPluginProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); + if (nl.getLength() == 1) { + nl = nl.item(0).getChildNodes(); + if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) { + return ((Text) nl.item(0)).getNodeValue(); + } + } + return "???"; // NOI18N + } + }); + } + + /** + * Store configured project name. + */ + @SuppressWarnings(value = "unchecked") + public void setName(final String name) { + ProjectManager.mutex().writeAccess(new Mutex.Action() { + public Object run() { + Element data = helper.getPrimaryConfigurationData(true); + + NodeList nl = data.getElementsByTagNameNS(SEPluginProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); + Element nameEl; + if (nl.getLength() == 1) { + nameEl = (Element) nl.item(0); + NodeList deadKids = nameEl.getChildNodes(); + while (deadKids.getLength() > 0) { + nameEl.removeChild(deadKids.item(0)); + } + } else { + nameEl = data.getOwnerDocument().createElementNS(SEPluginProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); + data.insertBefore(nameEl, data.getChildNodes().item(0)); + } + nameEl.appendChild(data.getOwnerDocument().createTextNode(name)); + helper.putPrimaryConfigurationData(data, true); + return null; + } + }); + } + + private PropertyEvaluator createEvaluator() { + //TODO: might need to use a custom evaluator to handle active platform substitutions... + return helper.getStandardPropertyEvaluator(); + } + + private FileBuiltQueryImplementation createFileBuiltQuery() { + return helper.createGlobFileBuiltQuery(getEvaluator(), + new String[]{"${src.dir}/*.java"}, // NOI18N + new String[]{"${build.classes.dir}/*.class"} // NOI18N + ); + } + + private SharabilityQueryImplementation createSharabilityQuery() { + return helper.createSharabilityQuery(getEvaluator(), + new String[]{"${src.dir}"}, // NOI18N + new String[]{"${build.dir}"} // NOI18N + ); + } + + private Sources getSources() { + final SourcesHelper sourcesHelper = new SourcesHelper(helper, getEvaluator()); + //TODO: add pricipal and typed source roots if required. + String srcLabel = NbBundle.getMessage(SEPluginProject.class, "LBL_Node_Sources"); //NOI18N + + String srcLoc = "${" + SEPluginProjectProperties.SRC_DIR + "}"; + sourcesHelper.addPrincipalSourceRoot(srcLoc, srcLabel, null, null); + sourcesHelper.addTypedSourceRoot(srcLoc, SEPluginProjectProperties.SOURCES_TYPE_XML, + srcLabel, null, null); + ProjectManager.mutex().postWriteRequest(new Runnable() { + public void run() { + sourcesHelper.registerExternalRoots(FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT); + } + }); + return sourcesHelper.createSources(); + } + + private Lookup createLookup(AuxiliaryConfiguration aux) { + + SubprojectProvider spp = refHelper.createSubprojectProvider(); + return Lookups.fixed(new Object[]{ + this, // to lookup this project from externally obtained Project + aux, + helper.createCacheDirectoryProvider(), + spp, + new Info(), + new SEPluginProjectActionProvider(this, helper, refHelper), + new SEPluginProjectLogicalViewProvider(this, helper, getEvaluator(), spp, refHelper), + new SEPluginProjectCustomizerProvider(this, helper, refHelper), + new AntArtifactProviderImpl(), + new ProjectXmlSavedHookImpl(), + new ProjectOpenedHookImpl(), + new RecommendedTemplatesImpl(), + new SEPluginProjectOperations(this), + getSources(), + createSharabilityQuery(), + createFileBuiltQuery() + }); + } +// Private inner classes ------------------------------------------------------- + + /** + * @see org.netbeans.api.project.ProjectInformation + */ + private final class Info implements ProjectInformation { + + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + + Info() { + } + + void firePropertyChange(String prop) { + pcs.firePropertyChange(prop, null, null); + } + + public String getName() { + return SEPluginProject.this.getName(); + } + + public String getDisplayName() { + return SEPluginProject.this.getName(); + } + + public Icon getIcon() { + return PROJECT_ICON; + } + + public Project getProject() { + return SEPluginProject.this; + } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + pcs.addPropertyChangeListener(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + pcs.removePropertyChangeListener(listener); + } + } + + /** + * @see org.netbeans.spi.project.support.ant.ProjectXmlSavedHook + */ + private final class ProjectXmlSavedHookImpl extends ProjectXmlSavedHook { + + ProjectXmlSavedHookImpl() { + } + + protected void projectXmlSaved() throws IOException { + genFilesHelper.refreshBuildScript( + GeneratedFilesHelper.BUILD_IMPL_XML_PATH, + SEPluginProject.class.getResource("resources/build-impl.xsl"), + false); + genFilesHelper.refreshBuildScript( + GeneratedFilesHelper.BUILD_XML_PATH, + SEPluginProject.class.getResource("resources/build.xsl"), + false); + } + } + + /** + * @see org.netbeans.spi.project.ui.ProjectOpenedHook + */ + private final class ProjectOpenedHookImpl extends ProjectOpenedHook { + + // TODO m + ProjectOpenedHookImpl() { + } + + @SuppressWarnings("unchecked") + protected void projectOpened() { + + try { + // Check up on build scripts. + genFilesHelper.refreshBuildScript( + GeneratedFilesHelper.BUILD_IMPL_XML_PATH, + SEPluginProject.class.getResource("resources/build-impl.xsl"), + true); + genFilesHelper.refreshBuildScript( + GeneratedFilesHelper.BUILD_XML_PATH, + SEPluginProject.class.getResource("resources/build.xsl"), + true); + } catch (IOException e) { + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); + } + + // Make it easier to run headless builds on the same machine at least. + ProjectManager.mutex().writeAccess(new Mutex.Action() { + public Object run() { + EditableProperties ep = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); + File buildProperties = new File(System.getProperty("netbeans.user"), "build.properties"); // NOI18N + ep.setProperty("user.properties.file", buildProperties.getAbsolutePath()); //NOI18N + helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep); + //TODO: add any other resolved private properties. for example, the project paths and lib paths + try { + ProjectManager.getDefault().saveProject(SEPluginProject.this); + } catch (IOException e) { + ErrorManager.getDefault().notify(e); + } + return null; + } + }); + + SEPluginProjectLogicalViewProvider logicalViewProvider = + SEPluginProject.this.getLookup().lookup(SEPluginProjectLogicalViewProvider.class); + if (logicalViewProvider != null && logicalViewProvider.hasBrokenLinks()) { + BrokenReferencesSupport.showAlert(); + } + } + + protected void projectClosed() { + // Probably unnecessary, but just in case: + try { + ProjectManager.getDefault().saveProject(SEPluginProject.this); + } catch (IOException e) { + ErrorManager.getDefault().notify(e); + } + } + } + + /** + * @see org.netbeans.spi.project.ui.RecommendedTemplates + * @see org.netbeans.spi.project.ui.PrivilegedTemplates + */ + private static final class RecommendedTemplatesImpl implements RecommendedTemplates, PrivilegedTemplates { + + // List of primarily supported templates + private static final String[] TYPES = new String[]{ + /* TODO: add any other recommended templates + "java-classes", // NOI18N + "ejb-types", // NOI18N + "java-beans", // NOI18N + "oasis-XML-catalogs", // NOI18N + "XML", // NOI18N + "ant-script", // NOI18N + "ant-task", // NOI18N + "simple-files" // NOI18N + */ + "SOA", + "XML", // NOI18N + "simple-files" // NOI18N + }; + private static final String[] PRIVILEGED_NAMES = new String[]{ + /* TODO: add any other privileged names + "Templates/Classes/Class.java", // NOI18N + "Templates/Classes/Package", // NOI18N + "Templates/Classes/Interface.java" // NOI18N + */ + "Templates/XML/XmlDocument.xml", // NOI18N + "Templates/XML/XmlSchema.xsd", // NOI18N + "Templates/XML/WSDL.wsdl", // NOI18N + "Templates/Other/properties.properties" // NOI18N + }; + + public String[] getRecommendedTypes() { + return TYPES; + } + + public String[] getPrivilegedTemplates() { + return PRIVILEGED_NAMES; + } + } + + /** + * Exports the main JAR as an official build product for use from other + * scripts. The type of the artifact will be {@link AntArtifact#TYPE_JAR}. + * + * @see org.netbeans.spi.project.ant.AntArtifactProvider + */ + private final class AntArtifactProviderImpl implements AntArtifactProvider { + + public AntArtifact[] getBuildArtifacts() { + return new AntArtifact[]{ + helper.createSimpleAntArtifact( + SEPluginProjectProperties.ARTIFACT_TYPE_JBI_SU_PREFIX + + helper.getStandardPropertyEvaluator().getProperty(SEPluginProjectProperties.JBI_SU_TARGET_NAME), + SEPluginProjectProperties.JBI_SU_ZIP, + helper.getStandardPropertyEvaluator(), + SEPluginProjectProperties.BUILD_TARGET_DIST, + SEPluginProjectProperties.BUILD_TARGET_CLEAN), + helper.createSimpleAntArtifact(SEPluginProjectProperties.ARTIFACT_TYPE_JAR, + SEPluginProjectProperties.JBI_SU_ZIP, + helper.getStandardPropertyEvaluator(), + SEPluginProjectProperties.BUILD_TARGET_DIST, + SEPluginProjectProperties.BUILD_TARGET_CLEAN) + }; + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectActionProvider.java b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectActionProvider.java new file mode 100644 index 000000000..f24d31835 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectActionProvider.java @@ -0,0 +1,136 @@ +/* + * SEPluginProjectActionProvider.java + * + */ +package net.openesb.component.${artifactId}.project; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import org.apache.tools.ant.module.api.support.ActionUtils; +import org.netbeans.spi.project.ActionProvider; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; +import org.netbeans.spi.project.support.ant.ReferenceHelper; +import org.netbeans.spi.project.ui.support.DefaultProjectOperations; +import org.openide.DialogDisplayer; +import org.openide.ErrorManager; +import org.openide.NotifyDescriptor; +import org.openide.filesystems.FileObject; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; + +/** + * Action provider of the SE Plugin projects. + * + * @author chikkala + */ +public class SEPluginProjectActionProvider implements ActionProvider { + + // Commands available from SE Plugin Project + private static final String[] supportedActions = {COMMAND_BUILD, COMMAND_CLEAN, COMMAND_REBUILD, COMMAND_DELETE, COMMAND_COPY, COMMAND_MOVE, COMMAND_RENAME}; + private SEPluginProject project; + // Ant project helper of the project + private AntProjectHelper antProjectHelper; + private ReferenceHelper refHelper; + /** + * Map from commands to ant targets + */ + private Map commands; + + public SEPluginProjectActionProvider(SEPluginProject project, AntProjectHelper antProjectHelper, ReferenceHelper refHelper) { + commands = new HashMap(); + commands.put(COMMAND_BUILD, new String[]{"dist"}); // NOI18N + commands.put(COMMAND_CLEAN, new String[]{"clean"}); // NOI18N + commands.put(COMMAND_REBUILD, new String[]{"clean", "dist"}); // NOI18N + //TODO: Add any other ant targets to commands map. + //commands.put(COMMAND_DEPLOY, new String[] {"run"}); // NOI18N + this.antProjectHelper = antProjectHelper; + this.project = project; + this.refHelper = refHelper; + } + + public String[] getSupportedActions() { + return supportedActions; + } + + public void invokeAction(final String command, final Lookup context) throws IllegalArgumentException { + + if (COMMAND_COPY.equals(command)) { + DefaultProjectOperations.performDefaultCopyOperation(project); + return; + } + + if (COMMAND_MOVE.equals(command)) { + DefaultProjectOperations.performDefaultMoveOperation(project); + return; + } + + if (COMMAND_RENAME.equals(command)) { + DefaultProjectOperations.performDefaultRenameOperation(project, null); + return; + } + if (COMMAND_DELETE.equals(command)) { + DefaultProjectOperations.performDefaultDeleteOperation(project); + return; + } + + Runnable action = new Runnable() { + public void run() { + Properties p = new Properties(); + String[] targetNames; + + targetNames = getTargetNames(command, context, p); + if (targetNames == null) { + return; + } + if (targetNames.length == 0) { + targetNames = null; + } + if (p.keySet().size() == 0) { + p = null; + } + try { + FileObject buildFo = findBuildXml(); + if (buildFo == null || !buildFo.isValid()) { + //The build.xml was deleted after the isActionEnabled was called + NotifyDescriptor nd = new NotifyDescriptor.Message(NbBundle.getMessage(SEPluginProjectActionProvider.class, + "LBL_No_Build_XML_Found"), NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(nd); + } else { + ActionUtils.runTarget(buildFo, targetNames, p); + } + } catch (IOException e) { + ErrorManager.getDefault().notify(e); + } + } + }; + //TODO: add code if needed that requires the execution to wait for some other task to complete. + action.run(); // execute the task to invoke the ant target for the command + + } + + public boolean isActionEnabled(String command, Lookup context) throws IllegalArgumentException { + if (findBuildXml() == null) { + return false; + } + //TODO: Add any commands enabling check logic if required. + return true; + } + + public FileObject findBuildXml() { + return project.getProjectDirectory().getFileObject(GeneratedFilesHelper.BUILD_XML_PATH); + } + + /** + * @return array of targets or null to stop execution; can return empty + * array + */ + public String[] getTargetNames(String command, Lookup context, Properties p) throws IllegalArgumentException { + String[] targetNames = commands.get(command); + //TODO: add any special code that requires adding new target names or setting the + // external properties p passed during the ant exection if required. + return targetNames; + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectGenerator.java b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectGenerator.java new file mode 100644 index 000000000..0cc2e39e1 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectGenerator.java @@ -0,0 +1,182 @@ +/* + * SEPluginProjectGenerator.java + * + */ +package net.openesb.component.${artifactId}.project; + +import java.io.File; +import java.io.File; +import java.io.IOException; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.netbeans.spi.project.support.ant.ProjectGenerator; +import org.netbeans.spi.project.support.ant.PropertyUtils; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileStateInvalidException; +import org.openide.filesystems.FileUtil; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Creates a Deployment Plugin Project for Service Engine. + * + * @author chikkala + */ +public class SEPluginProjectGenerator { + + private File mPrjDir; + private String mPrjName; + private String mSUName; + private String mSUDesc; + private String mSUTarget; + + public SEPluginProjectGenerator() { + this.mSUName = SEPluginProjectProperties.JBI_SU_NAME_VALUE; + this.mSUDesc = SEPluginProjectProperties.JBI_SU_DESCRIPTION_VALUE; + this.mSUTarget = SEPluginProjectProperties.JBI_SU_TARGET_NAME_VALUE; + } + + public File getProjectDirectory() { + return this.mPrjDir; + } + + public String getProjectName() { + return this.mPrjName; + } + + public String getSUName() { + return this.mSUName; + } + + public void setSUName(String suName) { + this.mSUName = suName; + } + + public String getSUDescription() { + return this.mSUDesc; + } + + public void setSUDescription(String suDesc) { + this.mSUDesc = suDesc; + } + + public String getSUTarget() { + return this.mSUTarget; + } + + public void setSUTarget(String suTarget) { + this.mSUTarget = suTarget; + } + + private void createPrimaryConfigurationData(AntProjectHelper prjHelper) { + + Element data = prjHelper.getPrimaryConfigurationData(true); + Document doc = data.getOwnerDocument(); + + Element nameEl = doc.createElementNS(SEPluginProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); // NOI18N + nameEl.appendChild(doc.createTextNode(this.getProjectName())); + data.appendChild(nameEl); + + prjHelper.putPrimaryConfigurationData(data, true); + } + + private void createProjectPrivateProperties(AntProjectHelper prjHelper) { + + EditableProperties ep = prjHelper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); + + //TODO: add any project private properties here. + // ep.setProperty("application.args", ""); // NOI18N + prjHelper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep); + } + + private void createProjectProperties(AntProjectHelper prjHelper) { + + EditableProperties ep = prjHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + + ep.setProperty(SEPluginProjectProperties.SRC_DIR, SEPluginProjectProperties.SRC_DIR_VALUE); + ep.setComment(SEPluginProjectProperties.SRC_DIR, new String[]{"# service unit source directory "}, false); // NOI18N + ep.setProperty(SEPluginProjectProperties.BUILD_DIR, SEPluginProjectProperties.BUILD_DIR_VALUE); + + ep.setProperty(SEPluginProjectProperties.BUILD_DIR, SEPluginProjectProperties.BUILD_DIR_VALUE); + + ep.setProperty(SEPluginProjectProperties.JBI_SU_ZIP, SEPluginProjectProperties.JBI_SU_ZIP_VALUE); + + ep.setProperty(SEPluginProjectProperties.JBI_SU_NAME, getSUName()); + ep.setProperty(SEPluginProjectProperties.JBI_SU_DESCRIPTION, getSUDescription()); + ep.setProperty(SEPluginProjectProperties.JBI_SU_TARGET_NAME, getSUTarget()); + + // save properties to file. + prjHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); + } + + public AntProjectHelper createProject(File prjDir, String prjName) throws IOException { + AntProjectHelper prjHelper = null; + + this.mPrjDir = prjDir; + this.mPrjName = prjName; + if (SEPluginProjectProperties.JBI_SU_NAME_VALUE.equals(this.getSUName())) { + // default value. so set the su name to project name. + String suName = PropertyUtils.getUsablePropertyName(this.getProjectName()); + this.setSUName(suName); + } + + FileObject prjDirFO = createProjectDir(this.getProjectDirectory()); + + prjHelper = ProjectGenerator.createProject(prjDirFO, SEPluginProjectType.TYPE); + + createPrimaryConfigurationData(prjHelper); + createProjectProperties(prjHelper); + createProjectPrivateProperties(prjHelper); + + FileObject srcFolder = FileUtil.createFolder(prjDirFO, SEPluginProjectProperties.SRC_DIR_VALUE); // NOI18N + + // create su jbi.xml + SEPluginProjectProperties.createDefaultSUDescriptor(srcFolder); + + //TODO: create any service unit specifc default artifacts here. + + Project p = ProjectManager.getDefault().findProject(prjDirFO); + ProjectManager.getDefault().saveProject(p); + + return prjHelper; + } + + private static FileObject createProjectDir(File dir) throws IOException { + FileObject dirFO; + if (!dir.exists()) { + //Refresh before mkdir not to depend on window focus, refreshFileSystem does not work correctly + refreshFolder(dir); + if (!dir.mkdirs()) { + throw new IOException("Can not create project folder."); //NOI18N + } + refreshFileSystem(dir); + } + dirFO = FileUtil.toFileObject(dir); + assert dirFO != null : "No such dir on disk: " + dir; // NOI18N + assert dirFO.isFolder() : "Not really a dir: " + dir; // NOI18N + return dirFO; + } + + private static void refreshFileSystem(final File dir) throws FileStateInvalidException { + File rootF = dir; + while (rootF.getParentFile() != null) { + rootF = rootF.getParentFile(); + } + FileObject dirFO = FileUtil.toFileObject(rootF); + assert dirFO != null : "At least disk roots must be mounted! " + rootF; // NOI18N + dirFO.getFileSystem().refresh(false); + } + + private static void refreshFolder(File dir) { + while (!dir.exists()) { + dir = dir.getParentFile(); + } + FileObject fo = FileUtil.toFileObject(dir); + if (fo != null) { + fo.getChildren(); + fo.refresh(); + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectLogicalViewProvider.java b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectLogicalViewProvider.java new file mode 100644 index 000000000..79f1cae06 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectLogicalViewProvider.java @@ -0,0 +1,81 @@ +/* + * SEPluginProjectLogicalViewProvider.java + * + */ +package net.openesb.component.${artifactId}.project; + +import org.netbeans.api.project.FileOwnerQuery; +import org.netbeans.api.project.Project; +import net.openesb.component.${artifactId}.project.node.SEPluginProjectNode; +import org.netbeans.spi.java.project.support.ui.BrokenReferencesSupport; +import org.netbeans.spi.java.project.support.ui.PackageView; +import org.netbeans.spi.project.SubprojectProvider; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.netbeans.spi.project.support.ant.ReferenceHelper; +import org.netbeans.spi.project.ui.LogicalViewProvider; +import org.openide.filesystems.FileObject; +import org.openide.nodes.Node; + +/** + * + * @author chikkala + */ +public class SEPluginProjectLogicalViewProvider implements LogicalViewProvider { + + private final Project mProject; + private final AntProjectHelper mHelper; + private final PropertyEvaluator mEvaluator; + private final SubprojectProvider mSpp; + private final ReferenceHelper mResolver; + + public SEPluginProjectLogicalViewProvider(Project project, AntProjectHelper helper, PropertyEvaluator evaluator, SubprojectProvider spp, ReferenceHelper resolver) { + this.mProject = project; + assert project != null; + this.mHelper = helper; + assert helper != null; + this.mEvaluator = evaluator; + assert evaluator != null; + this.mSpp = spp; + assert spp != null; + this.mResolver = resolver; + } + + public Node createLogicalView() { + return new SEPluginProjectNode(this.mProject, this.mHelper, this.mEvaluator, this.mSpp, this.mResolver); + } + + public Node findPath(Node root, Object target) { + Project project = root.getLookup().lookup(Project.class); + if (project == null) { + return null; + } + + if (target instanceof FileObject) { + FileObject fo = (FileObject) target; + Project owner = FileOwnerQuery.getOwner(fo); + if (!project.equals(owner)) { + return null; // Don't waste time if project does not own the fo + } + + Node[] nodes = root.getChildren().getNodes(true); + for (int i = 0; i < nodes.length; i++) { + Node result = PackageView.findPath(nodes[i], target); + if (result != null) { + return result; + } + } + } + + return null; + } + + private String[] getBreakableProperties() { + String[] breakableProps = new String[0]; + return breakableProps; + } + + public boolean hasBrokenLinks() { + return BrokenReferencesSupport.isBroken(mHelper, mResolver, getBreakableProperties(), new String[]{SEPluginProjectProperties.DEFAULT_PLATFORM}); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectOperations.java b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectOperations.java new file mode 100644 index 000000000..5c7dd9486 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectOperations.java @@ -0,0 +1,114 @@ +/* + * SEPluginProjectOperations.java + * + */ +package net.openesb.component.${artifactId}.project; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import org.apache.tools.ant.module.api.support.ActionUtils; +import org.netbeans.api.project.Project; +import org.netbeans.spi.project.ActionProvider; +import org.netbeans.spi.project.CopyOperationImplementation; +import org.netbeans.spi.project.DeleteOperationImplementation; +import org.netbeans.spi.project.MoveOperationImplementation; +import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; +import org.openide.filesystems.FileObject; +import org.openide.util.Lookup; +import org.openide.util.lookup.Lookups; + +/** + * + * @author chikkala + */ +public class SEPluginProjectOperations implements DeleteOperationImplementation, CopyOperationImplementation, MoveOperationImplementation { + + private SEPluginProject project; + + public SEPluginProjectOperations(SEPluginProject project) { + this.project = project; + } + + public void notifyDeleting() throws IOException { + SEPluginProjectActionProvider ap = project.getLookup().lookup(SEPluginProjectActionProvider.class); + + assert ap != null; + + Lookup context = Lookups.fixed(new Object[0]); + Properties p = new Properties(); + String[] targetNames = ap.getTargetNames(ActionProvider.COMMAND_CLEAN, context, p); + FileObject buildXML = project.getProjectDirectory().getFileObject(GeneratedFilesHelper.BUILD_XML_PATH); + + assert targetNames != null; + assert targetNames.length > 0; + + ActionUtils.runTarget(buildXML, targetNames, p).waitFinished(); + } + + public void notifyDeleted() throws IOException { + project.getAntProjectHelper().notifyDeleted(); + } + + public List getMetadataFiles() { + FileObject projectDirectory = project.getProjectDirectory(); + List files = new ArrayList(); + + addFile(projectDirectory, "nbproject", files); // NOI18N + addFile(projectDirectory, "build.xml", files); // NOI18N + addFile(projectDirectory, "manifest.mf", files); // NOI18N + addFile(projectDirectory, projectDirectory.getName(), files); //NOI18N + + return files; + } + + public List getDataFiles() { + List files = new ArrayList(); + FileObject projectDirectory = project.getProjectDirectory(); + FileObject srcDirFO = SEPluginProjectProperties.getSourceDirectory(project); + files.add(srcDirFO); + return files; + } + + public void notifyCopying() throws IOException { + // do nothing. + // This does copy the old distribution file over though, which is + // probably OK because "ant clean" will clean it up. + } + + public void notifyCopied(Project original, File originalPath, String newName) throws IOException { + if (original == null) { + // do nothing for the original project. + return; + } + + project.getReferenceHelper().fixReferences(originalPath); + + String oldName = project.getName(); + project.setName(newName); + } + + public void notifyMoving() throws IOException { + notifyDeleting(); + } + + public void notifyMoved(Project original, File originalPath, String newName) throws IOException { + if (original == null) { + project.getAntProjectHelper().notifyDeleted(); + return; + } + String oldName = project.getName(); + project.setName(newName); + project.getReferenceHelper().fixReferences(originalPath); + } + + private static void addFile(FileObject projectDirectory, String fileName, List result) { + FileObject file = projectDirectory.getFileObject(fileName); + + if (file != null) { + result.add(file); + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectProperties.java b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectProperties.java new file mode 100644 index 000000000..22166d15e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectProperties.java @@ -0,0 +1,149 @@ +/* + * SEPluginProjectProperties.java + * + */ +package net.openesb.component.${artifactId}.project; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.openide.filesystems.FileLock; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; + +/** + * + * @author chikkala + */ +public class SEPluginProjectProperties { + + public static final String DEFAULT_PLATFORM = "default_platform"; // NOI18N + public static final String SOURCES_TYPE_XML = "xml"; + public static final String SOURCES_TYPE_JAVA = "java"; + public static final String SE_PLUGIN_PROJECT_ICON_PATH = "serviceengine/project/resources/projectIcon.png"; // NOI18N" + /** + * comp app callable ant build targets see + * SEPluginProject.AntArtifactProviderImpl for more info. When a composite + * application project builds the service assembly it calls these targets to + * build a service unit added by this project. + */ + public static final String BUILD_TARGET_DIST = "dist_se"; // NOI18N + public static final String BUILD_TARGET_CLEAN = "clean"; // NOI18N + /** + * Ant artifact type value required for plugin to compapp project see + * SEPluginProject.AntArtifactProviderImpl for more info. The value used is + * "CAPS.asa: where is the name + * of the service engine to which the service unit created by this project + * will be deployed. + */ + public static final String ARTIFACT_TYPE_JBI_SU_PREFIX = "CAPS.asa:"; // NOI18N + /** + * service unit target property. The value is the component name of the + * service engine to which the service unit created by this project will be + * deployed. + */ + public static final String JBI_SU_TARGET_NAME = "jbi.su.target.name"; // NOI18N + /** + * Name of the service engine + */ + public static final String JBI_SU_TARGET_NAME_VALUE = "paramv4seplugin"; // NOI18N + public static final String ARTIFACT_TYPE_JAR = "jar"; // NOI18N + public static final String JBI_SU_NAME = "jbi.su.name"; // NOI18N + public static final String JBI_SU_NAME_VALUE = "ServiceUnit"; // NOI18N + public static final String JBI_SU_DESCRIPTION = "jbi.su.description"; // NOI18N + public static final String JBI_SU_DESCRIPTION_VALUE = "Service unit description"; // NOI18N + public static final String JBI_SU_ZIP = "jbi.su.zip"; + /** + * bug in the comp app project build system prevents us to define the + * service unit archive file name and location to be any thing. You must + * define a hardcoded name for the su archive. TODO: will use the + * ${build.dir}/${jbi.su.name}.zip when compapp bug is fixed. + */ + public static final String JBI_SU_ZIP_VALUE = "${build.dir}/SEDeployment.jar"; + // public static final String JBI_SU_ZIP_VALUE = "${build.dir}/${jbi.su.name}.zip"; + /** + * these properties can be used in the build script that produces the + * service unit archive file. + */ + public static final String JAR_COMPRESS = "jar.compress"; // NOI18N + public static final String BUILD_FILES_EXCLUDES = "build.files.excludes"; // NOI18N + public static final String BUILD_DIR = "build.dir"; // NOI18N + public static final String BUILD_DIR_VALUE = "build"; // NOI18N + public static final String JBI_SU_BUILD_DIR_VALUE = "${build.dir}/${jbi.su.name}"; // NOI18N + public static final String SRC_DIR = "src.dir"; // NOI18N + public static final String SRC_DIR_VALUE = "src"; // NOI18N + public static final String SU_JBI_XML_PATH = "META-INF/jbi.xml"; // NOI18N + + public static FileObject getSourceDirectory(SEPluginProject project) { + AntProjectHelper helper = project.getAntProjectHelper(); + String srcDir = helper.getStandardPropertyEvaluator().getProperty(SRC_DIR); // NOI18N + return helper.resolveFileObject(srcDir); + } + + public static FileObject createDefaultSUDescriptor(FileObject srcFolder) throws IOException { + FileObject jbiXmlFO = null; + + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + out.println(""); + out.println(""); + out.println(" "); + out.println(" "); + out.println(" "); + out.println(" "); + out.println(""); + out.close(); + writer.close(); + + jbiXmlFO = FileUtil.createData(srcFolder, SU_JBI_XML_PATH); + saveToFileObject(jbiXmlFO, writer.getBuffer()); + + return jbiXmlFO; + } + + public static void saveToFileObject(FileObject outFO, StringBuffer srcBuff) { + FileLock outLock = null; + OutputStream outS = null; + InputStream inS = null; + + try { + inS = new ByteArrayInputStream(srcBuff.toString().getBytes()); + outLock = outFO.lock(); + outS = outFO.getOutputStream(outLock); + FileUtil.copy(inS, outS); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + if (inS != null) { + try { + inS.close(); + } catch (Exception ex) { + //ingore + } + } + if (outS != null) { + try { + outS.close(); + } catch (Exception ex) { + //ingore + } + } + if (outLock != null) { + outLock.releaseLock(); + } + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectType.java b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectType.java new file mode 100644 index 000000000..1378bd99c --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/SEPluginProjectType.java @@ -0,0 +1,55 @@ +/* + * SEPluginProjectProperties.java + */ +package net.openesb.component.${artifactId}.project; + +import java.io.IOException; +import org.netbeans.api.project.Project; +import org.netbeans.spi.project.support.ant.AntBasedProjectType; +import org.netbeans.spi.project.support.ant.AntProjectHelper; + +/** + * Factory for simple service engine deployment plugin project projects. + * + * @author chikkala + */ +public final class SEPluginProjectType implements AntBasedProjectType { + + /** + */ + public static final String TYPE = "serviceengine.project.type"; // NOI18N + /** + */ + public static final String PROJECT_CONFIGURATION_NAMESPACE = "http://www.netbeans.org/ns/jbimodules/paramv4seplugin/1"; // NOI18N + /** + */ + public static final String PROJECT_CONFIGURATION_NAME = "data"; // NOI18N + /** + */ + public static final String PRIVATE_CONFIGURATION_NAME = "data"; // NOI18N + /** + */ + public static final String PRIVATE_CONFIGURATION_NAMESPACE = "http://www.netbeans.org/ns/jbimodules/paramv4seplugin/private/1"; // NOI18N + + /** + * Do nothing, just a service. + */ + public SEPluginProjectType() { + } + + public String getType() { + return TYPE; + } + + public Project createProject(AntProjectHelper helper) throws IOException { + return new SEPluginProject(helper); + } + + public String getPrimaryConfigurationDataElementName(boolean shared) { + return shared ? PROJECT_CONFIGURATION_NAME : PRIVATE_CONFIGURATION_NAME; + } + + public String getPrimaryConfigurationDataElementNamespace(boolean shared) { + return shared ? PROJECT_CONFIGURATION_NAMESPACE : PRIVATE_CONFIGURATION_NAMESPACE; + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/Bundle.properties b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/Bundle.properties new file mode 100644 index 000000000..05c5ab3d5 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/Bundle.properties @@ -0,0 +1,19 @@ +# CustomizerDialog +LBL_Customizer_Title=Project Properties - {0} +# cutomizer node labels +LBL_Config_General=General +LBL_Config_BuildCategories=Build +LBL_Config_Compile=Compile +LBL_Config_Package=Package + +# Cutomizer node panel strings +# sample cutomizer panel +# General cutomizer panel +LBL_config.general.su.name=Name: +LBL_config.general.su.desc=Description: +LBL_config.general.su.target=Target JBI Component\: +LBL_config.general.su.target.value.unknown=Unknown +LBL_config.package.su.zip=&Service Unit Archive File\: +LBL_config.package.build.files.exludes=&Exclude from archive file\: +LBL_config.package.build.files.exludes.message=(can not exclude jbi.xml) +CHKB_config.package.jar.compress=&Compress Archive File diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/CustomizerGeneral.form b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/CustomizerGeneral.form new file mode 100644 index 000000000..b54857007 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/CustomizerGeneral.form @@ -0,0 +1,128 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/CustomizerGeneral.java b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/CustomizerGeneral.java new file mode 100644 index 000000000..7943fd97c --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/CustomizerGeneral.java @@ -0,0 +1,178 @@ +/* + * CustomizerGeneral.java + */ +package net.openesb.component.${artifactId}.project.customizer; + +import javax.swing.JPanel; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import org.openide.util.HelpCtx; + +/** + * + * @author chikkala + */ +public class CustomizerGeneral extends JPanel implements HelpCtx.Provider { + + private SEPluginProjectCustomizerModel uiModel; + + public CustomizerGeneral(SEPluginProjectCustomizerModel uiModel) { + + this.uiModel = uiModel; + + initComponents(); + + initTargetComponent(uiModel.getSUTargetModel()); + + this.mSUNameTF.setDocument(uiModel.getSUNameModel()); + this.mSUDescriptionTA.setDocument(uiModel.getSUDescriptionModel()); + + } + + public HelpCtx getHelpCtx() { + return new HelpCtx(CustomizerGeneral.class); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + mSUTargetLBL = new javax.swing.JLabel(); + mSUTargetValueLBL = new javax.swing.JLabel(); + mSUNameLBL = new javax.swing.JLabel(); + mSUNameTF = new javax.swing.JTextField(); + mSUDescriptionLBL = new javax.swing.JLabel(); + mSUDescriptionScrollPane = new javax.swing.JScrollPane(); + mSUDescriptionTA = new javax.swing.JTextArea(); + mFillLBL = new javax.swing.JLabel(); + + setLayout(new java.awt.GridBagLayout()); + + mSUTargetLBL.setLabelFor(mSUTargetValueLBL); + mSUTargetLBL.setText(org.openide.util.NbBundle.getMessage(CustomizerGeneral.class, "LBL_config.general.su.target")); // NOI18N + mSUTargetLBL.setToolTipText(""); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.ipadx = 5; + gridBagConstraints.ipady = 5; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(12, 2, 2, 4); + add(mSUTargetLBL, gridBagConstraints); + mSUTargetLBL.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CustomizerGeneral.class, "LBL_config.general.su.target")); // NOI18N + + mSUTargetValueLBL.setText(org.openide.util.NbBundle.getMessage(CustomizerGeneral.class, "LBL_config.general.su.target.value.unknown")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.ipadx = 5; + gridBagConstraints.ipady = 5; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new java.awt.Insets(12, 2, 2, 4); + add(mSUTargetValueLBL, gridBagConstraints); + mSUTargetValueLBL.getAccessibleContext().setAccessibleName(""); + + mSUNameLBL.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); + mSUNameLBL.setLabelFor(mSUNameTF); + mSUNameLBL.setText(org.openide.util.NbBundle.getMessage(CustomizerGeneral.class, "LBL_config.general.su.name")); // NOI18N + mSUNameLBL.setToolTipText(""); + mSUNameLBL.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.ipadx = 5; + gridBagConstraints.ipady = 5; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 4); + add(mSUNameLBL, gridBagConstraints); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 1; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.ipadx = 5; + gridBagConstraints.ipady = 5; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 4); + add(mSUNameTF, gridBagConstraints); + + mSUDescriptionLBL.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); + mSUDescriptionLBL.setText(org.openide.util.NbBundle.getMessage(CustomizerGeneral.class, "LBL_config.general.su.desc")); // NOI18N + mSUDescriptionLBL.setToolTipText(""); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.ipadx = 5; + gridBagConstraints.ipady = 5; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 4); + add(mSUDescriptionLBL, gridBagConstraints); + + mSUDescriptionScrollPane.setPreferredSize(new java.awt.Dimension(4, 40)); + + mSUDescriptionTA.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N + mSUDescriptionTA.setMargin(new java.awt.Insets(1, 1, 1, 1)); + mSUDescriptionScrollPane.setViewportView(mSUDescriptionTA); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 2; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.ipadx = 5; + gridBagConstraints.ipady = 5; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 4); + add(mSUDescriptionScrollPane, gridBagConstraints); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 5; + gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; + gridBagConstraints.weighty = 1.0; + add(mFillLBL, gridBagConstraints); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel mFillLBL; + private javax.swing.JLabel mSUDescriptionLBL; + private javax.swing.JScrollPane mSUDescriptionScrollPane; + private javax.swing.JTextArea mSUDescriptionTA; + private javax.swing.JLabel mSUNameLBL; + private javax.swing.JTextField mSUNameTF; + private javax.swing.JLabel mSUTargetLBL; + private javax.swing.JLabel mSUTargetValueLBL; + // End of variables declaration//GEN-END:variables + + private void setDocumentText(Document doc, String text) { + try { + doc.remove(0, doc.getLength()); + doc.insertString(0, text, null); + } catch (BadLocationException ex) { + ex.printStackTrace(); + // ingore + } + } + + private String getDocumentText(Document doc) { + try { + return doc.getText(0, doc.getLength()); + } catch (BadLocationException ex) { + ex.printStackTrace(); + return ""; + } + } + + private void initTargetComponent(Document doc) { + String targetComp = getDocumentText(doc); + this.mSUTargetValueLBL.setText(targetComp); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/CustomizerPackage.form b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/CustomizerPackage.form new file mode 100644 index 000000000..7d688a980 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/CustomizerPackage.form @@ -0,0 +1,117 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/CustomizerPackage.java b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/CustomizerPackage.java new file mode 100644 index 000000000..a99cca3f3 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/CustomizerPackage.java @@ -0,0 +1,114 @@ +/* + * CustomizerPackage + */ +package net.openesb.component.${artifactId}.project.customizer; + +import javax.swing.JPanel; +import org.openide.util.HelpCtx; + +/** + * Customizer for general project attributes. + * + * @author chikkala + */ +public class CustomizerPackage extends JPanel implements HelpCtx.Provider { + + private SEPluginProjectCustomizerModel uiModel; + + public CustomizerPackage(SEPluginProjectCustomizerModel uiModel) { + this.uiModel = uiModel; + initComponents(); + + mZipFileTF.setDocument(uiModel.getSUZipModel()); + mExcludesTF.setDocument(uiModel.getBuildFilesExcludesModel()); + + uiModel.getJarCompressModel().setMnemonic(mCompressChkBox.getMnemonic()); + mCompressChkBox.setModel(uiModel.getJarCompressModel()); + } + + public HelpCtx getHelpCtx() { + return new HelpCtx(CustomizerPackage.class); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + mZipFileLBL = new javax.swing.JLabel(); + mZipFileTF = new javax.swing.JTextField(); + mExcludesLBL = new javax.swing.JLabel(); + mExcludesTF = new javax.swing.JTextField(); + mCompressChkBox = new javax.swing.JCheckBox(); + mExcludeMessageLBL = new javax.swing.JLabel(); + + setLayout(new java.awt.GridBagLayout()); + + mZipFileLBL.setLabelFor(mZipFileTF); + org.openide.awt.Mnemonics.setLocalizedText(mZipFileLBL, org.openide.util.NbBundle.getMessage(CustomizerPackage.class, "LBL_config.package.su.zip")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 12); + add(mZipFileLBL, gridBagConstraints); + + mZipFileTF.setEditable(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + add(mZipFileTF, gridBagConstraints); + mZipFileTF.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(CustomizerPackage.class).getString("AD_jTextFieldDistDir")); // NOI18N + + mExcludesLBL.setLabelFor(mExcludesTF); + org.openide.awt.Mnemonics.setLocalizedText(mExcludesLBL, org.openide.util.NbBundle.getMessage(CustomizerPackage.class, "LBL_config.package.build.files.exludes")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12); + add(mExcludesLBL, gridBagConstraints); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.weightx = 1.0; + add(mExcludesTF, gridBagConstraints); + mExcludesTF.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(CustomizerPackage.class).getString("AD_jTextFieldExcludes")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(mCompressChkBox, org.openide.util.NbBundle.getMessage(CustomizerPackage.class, "CHKB_config.package.jar.compress")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 3; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weighty = 1.0; + add(mCompressChkBox, gridBagConstraints); + mCompressChkBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(CustomizerPackage.class).getString("AD_jCheckBoxCompress")); // NOI18N + + mExcludeMessageLBL.setLabelFor(mExcludesTF); + org.openide.awt.Mnemonics.setLocalizedText(mExcludeMessageLBL, org.openide.util.NbBundle.getBundle(CustomizerPackage.class).getString("LBL_config.package.build.files.exludes.message")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 2; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0); + add(mExcludeMessageLBL, gridBagConstraints); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox mCompressChkBox; + private javax.swing.JLabel mExcludeMessageLBL; + private javax.swing.JLabel mExcludesLBL; + private javax.swing.JTextField mExcludesTF; + private javax.swing.JLabel mZipFileLBL; + private javax.swing.JTextField mZipFileTF; + // End of variables declaration//GEN-END:variables +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/SEPluginProjectCustomizerModel.java b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/SEPluginProjectCustomizerModel.java new file mode 100644 index 000000000..0da2f2a5a --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/SEPluginProjectCustomizerModel.java @@ -0,0 +1,125 @@ +/* + * SEPluginProjectCustomizerModel.java + * + */ +package net.openesb.component.${artifactId}.project.customizer; + +import java.io.IOException; +import javax.swing.ButtonModel; +import javax.swing.text.Document; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectManager; +import net.openesb.component.${artifactId}.project.SEPluginProjectProperties; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.netbeans.spi.project.support.ant.ReferenceHelper; +import org.netbeans.spi.project.support.ant.ui.StoreGroup; +import org.openide.ErrorManager; +import org.openide.filesystems.FileObject; +import org.openide.util.Mutex; +import org.openide.util.MutexException; + +/** + * + * @author chikkala + */ +public class SEPluginProjectCustomizerModel { + + private Project mProject; + private AntProjectHelper mAntPrjHelper; + private ReferenceHelper mRefHelper; + private StoreGroup mPrjPropsStore; + private Document mSUTargetModel; + private Document mSUNameModel; + private Document mSUDescModel; + private Document mSUZipModel; + private ButtonModel mSUZipCompressModel; + private Document mBuildFilesExcludesModel; + + /** + * Creates a new instance of Customizer UI Model and initializes it + */ + public SEPluginProjectCustomizerModel(Project project, AntProjectHelper antProjectHelper, ReferenceHelper refHelper) { + this.mProject = project; + this.mAntPrjHelper = antProjectHelper; + this.mRefHelper = refHelper; + this.mPrjPropsStore = new StoreGroup(); + init(); + } + + public Document getSUTargetModel() { + return this.mSUTargetModel; + } + + public Document getSUNameModel() { + return this.mSUNameModel; + } + + public Document getSUDescriptionModel() { + return this.mSUDescModel; + } + + public Document getSUZipModel() { + return this.mSUZipModel; + } + + public ButtonModel getJarCompressModel() { + return this.mSUZipCompressModel; + } + + public Document getBuildFilesExcludesModel() { + return this.mBuildFilesExcludesModel; + } + + /** + * Initializes the visual models + */ + private void init() { + // initialize visual models from project properties + PropertyEvaluator evaluator = this.mAntPrjHelper.getStandardPropertyEvaluator(); + // cutomizer-general + this.mSUTargetModel = this.mPrjPropsStore.createStringDocument(evaluator, SEPluginProjectProperties.JBI_SU_TARGET_NAME); + this.mSUNameModel = this.mPrjPropsStore.createStringDocument(evaluator, SEPluginProjectProperties.JBI_SU_NAME); + this.mSUDescModel = this.mPrjPropsStore.createStringDocument(evaluator, SEPluginProjectProperties.JBI_SU_DESCRIPTION); + // customizer-package + this.mSUZipModel = this.mPrjPropsStore.createStringDocument(evaluator, SEPluginProjectProperties.JBI_SU_ZIP); + this.mSUZipCompressModel = this.mPrjPropsStore.createToggleButtonModel(evaluator, SEPluginProjectProperties.JAR_COMPRESS); + this.mBuildFilesExcludesModel = this.mPrjPropsStore.createStringDocument(evaluator, SEPluginProjectProperties.BUILD_FILES_EXCLUDES); + } + + /** + * Save visual models to project properties and other metadata + */ + public void save() { + + try { + // Store properties + @SuppressWarnings("unchecked") + Boolean result = (Boolean) ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() { + final FileObject projectDir = mAntPrjHelper.getProjectDirectory(); + + public Object run() throws IOException { + //TODO: regenreate any project build script and project metadata if required. + // store project properties. + storeProperties(); + return Boolean.TRUE; + } + }); + // and save project if required. + if (result == Boolean.TRUE) { + ProjectManager.getDefault().saveProject(mProject); + } + } catch (MutexException e) { + ErrorManager.getDefault().notify((IOException) e.getException()); + } catch (IOException ex) { + ErrorManager.getDefault().notify(ex); + } + + } + + private void storeProperties() throws IOException { + EditableProperties projectProperties = mAntPrjHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + this.mPrjPropsStore.store(projectProperties); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/SEPluginProjectCustomizerProvider.java b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/SEPluginProjectCustomizerProvider.java new file mode 100644 index 000000000..124e39f28 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/customizer/SEPluginProjectCustomizerProvider.java @@ -0,0 +1,230 @@ +/* + * SEPluginProjectCustomizerProvider.java + * + */ +package net.openesb.component.${artifactId}.project.customizer; + +import java.awt.Dialog; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.ResourceBundle; +import javax.swing.JComponent; +import javax.swing.JPanel; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectUtils; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.ReferenceHelper; +import org.netbeans.spi.project.ui.CustomizerProvider; +import org.netbeans.spi.project.ui.support.ProjectCustomizer; +import org.openide.util.NbBundle; + +/** + * + * @author chikkala + */ +public class SEPluginProjectCustomizerProvider implements CustomizerProvider { + + // Option indexes + private static final int OPTION_OK = 0; + private static final int OPTION_CANCEL = OPTION_OK + 1; + // Option command names + private static final String COMMAND_OK = "OK"; // NOI18N + private static final String COMMAND_CANCEL = "CANCEL"; // NOI18N + // Categories + private static final String GENERAL = "General"; // NOI18N + private static final String BUILD_CATEGORIES = "Build"; // NOI18N + private static final String COMPILE = "Compile"; // NOI18N + private static final String PACKAGE = "Package"; // NOI18N + private Project project; + private AntProjectHelper antProjectHelper; + private ReferenceHelper refHelper; + private SEPluginProjectCustomizerModel uiModel; + private List categories; + private ProjectCustomizer.CategoryComponentProvider panelProvider; + private static Map project2Dialog = new HashMap(); + + public SEPluginProjectCustomizerProvider(Project project, AntProjectHelper antProjectHelper, ReferenceHelper refHelper) { + this.project = project; + this.refHelper = refHelper; + this.antProjectHelper = antProjectHelper; + } + + public void showCustomizer() { + showCustomizer(null); + } + + public void showCustomizer(String preselectedCategory) { + showCustomizer(preselectedCategory, null); + } + + public void showCustomizer(String preselectedCategory, String preselectedSubCategory) { + + Dialog dialog = project2Dialog.get(project); + if (dialog != null) { + dialog.setVisible(true); + return; + } else { + SEPluginProjectCustomizerModel model = new SEPluginProjectCustomizerModel(project, antProjectHelper, refHelper); + init(model); + + OptionListener listener = new OptionListener(project, uiModel); + + if (preselectedCategory != null && preselectedSubCategory != null) { + for (ProjectCustomizer.Category category : categories) { + if (preselectedCategory.equals(category.getName())) { + JComponent component = panelProvider.create(category); + if (component instanceof SubCategoryProvider) { + ((SubCategoryProvider) component).showSubCategory(preselectedSubCategory); + } + break; + } + } + } + dialog = ProjectCustomizer.createCustomizerDialog( + categories.toArray(new ProjectCustomizer.Category[categories.size()]), + panelProvider, preselectedCategory, listener, null); + dialog.addWindowListener(listener); + dialog.setTitle(MessageFormat.format(NbBundle.getMessage(SEPluginProjectCustomizerProvider.class, "LBL_Customizer_Title"), new Object[]{ProjectUtils.getInformation(project).getDisplayName()})); + + project2Dialog.put(project, dialog); + dialog.setVisible(true); + } + } + + private void init(SEPluginProjectCustomizerModel uiModel) { + + this.uiModel = uiModel; + categories = new ArrayList(); + panelProvider = new PanelProvider(createCategoriesMap()); + } + + /** + * Getter for categories + */ + protected List getCategories() { + return categories; + } + + /** + * This api is called when showCustomizer is invoked and if customizer + * provider is not fully initialized. The default implementation creates + * Project Reference and XML Catalog Categories. Subclasses can override + * this and may or may not call super depending upon, the categories are + * desired in project customizer. + */ + protected Map createCategoriesMap() { + + ResourceBundle bundle = NbBundle.getBundle(SEPluginProjectCustomizerProvider.class); + + ProjectCustomizer.Category generalNode = ProjectCustomizer.Category.create( + GENERAL, + bundle.getString("LBL_Config_General"), // NOI18N + null, + (ProjectCustomizer.Category[]) null); + ProjectCustomizer.Category packageNode = ProjectCustomizer.Category.create( + PACKAGE, + bundle.getString("LBL_Config_Package"), // NOI18N + null, + (ProjectCustomizer.Category[]) null); + /* //TODO: add new category if required + ProjectCustomizer.Category compileNode = ProjectCustomizer.Category.create( + COMPILE, + bundle.getString( "LBL_Config_Compile" ), // NOI18N + null, + (ProjectCustomizer.Category[])null); + */ + ProjectCustomizer.Category[] buildCategories = new ProjectCustomizer.Category[]{packageNode}; + // TODO: add other categories to build if required. + // buildCategories = new ProjectCustomizer.Category[] {compileNode, packageNode }; + ProjectCustomizer.Category buildCategoriesNode = ProjectCustomizer.Category.create( + BUILD_CATEGORIES, + bundle.getString("LBL_Config_BuildCategories"), // NOI18N + null, + buildCategories); + + getCategories().add(generalNode); + getCategories().add(buildCategoriesNode); + + Map panels = + new HashMap(); + + panels.put(generalNode, new CustomizerGeneral(uiModel)); + panels.put(packageNode, new CustomizerPackage(uiModel)); + // panels.put(compileNode, new CustomizerCompile(uiModel)); + + return panels; + } + + /** + * CategoryComponentProvider provider class. It stores categories and there + * corresponding UI in a map. An instance of PanelProvider is stored in + * CustomizerProviderImpl instance + */ + private static class PanelProvider implements ProjectCustomizer.CategoryComponentProvider { + + private JPanel EMPTY_PANEL = new JPanel(); + private Map panels; + + PanelProvider(Map panels) { + this.panels = panels; + } + + public JComponent create(ProjectCustomizer.Category category) { + JComponent panel = panels.get(category); + return panel == null ? EMPTY_PANEL : panel; + } + } + + /** + * Listens to the actions on the Customizer's option buttons + */ + private class OptionListener extends WindowAdapter implements ActionListener { + + private Project project; + private SEPluginProjectCustomizerModel uiModel; + + OptionListener(Project project, SEPluginProjectCustomizerModel uiModel) { + this.project = project; + this.uiModel = uiModel; + } + + // Listening to OK button ---------------------------------------------- + public void actionPerformed(ActionEvent e) { + // Store the properties into project + this.uiModel.save(); + // Close & dispose the the dialog + Dialog dialog = project2Dialog.get(project); + if (dialog != null) { + dialog.setVisible(false); + dialog.dispose(); + } + } + + // Listening to window events ------------------------------------------ + public void windowClosed(WindowEvent e) { + project2Dialog.remove(project); + } + + public void windowClosing(WindowEvent e) { + //Dispose the dialog otherwsie the {@link WindowAdapter#windowClosed} + //may not be called + Dialog dialog = project2Dialog.get(project); + if (dialog != null) { + dialog.setVisible(false); + dialog.dispose(); + } + } + } + + public static interface SubCategoryProvider { + + public void showSubCategory(String name); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/node/Bundle.properties b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/node/Bundle.properties new file mode 100644 index 000000000..aacefb0e0 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/node/Bundle.properties @@ -0,0 +1,16 @@ +LBL_Fix_Broken_Links_Action=Resolve Reference Problems... + +#Actions +LBL_CleanAction_Name=Clean Project +LBL_BuildAction_Name=Build Project +LBL_RebuildAction_Name=Clean and Build Project +LBL_RunAction_Name=Run Project +LBL_DebugAction_Name=Debug Project +LBL_JavadocAction_Name=Generate Javadoc for Project +LBL_TestAction_Name=Test Component +LBL_Properties_Action=Properties +LBL_AddProject_Action=Add Project... +LBL_AddLibrary_Action=Add Library... +LBL_AddFolder_Action=Add JAR/Folder... + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/node/SEPluginProjectNode.java b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/node/SEPluginProjectNode.java new file mode 100644 index 000000000..f756d9081 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/node/SEPluginProjectNode.java @@ -0,0 +1,350 @@ +/* + * SEPluginProjectNode.java + * + */ +package net.openesb.component.${artifactId}.project.node; + +import java.awt.event.ActionEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.ResourceBundle; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JSeparator; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectUtils; +import net.openesb.component.${artifactId}.project.SEPluginProjectProperties; +import org.netbeans.spi.java.project.support.ui.BrokenReferencesSupport; +import org.netbeans.spi.project.ActionProvider; +import org.netbeans.spi.project.SubprojectProvider; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.netbeans.spi.project.support.ant.ReferenceHelper; +import org.netbeans.spi.project.ui.support.CommonProjectActions; +import org.netbeans.spi.project.ui.support.DefaultProjectOperations; +import org.netbeans.spi.project.ui.support.ProjectSensitiveActions; +import org.openide.actions.FindAction; +import org.openide.filesystems.FileAttributeEvent; +import org.openide.filesystems.FileChangeListener; +import org.openide.filesystems.FileEvent; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileRenameEvent; +import org.openide.loaders.DataObject; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.FilterNode; +import org.openide.nodes.Node; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; +import org.openide.util.actions.SystemAction; +import org.openide.util.lookup.Lookups; + +/** + * + * @author chikkala + */ +public class SEPluginProjectNode extends AbstractNode { + + private Project project; + private AntProjectHelper helper; + private PropertyEvaluator evaluator; + private SubprojectProvider spp; + private ReferenceHelper resolver; + private Action brokenLinksAction; + private boolean broken; + + public SEPluginProjectNode(Project project, AntProjectHelper helper, PropertyEvaluator evaluator, SubprojectProvider spp, ReferenceHelper resolver) { + super(new SEPluginProjectNodeChildren(project, helper, evaluator), Lookups.singleton(project)); + setIconBaseWithExtension(SEPluginProjectProperties.SE_PLUGIN_PROJECT_ICON_PATH); + super.setName(ProjectUtils.getInformation(project).getDisplayName()); + + this.project = project; + assert project != null; + this.helper = helper; + assert helper != null; + this.evaluator = evaluator; + assert evaluator != null; + this.spp = spp; + assert spp != null; + this.resolver = resolver; + + if (hasBrokenLinks(helper, resolver)) { + broken = true; + brokenLinksAction = new BrokenLinksAction(); + } + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + // TODO: new HelpCtx("se_deploy_plugin_project_about"); // NOI18N + } + + @Override + public Action[] getActions(boolean context) { + if (context) { + return super.getActions(true); + } else { + return getAdditionalActions(); + } + } + + @Override + public boolean canRename() { + return true; + } + + @Override + public void setName(String s) { + DefaultProjectOperations.performDefaultRenameOperation(project, s); + } + + private String[] getBreakableProperties() { + String[] breakableProps = new String[0]; + return breakableProps; + } + + public boolean hasBrokenLinks(AntProjectHelper helper, ReferenceHelper resolver) { + return BrokenReferencesSupport.isBroken(helper, resolver, getBreakableProperties(), new String[]{SEPluginProjectProperties.DEFAULT_PLATFORM}); + } + + private Action[] getAdditionalActions() { + + ResourceBundle bundle = NbBundle.getBundle(SEPluginProjectNode.class); + + List actions = new ArrayList(); + + actions.add(CommonProjectActions.newFileAction()); + actions.add(null); + actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_BUILD, bundle.getString("LBL_BuildAction_Name"), null)); // NOI18N + actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_REBUILD, bundle.getString("LBL_RebuildAction_Name"), null)); // NOI18N + actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_CLEAN, bundle.getString("LBL_CleanAction_Name"), null)); // NOI18N + //TODO: add additional plugin specific actions + actions.add(null); + actions.add(CommonProjectActions.setAsMainProjectAction()); + actions.add(CommonProjectActions.openSubprojectsAction()); + actions.add(CommonProjectActions.closeProjectAction()); + actions.add(null); + actions.add(CommonProjectActions.renameProjectAction()); + actions.add(CommonProjectActions.moveProjectAction()); + actions.add(CommonProjectActions.copyProjectAction()); + actions.add(CommonProjectActions.deleteProjectAction()); + actions.add(null); + actions.add(SystemAction.get(FindAction.class)); + // add actions from layer filesystem configuration + addFromLayers(actions, "Projects/Actions"); //NOI18N + actions.add(null); + actions.add(brokenLinksAction); + actions.add(CommonProjectActions.customizeProjectAction()); + + return actions.toArray(new Action[actions.size()]); + } + + private void addFromLayers(List actions, String path) { + Lookup look = Lookups.forPath(path); + for (Object next : look.lookupAll(Object.class)) { + if (next instanceof Action) { + actions.add((Action) next); + } else if (next instanceof JSeparator) { + actions.add(null); + } + } + } + + /** + * This action is created only when project has broken references. Once + * these are resolved the action is disabled. + */ + private class BrokenLinksAction extends AbstractAction implements PropertyChangeListener { + + public BrokenLinksAction() { + evaluator.addPropertyChangeListener(this); + putValue(Action.NAME, NbBundle.getMessage(SEPluginProjectNode.class, "LBL_Fix_Broken_Links_Action")); + } + + public void actionPerformed(ActionEvent e) { + /* + BrokenReferencesSupport.showCustomizer(helper, resolver, BREAKABLE_PROPERTIES, new String[]{SEPluginProjectProperties.DEFAULT_PLATFORM}); + if (!hasBrokenLinks(helper, resolver)) { + disable(); + } + */ + // do nothing... + } + + public void propertyChange(PropertyChangeEvent evt) { + if (!broken) { + disable(); + return; + } + broken = hasBrokenLinks(helper, resolver); + if (!broken) { + disable(); + } + } + + private void disable() { + broken = false; + setEnabled(false); + evaluator.removePropertyChangeListener(this); + fireIconChange(); + fireOpenedIconChange(); + } + } + + private static final class SEPluginProjectNodeChildren extends Children.Keys implements FileChangeListener { + + private static final String KEY_SU_JBI_XML = "SU_JBI_XML_Key"; // NOI18N + private static final String KEY_SOURCE_DIR = "SourceDirKey"; // NOI18N + private Project project; + private AntProjectHelper helper; + private PropertyEvaluator evaluator; + + public SEPluginProjectNodeChildren(Project project, AntProjectHelper helper, PropertyEvaluator evaluator) { + this.project = project; + assert project != null; + this.helper = helper; + assert helper != null; + this.evaluator = evaluator; + assert evaluator != null; + } + + private FileObject getSourceFolder() { + String srcDir = helper.getStandardPropertyEvaluator().getProperty(SEPluginProjectProperties.SRC_DIR); // NOI18N + return helper.resolveFileObject(srcDir); + } + + private FileObject getJbiXml(FileObject srcDirFO) { + FileObject jbiXmlFO = null; + if (srcDirFO == null) { + return null; + } + jbiXmlFO = srcDirFO.getFileObject(SEPluginProjectProperties.SU_JBI_XML_PATH); + if (jbiXmlFO == null) { + // create default jbi.xml + try { + jbiXmlFO = SEPluginProjectProperties.createDefaultSUDescriptor(srcDirFO); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + return jbiXmlFO; + } + + @Override + @SuppressWarnings("unchecked") + protected void addNotify() { + super.addNotify(); + FileObject projectDirFO = project.getProjectDirectory(); + if (projectDirFO != null) { + projectDirFO.addFileChangeListener(this); + } + FileObject srcDirFO = getSourceFolder(); + if (srcDirFO != null) { + srcDirFO.addFileChangeListener(this); + } + setKeys(getKeys()); + } + + @Override + @SuppressWarnings("unchecked") + protected void removeNotify() { + + setKeys(Collections.emptySet()); + + FileObject projectDirFO = project.getProjectDirectory(); + if (projectDirFO != null) { + projectDirFO.removeFileChangeListener(this); + } + FileObject srcDirFO = getSourceFolder(); + if (srcDirFO != null) { + srcDirFO.removeFileChangeListener(this); + } + + super.removeNotify(); + } + + private Collection getKeys() { + //when the project is deleted externally do not try to create children, the source groups + //are not valid + if (project.getProjectDirectory() == null || !project.getProjectDirectory().isValid()) { + return Collections.emptyList(); + } + + List result = new ArrayList(); + + FileObject srcDirFO = null; + FileObject jbiXmlFO = null; + + srcDirFO = getSourceFolder(); + if (srcDirFO != null) { + jbiXmlFO = getJbiXml(srcDirFO); + } + if (jbiXmlFO != null) { + result.add(KEY_SU_JBI_XML); + } + + if (srcDirFO != null) { + result.add(KEY_SOURCE_DIR); + } + + //TODO: add any other top level node keys here. + return result; + } + + protected Node createNode(FileObject fo) { + try { + DataObject dataObj = DataObject.find(fo); + return new FilterNode(dataObj.getNodeDelegate()); + } catch (Exception ex) { + return null; + } + } + + protected Node[] createNodes(Object key) { + List newNodes = new ArrayList(); + if (KEY_SU_JBI_XML.equals(key)) { + FileObject srcDirFO = getSourceFolder(); + FileObject jbiXmlFO = getJbiXml(srcDirFO); + newNodes.add(createNode(jbiXmlFO)); + } else if (KEY_SOURCE_DIR.equals(key)) { + FileObject srcDirFO = getSourceFolder(); + newNodes.add(createNode(srcDirFO)); + } + return newNodes.toArray(new Node[newNodes.size()]); + } + + @SuppressWarnings("unchecked") + public void fileFolderCreated(FileEvent evt) { + setKeys(getKeys()); + } + + @SuppressWarnings("unchecked") + public void fileDataCreated(FileEvent evt) { + setKeys(getKeys()); + } + + public void fileChanged(FileEvent evt) { + + } + + @SuppressWarnings("unchecked") + public void fileDeleted(FileEvent evt) { + setKeys(getKeys()); + } + + @SuppressWarnings("unchecked") + public void fileRenamed(FileRenameEvent evt) { + setKeys(getKeys()); + } + + public void fileAttributeChanged(FileAttributeEvent evt) { + + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/resources/build-impl.xsl b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/resources/build-impl.xsl new file mode 100644 index 000000000..9adad65fd --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/resources/build-impl.xsl @@ -0,0 +1,208 @@ + + + + + + + + + + + + + + + default + .. + + + jar + Build whole project. + + + + ====================== + INITIALIZATION SECTION + ====================== + + + + Empty placeholder for easier customization. + You can override this target in the ../build.xml file. + + + + -pre-init + + + + + -pre-init,-init-private + + + + + -pre-init,-init-private,-init-user + + + + + -pre-init,-init-private,-init-user,-init-project + + + + + Empty placeholder for easier customization. + You can override this target in the ../build.xml file. + + + + -pre-init,-init-private,-init-user,-init-project,-do-init + Must set src.dir + Must set build.dir + Must set jbi.su.name + Must set jbi.su.zip + + + + -pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check + + + + =================== + COMPILATION SECTION + =================== + + + + init + + + + + Empty placeholder for easier customization. + You can override this target in the ../build.xml file. + + + + init,-pre-pre-compile,-pre-compile + + + + + + + + + + Empty placeholder for easier customization. + You can override this target in the ../build.xml file. + + + + init,-pre-pre-compile,-pre-compile,-do-compile,-post-compile + Compile project. + + + + ==================== + JAR BUILDING SECTION + ==================== + + + + init + + + + + Empty placeholder for easier customization. + You can override this target in the ../build.xml file. + + + + init,compile,-pre-pre-jar,-pre-jar + + + + + Empty placeholder for easier customization. + You can override this target in the ../build.xml file. + + + + init,compile,-pre-jar,-do-jar,-post-jar + Build JAR. + + + + init,jar + + + + init,jar + + + + =============== + CLEANUP SECTION + =============== + + + + init + + + + + + Empty placeholder for easier customization. + You can override this target in the ../build.xml file. + + + + init,-do-clean,-post-clean + Clean build products. + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/resources/build.xsl b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/resources/build.xsl new file mode 100644 index 000000000..288568af6 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/resources/build.xsl @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + You may freely edit this file. See commented blocks below for + some examples of how to customize the build. + (If you delete it and reopen the project it will be recreated.) + + + + + + + default + . + Builds, tests, and runs the project + . + + + + + + + + + + For list of available properties check the imported + nbproject/build-impl.xml file. + + + Another way to customize the build is by overriding existing main targets. + The targets of interest are: + + -init-macrodef-javac: defines macro for javac compilation + -init-macrodef-junit: defines macro for junit execution + -init-macrodef-debug: defines macro for class debugging + -init-macrodef-java: defines macro for class execution + -do-jar-with-manifest: JAR building (if you are using a manifest) + -do-jar-without-manifest: JAR building (if you are not using a manifest) + run: execution of project + -javadoc-build: Javadoc generation + test-report: JUnit report generation + + An example of overriding the target for project execution could look like this: + + + + + + + + Notice that the overridden target depends on the jar target and not only on + the compile target as the regular run target does. Again, for a list of available + properties which you can use, check the target you are overriding in the + nbproject/build-impl.xml file. + + ]]> + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/resources/projectIcon.png b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/resources/projectIcon.png new file mode 100644 index 000000000..efb923b40 Binary files /dev/null and b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/resources/projectIcon.png differ diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/resources/se-jbi-module.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/resources/se-jbi-module.xml new file mode 100644 index 000000000..01e9ab043 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/resources/se-jbi-module.xml @@ -0,0 +1,3 @@ + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/Bundle.properties b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/Bundle.properties new file mode 100644 index 000000000..56d0f658f --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/Bundle.properties @@ -0,0 +1,9 @@ +LBL_CreateProjectStep=Name and Location + +LBL_ProjectName=Project &Name: + +LBL_ProjectLocation=Project &Location: + +LBL_ProjectFolder=Project &Folder: + +LBL_Browse=Br&owse... diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/SEPluginProjectDescription.html b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/SEPluginProjectDescription.html new file mode 100644 index 000000000..21e9e6bdc --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/SEPluginProjectDescription.html @@ -0,0 +1,8 @@ + + + + + + Service Engine deploment plugin project + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/SEPluginProjectWizardIterator.java b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/SEPluginProjectWizardIterator.java new file mode 100644 index 000000000..5da0b6429 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/SEPluginProjectWizardIterator.java @@ -0,0 +1,238 @@ +/* + * SEPluginProjectWizardIterator.java + */ +package net.openesb.component.${artifactId}.project.wizard; + +import java.awt.Component; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; +import javax.swing.JComponent; +import javax.swing.event.ChangeListener; +import net.openesb.component.${artifactId}.project.SEPluginProjectGenerator; +import net.openesb.component.${artifactId}.project.SEPluginProjectProperties; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.ui.support.ProjectChooser; +import org.netbeans.spi.project.ui.templates.support.Templates; +import org.openide.WizardDescriptor; +import org.openide.filesystems.FileLock; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.filesystems.Repository; +import org.openide.loaders.DataFolder; +import org.openide.loaders.DataObject; +import org.openide.util.NbBundle; + +public class SEPluginProjectWizardIterator implements WizardDescriptor.InstantiatingIterator { + + public final static String PROJECT_DIR = "projdir"; + public final static String PROJECT_NAME = "name"; + public final static String DEF_PROJECT_NAME_VALUE = "JBIModule"; + private int index; + private WizardDescriptor.Panel[] panels; + private WizardDescriptor wiz; + + public SEPluginProjectWizardIterator() { + } + + public static SEPluginProjectWizardIterator createIterator() { + return new SEPluginProjectWizardIterator(); + } + + private WizardDescriptor.Panel[] createPanels() { + return new WizardDescriptor.Panel[]{ + new SEPluginProjectWizardPanel() + }; + } + + private String[] createSteps() { + return new String[]{ + NbBundle.getMessage(SEPluginProjectWizardIterator.class, "LBL_CreateProjectStep") + }; + } + + public Set instantiate(/*ProgressHandle handle*/) throws IOException { + + Set resultSet = createSEDeployPluginProject(); + // save the current projects folder + File dirF = FileUtil.normalizeFile((File) wiz.getProperty(PROJECT_DIR)); + File parent = dirF.getParentFile(); + if (parent != null && parent.exists()) { + ProjectChooser.setProjectsFolder(parent); + } + return resultSet; + } + + public void initialize(WizardDescriptor wiz) { + this.wiz = wiz; + + try { + FileObject templateFO = Templates.getTemplate(wiz); + DataObject templateDO = DataObject.find(templateFO); + this.wiz.putProperty(PROJECT_NAME, templateDO.getName()); + } catch (Exception ex) { + this.wiz.putProperty(PROJECT_NAME, DEF_PROJECT_NAME_VALUE); + } + + index = 0; + panels = createPanels(); + // Make sure list of steps is accurate. + String[] steps = createSteps(); + for (int i = 0; i < panels.length; i++) { + Component c = panels[i].getComponent(); + if (steps[i] == null) { + // Default step name to component name of panel. + // Mainly useful for getting the name of the target + // chooser to appear in the list of steps. + steps[i] = c.getName(); + } + if (c instanceof JComponent) { // assume Swing components + JComponent jc = (JComponent) c; + // Step #. + jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i)); + // Step name (actually the whole list for reference). + jc.putClientProperty("WizardPanel_contentData", steps); + } + } + } + + public void uninitialize(WizardDescriptor wiz) { + this.wiz.putProperty(PROJECT_DIR, null); + this.wiz.putProperty(PROJECT_NAME, null); + this.wiz = null; + panels = null; + } + + public String name() { + return MessageFormat.format("{0} of {1}", + new Object[]{new Integer(index + 1), new Integer(panels.length)}); + } + + public boolean hasNext() { + return index < panels.length - 1; + } + + public boolean hasPrevious() { + return index > 0; + } + + public void nextPanel() { + if (!hasNext()) { + throw new NoSuchElementException(); + } + index++; + } + + public void previousPanel() { + if (!hasPrevious()) { + throw new NoSuchElementException(); + } + index--; + } + + public WizardDescriptor.Panel current() { + return panels[index]; + } + + // If nothing unusual changes in the middle of the wizard, simply: + public final void addChangeListener(ChangeListener l) { + } + + public final void removeChangeListener(ChangeListener l) { + } + + protected Set createSEDeployPluginProject() throws IOException { + + Set resultSet = new LinkedHashSet(); + + File prjDirFile = FileUtil.normalizeFile((File) wiz.getProperty(PROJECT_DIR)); + String prjName = (String) wiz.getProperty(PROJECT_NAME); + + SEPluginProjectGenerator prjGenerator = new SEPluginProjectGenerator(); + AntProjectHelper h = prjGenerator.createProject(prjDirFile, prjName); + + FileObject projectDirFO = h.getProjectDirectory(); + resultSet.add(projectDirFO); + + Set defArtifacts = createProjectSpecificArtifacts(projectDirFO); + resultSet.addAll(defArtifacts); + + return resultSet; + } + + private FileObject copyResource(FileObject dirFO, String name, String resourcePath) throws IOException { + FileObject dataFO = null; + FileLock outLock = null; + OutputStream outS = null; + InputStream inS = null; + + try { + inS = this.getClass().getResourceAsStream(resourcePath); + dataFO = FileUtil.createData(dirFO, name); + outLock = dataFO.lock(); + outS = dataFO.getOutputStream(outLock); + FileUtil.copy(inS, outS); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + if (inS != null) { + try { + inS.close(); + } catch (Exception ex) { + //ingore + } + } + if (outS != null) { + try { + outS.close(); + } catch (Exception ex) { + //ingore + } + } + if (outLock != null) { + outLock.releaseLock(); + } + } + return dataFO; + } + + protected Set createProjectSpecificArtifacts(FileObject projectDirFO) throws IOException { + Set resultSet = new LinkedHashSet(); + //TODO: create any default service unit artifacts needed. + try { + + FileObject srcDirFO = projectDirFO.getFileObject(SEPluginProjectProperties.SRC_DIR_VALUE); + resultSet.add(srcDirFO); + + // create service unit jbi descriptor + FileObject metaInfDirFO = FileUtil.createFolder(srcDirFO, "META-INF"); + FileObject jbiXmlFO = copyResource(metaInfDirFO, "jbi.xml", "resources/jbi.xml"); + resultSet.add(jbiXmlFO); + + // create any service unit artifacts such as wsdl files and configuration files + + // list of su artifacts to be created from the resources directory + String[] suArtifacts = {"xsltmap.properties","goodbye.xsl","hello.xsl","Greetings.wsdl"}; + + for (String suArtifact : suArtifacts) { + FileObject suArtifactFO = copyResource(srcDirFO, suArtifact, "resources/" + suArtifact); + resultSet.add(suArtifactFO); + } + + //TODO: add any addtional default service unit artifacts here. + // FileObject suArtifactFO = copyResource(srcDirFO, "su-artifact.xml", "resources/su-artifact.xml"); + // resultSet.add(suArtifactFO); + + } catch (Exception ex) { + ex.printStackTrace(); + } + return resultSet; + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/SEPluginProjectWizardPanel.java b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/SEPluginProjectWizardPanel.java new file mode 100644 index 000000000..b742f7e67 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/SEPluginProjectWizardPanel.java @@ -0,0 +1,93 @@ +/* + * SEPluginProjectWizardPanel.java + */ +package net.openesb.component.${artifactId}.project.wizard; + +import java.awt.Component; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import org.openide.WizardDescriptor; +import org.openide.WizardValidationException; +import org.openide.util.HelpCtx; +import org.openide.util.NbBundle; + +/** + * Panel just asking for basic info. + */ +public class SEPluginProjectWizardPanel implements WizardDescriptor.Panel, + WizardDescriptor.ValidatingPanel, WizardDescriptor.FinishablePanel { + + private WizardDescriptor wizardDescriptor; + private SEPluginProjectWizardPanelVisual component; + + /** + * Creates a new instance of templateWizardPanel + */ + public SEPluginProjectWizardPanel() { + } + + public Component getComponent() { + if (component == null) { + component = new SEPluginProjectWizardPanelVisual(this); + component.setName(NbBundle.getMessage(SEPluginProjectWizardPanel.class, "LBL_CreateProjectStep")); + } + return component; + } + + public HelpCtx getHelp() { + return new HelpCtx(SEPluginProjectWizardPanel.class); + } + + public boolean isValid() { + getComponent(); + return component.valid(wizardDescriptor); + } + private final Set/**/ listeners = new HashSet(1); // or can use ChangeSupport in NB 6.0 + + @SuppressWarnings("unchecked") + public final void addChangeListener(ChangeListener l) { + synchronized (listeners) { + listeners.add(l); + } + } + + public final void removeChangeListener(ChangeListener l) { + synchronized (listeners) { + listeners.remove(l); + } + } + + @SuppressWarnings("unchecked") + protected final void fireChangeEvent() { + Iterator it; + synchronized (listeners) { + it = new HashSet(listeners).iterator(); + } + ChangeEvent ev = new ChangeEvent(this); + while (it.hasNext()) { + ((ChangeListener) it.next()).stateChanged(ev); + } + } + + public void readSettings(Object settings) { + wizardDescriptor = (WizardDescriptor) settings; + component.read(wizardDescriptor); + } + + public void storeSettings(Object settings) { + WizardDescriptor d = (WizardDescriptor) settings; + component.store(d); + } + + public boolean isFinishPanel() { + return true; + } + + public void validate() throws WizardValidationException { + getComponent(); + component.validate(wizardDescriptor); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/SEPluginProjectWizardPanelVisual.form b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/SEPluginProjectWizardPanelVisual.form new file mode 100644 index 000000000..b3238405d --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/SEPluginProjectWizardPanelVisual.form @@ -0,0 +1,120 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/SEPluginProjectWizardPanelVisual.java b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/SEPluginProjectWizardPanelVisual.java new file mode 100644 index 000000000..d16d84ddb --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/SEPluginProjectWizardPanelVisual.java @@ -0,0 +1,259 @@ +/* + * SEPluginProjectWizardPanelVisual.java + */ +package net.openesb.component.${artifactId}.project.wizard; + +import java.io.File; +import javax.swing.JFileChooser; +import javax.swing.JPanel; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.text.Document; +import org.netbeans.spi.project.ui.support.ProjectChooser; +import org.openide.WizardDescriptor; +import org.openide.WizardValidationException; +import org.openide.filesystems.FileUtil; + +public class SEPluginProjectWizardPanelVisual extends JPanel implements DocumentListener { + + public static final String PROP_PROJECT_NAME = "projectName"; + private SEPluginProjectWizardPanel panel; + + public SEPluginProjectWizardPanelVisual(SEPluginProjectWizardPanel panel) { + initComponents(); + this.panel = panel; + // Register listener on the textFields to make the automatic updates + projectNameTextField.getDocument().addDocumentListener(this); + projectLocationTextField.getDocument().addDocumentListener(this); + } + + public String getProjectName() { + return this.projectNameTextField.getText(); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + projectNameLabel = new javax.swing.JLabel(); + projectNameTextField = new javax.swing.JTextField(); + projectLocationLabel = new javax.swing.JLabel(); + projectLocationTextField = new javax.swing.JTextField(); + browseButton = new javax.swing.JButton(); + createdFolderLabel = new javax.swing.JLabel(); + createdFolderTextField = new javax.swing.JTextField(); + + projectNameLabel.setLabelFor(projectNameTextField); + org.openide.awt.Mnemonics.setLocalizedText(projectNameLabel, org.openide.util.NbBundle.getMessage(SEPluginProjectWizardPanelVisual.class, "LBL_ProjectName")); // NOI18N + + projectLocationLabel.setLabelFor(projectLocationTextField); + org.openide.awt.Mnemonics.setLocalizedText(projectLocationLabel, org.openide.util.NbBundle.getMessage(SEPluginProjectWizardPanelVisual.class, "LBL_ProjectLocation")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(SEPluginProjectWizardPanelVisual.class, "LBL_Browse")); // NOI18N + browseButton.setActionCommand("BROWSE"); + browseButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + browseButtonActionPerformed(evt); + } + }); + + createdFolderLabel.setLabelFor(createdFolderTextField); + org.openide.awt.Mnemonics.setLocalizedText(createdFolderLabel, org.openide.util.NbBundle.getMessage(SEPluginProjectWizardPanelVisual.class, "LBL_ProjectFolder")); // NOI18N + + createdFolderTextField.setEditable(false); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(projectNameLabel) + .add(projectLocationLabel) + .add(createdFolderLabel)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, projectNameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.TRAILING, projectLocationTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.TRAILING, createdFolderTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(browseButton) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(projectNameLabel) + .add(projectNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(projectLocationLabel) + .add(projectLocationTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(browseButton)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(createdFolderLabel) + .add(createdFolderTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(213, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + + private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed + String command = evt.getActionCommand(); + if ("BROWSE".equals(command)) { + JFileChooser chooser = new JFileChooser(); + FileUtil.preventFileChooserSymlinkTraversal(chooser, null); + chooser.setDialogTitle("Select Project Location"); + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + String path = this.projectLocationTextField.getText(); + if (path.length() > 0) { + File f = new File(path); + if (f.exists()) { + chooser.setSelectedFile(f); + } + } + if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { + File projectDir = chooser.getSelectedFile(); + projectLocationTextField.setText(FileUtil.normalizeFile(projectDir).getAbsolutePath()); + } + panel.fireChangeEvent(); + } + + }//GEN-LAST:event_browseButtonActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton browseButton; + private javax.swing.JLabel createdFolderLabel; + private javax.swing.JTextField createdFolderTextField; + private javax.swing.JLabel projectLocationLabel; + private javax.swing.JTextField projectLocationTextField; + private javax.swing.JLabel projectNameLabel; + private javax.swing.JTextField projectNameTextField; + // End of variables declaration//GEN-END:variables + + public void addNotify() { + super.addNotify(); + //same problem as in 31086, initial focus on Cancel button + projectNameTextField.requestFocus(); + } + + boolean valid(WizardDescriptor wizardDescriptor) { + + if (projectNameTextField.getText().length() == 0) { + wizardDescriptor.putProperty("WizardPanel_errorMessage", + "Project Name is not a valid folder name."); + return false; // Display name not specified + } + File f = FileUtil.normalizeFile(new File(projectLocationTextField.getText()).getAbsoluteFile()); + if (!f.isDirectory()) { + String message = "Project Folder is not a valid path."; + wizardDescriptor.putProperty("WizardPanel_errorMessage", message); + return false; + } + final File destFolder = FileUtil.normalizeFile(new File(createdFolderTextField.getText()).getAbsoluteFile()); + + File projLoc = destFolder; + while (projLoc != null && !projLoc.exists()) { + projLoc = projLoc.getParentFile(); + } + if (projLoc == null || !projLoc.canWrite()) { + wizardDescriptor.putProperty("WizardPanel_errorMessage", + "Project Folder cannot be created."); + return false; + } + + if (FileUtil.toFileObject(projLoc) == null) { + String message = "Project Folder is not a valid path."; + wizardDescriptor.putProperty("WizardPanel_errorMessage", message); + return false; + } + + File[] kids = destFolder.listFiles(); + if (destFolder.exists() && kids != null && kids.length > 0) { + // Folder exists and is not empty + wizardDescriptor.putProperty("WizardPanel_errorMessage", + "Project Folder already exists and is not empty."); + return false; + } + wizardDescriptor.putProperty("WizardPanel_errorMessage", ""); + return true; + } + + void store(WizardDescriptor d) { + String name = projectNameTextField.getText().trim(); + String folder = createdFolderTextField.getText().trim(); + + d.putProperty("projdir", new File(folder)); + d.putProperty("name", name); + } + + void read(WizardDescriptor settings) { + File projectLocation = (File) settings.getProperty(SEPluginProjectWizardIterator.PROJECT_DIR); + if (projectLocation == null || projectLocation.getParentFile() == null || !projectLocation.getParentFile().isDirectory()) { + projectLocation = ProjectChooser.getProjectsFolder(); + } else { + projectLocation = projectLocation.getParentFile(); + } + this.projectLocationTextField.setText(projectLocation.getAbsolutePath()); + + String projectName = (String) settings.getProperty(SEPluginProjectWizardIterator.PROJECT_NAME); + if (projectName == null) { + projectName = SEPluginProjectWizardIterator.DEF_PROJECT_NAME_VALUE; + } + this.projectNameTextField.setText(projectName); + this.projectNameTextField.selectAll(); + } + + void validate(WizardDescriptor d) throws WizardValidationException { + // nothing to validate + } + + // Implementation of DocumentListener -------------------------------------- + public void changedUpdate(DocumentEvent e) { + updateTexts(e); + if (this.projectNameTextField.getDocument() == e.getDocument()) { + firePropertyChange(PROP_PROJECT_NAME, null, this.projectNameTextField.getText()); + } + } + + public void insertUpdate(DocumentEvent e) { + updateTexts(e); + if (this.projectNameTextField.getDocument() == e.getDocument()) { + firePropertyChange(PROP_PROJECT_NAME, null, this.projectNameTextField.getText()); + } + } + + public void removeUpdate(DocumentEvent e) { + updateTexts(e); + if (this.projectNameTextField.getDocument() == e.getDocument()) { + firePropertyChange(PROP_PROJECT_NAME, null, this.projectNameTextField.getText()); + } + } + + /** + * Handles changes in the Project name and project directory, + */ + private void updateTexts(DocumentEvent e) { + + Document doc = e.getDocument(); + + if (doc == projectNameTextField.getDocument() || doc == projectLocationTextField.getDocument()) { + // Change in the project name + + String projectName = projectNameTextField.getText(); + String projectFolder = projectLocationTextField.getText(); + + //if (projectFolder.trim().length() == 0 || projectFolder.equals(oldName)) { + createdFolderTextField.setText(projectFolder + File.separatorChar + projectName); + //} + + } + panel.fireChangeEvent(); // Notify that the panel changed + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/resources/Greetings.wsdl b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/resources/Greetings.wsdl new file mode 100644 index 000000000..756417abf --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/resources/Greetings.wsdl @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/resources/goodbye.xsl b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/resources/goodbye.xsl new file mode 100644 index 000000000..3259f2f3a --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/resources/goodbye.xsl @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + Goodbye + ! Have a great time. + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/resources/hello.xsl b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/resources/hello.xsl new file mode 100644 index 000000000..d6794cbf8 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/resources/hello.xsl @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + Hello + ! + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/resources/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/resources/jbi.xml new file mode 100644 index 000000000..6c6757d3d --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/resources/jbi.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/resources/xsltmap.properties b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/resources/xsltmap.properties new file mode 100644 index 000000000..06e4b6631 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/project/wizard/resources/xsltmap.properties @@ -0,0 +1,28 @@ +# properties will be used to find the xslt file that will be used for invoking a +# service operation. +# The "xsltmap.properties" file should contain two types of properties +# 1. for namespace prefix to namespaceURI map that starts with "xmlns." prefix like +# "xmlns.tns-prefix=http://www.sun.com/jbi/examples/sample-service/echo" +# 2. a service description to xslt file properties with syntax like +# "{tns-prefix}service-name=xslt_file_name" and +# "{tns-prefix}service-name.{tns-prefix}operation-name=xslt_file_name" and +# "{tns-prefix}service-name.{tns-prefix}interface-name.operation-name=xslt_file_name" . +# the service description property is a "." delimited tokens that represents +# a serive or interface qname and a operation name. To locate xslt file either with +# service qname or service qname and operaton or serivice qname and interface qname +# and operation, all the three properties specified above should be there for each xslt file. +# + +xmlns.greet1=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greet2=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greettypes=http://www.sun.com/jbi/examples/sample-service/greetings/types +# just service level default settings +{greet2}greetService=hello.xsl +# service and operation +{greet2}greetService.{greet1}sayHello=hello.xsl +# service, interface, operation +{greet2}greetService.{greet1}greetings.sayHello=hello.xsl +# service and operation +{greet2}greetService.{greet1}sayGoodbye=goodbye.xsl +# service, interface, operation +{greet2}greetService.{greet1}greetings.sayGoodbye=goodbye.xsl diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/install-params.properties b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/install-params.properties new file mode 100644 index 000000000..712a6a3ac --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/install-params.properties @@ -0,0 +1,3 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/m2nbbuild-impl.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/m2nbbuild-impl.xml new file mode 100644 index 000000000..b1abf7e2e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/m2nbbuild-impl.xml @@ -0,0 +1,132 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + This project compile, package and test the JBI Components when invoked from Maven2. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/m2nbbuild.properties b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/m2nbbuild.properties new file mode 100644 index 000000000..663de1bb9 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/m2nbbuild.properties @@ -0,0 +1,48 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} build properties file to set/override the properties of the netbeans project +${symbol_pound} build properties when the netbeans build is called from the maven build lifecycle. +${symbol_pound} Netbeans project when build from the IDE, uses a build.properties from the user.dir +${symbol_pound} of the Netbeans IDE to resolve some of the properties used in the project such as +${symbol_pound} the libraries classpath. +${symbol_pound} When invoking the Netbeans project build from maven, this build.properties file +${symbol_pound} is not available. So, you can add the properties defined in ide build properties +${symbol_pound} that this project uses here. +${symbol_pound} + +${symbol_pound} default local repository settings. If the repository location is different +${symbol_pound} -D command line option should override this (e.g. mvn -Dmaven.repo.local=/my/m2/repository +maven.repo.local=${symbol_dollar}{user.home}/.m2/repository +${symbol_pound} begin jbi admin settings +${symbol_pound} set the below properties if you want to override the properties from nbproject/project.properties +${symbol_pound} that sets the application server admin settings. +${symbol_pound} +${symbol_pound} jbi.as.home=C:/Sun/glassfish-v2-b58g +${symbol_pound} jbi.host=localhost +${symbol_pound} jbi.port=4848 +${symbol_pound} jbi.username=admin +${symbol_pound} jbi.password=adminadmin +${symbol_pound} end jbi admin settings +${symbol_pound} + +${symbol_pound} classpath settings +junit.ant.task.classpath=${symbol_dollar}{maven.repo.local}/ant/ant-junit/1.6.5/ant-junit-1.6.5.jar +junit.runtime.classpath=${symbol_dollar}{maven.repo.local}/junit/junit/3.8.2/junit-3.8.2.jar +libs.junit.classpath=${symbol_dollar}{junit.runtime.classpath}:${symbol_dollar}{junit.ant.task.classpath} +libs.jbi-cdk-ant-tasks.classpath=${symbol_dollar}{maven.repo.local}/open-esb/jbi-cdk/jbi-cdk-ant-tasks/${version}/jbi-cdk-ant-tasks-${version}.jar + +libs.jbi.classpath=${symbol_dollar}{maven.repo.local}/open-esb/jbi/1.0/jbi-1.0.jar +libs.wsdl4j.162.classpath=${symbol_dollar}{maven.repo.local}/wsdl4j/wsdl4j/1.6.2/wsdl4j-1.6.2.jar +${symbol_pound} libs.jaxws21.classpath=${symbol_dollar}{jbi.as.home}/lib/javaee.jar:${symbol_dollar}{jbi.as.home}/lib/webservices-rt.jar +libs.jaxws21.classpath=${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/activation/activation/1.1/activation-1.1.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/xml/soap/saaj-api/1.3/saaj-api-1.3.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/xml/ws/jaxws-api/2.1/jaxws-api-2.1.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/com/sun/xml/messaging/saaj/saaj-impl/1.3/saaj-impl-1.3.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/com/sun/xml/ws/jaxws-rt/2.1.2/jaxws-rt-2.1.2.jar + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/m2nbbuild.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/m2nbbuild.xml new file mode 100644 index 000000000..31217d15d --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/m2nbbuild.xml @@ -0,0 +1,37 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + This project compile, package and test the JBI Components when invoked from Maven2. + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/build-impl.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/build-impl.xml new file mode 100644 index 000000000..89775b186 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/build-impl.xml @@ -0,0 +1,574 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Inside: postArchTypeGen - Post task is getting executed! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Inside: postArchTypeGen - Post task executed successfully! + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/genfiles.properties b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/genfiles.properties new file mode 100644 index 000000000..4972e19f9 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/genfiles.properties @@ -0,0 +1,11 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +build.xml.data.CRC32=d291c685 +build.xml.script.CRC32=5eca2350 +build.xml.stylesheet.CRC32=8add101f@1.0 +${symbol_pound} This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +${symbol_pound} Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=d291c685 +nbproject/build-impl.xml.script.CRC32=e3f75085 +nbproject/build-impl.xml.stylesheet.CRC32=4ed53ee0@1.0 diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/jbi_admin.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/jbi_admin.xml new file mode 100644 index 000000000..1d5833c62 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/jbi_admin.xml @@ -0,0 +1,504 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + +This ant script contains the jbi ant tasks and the targets and properties using +which the jbi admin commands can be performed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Usage : ant -f <fullpath>/jbi_admin.xml [options] [target] + options: -D<property>=<value> + Specify a property/value pairs as options that are valid for the target. + target : ant target name in jbi_admin.xml + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/jbiadmin-impl.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/jbiadmin-impl.xml new file mode 100644 index 000000000..7e7dca2ae --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/jbiadmin-impl.xml @@ -0,0 +1,339 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + Install, uninstall, reinstall, start, stop, shutdown jbi components. + + + + + + + + + + + + + + Must set jbi.host + Must set jbi.port + Must set jbi.username + Must set jbi.password + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/private/private.properties b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/private/private.properties new file mode 100644 index 000000000..e540325d5 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/private/private.properties @@ -0,0 +1,6 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +javac.debug=true +javadoc.preview=true +user.properties.file=D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working57${symbol_escape}${symbol_escape}.netbeans${symbol_escape}${symbol_escape}openesb${symbol_escape}${symbol_escape}build.properties diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/private/retriever/catalog.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/private/retriever/catalog.xml new file mode 100644 index 000000000..712a6a3ac --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/private/retriever/catalog.xml @@ -0,0 +1,3 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/project.properties b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/project.properties new file mode 100644 index 000000000..0822a9f0e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/project.properties @@ -0,0 +1,91 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +build.classes.dir=${symbol_dollar}{build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +${symbol_pound} This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${symbol_dollar}{build.dir}/generated +build.predist.dir=${symbol_dollar}{build.dir}/predist +build.predist.jar=${symbol_dollar}{build.predist.dir}/component.jar +build.predist.lib.dir=${symbol_dollar}{build.predist.dir}/lib +${symbol_pound} Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${symbol_dollar}{build.dir}/test/classes +build.test.dir=${symbol_dollar}{build.dir}/test +build.test.results.dir=${symbol_dollar}{build.dir}/test/results +conf.dir=src/conf +debug.classpath=${symbol_escape} + ${symbol_dollar}{run.classpath} +debug.test.classpath=${symbol_escape} + ${symbol_dollar}{run.test.classpath} +${symbol_pound} This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${symbol_dollar}{dist.dir}/${artifactId}.zip +dist.javadoc.dir=${symbol_dollar}{dist.dir}/javadoc +jar.compress=false +javac.classpath=${symbol_escape} + ${symbol_dollar}{libs.jbi.classpath}:${symbol_escape} + ${symbol_dollar}{jbi.component.sharedlibs.classpath}:${symbol_escape} + ${symbol_dollar}{jbi.component.lib.classpath} +${symbol_pound} Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.6 +javac.target=1.6 +javac.test.classpath=${symbol_escape} + ${symbol_dollar}{javac.classpath}:${symbol_escape} + ${symbol_dollar}{build.classes.dir}:${symbol_escape} + ${symbol_dollar}{libs.junit.classpath}:${symbol_escape} + ${symbol_dollar}{libs.jaxws21.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +jbi.ant.tasks.classpath=${symbol_escape} + ${symbol_dollar}{jbi.as.home}/lib/sun-appserv-ant.jar:${symbol_escape} + ${symbol_dollar}{jbi.as.home}/jbi/lib/jbi-ant-tasks.jar +jbi.as.home=D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working53${symbol_escape}${symbol_escape}glassfish +jbi.as.instance.id=[D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working53${symbol_escape}${symbol_escape}glassfish]deployer:Sun:AppServer::localhost:4848 +jbi.component.bootstrap.class=serviceengine.ProviderSEInstaller +jbi.component.class=serviceengine.ProviderSERuntime +jbi.component.description=Description of service engine : ${artifactId} +jbi.component.lib.classpath=${symbol_escape} + ${symbol_dollar}{libs.wsdl4j.162.classpath} +jbi.component.name=${artifactId} +jbi.component.sharedlibs.classpath= +jbi.component.type=service-engine +jbi.host=localhost +jbi.install.params.file=install-params.properties +jbi.install.with.params=false +jbi.password=this really long string is used to identify a password that has been stored in the Keyring +jbi.port=4848 +jbi.soap.binding.name=sun-http-binding +jbi.username=admin +meta.inf.dir=${symbol_dollar}{conf.dir}/META-INF +platform.active=default_platform +project.jbi.deploy.plugin=./deploy-plugin +project.testSA=test/testSA +run.classpath=${symbol_escape} + ${symbol_dollar}{javac.classpath}:${symbol_escape} + ${symbol_dollar}{build.classes.dir} +${symbol_pound} Space-separated list of JVM arguments used when running the project +${symbol_pound} (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +${symbol_pound} or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=${symbol_escape} + ${symbol_dollar}{javac.test.classpath}:${symbol_escape} + ${symbol_dollar}{build.test.classes.dir} +src.dir=src/java +test-sys-prop.test.results.dir=${symbol_dollar}{build.test.results.dir} +test-sys-prop.test.src.dir=test-sys-prop.test.src.dir +test.src.dir=test/java +testSA.enabled=true +testSA.name=${artifactId}_TestSA diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/project.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/project.xml new file mode 100644 index 000000000..942beffad --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/nbproject/project.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + org.netbeans.modules.jbi.apisupport.project.jbicomponent + + + ${artifactId} + service-engine + 1.6.5 + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/pom.xml b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 000000000..b0d360fba --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,173 @@ + + + + 4.0.0 + ${groupId} + ${artifactId} + jar + ${version} + JBI Component[ServiceEngine] + Maven project for JBI Component that contains the + maven and netbeans build setup and component code to build and test the JBI Component. + http://open-esb.org + + build + src/java + test/java + build/classes + build/test/classes + package + + + + maven-antrun-plugin + 1.2 + + + + default-cli + + run + + + + !!!!!!!!!!!!!!!!!!!!!! Moving Files and organizing package !!!!!!!!!!!!!!!!!!!!!!!! + + + + + + + + + ant + ant-nodeps + 1.6.5 + + + ant + ant-junit + 1.6.5 + test + + + junit + junit + 3.8.2 + test + + + + + + + + + maven2-repo1 + Maven2 Central Repository + http://repo1.maven.org/maven2 + + + download-java-net-maven2-repository + download.java.net Maven 2.x repository + http://download.java.net/maven/2/ + + + maven-repository.dev.java.net-repository + https://maven-repository.dev.java.net/nonav/repository/ + legacy + + + ws-zones + ws.zones maven repository + http://ws.zones.apache.org/repository2/ + + + apache.org + Maven Snapshots + http://people.apache.org/repo/m2-snapshot-repository + + false + + + + + + + + + apache.org + Maven Plugin Snapshots + http://people.apache.org/repo/m2-snapshot-repository + + false + + + + + + + + ant + ant-nodeps + 1.6.5 + + + ant + ant-junit + 1.6.5 + test + + + junit + junit + 3.8.2 + test + + + org.apache.maven + maven-ant-tasks + 2.0.7 + + + open-esb.jbi-cdk + jbi-cdk-ant-tasks + 1.0-SNAPSHOT + + + open-esb + jbi + 1.0 + + + wsdl4j + wsdl4j + 1.6.2 + + + com.sun.xml.ws + jaxws-rt + 2.1.2 + test + + + + + ${maven.repo.local} + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/test/resources/projects/basic/archetype.properties b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/test/resources/projects/basic/archetype.properties new file mode 100644 index 000000000..84ab644c4 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/test/resources/projects/basic/archetype.properties @@ -0,0 +1,5 @@ +#Tue Jul 23 17:03:00 IST 2013 +package=it.pkg +version=0.1-SNAPSHOT +groupId=archetype.it +artifactId=basic diff --git a/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/test/resources/projects/basic/goal.txt b/maven-archtype-v2/maven-archetype-service-engine-plugin-v2/src/test/resources/projects/basic/goal.txt new file mode 100644 index 000000000..e69de29bb diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/pom.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/pom.xml new file mode 100644 index 000000000..34d356fba --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/pom.xml @@ -0,0 +1,45 @@ + + + + + + 4.0.0 + + open-jbi-components + ServiceEngine-archetype + 1.0-SNAPSHOT + maven-archetype + + ServiceEngine-archetype + + + + + org.apache.maven.archetype + archetype-packaging + 2.2 + + + + + + + maven-archetype-plugin + 2.2 + + + + + + Maven project Archtype for OpenESB Service Engine, that contains the + maven and netbeans build setup and component code to build and test the JBI Component. + + http://open-esb.org + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/META-INF/maven/archetype-metadata.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 000000000..ea7fd9335 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,82 @@ + + + + + + + + + C:\\GlassFishESBv22\\glassfish + + + + + test/java + + **/*.xml + **/*.java + **/*.properties + + + + src/java + + **/*.java + + + + test/testSA + + **/*.xml + **/*.properties + + + + nbproject + + **/*.xml + **/*.properties + + + + src/conf + + **/*.xml + + + + nbproject/private + + **/*.xml + **/*.properties + + + + test/testSA + + **/*.xsl + **/*.zip + **/*.wsdl + + + + + + build.xml + install-params.properties + m2nbbuild-impl.xml + m2nbbuild.properties + m2nbbuild.xml + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build.xml new file mode 100644 index 000000000..14afd1d29 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build.xml @@ -0,0 +1,72 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + Builds, tests, and runs the project ${artifactId}. + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/pom.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/pom.xml new file mode 100644 index 000000000..1e58b6067 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/pom.xml @@ -0,0 +1,38 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + 4.0.0 + + ${package} + ${artifactId}-archetype + ${version} + maven-archetype + + ${artifactId}-archetype + + + + + org.apache.maven.archetype + archetype-packaging + 2.2 + + + + + + + maven-archetype-plugin + 2.2 + + + + + + Maven project for JBI Component that contains the + maven and netbeans build setup and component code to build and test the JBI Component. + + http://open-esb.org + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml new file mode 100644 index 000000000..c493031be --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml @@ -0,0 +1,33 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml new file mode 100644 index 000000000..2bdebaa2b --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml @@ -0,0 +1,146 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + org.netbeans.modules.apisupport.project + + + ${symbol_dollar}{artifactId} + + + + org.apache.tools.ant.module + + + + 3 + 3.27.0.2 + + + + org.jdesktop.layout + + + + 1 + 1.4 + + + + org.netbeans.modules.java.project + + + + 1 + 1.12 + + + + org.netbeans.modules.project.ant + + + + 1 + 1.16 + + + + org.netbeans.modules.projectapi + + + + 1 + 1.13 + + + + org.netbeans.modules.projectuiapi + + + + 1 + 1.24.0.6 + + + + org.netbeans.modules.queries + + + + 1 + 1.10 + + + + org.openide.actions + + + + 6.6.0.1 + + + + org.openide.awt + + + + 6.11.0.1 + + + + org.openide.dialogs + + + + 7.5 + + + + org.openide.execution + + + + 1.10 + + + + org.openide.filesystems + + + + 7.3 + + + + org.openide.loaders + + + + 6.5 + + + + org.openide.nodes + + + + 7.2.0.1 + + + + org.openide.util + + + + 7.9.0.1 + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test1Input.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test1Input.xml new file mode 100644 index 000000000..b50d82c16 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test1Input.xml @@ -0,0 +1,18 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + Srinivasan + Chikkala + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test2Input.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test2Input.xml new file mode 100644 index 000000000..947bb579c --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test2Input.xml @@ -0,0 +1,18 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + Srinivasan + Chikkala + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/build.xml new file mode 100644 index 000000000..5456aa8f2 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/build.xml @@ -0,0 +1,143 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.assembly.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml new file mode 100644 index 000000000..fd6c5a710 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml @@ -0,0 +1,47 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + ${symbol_dollar}{artifactId}_TestSA + This is a test Service Assembly to test Engine + + + + + ${symbol_dollar}{artifactId}_TestSUBC + This service unit enables soap inbound endpoint for a service in service engine + + + testSUBC.zip + sun-http-binding + + + + + ${symbol_dollar}{artifactId}_TestSUSE + This service unit enables greetings service provider in service engine + + + testSUSE.zip + ${symbol_dollar}{artifactId} + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml new file mode 100644 index 000000000..96e95745f --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml @@ -0,0 +1,77 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml new file mode 100644 index 000000000..251f4073e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml new file mode 100644 index 000000000..251f4073e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml new file mode 100644 index 000000000..75340ea7d --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml @@ -0,0 +1,77 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml new file mode 100644 index 000000000..1ce2022bf --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml new file mode 100644 index 000000000..1ce2022bf --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/install-params.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/install-params.properties new file mode 100644 index 000000000..712a6a3ac --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/install-params.properties @@ -0,0 +1,3 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/m2nbbuild-impl.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/m2nbbuild-impl.xml new file mode 100644 index 000000000..2093d6b39 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/m2nbbuild-impl.xml @@ -0,0 +1,133 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + This project compile, package and test the JBI Components when invoked from Maven2. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/m2nbbuild.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/m2nbbuild.properties new file mode 100644 index 000000000..663de1bb9 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/m2nbbuild.properties @@ -0,0 +1,48 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} build properties file to set/override the properties of the netbeans project +${symbol_pound} build properties when the netbeans build is called from the maven build lifecycle. +${symbol_pound} Netbeans project when build from the IDE, uses a build.properties from the user.dir +${symbol_pound} of the Netbeans IDE to resolve some of the properties used in the project such as +${symbol_pound} the libraries classpath. +${symbol_pound} When invoking the Netbeans project build from maven, this build.properties file +${symbol_pound} is not available. So, you can add the properties defined in ide build properties +${symbol_pound} that this project uses here. +${symbol_pound} + +${symbol_pound} default local repository settings. If the repository location is different +${symbol_pound} -D command line option should override this (e.g. mvn -Dmaven.repo.local=/my/m2/repository +maven.repo.local=${symbol_dollar}{user.home}/.m2/repository +${symbol_pound} begin jbi admin settings +${symbol_pound} set the below properties if you want to override the properties from nbproject/project.properties +${symbol_pound} that sets the application server admin settings. +${symbol_pound} +${symbol_pound} jbi.as.home=C:/Sun/glassfish-v2-b58g +${symbol_pound} jbi.host=localhost +${symbol_pound} jbi.port=4848 +${symbol_pound} jbi.username=admin +${symbol_pound} jbi.password=adminadmin +${symbol_pound} end jbi admin settings +${symbol_pound} + +${symbol_pound} classpath settings +junit.ant.task.classpath=${symbol_dollar}{maven.repo.local}/ant/ant-junit/1.6.5/ant-junit-1.6.5.jar +junit.runtime.classpath=${symbol_dollar}{maven.repo.local}/junit/junit/3.8.2/junit-3.8.2.jar +libs.junit.classpath=${symbol_dollar}{junit.runtime.classpath}:${symbol_dollar}{junit.ant.task.classpath} +libs.jbi-cdk-ant-tasks.classpath=${symbol_dollar}{maven.repo.local}/open-esb/jbi-cdk/jbi-cdk-ant-tasks/${version}/jbi-cdk-ant-tasks-${version}.jar + +libs.jbi.classpath=${symbol_dollar}{maven.repo.local}/open-esb/jbi/1.0/jbi-1.0.jar +libs.wsdl4j.162.classpath=${symbol_dollar}{maven.repo.local}/wsdl4j/wsdl4j/1.6.2/wsdl4j-1.6.2.jar +${symbol_pound} libs.jaxws21.classpath=${symbol_dollar}{jbi.as.home}/lib/javaee.jar:${symbol_dollar}{jbi.as.home}/lib/webservices-rt.jar +libs.jaxws21.classpath=${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/activation/activation/1.1/activation-1.1.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/xml/soap/saaj-api/1.3/saaj-api-1.3.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/xml/ws/jaxws-api/2.1/jaxws-api-2.1.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/com/sun/xml/messaging/saaj/saaj-impl/1.3/saaj-impl-1.3.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/com/sun/xml/ws/jaxws-rt/2.1.2/jaxws-rt-2.1.2.jar + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/m2nbbuild.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/m2nbbuild.xml new file mode 100644 index 000000000..31217d15d --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/m2nbbuild.xml @@ -0,0 +1,37 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + This project compile, package and test the JBI Components when invoked from Maven2. + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/build-impl.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/build-impl.xml new file mode 100644 index 000000000..2e8e00c93 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/build-impl.xml @@ -0,0 +1,554 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + Inside: postArchTypeGen - Post task is getting executed! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Inside: postArchTypeGen - Post task executed successfully! + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/genfiles.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/genfiles.properties new file mode 100644 index 000000000..cfde66418 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/genfiles.properties @@ -0,0 +1,11 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +build.xml.data.CRC32=ac78c060 +build.xml.script.CRC32=9068f2c7 +build.xml.stylesheet.CRC32=8add101f@1.0 +${symbol_pound} This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +${symbol_pound} Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=ac78c060 +nbproject/build-impl.xml.script.CRC32=d15987fd +nbproject/build-impl.xml.stylesheet.CRC32=4ed53ee0@1.0 diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/jbi_admin.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/jbi_admin.xml new file mode 100644 index 000000000..8a7d2a523 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/jbi_admin.xml @@ -0,0 +1,504 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + +This ant script contains the jbi ant tasks and the targets and properties using +which the jbi admin commands can be performed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Usage : ant -f <fullpath>/jbi_admin.xml [options] [target] + options: -D<property>=<value> + Specify a property/value pairs as options that are valid for the target. + target : ant target name in jbi_admin.xml + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/jbiadmin-impl.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/jbiadmin-impl.xml new file mode 100644 index 000000000..7e7dca2ae --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/jbiadmin-impl.xml @@ -0,0 +1,339 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + Install, uninstall, reinstall, start, stop, shutdown jbi components. + + + + + + + + + + + + + + Must set jbi.host + Must set jbi.port + Must set jbi.username + Must set jbi.password + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/private/private.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/private/private.properties new file mode 100644 index 000000000..e540325d5 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/private/private.properties @@ -0,0 +1,6 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +javac.debug=true +javadoc.preview=true +user.properties.file=D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working57${symbol_escape}${symbol_escape}.netbeans${symbol_escape}${symbol_escape}openesb${symbol_escape}${symbol_escape}build.properties diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/private/retriever/catalog.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/private/retriever/catalog.xml new file mode 100644 index 000000000..712a6a3ac --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/private/retriever/catalog.xml @@ -0,0 +1,3 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/project.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/project.properties new file mode 100644 index 000000000..2a9ec25b5 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/project.properties @@ -0,0 +1,93 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +build.classes.dir=${symbol_dollar}{build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +${symbol_pound} This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${symbol_dollar}{build.dir}/generated +build.predist.dir=${symbol_dollar}{build.dir}/predist +build.predist.jar=${symbol_dollar}{build.predist.dir}/component.jar +build.predist.lib.dir=${symbol_dollar}{build.predist.dir}/lib +${symbol_pound} Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${symbol_dollar}{build.dir}/test/classes +build.test.dir=${symbol_dollar}{build.dir}/test +build.test.results.dir=${symbol_dollar}{build.dir}/test/results +conf.dir=src/conf +debug.classpath=${symbol_escape} + ${symbol_dollar}{run.classpath} +debug.test.classpath=${symbol_escape} + ${symbol_dollar}{run.test.classpath} +${symbol_pound} This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${symbol_dollar}{dist.dir}/${artifactId}.zip +dist.javadoc.dir=${symbol_dollar}{dist.dir}/javadoc +jar.compress=false +javac.classpath=${symbol_escape} + ${symbol_dollar}{libs.jbi.classpath}:${symbol_escape} + ${symbol_dollar}{jbi.component.sharedlibs.classpath}:${symbol_escape} + ${symbol_dollar}{jbi.component.lib.classpath} +${symbol_pound} Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.6 +javac.target=1.6 +javac.test.classpath=${symbol_escape} + ${symbol_dollar}{javac.classpath}:${symbol_escape} + ${symbol_dollar}{build.classes.dir}:${symbol_escape} + ${symbol_dollar}{libs.junit.classpath}:${symbol_escape} + ${symbol_dollar}{libs.jaxws21.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +jbi.ant.tasks.classpath=${symbol_escape} + ${symbol_dollar}{jbi.as.home}/lib/sun-appserv-ant.jar:${symbol_escape} + ${symbol_dollar}{jbi.as.home}/jbi/lib/jbi-ant-tasks.jar +#jbi.as.home=D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working53${symbol_escape}${symbol_escape}glassfish +jbi.as.home=${glassfishLocation} +#jbi.as.instance.id=[D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working53${symbol_escape}${symbol_escape}glassfish]deployer:Sun:AppServer::localhost:4848 +jbi.as.instance.id=[${glassfishLocation}]deployer:Sun:AppServer::localhost:4848 +jbi.component.bootstrap.class=${artifactId}.ProviderSEInstaller +jbi.component.class=${artifactId}.ProviderSERuntime +jbi.component.description=Description of service engine : ${artifactId} +jbi.component.lib.classpath=${symbol_escape} + ${symbol_dollar}{libs.wsdl4j.162.classpath} +jbi.component.name=${artifactId} +jbi.component.sharedlibs.classpath= +jbi.component.type=service-engine +jbi.host=localhost +jbi.install.params.file=install-params.properties +jbi.install.with.params=false +jbi.password=this really long string is used to identify a password that has been stored in the Keyring +jbi.port=4848 +jbi.soap.binding.name=sun-http-binding +jbi.username=admin +meta.inf.dir=${symbol_dollar}{conf.dir}/META-INF +platform.active=default_platform +project.jbi.deploy.plugin=./deploy-plugin +project.testSA=test/testSA +run.classpath=${symbol_escape} + ${symbol_dollar}{javac.classpath}:${symbol_escape} + ${symbol_dollar}{build.classes.dir} +${symbol_pound} Space-separated list of JVM arguments used when running the project +${symbol_pound} (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +${symbol_pound} or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=${symbol_escape} + ${symbol_dollar}{javac.test.classpath}:${symbol_escape} + ${symbol_dollar}{build.test.classes.dir} +src.dir=src/java +test-sys-prop.test.results.dir=${symbol_dollar}{build.test.results.dir} +test-sys-prop.test.src.dir=test-sys-prop.test.src.dir +test.src.dir=test/java +testSA.enabled=true +testSA.name=${artifactId}_TestSA diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/project.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/project.xml new file mode 100644 index 000000000..942beffad --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/nbproject/project.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + org.netbeans.modules.jbi.apisupport.project.jbicomponent + + + ${artifactId} + service-engine + 1.6.5 + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/pom.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 000000000..a65255db9 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,282 @@ + + + + 4.0.0 + ${groupId} + ${artifactId} + jar + ${version} + JBI Component[${artifactId}] + Maven project for JBI Component that contains the + maven and netbeans build setup and component code to build and test the JBI Component. + http://open-esb.org + + build + src/java + test/java + build/classes + build/test/classes + package + + + org.apache.maven.plugins + maven-compiler-plugin + + true + 1.5 + 1.5 + + + **/*.java + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + + **/*.* + + + + + maven-surefire-plugin + 2.1.3 + true + + + true + + **/bindingtest/*.java + **/enginetest/*.java + + + + + + maven-antrun-plugin + 1.2 + + + m2nbbuild-compile + compile + + run + + + + + + + + + m2nbbuild-compile-test + test-compile + + run + + + + + + + + + m2nbbuild-package + package + + run + + + + + + + + + m2nbbuild-utest + test + + run + + + + + + + + + m2nbbuild-itest + integration-test + + run + + + + + + + + + m2nbbuild-clean + clean + + run + + + + + + + + + + default-cli + + run + + + + !!!!!!!!!!!!!!!!!!!!!! Moving Files and organizing package !!!!!!!!!!!!!!!!!!!!!!!! + + + + + + + + + ant + ant-nodeps + 1.6.5 + + + ant + ant-junit + 1.6.5 + test + + + junit + junit + 3.8.2 + test + + + + + + + + + maven2-repo1 + Maven2 Central Repository + http://repo1.maven.org/maven2 + + + download-java-net-maven2-repository + download.java.net Maven 2.x repository + http://download.java.net/maven/2/ + + + maven-repository.dev.java.net-repository + https://maven-repository.dev.java.net/nonav/repository/ + legacy + + + ws-zones + ws.zones maven repository + http://ws.zones.apache.org/repository2/ + + + apache.org + Maven Snapshots + http://people.apache.org/repo/m2-snapshot-repository + + false + + + + + + + + + apache.org + Maven Plugin Snapshots + http://people.apache.org/repo/m2-snapshot-repository + + false + + + + + + + + ant + ant-nodeps + 1.6.5 + + + ant + ant-junit + 1.6.5 + test + + + junit + junit + 3.8.2 + test + + + org.apache.maven + maven-ant-tasks + 2.0.7 + + + open-esb.jbi-cdk + jbi-cdk-ant-tasks + 1.0-SNAPSHOT + + + open-esb + jbi + 1.0 + + + wsdl4j + wsdl4j + 1.6.2 + + + com.sun.xml.ws + jaxws-rt + 2.1.2 + test + + + + + ${maven.repo.local} + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/conf/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/conf/META-INF/jbi.xml new file mode 100644 index 000000000..7c40ad15c --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/conf/META-INF/jbi.xml @@ -0,0 +1,45 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + ${artifactId} + Description of service engine : ${artifactId} + + + net.openesb.component.${artifactId}.ProviderSERuntime + + + component.jar + + lib/wsdl4j-1.6.2.jar + + + net.openesb.component.${artifactId}.ProviderSEInstaller + + + component.jar + + lib/wsdl4j-1.6.2.jar + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSEComponentLifeCycle.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSEComponentLifeCycle.java new file mode 100644 index 000000000..af3bbc2c6 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSEComponentLifeCycle.java @@ -0,0 +1,52 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ProviderSEComponentLifeCycle.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.BasicComponentLifeCycle; +import net.openesb.component.${artifactId}.common.DefaultMessageExchangeReceiver; +import net.openesb.component.${artifactId}.common.MessageExchangeReceiver; +import net.openesb.component.${artifactId}.common.RuntimeContext; +import javax.jbi.JBIException; +import javax.jbi.component.Component; + +/** + * This class extends the basic ComponentLifeCycle implementation to provide + * component specific implementation of the ComponentLifeCycle. + * + * @see javax.jbi.ComponentLifeCycle + * @see com.sun.jbi.sample.component.common.BasicComponentLifeCycle + * @author chikkala + */ +public class ProviderSEComponentLifeCycle extends BasicComponentLifeCycle { + + /** + * constructor + */ + public ProviderSEComponentLifeCycle(Component compRuntime) { + super(compRuntime); + } + + /** + * creates DefaultMessageExchangeReceiver to handles receiving and + * processing the message exchanges from the delivery channel. + */ + @Override + protected MessageExchangeReceiver createMessageExchangeReceiver() { + return new DefaultMessageExchangeReceiver(); + } + + /** + * chance to extended classes to do the component specific init + * + * @throws javax.jbi.JBIException + */ + @Override + protected void doInit() throws JBIException { + // NOOP + RuntimeContext.getInstance().setLogger(this.getClass().getName(), null); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSEEndpoint.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSEEndpoint.java new file mode 100644 index 000000000..cddaa21da --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSEEndpoint.java @@ -0,0 +1,101 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ProviderSEEndpoint.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.MessageExchangeHandler; +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.MessageExchangeListener; +import net.openesb.component.${artifactId}.common.deployment.ProviderEndpoint; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor; +import javax.jbi.JBIException; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.wsdl.Definition; + +/** + * This class extends the ProviderEndpoint to implement component specific + * endpoint configuration. It implements the MessageExchangeListener to receive + * message exchange notifications from the MessageExchangeSupport fired by + * MessageExchangeReceiver and process it using a message exchange handler. + * + * This endpoint is configured for a service provided by this component which + * can receive a xml document and apply xslt transformation and send the results + * back in a InOut message exchange to complete a service invocation on this + * endpoint. + * + * @author chikkala + */ +public class ProviderSEEndpoint extends ProviderEndpoint implements MessageExchangeListener { + + private XSLTFileLocator mXsltFileLocator; + private XSLTService mXsltService; + + /** + * Creates a new instance of XSLTProviderEndpoint + */ + public ProviderSEEndpoint(SUDescriptor.Provides provides, Definition wsdlDef, ProviderSEServiceUnit su) { + super(provides, wsdlDef, su); + } + + /** + * XSLT transformation service used in transformation of the xml documents + * received on this endpoint. + */ + public XSLTService getXSLTService() { + return this.mXsltService; + } + + /** + * returns the XSLTFileLocator object that is created to find the xslt file + * to be used for a particular service operation invocation by looking at + * the mapping file specified in the service unit that deploys this + * endpoint. + */ + public XSLTFileLocator getXSLTFileLocator() { + return this.mXsltFileLocator; + } + + @Override + public void doInit() throws JBIException { + RuntimeHelper.getLogger().info("ProviderSEEndpoint:doInit called"); + ProviderSEServiceUnit su = (ProviderSEServiceUnit) this.getServiceUnit(); + this.mXsltFileLocator = su.getXsltFileLocator(); + this.mXsltService = XSLTService.XSLTServiceImpl.getInstance(); + } + + /** + * creates the message exchange handler that will be used to process the + * message exchange received for this endpoint. + */ + @Override + public MessageExchangeHandler createMessageExchangeHandler() { + return new ProviderSEMessageExchangeHandler(this); + } + + /** + * returns the implementation of the message exchange listener which the + * MessageExchangeSupport invokes when a message exchange is received from + * delivery channel by MessageExchangeReceiver. + */ + @Override + protected MessageExchangeListener createMessageExchangeListener() { + return this; + } + + /** + * implementation of the message exchange received method of the listener. + */ + public void messageExchangeReceived(ExchangeStatus status, MessageExchange me) { + try { + RuntimeHelper.getLogger().fine("MXListener.MessageExchangeReceived: with Status: " + status); + processMessageExchangeWithHandler(status, me); + // processMessageExchange(me); + } catch (Exception ex) { + ex.printStackTrace(); + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSEInstaller.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSEInstaller.java new file mode 100644 index 000000000..88da303d2 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSEInstaller.java @@ -0,0 +1,34 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + /* + * ProviderSEInstaller.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.ComponentInstaller; + +/** + * This class extends the ComponentInstaller that implements the + * javax.jbi.component.Bootstrap for a component installation contract. + * + * If the default implemenation of the javax.jbi.component.Bootstrap in + * com.sun.jbi.sample.component.common.ComponentInstaller is not sufficient for + * this components install, uninstall and upgrade requirements, override the + * default implementation here to add component specific installation and + * upgrade tasks such as initializing configuration mbean and creating resources + * specific to component or upgrade workspace and service units during upgrading + * the component. + * + * @see javax.jbi.Bootstrap + * @see com.sun.jbi.sample.component.common.ComponentInstaller + * @author chikkala + */ +public class ProviderSEInstaller extends ComponentInstaller { + + /** + * Constructor to create the MyEngineInstaller. + */ + public ProviderSEInstaller() { + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSEMessageExchangeHandler.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSEMessageExchangeHandler.java new file mode 100644 index 000000000..b3002d6ac --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSEMessageExchangeHandler.java @@ -0,0 +1,171 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ProviderSEMessageExchangeHandler.java + * + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.AbstractMessageExchangeHandler; +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.wsdl.WSDL11JBIWrapper; +import java.io.StringReader; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.Fault; +import javax.jbi.messaging.InOut; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Source; + +/** + * This class extends the AbstractMessageExchangeHandler to implement the + * component specific message exchange processing on the provider side in a + * service engine. + * + * @author chikkala + */ +public class ProviderSEMessageExchangeHandler extends AbstractMessageExchangeHandler { + + private ProviderSEEndpoint mEndpoint; + + /** + * Creates a new instance of ProviderSEMXHandler + */ + public ProviderSEMessageExchangeHandler(ProviderSEEndpoint endpoint) { + this.mEndpoint = endpoint; + } + + protected Logger getLogger() { + return this.mEndpoint.getLogger(); + } + + protected DeliveryChannel getDeliveryChannel() { + return this.mEndpoint.getDeliveryChannel(); + } + + protected void validateMessageExchange() throws MessagingException { + MessageExchange msgExchange = this.getMessageExchange(); + + if (this.getMessageExchange() == null) { + throw new MessagingException("MessageExchange Object is null in MessageExchageHandler"); + } + + if (MessageExchange.Role.CONSUMER.equals(msgExchange.getRole())) { + throw new MessagingException("Provider Message Exchange Handler can not have MessageExchange with CONSUMER Role"); + } + + if (!(msgExchange instanceof InOut)) { + throw new MessagingException("InOut Message Exchange Handler MessageExchange object should be instanceof javax.jbi.messaging.InOut "); + } + } + + protected void processError(Exception ex) { + MessageExchange msgExchange = this.getMessageExchange(); + Exception errEx = msgExchange.getError(); // get the error and print + RuntimeHelper.getLogger().info( + "InOut Message Exchange Provider received Error: " + errEx.getMessage()); + msgExchange.getError().printStackTrace(); + } + + protected void processDone() { + MessageExchange msgExchange = this.getMessageExchange(); + RuntimeHelper.getLogger().info("InOut Message Exchange Provider received DONE :" + + " END of service invocation"); + } + + protected void processFault(Fault fault) { + MessageExchange msgExchange = this.getMessageExchange(); + RuntimeHelper.logError("InOut Message Exchange Provider Handler can not receive Fault on Provider side"); + } + + protected void processMessage() { + try { + processInMessageOnProvider((InOut) this.getMessageExchange()); + } catch (JBIException ex) { + ex.printStackTrace(); + } + } + + protected void processInMessageOnProvider(InOut inOutExchange) throws JBIException { + RuntimeHelper.getLogger().fine("Processing In Message on Provider side " + inOutExchange); + // receive IN message. + NormalizedMessage inMsg = inOutExchange.getInMessage(); + NormalizedMessage outMsg = null; + Fault fault = null; + Source inContent = null; + Source outContent = null; + Source faultContent = null; + String faultAsText = null; + // process in message + inContent = inMsg.getContent(); + // invoke the service operation + try { + QName opName = inOutExchange.getOperation(); + QName svcName = inOutExchange.getEndpoint().getServiceName(); + RuntimeHelper.getLogger().fine("xslt service info " + svcName + opName); + + XSLTFileLocator xsltFileLocator = this.mEndpoint.getXSLTFileLocator(); + XSLTService xsltService = this.mEndpoint.getXSLTService(); + + String xsltPath = xsltFileLocator.findXsltFile(svcName, opName); + RuntimeHelper.getLogger().fine("XsltPath " + xsltPath); + if (xsltPath == null) { + RuntimeHelper.getLogger().fine(" No XSLT File found in MAP " + + xsltFileLocator.printMap()); + } + outContent = xsltService.transform(inContent, xsltPath); + + } catch (Exception ex) { + // exception invoking the operation. so, set exception text as fault content. + ex.printStackTrace(); + faultAsText = RuntimeHelper.getExceptionAsText(ex); + String faultText = RuntimeHelper.getExceptionAsXmlText(ex); + faultContent = RuntimeHelper.createDOMSource(new StringReader(faultText)); + } + // set out or fault message + if (outContent != null) { + // set the out message content. + outMsg = inOutExchange.createMessage(); + inOutExchange.setOutMessage(outMsg); + normalizeOutMessage(inOutExchange, outMsg, outContent); + // outMsg.setContent(outContent); + } else if (faultContent != null) { + fault = inOutExchange.createFault(); + inOutExchange.setFault(fault); + fault.setContent(faultContent); // may need to normalize the content. + } + // send out or fault message. + // this.getDeliveryChannel().sendSync(inOutExchange, SEND_SYNC_TIMEOUT); + this.send(); + } + + private void normalizeOutMessage(MessageExchange me, NormalizedMessage normMsg, Source msgSrc) throws MessagingException { + try { + // DOMSource wrappedSource = wrapOutputMessage(me, msgSrc); + WSDL11JBIWrapper outWrapper = WSDL11JBIWrapper.createOutputWrapper( + this.mEndpoint.getWSDLOperation(me.getOperation())); + + // check if the output from the transformer is in a wrapped form + WSDL11JBIWrapper wrapper = WSDL11JBIWrapper.sourceToWrapper( + RuntimeHelper.sourceToDOMSource(msgSrc)); + if (wrapper != null) { + outWrapper.appendParts(wrapper.getParts()); + } else { + outWrapper.appendPart(RuntimeHelper.sourceToDOMSource(msgSrc)); + } + + normMsg.setContent(outWrapper.toDOMSource()); + + } catch (MessagingException ex) { + throw ex; + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSERuntime.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSERuntime.java new file mode 100644 index 000000000..5a395d9ee --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSERuntime.java @@ -0,0 +1,56 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ProviderSERuntime.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.ComponentRuntime; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.component.ServiceUnitManager; + +/** + * This class extends the ComponentRuntime that implements + * javax.jbi.component.Component interface required for the component contract + * at runtime. + * + * This class provides the component specific ComponentLifeCycle implementation + * as well as the component specific ServiceUnitManager implementation. + * + * Add any additional component runtime specific functionality here. + * + * @see javax.jbi.component.Component + * @see com.sun.jbi.sample.component.common.ComponentRuntime + * @see com.sun.jbi.sample.component.common.BasicComponentLifecycle + * @see + * com.sun.jbi.sample.component.common.deployment.AbstractServiceUnitManager + * @author chikkala + */ +public class ProviderSERuntime extends ComponentRuntime { + + /** + * Creates a new instance of MyEngineRuntime + */ + public ProviderSERuntime() { + super(); + } + + /** + * overriding the parent's createComponentLifeCycle to create component + * specific component lifecycle implementation. + */ + @Override + protected ComponentLifeCycle createComponentLifeCycle() { + return new ProviderSEComponentLifeCycle(this); + } + + /** + * overrides the parent's createServiceUnitManager to create component + * specific service unit manager + */ + @Override + protected ServiceUnitManager createServiceUnitManager() { + return new ProviderSESUManager(this); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSESUManager.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSESUManager.java new file mode 100644 index 000000000..ed2cbed58 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSESUManager.java @@ -0,0 +1,49 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ProviderSESUManager.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.deployment.AbstractServiceUnitManager; +import net.openesb.component.${artifactId}.common.deployment.ServiceUnit; +import java.util.logging.Logger; +import javax.jbi.management.DeploymentException; + +/** + * This class extends the AbstractServiceUnitManager to implement component + * specific service unit manager by creating the component specific ServiceUnit + * implementation. + * + * @see + * com.sun.jbi.sample.component.common.deployment.AbstractServiceUnitManager + * @see com.sun.jbi.sample.component.common.deployment.ServiceUnit + * @author chikkala + */ +public class ProviderSESUManager extends AbstractServiceUnitManager { + + private ProviderSERuntime mRuntime; + + /** + * Creates a new instance of ProviderSESUManager + */ + public ProviderSESUManager(ProviderSERuntime compRuntime) { + super(); + this.mRuntime = compRuntime; + } + + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + + protected String getComponentName() { + return RuntimeHelper.getComponentName(); + } + //TODO implement ProviderSEServiceUnit + + protected ServiceUnit createServiceUnit(String suName, String suRootPath) throws DeploymentException { + return new ProviderSEServiceUnit(suName, suRootPath); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSEServiceUnit.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSEServiceUnit.java new file mode 100644 index 000000000..e11af0975 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/ProviderSEServiceUnit.java @@ -0,0 +1,63 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ProviderSEServiceUnit.java + * + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.deployment.ServiceUnit; +import net.openesb.component.${artifactId}.common.deployment.ProviderEndpoint; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Provides; +import javax.jbi.management.DeploymentException; +import javax.wsdl.Definition; + +/** + * This class extends the ServiceUnit to implement the component specific + * service unit processing. It creates the component specific ProviderEndpoint + * implementation to configure the service provider endpoint on this component + * deployed in the service unit. It also processes the deployment artifacts that + * are specific to the service provided by the component. + * + * @author chikkala + */ +public class ProviderSEServiceUnit extends ServiceUnit { + + private XSLTFileLocator mXsltFileLocator; + + /** + * Creates a new instance of ProviderSEServiceUnit + */ + public ProviderSEServiceUnit(String suName, String suRootPath) { + super(suName, suRootPath); + } + + protected XSLTFileLocator getXsltFileLocator() { + return this.mXsltFileLocator; + } + + @Override + protected ProviderEndpoint createProviderEndpoint(Provides provides, Definition wsdlDef) { + return new ProviderSEEndpoint(provides, wsdlDef, this); + } + + /** + * load and validates the component specific deployment artifacts. It loads + * the xsltmap properties into XSLTFileLocator which will be used to find + * the xslt file corresponding to a service operation. + */ + @Override + protected void loadOtherArtifacts() throws DeploymentException { + super.loadOtherArtifacts(); + // load any component specific service unit artifacts + if (this.mXsltFileLocator == null) { + try { + this.mXsltFileLocator = + new XSLTFileLocator(this.getSURootPath(), "xsltmap.properties"); + } catch (Exception ex) { + throw new DeploymentException(ex); + } + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/XSLTFileLocator.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/XSLTFileLocator.java new file mode 100644 index 000000000..d5189d393 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/XSLTFileLocator.java @@ -0,0 +1,210 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * XSLTFileLocator.java + */ +package net.openesb.component.${artifactId}; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import javax.xml.namespace.QName; + +/** + * This class represents the component specific deployment artifact which reads + * the deployed "xsltmap.properties" file in the service unit and processes it + * to find the xslt file to be used for a particular operation on a service + * provided by the deployment. + *
+ * The "xsltmap.properties" file should contain two types of properties
+ * 1.for namespace prefix to namespaceURI map that starts with "xmlns." prefix like
+ *   "xmlns.tns-prefix=http://www.sun.com/jbi/examples/sample-service/echo"
+ * 2. a service description to xslt file properties with syntax like
+ *   "{tns-prefix}service-name=xslt_file_name"  and
+ *   "{tns-prefix}service-name.{tns-prefix}operation-name=xslt_file_name" and
+ *   "{tns-prefix}service-name.{tns-prefix}interface-name.operation-name=xslt_file_name" .
+ * the service description property is a "." delimited tokens that represents a serive
+ * or interface qname and a operation name. To locate xslt file either with service qname
+ * or service qname and operaton or serivice qname and interface qname and operation,
+ * all the three properties specified above should be there for each xslt file. for example,
+ *  xmlns.echo1=http://www.sun.com/jbi/examples/sample-service/echo
+ *  xmlns.echo2=http://www.sun.com/jbi/examples/sample-service/echo
+ *  {echo2}echoService=echo.xsl
+ *  {echo2}echoService.{echo1}echo=echo.xsl
+ *  {echo2}echoService.{echo1}echo.echo=echo.xsl
+ * 
+ * + * @author chikkala + */ +public class XSLTFileLocator { + + private Map mXsltFileMap; + + /** + * Creates a new instance of XsltLocator + */ + public XSLTFileLocator(String rootPath, String mapFile) throws Exception { + this.mXsltFileMap = new HashMap(); + initXsltLocator(rootPath, mapFile); + } + + private void initXsltLocator(String rootPath, String mapFilePath) throws Exception { + @SuppressWarnings("unchecked") + Map mapProps = loadMappingProperties(rootPath, mapFilePath); + + Map nsMap = new HashMap(); + Map xsltMap = new HashMap(); + + for (String name : mapProps.keySet()) { + String value = mapProps.get(name); + if (name.startsWith("{")) { + xsltMap.put(name, value); + } else if (name.startsWith("xmlns.")) { + String xmlns = name.substring(6); + nsMap.put(xmlns, value); + } + } + + for (String name : xsltMap.keySet()) { + String value = xsltMap.get(name); + String[] tokens = name.split("${symbol_escape}${symbol_escape}."); + String svcName = null; + String intrName = null; + String opName = null; + + if (tokens.length == 1) { + svcName = expandQName(tokens[0], nsMap); + } else if (tokens.length == 2) { + svcName = expandQName(tokens[0], nsMap); + opName = expandQName(tokens[1], nsMap); + } else if (tokens.length == 3) { + svcName = expandQName(tokens[0], nsMap); + intrName = expandQName(tokens[1], nsMap); + opName = tokens[2]; + } else { + System.out.println("invalid property name in xslt map property" + name); + } + + StringBuffer buff = new StringBuffer(); + buff.append(svcName); + if (intrName != null) { + buff.append("."); + buff.append(intrName); + } + if (opName != null) { + buff.append("."); + buff.append(opName); + } + File file = new File(rootPath, value); + String xsltFile = file.getAbsolutePath(); + this.mXsltFileMap.put(buff.toString(), xsltFile); + } + } + + private String expandQName(String qname, Map xmlnsMap) { + + // qname passed is "{prefix}localname" + QName temp = QName.valueOf(qname); + String prefix = temp.getNamespaceURI(); + String nsURI = xmlnsMap.get(prefix); + if (nsURI == null) { + nsURI = prefix; // just use the prefix as it is. + } + QName realQName = new QName(nsURI, temp.getLocalPart()); + return realQName.toString(); + } + + private Map loadMappingProperties(String rootPath, String mapFilePath) throws Exception { + File mapFile = new File(rootPath, mapFilePath); + Properties mapProps = new Properties(); + if (!mapFile.exists()) { + throw new Exception("Mapping file not found " + mapFilePath); + } + FileInputStream inStream = null; + try { + inStream = new FileInputStream(mapFile); + mapProps.load(inStream); + } catch (FileNotFoundException ex) { + ex.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); + } finally { + if (inStream != null) { + try { + inStream.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + return mapProps; + } + + /** + * return the xslt file mapped to either service name or service qname + + * operation qname + * + * @param serviceQName must be non null qname + * @param opQName can be null the xslt file can be located at service level. + */ + public String findXsltFile(QName serviceQName, QName opQName) { + StringBuffer buff = new StringBuffer(); + buff.append(serviceQName.toString()); + if (opQName != null) { + buff.append("."); + // workaround for the http soap bc bug which does not set the namespace + // uri on the op name. for time being use the serviceQName's namespace + String namespaceURI = opQName.getNamespaceURI(); + if (namespaceURI == null || namespaceURI.length() == 0) { + QName tempOp = + new QName(serviceQName.getNamespaceURI(), opQName.getLocalPart()); + buff.append(tempOp.toString()); + } else { + buff.append(opQName.toString()); + } + } + String xsltFile = this.mXsltFileMap.get(buff.toString()); + return xsltFile; + } + + /** + * return the xslt file mapped to either service name or service qname + + * interface qname + operation + * + * @param serviceQName must be non null service qname + * @param intrQName interface qname + * @param opName operation name ( not a qname) + */ + public String findXsltFile(QName serviceQName, QName intrQName, String opName) { + StringBuffer buff = new StringBuffer(); + buff.append(serviceQName.toString()); + if (intrQName != null) { + buff.append("."); + buff.append(intrQName.toString()); + } + if (opName != null) { + buff.append("."); + buff.append(opName); + } + String xsltFile = this.mXsltFileMap.get(buff.toString()); + return xsltFile; + } + + public String printMap() { + StringWriter buff = new StringWriter(); + PrintWriter out = new PrintWriter(buff); + for (String key : this.mXsltFileMap.keySet()) { + out.println("Key= " + key); + out.println("XsltFile= " + this.mXsltFileMap.get(key)); + } + out.close(); + return buff.getBuffer().toString(); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/XSLTService.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/XSLTService.java new file mode 100644 index 000000000..a303e10a0 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/XSLTService.java @@ -0,0 +1,108 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * XSLTService.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import java.io.File; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Properties; +import java.util.logging.Logger; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import org.w3c.dom.Document; + +/** + * This is a sample service implementation that takes the input as xml document + * and the xslt file to apply the xslt transformation on the input xml and + * return the transformed output xml. This implementation of the service is + * invoked when a InOut message exchange is processed to invoke a service + * provided by the engine. + * + * @author chikkala + */ +public interface XSLTService { + + /** + * this operation takes the input xml document and constructs the output xml + * document by applying the xslt in the file specified in xsltPath + * + * @param inputDoc input xml document + * @param xsltPath absolute file path of xslt file. + * @return transformed output xml document + */ + Source transform(Source inputDoc, String xsltPath) throws Exception; + + /** + * This class implements the echo service operations which the service + * engine will invoke when a InOut message exchange is processed to invoke a + * service provided by the engine. + */ + public static class XSLTServiceImpl implements XSLTService { + + private XSLTServiceImpl() { + } + + /** + * accessor to create/locate the service implementation + * + * @return echo service implementation + */ + public static XSLTService getInstance() { + return new XSLTServiceImpl(); + } + + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + + /** + * this operation takes the input xml document and constructs the output + * xml document with the same data to implement the echo. + * + * @param inputDoc input document + * @return output document + */ + public Source transform(Source inputDoc, String xsltPath) throws Exception { + Document outDoc = null; + StringBuffer inBuff = RuntimeHelper.readFromSource(inputDoc); + + getLogger().fine("${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} TRANSFORMER INPUT MESSAGE BEGIN ${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}"); + getLogger().fine(inBuff.toString()); + getLogger().fine("${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} TRANSFORMER INPUT MESSAGE END ${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}"); + + TransformerFactory tf = null; + tf = TransformerFactory.newInstance(); + StreamSource xsltSource = new StreamSource(new File(xsltPath)); + Transformer xformer = tf.newTransformer(xsltSource); + + Properties params = new Properties(); //TODO get the pramas from the user file + for (Object name : params.keySet()) { + xformer.setParameter((String) name, params.get(name)); + } + StringWriter writer = new StringWriter(); + StreamResult result = new StreamResult(writer); + + DOMSource xmlSource = new DOMSource(RuntimeHelper.buildDOMDocument(new StringReader(inBuff.toString()))); + + xformer.transform(xmlSource, result); + + getLogger().fine("${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} TRANSFORMER OUTPUT MESSAGE BEGIN ${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}"); + getLogger().fine(writer.getBuffer().toString()); + getLogger().fine("${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} TRANSFORMER OUTPUT MESSAGE END ${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}"); + + outDoc = RuntimeHelper.buildDOMDocument(new StringReader(writer.getBuffer().toString())); + DOMSource outSource = new DOMSource(outDoc); + + return outSource; + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java new file mode 100644 index 000000000..4987029b3 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java @@ -0,0 +1,141 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractMessageExchangeHandler.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import java.io.StringReader; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.Fault; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; +import javax.xml.namespace.QName; + +/** + * This class is an abstract implementation of the MessageExchangeHandler which + * provides the base implementation of the ME processing and provides hooks to + * extended classes to implement component specific processing. + * + * @author chikkala + */ +public abstract class AbstractMessageExchangeHandler implements MessageExchangeHandler { + + public static String IN_MESSAGE = "in"; + public static String OUT_MESSAGE = "out"; + + private MessageExchange mMessageExchange; + private ExchangeStatus mStatus; + /** Creates a new instance of AbstractMessageExchangeHandler */ + protected AbstractMessageExchangeHandler() { + this.mMessageExchange = null; + } + + protected abstract Logger getLogger(); + protected abstract DeliveryChannel getDeliveryChannel(); + protected abstract void validateMessageExchange() throws MessagingException; + protected abstract void processError(Exception ex); + protected abstract void processDone(); + protected abstract void processMessage(); + protected abstract void processFault(Fault fault); + + public final MessageExchange getMessageExchange() { + return this.mMessageExchange; + } + + public final void setMessageExchange(MessageExchange msgExchange) { + this.mMessageExchange = msgExchange; + } + + public final ExchangeStatus getMessageExchangeStatus() { + if ( this.mStatus != null ) { + return this.mStatus; + } else if ( this.mMessageExchange != null ) { + return this.mMessageExchange.getStatus(); + } else { + return null; + } + } + + public final void setMessageExchangeStatus(ExchangeStatus status) { + this.mStatus = status; + } + + protected void send() throws MessagingException { + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected boolean sendSync(long timeout) throws MessagingException { + return this.getDeliveryChannel().sendSync(this.mMessageExchange, timeout); + } + + protected void sendDone() throws MessagingException { + this.mMessageExchange.setStatus(ExchangeStatus.DONE); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void sendError(Exception ex) throws MessagingException { + this.mMessageExchange.setError(ex); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void sendFault(Exception ex, QName type, String name) throws MessagingException { + Fault fault = this.mMessageExchange.createFault(); + if ( ex != null ) { + String xmlText = RuntimeHelper.getExceptionAsXmlText(ex); + fault.setContent(RuntimeHelper.createDOMSource(new StringReader(xmlText))); + } + this.mMessageExchange.setFault(fault); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void processActive() { + Fault fault = this.getMessageExchange().getFault(); + if ( fault != null ) { + processFault(fault); + } else { + processMessage(); + } + } + /** + * implementation of the MessageExchangeHandler${symbol_pound}processMessageExchange method. + */ + public void processMessageExchange(ExchangeStatus status, MessageExchange msgEx) { + + getLogger().fine("MessageExchangeHandler.processMessageExchange:status: " + status ); + + this.setMessageExchangeStatus(status); + this.setMessageExchange(msgEx); + + try { + validateMessageExchange(); + } catch (MessagingException ex) { + getLogger().log(Level.FINE, "Invalid message exchange for processing ", ex); + if ( this.getMessageExchange() != null ) { + try { + sendError(ex); + } catch (MessagingException errEx) { + getLogger().log(Level.FINE, "Can not send invalid message exchange error", errEx); + } + } + return; + } + + MessageExchange msgExchange = this.getMessageExchange(); + + if (ExchangeStatus.ACTIVE.equals(status) ) { + processActive(); + } else if (ExchangeStatus.DONE.equals(status) ) { + processDone(); + } else if (ExchangeStatus.ERROR.equals(status) ) { + processError(msgExchange.getError()); + } + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java new file mode 100644 index 000000000..d76fbe0f9 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java @@ -0,0 +1,398 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractComponentLifeCycle.java + */ + +package net.openesb.component.${artifactId}.common; + +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.component.Component; +import javax.jbi.component.ComponentContext; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.MessagingException; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.StandardMBean; + +/** + * This class implements the javax.jbi.component.ComponentLifeCycle. This is an + * abstract class that keeps the reference to the component context and the lifecycle + * extension mbeans. It implements the lifecycle method and provide the extended methods + * for each lifecycle methods to implement component specific functionality. + *

+ * It makes sure that the mininum initialization required for the component + * lifecycle is implemented by this class or the classes extending this class. + *

+ * Another important functionality implemented in this class is that it initializes the global + * RuntimeContext for the component with the ComponentContext passed by the JBI runtime and the + * opened delivery channel to make them available globally to any class in the component implementation + * that may need it during component lifecycle + *

+ * Service engine or a binding component lifecycle implementation can directly extend + * this class for their required functionality and override some of the methods to provide + * their own implementation. + * + * @see javax.jbi.ComponentLifeCycle + * @author chikkala + */ +public class BasicComponentLifeCycle implements ComponentLifeCycle { + /** reference to the component runtime */ + private Component mCompRuntime; + /** component context */ + private ComponentContext mComponentContext; + /** Extension Mbean Name*/ + private ObjectName mExtensionMBeanName; + /** Extension Mbean Implementation*/ + private StandardMBean mExtensionMBeanImpl; + /** a message receiver that accepts messages from delivery channel */ + private MessageExchangeReceiver mMsgExchReceiver; + + /** + * constructor for the ComponentLifecycle implementation. + * @param compRuntime + */ + protected BasicComponentLifeCycle(Component compRuntime) { + this.mCompRuntime = compRuntime; + } + /** + * @return Component + */ + public final Component getComponentRuntime() { + return this.mCompRuntime; + } + /** + * @return ComponentContext component context. + */ + public final ComponentContext getComponentContext() { + return mComponentContext; + } + /** + * @return component name + */ + protected String getComponentName() { + return (this.mComponentContext != null) ? + this.mComponentContext.getComponentName() : null; + } + /////////////////////////////////////////////////////////////////////////// + // ComponentLifeCycle interface implemenation + /////////////////////////////////////////////////////////////////////////// + + /** + * Initializes the component lifecycle. This method makes sure that the + * component context passed by the jbi runtime is saved in the lifecycle + * object before calling the other component initialization methods to + * completely initialize the component. + * @param context Component context + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}init(javax.jbi.component.ComponentContext) + * @throws javax.jbi.JBIException on error + */ + public final void init(ComponentContext context) throws JBIException { + + if ( context == null ) { + throw new JBIException("Null Component Context received in " + + "Component Lifecycle init "); + } + this.mComponentContext = context; // 0. save the component context passed by jbi framework. + // initialize the content + initGlobalContext(); // 1. Initialize component runtime context. + registerExtensionMBean(); // 2. Create and register extension mbean. + openDeliveryChannel(); // 3. Open delivery channel. + initMessageExchangeReceiver(); // 4. Create message exchange receiver. + doInit(); // 5. Do any component specific initialization such + // as static service providers and consumers initialization. + + this.getLogger().fine("Component " + this.getComponentName() + " initialized"); + } + + /** + * Starts the component. Extended classes can override/implement the methods called + * in this method to provide component specify start functionality. + * + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}start() + * @throws javax.jbi.JBIException on error + */ + public final void start() throws JBIException { + + doStart(); // 1. do any other component specific start tasks such as + // activating any static service providers and consumers. + startMessageExchangeProcessing(); // 2. begin accepting and processing message exchanges. + + this.getLogger().fine("Component " + this.getComponentName() + " started"); + } + + /** + * Stop the component.Extended classes can override/implement the methods called + * in this method to provide component specify stop functionality. + * @throws javax.jbi.JBIException + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}stop() + */ + public final void stop() throws JBIException { + + stopMessageExchangeProcessing(); // 1. stop accepting and processing message exchanges. + doStop(); // 2. do any other component specific stop tasks such as + // deactivating any static service providers and consumers. + this.getLogger().fine("Component " + this.getComponentName() + " stopped."); + } + + /** + * Shut down the component. Extended classes can override/implement the methods called + * in this method to provide component specify shut down functionality. + * @throws javax.jbi.JBIException + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}shutDown() + */ + public final void shutDown() throws JBIException { + // clean up all resources. + shutdownMessageExchangeReceiver(); // 1. remove the message receiver. + closeDeliveryChannel(); // 2. close delivery channel + unregisterExtensionMBean(); // 3. unregister and remove extension mbean if exists. + doShutDown(); // 4. do any other component specific clean up tasks such + // as clean any static service providers and consumer resource. + this.getLogger().fine("Component " + this.getComponentName() + " shut down"); + } + /** + * create jmx object name for the extension mbean. default implementation does + * not required to have the extension mbean. + * @return ObjectName of the extension mbean + */ + protected ObjectName createExtensionMBeanName() { + return null; + } + /** + * gets the reference to the extension mbean name. + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}getExtensionMBeanName() + * @return ObjectName of the extension mbean objectname or null if component + * does not support extension mbean + */ + public final ObjectName getExtensionMBeanName() { + if ( this.mExtensionMBeanName == null ) { + this.mExtensionMBeanName = this.createExtensionMBeanName(); + } + return this.mExtensionMBeanName; + } + /** + * create mbean implementation for the extension mbean as a StandardMBean. default + * implementation does not require the extension mbean + * @return the ExtensionMBean implementation as StandardMBean + */ + protected StandardMBean createExtensionMBean() { + return null; + } + /** + * gets the reference to the extension mbean. + * @return extension mbean implementation or null if component does not support. + */ + protected final StandardMBean getExtensionMBean() { + if ( this.mExtensionMBeanImpl == null ) { + this.mExtensionMBeanImpl = this.createExtensionMBean(); + } + return this.mExtensionMBeanImpl; + } + /** + * if there is an extension mbean supported by the component, then register + * it with the mbean server. + * @throws JBIException on error registering mbean + */ + protected final void registerExtensionMBean() throws JBIException { + // creatre the extension mbean's object name + ObjectName mbeanName = this.getExtensionMBeanName(); + // create the extension mbean implemenation. + StandardMBean mbeanImpl = this.getExtensionMBean(); + + if ( mbeanName == null || mbeanImpl == null ) { + this.getLogger().fine(this.getComponentName() + + " Does not have Extension MBean implemenation "); + return; + } + // register with mbean only if object name and implementation are non null + try { + MBeanServer mbServer = RuntimeHelper.getComponentContext().getMBeanServer(); + mbServer.registerMBean(mbeanImpl, mbeanName); + } catch (Exception e) { + throw new JBIException("Failed to register Extension MBean for " + + this.getComponentName(), e); + } + } + /** + * remove the registered extension mbean from the mbean server if any. + */ + protected final void unregisterExtensionMBean() { + ObjectName mbeanName = this.getExtensionMBeanName(); + if ( mbeanName == null ) { + return; + } + try { + MBeanServer mbServer = RuntimeHelper.getComponentContext().getMBeanServer(); + mbServer.unregisterMBean(mbeanName); + } catch (Exception e) { + this.getLogger().log(Level.WARNING, + "Failed to unregister Extension MBean from MBeanServer for " + this.getComponentName(), e); + } + } + /** + * creates MessageExchangeReceiver implementation that handles receiving and processing + * the message exchanges from the delivery channel. Component should implement + * this method to provide the MessageReceiver. + * + * Component may return null indicating that they don't need the message receiver + * that can receive and process message exchanges from delivery channel. For example, + * components that have only service consumers which send a synchronous messages to + * providers don't need this. + * + * @throws java.lang.Exception + * @return MessageExchangeReceiver implementation. null if the component does not support it. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle${symbol_pound}createMessageExchangeReceiver + */ + protected MessageExchangeReceiver createMessageExchangeReceiver() { + return null; + } + /** + * returns the message exchange receiver implementation reference + * @return MessageExchangeReceiver interface + */ + protected final MessageExchangeReceiver getMessageExchangeReceiver() { + if ( this.mMsgExchReceiver == null ) { + this.mMsgExchReceiver = createMessageExchangeReceiver(); + } + return this.mMsgExchReceiver; + } + /** + * creates a message receiver object as part of the component initialization. + * @throws javax.jbi.JBIException + */ + protected void initMessageExchangeReceiver() throws JBIException { + // create and initialize the MessageExchangeReceiver + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.initReceiver(); + } + } + /** + * allows the component to accept the message exchange objects from the + * delivery channel and process it as part of the component startup process. + * @throws javax.jbi.JBIException + */ + protected void startMessageExchangeProcessing() throws JBIException { + // start message processing + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.startProcessing(); + } + } + /** + * stops the component from accepting the message exchange objects from the + * delivery channel as part of the component stop process + * @throws javax.jbi.JBIException + */ + protected void stopMessageExchangeProcessing() throws JBIException { + // stop message processing + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.stopProcessing(); + } + } + /** + * removes the message receiver as part of the component shutdown process + * @throws javax.jbi.JBIException + */ + protected void shutdownMessageExchangeReceiver() throws JBIException { + // clean up message processing. + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.shutdownReceiver(); + } + } + /** + * Returns logger initialized from the component context or a default logger. + * @return Logger + */ + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** + * initializes the RuntimeContext during component init lifecycle phase. This + * includes setting the ComponentContext and loggers etc. extended classes must + * save the component context in the RuntimeContext in this methods implementation. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle${symbol_pound}initGlobalContext + */ + protected void initGlobalContext() { + RuntimeContext.getInstance().setComponentContext(this.getComponentContext()); + RuntimeContext.getInstance().setLogger(this.getClass().getName(), null); + } + /** opens the delivery channel to accept or send message exchange objects + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle${symbol_pound}openDeliveryChannel + */ + protected void openDeliveryChannel() { + try { + DeliveryChannel channel = this.getComponentContext().getDeliveryChannel(); + RuntimeContext.getInstance().setDeliveryChannel(channel); + } catch (MessagingException ex) { + ex.printStackTrace(); + } + } + /** closes the delivery channel as part of the component shutdown process. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle${symbol_pound}closeDeliveryChannel + */ + protected void closeDeliveryChannel() { + // closes delivery channel and remove the reference. + try { + DeliveryChannel channel = RuntimeHelper.getDeliveryChannel(); + if ( channel != null ) { + channel.close(); + } + } catch (MessagingException ex) { + ex.printStackTrace(); + } finally { + RuntimeContext.getInstance().setDeliveryChannel(null); + } + } + /** + * chance to extended classes to do any extra component specific init tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * initialized here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle${symbol_pound}init method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle${symbol_pound}init + */ + protected void doInit() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific start tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * activated here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle${symbol_pound}start method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle${symbol_pound}start + */ + protected void doStart() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific stop tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * deactivated here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle${symbol_pound}stop method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle${symbol_pound}stop + */ + protected void doStop() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific shutdown tasks.If the component + * supports static service providers or consumers without deployment support, they can be + * cleaned up here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle${symbol_pound}shutdown method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle${symbol_pound}shutdown + */ + protected void doShutDown() throws JBIException { + //NOOP + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/ComponentInstaller.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/ComponentInstaller.java new file mode 100644 index 000000000..7e44dc053 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/ComponentInstaller.java @@ -0,0 +1,275 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + /* + * ComponentInstaller.java + */ +package net.openesb.component.${artifactId}.common; + +import java.util.List; +import java.util.logging.Level; +import javax.jbi.component.Bootstrap; +import javax.jbi.component.InstallationContext; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.StandardMBean; + +/** + * This class implements the javax.jbi.component.Bootstrap. This class implements + * the minimum required functionality for component installation contract + * of the jbi component in the jbi environment. It also takes care of maintaining + * the installation context reference and installation specific logger creation and + * installation extension mbean registration and unregistration during initialization + * and cleanup. Extended classes only need to supply the mbean name and its implementation + * object for the installation extensions. + * + * It makes sure that the installation context and the loggers are available to + * the classes extended from this class to add more installation specific functionality. + * + * Service engine or a binding component installation implementation can directly use + * this class or extend this class to add more functionality to their installation + * process. + * + * @see javax.jbi.Bootstrap + * @author chikkala + */ +public class ComponentInstaller implements Bootstrap { + /** default logger*/ + private Logger mDefLogger; + /** bootstrap logger */ + private Logger mBTLogger ; + /** Installation Context . */ + private InstallationContext mInstallationContext; + /** Extension Mbean Name*/ + private ObjectName mExtensionMBeanName; + /** Extension Mbean Implementation*/ + private StandardMBean mExtensionMBeanImpl; + + /** Constructor to create the ComponentInstaller. */ + public ComponentInstaller() { + } + /** + * @return InstallationContext of the component. + */ + public final InstallationContext getInstallationContext() { + return this.mInstallationContext; + } + protected String getComponentName() { + return (this.mInstallationContext != null) ? + this.mInstallationContext.getComponentName() : null; + } + /** + * @return logger initialized from the installation context or a default + * logger. + */ + protected Logger getLogger() { + // try init bootstrap logger + if (this.mBTLogger == null && this.mInstallationContext != null ) { + try { + this.mBTLogger = + this.mInstallationContext.getContext().getLogger(this.getClass().getName(), null); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + // init default logger if required + if ( this.mBTLogger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (this.mBTLogger != null) ? this.mBTLogger : this.mDefLogger; + } + /** + * Initializes the installation environment for a component. + * @see javax.jbi.component.Bootstrap${symbol_pound}init(javax.jbi.component.InstallationContext) + */ + public final void init(InstallationContext installContext) throws javax.jbi.JBIException { + + if ( installContext == null ) { + throw new JBIException("Null Installation Context received in " + + "Component Bootstrap initialization"); + } + // save the installation context reference passed by the jbi framework. + this.mInstallationContext = installContext; + registerExtensionMBean(); // create and register extension mbean + doInit(); // do any other extra initialization required specific to the component installation. + // initialize logger + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component Installer initialized"); + } + /** + * default implementation just logs the method call. extended classes should override this. + * @see javax.jbi.component.Bootstrap${symbol_pound}onInstall() + */ + public void onInstall() throws javax.jbi.JBIException { + //TODO: do required initializaton and resource creation + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component installed."); + } + /** + * default implementation just logs the method call. + * @see javax.jbi.component.Bootstrap${symbol_pound}onUninstall() + */ + public void onUninstall() throws javax.jbi.JBIException { + //TODO: do clean up the resource and other stuff. + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component uninstalled"); + } + /** + * default noop implementation of the cleanup. + * @see javax.jbi.component.Bootstrap${symbol_pound}cleanUp() + */ + public final void cleanUp() throws javax.jbi.JBIException { + + unregisterExtensionMBean(); // unregister extension mbean and remove it + doCleanUp(); // do any other extra cleanup specific to the component installation. + this.getLogger().fine( this.mInstallationContext.getComponentName() + + " Component Installer Cleaned up"); + } + + /** + * create jmx object name for the extension mbean. Extended classes should + * return the component specific installer extension mbean name here. + */ + protected ObjectName createExtensionMBeanName() { + return null; + } + /** + * default implementation that does not have extension mbean return null. + * @see javax.jbi.component.Bootstrap${symbol_pound}getExtensionMBeanName() + */ + public final javax.management.ObjectName getExtensionMBeanName() { + if ( this.mExtensionMBeanName == null ) { + this.mExtensionMBeanName = createExtensionMBeanName(); + } + return this.mExtensionMBeanName; + } + /** + * create mbean implementation for the extension mbean as a StandardMBean. Extended + * classes should return the installer extension mbean implementation as the + * standard mbean. + */ + protected StandardMBean createExtensionMBean() { + return null; + } + /** + * returns the installation extension mbean implementation. + * @return StandardMBean for the extension mbean implementation. + */ + protected final StandardMBean getExtensionMBean() { + if ( this.mExtensionMBeanImpl == null ) { + this.mExtensionMBeanImpl = this.createExtensionMBean(); + } + return this.mExtensionMBeanImpl; + } + /** + * Chance to extended classes to do the component installation specific init. + * Installation context will be initialized before calling this method. So, + * initialize other things if required in this method. + * @throws javax.jbi.JBIException on error + * @see com.sun.jbi.sample.component.common.ComponentInstaller${symbol_pound}init( + * javax.jbi.component.InstallationContext) + */ + protected void doInit() throws JBIException { + this.getLogger().info(this.getInstallationContext().getComponentName() + + " : Component Installer initialized"); + } + /** + * Chance to extended classes to do the component installation specific cleanup. + * ExtensionMbean will be unregistered before calling this method. + * @throws javax.jbi.JBIException on error + * @see com.sun.jbi.sample.component.common.ComponentInstaller${symbol_pound}cleanUp( + * javax.jbi.component.InstallationContext) + */ + protected void doCleanUp() throws JBIException { + this.getLogger().fine(this.getInstallationContext().getComponentName() + + " : Component Installer doCleanUp"); + } + /** + * if there is an extension mbean supported by the component, then register + * it with the mbean server. + */ + protected void registerExtensionMBean() throws JBIException { + // creatre the installation extension mbean's object name + ObjectName mbeanName = this.getExtensionMBeanName(); + // create the extension mbean implemenation if the object name is created. + StandardMBean mbeanImpl = this.getExtensionMBean(); + + if ( mbeanName == null || mbeanImpl == null ) { + this.getLogger().fine(this.getComponentName() + + " Does not have Installation Extension MBean implemenation "); + return; + } + // register with mbean only if object name and implementation are non null + try { + MBeanServer mbServer = this.getInstallationContext().getContext().getMBeanServer(); + mbServer.registerMBean(mbeanImpl, mbeanName); + } catch (Exception e) { + throw new JBIException("Failed to register Installation Extension MBean for " + + this.getComponentName(), e); + } + } + /** + * remove the registered extension mbean from the mbean server. + */ + protected void unregisterExtensionMBean() { + ObjectName mbeanName = this.getExtensionMBeanName(); + if ( mbeanName == null ) { + return; + } + try { + MBeanServer mbServer = this.getInstallationContext().getContext().getMBeanServer(); + mbServer.unregisterMBean(mbeanName); + } catch (Exception e) { + this.getLogger().log(Level.WARNING, + "Failed to unregister Installation extension MBean for " + this.getComponentName(), e); + } + } + /** + * This method is called by the JBI runtime to allow a component to upgrade + * it's workspace and any existing Service Units to match the new version of + * the component. The JBI runtime copies the existing workspace root to the + * new workspace root prior to calling this method, so that the component + * can examine the contents of the workspace root to determine the version + * of the component from which the upgrade is being made. All updates to the + * workspace root are done in-place; in the event of a failure, the JBI + * runtime reverts back to the original workspace root, the original install + * root, and the original Service Unit roots for the component. + * + * Note1: The component must ensure that it never holds open references + * to any files in the workspace root or any of the Service Unit roots upon + * returning from this method. Failure to do so will cause problems when + * the runtime attempts to complete the upgrade processing. + * + * Note2: The installation context that is normally initialized + * by the runtime by calling ${symbol_pound}init method of the javax.jbi.Bootstrap interface + * before install and uninstall will not be called before calling this + * upgrade method. So, installation context can not be used in this method's + * implementation. + * + * Note3: Since there won't be any installation context available, the logger + * that returned from the ${symbol_pound}getLogger method is a default logger created using + * the package name of this class or extended class if the method is overridden + * in the extended class. + * + * @param workspaceRoot the workspace root for the new version of the + * component that will replace the currently installed version. This is + * populated with the contents of the original workspace root and the + * component must update it to match the new version of the component. + * @param serviceUnitRoots a list of directory paths to all of the Service + * Units currently deployed to the component. The component must update all + * of these to match the new version of the component. + * @exception JBIException when there is an error requiring that the upgrade + * be terminated. + */ + public void upgrade(String workspaceRoot, List serviceUnitRoots) + throws javax.jbi.JBIException + { + //TODO: override this method in the extended class to handle the + // workspace root and service unit roots upgrade according to the + // component's requirement. + this.getLogger().fine("Default upgrade implementation. " + + "TODO: Implement workspace root and service unit roots upgrade."); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/ComponentRuntime.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/ComponentRuntime.java new file mode 100644 index 000000000..5c32ce274 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/ComponentRuntime.java @@ -0,0 +1,174 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ComponentRuntime.java + */ +package net.openesb.component.${artifactId}.common; + +import java.util.logging.Logger; +import javax.jbi.component.Component; +import javax.jbi.component.ComponentContext; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.component.ServiceUnitManager; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.servicedesc.ServiceEndpoint; +import org.w3c.dom.Document; +import org.w3c.dom.DocumentFragment; + +/** + * This class implements javax.jbi.component.Component interface which is + * responsible for creating the Component Lifecycle implementation and the + * ServiceUnitManager implementation for the jbi component. + * + * This class makes sure that non null component lifecycle implementation is + * returns by this class or any classes extended from this class which is + * required as a component contract. It also provides default implementation of + * all methods of the Component interface which the extended classes can + * override to add more functionality. + * + * @see javax.jbi.component.Component + * @author chikkala + */ +public class ComponentRuntime implements Component { + /** Component LifeCycle implementation */ + private ComponentLifeCycle mLifeCycle; + /** ServiceUnitManager implementation */ + private ServiceUnitManager mSUManager; + /** default logger*/ + private Logger mDefLogger; + + /** Creates a new instance of ComponentImpl */ + public ComponentRuntime() { + this.mLifeCycle = null; + this.mSUManager = null; + } + /** + * returns the ComponentContext. Any component runtime class extended from + * this class can override this method to return their own reference to the + * ComponentContext. + * @return ComponentContext component context. + */ + public ComponentContext getComponentContext() { + ComponentContext ctx = null; + if ( this.mLifeCycle != null && this.mLifeCycle instanceof BasicComponentLifeCycle ) { + ctx = ((BasicComponentLifeCycle) this.mLifeCycle).getComponentContext(); + } + return ctx; + } + /** + * Returns logger initialized from the component context or a default logger. + * @return Logger + */ + public Logger getLogger() { + Logger logger = null; + if ( this.mLifeCycle != null && this.mLifeCycle instanceof BasicComponentLifeCycle ) { + logger = ((BasicComponentLifeCycle) this.mLifeCycle).getLogger(); + } + // init default logger if required + if ( logger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (logger != null) ? logger : this.mDefLogger; + } + /** + * return the ComponentLifeCycle implementation. if returned null, the + * ComponentLifeCycleImpl will be used as the component lifecycle + * Extended classes can override this method and do their own ComponentLifecyle + * specific creation. + */ + protected ComponentLifeCycle createComponentLifeCycle() { + return new BasicComponentLifeCycle(this); + } + /** + * Get the life cycle control interface for this component. + * + * @return the life cycle control interface for this component + * @see javax.jbi.Component${symbol_pound}getLifeCycle() + */ + public final ComponentLifeCycle getLifeCycle() { + if ( this.mLifeCycle == null ) { + this.mLifeCycle = createComponentLifeCycle(); + if ( this.mLifeCycle == null ) { + this.getLogger().fine("Creating basic component lifecycle implemenation"); + // use the default ComponentLifeCycle Impl if a component + // specific implementation return null in createComponentLifeCycle. + this.mLifeCycle = new BasicComponentLifeCycle(this); + } + } + return this.mLifeCycle; + } + /** + * if this component supports service unit deployment, then return the + * service unit manager, else return null. + * Extended classes can override this method and do their own ServiceUnitManager + * specific creation. + */ + protected ServiceUnitManager createServiceUnitManager() { + return null; + } + /** + * Get the Service Unit manager for this component. + * + * @return the ServiceUnitManager for this component, or + * null if there is none. + * @see javax.jbi.Component${symbol_pound}getServiceUnitManager() + */ + public final ServiceUnitManager getServiceUnitManager() { + if ( this.mSUManager == null ) { + this.mSUManager = createServiceUnitManager(); + } + return this.mSUManager; + } + /** + * Retrieves a DOM representation containing metadata which describes the + * service provided by this component, through the given endpoint. + * + * Default implementation does not support service description. + * + * @see javax.jbi.Component${symbol_pound}getServiceDescription(javax.jbi.servicedesc.ServiceEndpoint) + */ + public Document getServiceDescription(ServiceEndpoint serviceEndpoint) { + return null; + } + /** + * This method is called by JBI to check if this component, in the role of + * provider of the service indicated by the given exchange, can actually + * perform the operation desired. + * + * Default implementation has no policy and allows all exchanges with consumer. + * + * @see javax.jbi.Component${symbol_pound}isExchangeWithProviderOkay( + * javax.jbi.servicedesc.ServiceEndpoint, javax.jbi.messaging.MessageExchange) + */ + public boolean isExchangeWithConsumerOkay( + ServiceEndpoint serviceEndpoint, MessageExchange messageExchange) { + return true; + } + /** + * This method is called by JBI to check if this component, in the role of + * consumer of the service indicated by the given exchange, can actually + * interact with the provider properly. The provider is described by the + * given endpoint and the service description supplied by that endpoint. + * + * Default implementation has no policy and allows all exchanges with provider. + * + * @see javax.jbi.Component${symbol_pound}isExchangeWithProviderOkay( + * javax.jbi.servicedesc.ServiceEndpoint, javax.jbi.messaging.MessageExchange) + */ + public boolean isExchangeWithProviderOkay( + ServiceEndpoint serviceEndpoint, MessageExchange messageExchange) { + return true; + } + /** + * Resolve the given endpoint reference. + * + * Default implementation does not have any XML dialect. So can not resolve the + * endpoint from the document fragment. + * + * @see javax.jbi.Component${symbol_pound}resolveEndpointReference(org.w3c.dom.DocumentFragment) + */ + public ServiceEndpoint resolveEndpointReference(DocumentFragment documentFragment) { + return null; + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java new file mode 100644 index 000000000..51c85bc6e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java @@ -0,0 +1,180 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * DefaultMessageExchangeReceiver.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import javax.jbi.JBIException; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; + +/** + * This class implements MessageExchangeReceiver interface. This is a default implementation that + * demonstrates the multi-threaded environment to receive and process message exchanges from the + * delivery channel. It uses a main thread to receive message exchanges from the delivery channel + * and then processes the received message exchanges in a individual threads from the thread pool. + * The controller methods of MessageExchangeReceiver controls the main thread and the thread pool + * execution. + * + * @author chikkala + */ +public class DefaultMessageExchangeReceiver implements MessageExchangeReceiver { + + /** delivery channel accept time out */ + private final static long DC_ACCEPT_TIME_OUT = 3000; // milliseconds + /** receiver thread wait time before polling for messages after woke up **/ + private final static long RECEIVER_WAIT_TIME = 2000; // milliseconds + /** receiver thread wait time before force shutdown */ + private final static long RECEIVER_SHUTDOWN_WAIT_TIME = 10; // seconds + /** handler threads wait time before forced shutdown */ + private final static long HANDLERS_SHUTDOWN_WAIT_TIME = 30; // seconds + /** handler thread pool size */ + private final static int HANDLER_THREAD_POOL_SIZE = 5; + /** receiver thread accept message exchange condition */ + private Boolean mCanAccept = false; + /** receiver thread termination condition */ + private Boolean mContinue = true; + /** receiver thread executor service */ + private ExecutorService mReceiverThreadMgr; + /** handler thread executor service */ + private ExecutorService mHandlerThreadPool; + + /** no default constructor for extended classes */ + public DefaultMessageExchangeReceiver() { + } + /** + * this method is called from the ComponentLifecyle.init method of the AbstractComponentLifecycle + * to initialize the message exchange receiving resources such as threads and thread pools + * throws JBIException on error + */ + public final void initReceiver() throws JBIException { + + this.mHandlerThreadPool = Executors.newFixedThreadPool(HANDLER_THREAD_POOL_SIZE); + this.mReceiverThreadMgr = Executors.newSingleThreadExecutor(); + + this.mReceiverThreadMgr.execute(new Runnable() { + public void run() { + Thread t = Thread.currentThread(); + while ( mContinue ) { + if (mCanAccept) { + receiveAndProcessMessageExchange(); + } else { + try { + t.sleep(RECEIVER_WAIT_TIME); + } catch (InterruptedException interruptException) { + // someone must have interrupted this thread + // do nothing + RuntimeHelper.logDebug("Interrupted the MessageReceiverThread in Sleep"); + } + } + } + } + }); + } + /** + * this method is called from the ComponentLifecyle.shutdown method of the AbstractComponentLifecycle + * to cleanup the message exchange receiving resources such as threads and thread pools. + * throws JBIException on error + */ + public final void shutdownReceiver() throws JBIException { + + synchronized ( mContinue ) { + mContinue = false; + } + boolean terminated = false; + try { + this.mReceiverThreadMgr.shutdown(); + terminated = this.mReceiverThreadMgr.awaitTermination( + RECEIVER_SHUTDOWN_WAIT_TIME, TimeUnit.SECONDS); + } catch (InterruptedException ex) { + RuntimeHelper.logDebug(ex); + } finally { + if ( !terminated ) { + RuntimeHelper.logDebug("Message Receiver not shutdown. Forcing shutdown"); + this.mReceiverThreadMgr.shutdownNow(); + } + } + shutdownHandlers(); + } + /** + * shutdown all the working threads from the thread pool. + */ + private final void shutdownHandlers() throws JBIException { + + boolean terminated = false; + try { + this.mHandlerThreadPool.shutdown(); + terminated = this.mHandlerThreadPool.awaitTermination( + HANDLERS_SHUTDOWN_WAIT_TIME, TimeUnit.SECONDS); + } catch (InterruptedException ex) { + RuntimeHelper.logDebug(ex); + } finally { + if ( !terminated ) { + RuntimeHelper.logDebug("Handler threads not shutdown. Forcing shutdown"); + this.mHandlerThreadPool.shutdownNow(); + } + } + } + /** + * this method is called from the ComponentLifecyle.start method of the AbstractComponentLifecycle + * to start receiving the message exchanges from the delivery channel and process them. + * throws JBIException on error + */ + public final void startProcessing() throws JBIException { + + synchronized ( this.mCanAccept ) { + this.mCanAccept = true; + } + } + /** + * this method is called from the ComponentLifecyle.stop method of the AbstractComponentLifecycle + * to stop receiving the message exchanges from the delivery channel. + * throws JBIException on error + */ + public final void stopProcessing() throws JBIException { + + synchronized ( this.mCanAccept ) { + this.mCanAccept = false; + } + } + + protected MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeHelper.getMessageExchangeSupport(); + } + + private void receiveAndProcessMessageExchange() { + try { + DeliveryChannel channel = RuntimeHelper.getDeliveryChannel(); + if ( channel == null ) { + RuntimeHelper.logDebug("DeliveryChannel Not Opened for receiving messages"); + return; + } + final MessageExchange msgExchange = channel.accept(DC_ACCEPT_TIME_OUT); + if ( msgExchange == null ) { + // delivery channel timeout occurred. do nothing. + // RuntimeHelper.logDebug("DeliveryChannel returned null message exchange from accept"); + return; + } + final ExchangeStatus status = msgExchange.getStatus(); + // process message exchange in a separate thread + this.mHandlerThreadPool.execute(new Runnable() { + public void run() { + getMessageExchangeSupport().fireMessageExchangeReceived(status, msgExchange); + } + }); + + } catch (MessagingException ex) { + RuntimeHelper.logWarning(ex); + ex.printStackTrace(); + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java new file mode 100644 index 000000000..fed6c987d --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java @@ -0,0 +1,31 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * MessageExchangeHandler.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; + +/** + * This interface is a Handler to perform message exchanges when the component + * receives the MessageExchange object from the delivery channel. + * Implementation of this interface should implement the processing of + * the active, error, done status of the MessageExchange object according to + * the MEP for which the MessageExchange object is created. + * + * @author chikkala + */ +public interface MessageExchangeHandler { + /** + * this method will be invoked to process the MessageExchange + * object. + * @param msgExchange MessageExchange object to process. + */ + void processMessageExchange(ExchangeStatus status, MessageExchange msgExchange); + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeListener.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeListener.java new file mode 100644 index 000000000..c27c1f221 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeListener.java @@ -0,0 +1,36 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * MessageExchangeListener.java + */ + +package net.openesb.component.${artifactId}.common; + +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; + +/** + * This interface defines the notification mechanism with which the message exchange object received + * from the delivery channel is processed by the interesting parties. A particular service endpoint + * implementation would first register the implementation of this interface with MessageExchangeSupport + * to get the notification of a received message exchange on a particular service endpoint and the + * implementation of the interface would process the message exchange when notified. + * + * When the com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver receives the message exchange + * object, it asks the MessageExchangeSupport to notify the MessageExchangeLister that is registered for the + * received message exchange object to process the message exchange object. + * @see com.sun.jbi.sample.component.common.MessageExchangeSupport + * @see com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @author chikkala + */ +public interface MessageExchangeListener { + /** + * MessageExchangeSupport will call this method to notify the lister implementation that a + * message exchange is received from the delivery channel. + * @param me MessageExchange Object + */ + void messageExchangeReceived(ExchangeStatus status, MessageExchange me); +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java new file mode 100644 index 000000000..607146abd --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java @@ -0,0 +1,47 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * MessageExchangeReceiver.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import javax.jbi.JBIException; + +/** + * This interface provides the methods can controls the receiving and processing of the message + * exchange objects from the delivery channel during the component lifecycle operations. + * The implementation of this interface can use multi-threaded environment to receive and process + * message exchanges from the delivery channel during the component lifecycle. + * @see com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver + * @author chikkala + */ +public interface MessageExchangeReceiver { + /** + * this method is called from the ComponentLifecyle.init method of the AbstractComponentLifecycle + * to initialize the message exchange receiving resources such as threads and thread pools + * throws JBIException on error + */ + void initReceiver() throws JBIException; + /** + * this method is called from the ComponentLifecyle.start method of the AbstractComponentLifecycle + * to start receiving the message exchanges from the delivery channel and process them. + * throws JBIException on error + */ + void startProcessing() throws JBIException; + /** + * this method is called from the ComponentLifecyle.stop method of the AbstractComponentLifecycle + * to stop receiving the message exchanges from the delivery channel. + * throws JBIException on error + */ + void stopProcessing() throws JBIException; + /** + * this method is called from the ComponentLifecyle.shutdown method of the AbstractComponentLifecycle + * to cleanup the message exchange receiving resources such as threads and thread pools. + * throws JBIException on error + */ + void shutdownReceiver() throws JBIException; + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java new file mode 100644 index 000000000..bddf9a8b1 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java @@ -0,0 +1,170 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * MessageExchangeSupport.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessageExchange.Role; +import javax.xml.namespace.QName; + +/** + * This class supports the registering and unregistering MessageExchangeListeners and the + * MessageExchangeHandlers that can be used to process the received message exchange from a + * delivery channel. A global reference to this class will be created in RuntimeContext object to + * provide access to this class from any where in the component runtime. + * + * A ProviderEndpoint or ConsumerEndpoint interested in a MessageExchange received from a delivery + * channel for a particular service endpoint will register the MessageExchangeListener with this + * class. The DefaultMessageExchangeReceiver when received a message exchange object from the delivery + * channel uses MessageExchangeSupport.processMessageExchange method to notify the registered listener. + * + * The MessageExchangeListener implementation ( ProviderEndpoint or ConsumerEndpoint ) while processing + * received message ( messageExchangeReceived()) will create and register the message exchange handlers + * to process the message exchange. + * + * @see RuntimeContext${symbol_pound}getMessageExchangeSupport + * @see RuntimeHelper${symbol_pound}getMessageExchangeSupport + * @see DefaultMessageExchangeReceiver${symbol_pound}receiveAndProcessMessageExchange + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @author chikkala + */ +public class MessageExchangeSupport { + /** listener map to notify a message exchange received event */ + private Map mListeners; + /** handlers that can process the message exchange */ + private Map mHandlers; + /** Creates a new instance of MessageExchangeSupport */ + public MessageExchangeSupport() { + this.mListeners = Collections.synchronizedMap(new HashMap()); + this.mHandlers = Collections.synchronizedMap(new HashMap()); + } + /** + * generates key that will be used to store the MessageExchangeListener objects. + * @param serviceName QName of the service + * @param endpointName endpoint name of the service. + */ + public String createListenerKey(Role role, QName interfaceName, QName serviceName, String endpointName) { + + StringBuffer strBuff = new StringBuffer(); + strBuff.append(interfaceName).append("+"); + strBuff.append(serviceName).append("+"); + strBuff.append(endpointName).append("+"); + String roleType = null; + if ( Role.CONSUMER.equals(role) ) { + roleType = "CONSUMER"; + } else if ( Role.PROVIDER.equals(role) ) { + roleType = "PROVIDER"; + } + strBuff.append(roleType); + return strBuff.toString(); + } + /** + * adds message exchange listener who are interested in receiving the notification when the + * message exchange is received from delivery channel. The listener can be registered with the + * following combination of the parameters: (role,interfaceName,serviceName, endpointName), + * (role,interfaceName,null, null), (role, null,serviceName, endpointName), (role, null,serviceName, null) + * + * @param role role of the message exchange listener PROVIDER or CONSUMER - can not be null. + * @param interfaceName QName of the interface ( protType ) - can be null if the serviceName is not null + * @param serviceName QName of the service - can be null if interfaceName is not null. + * @param endpointName endpoint name of the service. - can be null if the serviceName is not null. + * @param listener MessageExchangeListener object + */ + public synchronized void addMessageExchangeListener(Role role, QName interfaceName, QName serviceName, String endpointName, MessageExchangeListener listener) { + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + this.mListeners.put(key, listener); + } + /** + * removes any message exchange listener registered for the service endpoint specified by the serviceName and + * endpoint name. + * @param serviceName QName of the service + * @param endpointName endpoint name of the service. + */ + public synchronized void removeMessageExchangeListener(Role role, QName interfaceName, QName serviceName, String endpointName) { + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + MessageExchangeListener listener = this.mListeners.remove(key); + if ( listener == null ) { + RuntimeHelper.getLogger().fine("No message exchange listener removed with key " + key); + } + } + /** + * finds the MessageExchangeListner registers for the endpoint for which the message exchange is + * received and call the method on the listener + */ + public boolean fireMessageExchangeReceived(ExchangeStatus status, MessageExchange me) { + boolean notified = false; + Role role = me.getRole(); + QName interfaceName = me.getInterfaceName(); + QName serviceName = me.getEndpoint().getServiceName(); + String endpointName = me.getEndpoint().getEndpointName(); + // lookup with complete service description ( role + interface + service + endpoint ) + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + MessageExchangeListener listener = this.mListeners.get(key); + + if ( listener == null ) { // lookup with role+interface name + key = createListenerKey(role, interfaceName, null, null); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { // lookup with role + serviceName + endpointName + key = createListenerKey(role, null, serviceName, endpointName); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { // lookup with with role + serviceName + key = createListenerKey(role, null, serviceName, null); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { + RuntimeHelper.getLogger().fine("Could not find listener for message exchange" + me); + notified = false; + } else { + listener.messageExchangeReceived(status,me); + notified = true; + } + return notified; + } + /** + * registers the MessageExchangeHandler implementation against the message exchange id. + * @param me MessageExchange for which the handler need to be assigned + * @param handler MessageExchangeHandler implementation that will be registers. + */ + public synchronized void addMessageExchangeHandler(MessageExchange me, MessageExchangeHandler handler) { + this.mHandlers.put(me.getExchangeId(), handler); + } + /** + * removes the MessageExchangeHandler for the particular message exchange object + */ + public synchronized void removeMessageExchangeHandler(MessageExchange me) { + MessageExchangeHandler handler = this.mHandlers.remove(me.getExchangeId()); + if ( handler == null ) { + RuntimeHelper.getLogger().fine("No MessageExchangeHandler found for removing " + me.getExchangeId()); + } + } + /** + * looks up the registered message exchange handler for the message exchange object + * @param me MessageExchangeHandler. + */ + public synchronized MessageExchangeHandler findMessageExchangeHandler(MessageExchange me) { + return this.mHandlers.get(me.getExchangeId()); + } + /** + * looks up the registered message exchange handler for the message exchange object with Id + * @param exchangeId message exchange object's id + */ + public synchronized MessageExchangeHandler findMessageExchangeHandler(String exchangeId) { + return this.mHandlers.get(exchangeId); + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeContext.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeContext.java new file mode 100644 index 000000000..be75c7b7d --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeContext.java @@ -0,0 +1,176 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * RuntimeContext.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import java.util.logging.Logger; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; + +/** + * This class is global context for all the component runtime to store and + * retrieve the information that should be available anywhere in the component runtime. + * + * Each instance variable of this class will be initialized at various points of the + * component runtime using setter methods on this class. + * + * The two important objects that will be initialized and available from this context are + * ComponentContext and the opened DeliveryChannel objects both of which will be set from the + * implementation {@link BasicComponentLifeCycle}. + * + * Note that the ComponentContext from this global context will not be available until + * the jbi framework calls the init method of the ComponentLifeCycle of the component and + * then intern the implementation of the init method sets the context. + * + * @see BasicComponentLifeCycle${symbol_pound}initGlobalContext + * @see BasicComponentLifeCycle${symbol_pound}openDeliveryChannel + * @see BasicComponentLifeCycle${symbol_pound}closeDeliveryChannel + * @author chikkala + */ +public final class RuntimeContext { + /** RuntimeContext singleton instance */ + private static RuntimeContext sRuntimeContext; + /** default logger*/ + private Logger mDefLogger; + /** Logger object. */ + private Logger mLogger; + /** Holds value of property ComponentContext. */ + private ComponentContext mComponentContext; + /** Holds value of property DeliveryChannel. */ + private DeliveryChannel mDeliveryChannel; + /** MessageExchange processing support **/ + private MessageExchangeSupport mMESupport; + + /** outside code can not instantiate RuntimeContext */ + private RuntimeContext() { + } + /** + * @return RuntimeContext instance. + */ + public static RuntimeContext getInstance() { + if ( sRuntimeContext == null ) { + synchronized (RuntimeContext.class) { + if ( sRuntimeContext == null ) { + sRuntimeContext = new RuntimeContext(); + } + } + } + return sRuntimeContext; + } + /** + * Getter for to obtaining ComponentContext from any where in the component runtime. + * @return ComponentContext. + */ + public ComponentContext getComponentContext() { + return this.mComponentContext; + } + /** + * Sets the Component context reference in Runtime context for global access + * any class in the component runtime. + * com.sun.jbi.sample.component.common.AbstractComponentLifeCycle${symbol_pound}initContext + * method implementation should call this method to set the global context. + * see com.sun.jbi.sample.component.common.DefaultComponentLifeCycle${symbol_pound}initContext + * for details. + * @param componentContext New value of property ComponentContext. + * @see BasicComponentLifeCycle${symbol_pound}initGlobalContext + */ + public void setComponentContext(ComponentContext componentContext) { + if ( this.mComponentContext != null ) { + (new IllegalStateException("Component Context already " + + "initialized in RuntimeContext")).printStackTrace(); + } + this.mComponentContext = componentContext; + } + /** + * Getter for obtaining opened delivery channel from any where in the component runtime. + * @return DeliveryChannel. + */ + public DeliveryChannel getDeliveryChannel() { + return this.mDeliveryChannel; + } + /** + * Sets the opened delivery channel reference in Runtime context for global access + * any class in the component runtime. + * com.sun.jbi.sample.component.common.AbstractComponentLifeCycle${symbol_pound}initContext + * method implementation should call this method to set the global context. + * see com.sun.jbi.sample.component.common.DefaultComponentLifeCycle${symbol_pound}initContext + * for details. + * + * @param componentContext New value of property ComponentContext. + */ + public void setDeliveryChannel(DeliveryChannel deliveryChannel) { + if ( deliveryChannel != null && this.mDeliveryChannel != null ) { + (new IllegalStateException("Delivery Channel already " + + "initialized in RuntimeContext")).printStackTrace(); + } + this.mDeliveryChannel = deliveryChannel; + } + /** + * Sets the logger. + * + * @param name name for the Logger. + * @param resourceBundle resource bundle for the logger. can be null. + */ + public void setLogger(String name, String resourceBundle) { + + if (this.mComponentContext != null) { + // get the logger from component context if the component context is not null + try { + this.mLogger = this.mComponentContext.getLogger(name, resourceBundle); + } catch (Exception ex) { + ex.printStackTrace(); + } + } else { + this.mDefLogger = Logger.getLogger(name, resourceBundle); + } + } + /** + * Returns the logger. + * + * @return Logger + */ + public Logger getLogger() { + + // try init logger + if (this.mLogger == null && this.mComponentContext != null ) { + try { + this.mLogger = + this.mComponentContext.getLogger(this.getClass().getName(), null); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + // init default logger if required + if ( this.mLogger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (this.mLogger != null) ? this.mLogger : this.mDefLogger; + } + /** + * Returns the Component Name if the ComponentContext is set. else null + * @return component name + */ + public String getComponentName() { + String componentName = null; + if (this.mComponentContext != null) { + componentName = this.mComponentContext.getComponentName(); + } + return componentName; + } + /** + * Global MessageExchangeSupport reference. Various classes in the common + * component runtime would use this method to obtain the MessageExchangeSupport + * for processing message exchange objects received from delivery channel. + */ + public MessageExchangeSupport getMessageExchangeSupport() { + if ( this.mMESupport == null ) { + this.mMESupport = new MessageExchangeSupport(); + } + return this.mMESupport; + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeHelper.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeHelper.java new file mode 100644 index 000000000..f12c2b2f4 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeHelper.java @@ -0,0 +1,360 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * RuntimeHelper.java + */ + +package net.openesb.component.${artifactId}.common; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stream.StreamResult; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * This is a helper class that have bunch of methods for xml processing. + * @author chikkala + */ +public class RuntimeHelper { + + public static Logger getLogger() { + return RuntimeContext.getInstance().getLogger(); + } + + public static void logWarning(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.WARNING, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().warning(logObj.toString()); + } + } + + public static void logError(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.SEVERE, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().severe(logObj.toString()); + } + } + + public static void logDebug(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.FINER, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().finer(logObj.toString()); + } + } + + public static String getComponentName() { + return RuntimeContext.getInstance().getComponentName(); + } + public static ComponentContext getComponentContext() { + return RuntimeContext.getInstance().getComponentContext(); + } + public static DeliveryChannel getDeliveryChannel() { + return RuntimeContext.getInstance().getDeliveryChannel(); + } + + public static MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeContext.getInstance().getMessageExchangeSupport(); + } + + /** + * return the DOM Document + * @param xmlReader Reader + * @return dom document + * @throws Exception on parser exception or any other exception + */ + public static Document buildDOMDocument(Reader xmlReader) throws Exception { + InputSource xmlSource = new InputSource(xmlReader); + return buildDOMDocument(xmlSource); + } + /** + * return the DOM Document + * @param xmlReader Reader + * @return dom document + * @throws Exception on parser exception or any other exception + */ + public static Document buildDOMDocument(InputSource xmlSource) throws Exception { + Document xmlDoc = null; + DocumentBuilderFactory docBuilderFactory = + DocumentBuilderFactory.newInstance(); + docBuilderFactory.setValidating(false); + docBuilderFactory.setNamespaceAware(true); + DocumentBuilder docBuilder = + docBuilderFactory.newDocumentBuilder(); + docBuilder.setErrorHandler( new DefaultHandler() { + public void fatalError(SAXParseException e) + throws SAXException { + throw new SAXException(e.getMessage()); + } + }); + + docBuilder.setEntityResolver(new EntityResolver() { + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException, IOException { + StringReader reader = + new StringReader(""); // NOI18N + InputSource source = new InputSource(reader); + source.setPublicId(publicId); + source.setSystemId(systemId); + return source; + } + }); + + xmlDoc = docBuilder.parse(xmlSource); + + return xmlDoc; + } + /** + * reads xml text from DOMSource to StringBuffer + */ + public static StringBuffer readFromDOMSource(DOMSource domSource) { + + StringWriter writer = new StringWriter(); + + TransformerFactory tFactory = TransformerFactory.newInstance(); + Transformer trans = null; + try { + trans = tFactory.newTransformer(); + trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, + "yes"); + trans.setOutputProperty(OutputKeys.INDENT, "yes"); + StreamResult result = new StreamResult(writer); + trans.transform(domSource, result); + } catch (TransformerConfigurationException ex) { + ex.printStackTrace(); + } catch (TransformerException ex) { + ex.printStackTrace(); + } + + return writer.getBuffer(); + } + /** + * reads the xml text from InputSource into a StringBuffer + */ + public static StringBuffer readFromInputSource(InputSource inSource) { + + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + InputStream inStream = inSource.getByteStream(); + Reader reader = inSource.getCharacterStream(); + if ( reader == null ) { + reader = new InputStreamReader(inStream); + } + BufferedReader buff = new BufferedReader(reader); + try { + + for ( String line = null; (line = buff.readLine()) != null ; ) { + out.println(line); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + + return writer.getBuffer(); + } + /** + * reads xml from from DOM, SAX or Stream Source into a string buffer + */ + public static StringBuffer readFromSource(Source source) { + if ( source instanceof DOMSource ) { + return readFromDOMSource((DOMSource)source); + } else { + InputSource inSource = SAXSource.sourceToInputSource(source); + if ( inSource != null ) { + return readFromInputSource(inSource); + } else { + return null; + } + } + } + /** + * creates a DOMSource from the xml text read from the reader. + */ + public static DOMSource createDOMSource(Reader xmlReader) { + Document doc = null; + try { + doc = buildDOMDocument(xmlReader); + } catch (Exception ex) { + ex.printStackTrace(); + } + return new DOMSource(doc); + } + /** + * creates a DOMSource from any source. If the source itself is DOMSource, + * the source is returned as it is as DOMSource. + */ + public static DOMSource sourceToDOMSource(Source source) { + if ( source instanceof DOMSource) { + return (DOMSource) source; + } + InputSource xmlSource = SAXSource.sourceToInputSource(source); + Document doc = null; + try { + doc = buildDOMDocument(xmlSource); + } catch (Exception ex) { + ex.printStackTrace(); + } + return new DOMSource(doc); + } + /** + * converts the ex stracktrace to string. + */ + public static StringBuffer getExceptionStackTrace(Exception ex) { + StringWriter strWriter = new StringWriter(); + if ( ex != null ) { + PrintWriter out = new PrintWriter(strWriter); + ex.printStackTrace(out); + } + return strWriter.getBuffer(); + } + /** + * may be used to set the exception as fault content. + */ + public static String getExceptionAsXmlText(Exception ex) { + String message = replaceXmlEscapeCharsToEntityRefereces(ex.getMessage()); + String stackTrace = replaceXmlEscapeCharsToEntityRefereces( + getExceptionStackTrace(ex).toString()); + String exXmlText = + "" + + "" + message + "" + + "" + stackTrace + "" + + "" ; + return exXmlText; + } + + /** + * may be used to set the exception as fault content. + */ + public static String getExceptionAsText(Exception ex) { + String message = replaceXmlEscapeCharsToEntityRefereces(ex.getMessage()); + String stackTrace = replaceXmlEscapeCharsToEntityRefereces( + getExceptionStackTrace(ex).toString()); + StringBuffer buff = new StringBuffer(); + buff.append(message); + buff.append(System.getProperty("line.separator", "${symbol_escape}n")); + buff.append(stackTrace); + return buff.toString(); + } + + + /** + * For attribute values which denote a QName, i.e. include a namespace prefix, + * resolve the value into a QName. + * If a namespace can not be resolved, it is set to empty - it does not + * result in an exception + * @param attrValue the string value of the attribute + * @param element the element the attribute belongs to + */ + public static QName resolveAttrQName(String attrValue, Element element) { + int aColonLoc = attrValue.indexOf(":"); + String aLocalName = attrValue; + String aPrefix = null; + String aNS = null; + if (aColonLoc > -1) { + aPrefix = attrValue.substring(0, aColonLoc); + aLocalName = attrValue.substring(aColonLoc + 1); + + // Traverse up the hierarchy until a namespace definition is found + // or the top of the document is reached. + Node currNode = element; + while ((aNS == null || aNS.equals("")) && currNode != null) { + if (currNode.getNodeType() == Node.ELEMENT_NODE) { + aNS = ((Element) currNode).getAttribute("xmlns:" + aPrefix); + } + currNode = currNode.getParentNode(); + } + } + + QName qName = new QName(aNS, aLocalName, aPrefix); + + return qName; + } + + /** + * replaces the xml entity references with the xml escape chars + * @param xmlString Text with the xml escape chars + * @param Text with the xml entity references + */ + public static String replaceXmlEscapeCharsToEntityRefereces(String xmlString) { + if ( xmlString == null ) { + return xmlString; + } + + // just convert < , > and & only + StringBuffer sbuff = new StringBuffer(2 * xmlString.length()); + for ( int i = 0; i < xmlString.length(); ++i ) { + switch ( xmlString.charAt(i) ) { + case '&': sbuff.append("&"); + break; + case '<': sbuff.append("<"); + break; + case '>': sbuff.append(">"); + break; + default: sbuff.append( xmlString.charAt(i) ); + } + } + return sbuff.toString(); + } + + /** + * return Element node from a document node or non document. Use to extract + * the message root element. + * @root node from which the Element node will be extracted. + * @return Element node. + */ + public static Element getElement(Node root) { + Element msgEl = null; + if ( root instanceof Document) { + msgEl = ((Document)root).getDocumentElement(); + } else if (root instanceof Element) { + msgEl = (Element)root; + } else { + NodeList nodeList = root.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if ( node instanceof Element ) { + msgEl = (Element) node; + break; + } + } + } + return msgEl; + } + + public static Element getElement(DOMSource domSource) { + return getElement(domSource.getNode()); + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java new file mode 100644 index 000000000..fd0fc4f79 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java @@ -0,0 +1,312 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractServiceUnitManager.java + * + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.component.ServiceUnitManager; +import javax.jbi.management.DeploymentException; + +/** + * This is an abstract class that implements {@link javax.jbi.component.ServiceUnitManager} to provide a + * service unit deployment support for the component. The implementation supported by this service + * unit manager and related classes in this package provides WSDL1.1 based service unit deployment + * in the component. + * + * @see javax.jbi.component.ServiceUnitManager + * @see ServiceUnit + * + * @author chikkala + */ +public abstract class AbstractServiceUnitManager implements ServiceUnitManager { + + /** Map of ServiceUnit Name to the ServiceUnit Object for all the service units + * deployed in the component */ + private Map mSUMap; + + /** Creates a new instance of AbstractSUManager */ + protected AbstractServiceUnitManager() { + this.mSUMap = Collections.synchronizedMap(new HashMap()); + } + /** returns the component name + * @return component name. + */ + protected abstract String getComponentName(); + /** + * @return Logger + */ + protected abstract Logger getLogger(); + /** + * returns the creation of the ServiceUnit implementation specific to the service unit deployment + * for the component. + * @param suName service unit name + * @param suRootPath service unit root path + * @param concrete implementation of the ServiceUnit class. + */ + protected abstract ServiceUnit createServiceUnit(String suName, String suRootPath) + throws DeploymentException; + /** + * returns the service unit object deployed by the specified name. or null if not deployed. + * @param suName service unit name to look for + * @param ServiceUnit object for the suName. or null if not present. + */ + private ServiceUnit getServiceUnit(String suName) { + return this.mSUMap.get(suName); + } + /** + * lookup for the deployed service unit. If not there, throws a deployment exception. + * @param suName service unit name + * @return ServiceUnit object + * @throws DeploymentException if the service unit is not present. + */ + private ServiceUnit findServiceUnit(String suName) throws DeploymentException { + ServiceUnit serviceUnit = getServiceUnit(suName); + if ( serviceUnit == null ) { + throw new DeploymentException("Service unit " + suName + " does not exist"); + } + return serviceUnit; + } + /** + * add the service unit object to the list of deployed service units. if there is already a + * service unit present with the name, throws a deployment exception. + * @param su service unit to add + * @return ServiceUnit object that is added. + * @throws DeploymentException if the service unit already present. + */ + private ServiceUnit addServiceUnit(ServiceUnit su) throws DeploymentException { + String suName = su.getName(); + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU != null ) { + throw new DeploymentException("Service unit " + suName + "already exists"); + } + this.mSUMap.put(suName, su); + return su; + } + /** + * removes service unit object from the list of deployed service units. if there is no + * service unit present with the name, throws a deployment exception. + * @param su service unit to add + * @return ServiceUnit object that is being removed. + * @throws DeploymentException if the service unit already present. + */ + private ServiceUnit removeServiceUnit(ServiceUnit su) throws DeploymentException { + String suName = su.getName(); + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU == null ) { + throw new DeploymentException("Service unit " + suName + " does not exist"); + } + return this.mSUMap.remove(suName); + } + /** + * creates the concrete service unit implementation and calls the load method on it to initialize + * the created service unit. + * @param suName service unit name to create + * @param suRootPath service unit root path. + * @return ServiceUnit that is created and loaded. + */ + private ServiceUnit loadServiceUnit(String suName, String suRootPath) throws DeploymentException { + ServiceUnit serviceUnit = createServiceUnit(suName, suRootPath); + serviceUnit.doLoad(); + return serviceUnit; + } + /** + * deploys a service unit. it creates and loads the service unit object for the suName and then call + * doDeploy on the service unit and adds it to the deployed service unit list + * @return result as jbi management xml + * @throws DeploymentException if there is an error deploying. + */ + private synchronized String deployServiceUnit(String suName, String suRootPath) throws DeploymentException { + String result = suName; + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU != null ) { + throw new DeploymentException("Service unit " + suName + "already exists"); + } + ServiceUnit serviceUnit = loadServiceUnit(suName, suRootPath); + serviceUnit.doDeploy(); + addServiceUnit(serviceUnit); + return result; + } + /** + * Deploy a Service Unit to the component. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}deploy(String, String); + */ + public final String deploy(String suName, String suRootPath) throws DeploymentException { + this.getLogger().fine("Deploying service unit " + suName + " with suRootPath " + suRootPath); + String compName = this.getComponentName(); + boolean isSuccess = true; + String mainMsg = "Successfully deployed service unit " + suName; + Exception errEx = null; + try { + deployServiceUnit(suName, suRootPath); + } catch (Exception ex) { + isSuccess = false; + errEx = ex; + mainMsg = "Failed to deploy service unit " + suName ; + this.getLogger().log(Level.FINE, mainMsg, ex); + } + return createComponentTaskResultXML(compName, "deployTask", isSuccess, mainMsg, errEx); + } + + /** + * undeploys the service unit. it looks up the existing deployed service unit and call doUndeploy + * on it and then removes from the deployed service unit list. + */ + private synchronized String undeployServiceUnit(String suName, String suRootPath) throws DeploymentException { + String result = suName; + ServiceUnit serviceUnit = findServiceUnit(suName); + serviceUnit.doUndeploy(); + removeServiceUnit(serviceUnit); + return result; + } + /** + * Undeploy a service unit from the component. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}undeploy(String, String); + */ + public final String undeploy(String suName, String suRootPath) throws DeploymentException { + this.getLogger().fine("Undeploying service unit " + suName + " with suRootPath " + suRootPath); + String compName = this.getComponentName(); + boolean isSuccess = true; + String mainMsg = "Successfully undeployed service unit " + suName; + Exception errEx = null; + try { + undeployServiceUnit(suName, suRootPath); + } catch (Exception ex) { + isSuccess = false; + errEx = ex; + mainMsg = "Failed to undeploy service unit " + suName ; + this.getLogger().log(Level.FINE, mainMsg, errEx); + } + return createComponentTaskResultXML(compName, "undeployTask", isSuccess, mainMsg, errEx); + } + /** + * Initialize the given deployed service unit. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}init(String, String); */ + public final void init(String suName, String suRootPath) + throws DeploymentException { + this.getLogger().fine("Initializing service unit " + suName + " with suRootPath " + suRootPath); + String result = suName; + ServiceUnit serviceUnit = getServiceUnit(suName); + if ( serviceUnit == null ) { // if the service unit not exists, create and add + serviceUnit = loadServiceUnit(suName, suRootPath); // create and load service unit + addServiceUnit(serviceUnit); // add service unit to existing service units + } + serviceUnit.doInit(); // Do Service unit initialization tasks + this.getLogger().fine("Service unit initialized:" + suName); + } + /** + * Shut down the deployment. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}shutdown(String); + */ + public final void shutDown(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doShutdown(); // Do Service unit shutdown tasks + this.getLogger().fine("Service unit shut down:" + suName); + } + /** + * Start the deployed service unit. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}start(String); + */ + public final void start(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doStart(); // Do service unit start tasks. + this.getLogger().fine("Service unit started:" + suName ); + } + /** + * Stop the deployed service unit. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}stop(String); + */ + public final void stop(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doStop(); // do service unit stop tasks + this.getLogger().fine("Service unit stopped: " + suName + " stopped."); + } + + /** + * helper method to create result message as jbi management message xml. + * @param componentName name of the component for this xml. + * @param taskId task id + * @param isSuccess true to format a success result, false to format a failed result. + * @param mainMsg main result message + * @param errEx Exception, null if there is no exception in failure message. + * @return XML string. + */ + protected static String createComponentTaskResultXML( + String componentName, String taskId, boolean isSuccess, String mainMsg, Exception errEx ) { + + String exMsgXml = getComponentTaskResultExceptionXML(errEx); + String mainMsgXmlEsc = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces(mainMsg); + String taskResult = isSuccess ? "SUCCESS" : "FAILED"; + String msgType = isSuccess ? "INFO" : "ERROR"; + + String xmlResult = + "" + + " " + componentName + "" + + " " + + " " + + " " + taskId + "" + + " " + taskResult + "" + + " " + msgType + "" + + " " + + " " + + " SU_MGR_MSG_ID" + + " " + mainMsgXmlEsc + "" + + " " + + " " + + exMsgXml + + " " + + " " + + ""; + + return xmlResult; + } + /** + * converts the exception to the jbi management message xml chunk. + */ + private static String getComponentTaskResultExceptionXML(Exception errEx) { + StringBuffer exMsgBuff = new StringBuffer(); + if ( errEx == null ) { + return exMsgBuff.toString(); // empty string. + } + + List exList = new ArrayList(); + int exLevel = 0; + for ( Throwable cause = errEx ; cause != null ; cause = cause.getCause() ) { + String causeMsg = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces( + cause.getMessage()); + StringWriter stBuff = new StringWriter(); + PrintWriter stOut = new PrintWriter(stBuff); + StackTraceElement[] stList = cause.getStackTrace(); + for (StackTraceElement stEl : stList) { + stOut.println(stEl.toString()); + } + stOut.close(); + String causeStackTrace = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces( + stBuff.getBuffer().toString()); + + exMsgBuff.append(""); + exMsgBuff.append(" " + exLevel + ""); + exMsgBuff.append(" " + "SU_MGR_EXP_ID"); + exMsgBuff.append(" " + causeMsg + ""); + exMsgBuff.append(" "); + exMsgBuff.append(" " + causeStackTrace + ""); + exMsgBuff.append(""); + ++exLevel; + } + + return exMsgBuff.toString(); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java new file mode 100644 index 000000000..e9537ca9e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java @@ -0,0 +1,208 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ConsumerEndpoint.java + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import javax.jbi.JBIException; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.InOnly; +import javax.jbi.messaging.InOut; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.messaging.MessageExchangeFactory; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +/** + * This class extends from Endpoint class and implements lifecycle methods functionality required for the + * endpoint for a service consumer. {@link ServiceUnit${symbol_pound}createConsumerEndpoint} creates the object of this + * type to implement the service consumer functionality. + * + * @see ServiceUnit${symbol_pound}createConsumerEndpoint + * @author chikkala + */ + +public class ConsumerEndpoint extends Endpoint { + /** + * This constructor initializes the endpoint with CONSUMER role and makes sure that the service + * description passed to it is of consumer description. + */ + protected ConsumerEndpoint(SUDescriptor.Consumes consumes, Definition wsdlDef, ServiceUnit su) { + super(Role.CONSUMER, consumes, wsdlDef, su); + } + /** + * constructor that does not need service unit information. useful for creating the endpoint for + * static services provided by the component. + */ + protected ConsumerEndpoint(SUDescriptor.Consumes consumes, Definition wsdlDef) { + this(consumes, wsdlDef, null); + } + public final void init() throws JBIException { + getLogger().fine("ConsumerEndpoint: init called"); + doInit(); //1. initialize the endpiont resources + addMessageExchangeListener(); //2. register message exchange linster. + } + public final void activate() throws JBIException { + getLogger().fine("ConsumerEndpoint: activate called"); + //1. do common ativation tasks. + doActivate(); //2. do any other activation related tasks. + } + + public final void deactivate() throws JBIException { + getLogger().fine("ConsumerEndpoint: deactivate called"); + //1. do common deactivation tasks. + doDeactivate(); //2. do any other deactivation related tasks. + } + + public final void clean() throws JBIException { + getLogger().fine("ConsumerEndpoint: clean called"); + removeMessageExchangeListener(); //1. remove message exchange listener + doClean(); //2. clean up any other resources. + } + + protected void doInit() throws JBIException { + //NOOP + } + protected void doActivate() throws JBIException { + //NOOP + } + protected void doDeactivate() throws JBIException { + //NOOP + } + protected void doClean() throws JBIException { + //NOOP + } + + /** + * helper method to find the active ServiceEndpiont for the service described with the + * serviceDescriptor. This method looks for the Active ServiceEndpoint using interface or + * service name or service name and the endpoint name. + */ + public ServiceEndpoint findServiceEndpoint() { + + QName serviceType = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + + ServiceEndpoint [] refs = null; + ServiceEndpoint serviceEndpoint = null; + ComponentContext compContext = this.getComponentContext(); + + if ( compContext == null ) { + this.getLogger().info("Null Component context. Can not find ServiceEndpoint"); + return null; + } + // lookup ServiceEndpiont with concrete service(serice qname + endpoint name). + if ( serviceName != null && endpointName != null ) { + this.getLogger().info("Looking for ServiceEndpoint with:" + + " ServiceName: " + serviceName + " EndpointName: " + endpointName); + serviceEndpoint = compContext.getEndpoint(serviceName, endpointName); + } + // else lookup ServiceEndpiont with Service Name + if ( serviceEndpoint == null && serviceName != null && endpointName == null) { + this.getLogger().info("Looking for ServiceEndpoint with Service name: " + serviceName); + refs = compContext.getEndpointsForService(serviceName); + if ( refs != null && refs.length > 0 ) { + serviceEndpoint = refs[0]; + } + } + // else lookup ServiceEndpont with serviceType + if ( serviceEndpoint == null && serviceType != null && + serviceName == null && endpointName == null) { + this.getLogger().info("Looking for ServiceEndpoint with Service type: " + serviceType); + refs = compContext.getEndpoints(serviceType); + if ( refs != null && refs.length > 0 ) { + serviceEndpoint = refs[0]; + } + } + + return serviceEndpoint; + } + + /** + * this method creates a InOutMessageExchange Object and sets the required + * data on the MessageExchange object including the create and set the Normalized + * message object to hold the input message on the MessageExchange object. + */ + public InOut createInOutMessageExchange(QName operation) + throws MessagingException, JBIException { + + ServiceEndpoint serviceEndpoint = null; + // find a ServiceEndpoint activated by the Service Providers for this service + serviceEndpoint = findServiceEndpoint(); + + if ( serviceEndpoint == null ) { + // if not found a activated ServiceEndpoint for this service, throw exception. + throw new JBIException("Can not find an Active ServiceEndpoint for ${symbol_escape}n" + this.getService()); + } else { + this.setServiceEndpoint(serviceEndpoint); + } + + InOut inOutME = null; + DeliveryChannel channel = this.getDeliveryChannel(); + // create message exchange factory for the endpiont + MessageExchangeFactory factory = channel.createExchangeFactory(serviceEndpoint); + // create INOUT Message Exchange + inOutME = factory.createInOutExchange(); + // set operation + inOutME.setOperation(operation); + // set interface if that is not set + if ( inOutME.getInterfaceName() == null ) { + inOutME.setInterfaceName(this.getService().getInterface()); + } + // create IN Nomralized Message + NormalizedMessage inMsg = inOutME.createMessage(); + // set IN Normalized message on message exchange + inOutME.setInMessage(inMsg); + + return inOutME; + } + + /** + * this method creates a InOnlyMessageExchange Object and sets the required + * data on the MessageExchange object including the create and set the Normalized + * message object to hold the input message on the MessageExchange object. + */ + public InOnly createInOnlyMessageExchange(QName operation) + throws MessagingException, JBIException { + + ServiceEndpoint serviceEndpoint = null; + // find a ServiceEndpoint activated by the Service Providers for this service + serviceEndpoint = findServiceEndpoint(); + + if ( serviceEndpoint == null ) { + // if not found a activated ServiceEndpoint for this service, throw exception. + throw new JBIException("Can not find an Active ServiceEndpoint for ${symbol_escape}n" + this.getService()); + } else { + this.setServiceEndpoint(serviceEndpoint); + } + + InOnly inOnlyME = null; + DeliveryChannel channel = this.getDeliveryChannel(); + // create message exchange factory for the endpiont + MessageExchangeFactory factory = channel.createExchangeFactory(serviceEndpoint); + // create INOUT Message Exchange + inOnlyME = factory.createInOnlyExchange(); + // set operation + inOnlyME.setOperation(operation); + // set interface if that is not set + if ( inOnlyME.getInterfaceName() == null ) { + inOnlyME.setInterfaceName(this.getService().getInterface()); + } + // create IN Nomralized Message + NormalizedMessage inMsg = inOnlyME.createMessage(); + // set IN Normalized message on message exchange + inOnlyME.setInMessage(inMsg); + + return inOnlyME; + } + + +} \ No newline at end of file diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/Endpoint.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/Endpoint.java new file mode 100644 index 000000000..359114ed2 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/Endpoint.java @@ -0,0 +1,289 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * Endpoint.java + * + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.MessageExchangeHandler; +import net.openesb.component.${artifactId}.common.MessageExchangeListener; +import net.openesb.component.${artifactId}.common.MessageExchangeSupport; +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.xml.namespace.QName; + +/** + * This is an abstract class that represents the Endpoint defined for service provisioning or + * consumption in a jbi component. It stores the required service description ( wsdl definition, + * role, service unit to which it belongs etc) and defines the lifecycle operations {@link ${symbol_pound}init}, + * {@link ${symbol_pound}activate}, {@link ${symbol_pound}deactivate}, {@link ${symbol_pound}clean} to control a service endpoint that + * provides or consumes the service. + *

+ * Extended classes implement the abstract methods defined in this class to implement the endpoint + * functionality by providing the functionality to process the deployment artifacts specific to this + * endpoint, configure the endpoint to send/receive messages to/from delivery channel and process them + * according to the specific service implementation. + * + * @author chikkala + */ +public abstract class Endpoint { + /** Role of this endpoint. CONSUMER or PROVIDER */ + private Role mRole; + /** Service description from the SU descriptor for which this endpoint is configured */ + private SUDescriptor.Service mService; + /** WSDL definition corresponding to this endpoint */ + private Definition mWsdlDef; + /** service endpoint corresponding to this endpoint */ + private ServiceEndpoint mServiceEndpoint; + /** service unit from which this endpoint is created */ + private ServiceUnit mSU; // can be null + /** private constructor to force extended classes to use the parameterized constructor */ + private Endpoint() { + } + /** Creates a new instance of Endpoint + * @param role CONSUMER or PRVODER role. + * @param service service description from the su descriptor + * @param wsdl wsdl definition corresponding to this endpoint + * @param su service unit object which created this endpoint. + */ + protected Endpoint(Role role, SUDescriptor.Service service, Definition wsdl, ServiceUnit su) { + this.mService = service; + this.mRole = role; + this.mWsdlDef = wsdl; + this.mSU = su; + } + /** Creates a new instance of Endpoint without service unit. may be useful for static endpoints that + * are not part of the deployment + * @param role CONSUMER or PRVODER role. + * @param service service info from the su descriptor + * @param wsdl wsdl definition corresponding to this endpoint + */ + protected Endpoint(Role role, SUDescriptor.Service service, Definition wsdl) { + this(role, service, wsdl, null); + } + /** + * should be called to initialize any resources related to this endpoint object + * throws JBIException + */ + public abstract void init() throws JBIException; + /** + * activates the endpoint to send/receive messages + * throws JBIException + */ + public abstract void activate() throws JBIException; + /** + * deactivates the endpoint + * throws JBIException + */ + public abstract void deactivate() throws JBIException; + /** + * clean endpoint + * throws JBIException + */ + public abstract void clean() throws JBIException; + + public final Role getRole() { + return this.mRole; + } + public final boolean isProvider() { + return (Role.PROVIDER.equals(this.getRole())); + } + public final boolean isConsumer() { + return (Role.CONSUMER.equals(this.getRole())); + } + public final Definition getWSDL() { + return this.mWsdlDef; + } + public final SUDescriptor.Service getService() { + return this.mService; + } + public final ServiceEndpoint getServiceEndpoint() { + return this.mServiceEndpoint; + } + protected final void setServiceEndpoint(ServiceEndpoint svcEP) { + this.mServiceEndpoint = svcEP; + } + public final ServiceUnit getServiceUnit() { + return this.mSU; + } + /** + * generates an ID that would uniquely identify this endpoint implementation. Use as a key to map + * any information to store that is related to this endpoint. + */ + public final String getID() { + StringBuffer strBuff = new StringBuffer(); + strBuff.append(this.mService.getInterface()).append("+"); + strBuff.append(this.mService.getServiceName()).append("+"); + strBuff.append(this.mService.getEndpointName()).append("+"); + String roleType = null; + if ( Role.CONSUMER.equals(this.mRole) ) { + roleType = "CONSUMER"; + } else if ( Role.PROVIDER.equals(this.mRole) ) { + roleType = "PROVIDER"; + } + strBuff.append(roleType); + return strBuff.toString(); + } + + @Override + public String toString() { + return "Endpoint : " + "${symbol_escape}n" + this.mService; + } + /** + * checks if this endpoint is configured for the binding component or service engine. + */ + public boolean isForBindingComponent() { + boolean isForBindingComponent = false; + if ( this.mSU != null ) { + try { + isForBindingComponent = this.mSU.getSUDescriptor().isForBindingComponent(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + return isForBindingComponent; + } + + public QName getOperationQName(String opName) { + return new QName(this.getService().getInterface().getNamespaceURI(), opName); + } + + public Operation getWSDLOperation(QName opQName) { + String opName = null; + if ( opQName != null ) { + opName = opQName.getLocalPart(); + } + Operation operation = WSDLProcessor.findOperation(this.getWSDL(), + this.getService().getInterface(), opName); + return operation; + } + + public Binding getWSDLBinding() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + if ( serviceName != null ) { + return WSDLProcessor.findServiceBinding(this.getWSDL(), serviceName, endpointName); + } else { + return WSDLProcessor.findInterfaceBinding(this.getWSDL(), interfaceName, null); + } + } + /** @return logger */ + public Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** @return ComponentContext */ + public ComponentContext getComponentContext() { + return RuntimeHelper.getComponentContext(); + } + /** @return DeliveryChannel */ + public DeliveryChannel getDeliveryChannel() { + return RuntimeHelper.getDeliveryChannel(); + } + /** + * helper function to get the MessageExchangeSupport object + */ + public MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeHelper.getMessageExchangeSupport(); + } + + public MessageExchangeHandler createMessageExchangeHandler() { + return null; + } + /** + * creates the message exchange listener. Extended classes should return + * MessageExchangeListener implementation. + * @return MessageExchangeListener or null. + * + */ + protected MessageExchangeListener createMessageExchangeListener() { + return null; + } + /** + * Creates and adds message exchange listener to receive message exchange received notification. + */ + protected void addMessageExchangeListener() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + MessageExchangeListener meListener = createMessageExchangeListener(); + MessageExchangeSupport meListenerSupport = getMessageExchangeSupport(); + if ( meListenerSupport != null && meListener != null ) { + meListenerSupport.addMessageExchangeListener( + this.getRole(), interfaceName, serviceName, endpointName, meListener); + if ( serviceName != null ) { + meListenerSupport.addMessageExchangeListener( + this.getRole(), null, serviceName, endpointName, meListener); + } + } + } + /** + * Removes message exchange listener from the MessageExchangeSupport. + */ + protected void removeMessageExchangeListener() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + MessageExchangeSupport meListenerSupport = getMessageExchangeSupport(); + if ( meListenerSupport != null ) { + meListenerSupport.removeMessageExchangeListener( + this.getRole(), interfaceName, serviceName, endpointName); + if ( serviceName != null ) { + meListenerSupport.removeMessageExchangeListener( + this.getRole(), null, serviceName, endpointName); + } + } + } + + public final boolean processMessageExchangeWithHandler(ExchangeStatus status, MessageExchange me) { + + //1. lookup handler + //2. if not there create one and register + //3. call process message exchange on it + //4. check status. if that is the end, remove the handler + + MessageExchangeSupport support = this.getMessageExchangeSupport(); + if ( support == null ) { + getLogger().fine("No MessageExchangeSupport present"); + return false; + } + MessageExchangeHandler handler = support.findMessageExchangeHandler(me); + if ( handler == null ) { + handler = this.createMessageExchangeHandler(); + if ( handler == null ) { + getLogger().fine("MessageExchangeHandler not supported"); + return false; + } + support.addMessageExchangeHandler(me, handler); + } + + handler.processMessageExchange(status, me); + + getLogger().fine("XXX MX Handler processed ME with STATUS: " + status); + + if (!ExchangeStatus.ACTIVE.equals(status) ) { + // DONE or ERROR means done with the me. + getLogger().fine("End of ME processing. STATUS: " + status + + ". Removing the MX Handler ..."); + support.removeMessageExchangeHandler(me); + } + + return true; + } + +} + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java new file mode 100644 index 000000000..4bd932fc1 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java @@ -0,0 +1,107 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ProviderEndpoint.java + * + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Service; +import javax.jbi.JBIException; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Definition; + +/** + * This class extends from Endpoint class and implements lifecycle methods functionality required for the + * endpoint for a service provider. {@link ServiceUnit${symbol_pound}createProviderEndpoint} creates the object of this + * type to implement the service provider functionality. It makes sure that this class or the extended + * classes will activate or deactivate the ServiceEndpoint corresponding to the service + * provided by the endpoint is performed during the activate and deactivate method calls as part of the + * endpoint lifecycle. + * + * @see ServiceUnit${symbol_pound}createProviderEndpoint + * @author chikkala + */ + +public class ProviderEndpoint extends Endpoint { + /** + * This constructor initializes the endpoint with PROVIDER role and makes sure that the service + * description passed to it is of provider description. + */ + protected ProviderEndpoint(SUDescriptor.Provides provides, Definition wsdlDef, ServiceUnit su) { + super(Role.PROVIDER, provides, wsdlDef, su); + } + /** + * constructor that does not need service unit information. useful for creating the endpoint for + * static services provided by the component. + */ + protected ProviderEndpoint(SUDescriptor.Provides provides, Definition wsdlDef) { + this(provides, wsdlDef, null); + } + /** + * initializes the endpoint and creates and registers the MessageExchangeListener with + * MessageExchangeSupport. + */ + public final void init() throws JBIException { + getLogger().fine("ProviderEndpiont: init called"); + doInit(); //1. initialize the endpiont resources + addMessageExchangeListener(); //2. register message exchange linster. + } + /** + * calls activatesServiceEndpoint for the Provider. + */ + public final void activate() throws JBIException { + getLogger().fine("ProviderEndpiont: activate called"); + activateServiceEndpoint(); //1. activate service endpoint in NMR + doActivate(); //2. do any other activation related tasks. + } + /** + * calls deactivateServiceEndpoint for the Provider. + */ + public final void deactivate() throws JBIException { + getLogger().fine("ProviderEndpiont: deactivate called"); + deactivateServiceEndpoint(); //1. deactivates the service endpoint in NMR + doDeactivate(); //2. do any other deactivation related tasks. + } + /** + * removes the message exchange listener. cleans up other resources + */ + public final void clean() throws JBIException { + getLogger().fine("ProviderEndpiont: clean called"); + removeMessageExchangeListener(); //1. remove message exchange listener + doClean(); //2. clean up any other resources. + } + /** + * Activates the ServiceEndpoint with NMR + */ + private void activateServiceEndpoint() throws JBIException { + Service service = this.getService(); + ServiceEndpoint svcEP = this.getComponentContext().activateEndpoint( + service.getServiceName(), service.getEndpointName()); + this.setServiceEndpoint(svcEP); + } + /** + * Deactivates ServiceEndpoint in NMR + */ + private void deactivateServiceEndpoint() throws JBIException { + this.getComponentContext().deactivateEndpoint(this.getServiceEndpoint()); + this.setServiceEndpoint(null); + } + + protected void doInit() throws JBIException { + //NOOP + } + protected void doActivate() throws JBIException { + //NOOP + } + protected void doDeactivate() throws JBIException { + //NOOP + } + protected void doClean() throws JBIException { + //NOOP + } + +} \ No newline at end of file diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java new file mode 100644 index 000000000..1919647be --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java @@ -0,0 +1,364 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * SUDescriptor.java + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import javax.jbi.management.DeploymentException; +import javax.xml.namespace.QName; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * This interface represent the service unit descriptor (jbi.xml) model. This will be used in + * ServiceUnit implementation to find the services provided and consumed by this service unit. + * {@link SUDescriptorFactory${symbol_pound}getSUDescriptor} method reads the jbi.xml in the service unit to + * to the implementation of this interface. + * + * @see SUDescriptorFactory + * @see Consumes + * @see Provides + * @see ServiceUnit + * + * @author chikkala + */ +public interface SUDescriptor { + + Collection getProvidedServices(); + + Collection getConsumedServices(); + + boolean isForBindingComponent(); + + /** + * base interface that models the service information described in the service unit descriptor for + * consumed services and provided services. + */ + public interface Service { + /** + * Getter for property interfaceQName. + * @return Value of property interfaceQName. + */ + QName getInterface(); + /** + * Getter for property serviceName. + * @return Value of property serviceName. + */ + QName getServiceName(); + /** + * Getter for property endpointName. + * @return Value of property endpointName. + */ + String getEndpointName(); + } + /** + * marker interface that represents the provided services in the service unit + */ + public interface Provides extends Service { + } + /** + * this interface represents the consumed service information in the su descriptor. + */ + public interface Consumes extends Service { + + public final static String STANDARD_LINK = "standard"; + public final static String SOFT_LINK = "soft"; + public final static String HARD_LINK = "hard"; + /** + * Getter for property linkType. + * @return Value of property linkType. + */ + String getLinkType(); + } + /** + * This is a factory class that can build the Service Unit Descriptor model from the jbi.xml + */ + public static class SUDescriptorFactory { + + protected final static String JBI_TAG_NAME = "services"; + protected final static String SERVICES_TAG_NAME = "services"; + protected final static String BC_TAG_NAME = "binding-component"; + protected final static String PROVIDES_TAG_NAME = "provides"; + protected final static String CONSUMES_TAG_NAME = "consumes"; + protected final static String INTERFACE_TAG_NAME = "interface-name"; + protected final static String SERVICE_TAG_NAME = "service-name"; + protected final static String ENDPOINT_TAG_NAME = "endpoint-name"; + protected final static String LINK_TYPE_TAG_NAME = "link-type"; + /** + * method that builds the Service unit descriptor model from the jbi.xml + */ + public static SUDescriptor getSUDescriptor(String jbiXmlPath) throws Exception { + FileReader reader = null; + try { + reader = new FileReader(jbiXmlPath); + SUDescriptor suDesc = getSUDescriptor(reader); + return suDesc; + } finally { + if ( reader != null ) { + try { + reader.close(); + } catch (IOException ex) { + // ignore + } + } + } + } + /** + * method that builds the Service unit descriptor model from the jbi.xml + */ + public static SUDescriptor getSUDescriptor(Reader reader) throws Exception { + SUDescriptor suDescriptor = null; + Document suDescDoc = RuntimeHelper.buildDOMDocument(reader); + Element jbiEl = suDescDoc.getDocumentElement(); + if (JBI_TAG_NAME.equals(jbiEl.getTagName())) { + throw new DeploymentException("Invalid service unit descriptor : no jbi root element"); + } + + NodeList servicesNL = jbiEl.getElementsByTagName(SERVICES_TAG_NAME); + if (servicesNL != null && servicesNL.getLength() == 1) { + Element servicesEl = (Element) servicesNL.item(0); + suDescriptor = SUDescriptorImpl.createSUDescriptor(servicesEl); + } else { + throw new DeploymentException("Invalid service unit descriptor : invalid services element"); + } + + return suDescriptor; + } + + } + /** + * This class implements SUDescriptor + */ + public static class SUDescriptorImpl implements SUDescriptor { + + private List mConsumedList; + private List mProvidedList; + private boolean mIsForBindingComponent; + + protected SUDescriptorImpl(boolean isForBindingComponent) { + this.mIsForBindingComponent = isForBindingComponent; + this.mConsumedList = new ArrayList(); + this.mProvidedList = new ArrayList(); + } + + protected void addProvidedService(Provides provides) { + this.mProvidedList.add(provides); + } + + protected void addConsumedService(Consumes consumes) { + this.mConsumedList.add(consumes); + } + + public Collection getProvidedServices() { + // return unmodifiable collection + return Collections.unmodifiableCollection(this.mProvidedList); + } + + public Collection getConsumedServices() { + // return unmodifiable collection + return Collections.unmodifiableCollection(this.mConsumedList); + } + + public boolean isForBindingComponent() { + return this.mIsForBindingComponent; + } + + protected static SUDescriptor createSUDescriptor(Element servicesEl) throws Exception { + boolean isForBC = false; + String bcTagString = servicesEl.getAttribute(SUDescriptorFactory.BC_TAG_NAME); + isForBC = Boolean.valueOf(bcTagString).booleanValue(); + SUDescriptorImpl suDesc = new SUDescriptorImpl(isForBC); + // add consumes + NodeList consumesNL = servicesEl.getElementsByTagName(SUDescriptorFactory.CONSUMES_TAG_NAME); + for ( int i=0; i < consumesNL.getLength(); ++i) { + Element consumesEl = (Element) consumesNL.item(i); + Consumes consumes = ConsumedService.createConsumedService(consumesEl); + suDesc.addConsumedService(consumes); + } + // add provides + NodeList providesNL = servicesEl.getElementsByTagName(SUDescriptorFactory.PROVIDES_TAG_NAME); + for ( int i=0; i < providesNL.getLength(); ++i) { + Element providesEl = (Element) providesNL.item(i); + Provides provides = ProvidedService.createProvidedService(providesEl); + suDesc.addProvidedService(provides); + } + + return suDesc; + } + } + /** + * Base class that implements the Service interface + */ + public static abstract class AbstractService implements Service { + + private QName mInterface; + private QName mServiceName; + private String mEndpointName; + + private AbstractService() { + } + /** + * Getter for property interfaceQName. + * @return Value of property interfaceQName. + */ + public QName getInterface() { + return this.mInterface; + } + + /** + * Setter for property interfaceQName. + * @param interfaceQName New value of property interfaceQName. + */ + protected void setInterface(QName interfaceQName) { + this.mInterface = interfaceQName; + } + + /** + * Getter for property serviceName. + * @return Value of property serviceName. + */ + public QName getServiceName() { + return this.mServiceName; + } + + /** + * Setter for property serviceName. + * @param serviceName New value of property serviceName. + */ + protected void setServiceName(QName serviceName) { + this.mServiceName = serviceName; + } + + /** + * Getter for property endpointName. + * @return Value of property endpointName. + */ + public String getEndpointName() { + return this.mEndpointName; + } + + /** + * Setter for property endpointName. + * @param endpointName New value of property endpointName. + */ + protected void setEndpointName(String endpointName) { + this.mEndpointName = endpointName; + } + + } + /** + * This class implements the Provides interface + */ + public static class ProvidedService + extends AbstractService + implements Provides { + protected ProvidedService(QName interfaceQName, QName serviceName, String endpointName) { + this.setInterface(interfaceQName); + this.setServiceName(serviceName); + this.setEndpointName(endpointName); + } + + @Override + public String toString() { + return "Provides :" + + "${symbol_escape}n${symbol_escape}t interface-name= " + getInterface() + + "${symbol_escape}n${symbol_escape}t service-name= " + getServiceName() + + "${symbol_escape}n${symbol_escape}t endpont-name= " + getEndpointName(); + } + + protected static Provides createProvidedService(Element providesEl) throws Exception { + + String ifName = providesEl.getAttribute(SUDescriptorFactory.INTERFACE_TAG_NAME); + String serviceName = providesEl.getAttribute(SUDescriptorFactory.SERVICE_TAG_NAME); + String endpointName = providesEl.getAttribute(SUDescriptorFactory.ENDPOINT_TAG_NAME); + if ( ifName == null || serviceName == null || endpointName == null ) { + throw new Exception("Invalid provides element: missing " + SUDescriptorFactory.INTERFACE_TAG_NAME + + " or " + SUDescriptorFactory.SERVICE_TAG_NAME + " or " + SUDescriptorFactory.ENDPOINT_TAG_NAME ); + } + QName ifQName = RuntimeHelper.resolveAttrQName(ifName, providesEl); + QName serviceQName = RuntimeHelper.resolveAttrQName(serviceName, providesEl); + + return new ProvidedService(ifQName, serviceQName, endpointName); + } + } + /** + * This class implements the Consumes interface. + */ + public static class ConsumedService + extends AbstractService + implements Consumes { + private String mLinkType; + protected ConsumedService(QName interfaceQName, + QName serviceName, String endpointName, String linkType) { + this.setInterface(interfaceQName); + this.setServiceName(serviceName); + this.setEndpointName(endpointName); + this.mLinkType = linkType; + } + + /** + * Getter for property linkType. + * @return Value of property linkType. + */ + public String getLinkType() { + return this.mLinkType; + } + + @Override + public String toString() { + return "Cosumes :" + + "${symbol_escape}n${symbol_escape}t interface-name= " + getInterface() + + "${symbol_escape}n${symbol_escape}t service-name= " + getServiceName() + + "${symbol_escape}n${symbol_escape}t endpont-name= " + getEndpointName() + + "${symbol_escape}n${symbol_escape}t link-type= " + getLinkType(); + } + + protected static Consumes createConsumedService(Element consumesEl) throws Exception { + + String ifName = consumesEl.getAttribute(SUDescriptorFactory.INTERFACE_TAG_NAME); + String serviceName = consumesEl.getAttribute(SUDescriptorFactory.SERVICE_TAG_NAME); + String endpointName = consumesEl.getAttribute(SUDescriptorFactory.ENDPOINT_TAG_NAME); + String linkType = consumesEl.getAttribute(SUDescriptorFactory.LINK_TYPE_TAG_NAME); + if ( linkType == null || linkType.trim().length() == 0 ) { + linkType = STANDARD_LINK; + } + + if ( ifName == null ) { + throw new Exception("Invalid consumes element: missing " + + SUDescriptorFactory.INTERFACE_TAG_NAME ); + } + if ( serviceName == null || endpointName == null ) { + throw new Exception("Invalid consumes element: missing " + + SUDescriptorFactory.SERVICE_TAG_NAME + " or " + + SUDescriptorFactory.ENDPOINT_TAG_NAME ); + } + + QName ifQName = RuntimeHelper.resolveAttrQName(ifName, consumesEl); + QName serviceQName = null; + if ( serviceName != null ) { + serviceQName = RuntimeHelper.resolveAttrQName(serviceName, consumesEl); + } + if ( serviceQName != null && endpointName != null && linkType != null ) { + if (!(STANDARD_LINK.equals(linkType) || + SOFT_LINK.equals(linkType) || HARD_LINK.equals(linkType)) ) { + throw new Exception("Invalid consumes attribute value" + + SUDescriptorFactory.LINK_TYPE_TAG_NAME + "=" + linkType); + } + } + return new ConsumedService(ifQName, serviceQName, endpointName, linkType); + } + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java new file mode 100644 index 000000000..365633ddc --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java @@ -0,0 +1,464 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ServiceUnit.java + * + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Consumes; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Provides; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Service; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.management.DeploymentException; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; + +/** + * This is an abstract class that implements the service unit functionality in the component which + * processes the service unit artifacts and implement the actual service unit lifecycle functionality. + * The AbstractServiceUnitManager and its extended classes that implement the ServiceUnitManager + * functionality creates and maintains the reference to the concrete implementation of this class to + * invoke the functionality implemented by this class and its concrete implementation during the + * execution of the ServiceUnitMangers lifecycle methods by the jbi runtime. + *

+ * The main lifecycle methods of this class that will be called by the ServiceUnitManger implementation + * during the service unit deployment lifecycle are {@link ${symbol_pound}doload}, {@link ${symbol_pound}doDeploy}, {@link ${symbol_pound}doUndeploy}, + * {@link ${symbol_pound}doInit}, {@link ${symbol_pound}doStart}, {@link ${symbol_pound}doStop} and {@link ${symbol_pound}doShutdown} + *

+ * Service unit processing supported by this implementation is based on wsdl 1.1 deployments where the + * services provided and consumed in this service unit are described using wsdl 1.1 definitions. + *

+ * The main service unit artifacts that will be processed during deployment lifecycle of the service + * unit are 1.Service unit descriptor(jbi.xml) that describes the services provided and consumed by + * this service unit. 2.WSDL 1.1 document that describes the service definition 3.Component specific + * configurations related to services provided and consumed by this service unit. + *

+ * When the service unit is for Binding Component, the component specific configurations are read + * from the WSDL1.1 extensions defined in the WSDL document corresponding to the service provider + * or consumer deployed with this service unit. + *

+ * When the service unit is for Service Engine, the component specific configurations are read + * from the deployment artifacts such as xslt files and mapping files in the service unit zip file + * along with the WSDL document corresponding to the service provider or consumer deployed with this + * service unit. + * + * @see SUDescriptor + * @see Endpoint + * @see ProviderEndpoint + * @see ConsumerEndpoint + * @see WSDLProcessor + * @author chikkala + */ +public abstract class ServiceUnit { + /** Service Unit Name */ + private String mSUName; + /** Service Unit Root path passed by jbi runtime */ + private String mSURootPath; + /** service unit descriptor model unmarshalled from service unit jbi.xml */ + private SUDescriptor mSUDescriptor; + /** Map of Endpoint Key to ProviderEndpoint configurations in this service unit */ + private Map mProviderEndpointMap; + /** Map of Endpoint Key to ConsumerEndpoint configurations in this service unit */ + private Map mConsumerEndpointMap; + /** Map of Service Key to the WSDL Definition in this service unit */ + private Map mWSDLMap; + /** WSDLProcessor configured for this service unit to process wsdls in the service unit */ + private WSDLProcessor mWSDLProcessor; + /** + * + * @param suName + * @param suRootPath + */ + protected ServiceUnit(String suName, String suRootPath) { + this.mSUName = suName; + this.mSURootPath = suRootPath; + this.mSUDescriptor = null; + this.mWSDLMap = new HashMap(); + this.mProviderEndpointMap = new HashMap(); + this.mConsumerEndpointMap = new HashMap(); + } + /** returns service unit name + * @return service unit name + */ + public String getName() { + return this.mSUName; + } + /** returns service unit root path where the su artifacts are unzipped by the jbi runtime + * @return path to the service unit root directory. + */ + public String getSURootPath() { + return this.mSURootPath; + } + protected SUDescriptor createSUDescriptor() throws Exception { + File jbiXmlFile = new File(this.getSURootPath(), "META-INF/jbi.xml"); + String jbiXmlPath = jbiXmlFile.getAbsolutePath(); + return SUDescriptor.SUDescriptorFactory.getSUDescriptor(jbiXmlPath); + } + /** return the Service unit descriptor model that was read from the jbi.xml + * @return SUDescriptor + */ + public SUDescriptor getSUDescriptor() throws Exception { + if ( this.mSUDescriptor == null ) { + this.mSUDescriptor = createSUDescriptor(); + } + return this.mSUDescriptor; + } + public ProviderEndpoint getProviderEndpoint(String providerID) { + return this.mProviderEndpointMap.get(providerID); + } + public Collection getProviderEndpoints() { + return Collections.unmodifiableCollection(this.mProviderEndpointMap.values()); + } + public ConsumerEndpoint getConsumerEndpoint(String cosumerID) { + return this.mConsumerEndpointMap.get(cosumerID); + } + + public Collection getConsumerEndpoints() { + return Collections.unmodifiableCollection(this.mConsumerEndpointMap.values()); + } + /** + * @return Logger + */ + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** + * extended classes implement this method to create the su specific WSDLProcessor. for examples, + * a su supporting binding component may have wsdl extensions that it want to registry for reading + * the configurations from the wsdl file. + * @return WSDLProcessor + * @see com.sun.jbi.sample.component.common.wsdl.WSDLProcessor + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + */ + protected WSDLProcessor createWSDLProcessor() { + return new WSDLProcessor(this.getSURootPath()); + } + /** + * return the WSDLProcessor reference by creates if it is not yet created. + * @return WSDLProcessor. + */ + public final WSDLProcessor getWSDLProcessor() { + if ( this.mWSDLProcessor == null ) { + this.mWSDLProcessor = createWSDLProcessor(); + } + return this.mWSDLProcessor; + } + /** + * loads the service unit artifacts into the SU model. AbstractServiceUnitManager implementation + * calls this method during the during deploy and init lifecycle methods when the service unit + * object is newly created. + */ + public void doLoad() throws DeploymentException { + try { + SUDescriptor suDesc = getSUDescriptor(); // load jbi.xml + loadServiceDefinitions(); // check if the wsdls are valid for corresponding services. + loadOtherArtifacts(); // additional validations specific to component deployment features. + loadEndpoints(); // create endpoints + } catch ( DeploymentException jbiEx) { + throw jbiEx; + } catch (Exception ex) { + throw new DeploymentException(ex); + } + } + /** extended classes implement this method to perform the su specific deployment related tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doDeploy() throws DeploymentException { + // NOOP. doLoad has done it all. + this.getLogger().fine("ServiceUnit.doDeploy"); + } + /** extended classes implement this method to perform the su specific undeployment related tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doUndeploy() throws DeploymentException { + //NOOP + this.getLogger().fine("ServiceUnit.doUndeploy"); + } + /** extended classes implement this method to perform the su specific initialization tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doInit() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doInit"); + this.doInitEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on start in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doStart() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doStart"); + this.doActivateEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on stop in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doStop() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doStop"); + this.doDeactivateEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on shutdown in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doShutdown() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doShutdown"); + this.doCleanEndpoints(); + } + /** + * create the ProviderEndpoint that implement the service provider implementation specific to this su. + * @return ProviderEndpoint or null if the SU does not support the service provider access + */ + protected ProviderEndpoint createProviderEndpoint(Provides provides, Definition wsdlDef) { + return null; + } + /** + * create the ProviderEndpoint that implement the service consumer implementation specific to this su. + * @return ConsumerEndpoint or null if the SU does not support the service consumer access + */ + protected ConsumerEndpoint createConsumerEndpoint(Consumes consumes, Definition wsdlDef) { + return null; + } + /** + * generates the key based on the service to store the wsdl definitions . + */ + protected String getServiceKey(Service service) { + StringBuffer strBuff = new StringBuffer(); + strBuff.append(service.getInterface()).append("+"); + strBuff.append(service.getServiceName()).append("+"); + strBuff.append(service.getEndpointName()); + return strBuff.toString(); + } + /** + * looks up the wsdl definition loaded for this service. + */ + protected Definition findWSDLFor(Service service) throws WSDLException { + Definition wsdlDef = null; + String key = this.getServiceKey(service); + wsdlDef = this.mWSDLMap.get(key); + return wsdlDef; + } + + protected Definition findWSDL(List wsdlList, Service service, boolean ignoreEndpointLookup) { + Definition foundDef = null; + for ( Definition def : wsdlList ) { + if ( WSDLProcessor.isWSDLFor(def, service.getInterface(), service.getServiceName(), + ((ignoreEndpointLookup) ? null : service.getEndpointName()) ) ) { + foundDef = def; + break; + } + } + return foundDef; + } + /** + * loads the WSDL definitions corresponds to the service providers and consumers defined in the + * service unit descriptor. + */ + protected void loadServiceDefinitions() throws Exception { + + this.mWSDLMap = new HashMap(); + + WSDLProcessor wsdlProcessor = getWSDLProcessor(); + List wsdlList = wsdlProcessor.readWSDLs(this.getSURootPath()); + this.getLogger().fine("Number of wsdl definitions in service unit " + wsdlList.size()); + + List services = new ArrayList(); + services.addAll(this.getSUDescriptor().getProvidedServices()); + services.addAll(this.getSUDescriptor().getConsumedServices()); + + boolean isForBinding = this.getSUDescriptor().isForBindingComponent(); + this.getLogger().fine("Is this service unit for Binding? " + isForBinding); + + for ( Service service : services ) { + this.getLogger().fine("Looking up WSDL for service " + service); + boolean ignoreEndpointLookup = false; + boolean providerAtEngine = false; + if ( !isForBinding && service instanceof Provides ) { + ignoreEndpointLookup = true; + providerAtEngine = true; + } + Definition def = findWSDL(wsdlList, service, ignoreEndpointLookup); + if ( def == null ) { + throw new Exception("WSDL Definition not found for " + service); + } + this.mWSDLMap.put(getServiceKey(service), def); + if ( providerAtEngine ) { + // provider at engine. so add engine binding and endpoint to the wsdl + wsdlProcessor.create${artifactId}Binding(def, + service.getInterface(), service.getServiceName(), service.getEndpointName()); + } + } + } + /** extended classes implement this method to perform the su specific artifacts validation in + * this method implementation. + * @throws DeploymentException on error. + */ + protected void loadOtherArtifacts() throws DeploymentException { + // nothing to validate further. + this.getLogger().fine("ServiceUnit.loadOtherArtifacts"); + } + /** + * creates ProviderEndpoint and ConsumerEndpoint objects corresponding to the service providers + * and consumers described in the su descriptor ( jbi.xml ) + */ + protected void loadEndpoints() throws Exception { + + this.mProviderEndpointMap = new HashMap(); + this.mConsumerEndpointMap = new HashMap(); + + Collection providesList = this.getSUDescriptor().getProvidedServices(); + for ( Provides provides : providesList ) { + Definition wsdlDef = findWSDLFor(provides); + if ( wsdlDef == null ) { + throw new DeploymentException("WSDL Definitions not found for " + provides); + } + ProviderEndpoint provider = createProviderEndpoint(provides, wsdlDef); + this.mProviderEndpointMap.put(provider.getID(), provider); + } + + Collection consumesList = this.getSUDescriptor().getConsumedServices(); + for ( Consumes consumes : consumesList ) { + Definition wsdlDef = findWSDLFor(consumes); + if ( wsdlDef == null ) { + throw new DeploymentException("WSDL Definitions not found for " + consumes); + } + ConsumerEndpoint consumer = createConsumerEndpoint(consumes, wsdlDef); + this.mConsumerEndpointMap.put(consumer.getID(), consumer); + } + } + /** + * initializes the Endpoint objects created corresponding to the consumer and providers defined + * in the su descriptor + */ + protected void doInitEndpoints() throws DeploymentException { + // init endpoints. if any initialization fails, rollback the already inited endpoints + List initedEndpoints = new ArrayList(); + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getProviderEndpoints()); + allEndpoints.addAll(this.getConsumerEndpoints()); + + for ( Endpoint endpoint : allEndpoints ) { + try { + endpoint.init(); + initedEndpoints.add(endpoint); + } catch ( Exception initEx) { + doCleanEndpoints(initedEndpoints); + throw new DeploymentException(initEx); + } + } + + } + /** + * invokes activates method of all provider and consumer endpoint object in this su. if there is + * and error activating any one the endpoints, it deactivates the already activated ones and throws + * the error + */ + protected void doActivateEndpoints() throws DeploymentException { + // activate providers first and then consumers + List activatedEndpoints = new ArrayList(); + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getProviderEndpoints()); + allEndpoints.addAll(this.getConsumerEndpoints()); + + for ( Endpoint endpoint : allEndpoints ) { + try { + endpoint.activate(); + activatedEndpoints.add(endpoint); + } catch ( Exception actEx) { + doDeactivateEndpoints(activatedEndpoints); + throw new DeploymentException(actEx); + } + } + } + /** + * invokes deactivate method on the list of Endpoint objects passed to this method + */ + protected void doDeactivateEndpoints(List endpoints) { + for ( Endpoint endpoint : endpoints ) { + try { + endpoint.deactivate(); + } catch(Exception ex) { + // ignore the exception and log it. + this.getLogger().log(Level.FINE, ex.getMessage(), ex); + } + } + } + /** + * invokes deactivate method on the all consumer and provider endpoint objects + */ + protected void doDeactivateEndpoints() { + // deactivate consumers first and then the providers + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getConsumerEndpoints()); + allEndpoints.addAll(this.getProviderEndpoints()); + doDeactivateEndpoints(allEndpoints); + } + /** + * invokes clean method on the list of endpoint objects + */ + protected void doCleanEndpoints(List endpoints) { + for ( Endpoint endpoint : endpoints ) { + try { + endpoint.clean(); + } catch(Exception ex) { + // ignore the exception and log it. + this.getLogger().log(Level.FINE, ex.getMessage(), ex); + } + } + } + /** + * invokes clean method on the all consumer and provider endpoint objects in this su. + */ + protected void doCleanEndpoints() { + + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getConsumerEndpoints()); + allEndpoints.addAll(this.getProviderEndpoints()); + doCleanEndpoints(allEndpoints); + } + /** + * prints the service unit description + */ + protected final String printDetails() { + + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + + out.println("ServiceUnit Name : " + this.getName()); + out.println("ServiceUnit Root : " + this.getSURootPath()); + + SUDescriptor suDesc = null; + try { + suDesc = this.getSUDescriptor(); + for ( SUDescriptor.Consumes consumer : suDesc.getConsumedServices()) { + out.println(consumer); + } + for ( SUDescriptor.Provides provides : suDesc.getProvidedServices()) { + out.println(provides); + } + } catch (Exception ex) { + ex.printStackTrace(out); + } + return writer.getBuffer().toString(); + } + + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java new file mode 100644 index 000000000..67bbf5a45 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java @@ -0,0 +1,44 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractExtensibilityElement.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import javax.wsdl.extensions.ExtensibilityElement; +import javax.xml.namespace.QName; + +/** + * This is an abstract class which can be extended to create jwsdl (wsdl4j's) extension elements model to + * read/write the wsdl extension elements in wsdl 1.1 xml. + * + * @author chikkala + */ +public abstract class AbstractExtensibilityElement implements ExtensibilityElement, java.io.Serializable { + public static final long serialVersionUID = 1; + private QName mElementType; + private Boolean mRequired; + + /** Creates a new instance of AbstractExtensibilityElement */ + protected AbstractExtensibilityElement() { + } + + public void setElementType(QName elementType) { + this.mElementType = elementType; + } + + public QName getElementType() { + return this.mElementType; + } + + public void setRequired(Boolean required) { + this.mRequired = required; + } + + public Boolean getRequired() { + return this.mRequired; + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java new file mode 100644 index 000000000..5233aeee2 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java @@ -0,0 +1,45 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractExtensionRegistry.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.util.List; +import javax.wsdl.extensions.ExtensionRegistry; + +/** + * This is the abstract class used to add the wsdl extension serializers and deserializers to the + * wsdl extension registry configured to read/write wsdl extensions into a know java model. + * @see AbstractExtensionSerializer + * @see WSDLProcessor + * @author chikkala + */ +public abstract class AbstractExtensionRegistry extends ExtensionRegistry { + + /** Creates a new instance of AbstractSerializer + * it calls the createSerializers method to get the list of + * serializers and then call registerSerializer on each AbstractExtensionSerializer + * to register them with this registry. + * @see AbstractExtensionSerializer${symbol_pound}registerSerializer + */ + protected AbstractExtensionRegistry() { + super(); + List list = createSerializers(); + for (AbstractExtensionSerializer ser : list ) { + ser.registerSerializer(this); + } + // register ${artifactId} Binding serializers + AbstractExtensionSerializer seBindingSer = new SEBindingExt.SEBindingExtSerializer(); + seBindingSer.registerSerializer(this); + } + /** + * create wsdl extension serializers for each extension element to register with the extension + * registry. + * @return List of AbstractExtensionSerializer objects for serializing/deserializing the wsdl extensions. + * @see AbstractExtensionSerializer + */ + protected abstract List createSerializers(); +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java new file mode 100644 index 000000000..4ac1b37d6 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java @@ -0,0 +1,123 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractExtensionSerializer.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.io.PrintWriter; +import java.io.Serializable; +import java.util.Set; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionDeserializer; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.extensions.ExtensionSerializer; +import javax.xml.namespace.QName; +import org.w3c.dom.Attr; +import org.w3c.dom.Element; + +/** + * This class is an abstract class that should be extended to implements extension serializer and + * deserializer. This class implements the code required for registering the serializer and deserializer + * implemented by this class. THe AbstractExtensionRegistry class calls the ${symbol_pound}registerSerializer method + * to register the concrete implementation of this class with extension registry. + * @see AbstractExtensionRegistry + * @author chikkala + */ +public abstract class AbstractExtensionSerializer + implements ExtensionSerializer, ExtensionDeserializer, Serializable { + + public static final long serialVersionUID = 1; + + private Class mParentType; + private Class mExtensionType; + private QName mElementType; + + /** Creates a new instance of AbstractSerializer */ + public AbstractExtensionSerializer(Class parentType, QName elementType, Class extensionType) { + this.mParentType = parentType; + this.mElementType = elementType; + this.mExtensionType = extensionType; + } + + public Class getParentType() { + return this.mParentType; + } + public QName getElementType() { + return this.mElementType; + } + public Class getExtensionType() { + return this.mExtensionType; + } + + public void registerSerializer(ExtensionRegistry extReg) { + extReg.registerSerializer(this.mParentType, this.mElementType, this); + extReg.registerDeserializer(this.mParentType, this.mElementType, this); + extReg.mapExtensionTypes(this.mParentType, this.mElementType, this.mExtensionType); + } + + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg ) throws WSDLException { + // DO NOTHING. Binding component runtime does not need to serialize the wsdl extensions. + } + + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + return null; + } + + public static String getAttribute(Element el, String attrName) { + String attrValue = null; + Attr attr = el.getAttributeNode(attrName); + if ( attr != null ) { + attrValue = attr.getValue(); + } + return attrValue; + } + + protected String getNamespacePrefix(Definition def, String namespaceURI, String defPrefix) { + String prefix = null; + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + Set keySet = def.getNamespaces().keySet(); + String newPrefix = "ns"; + if ( defPrefix != null && defPrefix.trim().length() > 0 ){ + newPrefix = defPrefix; + } + prefix = newPrefix; + for ( int i=0; i < Integer.MAX_VALUE; ++i) { + if (!keySet.contains(prefix)) { + break; + } else { + prefix = newPrefix + i; + } + } + } + return prefix; + } + /** + * @return the name with the prefix defined for the namespaceURI in the wsdl definition. + * @throws WSDLException if the prefix not found in the wsdl definition. note that the + * default prefix is an empty string. + */ + protected String getQualifiedName(Definition def, + String namespaceURI, String localName) throws WSDLException { + String prefix = null; + if (namespaceURI != null && !namespaceURI.equals("")) { + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + throw new WSDLException(WSDLException.OTHER_ERROR, + "Can not find prefix in WSDL Definition for " + namespaceURI); + } + } + if ( prefix != null && !prefix.equals("")) { + return prefix + ":" + localName; + } else { + return localName; + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java new file mode 100644 index 000000000..b10800550 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java @@ -0,0 +1,229 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractNormalizer.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.util.ArrayList; +import java.util.List; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Part; +import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.dom.DOMSource; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * This is an abstract class that implements most of the functionality to normalize the binding protocol + * specific concrete message to jbi wrapper and and denormalize jbi wrapper to the concrete binding + * protocol specific message. + *

+ * The extended classes specific to particular binding protocol will be used when a jbi binding + * component is sending and receiving messages from the external service providers and consumers using + * a particular binding protocol known to this class. Extended implementation of this class should make + * use of the helper methods in this class in normalizing and denormalizing the messages. + * @see JMXBindingNormalizer + * @author chikkala + */ +public abstract class AbstractNormalizer { + + public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/"; + /** wsdl definition to use when normalizing and denormalizing */ + private Definition mWSDL; + /** Binding definition to use when normalizing and denormalizing */ + private Binding mBinding; + + private AbstractNormalizer() {} + /** Creates a new instance of JMXBCNormalizer */ + public AbstractNormalizer(Definition wsdl, Binding binding) { + this.mWSDL = wsdl; + this.mBinding = binding; + } + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete mssage of a particular binding protocol. + */ + public abstract void normalizeInput(Operation operation, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete message of a particular binding protocol. + */ + public abstract void normalizeOutput(Operation operation, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete message of a particular binding protocol. + */ + public abstract void normalizeFault(Operation operation, String faultName, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * denormalize the normalized message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be de-normalized. + * @param normMsg NormalizedMessage which should be used to create de-normalized message. + */ + public abstract DOMSource denormalizeInput(Operation operation, NormalizedMessage normMsg) + throws MessagingException; + /** + * denormalize the normalized message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be denormalized. + * @param normMsg NormalizedMessage which should be used to create denormalized message. + */ + public abstract DOMSource denormalizeOutput(Operation operation, NormalizedMessage normMsg) + throws MessagingException; + + /** + * denormalized the normalized fault message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be denormalized. + * @param normMsg NormalizedMessage which should be used to create denormalized message. + */ + public abstract DOMSource denormalizeFault(Operation operation, String faultName, NormalizedMessage normMsg) + throws MessagingException; + /** + * @return the wsdl definition to use in normalizing and denormalizing the message + */ + protected Definition getWSDL() { + return this.mWSDL; + } + /** + * @return the wsdl binding definition to use in normalizing and denormalizing the message + */ + protected Binding getBinding() { + return this.mBinding; + } + /** + * create and add message parts to the jbiWrapper according to the abstract message model. This + * method assumes that the each element in the msgParts list passed to it is mapped to the part + * of the abstract wsdl message and uses the type or element attribute of the abstract message to + * determine whether the element is actual part element or a wrapped part type. + * Use this method in normalizing the concrete protocol specific message to jbi wrapper message. + * @param jbiWrapper object that holds the jbi wrapper information. + * @param wsdlMsg abstract message from the wsdl definition + * @param msgParts actual message parts from the concrete message + */ + protected void addMessagePartsToJBIWrapper(WSDL11JBIWrapper jbiWrapper, Message wsdlMsg, List msgParts) throws MessagingException { + List wsdlParts = wsdlMsg.getOrderedParts(null); + for ( int i=0; i < wsdlParts.size(); ++i ) { + Part wsdlPart = (Part) wsdlParts.get(i); + if ( i >= msgParts.size() ) { + throw new MessagingException("missing message content for part " + wsdlPart.getName()); + } + Element msgPart = msgParts.get(i); + if ( wsdlPart.getElementName() != null ) { + jbiWrapper.appendPart(msgPart); + } else { + // it is type. + // check the element name is same as part + if ( !wsdlPart.getName().equals(msgPart.getLocalName()) ) { + throw new MessagingException("mismatched message content for part " + wsdlPart.getName()); + } + if ( !wsdlMsg.getQName().getNamespaceURI().equals(msgPart.getNamespaceURI()) ) { + throw new MessagingException("mismatched message content namespace for part " + wsdlPart.getName()); + } + // check the content is text or element. + List partContent = getChildElements(msgPart); + if ( partContent.size() > 0 ) { + // add content as part elements + jbiWrapper.appendPart(partContent); + } else { + // add the content as text + jbiWrapper.appendPart(msgPart.getTextContent()); + } + } + } + } + /** + * extracts the message parts from the jbiWrapper according to the abstract wsdl message + * definition passed to it. Use this method in denormalizing the jbi wrapper message into the + * binding protocol specific concrete message. + * @param jbiWrapper jbi wrapper object that contains message parts and the message type information. + * @param wsdlMsg abstract wsdl message definition to use in constructing the part elements. + */ + protected List getMessagePartsFromJBIWrapper(WSDL11JBIWrapper jbiWrapper, Message wsdlMsg) + throws MessagingException, ParserConfigurationException { + + List msgParts = new ArrayList(); + int jbiPartCount = jbiWrapper.getPartCount(); + List wsdlParts = wsdlMsg.getOrderedParts(null); + QName msgType = jbiWrapper.getType(); + if (!wsdlMsg.getQName().getNamespaceURI().equals(msgType.getNamespaceURI())) { + throw new MessagingException("Namespace mismatch between jbi wrapper message type and wsdl message"); + } + Document newDoc = jbiWrapper.getDocumentBuilder().newDocument(); + for ( int i=0; i < wsdlParts.size(); ++i ) { + Part wsdlPart = (Part) wsdlParts.get(i); + if ( i >= jbiPartCount ) { + throw new MessagingException("missing message content for part " + wsdlPart.getName()); + } + if ( wsdlPart.getElementName() != null ) { + msgParts.add(jbiWrapper.getPartAsElement(i)); + } else { + // it is type. create a new element for a typed part + // check the element name is same as part + String prefix = msgType.getPrefix(); + String nsURI = msgType.getNamespaceURI(); + String localName = wsdlPart.getName(); + Element partEl = newDoc.createElementNS(nsURI, prefix + ":" + localName); + partEl.setAttributeNS(XMLNS_NS, "xmlns:"+prefix, nsURI); + NodeList partContent = jbiWrapper.getPart(i); + appendChildren(partEl, partContent, newDoc, true); + msgParts.add(partEl); + } + } + return msgParts; + } + /** + * utility method that can append the nodeList passed to it to the element children. + * @param el element node to which the nodeList should be appended + * @param doc the document object that should be used to import the nodeList + * @param importNode true if the nodeList should be imported while appending the nodeList to the + * element children. false if no import is necessary. + */ + protected void appendChildren(Element el, NodeList nodeList, Document doc, boolean importNode) { + + for ( int pIdx = 0; pIdx < nodeList.getLength(); ++pIdx) { + Node node = nodeList.item(pIdx); + if ( importNode ) { + node = doc.importNode(node, true); + } + el.appendChild(node); + } + } + /** + * @param el element from which to extract the child elements + * @return List list of child Element nodes. + */ + protected List getChildElements(Element el) { + List list = new ArrayList(); + NodeList nodeList = el.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if (!(node instanceof Element) ){ + continue; + } + list.add((Element)node); + } + return list; + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java new file mode 100644 index 000000000..30663d867 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java @@ -0,0 +1,99 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * SEBindingExt.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.io.PrintWriter; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation classes implement wsdl 1.1 extension model for the + * jbi service engine binding that is defined in jsr 208(sec. 5.5.6.1). to read/write concrete binding + * element in the wsdl definition for the service endpoint binding provided by the service engine. + * The wsdl definition with this binding information can be used in providing the service provider + * metadata returned by the service engine in Component.getServiceDescription. + *

+ * AbstractExtensionRegistry by default include this extension serializers in the + * registry to read/write this service engine binding type in the wsdl definition. + *

+ * During a service unit deployment/initialization in the service engine, the deployed wsdl definition + * is loaded and modified to provide this binding for the service provided by the engine. + * + * @see WSDLProcessor${symbol_pound}create${artifactId}Binding + * @see AbstractExtensionRegistry + * @see com.sun.jbi.sample.component.common.deployment.ServiceUnit${symbol_pound}loadServiceDefinitions + * @author chikkala + */ +public interface SEBindingExt extends ExtensibilityElement, java.io.Serializable { + + public static final String NS_URI = "http://java.sun.com/xml/ns/jbi/binding/service+engine"; + public static final String NS_DEF_PREFIX = "jbise"; + /** Element names. */ + public static final String EL_BINDING_EXT = "binding"; + /**Qualified element names.*/ + public static final QName QN_BINDING_EXT = new QName(NS_URI, EL_BINDING_EXT); + + public static class SEBindingExtImpl extends AbstractExtensibilityElement implements SEBindingExt { + + public SEBindingExtImpl() { + setElementType(QN_BINDING_EXT); + } + @Override + public String toString() { + StringBuffer buff = new StringBuffer(); + buff.append("<"+NS_DEF_PREFIX+":"+EL_BINDING_EXT); + buff.append("/>"); + return buff.toString(); + } + /** + * creates and adds the jbi service engine binding extensibility element to the wsdl definition + * under specified binding definition. + */ + public static SEBindingExtImpl addExtensibilityElement(Definition wsdlDef, Binding binding) { + SEBindingExtImpl bindingExt = new SEBindingExt.SEBindingExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, binding, bindingExt, SEBindingExt.NS_DEF_PREFIX); + return bindingExt; + } + } + /** + * serializer and descrializer implementation for the binding extension element. + */ + public static class SEBindingExtSerializer extends AbstractExtensionSerializer { + + public SEBindingExtSerializer() { + super(Binding.class, QN_BINDING_EXT, SEBindingExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + SEBindingExt extObj = (SEBindingExt)extReg.createExtension(parentType, elementType); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg ) throws WSDLException { + + String elName = getQualifiedName(def, NS_URI, EL_BINDING_EXT); + + SEBindingExt extObj = (SEBindingExt)extension; + + StringBuffer buff = new StringBuffer(); + buff.append("<" + elName ); + buff.append("/>"); + pw.println(buff.toString()); + } + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java new file mode 100644 index 000000000..92606104d --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java @@ -0,0 +1,471 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * WSDL11JBIWrapper.java + * + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.dom.DOMSource; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +/** + * This class wraps the wsdl11 messages to the jbi wrapper message suitable for + * processing in the wsdl2.0 model of the normalized message in jbi as defined in jsr208 like + * + * + * + * + * + * + * + * + * + * + * @author chikkala + */ +public class WSDL11JBIWrapper { + + public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/"; + public static final String WRAPPER_NAMESPACE = "http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper"; + public static final String DEF_NS_PREFIX = "jbiwrp"; + public static final String DEF_MESSAGE_NS_PREFIX = "msgns"; + public static final String JBI_MESSAGE_EL = "message"; + public static final String JBI_PART_EL = "part"; + public static final String VERSION_ATTR = "version"; + public static final String VERSION_ATTR_VALUE = "1.0"; + public static final String TYPE_ATTR = "type"; + public static final String NAME_ATTR = "name"; + + private static DocumentBuilder sDocBuilder = null; + /** qname of message attribute from wsdl:input, wsdl:output or wsdl:fault */ + private QName mType; + /** optional name attribute from wsdl:input, wsdl:output or wsdl:fault */ + private String mName; + /** each parts contents as node list */ + List mPartConentList = new ArrayList(); + + /** Creates a new instance of WSDL11JBIWrapper */ + public WSDL11JBIWrapper() { + } + /** creates the namespace aware document builder. extended classes can override this method + * to return the doc builder created else where. + */ + protected DocumentBuilder createDocumentBuilder() throws ParserConfigurationException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + return factory.newDocumentBuilder(); + } + /** return the document builder + * @return DocumentBuilder + */ + public final DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { + if ( WSDL11JBIWrapper.sDocBuilder == null ) { + WSDL11JBIWrapper.sDocBuilder = createDocumentBuilder(); + } + return WSDL11JBIWrapper.sDocBuilder; + } + /** + * @return type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + */ + public QName getType() { + return this.mType; + } + /** + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + */ + public void setType(QName type) { + this.mType = type; + } + /** @return name attribute from wsdl:input, wsdl:output or wsdl:fault. or null if not set. */ + public String getName() { + return this.mName; + } + /** + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault. can be null. + */ + public void setName(String name) { + this.mName = name; + } + /** + * appends part content as node list + */ + public void appendPart(NodeList partContent) { + this.mPartConentList.add(partContent); + } + /** + * append part content from the List of nodes + */ + public void appendPart(List partContent) { + this.mPartConentList.add(new NodeListImpl(partContent)); + } + /** + * append part content as element + */ + public void appendPart(Element partContent) { + this.mPartConentList.add(new NodeListImpl(partContent)); + } + /** + * append part content from DOMSource + */ + public void appendPart(DOMSource partContent) { + Element partConentEl = getElement(partContent.getNode()); + this.mPartConentList.add(new NodeListImpl(partConentEl)); + } + /** + * append part content as text node. + */ + public void appendPart(String partContent) { + Text textContent = null; + try { + textContent = this.getDocumentBuilder().newDocument().createTextNode(partContent); + } catch (ParserConfigurationException ex) { + ex.printStackTrace(); + } + if ( textContent != null ) { + this.mPartConentList.add(new NodeListImpl(textContent)); + } + } + /** + * append list of part contents each is a NodeList to the parts + */ + public void appendParts(List partContentList) { + this.mPartConentList.addAll(partContentList); + } + /** + * returned the ordered list of part contents. + */ + public List getParts() { + return Collections.unmodifiableList(this.mPartConentList); + } + /** + * return the number of parts + */ + public int getPartCount() { + return this.mPartConentList.size(); + } + /** + * return the part content at a particular index as NodeList. + */ + public NodeList getPart(int idx) { + return this.mPartConentList.get(idx); + } + /** + * return part context at a particular index as text + */ + public String getPartAsText(int idx) { + NodeList partNodes = getPart(idx); + Document doc; + try { + doc = this.getDocumentBuilder().newDocument(); + Element el = doc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_PART_EL); + for ( int i=0; i < partNodes.getLength(); ++i) { + el.appendChild(partNodes.item(i)); + } + return el.getTextContent(); + } catch (ParserConfigurationException ex) { + return null; + } + } + /** + * return part context at a particular index as Element + */ + public Element getPartAsElement(int idx) { + Element contentEl = null; + NodeList partNodes = getPart(idx); + for ( int i=0; i < partNodes.getLength(); ++i) { + Node node = partNodes.item(i); + if ( node instanceof Element) { + contentEl = (Element)node; + break; + } + } + return contentEl; + } + /** + * creates Document from this wrapper object. Before calling this method, + * the type, name (optional) and parts contents should be set. + * @return Document containing the wsdl 11 wrapper xml + */ + public Document toDocument() throws ParserConfigurationException { + + Document wrapperDoc = getDocumentBuilder().newDocument(); + Element jbiMessage = wrapperDoc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_MESSAGE_EL); + jbiMessage.setAttribute(VERSION_ATTR, VERSION_ATTR_VALUE); + wrapperDoc.appendChild(jbiMessage); + + QName type = this.getType(); + if ( type == null ) { + type = new QName("", "", DEF_MESSAGE_NS_PREFIX); + } + // set the jbiMessage attributes + String prefix = type.getPrefix(); + if (prefix == null || prefix.length() == 0) { + prefix = DEF_MESSAGE_NS_PREFIX; + } + jbiMessage.setAttribute(TYPE_ATTR, prefix + ":" + type.getLocalPart()); + jbiMessage.setAttributeNS( XMLNS_NS, "xmlns:" + prefix, type.getNamespaceURI()); + + String name = this.getName(); + if (name != null && name.trim().length() > 0 ) { + jbiMessage.setAttribute(NAME_ATTR, name); + } + + List partContentList = this.getParts(); + for ( NodeList nodeList : partContentList ) { + // set jbi part message + Element jbiPart = wrapperDoc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_PART_EL); + jbiMessage.appendChild(jbiPart); + for ( int i =0; i < nodeList.getLength(); ++i ) { + Node importedMsgNode = wrapperDoc.importNode(nodeList.item(i), true); + jbiPart.appendChild(importedMsgNode); + } + } + + return wrapperDoc; + + } + /** + * creates DOMSource from this wrapper object. Before calling this method, + * the type, name (optional) and parts contents should be set. + * @return DOMSource containing the wsdl 11 wrapper xml + */ + public DOMSource toDOMSource() throws ParserConfigurationException { + DOMSource wrappedSource = new DOMSource(); + wrappedSource.setNode(toDocument()); + return wrappedSource; + } + /** + * return Element node from a document node or non document. Use to extract + * the message root element. + * @root node from which the Element node will be extracted. + * @return Element node. + */ + public static Element getElement(Node root) { + Element msgEl = null; + if ( root instanceof Document) { + msgEl = ((Document)root).getDocumentElement(); + } else if (root instanceof Element) { + msgEl = (Element)root; + } else { + NodeList nodeList = root.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if ( node instanceof Element ) { + msgEl = (Element) node; + break; + } + } + } + return msgEl; + } + /** + * creates wrapper object from the DOMSource that has wsdl 11 wrapper xml. + * @param wrappedMsg wsdl 11 wrapper xml as DOMSource + * @return WSDL11JBIWrapper representing the wrapper xml. + */ + public static WSDL11JBIWrapper sourceToWrapper(DOMSource wrappedMsg) { + Element jbiMessage = getElement(wrappedMsg.getNode()); + if ( jbiMessage == null ) { + return null; + } + String nsURI = jbiMessage.getNamespaceURI(); + String tagName = jbiMessage.getLocalName(); + if (!WRAPPER_NAMESPACE.equals(nsURI) || !JBI_MESSAGE_EL.equals(tagName)) { + return null; + } + String name = jbiMessage.getAttribute(NAME_ATTR); + String typeQN = jbiMessage.getAttribute(TYPE_ATTR); + String typePrefix = ""; + String typeName = ""; + if ( typeQN != null && typeQN.trim().length() > 0 ) { + int idx = typeQN.indexOf(':'); + if ( idx >= 0 ) { + typePrefix = typeQN.substring(0, idx); + if ( typeQN.length() > idx ) { + typeName = typeQN.substring(idx+1); + } + } else { + typePrefix = ""; + typeName = typeQN; + } + } + String typeURI = jbiMessage.getAttribute("xmlns:" + typePrefix); + QName typeQName = new QName(typeURI, typeName, typePrefix); + + WSDL11JBIWrapper wrapper = new WSDL11JBIWrapper(); + wrapper.setName(name); + wrapper.setType(typeQName); + NodeList jbiPartList = jbiMessage.getElementsByTagNameNS(WRAPPER_NAMESPACE, JBI_PART_EL); + for ( int i=0; i < jbiPartList.getLength(); ++i) { + Node jbiPart = jbiPartList.item(i); + wrapper.appendPart(jbiPart.getChildNodes()); + } + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object and sets the type and name of the object + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name ) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = new WSDL11JBIWrapper(); + wrapper.setName(name); + wrapper.setType(type); + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object. useful when the message has one part and the + * part content has multiple child element. + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @param partContent part content as node list + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name, NodeList partContent) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name); + wrapper.appendPart(partContent); + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object. useful when the message has one part and the + * part content is a single element + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @param partContent part content as node list + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name, Element msgEl) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name, new WSDL11JBIWrapper.NodeListImpl(msgEl)); + return wrapper; + } + + public static WSDL11JBIWrapper createWrapper(QName type, String name, DOMSource inputSource) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name); + Node msgNode = getElement(inputSource.getNode()); + NodeList nodeList = new WSDL11JBIWrapper.NodeListImpl(msgNode); + wrapper.appendPart(nodeList); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations input element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createInputWrapper(Operation operation) throws ParserConfigurationException { + QName type = null; + String name = null; + + Input input = operation.getInput(); + if ( input == null ) { + return null; + } + name = input.getName(); + Message wsdlMsg = input.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations output element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createOutputWrapper(Operation operation) throws ParserConfigurationException { + QName type = null; + String name = null; + + Output output = operation.getOutput(); + if ( output == null) { + return null; + } + name = output.getName(); + Message wsdlMsg = output.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations output element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @param faultName fault name, can be null to look for the fault with no name. + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createFaultWrapper(Operation operation, String faultName) throws ParserConfigurationException { + QName type = null; + String name = null; + @SuppressWarnings("unchecked") + Map faultMap = operation.getFaults(); + Fault fault = faultMap.get(faultName); + + if ( fault == null ) { + return null; + } + name = fault.getName(); + Message wsdlMsg = fault.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * NodeList implementation. + */ + public static class NodeListImpl extends ArrayList implements NodeList { + + public NodeListImpl() { + super(); + } + + public NodeListImpl(Node aNode) { + super(); + if (aNode != null) { + this.add(aNode); + } + } + + public NodeListImpl(List nodes) { + if (nodes != null) { + this.addAll(nodes); + } + } + + public int getLength() { + return this.size(); + } + + public Node item(int idx) { + return this.get(idx); + } + + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java new file mode 100644 index 000000000..6e0c0993f --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java @@ -0,0 +1,419 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * WSDLProcessor.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ElementExtensible; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.wsdl.xml.WSDLWriter; +import javax.xml.namespace.QName; + +/** + * This class is used to configure jwsdl(wsdl4j) to read and process wsdl documents with wsdl extensions. + * It provides set of helper methods to read and process the wsdl definitions from files with .wsdl + * extension from a specified directory. + *

+ * A Binding Component that is processing the wsdl extensions for its deployment configuration would + * extend this class and provide the required ExtensionRegistry that will have the extension serializers + * and deserializers configured to read/write the extensions from/to the java model. + *

+ * A Service Engine that is processing the wsdl during deployment can directly use this class + * to process the wsdl as the default implementation returned by this class configures the wsdl extension + * registry to read/write the service engine binding extensions. + * + * @see AbstractExtensionRegistry + * @see SEBindingExt + * @author chikkala + */ +public class WSDLProcessor { + + private String mXmlCatalogPath = "xml-catalog.xml"; + private String mWsdlDirPath = ""; + private WSDLReader mReader; + + /** Creates a new instance of WSDLProcessor + */ + public WSDLProcessor(String wsdlDir) { + this(wsdlDir, null); + } + /** Creates a new instance of WSDLProcessor + */ + public WSDLProcessor(String wsdlDir, String xmlCatPath) { + if ( wsdlDir != null ) { + this.mWsdlDirPath = wsdlDir; + } + if ( xmlCatPath != null ) { + this.mXmlCatalogPath = xmlCatPath; + } + } + /** @return directory path from which this class reads the wsdl files with .wsdl as file extension. */ + public String getWSDLDirectory() { + return this.mWsdlDirPath; + } + /** path to the xml catalog file in the service unit which can be used for Catalog-based entity + * and URI resolution. + */ + public String getXmlCatelogPath() { + return this.mXmlCatalogPath; + } + /** wsdl extension registry required for processing the wsdl extensions in the wsdl definition to + * java model. Binding component that is processing the wsdl extensions for its deployment + * configuration would provide the required ExtensionRegistry that will have the extension serializers + * and deserializers configured to read/write the extensions from/to the java model. + * @return ExtensionSerializer + * @see AbstractExtensionSerializer + */ + protected ExtensionRegistry getExtensionRegistry() { + return new AbstractExtensionRegistry() { + protected List createSerializers() { + return new ArrayList(); + } + }; + } + /** + * @return the WSDLReader configured with extension registry to process the wsdl extensions. + */ + public final WSDLReader getWSDLReader() throws WSDLException { + if ( this.mReader == null ) { + WSDLFactory factory = WSDLFactory.newInstance(); + this.mReader = factory.newWSDLReader(); + // reader.setFeature("javax.wsdl.verbose", true); + // reader.setFeature("javax.wsdl.importDocuments", true); + this.mReader.setExtensionRegistry(getExtensionRegistry()); + } + return this.mReader; + } + /** + * reads the wsdl file and returns the wsdl definition jwsdl model. + * @param wsldFilePath relative path to wsdl file from the the root wsdl directory returns from + * ${symbol_pound}getWSDLDirectory in the service unit or or absolute path . + * @return Definition + */ + public Definition readWSDL(String wsdlFilePath) throws WSDLException { + File wsdlFile = new File(wsdlFilePath); + if ( !wsdlFile.isAbsolute() ) { + wsdlFile = new File(this.mWsdlDirPath, wsdlFilePath); + } + return getWSDLReader().readWSDL(wsdlFile.getAbsolutePath()); + } + /** + * reads the files with .wsdl file extension in a directory. If the directory should + * be searched recursively, it searches this directory, all child directories of this + * directory and then to their child directories recursively. + * @param dir directory file to search for .wsdl files + * @param rec if set to true, it recursively searches the directory. if set to false, only + * this directory is searched. + * @return List of Files with .wsdl extension. + */ + public List listWSDLFiles(File dir, final boolean rec) throws IOException { + if ( dir == null || !dir.isDirectory()) { + throw new IOException(dir + " is not a directory for looking up wsdl files"); + } + List wsdlList = new ArrayList(); + File[] files = dir.listFiles(new FileFilter() { + public boolean accept(File pathname) { + if ( rec && pathname.isDirectory()) { + return true; + } else { + String name = pathname.getName(); + int idx = name.lastIndexOf('.'); + if ( idx < 0 ) { + return false; + } + String ext = name.substring(idx); + return ".wsdl".equalsIgnoreCase(ext); + } + } + }); + for ( File file : files ) { + if ( rec && file.isDirectory()) { + List wsdlFiles = listWSDLFiles(file, rec); + wsdlList.addAll(wsdlFiles); + } else { + wsdlList.add(file); + } + } + return wsdlList; + } + /** + * reads the files with .wsdl file extension in a directory fromDir and return the list of + * wsdl definitions corresponding to them. + * @param fromDir path to the directory relative to the root wsdl directory returns from + * ${symbol_pound}getWSDLDirectory or the absolute path to the directory. + */ + public List readWSDLs(String fromDir) throws WSDLException { + if ( fromDir == null ) { fromDir = ""; } + File wsdlDir = new File(fromDir); + if (!wsdlDir.isAbsolute()) { + wsdlDir = new File(this.mWsdlDirPath, fromDir); + } + + List wsdlFiles = new ArrayList(); + try { + wsdlFiles = listWSDLFiles(wsdlDir, true); + } catch (IOException ioEx) { + throw new WSDLException("WSDLFileReadError", ioEx.getMessage(),ioEx); + } + + List wsdlPaths = new ArrayList(); + for ( File wsdlFile : wsdlFiles) { + wsdlPaths.add(wsdlFile.getAbsolutePath()); + } + Collections.sort(wsdlPaths); + + List wsdlList = new ArrayList(); + for ( String wsdlPath : wsdlPaths ) { + Definition wsdlDef = readWSDL(wsdlPath); + wsdlList.add(wsdlDef); + } + return wsdlList; + } + /** + * finds PortType using port type ( interface ) qname. + */ + public static PortType findInterface(Definition wsdlDef, QName interfaceName) { + return wsdlDef.getPortType(interfaceName); + } + /** finds the Service using service qname */ + public static Service findService(Definition wsdlDef, QName serviceName) { + return wsdlDef.getService(serviceName); + } + /** finds the wsdl port using service qname and endpoint name */ + public static Port findServiceEndpoint(Definition wsdlDef, QName serviceName, String endpointName) { + Service service = null; + Port port = null; + service = findService(wsdlDef, serviceName); + if ( service != null ) { + port = service.getPort(endpointName); + } + return port; + } + /** + * finds the binding definition to which the service with serviceName and endpointName was bound. + */ + public static Binding findServiceBinding(Definition wsdlDef, QName serviceName, String endpointName) { + Binding binding = null; + Port port = findServiceEndpoint(wsdlDef, serviceName, endpointName); + if ( port != null ) { + binding = port.getBinding(); + } + return binding; + } + /** + * finds the binding definition using the interface(portType) qname with a + */ + public static Binding findInterfaceBinding(Definition wsdlDef, + QName interfaceQName, QName extQName) { + Map bindingMap = wsdlDef.getBindings(); + @SuppressWarnings("unchecked") + Collection bindings = bindingMap.values(); + for ( Binding binding : bindings ) { + if ( binding.getPortType().getQName().equals(interfaceQName)) { + return binding; + } + } + return null; + } + + /** + * find the wsdl4j operation corresponds to the interface+operation. + * @param wsdlDef wsdl definition + * @param portTypeQName portType QName + * @param opName operation name. if null, first operation in the portType + * is returned. + * @return Operation corresponding to the portType+opName + */ + public static Operation findOperation(Definition wsdlDef, + QName portTypeQName, String opName) { + Operation operation = null; + PortType portType = wsdlDef.getPortType(portTypeQName); + if ( portType != null ) { + if ( opName != null ) { + operation = portType.getOperation(opName, null, null); + } else { + @SuppressWarnings("unchecked") + List list = portType.getOperations(); + if ( list != null && list.size() > 0 ) { + operation = list.get(0); + } + } + } + return operation; + } + /** + * verifies whether the wsdl definition contains the specified service descriptions or not. Used + * to locate the wsdl definition for the services describes in service unit deployment + * descriptor(jbi.xm). + * @param interfaceName portType qname to find in the definition. can be null if you are trying to + * find only service endpoint description. + * @param serviceName qname for the service to find in this wsdl. can be null if + * you are trying to find only portType (abstract service) description. + * @param endpointName port name to find in the service definition. null if only + * service with any port should be looked up. + * + * @return true if the wsdl definition contains the specified service description. + */ + public static boolean isWSDLFor(Definition wsdlDef, + QName interfaceName, QName serviceName, String endpointName) { + PortType portType = null; + Service service = null; + Port port = null; + if ( interfaceName != null ) { + portType = findInterface(wsdlDef, interfaceName); + } + + if ( serviceName != null ) { + service = findService(wsdlDef, serviceName); + } + + if ( endpointName != null && service != null ) { + port = service.getPort(endpointName); + } + + boolean isWSDL = true; + + if ( (interfaceName != null && portType == null) || + ( serviceName != null && service == null ) || + ( endpointName != null && (service == null || port == null)) ) { + isWSDL = false; + } + + return isWSDL; + } + /** + * creates a binding definition that contains a service engine binding elements in the specified + * wsdl definition for a portType. It will try to find/create the binding element with interface + * local name with a "_JBISEBinding" suffix and add service engine binding element to it if it + * is not present. + * @param wsdl wsdl definition + * @param interfaceName portType qname to which the binding is created. + * @return a Binding contains service engine binding that is created for the portType. + */ + public Binding create${artifactId}Binding(Definition wsdl, QName interfaceName) { + QName bindingQName = new QName(wsdl.getQName().getNamespaceURI(), + interfaceName.getLocalPart() + "_JBISEBinding"); + Binding binding = wsdl.getBinding(bindingQName); + if ( binding == null ) { + binding = wsdl.createBinding(); + binding.setQName(bindingQName); + binding.setPortType(wsdl.getPortType(interfaceName)); + binding.setUndefined(false); + + ExtensibilityElement bindingExt = + SEBindingExt.SEBindingExtImpl.addExtensibilityElement(wsdl, binding); + + wsdl.addBinding(binding); + } + return binding; + } + /** + * creates port and binding elements that provide the the service engine binding for a service. + * @param wsdl wsdl definition + * @param interfaceName portType qname to which the binding is created. + * @param serviceName service under which the port definition bound to the service engine binding + * should be created. + * @param endpointName port name. + * @return a Binding contains service engine binding that is created for the portType. + */ + public Binding create${artifactId}Binding(Definition wsdl, QName interfaceName, QName serviceName, String endpointName ) { + Binding binding = null; + Service service = findService(wsdl, serviceName); + if ( service == null ) { + return null; + } + Port port = service.getPort(endpointName); + if ( port != null ) { + binding = port.getBinding(); + } else { + // create port + port = wsdl.createPort(); + port.setName(endpointName); + binding = create${artifactId}Binding(wsdl, interfaceName); + port.setBinding(binding); + service.addPort(port); + } + return binding; + } + /** prints the wsdl to text from the wsdl definition */ + public static void printWSDL(PrintWriter out, Definition def) { + try { + WSDLFactory factory = WSDLFactory.newInstance(); + WSDLWriter wsdlWriter = factory.newWSDLWriter(); + wsdlWriter.writeWSDL(def, out); + } catch (WSDLException ex) { + ex.printStackTrace(out); + } + } + /** prints the wsdl to text from the wsdl definition */ + public static String printWSDLToString(Definition def) { + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + printWSDL(out, def); + out.close(); + return writer.getBuffer().toString(); + } + /** returns an existing namespace prefix or create one if not exists for the corresponding namespaceURI */ + public static String getNamespacePrefix(Definition def, String namespaceURI, String defPrefix) { + String prefix = null; + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + Set keySet = def.getNamespaces().keySet(); + String newPrefix = "ns"; + if ( defPrefix != null && defPrefix.trim().length() > 0 ){ + newPrefix = defPrefix; + } + prefix = newPrefix; + for ( int i=0; i < Integer.MAX_VALUE; ++i) { + if (!keySet.contains(prefix)) { + break; + } else { + prefix = newPrefix + i; + } + } + } + return prefix; + } + + /** + * creates and adds the jbi service engine binding extensibility element to the wsdl definition + * under specified binding definition. + */ + public static void addExtensibilityElement(Definition wsdlDef, + ElementExtensible extensibleEl, ExtensibilityElement extEl, String defPrefix) { + QName elementType = extEl.getElementType(); + String namespaceURI = elementType.getNamespaceURI(); + String prefix = wsdlDef.getPrefix(namespaceURI); + if ( prefix == null ) { + // no namespace prefix defined. create one. + prefix = WSDLProcessor.getNamespacePrefix(wsdlDef, namespaceURI, defPrefix); + wsdlDef.addNamespace(prefix, namespaceURI); + } + extensibleEl.addExtensibilityElement(extEl); + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/enginetest/ServiceEngineTest.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/enginetest/ServiceEngineTest.java new file mode 100644 index 000000000..926d7af97 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/enginetest/ServiceEngineTest.java @@ -0,0 +1,54 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ${artifactId}Test.java + */ + +package enginetest; + +import net.openesb.component.${artifactId}.test.JBIComponentTestClient; +import net.openesb.component.${artifactId}.test.SOAPBindingTestClient; +import java.util.Properties; + import junit.framework.TestCase; + +/** + * The test method in this testcase uses the SOAPBindingTestClient to send the + * input document to the echo service provided by service engine via soap binding + * component and receives the output document which will be placed in test results + * directory under the same package as this test case. + * @see com.sun.jbi.sample.component.test.SOAPBindingTestClinet + * @author chikkala + */ +public class ServiceEngineTest + extends TestCase +{ + public ServiceEngineTest(String testName) { + super(testName); + } + + public void test1() throws Exception { + String testPropertiesPath = "test1.properties"; + JBIComponentTestClient testClient = new SOAPBindingTestClient(); + Properties testProps = testClient.loadTestProperties(this.getClass(), testPropertiesPath); + testClient.testService(testProps); + } + + public void test2() throws Exception { + String testPropertiesPath = "test2.properties"; + JBIComponentTestClient testClient = new SOAPBindingTestClient(); + Properties testProps = testClient.loadTestProperties(this.getClass(), testPropertiesPath); + testClient.testService(testProps); + } + + public static void main(String[] args) { + try { + ServiceEngineTest compTest = new ServiceEngineTest("ServiceEngineTest"); + compTest.test1(); + compTest.test2(); + } catch(Exception ex) { + ex.printStackTrace(); + } + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/enginetest/test1.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/enginetest/test1.properties new file mode 100644 index 000000000..fd5ee2403 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/enginetest/test1.properties @@ -0,0 +1,11 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +input.file=test1Input.xml +${symbol_pound} expected.file=Expected.xml +output.file=test1Output.xml +soap.binding.inbound.endpoint.address.location=http://localhost:12010/ServiceEngine/greetings +soap.binding.soapaction=sayHello +fail.on.soap.fault=true + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/enginetest/test1Input.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/enginetest/test1Input.xml new file mode 100644 index 000000000..b1a3ecc9e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/enginetest/test1Input.xml @@ -0,0 +1,15 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + Srinivasan + Chikkala + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/enginetest/test2.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/enginetest/test2.properties new file mode 100644 index 000000000..5a35303e5 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/enginetest/test2.properties @@ -0,0 +1,11 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +input.file=test2Input.xml +${symbol_pound} expected.file=Expected.xml +output.file=test2Output.xml +soap.binding.inbound.endpoint.address.location=http://localhost:12010/ServiceEngine/greetings +soap.binding.soapaction=sayGoodbye +fail.on.soap.fault=true + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/enginetest/test2Input.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/enginetest/test2Input.xml new file mode 100644 index 000000000..47952104c --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/enginetest/test2Input.xml @@ -0,0 +1,15 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + Srinivasan + Chikkala + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java new file mode 100644 index 000000000..919ad6829 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java @@ -0,0 +1,298 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JBIComponentTestClient.java + */ + +package net.openesb.component.${artifactId}.test; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Properties; + +/** + * This class implements the base framework for the testing the JBI components. + * Testing the JBI component involves may require deploying a service to the + * component(s) to enable the service provided by the test component and then + * invoking the service provided by the test component. If the test component is + * a binding component, then a service provider component such as sample service + * engine is required to test the component end to end. If the test component is a + * service engine, then the service on the test component can be invoked via + * soap/http binding component. + * + * This class provides the utilites to read the test properties, read the input + * message from the file and save the output to the file. The testService + * method implemented here can be executed as the test for the component. The + * testService method calls the invokeService method with the input document and + * expects a output document or error that will be saved to the output file. + * The method invokeService should be implemented by the extended test classes to + * inplement a suitable service consumer implemenation for the test compoent. + * See JMXBindingTestClient.java or SOAPBidningTestClient.java for more details + * on how to implement a partucular test service consumer. + * + * @author chikkala + */ +public abstract class JBIComponentTestClient { + + public static final String TEST_PROPS_FILE_PROP = "test.properties.file"; + public static final String TEST_RESULTS_DIR_PROP = "test.results.dir"; + public static final String TEST_SRC_DIR_PROP = "test.src.dir"; + + public static final String TEST_PACKAGE_PROP = "test.package.name"; + + public static final String INPUT_FILE_PROP = "input.file"; + public static final String EXPECTED_FILE_PROP = "expected.file"; + public static final String OUTPUT_FILE_PROP = "output.file"; + + public static final String DEF_TEST_PROP_FILE = "test.properties"; + public static final String DEF_INPUT_FILE = "Input.xml"; + public static final String DEF_OUTPUT_FILE = "Output.xml"; + public static final String DEF_TEST_RESULTS_DIR = "test-results"; + + public JBIComponentTestClient() { + } + /** + * returns the absolute resource path w.r.t. the packagePath if the resource name + * is relative else return the resourceName as it is. + * @param package name ( dot separated ) + * @param resourcName dot separated name or a absolute resource path + * @return abosolute resource path with path separator + */ + public static String resolveResourcePath(String packageName, String resourceName) { + String resourcePath = resourceName; + if ( !resourceName.startsWith("/")) { + // it is relative resource file. resolve it w.r.t. testPackage + String pkgDir = packageName.trim().replace('.', '/'); + if ( pkgDir.length() != 0 ) { + pkgDir += "/"; + } + resourcePath = "/" + pkgDir + resourceName; + } + return resourcePath; + } + /** + * loads the resource file as properties. + * @param testPackage package name where this test belongs + * @param testPropPath resource path relative to testPackage or absolute resource path + */ + public Properties loadTestProperties(String testPackage, String testPropPath) throws IOException { + String propsResourcePath = resolveResourcePath(testPackage, testPropPath); + + InputStream testPropIS = null; + try { + testPropIS = this.getClass().getResourceAsStream(propsResourcePath); + Properties testProps = new Properties(); + testProps.load(testPropIS); + testProps.setProperty(TEST_PACKAGE_PROP, testPackage); + return testProps; + } finally { + if ( testPropIS != null ) { + try { + testPropIS.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + } + /** + * load default test properties file in the testClass package. + * @param testClass Class where to look for the default test properties + * @param testPropPath resource path relative to testPackage or absolute resource path + * @return Properties test properties + */ + public Properties loadTestProperties(Class testClass, String testPropPath) throws IOException { + return loadTestProperties(testClass.getPackage().getName(), testPropPath ); + } + /** + * load default test properties file in the testClass package. + * @param testClass Class where to look for the default test properties + * @return Properties test properties + */ + public Properties loadTestProperties(Class testClass) throws IOException { + return loadTestProperties(testClass.getPackage().getName(), DEF_TEST_PROP_FILE ); + } + /** + * loads the resource file to string bugger + * @param inputFile resource file path + */ + public StringBuffer loadResourceFile(String resourcePath) throws FileNotFoundException, IOException { + + InputStream inputIS = null; + InputStreamReader inputReader = null; + BufferedReader reader = null; + StringWriter strWriter = null; + PrintWriter writer = null; + try { + inputIS = this.getClass().getResourceAsStream(resourcePath); + inputReader = new InputStreamReader(inputIS); + reader = new BufferedReader(inputReader); + strWriter = new StringWriter(); + writer = new PrintWriter(strWriter); + for ( String line = null; (line = reader.readLine()) != null ; ) { + writer.println(line); + } + writer.close(); + strWriter.close(); + return strWriter.getBuffer(); + } finally { + if ( inputIS != null ) { + try { + inputIS.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + } + + /** + * reads data from the reader and saves to file + * @param reader reader from which to read the data and save to file + * @param outputFilePath absolute file path + */ + public void saveOutputToFile(Reader reader, String outputFilePath) throws IOException { + + BufferedReader buff = null; + FileWriter fileWriter = null; + PrintWriter writer = null; + try { + buff = new BufferedReader(reader); + fileWriter = new FileWriter(outputFilePath); + writer = new PrintWriter(fileWriter); + for ( String line = null; (line = buff.readLine()) != null ; ) { + writer.println(line); + } + } finally { + if ( writer != null ) { + writer.close(); + } + if ( fileWriter != null ) { + fileWriter.close(); + } + } + } + + /** + * resource path. + */ + public String getInputFileResourcePath(Properties testProps) { + + String testPkg = testProps.getProperty(TEST_PACKAGE_PROP, ""); + String inputFile = testProps.getProperty(INPUT_FILE_PROP, DEF_INPUT_FILE); + String resourcePath = resolveResourcePath(testPkg, inputFile); + return resourcePath; + } + /** + * return resource path + */ + public String getExpectedFileResourcePath(Properties testProps) { + + String testPkg = testProps.getProperty(TEST_PACKAGE_PROP, ""); + String resourcePath = null; + String expFile = testProps.getProperty(EXPECTED_FILE_PROP, null); + if ( expFile != null ) { + resourcePath = resolveResourcePath(testPkg, expFile); + } + return resourcePath; + } + /** + * return the absolute path to the output file + */ + public String getOutputFilePath(Properties testProps) { + + String defPackage = this.getClass().getPackage().getName(); + String testPackage = testProps.getProperty(TEST_PACKAGE_PROP, defPackage); + String testPackageDir = testPackage.replace('.','/'); + String outputFile = testProps.getProperty(OUTPUT_FILE_PROP, DEF_OUTPUT_FILE); + + String userHomeDir = System.getProperty("user.home", ""); + String userDir = System.getProperty("user.dir", userHomeDir); + String defResultsDir = userDir + "/" + DEF_TEST_RESULTS_DIR; + String sysResultDir = System.getProperty(TEST_RESULTS_DIR_PROP, defResultsDir); + String resultDir = testProps.getProperty(TEST_RESULTS_DIR_PROP, sysResultDir); + + File outputDir = new File(resultDir, testPackageDir); + // System.out.println("Creating the test results output dir " + outputDir); + outputDir.mkdirs(); + return (new File(outputDir, outputFile)).getAbsolutePath(); + } + + /** + * This is the method where the actual service invocation code based on the + * type of client will be implemented. testService method calls this method + * after preparing the test input and then processes the output returned by + * this method to complte the test. + * @param inputDoc + * @param testProps + * @throws java.lang.Exception + * @return + */ + public abstract StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception; + + /** + * abstract method implemented by the extended classes to compare the output + * document with the expected output to determine the test is a failure or + * success. + * @param outputDoc + * @param expectedDoc + * @param testProps + * @throws java.lang.Exception + */ + public abstract void compareWithExpectedOutput(StringBuffer outputDoc, + StringBuffer expectedDoc, Properties testProps) throws Exception; + + /** + * This is the main test method that a test case will call to test the + * service. The standard steps that required to invoke the service and + * process the output will be done in this method. Each test case creates + * the test Properties required for that test and executes this method for + * testing the service by passing the test properties to it. This method + * prepares the input and executes the invokeService method to invoke a + * service with the prepared input. It then processes the return value from + * the invokeService to complete the test. + * + * @param testProps + * @throws java.lang.Exception + */ + public void testService(Properties testProps) throws Exception { + + String inFilePath = getInputFileResourcePath(testProps); + String outFilePath = getOutputFilePath(testProps); + String expFilePath = getExpectedFileResourcePath(testProps); + File outDir = (new File(outFilePath)).getParentFile(); + outDir.mkdirs(); + + StringBuffer outputDoc = new StringBuffer(); + + try { + StringBuffer inputDoc = loadResourceFile(inFilePath); + outputDoc = invokeService(inputDoc, testProps); + if ( expFilePath != null ) { + StringBuffer expOutputDoc = loadResourceFile(expFilePath); + compareWithExpectedOutput(inputDoc, expOutputDoc, testProps); + } + } catch (Exception ex) { + StringWriter out = new StringWriter(); + ex.printStackTrace(new PrintWriter(out)); + outputDoc.append(out.getBuffer()); + throw ex; + } finally { + if ( outputDoc != null ) { + System.out.println(outputDoc); + this.saveOutputToFile(new StringReader(outputDoc.toString()), outFilePath); + } + } + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java new file mode 100644 index 000000000..7cc8c103e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java @@ -0,0 +1,136 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingTestClient.java + */ + +package net.openesb.component.${artifactId}.test; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanException; +import javax.management.MBeanServerConnection; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.management.ReflectionException; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; + +/** + * This class extends the JBIComponentTestClient and implements the invokeService + * method to test the proxy service consumer implementation by a binding component + * that can communicate with the external service consumers using JMX interface. + * @author chikkala + */ +public class JMXBindingTestClient extends JBIComponentTestClient { + + public static final String CONSUMER_EP_INBOUND_OPERATION_PROP = "consumer.jmx.bc.ep.operation"; + public static final String CONSUMER_EP_ADDRESS_MBEAN_PROP = "consumer.jmx.bc.ep.address.mbean"; + public static final String CONSUMER_EP_ADDRESS_URL_PROP = "consumer.jmx.bc.ep.address.serviceURL"; + public static final String CONSUMER_EP_ADDRESS_USERNAME_PROP = "consumer.jmx.bc.ep.address.username"; + public static final String CONSUMER_EP_ADDRESS_PASSWORD_PROP = "consumer.jmx.bc.ep.address.password"; + + public static final String PROVIDER_EP_INBOUND_OPERATION_PROP = "provider.jmx.bc.ep.operation"; + public static final String PROVIDER_EP_ADDRESS_MBEAN_PROP = "provider.jmx.bc.ep.address.mbean"; + public static final String PROVIDER_EP_ADDRESS_URL_PROP = "provider.jmx.bc.ep.address.serviceURL"; + public static final String PROVIDER_EP_ADDRESS_USERNAME_PROP = "provider.jmx.bc.ep.address.username"; + public static final String PROVIDER_EP_ADDRESS_PASSWORD_PROP = "provider.jmx.bc.ep.address.password"; + + + /** + * Creates a new instance of JMXBindingTestClient + */ + public JMXBindingTestClient() { + super(); + } + /** + * creates jmx connection to send the input message to the binding component. + */ + public static MBeanServerConnection getJMXConnection(Properties testProps) + throws MalformedURLException, IOException { + + String jmxUrl = testProps.getProperty(CONSUMER_EP_ADDRESS_URL_PROP); + String username = testProps.getProperty(CONSUMER_EP_ADDRESS_USERNAME_PROP); + String password = testProps.getProperty(CONSUMER_EP_ADDRESS_PASSWORD_PROP); + + Map env = new HashMap(); + if ( username != null ) { + String [] credentials = new String [] {username, password}; + env.put("jmx.remote.credentials", credentials); + env.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, JMXBindingTestClient.class.getClassLoader()); + } + JMXServiceURL serviceURL = new JMXServiceURL(jmxUrl); + JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, env); + MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection(); + return mbeanServerConnection; + } + /** + * constructs the jmx mbean objectname + */ + public static ObjectName createJMXEndpointMBeanObjectName(String endpointAddressMBean) throws MalformedObjectNameException { + // String objectName = JMX_DOMAIN + ":" + JMX_ENDPOINT_ADDRESS_KEY + "=" + endpointAddressMBean; + return new ObjectName(endpointAddressMBean); + } + /** + * invokes a jmx mbean to send message. + */ + public static StringBuffer invokeSendMessage(MBeanServerConnection jmxConn, ObjectName epAddressName, + String operation, StringBuffer inputDoc) + throws MalformedObjectNameException, InstanceNotFoundException, + MBeanException, ReflectionException, IOException { + StringBuffer outDoc = null; + + Object result = null; + String mbeanOperation = "sendMessage"; + + Object[] params = new Object[2]; + params[0] = operation; + params[1] = inputDoc; + + String[] signature = new String[2]; + signature[0] = "java.lang.String"; + signature[1] = "java.lang.StringBuffer"; + + result = jmxConn.invoke(epAddressName, mbeanOperation, params, signature); + if ( result != null ) { + outDoc = (StringBuffer)result; + } + + return outDoc; + } + /** + * invokes the service via jmx interface. + */ + public StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception { + + ObjectName epAddressName = new ObjectName(testProps.getProperty(CONSUMER_EP_ADDRESS_MBEAN_PROP)); + String operation = testProps.getProperty(CONSUMER_EP_INBOUND_OPERATION_PROP); + + MBeanServerConnection jmxConn = getJMXConnection(testProps); + StringBuffer outputDoc = null; + try { + outputDoc = invokeSendMessage(jmxConn, epAddressName, operation, inputDoc); + } catch (MBeanException ex) { + Exception targetEx = ex.getTargetException(); + if ( targetEx != null ) { + throw targetEx; + } else { + throw ex; + } + } + return outputDoc; + } + /** no expected output comparison implemented */ + public void compareWithExpectedOutput(StringBuffer inputDoc, + StringBuffer expectedDoc, + Properties testProps) throws Exception { + // throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java new file mode 100644 index 000000000..28f534612 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java @@ -0,0 +1,159 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * SOAPBindingTestClient.java + */ + +package net.openesb.component.${artifactId}.test; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Properties; +import javax.xml.soap.MessageFactory; +import javax.xml.soap.MimeHeaders; +import javax.xml.soap.SOAPConnection; +import javax.xml.soap.SOAPConnectionFactory; +import javax.xml.soap.SOAPException; +import javax.xml.soap.SOAPFault; +import javax.xml.soap.SOAPMessage; +import javax.xml.soap.SOAPPart; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +/** + * This class extends the JBIComponentTestClient and implements the invokeService + * method to test the Service Engine via SOAP Binding by invoking the service using + * SOAP Client that sends the message to the service provider via soaphttp binding. + * + * @author chikkala + */ +public class SOAPBindingTestClient extends JBIComponentTestClient { + + private static final String ADDRESS_PROP = "soap.binding.inbound.endpoint.address.location"; + private static final String SOAP_ACTION_PROP = "soap.binding.soapaction"; + private static final String FAIL_ON_SOAP_FAULT_PROP = "fail.on.soap.fault"; + + private static MessageFactory messageFactory; + private static SOAPConnectionFactory soapConnFactory; + private static SOAPConnection connection; + + public SOAPBindingTestClient() throws SOAPException { + init(); + } + /** initializes SOAP client */ + private synchronized void init() throws SOAPException { + if ( messageFactory == null ) { + messageFactory = MessageFactory.newInstance(); + } + if ( soapConnFactory == null ) { + soapConnFactory = SOAPConnectionFactory.newInstance(); + } + if ( connection == null ) { + connection = soapConnFactory.createConnection(); + } + } + + /** + * read in a soap message from the given input file + */ + private static SOAPMessage loadMessage(Reader inReader) throws SOAPException, IOException { + //Create and populate the message from a file + SOAPMessage message = messageFactory.createMessage(); + SOAPPart soapPart = message.getSOAPPart(); + StreamSource preppedMsgSrc = new StreamSource(inReader); + soapPart.setContent(preppedMsgSrc); + message.saveChanges(); + return message; + } + /** saves the SOAP message as xml text to a writer */ + private static void saveMessage(SOAPMessage response, Writer outWriter) + throws TransformerConfigurationException, SOAPException, TransformerException { + + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + transformerFactory.setAttribute("indent-number", new Integer(2)); + Transformer transformer = transformerFactory.newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + + SOAPPart replySOAPPart = response.getSOAPPart(); + Source sourceContent = replySOAPPart.getContent(); + StreamResult result = new StreamResult(outWriter); + try { + transformer.transform(sourceContent, result); + } catch (TransformerException ex) { + ex.printStackTrace(); + } + } + /** + * Send a soap message + * @param destination URL to send to + * @param message message to send + * @param expectedHttpStatus expected http status code or null if success is expected + * @return reply soap message + */ + private static SOAPMessage sendMessage(String destination, SOAPMessage message, String soapAction) throws SOAPException { + + // Add soapAction if not null + if (soapAction != null) { + MimeHeaders hd = message.getMimeHeaders(); + hd.setHeader("SOAPAction", soapAction); + } + // Send the message and get a reply + SOAPMessage reply = null; + reply = connection.call(message, destination); + return reply; + } + /** check the xml text in the StringBuffer passed contains SOAP Fault. */ + public boolean isSOAPFault(StringBuffer msgBuff) { + SOAPFault soapFault = null; + try { + SOAPMessage inMsg = loadMessage(new StringReader(msgBuff.toString())); + soapFault = inMsg.getSOAPBody().getFault(); + } catch (Exception ex) { + // any exception, means either no fault elem or invalid xml + } + return (soapFault != null); + } + /** + * invokes the service ny sending the input message and return the output + * message returned by the service. + */ + public StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception { + + String soapAction = testProps.getProperty(SOAP_ACTION_PROP); + String destination = testProps.getProperty(ADDRESS_PROP); + SOAPMessage inMsg = loadMessage(new StringReader(inputDoc.toString())); + SOAPMessage outMsg = sendMessage(destination, inMsg, soapAction); + StringWriter out = new StringWriter(); + saveMessage(outMsg, out); + StringBuffer outDoc = out.getBuffer(); + Boolean failOnSoapFault = Boolean.valueOf(testProps.getProperty(FAIL_ON_SOAP_FAULT_PROP, "false")); + if ( failOnSoapFault ) { + if (isSOAPFault(outDoc)) { + StringBuffer errBuff = new StringBuffer("${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} SOAP FAULT ${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} ${symbol_escape}n"); + errBuff.append(outDoc); + throw new Exception(errBuff.toString()); + } + } + return outDoc; + } + /** comparing the received output document with the expected document. throw + * exception if the docs are not same. throwing the exception in this method + * fails the test. + */ + public void compareWithExpectedOutput(StringBuffer outputDoc, + StringBuffer expectedDoc, + Properties testProps) throws Exception { + // throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/build.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/build.properties new file mode 100644 index 000000000..945269943 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/build.properties @@ -0,0 +1,22 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} Build properties for the service assembly builds +${symbol_pound} user.properties.file=../../user.properties +src.dir=src +${symbol_pound} This directory is removed when the project is cleaned: +build.dir=build +service.assembly.name=testSA + +${symbol_pound}no.deps=true set the no.deps property if there are no SUs to build +${symbol_pound} for each testSU define the properties here. +${symbol_pound} dependent BC SU projects dependency +${symbol_pound} service unit name +service.unit.name.testSUBC=testSUBC +${symbol_pound} service unit project directory +project.testSUBC=testSUBC + +${symbol_pound} service unit name +service.unit.name.testSUSE=testSUSE +${symbol_pound} service unit project directory +project.testSUSE=testSUSE diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/build.xml new file mode 100644 index 000000000..02f75e641 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/build.xml @@ -0,0 +1,140 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.assembly.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml new file mode 100644 index 000000000..ed9f610e9 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml @@ -0,0 +1,44 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + ${artifactId}_TestSA + This is a test Service Assembly to test Engine + + + + + ${artifactId}_TestSUBC + This service unit enables soap inbound endpoint for a service in service engine + + + testSUBC.zip + sun-http-binding + + + + + ${artifactId}_TestSUSE + This service unit enables greetings service provider in service engine + + + testSUSE.zip + ${artifactId} + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build.properties new file mode 100644 index 000000000..1bfd81c69 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build.properties @@ -0,0 +1,10 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} Build properties for the service unit builds +src.dir=src +${symbol_pound} This directory is removed when the project is cleaned: +${symbol_pound}build.dir=../../../build/test/testSU/build +build.dir=build +service.unit.name=testSUSE + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml new file mode 100644 index 000000000..777fb3cf9 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml @@ -0,0 +1,74 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC.zip b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC.zip new file mode 100644 index 000000000..f4205815d Binary files /dev/null and b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC.zip differ diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC/Greetings.wsdl b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC/Greetings.wsdl new file mode 100644 index 000000000..038d91bcd --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC/Greetings.wsdl @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml new file mode 100644 index 000000000..05f4f9bef --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml @@ -0,0 +1,17 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/src/Greetings.wsdl b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/src/Greetings.wsdl new file mode 100644 index 000000000..8a160abd0 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/src/Greetings.wsdl @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml new file mode 100644 index 000000000..05f4f9bef --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml @@ -0,0 +1,17 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build.properties new file mode 100644 index 000000000..1bfd81c69 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build.properties @@ -0,0 +1,10 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} Build properties for the service unit builds +src.dir=src +${symbol_pound} This directory is removed when the project is cleaned: +${symbol_pound}build.dir=../../../build/test/testSU/build +build.dir=build +service.unit.name=testSUSE + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml new file mode 100644 index 000000000..846415d3a --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml @@ -0,0 +1,74 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE.zip b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE.zip new file mode 100644 index 000000000..2db1a3a5c Binary files /dev/null and b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE.zip differ diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/Greetings.wsdl b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/Greetings.wsdl new file mode 100644 index 000000000..038d91bcd --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/Greetings.wsdl @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml new file mode 100644 index 000000000..8235893ee --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml @@ -0,0 +1,17 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/goodbye.xsl b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/goodbye.xsl new file mode 100644 index 000000000..c60e39b73 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/goodbye.xsl @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + Goodbye ! Have a great time. + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/hello.xsl b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/hello.xsl new file mode 100644 index 000000000..994b66f98 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/hello.xsl @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + Hello ! + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/xsltmap.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/xsltmap.properties new file mode 100644 index 000000000..44baf5452 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/xsltmap.properties @@ -0,0 +1,31 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} properties will be used to find the xslt file that will be used for invoking a +${symbol_pound} service operation. +${symbol_pound} The "xsltmap.properties" file should contain two types of properties +${symbol_pound} 1. for namespace prefix to namespaceURI map that starts with "xmlns." prefix like +${symbol_pound} "xmlns.tns-prefix=http://www.sun.com/jbi/examples/sample-service/echo" +${symbol_pound} 2. a service description to xslt file properties with syntax like +${symbol_pound} "{tns-prefix}service-name=xslt_file_name" and +${symbol_pound} "{tns-prefix}service-name.{tns-prefix}operation-name=xslt_file_name" and +${symbol_pound} "{tns-prefix}service-name.{tns-prefix}interface-name.operation-name=xslt_file_name" . +${symbol_pound} the service description property is a "." delimited tokens that represents +${symbol_pound} a serive or interface qname and a operation name. To locate xslt file either with +${symbol_pound} service qname or service qname and operaton or serivice qname and interface qname +${symbol_pound} and operation, all the three properties specified above should be there for each xslt file. +${symbol_pound} + +xmlns.greet1=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greet2=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greettypes=http://www.sun.com/jbi/examples/sample-service/greetings/types +${symbol_pound} just service level default settings +{greet2}greetService=hello.xsl +${symbol_pound} service and operation +{greet2}greetService.{greet1}sayHello=hello.xsl +${symbol_pound} service, interface, operation +{greet2}greetService.{greet1}greetings.sayHello=hello.xsl +${symbol_pound} service and operation +{greet2}greetService.{greet1}sayGoodbye=goodbye.xsl +${symbol_pound} service, interface, operation +{greet2}greetService.{greet1}greetings.sayGoodbye=goodbye.xsl diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/Greetings.wsdl b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/Greetings.wsdl new file mode 100644 index 000000000..8a160abd0 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/Greetings.wsdl @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml new file mode 100644 index 000000000..8235893ee --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml @@ -0,0 +1,17 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/goodbye.xsl b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/goodbye.xsl new file mode 100644 index 000000000..c60e39b73 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/goodbye.xsl @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + Goodbye ! Have a great time. + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/hello.xsl b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/hello.xsl new file mode 100644 index 000000000..994b66f98 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/hello.xsl @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + Hello ! + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/xsltmap.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/xsltmap.properties new file mode 100644 index 000000000..44baf5452 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/xsltmap.properties @@ -0,0 +1,31 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} properties will be used to find the xslt file that will be used for invoking a +${symbol_pound} service operation. +${symbol_pound} The "xsltmap.properties" file should contain two types of properties +${symbol_pound} 1. for namespace prefix to namespaceURI map that starts with "xmlns." prefix like +${symbol_pound} "xmlns.tns-prefix=http://www.sun.com/jbi/examples/sample-service/echo" +${symbol_pound} 2. a service description to xslt file properties with syntax like +${symbol_pound} "{tns-prefix}service-name=xslt_file_name" and +${symbol_pound} "{tns-prefix}service-name.{tns-prefix}operation-name=xslt_file_name" and +${symbol_pound} "{tns-prefix}service-name.{tns-prefix}interface-name.operation-name=xslt_file_name" . +${symbol_pound} the service description property is a "." delimited tokens that represents +${symbol_pound} a serive or interface qname and a operation name. To locate xslt file either with +${symbol_pound} service qname or service qname and operaton or serivice qname and interface qname +${symbol_pound} and operation, all the three properties specified above should be there for each xslt file. +${symbol_pound} + +xmlns.greet1=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greet2=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greettypes=http://www.sun.com/jbi/examples/sample-service/greetings/types +${symbol_pound} just service level default settings +{greet2}greetService=hello.xsl +${symbol_pound} service and operation +{greet2}greetService.{greet1}sayHello=hello.xsl +${symbol_pound} service, interface, operation +{greet2}greetService.{greet1}greetings.sayHello=hello.xsl +${symbol_pound} service and operation +{greet2}greetService.{greet1}sayGoodbye=goodbye.xsl +${symbol_pound} service, interface, operation +{greet2}greetService.{greet1}greetings.sayGoodbye=goodbye.xsl diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/test/resources/projects/basic/archetype.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/src/test/resources/projects/basic/archetype.properties new file mode 100644 index 000000000..c7bdacd1c --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/src/test/resources/projects/basic/archetype.properties @@ -0,0 +1,6 @@ +#Tue Jul 30 12:05:58 IST 2013 +package=it.pkg +version=0.1-SNAPSHOT +groupId=archetype.it +artifactId=ServiceEngine-archetype +glassfishLocation=C:\\GlassFishESBv22\\glassfish diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/src/test/resources/projects/basic/goal.txt b/maven-archtype-v2/maven-archetype-service-engine-v2/src/test/resources/projects/basic/goal.txt new file mode 100644 index 000000000..e69de29bb diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/ServiceEngine-archetype-1.0-SNAPSHOT.jar b/maven-archtype-v2/maven-archetype-service-engine-v2/target/ServiceEngine-archetype-1.0-SNAPSHOT.jar new file mode 100644 index 000000000..f581fde1a Binary files /dev/null and b/maven-archtype-v2/maven-archetype-service-engine-v2/target/ServiceEngine-archetype-1.0-SNAPSHOT.jar differ diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/META-INF/maven/archetype-metadata.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/META-INF/maven/archetype-metadata.xml new file mode 100644 index 000000000..ea7fd9335 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,82 @@ + + + + + + + + + C:\\GlassFishESBv22\\glassfish + + + + + test/java + + **/*.xml + **/*.java + **/*.properties + + + + src/java + + **/*.java + + + + test/testSA + + **/*.xml + **/*.properties + + + + nbproject + + **/*.xml + **/*.properties + + + + src/conf + + **/*.xml + + + + nbproject/private + + **/*.xml + **/*.properties + + + + test/testSA + + **/*.xsl + **/*.zip + **/*.wsdl + + + + + + build.xml + install-params.properties + m2nbbuild-impl.xml + m2nbbuild.properties + m2nbbuild.xml + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build.xml new file mode 100644 index 000000000..14afd1d29 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build.xml @@ -0,0 +1,72 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + Builds, tests, and runs the project ${artifactId}. + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/pom.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/pom.xml new file mode 100644 index 000000000..1e58b6067 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/pom.xml @@ -0,0 +1,38 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + 4.0.0 + + ${package} + ${artifactId}-archetype + ${version} + maven-archetype + + ${artifactId}-archetype + + + + + org.apache.maven.archetype + archetype-packaging + 2.2 + + + + + + + maven-archetype-plugin + 2.2 + + + + + + Maven project for JBI Component that contains the + maven and netbeans build setup and component code to build and test the JBI Component. + + http://open-esb.org + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml new file mode 100644 index 000000000..c493031be --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml @@ -0,0 +1,33 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml new file mode 100644 index 000000000..2bdebaa2b --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml @@ -0,0 +1,146 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + org.netbeans.modules.apisupport.project + + + ${symbol_dollar}{artifactId} + + + + org.apache.tools.ant.module + + + + 3 + 3.27.0.2 + + + + org.jdesktop.layout + + + + 1 + 1.4 + + + + org.netbeans.modules.java.project + + + + 1 + 1.12 + + + + org.netbeans.modules.project.ant + + + + 1 + 1.16 + + + + org.netbeans.modules.projectapi + + + + 1 + 1.13 + + + + org.netbeans.modules.projectuiapi + + + + 1 + 1.24.0.6 + + + + org.netbeans.modules.queries + + + + 1 + 1.10 + + + + org.openide.actions + + + + 6.6.0.1 + + + + org.openide.awt + + + + 6.11.0.1 + + + + org.openide.dialogs + + + + 7.5 + + + + org.openide.execution + + + + 1.10 + + + + org.openide.filesystems + + + + 7.3 + + + + org.openide.loaders + + + + 6.5 + + + + org.openide.nodes + + + + 7.2.0.1 + + + + org.openide.util + + + + 7.9.0.1 + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test1Input.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test1Input.xml new file mode 100644 index 000000000..b50d82c16 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test1Input.xml @@ -0,0 +1,18 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + Srinivasan + Chikkala + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test2Input.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test2Input.xml new file mode 100644 index 000000000..947bb579c --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/enginetest/test2Input.xml @@ -0,0 +1,18 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + Srinivasan + Chikkala + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/build.xml new file mode 100644 index 000000000..5456aa8f2 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/build.xml @@ -0,0 +1,143 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.assembly.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml new file mode 100644 index 000000000..fd6c5a710 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml @@ -0,0 +1,47 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + ${symbol_dollar}{artifactId}_TestSA + This is a test Service Assembly to test Engine + + + + + ${symbol_dollar}{artifactId}_TestSUBC + This service unit enables soap inbound endpoint for a service in service engine + + + testSUBC.zip + sun-http-binding + + + + + ${symbol_dollar}{artifactId}_TestSUSE + This service unit enables greetings service provider in service engine + + + testSUSE.zip + ${symbol_dollar}{artifactId} + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml new file mode 100644 index 000000000..96e95745f --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml @@ -0,0 +1,77 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml new file mode 100644 index 000000000..251f4073e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml new file mode 100644 index 000000000..251f4073e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml new file mode 100644 index 000000000..75340ea7d --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml @@ -0,0 +1,77 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml new file mode 100644 index 000000000..1ce2022bf --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml new file mode 100644 index 000000000..1ce2022bf --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/install-params.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/install-params.properties new file mode 100644 index 000000000..712a6a3ac --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/install-params.properties @@ -0,0 +1,3 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/m2nbbuild-impl.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/m2nbbuild-impl.xml new file mode 100644 index 000000000..2093d6b39 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/m2nbbuild-impl.xml @@ -0,0 +1,133 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + This project compile, package and test the JBI Components when invoked from Maven2. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/m2nbbuild.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/m2nbbuild.properties new file mode 100644 index 000000000..663de1bb9 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/m2nbbuild.properties @@ -0,0 +1,48 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} build properties file to set/override the properties of the netbeans project +${symbol_pound} build properties when the netbeans build is called from the maven build lifecycle. +${symbol_pound} Netbeans project when build from the IDE, uses a build.properties from the user.dir +${symbol_pound} of the Netbeans IDE to resolve some of the properties used in the project such as +${symbol_pound} the libraries classpath. +${symbol_pound} When invoking the Netbeans project build from maven, this build.properties file +${symbol_pound} is not available. So, you can add the properties defined in ide build properties +${symbol_pound} that this project uses here. +${symbol_pound} + +${symbol_pound} default local repository settings. If the repository location is different +${symbol_pound} -D command line option should override this (e.g. mvn -Dmaven.repo.local=/my/m2/repository +maven.repo.local=${symbol_dollar}{user.home}/.m2/repository +${symbol_pound} begin jbi admin settings +${symbol_pound} set the below properties if you want to override the properties from nbproject/project.properties +${symbol_pound} that sets the application server admin settings. +${symbol_pound} +${symbol_pound} jbi.as.home=C:/Sun/glassfish-v2-b58g +${symbol_pound} jbi.host=localhost +${symbol_pound} jbi.port=4848 +${symbol_pound} jbi.username=admin +${symbol_pound} jbi.password=adminadmin +${symbol_pound} end jbi admin settings +${symbol_pound} + +${symbol_pound} classpath settings +junit.ant.task.classpath=${symbol_dollar}{maven.repo.local}/ant/ant-junit/1.6.5/ant-junit-1.6.5.jar +junit.runtime.classpath=${symbol_dollar}{maven.repo.local}/junit/junit/3.8.2/junit-3.8.2.jar +libs.junit.classpath=${symbol_dollar}{junit.runtime.classpath}:${symbol_dollar}{junit.ant.task.classpath} +libs.jbi-cdk-ant-tasks.classpath=${symbol_dollar}{maven.repo.local}/open-esb/jbi-cdk/jbi-cdk-ant-tasks/${version}/jbi-cdk-ant-tasks-${version}.jar + +libs.jbi.classpath=${symbol_dollar}{maven.repo.local}/open-esb/jbi/1.0/jbi-1.0.jar +libs.wsdl4j.162.classpath=${symbol_dollar}{maven.repo.local}/wsdl4j/wsdl4j/1.6.2/wsdl4j-1.6.2.jar +${symbol_pound} libs.jaxws21.classpath=${symbol_dollar}{jbi.as.home}/lib/javaee.jar:${symbol_dollar}{jbi.as.home}/lib/webservices-rt.jar +libs.jaxws21.classpath=${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/activation/activation/1.1/activation-1.1.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/xml/soap/saaj-api/1.3/saaj-api-1.3.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/xml/ws/jaxws-api/2.1/jaxws-api-2.1.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/com/sun/xml/messaging/saaj/saaj-impl/1.3/saaj-impl-1.3.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/com/sun/xml/ws/jaxws-rt/2.1.2/jaxws-rt-2.1.2.jar + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/m2nbbuild.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/m2nbbuild.xml new file mode 100644 index 000000000..31217d15d --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/m2nbbuild.xml @@ -0,0 +1,37 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + This project compile, package and test the JBI Components when invoked from Maven2. + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/build-impl.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/build-impl.xml new file mode 100644 index 000000000..2e8e00c93 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/build-impl.xml @@ -0,0 +1,554 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + Inside: postArchTypeGen - Post task is getting executed! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Inside: postArchTypeGen - Post task executed successfully! + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/genfiles.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/genfiles.properties new file mode 100644 index 000000000..cfde66418 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/genfiles.properties @@ -0,0 +1,11 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +build.xml.data.CRC32=ac78c060 +build.xml.script.CRC32=9068f2c7 +build.xml.stylesheet.CRC32=8add101f@1.0 +${symbol_pound} This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +${symbol_pound} Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=ac78c060 +nbproject/build-impl.xml.script.CRC32=d15987fd +nbproject/build-impl.xml.stylesheet.CRC32=4ed53ee0@1.0 diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/jbi_admin.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/jbi_admin.xml new file mode 100644 index 000000000..8a7d2a523 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/jbi_admin.xml @@ -0,0 +1,504 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + +This ant script contains the jbi ant tasks and the targets and properties using +which the jbi admin commands can be performed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Usage : ant -f <fullpath>/jbi_admin.xml [options] [target] + options: -D<property>=<value> + Specify a property/value pairs as options that are valid for the target. + target : ant target name in jbi_admin.xml + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/jbiadmin-impl.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/jbiadmin-impl.xml new file mode 100644 index 000000000..7e7dca2ae --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/jbiadmin-impl.xml @@ -0,0 +1,339 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + Install, uninstall, reinstall, start, stop, shutdown jbi components. + + + + + + + + + + + + + + Must set jbi.host + Must set jbi.port + Must set jbi.username + Must set jbi.password + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/private/private.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/private/private.properties new file mode 100644 index 000000000..e540325d5 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/private/private.properties @@ -0,0 +1,6 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +javac.debug=true +javadoc.preview=true +user.properties.file=D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working57${symbol_escape}${symbol_escape}.netbeans${symbol_escape}${symbol_escape}openesb${symbol_escape}${symbol_escape}build.properties diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/private/retriever/catalog.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/private/retriever/catalog.xml new file mode 100644 index 000000000..712a6a3ac --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/private/retriever/catalog.xml @@ -0,0 +1,3 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/project.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/project.properties new file mode 100644 index 000000000..2a9ec25b5 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/project.properties @@ -0,0 +1,93 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +build.classes.dir=${symbol_dollar}{build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +${symbol_pound} This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${symbol_dollar}{build.dir}/generated +build.predist.dir=${symbol_dollar}{build.dir}/predist +build.predist.jar=${symbol_dollar}{build.predist.dir}/component.jar +build.predist.lib.dir=${symbol_dollar}{build.predist.dir}/lib +${symbol_pound} Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${symbol_dollar}{build.dir}/test/classes +build.test.dir=${symbol_dollar}{build.dir}/test +build.test.results.dir=${symbol_dollar}{build.dir}/test/results +conf.dir=src/conf +debug.classpath=${symbol_escape} + ${symbol_dollar}{run.classpath} +debug.test.classpath=${symbol_escape} + ${symbol_dollar}{run.test.classpath} +${symbol_pound} This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${symbol_dollar}{dist.dir}/${artifactId}.zip +dist.javadoc.dir=${symbol_dollar}{dist.dir}/javadoc +jar.compress=false +javac.classpath=${symbol_escape} + ${symbol_dollar}{libs.jbi.classpath}:${symbol_escape} + ${symbol_dollar}{jbi.component.sharedlibs.classpath}:${symbol_escape} + ${symbol_dollar}{jbi.component.lib.classpath} +${symbol_pound} Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.6 +javac.target=1.6 +javac.test.classpath=${symbol_escape} + ${symbol_dollar}{javac.classpath}:${symbol_escape} + ${symbol_dollar}{build.classes.dir}:${symbol_escape} + ${symbol_dollar}{libs.junit.classpath}:${symbol_escape} + ${symbol_dollar}{libs.jaxws21.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +jbi.ant.tasks.classpath=${symbol_escape} + ${symbol_dollar}{jbi.as.home}/lib/sun-appserv-ant.jar:${symbol_escape} + ${symbol_dollar}{jbi.as.home}/jbi/lib/jbi-ant-tasks.jar +#jbi.as.home=D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working53${symbol_escape}${symbol_escape}glassfish +jbi.as.home=${glassfishLocation} +#jbi.as.instance.id=[D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working53${symbol_escape}${symbol_escape}glassfish]deployer:Sun:AppServer::localhost:4848 +jbi.as.instance.id=[${glassfishLocation}]deployer:Sun:AppServer::localhost:4848 +jbi.component.bootstrap.class=${artifactId}.ProviderSEInstaller +jbi.component.class=${artifactId}.ProviderSERuntime +jbi.component.description=Description of service engine : ${artifactId} +jbi.component.lib.classpath=${symbol_escape} + ${symbol_dollar}{libs.wsdl4j.162.classpath} +jbi.component.name=${artifactId} +jbi.component.sharedlibs.classpath= +jbi.component.type=service-engine +jbi.host=localhost +jbi.install.params.file=install-params.properties +jbi.install.with.params=false +jbi.password=this really long string is used to identify a password that has been stored in the Keyring +jbi.port=4848 +jbi.soap.binding.name=sun-http-binding +jbi.username=admin +meta.inf.dir=${symbol_dollar}{conf.dir}/META-INF +platform.active=default_platform +project.jbi.deploy.plugin=./deploy-plugin +project.testSA=test/testSA +run.classpath=${symbol_escape} + ${symbol_dollar}{javac.classpath}:${symbol_escape} + ${symbol_dollar}{build.classes.dir} +${symbol_pound} Space-separated list of JVM arguments used when running the project +${symbol_pound} (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +${symbol_pound} or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=${symbol_escape} + ${symbol_dollar}{javac.test.classpath}:${symbol_escape} + ${symbol_dollar}{build.test.classes.dir} +src.dir=src/java +test-sys-prop.test.results.dir=${symbol_dollar}{build.test.results.dir} +test-sys-prop.test.src.dir=test-sys-prop.test.src.dir +test.src.dir=test/java +testSA.enabled=true +testSA.name=${artifactId}_TestSA diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/project.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/project.xml new file mode 100644 index 000000000..942beffad --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/nbproject/project.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + org.netbeans.modules.jbi.apisupport.project.jbicomponent + + + ${artifactId} + service-engine + 1.6.5 + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/pom.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/pom.xml new file mode 100644 index 000000000..a65255db9 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/pom.xml @@ -0,0 +1,282 @@ + + + + 4.0.0 + ${groupId} + ${artifactId} + jar + ${version} + JBI Component[${artifactId}] + Maven project for JBI Component that contains the + maven and netbeans build setup and component code to build and test the JBI Component. + http://open-esb.org + + build + src/java + test/java + build/classes + build/test/classes + package + + + org.apache.maven.plugins + maven-compiler-plugin + + true + 1.5 + 1.5 + + + **/*.java + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + + **/*.* + + + + + maven-surefire-plugin + 2.1.3 + true + + + true + + **/bindingtest/*.java + **/enginetest/*.java + + + + + + maven-antrun-plugin + 1.2 + + + m2nbbuild-compile + compile + + run + + + + + + + + + m2nbbuild-compile-test + test-compile + + run + + + + + + + + + m2nbbuild-package + package + + run + + + + + + + + + m2nbbuild-utest + test + + run + + + + + + + + + m2nbbuild-itest + integration-test + + run + + + + + + + + + m2nbbuild-clean + clean + + run + + + + + + + + + + default-cli + + run + + + + !!!!!!!!!!!!!!!!!!!!!! Moving Files and organizing package !!!!!!!!!!!!!!!!!!!!!!!! + + + + + + + + + ant + ant-nodeps + 1.6.5 + + + ant + ant-junit + 1.6.5 + test + + + junit + junit + 3.8.2 + test + + + + + + + + + maven2-repo1 + Maven2 Central Repository + http://repo1.maven.org/maven2 + + + download-java-net-maven2-repository + download.java.net Maven 2.x repository + http://download.java.net/maven/2/ + + + maven-repository.dev.java.net-repository + https://maven-repository.dev.java.net/nonav/repository/ + legacy + + + ws-zones + ws.zones maven repository + http://ws.zones.apache.org/repository2/ + + + apache.org + Maven Snapshots + http://people.apache.org/repo/m2-snapshot-repository + + false + + + + + + + + + apache.org + Maven Plugin Snapshots + http://people.apache.org/repo/m2-snapshot-repository + + false + + + + + + + + ant + ant-nodeps + 1.6.5 + + + ant + ant-junit + 1.6.5 + test + + + junit + junit + 3.8.2 + test + + + org.apache.maven + maven-ant-tasks + 2.0.7 + + + open-esb.jbi-cdk + jbi-cdk-ant-tasks + 1.0-SNAPSHOT + + + open-esb + jbi + 1.0 + + + wsdl4j + wsdl4j + 1.6.2 + + + com.sun.xml.ws + jaxws-rt + 2.1.2 + test + + + + + ${maven.repo.local} + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/conf/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/conf/META-INF/jbi.xml new file mode 100644 index 000000000..7c40ad15c --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/conf/META-INF/jbi.xml @@ -0,0 +1,45 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + ${artifactId} + Description of service engine : ${artifactId} + + + net.openesb.component.${artifactId}.ProviderSERuntime + + + component.jar + + lib/wsdl4j-1.6.2.jar + + + net.openesb.component.${artifactId}.ProviderSEInstaller + + + component.jar + + lib/wsdl4j-1.6.2.jar + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSEComponentLifeCycle.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSEComponentLifeCycle.java new file mode 100644 index 000000000..af3bbc2c6 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSEComponentLifeCycle.java @@ -0,0 +1,52 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ProviderSEComponentLifeCycle.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.BasicComponentLifeCycle; +import net.openesb.component.${artifactId}.common.DefaultMessageExchangeReceiver; +import net.openesb.component.${artifactId}.common.MessageExchangeReceiver; +import net.openesb.component.${artifactId}.common.RuntimeContext; +import javax.jbi.JBIException; +import javax.jbi.component.Component; + +/** + * This class extends the basic ComponentLifeCycle implementation to provide + * component specific implementation of the ComponentLifeCycle. + * + * @see javax.jbi.ComponentLifeCycle + * @see com.sun.jbi.sample.component.common.BasicComponentLifeCycle + * @author chikkala + */ +public class ProviderSEComponentLifeCycle extends BasicComponentLifeCycle { + + /** + * constructor + */ + public ProviderSEComponentLifeCycle(Component compRuntime) { + super(compRuntime); + } + + /** + * creates DefaultMessageExchangeReceiver to handles receiving and + * processing the message exchanges from the delivery channel. + */ + @Override + protected MessageExchangeReceiver createMessageExchangeReceiver() { + return new DefaultMessageExchangeReceiver(); + } + + /** + * chance to extended classes to do the component specific init + * + * @throws javax.jbi.JBIException + */ + @Override + protected void doInit() throws JBIException { + // NOOP + RuntimeContext.getInstance().setLogger(this.getClass().getName(), null); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSEEndpoint.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSEEndpoint.java new file mode 100644 index 000000000..cddaa21da --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSEEndpoint.java @@ -0,0 +1,101 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ProviderSEEndpoint.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.MessageExchangeHandler; +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.MessageExchangeListener; +import net.openesb.component.${artifactId}.common.deployment.ProviderEndpoint; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor; +import javax.jbi.JBIException; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.wsdl.Definition; + +/** + * This class extends the ProviderEndpoint to implement component specific + * endpoint configuration. It implements the MessageExchangeListener to receive + * message exchange notifications from the MessageExchangeSupport fired by + * MessageExchangeReceiver and process it using a message exchange handler. + * + * This endpoint is configured for a service provided by this component which + * can receive a xml document and apply xslt transformation and send the results + * back in a InOut message exchange to complete a service invocation on this + * endpoint. + * + * @author chikkala + */ +public class ProviderSEEndpoint extends ProviderEndpoint implements MessageExchangeListener { + + private XSLTFileLocator mXsltFileLocator; + private XSLTService mXsltService; + + /** + * Creates a new instance of XSLTProviderEndpoint + */ + public ProviderSEEndpoint(SUDescriptor.Provides provides, Definition wsdlDef, ProviderSEServiceUnit su) { + super(provides, wsdlDef, su); + } + + /** + * XSLT transformation service used in transformation of the xml documents + * received on this endpoint. + */ + public XSLTService getXSLTService() { + return this.mXsltService; + } + + /** + * returns the XSLTFileLocator object that is created to find the xslt file + * to be used for a particular service operation invocation by looking at + * the mapping file specified in the service unit that deploys this + * endpoint. + */ + public XSLTFileLocator getXSLTFileLocator() { + return this.mXsltFileLocator; + } + + @Override + public void doInit() throws JBIException { + RuntimeHelper.getLogger().info("ProviderSEEndpoint:doInit called"); + ProviderSEServiceUnit su = (ProviderSEServiceUnit) this.getServiceUnit(); + this.mXsltFileLocator = su.getXsltFileLocator(); + this.mXsltService = XSLTService.XSLTServiceImpl.getInstance(); + } + + /** + * creates the message exchange handler that will be used to process the + * message exchange received for this endpoint. + */ + @Override + public MessageExchangeHandler createMessageExchangeHandler() { + return new ProviderSEMessageExchangeHandler(this); + } + + /** + * returns the implementation of the message exchange listener which the + * MessageExchangeSupport invokes when a message exchange is received from + * delivery channel by MessageExchangeReceiver. + */ + @Override + protected MessageExchangeListener createMessageExchangeListener() { + return this; + } + + /** + * implementation of the message exchange received method of the listener. + */ + public void messageExchangeReceived(ExchangeStatus status, MessageExchange me) { + try { + RuntimeHelper.getLogger().fine("MXListener.MessageExchangeReceived: with Status: " + status); + processMessageExchangeWithHandler(status, me); + // processMessageExchange(me); + } catch (Exception ex) { + ex.printStackTrace(); + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSEInstaller.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSEInstaller.java new file mode 100644 index 000000000..88da303d2 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSEInstaller.java @@ -0,0 +1,34 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + /* + * ProviderSEInstaller.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.ComponentInstaller; + +/** + * This class extends the ComponentInstaller that implements the + * javax.jbi.component.Bootstrap for a component installation contract. + * + * If the default implemenation of the javax.jbi.component.Bootstrap in + * com.sun.jbi.sample.component.common.ComponentInstaller is not sufficient for + * this components install, uninstall and upgrade requirements, override the + * default implementation here to add component specific installation and + * upgrade tasks such as initializing configuration mbean and creating resources + * specific to component or upgrade workspace and service units during upgrading + * the component. + * + * @see javax.jbi.Bootstrap + * @see com.sun.jbi.sample.component.common.ComponentInstaller + * @author chikkala + */ +public class ProviderSEInstaller extends ComponentInstaller { + + /** + * Constructor to create the MyEngineInstaller. + */ + public ProviderSEInstaller() { + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSEMessageExchangeHandler.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSEMessageExchangeHandler.java new file mode 100644 index 000000000..b3002d6ac --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSEMessageExchangeHandler.java @@ -0,0 +1,171 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ProviderSEMessageExchangeHandler.java + * + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.AbstractMessageExchangeHandler; +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.wsdl.WSDL11JBIWrapper; +import java.io.StringReader; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.Fault; +import javax.jbi.messaging.InOut; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Source; + +/** + * This class extends the AbstractMessageExchangeHandler to implement the + * component specific message exchange processing on the provider side in a + * service engine. + * + * @author chikkala + */ +public class ProviderSEMessageExchangeHandler extends AbstractMessageExchangeHandler { + + private ProviderSEEndpoint mEndpoint; + + /** + * Creates a new instance of ProviderSEMXHandler + */ + public ProviderSEMessageExchangeHandler(ProviderSEEndpoint endpoint) { + this.mEndpoint = endpoint; + } + + protected Logger getLogger() { + return this.mEndpoint.getLogger(); + } + + protected DeliveryChannel getDeliveryChannel() { + return this.mEndpoint.getDeliveryChannel(); + } + + protected void validateMessageExchange() throws MessagingException { + MessageExchange msgExchange = this.getMessageExchange(); + + if (this.getMessageExchange() == null) { + throw new MessagingException("MessageExchange Object is null in MessageExchageHandler"); + } + + if (MessageExchange.Role.CONSUMER.equals(msgExchange.getRole())) { + throw new MessagingException("Provider Message Exchange Handler can not have MessageExchange with CONSUMER Role"); + } + + if (!(msgExchange instanceof InOut)) { + throw new MessagingException("InOut Message Exchange Handler MessageExchange object should be instanceof javax.jbi.messaging.InOut "); + } + } + + protected void processError(Exception ex) { + MessageExchange msgExchange = this.getMessageExchange(); + Exception errEx = msgExchange.getError(); // get the error and print + RuntimeHelper.getLogger().info( + "InOut Message Exchange Provider received Error: " + errEx.getMessage()); + msgExchange.getError().printStackTrace(); + } + + protected void processDone() { + MessageExchange msgExchange = this.getMessageExchange(); + RuntimeHelper.getLogger().info("InOut Message Exchange Provider received DONE :" + + " END of service invocation"); + } + + protected void processFault(Fault fault) { + MessageExchange msgExchange = this.getMessageExchange(); + RuntimeHelper.logError("InOut Message Exchange Provider Handler can not receive Fault on Provider side"); + } + + protected void processMessage() { + try { + processInMessageOnProvider((InOut) this.getMessageExchange()); + } catch (JBIException ex) { + ex.printStackTrace(); + } + } + + protected void processInMessageOnProvider(InOut inOutExchange) throws JBIException { + RuntimeHelper.getLogger().fine("Processing In Message on Provider side " + inOutExchange); + // receive IN message. + NormalizedMessage inMsg = inOutExchange.getInMessage(); + NormalizedMessage outMsg = null; + Fault fault = null; + Source inContent = null; + Source outContent = null; + Source faultContent = null; + String faultAsText = null; + // process in message + inContent = inMsg.getContent(); + // invoke the service operation + try { + QName opName = inOutExchange.getOperation(); + QName svcName = inOutExchange.getEndpoint().getServiceName(); + RuntimeHelper.getLogger().fine("xslt service info " + svcName + opName); + + XSLTFileLocator xsltFileLocator = this.mEndpoint.getXSLTFileLocator(); + XSLTService xsltService = this.mEndpoint.getXSLTService(); + + String xsltPath = xsltFileLocator.findXsltFile(svcName, opName); + RuntimeHelper.getLogger().fine("XsltPath " + xsltPath); + if (xsltPath == null) { + RuntimeHelper.getLogger().fine(" No XSLT File found in MAP " + + xsltFileLocator.printMap()); + } + outContent = xsltService.transform(inContent, xsltPath); + + } catch (Exception ex) { + // exception invoking the operation. so, set exception text as fault content. + ex.printStackTrace(); + faultAsText = RuntimeHelper.getExceptionAsText(ex); + String faultText = RuntimeHelper.getExceptionAsXmlText(ex); + faultContent = RuntimeHelper.createDOMSource(new StringReader(faultText)); + } + // set out or fault message + if (outContent != null) { + // set the out message content. + outMsg = inOutExchange.createMessage(); + inOutExchange.setOutMessage(outMsg); + normalizeOutMessage(inOutExchange, outMsg, outContent); + // outMsg.setContent(outContent); + } else if (faultContent != null) { + fault = inOutExchange.createFault(); + inOutExchange.setFault(fault); + fault.setContent(faultContent); // may need to normalize the content. + } + // send out or fault message. + // this.getDeliveryChannel().sendSync(inOutExchange, SEND_SYNC_TIMEOUT); + this.send(); + } + + private void normalizeOutMessage(MessageExchange me, NormalizedMessage normMsg, Source msgSrc) throws MessagingException { + try { + // DOMSource wrappedSource = wrapOutputMessage(me, msgSrc); + WSDL11JBIWrapper outWrapper = WSDL11JBIWrapper.createOutputWrapper( + this.mEndpoint.getWSDLOperation(me.getOperation())); + + // check if the output from the transformer is in a wrapped form + WSDL11JBIWrapper wrapper = WSDL11JBIWrapper.sourceToWrapper( + RuntimeHelper.sourceToDOMSource(msgSrc)); + if (wrapper != null) { + outWrapper.appendParts(wrapper.getParts()); + } else { + outWrapper.appendPart(RuntimeHelper.sourceToDOMSource(msgSrc)); + } + + normMsg.setContent(outWrapper.toDOMSource()); + + } catch (MessagingException ex) { + throw ex; + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSERuntime.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSERuntime.java new file mode 100644 index 000000000..5a395d9ee --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSERuntime.java @@ -0,0 +1,56 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ProviderSERuntime.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.ComponentRuntime; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.component.ServiceUnitManager; + +/** + * This class extends the ComponentRuntime that implements + * javax.jbi.component.Component interface required for the component contract + * at runtime. + * + * This class provides the component specific ComponentLifeCycle implementation + * as well as the component specific ServiceUnitManager implementation. + * + * Add any additional component runtime specific functionality here. + * + * @see javax.jbi.component.Component + * @see com.sun.jbi.sample.component.common.ComponentRuntime + * @see com.sun.jbi.sample.component.common.BasicComponentLifecycle + * @see + * com.sun.jbi.sample.component.common.deployment.AbstractServiceUnitManager + * @author chikkala + */ +public class ProviderSERuntime extends ComponentRuntime { + + /** + * Creates a new instance of MyEngineRuntime + */ + public ProviderSERuntime() { + super(); + } + + /** + * overriding the parent's createComponentLifeCycle to create component + * specific component lifecycle implementation. + */ + @Override + protected ComponentLifeCycle createComponentLifeCycle() { + return new ProviderSEComponentLifeCycle(this); + } + + /** + * overrides the parent's createServiceUnitManager to create component + * specific service unit manager + */ + @Override + protected ServiceUnitManager createServiceUnitManager() { + return new ProviderSESUManager(this); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSESUManager.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSESUManager.java new file mode 100644 index 000000000..ed2cbed58 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSESUManager.java @@ -0,0 +1,49 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ProviderSESUManager.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.deployment.AbstractServiceUnitManager; +import net.openesb.component.${artifactId}.common.deployment.ServiceUnit; +import java.util.logging.Logger; +import javax.jbi.management.DeploymentException; + +/** + * This class extends the AbstractServiceUnitManager to implement component + * specific service unit manager by creating the component specific ServiceUnit + * implementation. + * + * @see + * com.sun.jbi.sample.component.common.deployment.AbstractServiceUnitManager + * @see com.sun.jbi.sample.component.common.deployment.ServiceUnit + * @author chikkala + */ +public class ProviderSESUManager extends AbstractServiceUnitManager { + + private ProviderSERuntime mRuntime; + + /** + * Creates a new instance of ProviderSESUManager + */ + public ProviderSESUManager(ProviderSERuntime compRuntime) { + super(); + this.mRuntime = compRuntime; + } + + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + + protected String getComponentName() { + return RuntimeHelper.getComponentName(); + } + //TODO implement ProviderSEServiceUnit + + protected ServiceUnit createServiceUnit(String suName, String suRootPath) throws DeploymentException { + return new ProviderSEServiceUnit(suName, suRootPath); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSEServiceUnit.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSEServiceUnit.java new file mode 100644 index 000000000..e11af0975 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/ProviderSEServiceUnit.java @@ -0,0 +1,63 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ProviderSEServiceUnit.java + * + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.deployment.ServiceUnit; +import net.openesb.component.${artifactId}.common.deployment.ProviderEndpoint; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Provides; +import javax.jbi.management.DeploymentException; +import javax.wsdl.Definition; + +/** + * This class extends the ServiceUnit to implement the component specific + * service unit processing. It creates the component specific ProviderEndpoint + * implementation to configure the service provider endpoint on this component + * deployed in the service unit. It also processes the deployment artifacts that + * are specific to the service provided by the component. + * + * @author chikkala + */ +public class ProviderSEServiceUnit extends ServiceUnit { + + private XSLTFileLocator mXsltFileLocator; + + /** + * Creates a new instance of ProviderSEServiceUnit + */ + public ProviderSEServiceUnit(String suName, String suRootPath) { + super(suName, suRootPath); + } + + protected XSLTFileLocator getXsltFileLocator() { + return this.mXsltFileLocator; + } + + @Override + protected ProviderEndpoint createProviderEndpoint(Provides provides, Definition wsdlDef) { + return new ProviderSEEndpoint(provides, wsdlDef, this); + } + + /** + * load and validates the component specific deployment artifacts. It loads + * the xsltmap properties into XSLTFileLocator which will be used to find + * the xslt file corresponding to a service operation. + */ + @Override + protected void loadOtherArtifacts() throws DeploymentException { + super.loadOtherArtifacts(); + // load any component specific service unit artifacts + if (this.mXsltFileLocator == null) { + try { + this.mXsltFileLocator = + new XSLTFileLocator(this.getSURootPath(), "xsltmap.properties"); + } catch (Exception ex) { + throw new DeploymentException(ex); + } + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/XSLTFileLocator.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/XSLTFileLocator.java new file mode 100644 index 000000000..d5189d393 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/XSLTFileLocator.java @@ -0,0 +1,210 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * XSLTFileLocator.java + */ +package net.openesb.component.${artifactId}; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import javax.xml.namespace.QName; + +/** + * This class represents the component specific deployment artifact which reads + * the deployed "xsltmap.properties" file in the service unit and processes it + * to find the xslt file to be used for a particular operation on a service + * provided by the deployment. + *

+ * The "xsltmap.properties" file should contain two types of properties
+ * 1.for namespace prefix to namespaceURI map that starts with "xmlns." prefix like
+ *   "xmlns.tns-prefix=http://www.sun.com/jbi/examples/sample-service/echo"
+ * 2. a service description to xslt file properties with syntax like
+ *   "{tns-prefix}service-name=xslt_file_name"  and
+ *   "{tns-prefix}service-name.{tns-prefix}operation-name=xslt_file_name" and
+ *   "{tns-prefix}service-name.{tns-prefix}interface-name.operation-name=xslt_file_name" .
+ * the service description property is a "." delimited tokens that represents a serive
+ * or interface qname and a operation name. To locate xslt file either with service qname
+ * or service qname and operaton or serivice qname and interface qname and operation,
+ * all the three properties specified above should be there for each xslt file. for example,
+ *  xmlns.echo1=http://www.sun.com/jbi/examples/sample-service/echo
+ *  xmlns.echo2=http://www.sun.com/jbi/examples/sample-service/echo
+ *  {echo2}echoService=echo.xsl
+ *  {echo2}echoService.{echo1}echo=echo.xsl
+ *  {echo2}echoService.{echo1}echo.echo=echo.xsl
+ * 
+ * + * @author chikkala + */ +public class XSLTFileLocator { + + private Map mXsltFileMap; + + /** + * Creates a new instance of XsltLocator + */ + public XSLTFileLocator(String rootPath, String mapFile) throws Exception { + this.mXsltFileMap = new HashMap(); + initXsltLocator(rootPath, mapFile); + } + + private void initXsltLocator(String rootPath, String mapFilePath) throws Exception { + @SuppressWarnings("unchecked") + Map mapProps = loadMappingProperties(rootPath, mapFilePath); + + Map nsMap = new HashMap(); + Map xsltMap = new HashMap(); + + for (String name : mapProps.keySet()) { + String value = mapProps.get(name); + if (name.startsWith("{")) { + xsltMap.put(name, value); + } else if (name.startsWith("xmlns.")) { + String xmlns = name.substring(6); + nsMap.put(xmlns, value); + } + } + + for (String name : xsltMap.keySet()) { + String value = xsltMap.get(name); + String[] tokens = name.split("${symbol_escape}${symbol_escape}."); + String svcName = null; + String intrName = null; + String opName = null; + + if (tokens.length == 1) { + svcName = expandQName(tokens[0], nsMap); + } else if (tokens.length == 2) { + svcName = expandQName(tokens[0], nsMap); + opName = expandQName(tokens[1], nsMap); + } else if (tokens.length == 3) { + svcName = expandQName(tokens[0], nsMap); + intrName = expandQName(tokens[1], nsMap); + opName = tokens[2]; + } else { + System.out.println("invalid property name in xslt map property" + name); + } + + StringBuffer buff = new StringBuffer(); + buff.append(svcName); + if (intrName != null) { + buff.append("."); + buff.append(intrName); + } + if (opName != null) { + buff.append("."); + buff.append(opName); + } + File file = new File(rootPath, value); + String xsltFile = file.getAbsolutePath(); + this.mXsltFileMap.put(buff.toString(), xsltFile); + } + } + + private String expandQName(String qname, Map xmlnsMap) { + + // qname passed is "{prefix}localname" + QName temp = QName.valueOf(qname); + String prefix = temp.getNamespaceURI(); + String nsURI = xmlnsMap.get(prefix); + if (nsURI == null) { + nsURI = prefix; // just use the prefix as it is. + } + QName realQName = new QName(nsURI, temp.getLocalPart()); + return realQName.toString(); + } + + private Map loadMappingProperties(String rootPath, String mapFilePath) throws Exception { + File mapFile = new File(rootPath, mapFilePath); + Properties mapProps = new Properties(); + if (!mapFile.exists()) { + throw new Exception("Mapping file not found " + mapFilePath); + } + FileInputStream inStream = null; + try { + inStream = new FileInputStream(mapFile); + mapProps.load(inStream); + } catch (FileNotFoundException ex) { + ex.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); + } finally { + if (inStream != null) { + try { + inStream.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + return mapProps; + } + + /** + * return the xslt file mapped to either service name or service qname + + * operation qname + * + * @param serviceQName must be non null qname + * @param opQName can be null the xslt file can be located at service level. + */ + public String findXsltFile(QName serviceQName, QName opQName) { + StringBuffer buff = new StringBuffer(); + buff.append(serviceQName.toString()); + if (opQName != null) { + buff.append("."); + // workaround for the http soap bc bug which does not set the namespace + // uri on the op name. for time being use the serviceQName's namespace + String namespaceURI = opQName.getNamespaceURI(); + if (namespaceURI == null || namespaceURI.length() == 0) { + QName tempOp = + new QName(serviceQName.getNamespaceURI(), opQName.getLocalPart()); + buff.append(tempOp.toString()); + } else { + buff.append(opQName.toString()); + } + } + String xsltFile = this.mXsltFileMap.get(buff.toString()); + return xsltFile; + } + + /** + * return the xslt file mapped to either service name or service qname + + * interface qname + operation + * + * @param serviceQName must be non null service qname + * @param intrQName interface qname + * @param opName operation name ( not a qname) + */ + public String findXsltFile(QName serviceQName, QName intrQName, String opName) { + StringBuffer buff = new StringBuffer(); + buff.append(serviceQName.toString()); + if (intrQName != null) { + buff.append("."); + buff.append(intrQName.toString()); + } + if (opName != null) { + buff.append("."); + buff.append(opName); + } + String xsltFile = this.mXsltFileMap.get(buff.toString()); + return xsltFile; + } + + public String printMap() { + StringWriter buff = new StringWriter(); + PrintWriter out = new PrintWriter(buff); + for (String key : this.mXsltFileMap.keySet()) { + out.println("Key= " + key); + out.println("XsltFile= " + this.mXsltFileMap.get(key)); + } + out.close(); + return buff.getBuffer().toString(); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/XSLTService.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/XSLTService.java new file mode 100644 index 000000000..a303e10a0 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/XSLTService.java @@ -0,0 +1,108 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * XSLTService.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import java.io.File; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Properties; +import java.util.logging.Logger; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import org.w3c.dom.Document; + +/** + * This is a sample service implementation that takes the input as xml document + * and the xslt file to apply the xslt transformation on the input xml and + * return the transformed output xml. This implementation of the service is + * invoked when a InOut message exchange is processed to invoke a service + * provided by the engine. + * + * @author chikkala + */ +public interface XSLTService { + + /** + * this operation takes the input xml document and constructs the output xml + * document by applying the xslt in the file specified in xsltPath + * + * @param inputDoc input xml document + * @param xsltPath absolute file path of xslt file. + * @return transformed output xml document + */ + Source transform(Source inputDoc, String xsltPath) throws Exception; + + /** + * This class implements the echo service operations which the service + * engine will invoke when a InOut message exchange is processed to invoke a + * service provided by the engine. + */ + public static class XSLTServiceImpl implements XSLTService { + + private XSLTServiceImpl() { + } + + /** + * accessor to create/locate the service implementation + * + * @return echo service implementation + */ + public static XSLTService getInstance() { + return new XSLTServiceImpl(); + } + + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + + /** + * this operation takes the input xml document and constructs the output + * xml document with the same data to implement the echo. + * + * @param inputDoc input document + * @return output document + */ + public Source transform(Source inputDoc, String xsltPath) throws Exception { + Document outDoc = null; + StringBuffer inBuff = RuntimeHelper.readFromSource(inputDoc); + + getLogger().fine("${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} TRANSFORMER INPUT MESSAGE BEGIN ${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}"); + getLogger().fine(inBuff.toString()); + getLogger().fine("${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} TRANSFORMER INPUT MESSAGE END ${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}"); + + TransformerFactory tf = null; + tf = TransformerFactory.newInstance(); + StreamSource xsltSource = new StreamSource(new File(xsltPath)); + Transformer xformer = tf.newTransformer(xsltSource); + + Properties params = new Properties(); //TODO get the pramas from the user file + for (Object name : params.keySet()) { + xformer.setParameter((String) name, params.get(name)); + } + StringWriter writer = new StringWriter(); + StreamResult result = new StreamResult(writer); + + DOMSource xmlSource = new DOMSource(RuntimeHelper.buildDOMDocument(new StringReader(inBuff.toString()))); + + xformer.transform(xmlSource, result); + + getLogger().fine("${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} TRANSFORMER OUTPUT MESSAGE BEGIN ${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}"); + getLogger().fine(writer.getBuffer().toString()); + getLogger().fine("${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} TRANSFORMER OUTPUT MESSAGE END ${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}"); + + outDoc = RuntimeHelper.buildDOMDocument(new StringReader(writer.getBuffer().toString())); + DOMSource outSource = new DOMSource(outDoc); + + return outSource; + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java new file mode 100644 index 000000000..4987029b3 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java @@ -0,0 +1,141 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractMessageExchangeHandler.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import java.io.StringReader; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.Fault; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; +import javax.xml.namespace.QName; + +/** + * This class is an abstract implementation of the MessageExchangeHandler which + * provides the base implementation of the ME processing and provides hooks to + * extended classes to implement component specific processing. + * + * @author chikkala + */ +public abstract class AbstractMessageExchangeHandler implements MessageExchangeHandler { + + public static String IN_MESSAGE = "in"; + public static String OUT_MESSAGE = "out"; + + private MessageExchange mMessageExchange; + private ExchangeStatus mStatus; + /** Creates a new instance of AbstractMessageExchangeHandler */ + protected AbstractMessageExchangeHandler() { + this.mMessageExchange = null; + } + + protected abstract Logger getLogger(); + protected abstract DeliveryChannel getDeliveryChannel(); + protected abstract void validateMessageExchange() throws MessagingException; + protected abstract void processError(Exception ex); + protected abstract void processDone(); + protected abstract void processMessage(); + protected abstract void processFault(Fault fault); + + public final MessageExchange getMessageExchange() { + return this.mMessageExchange; + } + + public final void setMessageExchange(MessageExchange msgExchange) { + this.mMessageExchange = msgExchange; + } + + public final ExchangeStatus getMessageExchangeStatus() { + if ( this.mStatus != null ) { + return this.mStatus; + } else if ( this.mMessageExchange != null ) { + return this.mMessageExchange.getStatus(); + } else { + return null; + } + } + + public final void setMessageExchangeStatus(ExchangeStatus status) { + this.mStatus = status; + } + + protected void send() throws MessagingException { + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected boolean sendSync(long timeout) throws MessagingException { + return this.getDeliveryChannel().sendSync(this.mMessageExchange, timeout); + } + + protected void sendDone() throws MessagingException { + this.mMessageExchange.setStatus(ExchangeStatus.DONE); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void sendError(Exception ex) throws MessagingException { + this.mMessageExchange.setError(ex); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void sendFault(Exception ex, QName type, String name) throws MessagingException { + Fault fault = this.mMessageExchange.createFault(); + if ( ex != null ) { + String xmlText = RuntimeHelper.getExceptionAsXmlText(ex); + fault.setContent(RuntimeHelper.createDOMSource(new StringReader(xmlText))); + } + this.mMessageExchange.setFault(fault); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void processActive() { + Fault fault = this.getMessageExchange().getFault(); + if ( fault != null ) { + processFault(fault); + } else { + processMessage(); + } + } + /** + * implementation of the MessageExchangeHandler${symbol_pound}processMessageExchange method. + */ + public void processMessageExchange(ExchangeStatus status, MessageExchange msgEx) { + + getLogger().fine("MessageExchangeHandler.processMessageExchange:status: " + status ); + + this.setMessageExchangeStatus(status); + this.setMessageExchange(msgEx); + + try { + validateMessageExchange(); + } catch (MessagingException ex) { + getLogger().log(Level.FINE, "Invalid message exchange for processing ", ex); + if ( this.getMessageExchange() != null ) { + try { + sendError(ex); + } catch (MessagingException errEx) { + getLogger().log(Level.FINE, "Can not send invalid message exchange error", errEx); + } + } + return; + } + + MessageExchange msgExchange = this.getMessageExchange(); + + if (ExchangeStatus.ACTIVE.equals(status) ) { + processActive(); + } else if (ExchangeStatus.DONE.equals(status) ) { + processDone(); + } else if (ExchangeStatus.ERROR.equals(status) ) { + processError(msgExchange.getError()); + } + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java new file mode 100644 index 000000000..d76fbe0f9 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java @@ -0,0 +1,398 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractComponentLifeCycle.java + */ + +package net.openesb.component.${artifactId}.common; + +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.component.Component; +import javax.jbi.component.ComponentContext; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.MessagingException; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.StandardMBean; + +/** + * This class implements the javax.jbi.component.ComponentLifeCycle. This is an + * abstract class that keeps the reference to the component context and the lifecycle + * extension mbeans. It implements the lifecycle method and provide the extended methods + * for each lifecycle methods to implement component specific functionality. + *

+ * It makes sure that the mininum initialization required for the component + * lifecycle is implemented by this class or the classes extending this class. + *

+ * Another important functionality implemented in this class is that it initializes the global + * RuntimeContext for the component with the ComponentContext passed by the JBI runtime and the + * opened delivery channel to make them available globally to any class in the component implementation + * that may need it during component lifecycle + *

+ * Service engine or a binding component lifecycle implementation can directly extend + * this class for their required functionality and override some of the methods to provide + * their own implementation. + * + * @see javax.jbi.ComponentLifeCycle + * @author chikkala + */ +public class BasicComponentLifeCycle implements ComponentLifeCycle { + /** reference to the component runtime */ + private Component mCompRuntime; + /** component context */ + private ComponentContext mComponentContext; + /** Extension Mbean Name*/ + private ObjectName mExtensionMBeanName; + /** Extension Mbean Implementation*/ + private StandardMBean mExtensionMBeanImpl; + /** a message receiver that accepts messages from delivery channel */ + private MessageExchangeReceiver mMsgExchReceiver; + + /** + * constructor for the ComponentLifecycle implementation. + * @param compRuntime + */ + protected BasicComponentLifeCycle(Component compRuntime) { + this.mCompRuntime = compRuntime; + } + /** + * @return Component + */ + public final Component getComponentRuntime() { + return this.mCompRuntime; + } + /** + * @return ComponentContext component context. + */ + public final ComponentContext getComponentContext() { + return mComponentContext; + } + /** + * @return component name + */ + protected String getComponentName() { + return (this.mComponentContext != null) ? + this.mComponentContext.getComponentName() : null; + } + /////////////////////////////////////////////////////////////////////////// + // ComponentLifeCycle interface implemenation + /////////////////////////////////////////////////////////////////////////// + + /** + * Initializes the component lifecycle. This method makes sure that the + * component context passed by the jbi runtime is saved in the lifecycle + * object before calling the other component initialization methods to + * completely initialize the component. + * @param context Component context + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}init(javax.jbi.component.ComponentContext) + * @throws javax.jbi.JBIException on error + */ + public final void init(ComponentContext context) throws JBIException { + + if ( context == null ) { + throw new JBIException("Null Component Context received in " + + "Component Lifecycle init "); + } + this.mComponentContext = context; // 0. save the component context passed by jbi framework. + // initialize the content + initGlobalContext(); // 1. Initialize component runtime context. + registerExtensionMBean(); // 2. Create and register extension mbean. + openDeliveryChannel(); // 3. Open delivery channel. + initMessageExchangeReceiver(); // 4. Create message exchange receiver. + doInit(); // 5. Do any component specific initialization such + // as static service providers and consumers initialization. + + this.getLogger().fine("Component " + this.getComponentName() + " initialized"); + } + + /** + * Starts the component. Extended classes can override/implement the methods called + * in this method to provide component specify start functionality. + * + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}start() + * @throws javax.jbi.JBIException on error + */ + public final void start() throws JBIException { + + doStart(); // 1. do any other component specific start tasks such as + // activating any static service providers and consumers. + startMessageExchangeProcessing(); // 2. begin accepting and processing message exchanges. + + this.getLogger().fine("Component " + this.getComponentName() + " started"); + } + + /** + * Stop the component.Extended classes can override/implement the methods called + * in this method to provide component specify stop functionality. + * @throws javax.jbi.JBIException + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}stop() + */ + public final void stop() throws JBIException { + + stopMessageExchangeProcessing(); // 1. stop accepting and processing message exchanges. + doStop(); // 2. do any other component specific stop tasks such as + // deactivating any static service providers and consumers. + this.getLogger().fine("Component " + this.getComponentName() + " stopped."); + } + + /** + * Shut down the component. Extended classes can override/implement the methods called + * in this method to provide component specify shut down functionality. + * @throws javax.jbi.JBIException + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}shutDown() + */ + public final void shutDown() throws JBIException { + // clean up all resources. + shutdownMessageExchangeReceiver(); // 1. remove the message receiver. + closeDeliveryChannel(); // 2. close delivery channel + unregisterExtensionMBean(); // 3. unregister and remove extension mbean if exists. + doShutDown(); // 4. do any other component specific clean up tasks such + // as clean any static service providers and consumer resource. + this.getLogger().fine("Component " + this.getComponentName() + " shut down"); + } + /** + * create jmx object name for the extension mbean. default implementation does + * not required to have the extension mbean. + * @return ObjectName of the extension mbean + */ + protected ObjectName createExtensionMBeanName() { + return null; + } + /** + * gets the reference to the extension mbean name. + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}getExtensionMBeanName() + * @return ObjectName of the extension mbean objectname or null if component + * does not support extension mbean + */ + public final ObjectName getExtensionMBeanName() { + if ( this.mExtensionMBeanName == null ) { + this.mExtensionMBeanName = this.createExtensionMBeanName(); + } + return this.mExtensionMBeanName; + } + /** + * create mbean implementation for the extension mbean as a StandardMBean. default + * implementation does not require the extension mbean + * @return the ExtensionMBean implementation as StandardMBean + */ + protected StandardMBean createExtensionMBean() { + return null; + } + /** + * gets the reference to the extension mbean. + * @return extension mbean implementation or null if component does not support. + */ + protected final StandardMBean getExtensionMBean() { + if ( this.mExtensionMBeanImpl == null ) { + this.mExtensionMBeanImpl = this.createExtensionMBean(); + } + return this.mExtensionMBeanImpl; + } + /** + * if there is an extension mbean supported by the component, then register + * it with the mbean server. + * @throws JBIException on error registering mbean + */ + protected final void registerExtensionMBean() throws JBIException { + // creatre the extension mbean's object name + ObjectName mbeanName = this.getExtensionMBeanName(); + // create the extension mbean implemenation. + StandardMBean mbeanImpl = this.getExtensionMBean(); + + if ( mbeanName == null || mbeanImpl == null ) { + this.getLogger().fine(this.getComponentName() + + " Does not have Extension MBean implemenation "); + return; + } + // register with mbean only if object name and implementation are non null + try { + MBeanServer mbServer = RuntimeHelper.getComponentContext().getMBeanServer(); + mbServer.registerMBean(mbeanImpl, mbeanName); + } catch (Exception e) { + throw new JBIException("Failed to register Extension MBean for " + + this.getComponentName(), e); + } + } + /** + * remove the registered extension mbean from the mbean server if any. + */ + protected final void unregisterExtensionMBean() { + ObjectName mbeanName = this.getExtensionMBeanName(); + if ( mbeanName == null ) { + return; + } + try { + MBeanServer mbServer = RuntimeHelper.getComponentContext().getMBeanServer(); + mbServer.unregisterMBean(mbeanName); + } catch (Exception e) { + this.getLogger().log(Level.WARNING, + "Failed to unregister Extension MBean from MBeanServer for " + this.getComponentName(), e); + } + } + /** + * creates MessageExchangeReceiver implementation that handles receiving and processing + * the message exchanges from the delivery channel. Component should implement + * this method to provide the MessageReceiver. + * + * Component may return null indicating that they don't need the message receiver + * that can receive and process message exchanges from delivery channel. For example, + * components that have only service consumers which send a synchronous messages to + * providers don't need this. + * + * @throws java.lang.Exception + * @return MessageExchangeReceiver implementation. null if the component does not support it. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle${symbol_pound}createMessageExchangeReceiver + */ + protected MessageExchangeReceiver createMessageExchangeReceiver() { + return null; + } + /** + * returns the message exchange receiver implementation reference + * @return MessageExchangeReceiver interface + */ + protected final MessageExchangeReceiver getMessageExchangeReceiver() { + if ( this.mMsgExchReceiver == null ) { + this.mMsgExchReceiver = createMessageExchangeReceiver(); + } + return this.mMsgExchReceiver; + } + /** + * creates a message receiver object as part of the component initialization. + * @throws javax.jbi.JBIException + */ + protected void initMessageExchangeReceiver() throws JBIException { + // create and initialize the MessageExchangeReceiver + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.initReceiver(); + } + } + /** + * allows the component to accept the message exchange objects from the + * delivery channel and process it as part of the component startup process. + * @throws javax.jbi.JBIException + */ + protected void startMessageExchangeProcessing() throws JBIException { + // start message processing + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.startProcessing(); + } + } + /** + * stops the component from accepting the message exchange objects from the + * delivery channel as part of the component stop process + * @throws javax.jbi.JBIException + */ + protected void stopMessageExchangeProcessing() throws JBIException { + // stop message processing + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.stopProcessing(); + } + } + /** + * removes the message receiver as part of the component shutdown process + * @throws javax.jbi.JBIException + */ + protected void shutdownMessageExchangeReceiver() throws JBIException { + // clean up message processing. + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.shutdownReceiver(); + } + } + /** + * Returns logger initialized from the component context or a default logger. + * @return Logger + */ + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** + * initializes the RuntimeContext during component init lifecycle phase. This + * includes setting the ComponentContext and loggers etc. extended classes must + * save the component context in the RuntimeContext in this methods implementation. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle${symbol_pound}initGlobalContext + */ + protected void initGlobalContext() { + RuntimeContext.getInstance().setComponentContext(this.getComponentContext()); + RuntimeContext.getInstance().setLogger(this.getClass().getName(), null); + } + /** opens the delivery channel to accept or send message exchange objects + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle${symbol_pound}openDeliveryChannel + */ + protected void openDeliveryChannel() { + try { + DeliveryChannel channel = this.getComponentContext().getDeliveryChannel(); + RuntimeContext.getInstance().setDeliveryChannel(channel); + } catch (MessagingException ex) { + ex.printStackTrace(); + } + } + /** closes the delivery channel as part of the component shutdown process. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle${symbol_pound}closeDeliveryChannel + */ + protected void closeDeliveryChannel() { + // closes delivery channel and remove the reference. + try { + DeliveryChannel channel = RuntimeHelper.getDeliveryChannel(); + if ( channel != null ) { + channel.close(); + } + } catch (MessagingException ex) { + ex.printStackTrace(); + } finally { + RuntimeContext.getInstance().setDeliveryChannel(null); + } + } + /** + * chance to extended classes to do any extra component specific init tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * initialized here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle${symbol_pound}init method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle${symbol_pound}init + */ + protected void doInit() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific start tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * activated here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle${symbol_pound}start method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle${symbol_pound}start + */ + protected void doStart() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific stop tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * deactivated here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle${symbol_pound}stop method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle${symbol_pound}stop + */ + protected void doStop() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific shutdown tasks.If the component + * supports static service providers or consumers without deployment support, they can be + * cleaned up here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle${symbol_pound}shutdown method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle${symbol_pound}shutdown + */ + protected void doShutDown() throws JBIException { + //NOOP + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/ComponentInstaller.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/ComponentInstaller.java new file mode 100644 index 000000000..7e44dc053 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/ComponentInstaller.java @@ -0,0 +1,275 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + /* + * ComponentInstaller.java + */ +package net.openesb.component.${artifactId}.common; + +import java.util.List; +import java.util.logging.Level; +import javax.jbi.component.Bootstrap; +import javax.jbi.component.InstallationContext; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.StandardMBean; + +/** + * This class implements the javax.jbi.component.Bootstrap. This class implements + * the minimum required functionality for component installation contract + * of the jbi component in the jbi environment. It also takes care of maintaining + * the installation context reference and installation specific logger creation and + * installation extension mbean registration and unregistration during initialization + * and cleanup. Extended classes only need to supply the mbean name and its implementation + * object for the installation extensions. + * + * It makes sure that the installation context and the loggers are available to + * the classes extended from this class to add more installation specific functionality. + * + * Service engine or a binding component installation implementation can directly use + * this class or extend this class to add more functionality to their installation + * process. + * + * @see javax.jbi.Bootstrap + * @author chikkala + */ +public class ComponentInstaller implements Bootstrap { + /** default logger*/ + private Logger mDefLogger; + /** bootstrap logger */ + private Logger mBTLogger ; + /** Installation Context . */ + private InstallationContext mInstallationContext; + /** Extension Mbean Name*/ + private ObjectName mExtensionMBeanName; + /** Extension Mbean Implementation*/ + private StandardMBean mExtensionMBeanImpl; + + /** Constructor to create the ComponentInstaller. */ + public ComponentInstaller() { + } + /** + * @return InstallationContext of the component. + */ + public final InstallationContext getInstallationContext() { + return this.mInstallationContext; + } + protected String getComponentName() { + return (this.mInstallationContext != null) ? + this.mInstallationContext.getComponentName() : null; + } + /** + * @return logger initialized from the installation context or a default + * logger. + */ + protected Logger getLogger() { + // try init bootstrap logger + if (this.mBTLogger == null && this.mInstallationContext != null ) { + try { + this.mBTLogger = + this.mInstallationContext.getContext().getLogger(this.getClass().getName(), null); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + // init default logger if required + if ( this.mBTLogger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (this.mBTLogger != null) ? this.mBTLogger : this.mDefLogger; + } + /** + * Initializes the installation environment for a component. + * @see javax.jbi.component.Bootstrap${symbol_pound}init(javax.jbi.component.InstallationContext) + */ + public final void init(InstallationContext installContext) throws javax.jbi.JBIException { + + if ( installContext == null ) { + throw new JBIException("Null Installation Context received in " + + "Component Bootstrap initialization"); + } + // save the installation context reference passed by the jbi framework. + this.mInstallationContext = installContext; + registerExtensionMBean(); // create and register extension mbean + doInit(); // do any other extra initialization required specific to the component installation. + // initialize logger + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component Installer initialized"); + } + /** + * default implementation just logs the method call. extended classes should override this. + * @see javax.jbi.component.Bootstrap${symbol_pound}onInstall() + */ + public void onInstall() throws javax.jbi.JBIException { + //TODO: do required initializaton and resource creation + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component installed."); + } + /** + * default implementation just logs the method call. + * @see javax.jbi.component.Bootstrap${symbol_pound}onUninstall() + */ + public void onUninstall() throws javax.jbi.JBIException { + //TODO: do clean up the resource and other stuff. + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component uninstalled"); + } + /** + * default noop implementation of the cleanup. + * @see javax.jbi.component.Bootstrap${symbol_pound}cleanUp() + */ + public final void cleanUp() throws javax.jbi.JBIException { + + unregisterExtensionMBean(); // unregister extension mbean and remove it + doCleanUp(); // do any other extra cleanup specific to the component installation. + this.getLogger().fine( this.mInstallationContext.getComponentName() + + " Component Installer Cleaned up"); + } + + /** + * create jmx object name for the extension mbean. Extended classes should + * return the component specific installer extension mbean name here. + */ + protected ObjectName createExtensionMBeanName() { + return null; + } + /** + * default implementation that does not have extension mbean return null. + * @see javax.jbi.component.Bootstrap${symbol_pound}getExtensionMBeanName() + */ + public final javax.management.ObjectName getExtensionMBeanName() { + if ( this.mExtensionMBeanName == null ) { + this.mExtensionMBeanName = createExtensionMBeanName(); + } + return this.mExtensionMBeanName; + } + /** + * create mbean implementation for the extension mbean as a StandardMBean. Extended + * classes should return the installer extension mbean implementation as the + * standard mbean. + */ + protected StandardMBean createExtensionMBean() { + return null; + } + /** + * returns the installation extension mbean implementation. + * @return StandardMBean for the extension mbean implementation. + */ + protected final StandardMBean getExtensionMBean() { + if ( this.mExtensionMBeanImpl == null ) { + this.mExtensionMBeanImpl = this.createExtensionMBean(); + } + return this.mExtensionMBeanImpl; + } + /** + * Chance to extended classes to do the component installation specific init. + * Installation context will be initialized before calling this method. So, + * initialize other things if required in this method. + * @throws javax.jbi.JBIException on error + * @see com.sun.jbi.sample.component.common.ComponentInstaller${symbol_pound}init( + * javax.jbi.component.InstallationContext) + */ + protected void doInit() throws JBIException { + this.getLogger().info(this.getInstallationContext().getComponentName() + + " : Component Installer initialized"); + } + /** + * Chance to extended classes to do the component installation specific cleanup. + * ExtensionMbean will be unregistered before calling this method. + * @throws javax.jbi.JBIException on error + * @see com.sun.jbi.sample.component.common.ComponentInstaller${symbol_pound}cleanUp( + * javax.jbi.component.InstallationContext) + */ + protected void doCleanUp() throws JBIException { + this.getLogger().fine(this.getInstallationContext().getComponentName() + + " : Component Installer doCleanUp"); + } + /** + * if there is an extension mbean supported by the component, then register + * it with the mbean server. + */ + protected void registerExtensionMBean() throws JBIException { + // creatre the installation extension mbean's object name + ObjectName mbeanName = this.getExtensionMBeanName(); + // create the extension mbean implemenation if the object name is created. + StandardMBean mbeanImpl = this.getExtensionMBean(); + + if ( mbeanName == null || mbeanImpl == null ) { + this.getLogger().fine(this.getComponentName() + + " Does not have Installation Extension MBean implemenation "); + return; + } + // register with mbean only if object name and implementation are non null + try { + MBeanServer mbServer = this.getInstallationContext().getContext().getMBeanServer(); + mbServer.registerMBean(mbeanImpl, mbeanName); + } catch (Exception e) { + throw new JBIException("Failed to register Installation Extension MBean for " + + this.getComponentName(), e); + } + } + /** + * remove the registered extension mbean from the mbean server. + */ + protected void unregisterExtensionMBean() { + ObjectName mbeanName = this.getExtensionMBeanName(); + if ( mbeanName == null ) { + return; + } + try { + MBeanServer mbServer = this.getInstallationContext().getContext().getMBeanServer(); + mbServer.unregisterMBean(mbeanName); + } catch (Exception e) { + this.getLogger().log(Level.WARNING, + "Failed to unregister Installation extension MBean for " + this.getComponentName(), e); + } + } + /** + * This method is called by the JBI runtime to allow a component to upgrade + * it's workspace and any existing Service Units to match the new version of + * the component. The JBI runtime copies the existing workspace root to the + * new workspace root prior to calling this method, so that the component + * can examine the contents of the workspace root to determine the version + * of the component from which the upgrade is being made. All updates to the + * workspace root are done in-place; in the event of a failure, the JBI + * runtime reverts back to the original workspace root, the original install + * root, and the original Service Unit roots for the component. + * + * Note1: The component must ensure that it never holds open references + * to any files in the workspace root or any of the Service Unit roots upon + * returning from this method. Failure to do so will cause problems when + * the runtime attempts to complete the upgrade processing. + * + * Note2: The installation context that is normally initialized + * by the runtime by calling ${symbol_pound}init method of the javax.jbi.Bootstrap interface + * before install and uninstall will not be called before calling this + * upgrade method. So, installation context can not be used in this method's + * implementation. + * + * Note3: Since there won't be any installation context available, the logger + * that returned from the ${symbol_pound}getLogger method is a default logger created using + * the package name of this class or extended class if the method is overridden + * in the extended class. + * + * @param workspaceRoot the workspace root for the new version of the + * component that will replace the currently installed version. This is + * populated with the contents of the original workspace root and the + * component must update it to match the new version of the component. + * @param serviceUnitRoots a list of directory paths to all of the Service + * Units currently deployed to the component. The component must update all + * of these to match the new version of the component. + * @exception JBIException when there is an error requiring that the upgrade + * be terminated. + */ + public void upgrade(String workspaceRoot, List serviceUnitRoots) + throws javax.jbi.JBIException + { + //TODO: override this method in the extended class to handle the + // workspace root and service unit roots upgrade according to the + // component's requirement. + this.getLogger().fine("Default upgrade implementation. " + + "TODO: Implement workspace root and service unit roots upgrade."); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/ComponentRuntime.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/ComponentRuntime.java new file mode 100644 index 000000000..5c32ce274 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/ComponentRuntime.java @@ -0,0 +1,174 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ComponentRuntime.java + */ +package net.openesb.component.${artifactId}.common; + +import java.util.logging.Logger; +import javax.jbi.component.Component; +import javax.jbi.component.ComponentContext; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.component.ServiceUnitManager; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.servicedesc.ServiceEndpoint; +import org.w3c.dom.Document; +import org.w3c.dom.DocumentFragment; + +/** + * This class implements javax.jbi.component.Component interface which is + * responsible for creating the Component Lifecycle implementation and the + * ServiceUnitManager implementation for the jbi component. + * + * This class makes sure that non null component lifecycle implementation is + * returns by this class or any classes extended from this class which is + * required as a component contract. It also provides default implementation of + * all methods of the Component interface which the extended classes can + * override to add more functionality. + * + * @see javax.jbi.component.Component + * @author chikkala + */ +public class ComponentRuntime implements Component { + /** Component LifeCycle implementation */ + private ComponentLifeCycle mLifeCycle; + /** ServiceUnitManager implementation */ + private ServiceUnitManager mSUManager; + /** default logger*/ + private Logger mDefLogger; + + /** Creates a new instance of ComponentImpl */ + public ComponentRuntime() { + this.mLifeCycle = null; + this.mSUManager = null; + } + /** + * returns the ComponentContext. Any component runtime class extended from + * this class can override this method to return their own reference to the + * ComponentContext. + * @return ComponentContext component context. + */ + public ComponentContext getComponentContext() { + ComponentContext ctx = null; + if ( this.mLifeCycle != null && this.mLifeCycle instanceof BasicComponentLifeCycle ) { + ctx = ((BasicComponentLifeCycle) this.mLifeCycle).getComponentContext(); + } + return ctx; + } + /** + * Returns logger initialized from the component context or a default logger. + * @return Logger + */ + public Logger getLogger() { + Logger logger = null; + if ( this.mLifeCycle != null && this.mLifeCycle instanceof BasicComponentLifeCycle ) { + logger = ((BasicComponentLifeCycle) this.mLifeCycle).getLogger(); + } + // init default logger if required + if ( logger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (logger != null) ? logger : this.mDefLogger; + } + /** + * return the ComponentLifeCycle implementation. if returned null, the + * ComponentLifeCycleImpl will be used as the component lifecycle + * Extended classes can override this method and do their own ComponentLifecyle + * specific creation. + */ + protected ComponentLifeCycle createComponentLifeCycle() { + return new BasicComponentLifeCycle(this); + } + /** + * Get the life cycle control interface for this component. + * + * @return the life cycle control interface for this component + * @see javax.jbi.Component${symbol_pound}getLifeCycle() + */ + public final ComponentLifeCycle getLifeCycle() { + if ( this.mLifeCycle == null ) { + this.mLifeCycle = createComponentLifeCycle(); + if ( this.mLifeCycle == null ) { + this.getLogger().fine("Creating basic component lifecycle implemenation"); + // use the default ComponentLifeCycle Impl if a component + // specific implementation return null in createComponentLifeCycle. + this.mLifeCycle = new BasicComponentLifeCycle(this); + } + } + return this.mLifeCycle; + } + /** + * if this component supports service unit deployment, then return the + * service unit manager, else return null. + * Extended classes can override this method and do their own ServiceUnitManager + * specific creation. + */ + protected ServiceUnitManager createServiceUnitManager() { + return null; + } + /** + * Get the Service Unit manager for this component. + * + * @return the ServiceUnitManager for this component, or + * null if there is none. + * @see javax.jbi.Component${symbol_pound}getServiceUnitManager() + */ + public final ServiceUnitManager getServiceUnitManager() { + if ( this.mSUManager == null ) { + this.mSUManager = createServiceUnitManager(); + } + return this.mSUManager; + } + /** + * Retrieves a DOM representation containing metadata which describes the + * service provided by this component, through the given endpoint. + * + * Default implementation does not support service description. + * + * @see javax.jbi.Component${symbol_pound}getServiceDescription(javax.jbi.servicedesc.ServiceEndpoint) + */ + public Document getServiceDescription(ServiceEndpoint serviceEndpoint) { + return null; + } + /** + * This method is called by JBI to check if this component, in the role of + * provider of the service indicated by the given exchange, can actually + * perform the operation desired. + * + * Default implementation has no policy and allows all exchanges with consumer. + * + * @see javax.jbi.Component${symbol_pound}isExchangeWithProviderOkay( + * javax.jbi.servicedesc.ServiceEndpoint, javax.jbi.messaging.MessageExchange) + */ + public boolean isExchangeWithConsumerOkay( + ServiceEndpoint serviceEndpoint, MessageExchange messageExchange) { + return true; + } + /** + * This method is called by JBI to check if this component, in the role of + * consumer of the service indicated by the given exchange, can actually + * interact with the provider properly. The provider is described by the + * given endpoint and the service description supplied by that endpoint. + * + * Default implementation has no policy and allows all exchanges with provider. + * + * @see javax.jbi.Component${symbol_pound}isExchangeWithProviderOkay( + * javax.jbi.servicedesc.ServiceEndpoint, javax.jbi.messaging.MessageExchange) + */ + public boolean isExchangeWithProviderOkay( + ServiceEndpoint serviceEndpoint, MessageExchange messageExchange) { + return true; + } + /** + * Resolve the given endpoint reference. + * + * Default implementation does not have any XML dialect. So can not resolve the + * endpoint from the document fragment. + * + * @see javax.jbi.Component${symbol_pound}resolveEndpointReference(org.w3c.dom.DocumentFragment) + */ + public ServiceEndpoint resolveEndpointReference(DocumentFragment documentFragment) { + return null; + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java new file mode 100644 index 000000000..51c85bc6e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java @@ -0,0 +1,180 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * DefaultMessageExchangeReceiver.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import javax.jbi.JBIException; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; + +/** + * This class implements MessageExchangeReceiver interface. This is a default implementation that + * demonstrates the multi-threaded environment to receive and process message exchanges from the + * delivery channel. It uses a main thread to receive message exchanges from the delivery channel + * and then processes the received message exchanges in a individual threads from the thread pool. + * The controller methods of MessageExchangeReceiver controls the main thread and the thread pool + * execution. + * + * @author chikkala + */ +public class DefaultMessageExchangeReceiver implements MessageExchangeReceiver { + + /** delivery channel accept time out */ + private final static long DC_ACCEPT_TIME_OUT = 3000; // milliseconds + /** receiver thread wait time before polling for messages after woke up **/ + private final static long RECEIVER_WAIT_TIME = 2000; // milliseconds + /** receiver thread wait time before force shutdown */ + private final static long RECEIVER_SHUTDOWN_WAIT_TIME = 10; // seconds + /** handler threads wait time before forced shutdown */ + private final static long HANDLERS_SHUTDOWN_WAIT_TIME = 30; // seconds + /** handler thread pool size */ + private final static int HANDLER_THREAD_POOL_SIZE = 5; + /** receiver thread accept message exchange condition */ + private Boolean mCanAccept = false; + /** receiver thread termination condition */ + private Boolean mContinue = true; + /** receiver thread executor service */ + private ExecutorService mReceiverThreadMgr; + /** handler thread executor service */ + private ExecutorService mHandlerThreadPool; + + /** no default constructor for extended classes */ + public DefaultMessageExchangeReceiver() { + } + /** + * this method is called from the ComponentLifecyle.init method of the AbstractComponentLifecycle + * to initialize the message exchange receiving resources such as threads and thread pools + * throws JBIException on error + */ + public final void initReceiver() throws JBIException { + + this.mHandlerThreadPool = Executors.newFixedThreadPool(HANDLER_THREAD_POOL_SIZE); + this.mReceiverThreadMgr = Executors.newSingleThreadExecutor(); + + this.mReceiverThreadMgr.execute(new Runnable() { + public void run() { + Thread t = Thread.currentThread(); + while ( mContinue ) { + if (mCanAccept) { + receiveAndProcessMessageExchange(); + } else { + try { + t.sleep(RECEIVER_WAIT_TIME); + } catch (InterruptedException interruptException) { + // someone must have interrupted this thread + // do nothing + RuntimeHelper.logDebug("Interrupted the MessageReceiverThread in Sleep"); + } + } + } + } + }); + } + /** + * this method is called from the ComponentLifecyle.shutdown method of the AbstractComponentLifecycle + * to cleanup the message exchange receiving resources such as threads and thread pools. + * throws JBIException on error + */ + public final void shutdownReceiver() throws JBIException { + + synchronized ( mContinue ) { + mContinue = false; + } + boolean terminated = false; + try { + this.mReceiverThreadMgr.shutdown(); + terminated = this.mReceiverThreadMgr.awaitTermination( + RECEIVER_SHUTDOWN_WAIT_TIME, TimeUnit.SECONDS); + } catch (InterruptedException ex) { + RuntimeHelper.logDebug(ex); + } finally { + if ( !terminated ) { + RuntimeHelper.logDebug("Message Receiver not shutdown. Forcing shutdown"); + this.mReceiverThreadMgr.shutdownNow(); + } + } + shutdownHandlers(); + } + /** + * shutdown all the working threads from the thread pool. + */ + private final void shutdownHandlers() throws JBIException { + + boolean terminated = false; + try { + this.mHandlerThreadPool.shutdown(); + terminated = this.mHandlerThreadPool.awaitTermination( + HANDLERS_SHUTDOWN_WAIT_TIME, TimeUnit.SECONDS); + } catch (InterruptedException ex) { + RuntimeHelper.logDebug(ex); + } finally { + if ( !terminated ) { + RuntimeHelper.logDebug("Handler threads not shutdown. Forcing shutdown"); + this.mHandlerThreadPool.shutdownNow(); + } + } + } + /** + * this method is called from the ComponentLifecyle.start method of the AbstractComponentLifecycle + * to start receiving the message exchanges from the delivery channel and process them. + * throws JBIException on error + */ + public final void startProcessing() throws JBIException { + + synchronized ( this.mCanAccept ) { + this.mCanAccept = true; + } + } + /** + * this method is called from the ComponentLifecyle.stop method of the AbstractComponentLifecycle + * to stop receiving the message exchanges from the delivery channel. + * throws JBIException on error + */ + public final void stopProcessing() throws JBIException { + + synchronized ( this.mCanAccept ) { + this.mCanAccept = false; + } + } + + protected MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeHelper.getMessageExchangeSupport(); + } + + private void receiveAndProcessMessageExchange() { + try { + DeliveryChannel channel = RuntimeHelper.getDeliveryChannel(); + if ( channel == null ) { + RuntimeHelper.logDebug("DeliveryChannel Not Opened for receiving messages"); + return; + } + final MessageExchange msgExchange = channel.accept(DC_ACCEPT_TIME_OUT); + if ( msgExchange == null ) { + // delivery channel timeout occurred. do nothing. + // RuntimeHelper.logDebug("DeliveryChannel returned null message exchange from accept"); + return; + } + final ExchangeStatus status = msgExchange.getStatus(); + // process message exchange in a separate thread + this.mHandlerThreadPool.execute(new Runnable() { + public void run() { + getMessageExchangeSupport().fireMessageExchangeReceived(status, msgExchange); + } + }); + + } catch (MessagingException ex) { + RuntimeHelper.logWarning(ex); + ex.printStackTrace(); + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java new file mode 100644 index 000000000..fed6c987d --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java @@ -0,0 +1,31 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * MessageExchangeHandler.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; + +/** + * This interface is a Handler to perform message exchanges when the component + * receives the MessageExchange object from the delivery channel. + * Implementation of this interface should implement the processing of + * the active, error, done status of the MessageExchange object according to + * the MEP for which the MessageExchange object is created. + * + * @author chikkala + */ +public interface MessageExchangeHandler { + /** + * this method will be invoked to process the MessageExchange + * object. + * @param msgExchange MessageExchange object to process. + */ + void processMessageExchange(ExchangeStatus status, MessageExchange msgExchange); + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeListener.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeListener.java new file mode 100644 index 000000000..c27c1f221 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeListener.java @@ -0,0 +1,36 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * MessageExchangeListener.java + */ + +package net.openesb.component.${artifactId}.common; + +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; + +/** + * This interface defines the notification mechanism with which the message exchange object received + * from the delivery channel is processed by the interesting parties. A particular service endpoint + * implementation would first register the implementation of this interface with MessageExchangeSupport + * to get the notification of a received message exchange on a particular service endpoint and the + * implementation of the interface would process the message exchange when notified. + * + * When the com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver receives the message exchange + * object, it asks the MessageExchangeSupport to notify the MessageExchangeLister that is registered for the + * received message exchange object to process the message exchange object. + * @see com.sun.jbi.sample.component.common.MessageExchangeSupport + * @see com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @author chikkala + */ +public interface MessageExchangeListener { + /** + * MessageExchangeSupport will call this method to notify the lister implementation that a + * message exchange is received from the delivery channel. + * @param me MessageExchange Object + */ + void messageExchangeReceived(ExchangeStatus status, MessageExchange me); +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java new file mode 100644 index 000000000..607146abd --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java @@ -0,0 +1,47 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * MessageExchangeReceiver.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import javax.jbi.JBIException; + +/** + * This interface provides the methods can controls the receiving and processing of the message + * exchange objects from the delivery channel during the component lifecycle operations. + * The implementation of this interface can use multi-threaded environment to receive and process + * message exchanges from the delivery channel during the component lifecycle. + * @see com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver + * @author chikkala + */ +public interface MessageExchangeReceiver { + /** + * this method is called from the ComponentLifecyle.init method of the AbstractComponentLifecycle + * to initialize the message exchange receiving resources such as threads and thread pools + * throws JBIException on error + */ + void initReceiver() throws JBIException; + /** + * this method is called from the ComponentLifecyle.start method of the AbstractComponentLifecycle + * to start receiving the message exchanges from the delivery channel and process them. + * throws JBIException on error + */ + void startProcessing() throws JBIException; + /** + * this method is called from the ComponentLifecyle.stop method of the AbstractComponentLifecycle + * to stop receiving the message exchanges from the delivery channel. + * throws JBIException on error + */ + void stopProcessing() throws JBIException; + /** + * this method is called from the ComponentLifecyle.shutdown method of the AbstractComponentLifecycle + * to cleanup the message exchange receiving resources such as threads and thread pools. + * throws JBIException on error + */ + void shutdownReceiver() throws JBIException; + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java new file mode 100644 index 000000000..bddf9a8b1 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java @@ -0,0 +1,170 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * MessageExchangeSupport.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessageExchange.Role; +import javax.xml.namespace.QName; + +/** + * This class supports the registering and unregistering MessageExchangeListeners and the + * MessageExchangeHandlers that can be used to process the received message exchange from a + * delivery channel. A global reference to this class will be created in RuntimeContext object to + * provide access to this class from any where in the component runtime. + * + * A ProviderEndpoint or ConsumerEndpoint interested in a MessageExchange received from a delivery + * channel for a particular service endpoint will register the MessageExchangeListener with this + * class. The DefaultMessageExchangeReceiver when received a message exchange object from the delivery + * channel uses MessageExchangeSupport.processMessageExchange method to notify the registered listener. + * + * The MessageExchangeListener implementation ( ProviderEndpoint or ConsumerEndpoint ) while processing + * received message ( messageExchangeReceived()) will create and register the message exchange handlers + * to process the message exchange. + * + * @see RuntimeContext${symbol_pound}getMessageExchangeSupport + * @see RuntimeHelper${symbol_pound}getMessageExchangeSupport + * @see DefaultMessageExchangeReceiver${symbol_pound}receiveAndProcessMessageExchange + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @author chikkala + */ +public class MessageExchangeSupport { + /** listener map to notify a message exchange received event */ + private Map mListeners; + /** handlers that can process the message exchange */ + private Map mHandlers; + /** Creates a new instance of MessageExchangeSupport */ + public MessageExchangeSupport() { + this.mListeners = Collections.synchronizedMap(new HashMap()); + this.mHandlers = Collections.synchronizedMap(new HashMap()); + } + /** + * generates key that will be used to store the MessageExchangeListener objects. + * @param serviceName QName of the service + * @param endpointName endpoint name of the service. + */ + public String createListenerKey(Role role, QName interfaceName, QName serviceName, String endpointName) { + + StringBuffer strBuff = new StringBuffer(); + strBuff.append(interfaceName).append("+"); + strBuff.append(serviceName).append("+"); + strBuff.append(endpointName).append("+"); + String roleType = null; + if ( Role.CONSUMER.equals(role) ) { + roleType = "CONSUMER"; + } else if ( Role.PROVIDER.equals(role) ) { + roleType = "PROVIDER"; + } + strBuff.append(roleType); + return strBuff.toString(); + } + /** + * adds message exchange listener who are interested in receiving the notification when the + * message exchange is received from delivery channel. The listener can be registered with the + * following combination of the parameters: (role,interfaceName,serviceName, endpointName), + * (role,interfaceName,null, null), (role, null,serviceName, endpointName), (role, null,serviceName, null) + * + * @param role role of the message exchange listener PROVIDER or CONSUMER - can not be null. + * @param interfaceName QName of the interface ( protType ) - can be null if the serviceName is not null + * @param serviceName QName of the service - can be null if interfaceName is not null. + * @param endpointName endpoint name of the service. - can be null if the serviceName is not null. + * @param listener MessageExchangeListener object + */ + public synchronized void addMessageExchangeListener(Role role, QName interfaceName, QName serviceName, String endpointName, MessageExchangeListener listener) { + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + this.mListeners.put(key, listener); + } + /** + * removes any message exchange listener registered for the service endpoint specified by the serviceName and + * endpoint name. + * @param serviceName QName of the service + * @param endpointName endpoint name of the service. + */ + public synchronized void removeMessageExchangeListener(Role role, QName interfaceName, QName serviceName, String endpointName) { + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + MessageExchangeListener listener = this.mListeners.remove(key); + if ( listener == null ) { + RuntimeHelper.getLogger().fine("No message exchange listener removed with key " + key); + } + } + /** + * finds the MessageExchangeListner registers for the endpoint for which the message exchange is + * received and call the method on the listener + */ + public boolean fireMessageExchangeReceived(ExchangeStatus status, MessageExchange me) { + boolean notified = false; + Role role = me.getRole(); + QName interfaceName = me.getInterfaceName(); + QName serviceName = me.getEndpoint().getServiceName(); + String endpointName = me.getEndpoint().getEndpointName(); + // lookup with complete service description ( role + interface + service + endpoint ) + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + MessageExchangeListener listener = this.mListeners.get(key); + + if ( listener == null ) { // lookup with role+interface name + key = createListenerKey(role, interfaceName, null, null); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { // lookup with role + serviceName + endpointName + key = createListenerKey(role, null, serviceName, endpointName); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { // lookup with with role + serviceName + key = createListenerKey(role, null, serviceName, null); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { + RuntimeHelper.getLogger().fine("Could not find listener for message exchange" + me); + notified = false; + } else { + listener.messageExchangeReceived(status,me); + notified = true; + } + return notified; + } + /** + * registers the MessageExchangeHandler implementation against the message exchange id. + * @param me MessageExchange for which the handler need to be assigned + * @param handler MessageExchangeHandler implementation that will be registers. + */ + public synchronized void addMessageExchangeHandler(MessageExchange me, MessageExchangeHandler handler) { + this.mHandlers.put(me.getExchangeId(), handler); + } + /** + * removes the MessageExchangeHandler for the particular message exchange object + */ + public synchronized void removeMessageExchangeHandler(MessageExchange me) { + MessageExchangeHandler handler = this.mHandlers.remove(me.getExchangeId()); + if ( handler == null ) { + RuntimeHelper.getLogger().fine("No MessageExchangeHandler found for removing " + me.getExchangeId()); + } + } + /** + * looks up the registered message exchange handler for the message exchange object + * @param me MessageExchangeHandler. + */ + public synchronized MessageExchangeHandler findMessageExchangeHandler(MessageExchange me) { + return this.mHandlers.get(me.getExchangeId()); + } + /** + * looks up the registered message exchange handler for the message exchange object with Id + * @param exchangeId message exchange object's id + */ + public synchronized MessageExchangeHandler findMessageExchangeHandler(String exchangeId) { + return this.mHandlers.get(exchangeId); + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeContext.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeContext.java new file mode 100644 index 000000000..be75c7b7d --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeContext.java @@ -0,0 +1,176 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * RuntimeContext.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import java.util.logging.Logger; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; + +/** + * This class is global context for all the component runtime to store and + * retrieve the information that should be available anywhere in the component runtime. + * + * Each instance variable of this class will be initialized at various points of the + * component runtime using setter methods on this class. + * + * The two important objects that will be initialized and available from this context are + * ComponentContext and the opened DeliveryChannel objects both of which will be set from the + * implementation {@link BasicComponentLifeCycle}. + * + * Note that the ComponentContext from this global context will not be available until + * the jbi framework calls the init method of the ComponentLifeCycle of the component and + * then intern the implementation of the init method sets the context. + * + * @see BasicComponentLifeCycle${symbol_pound}initGlobalContext + * @see BasicComponentLifeCycle${symbol_pound}openDeliveryChannel + * @see BasicComponentLifeCycle${symbol_pound}closeDeliveryChannel + * @author chikkala + */ +public final class RuntimeContext { + /** RuntimeContext singleton instance */ + private static RuntimeContext sRuntimeContext; + /** default logger*/ + private Logger mDefLogger; + /** Logger object. */ + private Logger mLogger; + /** Holds value of property ComponentContext. */ + private ComponentContext mComponentContext; + /** Holds value of property DeliveryChannel. */ + private DeliveryChannel mDeliveryChannel; + /** MessageExchange processing support **/ + private MessageExchangeSupport mMESupport; + + /** outside code can not instantiate RuntimeContext */ + private RuntimeContext() { + } + /** + * @return RuntimeContext instance. + */ + public static RuntimeContext getInstance() { + if ( sRuntimeContext == null ) { + synchronized (RuntimeContext.class) { + if ( sRuntimeContext == null ) { + sRuntimeContext = new RuntimeContext(); + } + } + } + return sRuntimeContext; + } + /** + * Getter for to obtaining ComponentContext from any where in the component runtime. + * @return ComponentContext. + */ + public ComponentContext getComponentContext() { + return this.mComponentContext; + } + /** + * Sets the Component context reference in Runtime context for global access + * any class in the component runtime. + * com.sun.jbi.sample.component.common.AbstractComponentLifeCycle${symbol_pound}initContext + * method implementation should call this method to set the global context. + * see com.sun.jbi.sample.component.common.DefaultComponentLifeCycle${symbol_pound}initContext + * for details. + * @param componentContext New value of property ComponentContext. + * @see BasicComponentLifeCycle${symbol_pound}initGlobalContext + */ + public void setComponentContext(ComponentContext componentContext) { + if ( this.mComponentContext != null ) { + (new IllegalStateException("Component Context already " + + "initialized in RuntimeContext")).printStackTrace(); + } + this.mComponentContext = componentContext; + } + /** + * Getter for obtaining opened delivery channel from any where in the component runtime. + * @return DeliveryChannel. + */ + public DeliveryChannel getDeliveryChannel() { + return this.mDeliveryChannel; + } + /** + * Sets the opened delivery channel reference in Runtime context for global access + * any class in the component runtime. + * com.sun.jbi.sample.component.common.AbstractComponentLifeCycle${symbol_pound}initContext + * method implementation should call this method to set the global context. + * see com.sun.jbi.sample.component.common.DefaultComponentLifeCycle${symbol_pound}initContext + * for details. + * + * @param componentContext New value of property ComponentContext. + */ + public void setDeliveryChannel(DeliveryChannel deliveryChannel) { + if ( deliveryChannel != null && this.mDeliveryChannel != null ) { + (new IllegalStateException("Delivery Channel already " + + "initialized in RuntimeContext")).printStackTrace(); + } + this.mDeliveryChannel = deliveryChannel; + } + /** + * Sets the logger. + * + * @param name name for the Logger. + * @param resourceBundle resource bundle for the logger. can be null. + */ + public void setLogger(String name, String resourceBundle) { + + if (this.mComponentContext != null) { + // get the logger from component context if the component context is not null + try { + this.mLogger = this.mComponentContext.getLogger(name, resourceBundle); + } catch (Exception ex) { + ex.printStackTrace(); + } + } else { + this.mDefLogger = Logger.getLogger(name, resourceBundle); + } + } + /** + * Returns the logger. + * + * @return Logger + */ + public Logger getLogger() { + + // try init logger + if (this.mLogger == null && this.mComponentContext != null ) { + try { + this.mLogger = + this.mComponentContext.getLogger(this.getClass().getName(), null); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + // init default logger if required + if ( this.mLogger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (this.mLogger != null) ? this.mLogger : this.mDefLogger; + } + /** + * Returns the Component Name if the ComponentContext is set. else null + * @return component name + */ + public String getComponentName() { + String componentName = null; + if (this.mComponentContext != null) { + componentName = this.mComponentContext.getComponentName(); + } + return componentName; + } + /** + * Global MessageExchangeSupport reference. Various classes in the common + * component runtime would use this method to obtain the MessageExchangeSupport + * for processing message exchange objects received from delivery channel. + */ + public MessageExchangeSupport getMessageExchangeSupport() { + if ( this.mMESupport == null ) { + this.mMESupport = new MessageExchangeSupport(); + } + return this.mMESupport; + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeHelper.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeHelper.java new file mode 100644 index 000000000..f12c2b2f4 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeHelper.java @@ -0,0 +1,360 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * RuntimeHelper.java + */ + +package net.openesb.component.${artifactId}.common; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stream.StreamResult; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * This is a helper class that have bunch of methods for xml processing. + * @author chikkala + */ +public class RuntimeHelper { + + public static Logger getLogger() { + return RuntimeContext.getInstance().getLogger(); + } + + public static void logWarning(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.WARNING, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().warning(logObj.toString()); + } + } + + public static void logError(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.SEVERE, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().severe(logObj.toString()); + } + } + + public static void logDebug(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.FINER, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().finer(logObj.toString()); + } + } + + public static String getComponentName() { + return RuntimeContext.getInstance().getComponentName(); + } + public static ComponentContext getComponentContext() { + return RuntimeContext.getInstance().getComponentContext(); + } + public static DeliveryChannel getDeliveryChannel() { + return RuntimeContext.getInstance().getDeliveryChannel(); + } + + public static MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeContext.getInstance().getMessageExchangeSupport(); + } + + /** + * return the DOM Document + * @param xmlReader Reader + * @return dom document + * @throws Exception on parser exception or any other exception + */ + public static Document buildDOMDocument(Reader xmlReader) throws Exception { + InputSource xmlSource = new InputSource(xmlReader); + return buildDOMDocument(xmlSource); + } + /** + * return the DOM Document + * @param xmlReader Reader + * @return dom document + * @throws Exception on parser exception or any other exception + */ + public static Document buildDOMDocument(InputSource xmlSource) throws Exception { + Document xmlDoc = null; + DocumentBuilderFactory docBuilderFactory = + DocumentBuilderFactory.newInstance(); + docBuilderFactory.setValidating(false); + docBuilderFactory.setNamespaceAware(true); + DocumentBuilder docBuilder = + docBuilderFactory.newDocumentBuilder(); + docBuilder.setErrorHandler( new DefaultHandler() { + public void fatalError(SAXParseException e) + throws SAXException { + throw new SAXException(e.getMessage()); + } + }); + + docBuilder.setEntityResolver(new EntityResolver() { + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException, IOException { + StringReader reader = + new StringReader(""); // NOI18N + InputSource source = new InputSource(reader); + source.setPublicId(publicId); + source.setSystemId(systemId); + return source; + } + }); + + xmlDoc = docBuilder.parse(xmlSource); + + return xmlDoc; + } + /** + * reads xml text from DOMSource to StringBuffer + */ + public static StringBuffer readFromDOMSource(DOMSource domSource) { + + StringWriter writer = new StringWriter(); + + TransformerFactory tFactory = TransformerFactory.newInstance(); + Transformer trans = null; + try { + trans = tFactory.newTransformer(); + trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, + "yes"); + trans.setOutputProperty(OutputKeys.INDENT, "yes"); + StreamResult result = new StreamResult(writer); + trans.transform(domSource, result); + } catch (TransformerConfigurationException ex) { + ex.printStackTrace(); + } catch (TransformerException ex) { + ex.printStackTrace(); + } + + return writer.getBuffer(); + } + /** + * reads the xml text from InputSource into a StringBuffer + */ + public static StringBuffer readFromInputSource(InputSource inSource) { + + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + InputStream inStream = inSource.getByteStream(); + Reader reader = inSource.getCharacterStream(); + if ( reader == null ) { + reader = new InputStreamReader(inStream); + } + BufferedReader buff = new BufferedReader(reader); + try { + + for ( String line = null; (line = buff.readLine()) != null ; ) { + out.println(line); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + + return writer.getBuffer(); + } + /** + * reads xml from from DOM, SAX or Stream Source into a string buffer + */ + public static StringBuffer readFromSource(Source source) { + if ( source instanceof DOMSource ) { + return readFromDOMSource((DOMSource)source); + } else { + InputSource inSource = SAXSource.sourceToInputSource(source); + if ( inSource != null ) { + return readFromInputSource(inSource); + } else { + return null; + } + } + } + /** + * creates a DOMSource from the xml text read from the reader. + */ + public static DOMSource createDOMSource(Reader xmlReader) { + Document doc = null; + try { + doc = buildDOMDocument(xmlReader); + } catch (Exception ex) { + ex.printStackTrace(); + } + return new DOMSource(doc); + } + /** + * creates a DOMSource from any source. If the source itself is DOMSource, + * the source is returned as it is as DOMSource. + */ + public static DOMSource sourceToDOMSource(Source source) { + if ( source instanceof DOMSource) { + return (DOMSource) source; + } + InputSource xmlSource = SAXSource.sourceToInputSource(source); + Document doc = null; + try { + doc = buildDOMDocument(xmlSource); + } catch (Exception ex) { + ex.printStackTrace(); + } + return new DOMSource(doc); + } + /** + * converts the ex stracktrace to string. + */ + public static StringBuffer getExceptionStackTrace(Exception ex) { + StringWriter strWriter = new StringWriter(); + if ( ex != null ) { + PrintWriter out = new PrintWriter(strWriter); + ex.printStackTrace(out); + } + return strWriter.getBuffer(); + } + /** + * may be used to set the exception as fault content. + */ + public static String getExceptionAsXmlText(Exception ex) { + String message = replaceXmlEscapeCharsToEntityRefereces(ex.getMessage()); + String stackTrace = replaceXmlEscapeCharsToEntityRefereces( + getExceptionStackTrace(ex).toString()); + String exXmlText = + "" + + "" + message + "" + + "" + stackTrace + "" + + "" ; + return exXmlText; + } + + /** + * may be used to set the exception as fault content. + */ + public static String getExceptionAsText(Exception ex) { + String message = replaceXmlEscapeCharsToEntityRefereces(ex.getMessage()); + String stackTrace = replaceXmlEscapeCharsToEntityRefereces( + getExceptionStackTrace(ex).toString()); + StringBuffer buff = new StringBuffer(); + buff.append(message); + buff.append(System.getProperty("line.separator", "${symbol_escape}n")); + buff.append(stackTrace); + return buff.toString(); + } + + + /** + * For attribute values which denote a QName, i.e. include a namespace prefix, + * resolve the value into a QName. + * If a namespace can not be resolved, it is set to empty - it does not + * result in an exception + * @param attrValue the string value of the attribute + * @param element the element the attribute belongs to + */ + public static QName resolveAttrQName(String attrValue, Element element) { + int aColonLoc = attrValue.indexOf(":"); + String aLocalName = attrValue; + String aPrefix = null; + String aNS = null; + if (aColonLoc > -1) { + aPrefix = attrValue.substring(0, aColonLoc); + aLocalName = attrValue.substring(aColonLoc + 1); + + // Traverse up the hierarchy until a namespace definition is found + // or the top of the document is reached. + Node currNode = element; + while ((aNS == null || aNS.equals("")) && currNode != null) { + if (currNode.getNodeType() == Node.ELEMENT_NODE) { + aNS = ((Element) currNode).getAttribute("xmlns:" + aPrefix); + } + currNode = currNode.getParentNode(); + } + } + + QName qName = new QName(aNS, aLocalName, aPrefix); + + return qName; + } + + /** + * replaces the xml entity references with the xml escape chars + * @param xmlString Text with the xml escape chars + * @param Text with the xml entity references + */ + public static String replaceXmlEscapeCharsToEntityRefereces(String xmlString) { + if ( xmlString == null ) { + return xmlString; + } + + // just convert < , > and & only + StringBuffer sbuff = new StringBuffer(2 * xmlString.length()); + for ( int i = 0; i < xmlString.length(); ++i ) { + switch ( xmlString.charAt(i) ) { + case '&': sbuff.append("&"); + break; + case '<': sbuff.append("<"); + break; + case '>': sbuff.append(">"); + break; + default: sbuff.append( xmlString.charAt(i) ); + } + } + return sbuff.toString(); + } + + /** + * return Element node from a document node or non document. Use to extract + * the message root element. + * @root node from which the Element node will be extracted. + * @return Element node. + */ + public static Element getElement(Node root) { + Element msgEl = null; + if ( root instanceof Document) { + msgEl = ((Document)root).getDocumentElement(); + } else if (root instanceof Element) { + msgEl = (Element)root; + } else { + NodeList nodeList = root.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if ( node instanceof Element ) { + msgEl = (Element) node; + break; + } + } + } + return msgEl; + } + + public static Element getElement(DOMSource domSource) { + return getElement(domSource.getNode()); + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java new file mode 100644 index 000000000..fd0fc4f79 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java @@ -0,0 +1,312 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractServiceUnitManager.java + * + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.component.ServiceUnitManager; +import javax.jbi.management.DeploymentException; + +/** + * This is an abstract class that implements {@link javax.jbi.component.ServiceUnitManager} to provide a + * service unit deployment support for the component. The implementation supported by this service + * unit manager and related classes in this package provides WSDL1.1 based service unit deployment + * in the component. + * + * @see javax.jbi.component.ServiceUnitManager + * @see ServiceUnit + * + * @author chikkala + */ +public abstract class AbstractServiceUnitManager implements ServiceUnitManager { + + /** Map of ServiceUnit Name to the ServiceUnit Object for all the service units + * deployed in the component */ + private Map mSUMap; + + /** Creates a new instance of AbstractSUManager */ + protected AbstractServiceUnitManager() { + this.mSUMap = Collections.synchronizedMap(new HashMap()); + } + /** returns the component name + * @return component name. + */ + protected abstract String getComponentName(); + /** + * @return Logger + */ + protected abstract Logger getLogger(); + /** + * returns the creation of the ServiceUnit implementation specific to the service unit deployment + * for the component. + * @param suName service unit name + * @param suRootPath service unit root path + * @param concrete implementation of the ServiceUnit class. + */ + protected abstract ServiceUnit createServiceUnit(String suName, String suRootPath) + throws DeploymentException; + /** + * returns the service unit object deployed by the specified name. or null if not deployed. + * @param suName service unit name to look for + * @param ServiceUnit object for the suName. or null if not present. + */ + private ServiceUnit getServiceUnit(String suName) { + return this.mSUMap.get(suName); + } + /** + * lookup for the deployed service unit. If not there, throws a deployment exception. + * @param suName service unit name + * @return ServiceUnit object + * @throws DeploymentException if the service unit is not present. + */ + private ServiceUnit findServiceUnit(String suName) throws DeploymentException { + ServiceUnit serviceUnit = getServiceUnit(suName); + if ( serviceUnit == null ) { + throw new DeploymentException("Service unit " + suName + " does not exist"); + } + return serviceUnit; + } + /** + * add the service unit object to the list of deployed service units. if there is already a + * service unit present with the name, throws a deployment exception. + * @param su service unit to add + * @return ServiceUnit object that is added. + * @throws DeploymentException if the service unit already present. + */ + private ServiceUnit addServiceUnit(ServiceUnit su) throws DeploymentException { + String suName = su.getName(); + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU != null ) { + throw new DeploymentException("Service unit " + suName + "already exists"); + } + this.mSUMap.put(suName, su); + return su; + } + /** + * removes service unit object from the list of deployed service units. if there is no + * service unit present with the name, throws a deployment exception. + * @param su service unit to add + * @return ServiceUnit object that is being removed. + * @throws DeploymentException if the service unit already present. + */ + private ServiceUnit removeServiceUnit(ServiceUnit su) throws DeploymentException { + String suName = su.getName(); + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU == null ) { + throw new DeploymentException("Service unit " + suName + " does not exist"); + } + return this.mSUMap.remove(suName); + } + /** + * creates the concrete service unit implementation and calls the load method on it to initialize + * the created service unit. + * @param suName service unit name to create + * @param suRootPath service unit root path. + * @return ServiceUnit that is created and loaded. + */ + private ServiceUnit loadServiceUnit(String suName, String suRootPath) throws DeploymentException { + ServiceUnit serviceUnit = createServiceUnit(suName, suRootPath); + serviceUnit.doLoad(); + return serviceUnit; + } + /** + * deploys a service unit. it creates and loads the service unit object for the suName and then call + * doDeploy on the service unit and adds it to the deployed service unit list + * @return result as jbi management xml + * @throws DeploymentException if there is an error deploying. + */ + private synchronized String deployServiceUnit(String suName, String suRootPath) throws DeploymentException { + String result = suName; + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU != null ) { + throw new DeploymentException("Service unit " + suName + "already exists"); + } + ServiceUnit serviceUnit = loadServiceUnit(suName, suRootPath); + serviceUnit.doDeploy(); + addServiceUnit(serviceUnit); + return result; + } + /** + * Deploy a Service Unit to the component. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}deploy(String, String); + */ + public final String deploy(String suName, String suRootPath) throws DeploymentException { + this.getLogger().fine("Deploying service unit " + suName + " with suRootPath " + suRootPath); + String compName = this.getComponentName(); + boolean isSuccess = true; + String mainMsg = "Successfully deployed service unit " + suName; + Exception errEx = null; + try { + deployServiceUnit(suName, suRootPath); + } catch (Exception ex) { + isSuccess = false; + errEx = ex; + mainMsg = "Failed to deploy service unit " + suName ; + this.getLogger().log(Level.FINE, mainMsg, ex); + } + return createComponentTaskResultXML(compName, "deployTask", isSuccess, mainMsg, errEx); + } + + /** + * undeploys the service unit. it looks up the existing deployed service unit and call doUndeploy + * on it and then removes from the deployed service unit list. + */ + private synchronized String undeployServiceUnit(String suName, String suRootPath) throws DeploymentException { + String result = suName; + ServiceUnit serviceUnit = findServiceUnit(suName); + serviceUnit.doUndeploy(); + removeServiceUnit(serviceUnit); + return result; + } + /** + * Undeploy a service unit from the component. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}undeploy(String, String); + */ + public final String undeploy(String suName, String suRootPath) throws DeploymentException { + this.getLogger().fine("Undeploying service unit " + suName + " with suRootPath " + suRootPath); + String compName = this.getComponentName(); + boolean isSuccess = true; + String mainMsg = "Successfully undeployed service unit " + suName; + Exception errEx = null; + try { + undeployServiceUnit(suName, suRootPath); + } catch (Exception ex) { + isSuccess = false; + errEx = ex; + mainMsg = "Failed to undeploy service unit " + suName ; + this.getLogger().log(Level.FINE, mainMsg, errEx); + } + return createComponentTaskResultXML(compName, "undeployTask", isSuccess, mainMsg, errEx); + } + /** + * Initialize the given deployed service unit. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}init(String, String); */ + public final void init(String suName, String suRootPath) + throws DeploymentException { + this.getLogger().fine("Initializing service unit " + suName + " with suRootPath " + suRootPath); + String result = suName; + ServiceUnit serviceUnit = getServiceUnit(suName); + if ( serviceUnit == null ) { // if the service unit not exists, create and add + serviceUnit = loadServiceUnit(suName, suRootPath); // create and load service unit + addServiceUnit(serviceUnit); // add service unit to existing service units + } + serviceUnit.doInit(); // Do Service unit initialization tasks + this.getLogger().fine("Service unit initialized:" + suName); + } + /** + * Shut down the deployment. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}shutdown(String); + */ + public final void shutDown(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doShutdown(); // Do Service unit shutdown tasks + this.getLogger().fine("Service unit shut down:" + suName); + } + /** + * Start the deployed service unit. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}start(String); + */ + public final void start(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doStart(); // Do service unit start tasks. + this.getLogger().fine("Service unit started:" + suName ); + } + /** + * Stop the deployed service unit. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}stop(String); + */ + public final void stop(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doStop(); // do service unit stop tasks + this.getLogger().fine("Service unit stopped: " + suName + " stopped."); + } + + /** + * helper method to create result message as jbi management message xml. + * @param componentName name of the component for this xml. + * @param taskId task id + * @param isSuccess true to format a success result, false to format a failed result. + * @param mainMsg main result message + * @param errEx Exception, null if there is no exception in failure message. + * @return XML string. + */ + protected static String createComponentTaskResultXML( + String componentName, String taskId, boolean isSuccess, String mainMsg, Exception errEx ) { + + String exMsgXml = getComponentTaskResultExceptionXML(errEx); + String mainMsgXmlEsc = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces(mainMsg); + String taskResult = isSuccess ? "SUCCESS" : "FAILED"; + String msgType = isSuccess ? "INFO" : "ERROR"; + + String xmlResult = + "" + + " " + componentName + "" + + " " + + " " + + " " + taskId + "" + + " " + taskResult + "" + + " " + msgType + "" + + " " + + " " + + " SU_MGR_MSG_ID" + + " " + mainMsgXmlEsc + "" + + " " + + " " + + exMsgXml + + " " + + " " + + ""; + + return xmlResult; + } + /** + * converts the exception to the jbi management message xml chunk. + */ + private static String getComponentTaskResultExceptionXML(Exception errEx) { + StringBuffer exMsgBuff = new StringBuffer(); + if ( errEx == null ) { + return exMsgBuff.toString(); // empty string. + } + + List exList = new ArrayList(); + int exLevel = 0; + for ( Throwable cause = errEx ; cause != null ; cause = cause.getCause() ) { + String causeMsg = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces( + cause.getMessage()); + StringWriter stBuff = new StringWriter(); + PrintWriter stOut = new PrintWriter(stBuff); + StackTraceElement[] stList = cause.getStackTrace(); + for (StackTraceElement stEl : stList) { + stOut.println(stEl.toString()); + } + stOut.close(); + String causeStackTrace = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces( + stBuff.getBuffer().toString()); + + exMsgBuff.append(""); + exMsgBuff.append(" " + exLevel + ""); + exMsgBuff.append(" " + "SU_MGR_EXP_ID"); + exMsgBuff.append(" " + causeMsg + ""); + exMsgBuff.append(" "); + exMsgBuff.append(" " + causeStackTrace + ""); + exMsgBuff.append(""); + ++exLevel; + } + + return exMsgBuff.toString(); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java new file mode 100644 index 000000000..e9537ca9e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java @@ -0,0 +1,208 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ConsumerEndpoint.java + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import javax.jbi.JBIException; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.InOnly; +import javax.jbi.messaging.InOut; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.messaging.MessageExchangeFactory; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +/** + * This class extends from Endpoint class and implements lifecycle methods functionality required for the + * endpoint for a service consumer. {@link ServiceUnit${symbol_pound}createConsumerEndpoint} creates the object of this + * type to implement the service consumer functionality. + * + * @see ServiceUnit${symbol_pound}createConsumerEndpoint + * @author chikkala + */ + +public class ConsumerEndpoint extends Endpoint { + /** + * This constructor initializes the endpoint with CONSUMER role and makes sure that the service + * description passed to it is of consumer description. + */ + protected ConsumerEndpoint(SUDescriptor.Consumes consumes, Definition wsdlDef, ServiceUnit su) { + super(Role.CONSUMER, consumes, wsdlDef, su); + } + /** + * constructor that does not need service unit information. useful for creating the endpoint for + * static services provided by the component. + */ + protected ConsumerEndpoint(SUDescriptor.Consumes consumes, Definition wsdlDef) { + this(consumes, wsdlDef, null); + } + public final void init() throws JBIException { + getLogger().fine("ConsumerEndpoint: init called"); + doInit(); //1. initialize the endpiont resources + addMessageExchangeListener(); //2. register message exchange linster. + } + public final void activate() throws JBIException { + getLogger().fine("ConsumerEndpoint: activate called"); + //1. do common ativation tasks. + doActivate(); //2. do any other activation related tasks. + } + + public final void deactivate() throws JBIException { + getLogger().fine("ConsumerEndpoint: deactivate called"); + //1. do common deactivation tasks. + doDeactivate(); //2. do any other deactivation related tasks. + } + + public final void clean() throws JBIException { + getLogger().fine("ConsumerEndpoint: clean called"); + removeMessageExchangeListener(); //1. remove message exchange listener + doClean(); //2. clean up any other resources. + } + + protected void doInit() throws JBIException { + //NOOP + } + protected void doActivate() throws JBIException { + //NOOP + } + protected void doDeactivate() throws JBIException { + //NOOP + } + protected void doClean() throws JBIException { + //NOOP + } + + /** + * helper method to find the active ServiceEndpiont for the service described with the + * serviceDescriptor. This method looks for the Active ServiceEndpoint using interface or + * service name or service name and the endpoint name. + */ + public ServiceEndpoint findServiceEndpoint() { + + QName serviceType = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + + ServiceEndpoint [] refs = null; + ServiceEndpoint serviceEndpoint = null; + ComponentContext compContext = this.getComponentContext(); + + if ( compContext == null ) { + this.getLogger().info("Null Component context. Can not find ServiceEndpoint"); + return null; + } + // lookup ServiceEndpiont with concrete service(serice qname + endpoint name). + if ( serviceName != null && endpointName != null ) { + this.getLogger().info("Looking for ServiceEndpoint with:" + + " ServiceName: " + serviceName + " EndpointName: " + endpointName); + serviceEndpoint = compContext.getEndpoint(serviceName, endpointName); + } + // else lookup ServiceEndpiont with Service Name + if ( serviceEndpoint == null && serviceName != null && endpointName == null) { + this.getLogger().info("Looking for ServiceEndpoint with Service name: " + serviceName); + refs = compContext.getEndpointsForService(serviceName); + if ( refs != null && refs.length > 0 ) { + serviceEndpoint = refs[0]; + } + } + // else lookup ServiceEndpont with serviceType + if ( serviceEndpoint == null && serviceType != null && + serviceName == null && endpointName == null) { + this.getLogger().info("Looking for ServiceEndpoint with Service type: " + serviceType); + refs = compContext.getEndpoints(serviceType); + if ( refs != null && refs.length > 0 ) { + serviceEndpoint = refs[0]; + } + } + + return serviceEndpoint; + } + + /** + * this method creates a InOutMessageExchange Object and sets the required + * data on the MessageExchange object including the create and set the Normalized + * message object to hold the input message on the MessageExchange object. + */ + public InOut createInOutMessageExchange(QName operation) + throws MessagingException, JBIException { + + ServiceEndpoint serviceEndpoint = null; + // find a ServiceEndpoint activated by the Service Providers for this service + serviceEndpoint = findServiceEndpoint(); + + if ( serviceEndpoint == null ) { + // if not found a activated ServiceEndpoint for this service, throw exception. + throw new JBIException("Can not find an Active ServiceEndpoint for ${symbol_escape}n" + this.getService()); + } else { + this.setServiceEndpoint(serviceEndpoint); + } + + InOut inOutME = null; + DeliveryChannel channel = this.getDeliveryChannel(); + // create message exchange factory for the endpiont + MessageExchangeFactory factory = channel.createExchangeFactory(serviceEndpoint); + // create INOUT Message Exchange + inOutME = factory.createInOutExchange(); + // set operation + inOutME.setOperation(operation); + // set interface if that is not set + if ( inOutME.getInterfaceName() == null ) { + inOutME.setInterfaceName(this.getService().getInterface()); + } + // create IN Nomralized Message + NormalizedMessage inMsg = inOutME.createMessage(); + // set IN Normalized message on message exchange + inOutME.setInMessage(inMsg); + + return inOutME; + } + + /** + * this method creates a InOnlyMessageExchange Object and sets the required + * data on the MessageExchange object including the create and set the Normalized + * message object to hold the input message on the MessageExchange object. + */ + public InOnly createInOnlyMessageExchange(QName operation) + throws MessagingException, JBIException { + + ServiceEndpoint serviceEndpoint = null; + // find a ServiceEndpoint activated by the Service Providers for this service + serviceEndpoint = findServiceEndpoint(); + + if ( serviceEndpoint == null ) { + // if not found a activated ServiceEndpoint for this service, throw exception. + throw new JBIException("Can not find an Active ServiceEndpoint for ${symbol_escape}n" + this.getService()); + } else { + this.setServiceEndpoint(serviceEndpoint); + } + + InOnly inOnlyME = null; + DeliveryChannel channel = this.getDeliveryChannel(); + // create message exchange factory for the endpiont + MessageExchangeFactory factory = channel.createExchangeFactory(serviceEndpoint); + // create INOUT Message Exchange + inOnlyME = factory.createInOnlyExchange(); + // set operation + inOnlyME.setOperation(operation); + // set interface if that is not set + if ( inOnlyME.getInterfaceName() == null ) { + inOnlyME.setInterfaceName(this.getService().getInterface()); + } + // create IN Nomralized Message + NormalizedMessage inMsg = inOnlyME.createMessage(); + // set IN Normalized message on message exchange + inOnlyME.setInMessage(inMsg); + + return inOnlyME; + } + + +} \ No newline at end of file diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/Endpoint.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/Endpoint.java new file mode 100644 index 000000000..359114ed2 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/Endpoint.java @@ -0,0 +1,289 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * Endpoint.java + * + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.MessageExchangeHandler; +import net.openesb.component.${artifactId}.common.MessageExchangeListener; +import net.openesb.component.${artifactId}.common.MessageExchangeSupport; +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.xml.namespace.QName; + +/** + * This is an abstract class that represents the Endpoint defined for service provisioning or + * consumption in a jbi component. It stores the required service description ( wsdl definition, + * role, service unit to which it belongs etc) and defines the lifecycle operations {@link ${symbol_pound}init}, + * {@link ${symbol_pound}activate}, {@link ${symbol_pound}deactivate}, {@link ${symbol_pound}clean} to control a service endpoint that + * provides or consumes the service. + *

+ * Extended classes implement the abstract methods defined in this class to implement the endpoint + * functionality by providing the functionality to process the deployment artifacts specific to this + * endpoint, configure the endpoint to send/receive messages to/from delivery channel and process them + * according to the specific service implementation. + * + * @author chikkala + */ +public abstract class Endpoint { + /** Role of this endpoint. CONSUMER or PROVIDER */ + private Role mRole; + /** Service description from the SU descriptor for which this endpoint is configured */ + private SUDescriptor.Service mService; + /** WSDL definition corresponding to this endpoint */ + private Definition mWsdlDef; + /** service endpoint corresponding to this endpoint */ + private ServiceEndpoint mServiceEndpoint; + /** service unit from which this endpoint is created */ + private ServiceUnit mSU; // can be null + /** private constructor to force extended classes to use the parameterized constructor */ + private Endpoint() { + } + /** Creates a new instance of Endpoint + * @param role CONSUMER or PRVODER role. + * @param service service description from the su descriptor + * @param wsdl wsdl definition corresponding to this endpoint + * @param su service unit object which created this endpoint. + */ + protected Endpoint(Role role, SUDescriptor.Service service, Definition wsdl, ServiceUnit su) { + this.mService = service; + this.mRole = role; + this.mWsdlDef = wsdl; + this.mSU = su; + } + /** Creates a new instance of Endpoint without service unit. may be useful for static endpoints that + * are not part of the deployment + * @param role CONSUMER or PRVODER role. + * @param service service info from the su descriptor + * @param wsdl wsdl definition corresponding to this endpoint + */ + protected Endpoint(Role role, SUDescriptor.Service service, Definition wsdl) { + this(role, service, wsdl, null); + } + /** + * should be called to initialize any resources related to this endpoint object + * throws JBIException + */ + public abstract void init() throws JBIException; + /** + * activates the endpoint to send/receive messages + * throws JBIException + */ + public abstract void activate() throws JBIException; + /** + * deactivates the endpoint + * throws JBIException + */ + public abstract void deactivate() throws JBIException; + /** + * clean endpoint + * throws JBIException + */ + public abstract void clean() throws JBIException; + + public final Role getRole() { + return this.mRole; + } + public final boolean isProvider() { + return (Role.PROVIDER.equals(this.getRole())); + } + public final boolean isConsumer() { + return (Role.CONSUMER.equals(this.getRole())); + } + public final Definition getWSDL() { + return this.mWsdlDef; + } + public final SUDescriptor.Service getService() { + return this.mService; + } + public final ServiceEndpoint getServiceEndpoint() { + return this.mServiceEndpoint; + } + protected final void setServiceEndpoint(ServiceEndpoint svcEP) { + this.mServiceEndpoint = svcEP; + } + public final ServiceUnit getServiceUnit() { + return this.mSU; + } + /** + * generates an ID that would uniquely identify this endpoint implementation. Use as a key to map + * any information to store that is related to this endpoint. + */ + public final String getID() { + StringBuffer strBuff = new StringBuffer(); + strBuff.append(this.mService.getInterface()).append("+"); + strBuff.append(this.mService.getServiceName()).append("+"); + strBuff.append(this.mService.getEndpointName()).append("+"); + String roleType = null; + if ( Role.CONSUMER.equals(this.mRole) ) { + roleType = "CONSUMER"; + } else if ( Role.PROVIDER.equals(this.mRole) ) { + roleType = "PROVIDER"; + } + strBuff.append(roleType); + return strBuff.toString(); + } + + @Override + public String toString() { + return "Endpoint : " + "${symbol_escape}n" + this.mService; + } + /** + * checks if this endpoint is configured for the binding component or service engine. + */ + public boolean isForBindingComponent() { + boolean isForBindingComponent = false; + if ( this.mSU != null ) { + try { + isForBindingComponent = this.mSU.getSUDescriptor().isForBindingComponent(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + return isForBindingComponent; + } + + public QName getOperationQName(String opName) { + return new QName(this.getService().getInterface().getNamespaceURI(), opName); + } + + public Operation getWSDLOperation(QName opQName) { + String opName = null; + if ( opQName != null ) { + opName = opQName.getLocalPart(); + } + Operation operation = WSDLProcessor.findOperation(this.getWSDL(), + this.getService().getInterface(), opName); + return operation; + } + + public Binding getWSDLBinding() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + if ( serviceName != null ) { + return WSDLProcessor.findServiceBinding(this.getWSDL(), serviceName, endpointName); + } else { + return WSDLProcessor.findInterfaceBinding(this.getWSDL(), interfaceName, null); + } + } + /** @return logger */ + public Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** @return ComponentContext */ + public ComponentContext getComponentContext() { + return RuntimeHelper.getComponentContext(); + } + /** @return DeliveryChannel */ + public DeliveryChannel getDeliveryChannel() { + return RuntimeHelper.getDeliveryChannel(); + } + /** + * helper function to get the MessageExchangeSupport object + */ + public MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeHelper.getMessageExchangeSupport(); + } + + public MessageExchangeHandler createMessageExchangeHandler() { + return null; + } + /** + * creates the message exchange listener. Extended classes should return + * MessageExchangeListener implementation. + * @return MessageExchangeListener or null. + * + */ + protected MessageExchangeListener createMessageExchangeListener() { + return null; + } + /** + * Creates and adds message exchange listener to receive message exchange received notification. + */ + protected void addMessageExchangeListener() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + MessageExchangeListener meListener = createMessageExchangeListener(); + MessageExchangeSupport meListenerSupport = getMessageExchangeSupport(); + if ( meListenerSupport != null && meListener != null ) { + meListenerSupport.addMessageExchangeListener( + this.getRole(), interfaceName, serviceName, endpointName, meListener); + if ( serviceName != null ) { + meListenerSupport.addMessageExchangeListener( + this.getRole(), null, serviceName, endpointName, meListener); + } + } + } + /** + * Removes message exchange listener from the MessageExchangeSupport. + */ + protected void removeMessageExchangeListener() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + MessageExchangeSupport meListenerSupport = getMessageExchangeSupport(); + if ( meListenerSupport != null ) { + meListenerSupport.removeMessageExchangeListener( + this.getRole(), interfaceName, serviceName, endpointName); + if ( serviceName != null ) { + meListenerSupport.removeMessageExchangeListener( + this.getRole(), null, serviceName, endpointName); + } + } + } + + public final boolean processMessageExchangeWithHandler(ExchangeStatus status, MessageExchange me) { + + //1. lookup handler + //2. if not there create one and register + //3. call process message exchange on it + //4. check status. if that is the end, remove the handler + + MessageExchangeSupport support = this.getMessageExchangeSupport(); + if ( support == null ) { + getLogger().fine("No MessageExchangeSupport present"); + return false; + } + MessageExchangeHandler handler = support.findMessageExchangeHandler(me); + if ( handler == null ) { + handler = this.createMessageExchangeHandler(); + if ( handler == null ) { + getLogger().fine("MessageExchangeHandler not supported"); + return false; + } + support.addMessageExchangeHandler(me, handler); + } + + handler.processMessageExchange(status, me); + + getLogger().fine("XXX MX Handler processed ME with STATUS: " + status); + + if (!ExchangeStatus.ACTIVE.equals(status) ) { + // DONE or ERROR means done with the me. + getLogger().fine("End of ME processing. STATUS: " + status + + ". Removing the MX Handler ..."); + support.removeMessageExchangeHandler(me); + } + + return true; + } + +} + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java new file mode 100644 index 000000000..4bd932fc1 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java @@ -0,0 +1,107 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ProviderEndpoint.java + * + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Service; +import javax.jbi.JBIException; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Definition; + +/** + * This class extends from Endpoint class and implements lifecycle methods functionality required for the + * endpoint for a service provider. {@link ServiceUnit${symbol_pound}createProviderEndpoint} creates the object of this + * type to implement the service provider functionality. It makes sure that this class or the extended + * classes will activate or deactivate the ServiceEndpoint corresponding to the service + * provided by the endpoint is performed during the activate and deactivate method calls as part of the + * endpoint lifecycle. + * + * @see ServiceUnit${symbol_pound}createProviderEndpoint + * @author chikkala + */ + +public class ProviderEndpoint extends Endpoint { + /** + * This constructor initializes the endpoint with PROVIDER role and makes sure that the service + * description passed to it is of provider description. + */ + protected ProviderEndpoint(SUDescriptor.Provides provides, Definition wsdlDef, ServiceUnit su) { + super(Role.PROVIDER, provides, wsdlDef, su); + } + /** + * constructor that does not need service unit information. useful for creating the endpoint for + * static services provided by the component. + */ + protected ProviderEndpoint(SUDescriptor.Provides provides, Definition wsdlDef) { + this(provides, wsdlDef, null); + } + /** + * initializes the endpoint and creates and registers the MessageExchangeListener with + * MessageExchangeSupport. + */ + public final void init() throws JBIException { + getLogger().fine("ProviderEndpiont: init called"); + doInit(); //1. initialize the endpiont resources + addMessageExchangeListener(); //2. register message exchange linster. + } + /** + * calls activatesServiceEndpoint for the Provider. + */ + public final void activate() throws JBIException { + getLogger().fine("ProviderEndpiont: activate called"); + activateServiceEndpoint(); //1. activate service endpoint in NMR + doActivate(); //2. do any other activation related tasks. + } + /** + * calls deactivateServiceEndpoint for the Provider. + */ + public final void deactivate() throws JBIException { + getLogger().fine("ProviderEndpiont: deactivate called"); + deactivateServiceEndpoint(); //1. deactivates the service endpoint in NMR + doDeactivate(); //2. do any other deactivation related tasks. + } + /** + * removes the message exchange listener. cleans up other resources + */ + public final void clean() throws JBIException { + getLogger().fine("ProviderEndpiont: clean called"); + removeMessageExchangeListener(); //1. remove message exchange listener + doClean(); //2. clean up any other resources. + } + /** + * Activates the ServiceEndpoint with NMR + */ + private void activateServiceEndpoint() throws JBIException { + Service service = this.getService(); + ServiceEndpoint svcEP = this.getComponentContext().activateEndpoint( + service.getServiceName(), service.getEndpointName()); + this.setServiceEndpoint(svcEP); + } + /** + * Deactivates ServiceEndpoint in NMR + */ + private void deactivateServiceEndpoint() throws JBIException { + this.getComponentContext().deactivateEndpoint(this.getServiceEndpoint()); + this.setServiceEndpoint(null); + } + + protected void doInit() throws JBIException { + //NOOP + } + protected void doActivate() throws JBIException { + //NOOP + } + protected void doDeactivate() throws JBIException { + //NOOP + } + protected void doClean() throws JBIException { + //NOOP + } + +} \ No newline at end of file diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java new file mode 100644 index 000000000..1919647be --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java @@ -0,0 +1,364 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * SUDescriptor.java + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import javax.jbi.management.DeploymentException; +import javax.xml.namespace.QName; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * This interface represent the service unit descriptor (jbi.xml) model. This will be used in + * ServiceUnit implementation to find the services provided and consumed by this service unit. + * {@link SUDescriptorFactory${symbol_pound}getSUDescriptor} method reads the jbi.xml in the service unit to + * to the implementation of this interface. + * + * @see SUDescriptorFactory + * @see Consumes + * @see Provides + * @see ServiceUnit + * + * @author chikkala + */ +public interface SUDescriptor { + + Collection getProvidedServices(); + + Collection getConsumedServices(); + + boolean isForBindingComponent(); + + /** + * base interface that models the service information described in the service unit descriptor for + * consumed services and provided services. + */ + public interface Service { + /** + * Getter for property interfaceQName. + * @return Value of property interfaceQName. + */ + QName getInterface(); + /** + * Getter for property serviceName. + * @return Value of property serviceName. + */ + QName getServiceName(); + /** + * Getter for property endpointName. + * @return Value of property endpointName. + */ + String getEndpointName(); + } + /** + * marker interface that represents the provided services in the service unit + */ + public interface Provides extends Service { + } + /** + * this interface represents the consumed service information in the su descriptor. + */ + public interface Consumes extends Service { + + public final static String STANDARD_LINK = "standard"; + public final static String SOFT_LINK = "soft"; + public final static String HARD_LINK = "hard"; + /** + * Getter for property linkType. + * @return Value of property linkType. + */ + String getLinkType(); + } + /** + * This is a factory class that can build the Service Unit Descriptor model from the jbi.xml + */ + public static class SUDescriptorFactory { + + protected final static String JBI_TAG_NAME = "services"; + protected final static String SERVICES_TAG_NAME = "services"; + protected final static String BC_TAG_NAME = "binding-component"; + protected final static String PROVIDES_TAG_NAME = "provides"; + protected final static String CONSUMES_TAG_NAME = "consumes"; + protected final static String INTERFACE_TAG_NAME = "interface-name"; + protected final static String SERVICE_TAG_NAME = "service-name"; + protected final static String ENDPOINT_TAG_NAME = "endpoint-name"; + protected final static String LINK_TYPE_TAG_NAME = "link-type"; + /** + * method that builds the Service unit descriptor model from the jbi.xml + */ + public static SUDescriptor getSUDescriptor(String jbiXmlPath) throws Exception { + FileReader reader = null; + try { + reader = new FileReader(jbiXmlPath); + SUDescriptor suDesc = getSUDescriptor(reader); + return suDesc; + } finally { + if ( reader != null ) { + try { + reader.close(); + } catch (IOException ex) { + // ignore + } + } + } + } + /** + * method that builds the Service unit descriptor model from the jbi.xml + */ + public static SUDescriptor getSUDescriptor(Reader reader) throws Exception { + SUDescriptor suDescriptor = null; + Document suDescDoc = RuntimeHelper.buildDOMDocument(reader); + Element jbiEl = suDescDoc.getDocumentElement(); + if (JBI_TAG_NAME.equals(jbiEl.getTagName())) { + throw new DeploymentException("Invalid service unit descriptor : no jbi root element"); + } + + NodeList servicesNL = jbiEl.getElementsByTagName(SERVICES_TAG_NAME); + if (servicesNL != null && servicesNL.getLength() == 1) { + Element servicesEl = (Element) servicesNL.item(0); + suDescriptor = SUDescriptorImpl.createSUDescriptor(servicesEl); + } else { + throw new DeploymentException("Invalid service unit descriptor : invalid services element"); + } + + return suDescriptor; + } + + } + /** + * This class implements SUDescriptor + */ + public static class SUDescriptorImpl implements SUDescriptor { + + private List mConsumedList; + private List mProvidedList; + private boolean mIsForBindingComponent; + + protected SUDescriptorImpl(boolean isForBindingComponent) { + this.mIsForBindingComponent = isForBindingComponent; + this.mConsumedList = new ArrayList(); + this.mProvidedList = new ArrayList(); + } + + protected void addProvidedService(Provides provides) { + this.mProvidedList.add(provides); + } + + protected void addConsumedService(Consumes consumes) { + this.mConsumedList.add(consumes); + } + + public Collection getProvidedServices() { + // return unmodifiable collection + return Collections.unmodifiableCollection(this.mProvidedList); + } + + public Collection getConsumedServices() { + // return unmodifiable collection + return Collections.unmodifiableCollection(this.mConsumedList); + } + + public boolean isForBindingComponent() { + return this.mIsForBindingComponent; + } + + protected static SUDescriptor createSUDescriptor(Element servicesEl) throws Exception { + boolean isForBC = false; + String bcTagString = servicesEl.getAttribute(SUDescriptorFactory.BC_TAG_NAME); + isForBC = Boolean.valueOf(bcTagString).booleanValue(); + SUDescriptorImpl suDesc = new SUDescriptorImpl(isForBC); + // add consumes + NodeList consumesNL = servicesEl.getElementsByTagName(SUDescriptorFactory.CONSUMES_TAG_NAME); + for ( int i=0; i < consumesNL.getLength(); ++i) { + Element consumesEl = (Element) consumesNL.item(i); + Consumes consumes = ConsumedService.createConsumedService(consumesEl); + suDesc.addConsumedService(consumes); + } + // add provides + NodeList providesNL = servicesEl.getElementsByTagName(SUDescriptorFactory.PROVIDES_TAG_NAME); + for ( int i=0; i < providesNL.getLength(); ++i) { + Element providesEl = (Element) providesNL.item(i); + Provides provides = ProvidedService.createProvidedService(providesEl); + suDesc.addProvidedService(provides); + } + + return suDesc; + } + } + /** + * Base class that implements the Service interface + */ + public static abstract class AbstractService implements Service { + + private QName mInterface; + private QName mServiceName; + private String mEndpointName; + + private AbstractService() { + } + /** + * Getter for property interfaceQName. + * @return Value of property interfaceQName. + */ + public QName getInterface() { + return this.mInterface; + } + + /** + * Setter for property interfaceQName. + * @param interfaceQName New value of property interfaceQName. + */ + protected void setInterface(QName interfaceQName) { + this.mInterface = interfaceQName; + } + + /** + * Getter for property serviceName. + * @return Value of property serviceName. + */ + public QName getServiceName() { + return this.mServiceName; + } + + /** + * Setter for property serviceName. + * @param serviceName New value of property serviceName. + */ + protected void setServiceName(QName serviceName) { + this.mServiceName = serviceName; + } + + /** + * Getter for property endpointName. + * @return Value of property endpointName. + */ + public String getEndpointName() { + return this.mEndpointName; + } + + /** + * Setter for property endpointName. + * @param endpointName New value of property endpointName. + */ + protected void setEndpointName(String endpointName) { + this.mEndpointName = endpointName; + } + + } + /** + * This class implements the Provides interface + */ + public static class ProvidedService + extends AbstractService + implements Provides { + protected ProvidedService(QName interfaceQName, QName serviceName, String endpointName) { + this.setInterface(interfaceQName); + this.setServiceName(serviceName); + this.setEndpointName(endpointName); + } + + @Override + public String toString() { + return "Provides :" + + "${symbol_escape}n${symbol_escape}t interface-name= " + getInterface() + + "${symbol_escape}n${symbol_escape}t service-name= " + getServiceName() + + "${symbol_escape}n${symbol_escape}t endpont-name= " + getEndpointName(); + } + + protected static Provides createProvidedService(Element providesEl) throws Exception { + + String ifName = providesEl.getAttribute(SUDescriptorFactory.INTERFACE_TAG_NAME); + String serviceName = providesEl.getAttribute(SUDescriptorFactory.SERVICE_TAG_NAME); + String endpointName = providesEl.getAttribute(SUDescriptorFactory.ENDPOINT_TAG_NAME); + if ( ifName == null || serviceName == null || endpointName == null ) { + throw new Exception("Invalid provides element: missing " + SUDescriptorFactory.INTERFACE_TAG_NAME + + " or " + SUDescriptorFactory.SERVICE_TAG_NAME + " or " + SUDescriptorFactory.ENDPOINT_TAG_NAME ); + } + QName ifQName = RuntimeHelper.resolveAttrQName(ifName, providesEl); + QName serviceQName = RuntimeHelper.resolveAttrQName(serviceName, providesEl); + + return new ProvidedService(ifQName, serviceQName, endpointName); + } + } + /** + * This class implements the Consumes interface. + */ + public static class ConsumedService + extends AbstractService + implements Consumes { + private String mLinkType; + protected ConsumedService(QName interfaceQName, + QName serviceName, String endpointName, String linkType) { + this.setInterface(interfaceQName); + this.setServiceName(serviceName); + this.setEndpointName(endpointName); + this.mLinkType = linkType; + } + + /** + * Getter for property linkType. + * @return Value of property linkType. + */ + public String getLinkType() { + return this.mLinkType; + } + + @Override + public String toString() { + return "Cosumes :" + + "${symbol_escape}n${symbol_escape}t interface-name= " + getInterface() + + "${symbol_escape}n${symbol_escape}t service-name= " + getServiceName() + + "${symbol_escape}n${symbol_escape}t endpont-name= " + getEndpointName() + + "${symbol_escape}n${symbol_escape}t link-type= " + getLinkType(); + } + + protected static Consumes createConsumedService(Element consumesEl) throws Exception { + + String ifName = consumesEl.getAttribute(SUDescriptorFactory.INTERFACE_TAG_NAME); + String serviceName = consumesEl.getAttribute(SUDescriptorFactory.SERVICE_TAG_NAME); + String endpointName = consumesEl.getAttribute(SUDescriptorFactory.ENDPOINT_TAG_NAME); + String linkType = consumesEl.getAttribute(SUDescriptorFactory.LINK_TYPE_TAG_NAME); + if ( linkType == null || linkType.trim().length() == 0 ) { + linkType = STANDARD_LINK; + } + + if ( ifName == null ) { + throw new Exception("Invalid consumes element: missing " + + SUDescriptorFactory.INTERFACE_TAG_NAME ); + } + if ( serviceName == null || endpointName == null ) { + throw new Exception("Invalid consumes element: missing " + + SUDescriptorFactory.SERVICE_TAG_NAME + " or " + + SUDescriptorFactory.ENDPOINT_TAG_NAME ); + } + + QName ifQName = RuntimeHelper.resolveAttrQName(ifName, consumesEl); + QName serviceQName = null; + if ( serviceName != null ) { + serviceQName = RuntimeHelper.resolveAttrQName(serviceName, consumesEl); + } + if ( serviceQName != null && endpointName != null && linkType != null ) { + if (!(STANDARD_LINK.equals(linkType) || + SOFT_LINK.equals(linkType) || HARD_LINK.equals(linkType)) ) { + throw new Exception("Invalid consumes attribute value" + + SUDescriptorFactory.LINK_TYPE_TAG_NAME + "=" + linkType); + } + } + return new ConsumedService(ifQName, serviceQName, endpointName, linkType); + } + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java new file mode 100644 index 000000000..365633ddc --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java @@ -0,0 +1,464 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ServiceUnit.java + * + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Consumes; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Provides; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Service; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.management.DeploymentException; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; + +/** + * This is an abstract class that implements the service unit functionality in the component which + * processes the service unit artifacts and implement the actual service unit lifecycle functionality. + * The AbstractServiceUnitManager and its extended classes that implement the ServiceUnitManager + * functionality creates and maintains the reference to the concrete implementation of this class to + * invoke the functionality implemented by this class and its concrete implementation during the + * execution of the ServiceUnitMangers lifecycle methods by the jbi runtime. + *

+ * The main lifecycle methods of this class that will be called by the ServiceUnitManger implementation + * during the service unit deployment lifecycle are {@link ${symbol_pound}doload}, {@link ${symbol_pound}doDeploy}, {@link ${symbol_pound}doUndeploy}, + * {@link ${symbol_pound}doInit}, {@link ${symbol_pound}doStart}, {@link ${symbol_pound}doStop} and {@link ${symbol_pound}doShutdown} + *

+ * Service unit processing supported by this implementation is based on wsdl 1.1 deployments where the + * services provided and consumed in this service unit are described using wsdl 1.1 definitions. + *

+ * The main service unit artifacts that will be processed during deployment lifecycle of the service + * unit are 1.Service unit descriptor(jbi.xml) that describes the services provided and consumed by + * this service unit. 2.WSDL 1.1 document that describes the service definition 3.Component specific + * configurations related to services provided and consumed by this service unit. + *

+ * When the service unit is for Binding Component, the component specific configurations are read + * from the WSDL1.1 extensions defined in the WSDL document corresponding to the service provider + * or consumer deployed with this service unit. + *

+ * When the service unit is for Service Engine, the component specific configurations are read + * from the deployment artifacts such as xslt files and mapping files in the service unit zip file + * along with the WSDL document corresponding to the service provider or consumer deployed with this + * service unit. + * + * @see SUDescriptor + * @see Endpoint + * @see ProviderEndpoint + * @see ConsumerEndpoint + * @see WSDLProcessor + * @author chikkala + */ +public abstract class ServiceUnit { + /** Service Unit Name */ + private String mSUName; + /** Service Unit Root path passed by jbi runtime */ + private String mSURootPath; + /** service unit descriptor model unmarshalled from service unit jbi.xml */ + private SUDescriptor mSUDescriptor; + /** Map of Endpoint Key to ProviderEndpoint configurations in this service unit */ + private Map mProviderEndpointMap; + /** Map of Endpoint Key to ConsumerEndpoint configurations in this service unit */ + private Map mConsumerEndpointMap; + /** Map of Service Key to the WSDL Definition in this service unit */ + private Map mWSDLMap; + /** WSDLProcessor configured for this service unit to process wsdls in the service unit */ + private WSDLProcessor mWSDLProcessor; + /** + * + * @param suName + * @param suRootPath + */ + protected ServiceUnit(String suName, String suRootPath) { + this.mSUName = suName; + this.mSURootPath = suRootPath; + this.mSUDescriptor = null; + this.mWSDLMap = new HashMap(); + this.mProviderEndpointMap = new HashMap(); + this.mConsumerEndpointMap = new HashMap(); + } + /** returns service unit name + * @return service unit name + */ + public String getName() { + return this.mSUName; + } + /** returns service unit root path where the su artifacts are unzipped by the jbi runtime + * @return path to the service unit root directory. + */ + public String getSURootPath() { + return this.mSURootPath; + } + protected SUDescriptor createSUDescriptor() throws Exception { + File jbiXmlFile = new File(this.getSURootPath(), "META-INF/jbi.xml"); + String jbiXmlPath = jbiXmlFile.getAbsolutePath(); + return SUDescriptor.SUDescriptorFactory.getSUDescriptor(jbiXmlPath); + } + /** return the Service unit descriptor model that was read from the jbi.xml + * @return SUDescriptor + */ + public SUDescriptor getSUDescriptor() throws Exception { + if ( this.mSUDescriptor == null ) { + this.mSUDescriptor = createSUDescriptor(); + } + return this.mSUDescriptor; + } + public ProviderEndpoint getProviderEndpoint(String providerID) { + return this.mProviderEndpointMap.get(providerID); + } + public Collection getProviderEndpoints() { + return Collections.unmodifiableCollection(this.mProviderEndpointMap.values()); + } + public ConsumerEndpoint getConsumerEndpoint(String cosumerID) { + return this.mConsumerEndpointMap.get(cosumerID); + } + + public Collection getConsumerEndpoints() { + return Collections.unmodifiableCollection(this.mConsumerEndpointMap.values()); + } + /** + * @return Logger + */ + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** + * extended classes implement this method to create the su specific WSDLProcessor. for examples, + * a su supporting binding component may have wsdl extensions that it want to registry for reading + * the configurations from the wsdl file. + * @return WSDLProcessor + * @see com.sun.jbi.sample.component.common.wsdl.WSDLProcessor + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + */ + protected WSDLProcessor createWSDLProcessor() { + return new WSDLProcessor(this.getSURootPath()); + } + /** + * return the WSDLProcessor reference by creates if it is not yet created. + * @return WSDLProcessor. + */ + public final WSDLProcessor getWSDLProcessor() { + if ( this.mWSDLProcessor == null ) { + this.mWSDLProcessor = createWSDLProcessor(); + } + return this.mWSDLProcessor; + } + /** + * loads the service unit artifacts into the SU model. AbstractServiceUnitManager implementation + * calls this method during the during deploy and init lifecycle methods when the service unit + * object is newly created. + */ + public void doLoad() throws DeploymentException { + try { + SUDescriptor suDesc = getSUDescriptor(); // load jbi.xml + loadServiceDefinitions(); // check if the wsdls are valid for corresponding services. + loadOtherArtifacts(); // additional validations specific to component deployment features. + loadEndpoints(); // create endpoints + } catch ( DeploymentException jbiEx) { + throw jbiEx; + } catch (Exception ex) { + throw new DeploymentException(ex); + } + } + /** extended classes implement this method to perform the su specific deployment related tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doDeploy() throws DeploymentException { + // NOOP. doLoad has done it all. + this.getLogger().fine("ServiceUnit.doDeploy"); + } + /** extended classes implement this method to perform the su specific undeployment related tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doUndeploy() throws DeploymentException { + //NOOP + this.getLogger().fine("ServiceUnit.doUndeploy"); + } + /** extended classes implement this method to perform the su specific initialization tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doInit() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doInit"); + this.doInitEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on start in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doStart() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doStart"); + this.doActivateEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on stop in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doStop() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doStop"); + this.doDeactivateEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on shutdown in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doShutdown() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doShutdown"); + this.doCleanEndpoints(); + } + /** + * create the ProviderEndpoint that implement the service provider implementation specific to this su. + * @return ProviderEndpoint or null if the SU does not support the service provider access + */ + protected ProviderEndpoint createProviderEndpoint(Provides provides, Definition wsdlDef) { + return null; + } + /** + * create the ProviderEndpoint that implement the service consumer implementation specific to this su. + * @return ConsumerEndpoint or null if the SU does not support the service consumer access + */ + protected ConsumerEndpoint createConsumerEndpoint(Consumes consumes, Definition wsdlDef) { + return null; + } + /** + * generates the key based on the service to store the wsdl definitions . + */ + protected String getServiceKey(Service service) { + StringBuffer strBuff = new StringBuffer(); + strBuff.append(service.getInterface()).append("+"); + strBuff.append(service.getServiceName()).append("+"); + strBuff.append(service.getEndpointName()); + return strBuff.toString(); + } + /** + * looks up the wsdl definition loaded for this service. + */ + protected Definition findWSDLFor(Service service) throws WSDLException { + Definition wsdlDef = null; + String key = this.getServiceKey(service); + wsdlDef = this.mWSDLMap.get(key); + return wsdlDef; + } + + protected Definition findWSDL(List wsdlList, Service service, boolean ignoreEndpointLookup) { + Definition foundDef = null; + for ( Definition def : wsdlList ) { + if ( WSDLProcessor.isWSDLFor(def, service.getInterface(), service.getServiceName(), + ((ignoreEndpointLookup) ? null : service.getEndpointName()) ) ) { + foundDef = def; + break; + } + } + return foundDef; + } + /** + * loads the WSDL definitions corresponds to the service providers and consumers defined in the + * service unit descriptor. + */ + protected void loadServiceDefinitions() throws Exception { + + this.mWSDLMap = new HashMap(); + + WSDLProcessor wsdlProcessor = getWSDLProcessor(); + List wsdlList = wsdlProcessor.readWSDLs(this.getSURootPath()); + this.getLogger().fine("Number of wsdl definitions in service unit " + wsdlList.size()); + + List services = new ArrayList(); + services.addAll(this.getSUDescriptor().getProvidedServices()); + services.addAll(this.getSUDescriptor().getConsumedServices()); + + boolean isForBinding = this.getSUDescriptor().isForBindingComponent(); + this.getLogger().fine("Is this service unit for Binding? " + isForBinding); + + for ( Service service : services ) { + this.getLogger().fine("Looking up WSDL for service " + service); + boolean ignoreEndpointLookup = false; + boolean providerAtEngine = false; + if ( !isForBinding && service instanceof Provides ) { + ignoreEndpointLookup = true; + providerAtEngine = true; + } + Definition def = findWSDL(wsdlList, service, ignoreEndpointLookup); + if ( def == null ) { + throw new Exception("WSDL Definition not found for " + service); + } + this.mWSDLMap.put(getServiceKey(service), def); + if ( providerAtEngine ) { + // provider at engine. so add engine binding and endpoint to the wsdl + wsdlProcessor.create${artifactId}Binding(def, + service.getInterface(), service.getServiceName(), service.getEndpointName()); + } + } + } + /** extended classes implement this method to perform the su specific artifacts validation in + * this method implementation. + * @throws DeploymentException on error. + */ + protected void loadOtherArtifacts() throws DeploymentException { + // nothing to validate further. + this.getLogger().fine("ServiceUnit.loadOtherArtifacts"); + } + /** + * creates ProviderEndpoint and ConsumerEndpoint objects corresponding to the service providers + * and consumers described in the su descriptor ( jbi.xml ) + */ + protected void loadEndpoints() throws Exception { + + this.mProviderEndpointMap = new HashMap(); + this.mConsumerEndpointMap = new HashMap(); + + Collection providesList = this.getSUDescriptor().getProvidedServices(); + for ( Provides provides : providesList ) { + Definition wsdlDef = findWSDLFor(provides); + if ( wsdlDef == null ) { + throw new DeploymentException("WSDL Definitions not found for " + provides); + } + ProviderEndpoint provider = createProviderEndpoint(provides, wsdlDef); + this.mProviderEndpointMap.put(provider.getID(), provider); + } + + Collection consumesList = this.getSUDescriptor().getConsumedServices(); + for ( Consumes consumes : consumesList ) { + Definition wsdlDef = findWSDLFor(consumes); + if ( wsdlDef == null ) { + throw new DeploymentException("WSDL Definitions not found for " + consumes); + } + ConsumerEndpoint consumer = createConsumerEndpoint(consumes, wsdlDef); + this.mConsumerEndpointMap.put(consumer.getID(), consumer); + } + } + /** + * initializes the Endpoint objects created corresponding to the consumer and providers defined + * in the su descriptor + */ + protected void doInitEndpoints() throws DeploymentException { + // init endpoints. if any initialization fails, rollback the already inited endpoints + List initedEndpoints = new ArrayList(); + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getProviderEndpoints()); + allEndpoints.addAll(this.getConsumerEndpoints()); + + for ( Endpoint endpoint : allEndpoints ) { + try { + endpoint.init(); + initedEndpoints.add(endpoint); + } catch ( Exception initEx) { + doCleanEndpoints(initedEndpoints); + throw new DeploymentException(initEx); + } + } + + } + /** + * invokes activates method of all provider and consumer endpoint object in this su. if there is + * and error activating any one the endpoints, it deactivates the already activated ones and throws + * the error + */ + protected void doActivateEndpoints() throws DeploymentException { + // activate providers first and then consumers + List activatedEndpoints = new ArrayList(); + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getProviderEndpoints()); + allEndpoints.addAll(this.getConsumerEndpoints()); + + for ( Endpoint endpoint : allEndpoints ) { + try { + endpoint.activate(); + activatedEndpoints.add(endpoint); + } catch ( Exception actEx) { + doDeactivateEndpoints(activatedEndpoints); + throw new DeploymentException(actEx); + } + } + } + /** + * invokes deactivate method on the list of Endpoint objects passed to this method + */ + protected void doDeactivateEndpoints(List endpoints) { + for ( Endpoint endpoint : endpoints ) { + try { + endpoint.deactivate(); + } catch(Exception ex) { + // ignore the exception and log it. + this.getLogger().log(Level.FINE, ex.getMessage(), ex); + } + } + } + /** + * invokes deactivate method on the all consumer and provider endpoint objects + */ + protected void doDeactivateEndpoints() { + // deactivate consumers first and then the providers + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getConsumerEndpoints()); + allEndpoints.addAll(this.getProviderEndpoints()); + doDeactivateEndpoints(allEndpoints); + } + /** + * invokes clean method on the list of endpoint objects + */ + protected void doCleanEndpoints(List endpoints) { + for ( Endpoint endpoint : endpoints ) { + try { + endpoint.clean(); + } catch(Exception ex) { + // ignore the exception and log it. + this.getLogger().log(Level.FINE, ex.getMessage(), ex); + } + } + } + /** + * invokes clean method on the all consumer and provider endpoint objects in this su. + */ + protected void doCleanEndpoints() { + + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getConsumerEndpoints()); + allEndpoints.addAll(this.getProviderEndpoints()); + doCleanEndpoints(allEndpoints); + } + /** + * prints the service unit description + */ + protected final String printDetails() { + + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + + out.println("ServiceUnit Name : " + this.getName()); + out.println("ServiceUnit Root : " + this.getSURootPath()); + + SUDescriptor suDesc = null; + try { + suDesc = this.getSUDescriptor(); + for ( SUDescriptor.Consumes consumer : suDesc.getConsumedServices()) { + out.println(consumer); + } + for ( SUDescriptor.Provides provides : suDesc.getProvidedServices()) { + out.println(provides); + } + } catch (Exception ex) { + ex.printStackTrace(out); + } + return writer.getBuffer().toString(); + } + + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java new file mode 100644 index 000000000..67bbf5a45 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java @@ -0,0 +1,44 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractExtensibilityElement.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import javax.wsdl.extensions.ExtensibilityElement; +import javax.xml.namespace.QName; + +/** + * This is an abstract class which can be extended to create jwsdl (wsdl4j's) extension elements model to + * read/write the wsdl extension elements in wsdl 1.1 xml. + * + * @author chikkala + */ +public abstract class AbstractExtensibilityElement implements ExtensibilityElement, java.io.Serializable { + public static final long serialVersionUID = 1; + private QName mElementType; + private Boolean mRequired; + + /** Creates a new instance of AbstractExtensibilityElement */ + protected AbstractExtensibilityElement() { + } + + public void setElementType(QName elementType) { + this.mElementType = elementType; + } + + public QName getElementType() { + return this.mElementType; + } + + public void setRequired(Boolean required) { + this.mRequired = required; + } + + public Boolean getRequired() { + return this.mRequired; + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java new file mode 100644 index 000000000..5233aeee2 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java @@ -0,0 +1,45 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractExtensionRegistry.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.util.List; +import javax.wsdl.extensions.ExtensionRegistry; + +/** + * This is the abstract class used to add the wsdl extension serializers and deserializers to the + * wsdl extension registry configured to read/write wsdl extensions into a know java model. + * @see AbstractExtensionSerializer + * @see WSDLProcessor + * @author chikkala + */ +public abstract class AbstractExtensionRegistry extends ExtensionRegistry { + + /** Creates a new instance of AbstractSerializer + * it calls the createSerializers method to get the list of + * serializers and then call registerSerializer on each AbstractExtensionSerializer + * to register them with this registry. + * @see AbstractExtensionSerializer${symbol_pound}registerSerializer + */ + protected AbstractExtensionRegistry() { + super(); + List list = createSerializers(); + for (AbstractExtensionSerializer ser : list ) { + ser.registerSerializer(this); + } + // register ${artifactId} Binding serializers + AbstractExtensionSerializer seBindingSer = new SEBindingExt.SEBindingExtSerializer(); + seBindingSer.registerSerializer(this); + } + /** + * create wsdl extension serializers for each extension element to register with the extension + * registry. + * @return List of AbstractExtensionSerializer objects for serializing/deserializing the wsdl extensions. + * @see AbstractExtensionSerializer + */ + protected abstract List createSerializers(); +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java new file mode 100644 index 000000000..4ac1b37d6 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java @@ -0,0 +1,123 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractExtensionSerializer.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.io.PrintWriter; +import java.io.Serializable; +import java.util.Set; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionDeserializer; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.extensions.ExtensionSerializer; +import javax.xml.namespace.QName; +import org.w3c.dom.Attr; +import org.w3c.dom.Element; + +/** + * This class is an abstract class that should be extended to implements extension serializer and + * deserializer. This class implements the code required for registering the serializer and deserializer + * implemented by this class. THe AbstractExtensionRegistry class calls the ${symbol_pound}registerSerializer method + * to register the concrete implementation of this class with extension registry. + * @see AbstractExtensionRegistry + * @author chikkala + */ +public abstract class AbstractExtensionSerializer + implements ExtensionSerializer, ExtensionDeserializer, Serializable { + + public static final long serialVersionUID = 1; + + private Class mParentType; + private Class mExtensionType; + private QName mElementType; + + /** Creates a new instance of AbstractSerializer */ + public AbstractExtensionSerializer(Class parentType, QName elementType, Class extensionType) { + this.mParentType = parentType; + this.mElementType = elementType; + this.mExtensionType = extensionType; + } + + public Class getParentType() { + return this.mParentType; + } + public QName getElementType() { + return this.mElementType; + } + public Class getExtensionType() { + return this.mExtensionType; + } + + public void registerSerializer(ExtensionRegistry extReg) { + extReg.registerSerializer(this.mParentType, this.mElementType, this); + extReg.registerDeserializer(this.mParentType, this.mElementType, this); + extReg.mapExtensionTypes(this.mParentType, this.mElementType, this.mExtensionType); + } + + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg ) throws WSDLException { + // DO NOTHING. Binding component runtime does not need to serialize the wsdl extensions. + } + + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + return null; + } + + public static String getAttribute(Element el, String attrName) { + String attrValue = null; + Attr attr = el.getAttributeNode(attrName); + if ( attr != null ) { + attrValue = attr.getValue(); + } + return attrValue; + } + + protected String getNamespacePrefix(Definition def, String namespaceURI, String defPrefix) { + String prefix = null; + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + Set keySet = def.getNamespaces().keySet(); + String newPrefix = "ns"; + if ( defPrefix != null && defPrefix.trim().length() > 0 ){ + newPrefix = defPrefix; + } + prefix = newPrefix; + for ( int i=0; i < Integer.MAX_VALUE; ++i) { + if (!keySet.contains(prefix)) { + break; + } else { + prefix = newPrefix + i; + } + } + } + return prefix; + } + /** + * @return the name with the prefix defined for the namespaceURI in the wsdl definition. + * @throws WSDLException if the prefix not found in the wsdl definition. note that the + * default prefix is an empty string. + */ + protected String getQualifiedName(Definition def, + String namespaceURI, String localName) throws WSDLException { + String prefix = null; + if (namespaceURI != null && !namespaceURI.equals("")) { + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + throw new WSDLException(WSDLException.OTHER_ERROR, + "Can not find prefix in WSDL Definition for " + namespaceURI); + } + } + if ( prefix != null && !prefix.equals("")) { + return prefix + ":" + localName; + } else { + return localName; + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java new file mode 100644 index 000000000..b10800550 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java @@ -0,0 +1,229 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractNormalizer.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.util.ArrayList; +import java.util.List; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Part; +import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.dom.DOMSource; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * This is an abstract class that implements most of the functionality to normalize the binding protocol + * specific concrete message to jbi wrapper and and denormalize jbi wrapper to the concrete binding + * protocol specific message. + *

+ * The extended classes specific to particular binding protocol will be used when a jbi binding + * component is sending and receiving messages from the external service providers and consumers using + * a particular binding protocol known to this class. Extended implementation of this class should make + * use of the helper methods in this class in normalizing and denormalizing the messages. + * @see JMXBindingNormalizer + * @author chikkala + */ +public abstract class AbstractNormalizer { + + public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/"; + /** wsdl definition to use when normalizing and denormalizing */ + private Definition mWSDL; + /** Binding definition to use when normalizing and denormalizing */ + private Binding mBinding; + + private AbstractNormalizer() {} + /** Creates a new instance of JMXBCNormalizer */ + public AbstractNormalizer(Definition wsdl, Binding binding) { + this.mWSDL = wsdl; + this.mBinding = binding; + } + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete mssage of a particular binding protocol. + */ + public abstract void normalizeInput(Operation operation, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete message of a particular binding protocol. + */ + public abstract void normalizeOutput(Operation operation, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete message of a particular binding protocol. + */ + public abstract void normalizeFault(Operation operation, String faultName, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * denormalize the normalized message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be de-normalized. + * @param normMsg NormalizedMessage which should be used to create de-normalized message. + */ + public abstract DOMSource denormalizeInput(Operation operation, NormalizedMessage normMsg) + throws MessagingException; + /** + * denormalize the normalized message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be denormalized. + * @param normMsg NormalizedMessage which should be used to create denormalized message. + */ + public abstract DOMSource denormalizeOutput(Operation operation, NormalizedMessage normMsg) + throws MessagingException; + + /** + * denormalized the normalized fault message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be denormalized. + * @param normMsg NormalizedMessage which should be used to create denormalized message. + */ + public abstract DOMSource denormalizeFault(Operation operation, String faultName, NormalizedMessage normMsg) + throws MessagingException; + /** + * @return the wsdl definition to use in normalizing and denormalizing the message + */ + protected Definition getWSDL() { + return this.mWSDL; + } + /** + * @return the wsdl binding definition to use in normalizing and denormalizing the message + */ + protected Binding getBinding() { + return this.mBinding; + } + /** + * create and add message parts to the jbiWrapper according to the abstract message model. This + * method assumes that the each element in the msgParts list passed to it is mapped to the part + * of the abstract wsdl message and uses the type or element attribute of the abstract message to + * determine whether the element is actual part element or a wrapped part type. + * Use this method in normalizing the concrete protocol specific message to jbi wrapper message. + * @param jbiWrapper object that holds the jbi wrapper information. + * @param wsdlMsg abstract message from the wsdl definition + * @param msgParts actual message parts from the concrete message + */ + protected void addMessagePartsToJBIWrapper(WSDL11JBIWrapper jbiWrapper, Message wsdlMsg, List msgParts) throws MessagingException { + List wsdlParts = wsdlMsg.getOrderedParts(null); + for ( int i=0; i < wsdlParts.size(); ++i ) { + Part wsdlPart = (Part) wsdlParts.get(i); + if ( i >= msgParts.size() ) { + throw new MessagingException("missing message content for part " + wsdlPart.getName()); + } + Element msgPart = msgParts.get(i); + if ( wsdlPart.getElementName() != null ) { + jbiWrapper.appendPart(msgPart); + } else { + // it is type. + // check the element name is same as part + if ( !wsdlPart.getName().equals(msgPart.getLocalName()) ) { + throw new MessagingException("mismatched message content for part " + wsdlPart.getName()); + } + if ( !wsdlMsg.getQName().getNamespaceURI().equals(msgPart.getNamespaceURI()) ) { + throw new MessagingException("mismatched message content namespace for part " + wsdlPart.getName()); + } + // check the content is text or element. + List partContent = getChildElements(msgPart); + if ( partContent.size() > 0 ) { + // add content as part elements + jbiWrapper.appendPart(partContent); + } else { + // add the content as text + jbiWrapper.appendPart(msgPart.getTextContent()); + } + } + } + } + /** + * extracts the message parts from the jbiWrapper according to the abstract wsdl message + * definition passed to it. Use this method in denormalizing the jbi wrapper message into the + * binding protocol specific concrete message. + * @param jbiWrapper jbi wrapper object that contains message parts and the message type information. + * @param wsdlMsg abstract wsdl message definition to use in constructing the part elements. + */ + protected List getMessagePartsFromJBIWrapper(WSDL11JBIWrapper jbiWrapper, Message wsdlMsg) + throws MessagingException, ParserConfigurationException { + + List msgParts = new ArrayList(); + int jbiPartCount = jbiWrapper.getPartCount(); + List wsdlParts = wsdlMsg.getOrderedParts(null); + QName msgType = jbiWrapper.getType(); + if (!wsdlMsg.getQName().getNamespaceURI().equals(msgType.getNamespaceURI())) { + throw new MessagingException("Namespace mismatch between jbi wrapper message type and wsdl message"); + } + Document newDoc = jbiWrapper.getDocumentBuilder().newDocument(); + for ( int i=0; i < wsdlParts.size(); ++i ) { + Part wsdlPart = (Part) wsdlParts.get(i); + if ( i >= jbiPartCount ) { + throw new MessagingException("missing message content for part " + wsdlPart.getName()); + } + if ( wsdlPart.getElementName() != null ) { + msgParts.add(jbiWrapper.getPartAsElement(i)); + } else { + // it is type. create a new element for a typed part + // check the element name is same as part + String prefix = msgType.getPrefix(); + String nsURI = msgType.getNamespaceURI(); + String localName = wsdlPart.getName(); + Element partEl = newDoc.createElementNS(nsURI, prefix + ":" + localName); + partEl.setAttributeNS(XMLNS_NS, "xmlns:"+prefix, nsURI); + NodeList partContent = jbiWrapper.getPart(i); + appendChildren(partEl, partContent, newDoc, true); + msgParts.add(partEl); + } + } + return msgParts; + } + /** + * utility method that can append the nodeList passed to it to the element children. + * @param el element node to which the nodeList should be appended + * @param doc the document object that should be used to import the nodeList + * @param importNode true if the nodeList should be imported while appending the nodeList to the + * element children. false if no import is necessary. + */ + protected void appendChildren(Element el, NodeList nodeList, Document doc, boolean importNode) { + + for ( int pIdx = 0; pIdx < nodeList.getLength(); ++pIdx) { + Node node = nodeList.item(pIdx); + if ( importNode ) { + node = doc.importNode(node, true); + } + el.appendChild(node); + } + } + /** + * @param el element from which to extract the child elements + * @return List list of child Element nodes. + */ + protected List getChildElements(Element el) { + List list = new ArrayList(); + NodeList nodeList = el.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if (!(node instanceof Element) ){ + continue; + } + list.add((Element)node); + } + return list; + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java new file mode 100644 index 000000000..30663d867 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java @@ -0,0 +1,99 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * SEBindingExt.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.io.PrintWriter; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation classes implement wsdl 1.1 extension model for the + * jbi service engine binding that is defined in jsr 208(sec. 5.5.6.1). to read/write concrete binding + * element in the wsdl definition for the service endpoint binding provided by the service engine. + * The wsdl definition with this binding information can be used in providing the service provider + * metadata returned by the service engine in Component.getServiceDescription. + *

+ * AbstractExtensionRegistry by default include this extension serializers in the + * registry to read/write this service engine binding type in the wsdl definition. + *

+ * During a service unit deployment/initialization in the service engine, the deployed wsdl definition + * is loaded and modified to provide this binding for the service provided by the engine. + * + * @see WSDLProcessor${symbol_pound}create${artifactId}Binding + * @see AbstractExtensionRegistry + * @see com.sun.jbi.sample.component.common.deployment.ServiceUnit${symbol_pound}loadServiceDefinitions + * @author chikkala + */ +public interface SEBindingExt extends ExtensibilityElement, java.io.Serializable { + + public static final String NS_URI = "http://java.sun.com/xml/ns/jbi/binding/service+engine"; + public static final String NS_DEF_PREFIX = "jbise"; + /** Element names. */ + public static final String EL_BINDING_EXT = "binding"; + /**Qualified element names.*/ + public static final QName QN_BINDING_EXT = new QName(NS_URI, EL_BINDING_EXT); + + public static class SEBindingExtImpl extends AbstractExtensibilityElement implements SEBindingExt { + + public SEBindingExtImpl() { + setElementType(QN_BINDING_EXT); + } + @Override + public String toString() { + StringBuffer buff = new StringBuffer(); + buff.append("<"+NS_DEF_PREFIX+":"+EL_BINDING_EXT); + buff.append("/>"); + return buff.toString(); + } + /** + * creates and adds the jbi service engine binding extensibility element to the wsdl definition + * under specified binding definition. + */ + public static SEBindingExtImpl addExtensibilityElement(Definition wsdlDef, Binding binding) { + SEBindingExtImpl bindingExt = new SEBindingExt.SEBindingExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, binding, bindingExt, SEBindingExt.NS_DEF_PREFIX); + return bindingExt; + } + } + /** + * serializer and descrializer implementation for the binding extension element. + */ + public static class SEBindingExtSerializer extends AbstractExtensionSerializer { + + public SEBindingExtSerializer() { + super(Binding.class, QN_BINDING_EXT, SEBindingExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + SEBindingExt extObj = (SEBindingExt)extReg.createExtension(parentType, elementType); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg ) throws WSDLException { + + String elName = getQualifiedName(def, NS_URI, EL_BINDING_EXT); + + SEBindingExt extObj = (SEBindingExt)extension; + + StringBuffer buff = new StringBuffer(); + buff.append("<" + elName ); + buff.append("/>"); + pw.println(buff.toString()); + } + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java new file mode 100644 index 000000000..92606104d --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java @@ -0,0 +1,471 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * WSDL11JBIWrapper.java + * + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.dom.DOMSource; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +/** + * This class wraps the wsdl11 messages to the jbi wrapper message suitable for + * processing in the wsdl2.0 model of the normalized message in jbi as defined in jsr208 like + * + * + * + * + * + * + * + * + * + * + * @author chikkala + */ +public class WSDL11JBIWrapper { + + public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/"; + public static final String WRAPPER_NAMESPACE = "http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper"; + public static final String DEF_NS_PREFIX = "jbiwrp"; + public static final String DEF_MESSAGE_NS_PREFIX = "msgns"; + public static final String JBI_MESSAGE_EL = "message"; + public static final String JBI_PART_EL = "part"; + public static final String VERSION_ATTR = "version"; + public static final String VERSION_ATTR_VALUE = "1.0"; + public static final String TYPE_ATTR = "type"; + public static final String NAME_ATTR = "name"; + + private static DocumentBuilder sDocBuilder = null; + /** qname of message attribute from wsdl:input, wsdl:output or wsdl:fault */ + private QName mType; + /** optional name attribute from wsdl:input, wsdl:output or wsdl:fault */ + private String mName; + /** each parts contents as node list */ + List mPartConentList = new ArrayList(); + + /** Creates a new instance of WSDL11JBIWrapper */ + public WSDL11JBIWrapper() { + } + /** creates the namespace aware document builder. extended classes can override this method + * to return the doc builder created else where. + */ + protected DocumentBuilder createDocumentBuilder() throws ParserConfigurationException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + return factory.newDocumentBuilder(); + } + /** return the document builder + * @return DocumentBuilder + */ + public final DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { + if ( WSDL11JBIWrapper.sDocBuilder == null ) { + WSDL11JBIWrapper.sDocBuilder = createDocumentBuilder(); + } + return WSDL11JBIWrapper.sDocBuilder; + } + /** + * @return type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + */ + public QName getType() { + return this.mType; + } + /** + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + */ + public void setType(QName type) { + this.mType = type; + } + /** @return name attribute from wsdl:input, wsdl:output or wsdl:fault. or null if not set. */ + public String getName() { + return this.mName; + } + /** + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault. can be null. + */ + public void setName(String name) { + this.mName = name; + } + /** + * appends part content as node list + */ + public void appendPart(NodeList partContent) { + this.mPartConentList.add(partContent); + } + /** + * append part content from the List of nodes + */ + public void appendPart(List partContent) { + this.mPartConentList.add(new NodeListImpl(partContent)); + } + /** + * append part content as element + */ + public void appendPart(Element partContent) { + this.mPartConentList.add(new NodeListImpl(partContent)); + } + /** + * append part content from DOMSource + */ + public void appendPart(DOMSource partContent) { + Element partConentEl = getElement(partContent.getNode()); + this.mPartConentList.add(new NodeListImpl(partConentEl)); + } + /** + * append part content as text node. + */ + public void appendPart(String partContent) { + Text textContent = null; + try { + textContent = this.getDocumentBuilder().newDocument().createTextNode(partContent); + } catch (ParserConfigurationException ex) { + ex.printStackTrace(); + } + if ( textContent != null ) { + this.mPartConentList.add(new NodeListImpl(textContent)); + } + } + /** + * append list of part contents each is a NodeList to the parts + */ + public void appendParts(List partContentList) { + this.mPartConentList.addAll(partContentList); + } + /** + * returned the ordered list of part contents. + */ + public List getParts() { + return Collections.unmodifiableList(this.mPartConentList); + } + /** + * return the number of parts + */ + public int getPartCount() { + return this.mPartConentList.size(); + } + /** + * return the part content at a particular index as NodeList. + */ + public NodeList getPart(int idx) { + return this.mPartConentList.get(idx); + } + /** + * return part context at a particular index as text + */ + public String getPartAsText(int idx) { + NodeList partNodes = getPart(idx); + Document doc; + try { + doc = this.getDocumentBuilder().newDocument(); + Element el = doc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_PART_EL); + for ( int i=0; i < partNodes.getLength(); ++i) { + el.appendChild(partNodes.item(i)); + } + return el.getTextContent(); + } catch (ParserConfigurationException ex) { + return null; + } + } + /** + * return part context at a particular index as Element + */ + public Element getPartAsElement(int idx) { + Element contentEl = null; + NodeList partNodes = getPart(idx); + for ( int i=0; i < partNodes.getLength(); ++i) { + Node node = partNodes.item(i); + if ( node instanceof Element) { + contentEl = (Element)node; + break; + } + } + return contentEl; + } + /** + * creates Document from this wrapper object. Before calling this method, + * the type, name (optional) and parts contents should be set. + * @return Document containing the wsdl 11 wrapper xml + */ + public Document toDocument() throws ParserConfigurationException { + + Document wrapperDoc = getDocumentBuilder().newDocument(); + Element jbiMessage = wrapperDoc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_MESSAGE_EL); + jbiMessage.setAttribute(VERSION_ATTR, VERSION_ATTR_VALUE); + wrapperDoc.appendChild(jbiMessage); + + QName type = this.getType(); + if ( type == null ) { + type = new QName("", "", DEF_MESSAGE_NS_PREFIX); + } + // set the jbiMessage attributes + String prefix = type.getPrefix(); + if (prefix == null || prefix.length() == 0) { + prefix = DEF_MESSAGE_NS_PREFIX; + } + jbiMessage.setAttribute(TYPE_ATTR, prefix + ":" + type.getLocalPart()); + jbiMessage.setAttributeNS( XMLNS_NS, "xmlns:" + prefix, type.getNamespaceURI()); + + String name = this.getName(); + if (name != null && name.trim().length() > 0 ) { + jbiMessage.setAttribute(NAME_ATTR, name); + } + + List partContentList = this.getParts(); + for ( NodeList nodeList : partContentList ) { + // set jbi part message + Element jbiPart = wrapperDoc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_PART_EL); + jbiMessage.appendChild(jbiPart); + for ( int i =0; i < nodeList.getLength(); ++i ) { + Node importedMsgNode = wrapperDoc.importNode(nodeList.item(i), true); + jbiPart.appendChild(importedMsgNode); + } + } + + return wrapperDoc; + + } + /** + * creates DOMSource from this wrapper object. Before calling this method, + * the type, name (optional) and parts contents should be set. + * @return DOMSource containing the wsdl 11 wrapper xml + */ + public DOMSource toDOMSource() throws ParserConfigurationException { + DOMSource wrappedSource = new DOMSource(); + wrappedSource.setNode(toDocument()); + return wrappedSource; + } + /** + * return Element node from a document node or non document. Use to extract + * the message root element. + * @root node from which the Element node will be extracted. + * @return Element node. + */ + public static Element getElement(Node root) { + Element msgEl = null; + if ( root instanceof Document) { + msgEl = ((Document)root).getDocumentElement(); + } else if (root instanceof Element) { + msgEl = (Element)root; + } else { + NodeList nodeList = root.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if ( node instanceof Element ) { + msgEl = (Element) node; + break; + } + } + } + return msgEl; + } + /** + * creates wrapper object from the DOMSource that has wsdl 11 wrapper xml. + * @param wrappedMsg wsdl 11 wrapper xml as DOMSource + * @return WSDL11JBIWrapper representing the wrapper xml. + */ + public static WSDL11JBIWrapper sourceToWrapper(DOMSource wrappedMsg) { + Element jbiMessage = getElement(wrappedMsg.getNode()); + if ( jbiMessage == null ) { + return null; + } + String nsURI = jbiMessage.getNamespaceURI(); + String tagName = jbiMessage.getLocalName(); + if (!WRAPPER_NAMESPACE.equals(nsURI) || !JBI_MESSAGE_EL.equals(tagName)) { + return null; + } + String name = jbiMessage.getAttribute(NAME_ATTR); + String typeQN = jbiMessage.getAttribute(TYPE_ATTR); + String typePrefix = ""; + String typeName = ""; + if ( typeQN != null && typeQN.trim().length() > 0 ) { + int idx = typeQN.indexOf(':'); + if ( idx >= 0 ) { + typePrefix = typeQN.substring(0, idx); + if ( typeQN.length() > idx ) { + typeName = typeQN.substring(idx+1); + } + } else { + typePrefix = ""; + typeName = typeQN; + } + } + String typeURI = jbiMessage.getAttribute("xmlns:" + typePrefix); + QName typeQName = new QName(typeURI, typeName, typePrefix); + + WSDL11JBIWrapper wrapper = new WSDL11JBIWrapper(); + wrapper.setName(name); + wrapper.setType(typeQName); + NodeList jbiPartList = jbiMessage.getElementsByTagNameNS(WRAPPER_NAMESPACE, JBI_PART_EL); + for ( int i=0; i < jbiPartList.getLength(); ++i) { + Node jbiPart = jbiPartList.item(i); + wrapper.appendPart(jbiPart.getChildNodes()); + } + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object and sets the type and name of the object + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name ) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = new WSDL11JBIWrapper(); + wrapper.setName(name); + wrapper.setType(type); + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object. useful when the message has one part and the + * part content has multiple child element. + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @param partContent part content as node list + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name, NodeList partContent) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name); + wrapper.appendPart(partContent); + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object. useful when the message has one part and the + * part content is a single element + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @param partContent part content as node list + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name, Element msgEl) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name, new WSDL11JBIWrapper.NodeListImpl(msgEl)); + return wrapper; + } + + public static WSDL11JBIWrapper createWrapper(QName type, String name, DOMSource inputSource) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name); + Node msgNode = getElement(inputSource.getNode()); + NodeList nodeList = new WSDL11JBIWrapper.NodeListImpl(msgNode); + wrapper.appendPart(nodeList); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations input element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createInputWrapper(Operation operation) throws ParserConfigurationException { + QName type = null; + String name = null; + + Input input = operation.getInput(); + if ( input == null ) { + return null; + } + name = input.getName(); + Message wsdlMsg = input.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations output element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createOutputWrapper(Operation operation) throws ParserConfigurationException { + QName type = null; + String name = null; + + Output output = operation.getOutput(); + if ( output == null) { + return null; + } + name = output.getName(); + Message wsdlMsg = output.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations output element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @param faultName fault name, can be null to look for the fault with no name. + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createFaultWrapper(Operation operation, String faultName) throws ParserConfigurationException { + QName type = null; + String name = null; + @SuppressWarnings("unchecked") + Map faultMap = operation.getFaults(); + Fault fault = faultMap.get(faultName); + + if ( fault == null ) { + return null; + } + name = fault.getName(); + Message wsdlMsg = fault.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * NodeList implementation. + */ + public static class NodeListImpl extends ArrayList implements NodeList { + + public NodeListImpl() { + super(); + } + + public NodeListImpl(Node aNode) { + super(); + if (aNode != null) { + this.add(aNode); + } + } + + public NodeListImpl(List nodes) { + if (nodes != null) { + this.addAll(nodes); + } + } + + public int getLength() { + return this.size(); + } + + public Node item(int idx) { + return this.get(idx); + } + + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java new file mode 100644 index 000000000..6e0c0993f --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java @@ -0,0 +1,419 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * WSDLProcessor.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ElementExtensible; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.wsdl.xml.WSDLWriter; +import javax.xml.namespace.QName; + +/** + * This class is used to configure jwsdl(wsdl4j) to read and process wsdl documents with wsdl extensions. + * It provides set of helper methods to read and process the wsdl definitions from files with .wsdl + * extension from a specified directory. + *

+ * A Binding Component that is processing the wsdl extensions for its deployment configuration would + * extend this class and provide the required ExtensionRegistry that will have the extension serializers + * and deserializers configured to read/write the extensions from/to the java model. + *

+ * A Service Engine that is processing the wsdl during deployment can directly use this class + * to process the wsdl as the default implementation returned by this class configures the wsdl extension + * registry to read/write the service engine binding extensions. + * + * @see AbstractExtensionRegistry + * @see SEBindingExt + * @author chikkala + */ +public class WSDLProcessor { + + private String mXmlCatalogPath = "xml-catalog.xml"; + private String mWsdlDirPath = ""; + private WSDLReader mReader; + + /** Creates a new instance of WSDLProcessor + */ + public WSDLProcessor(String wsdlDir) { + this(wsdlDir, null); + } + /** Creates a new instance of WSDLProcessor + */ + public WSDLProcessor(String wsdlDir, String xmlCatPath) { + if ( wsdlDir != null ) { + this.mWsdlDirPath = wsdlDir; + } + if ( xmlCatPath != null ) { + this.mXmlCatalogPath = xmlCatPath; + } + } + /** @return directory path from which this class reads the wsdl files with .wsdl as file extension. */ + public String getWSDLDirectory() { + return this.mWsdlDirPath; + } + /** path to the xml catalog file in the service unit which can be used for Catalog-based entity + * and URI resolution. + */ + public String getXmlCatelogPath() { + return this.mXmlCatalogPath; + } + /** wsdl extension registry required for processing the wsdl extensions in the wsdl definition to + * java model. Binding component that is processing the wsdl extensions for its deployment + * configuration would provide the required ExtensionRegistry that will have the extension serializers + * and deserializers configured to read/write the extensions from/to the java model. + * @return ExtensionSerializer + * @see AbstractExtensionSerializer + */ + protected ExtensionRegistry getExtensionRegistry() { + return new AbstractExtensionRegistry() { + protected List createSerializers() { + return new ArrayList(); + } + }; + } + /** + * @return the WSDLReader configured with extension registry to process the wsdl extensions. + */ + public final WSDLReader getWSDLReader() throws WSDLException { + if ( this.mReader == null ) { + WSDLFactory factory = WSDLFactory.newInstance(); + this.mReader = factory.newWSDLReader(); + // reader.setFeature("javax.wsdl.verbose", true); + // reader.setFeature("javax.wsdl.importDocuments", true); + this.mReader.setExtensionRegistry(getExtensionRegistry()); + } + return this.mReader; + } + /** + * reads the wsdl file and returns the wsdl definition jwsdl model. + * @param wsldFilePath relative path to wsdl file from the the root wsdl directory returns from + * ${symbol_pound}getWSDLDirectory in the service unit or or absolute path . + * @return Definition + */ + public Definition readWSDL(String wsdlFilePath) throws WSDLException { + File wsdlFile = new File(wsdlFilePath); + if ( !wsdlFile.isAbsolute() ) { + wsdlFile = new File(this.mWsdlDirPath, wsdlFilePath); + } + return getWSDLReader().readWSDL(wsdlFile.getAbsolutePath()); + } + /** + * reads the files with .wsdl file extension in a directory. If the directory should + * be searched recursively, it searches this directory, all child directories of this + * directory and then to their child directories recursively. + * @param dir directory file to search for .wsdl files + * @param rec if set to true, it recursively searches the directory. if set to false, only + * this directory is searched. + * @return List of Files with .wsdl extension. + */ + public List listWSDLFiles(File dir, final boolean rec) throws IOException { + if ( dir == null || !dir.isDirectory()) { + throw new IOException(dir + " is not a directory for looking up wsdl files"); + } + List wsdlList = new ArrayList(); + File[] files = dir.listFiles(new FileFilter() { + public boolean accept(File pathname) { + if ( rec && pathname.isDirectory()) { + return true; + } else { + String name = pathname.getName(); + int idx = name.lastIndexOf('.'); + if ( idx < 0 ) { + return false; + } + String ext = name.substring(idx); + return ".wsdl".equalsIgnoreCase(ext); + } + } + }); + for ( File file : files ) { + if ( rec && file.isDirectory()) { + List wsdlFiles = listWSDLFiles(file, rec); + wsdlList.addAll(wsdlFiles); + } else { + wsdlList.add(file); + } + } + return wsdlList; + } + /** + * reads the files with .wsdl file extension in a directory fromDir and return the list of + * wsdl definitions corresponding to them. + * @param fromDir path to the directory relative to the root wsdl directory returns from + * ${symbol_pound}getWSDLDirectory or the absolute path to the directory. + */ + public List readWSDLs(String fromDir) throws WSDLException { + if ( fromDir == null ) { fromDir = ""; } + File wsdlDir = new File(fromDir); + if (!wsdlDir.isAbsolute()) { + wsdlDir = new File(this.mWsdlDirPath, fromDir); + } + + List wsdlFiles = new ArrayList(); + try { + wsdlFiles = listWSDLFiles(wsdlDir, true); + } catch (IOException ioEx) { + throw new WSDLException("WSDLFileReadError", ioEx.getMessage(),ioEx); + } + + List wsdlPaths = new ArrayList(); + for ( File wsdlFile : wsdlFiles) { + wsdlPaths.add(wsdlFile.getAbsolutePath()); + } + Collections.sort(wsdlPaths); + + List wsdlList = new ArrayList(); + for ( String wsdlPath : wsdlPaths ) { + Definition wsdlDef = readWSDL(wsdlPath); + wsdlList.add(wsdlDef); + } + return wsdlList; + } + /** + * finds PortType using port type ( interface ) qname. + */ + public static PortType findInterface(Definition wsdlDef, QName interfaceName) { + return wsdlDef.getPortType(interfaceName); + } + /** finds the Service using service qname */ + public static Service findService(Definition wsdlDef, QName serviceName) { + return wsdlDef.getService(serviceName); + } + /** finds the wsdl port using service qname and endpoint name */ + public static Port findServiceEndpoint(Definition wsdlDef, QName serviceName, String endpointName) { + Service service = null; + Port port = null; + service = findService(wsdlDef, serviceName); + if ( service != null ) { + port = service.getPort(endpointName); + } + return port; + } + /** + * finds the binding definition to which the service with serviceName and endpointName was bound. + */ + public static Binding findServiceBinding(Definition wsdlDef, QName serviceName, String endpointName) { + Binding binding = null; + Port port = findServiceEndpoint(wsdlDef, serviceName, endpointName); + if ( port != null ) { + binding = port.getBinding(); + } + return binding; + } + /** + * finds the binding definition using the interface(portType) qname with a + */ + public static Binding findInterfaceBinding(Definition wsdlDef, + QName interfaceQName, QName extQName) { + Map bindingMap = wsdlDef.getBindings(); + @SuppressWarnings("unchecked") + Collection bindings = bindingMap.values(); + for ( Binding binding : bindings ) { + if ( binding.getPortType().getQName().equals(interfaceQName)) { + return binding; + } + } + return null; + } + + /** + * find the wsdl4j operation corresponds to the interface+operation. + * @param wsdlDef wsdl definition + * @param portTypeQName portType QName + * @param opName operation name. if null, first operation in the portType + * is returned. + * @return Operation corresponding to the portType+opName + */ + public static Operation findOperation(Definition wsdlDef, + QName portTypeQName, String opName) { + Operation operation = null; + PortType portType = wsdlDef.getPortType(portTypeQName); + if ( portType != null ) { + if ( opName != null ) { + operation = portType.getOperation(opName, null, null); + } else { + @SuppressWarnings("unchecked") + List list = portType.getOperations(); + if ( list != null && list.size() > 0 ) { + operation = list.get(0); + } + } + } + return operation; + } + /** + * verifies whether the wsdl definition contains the specified service descriptions or not. Used + * to locate the wsdl definition for the services describes in service unit deployment + * descriptor(jbi.xm). + * @param interfaceName portType qname to find in the definition. can be null if you are trying to + * find only service endpoint description. + * @param serviceName qname for the service to find in this wsdl. can be null if + * you are trying to find only portType (abstract service) description. + * @param endpointName port name to find in the service definition. null if only + * service with any port should be looked up. + * + * @return true if the wsdl definition contains the specified service description. + */ + public static boolean isWSDLFor(Definition wsdlDef, + QName interfaceName, QName serviceName, String endpointName) { + PortType portType = null; + Service service = null; + Port port = null; + if ( interfaceName != null ) { + portType = findInterface(wsdlDef, interfaceName); + } + + if ( serviceName != null ) { + service = findService(wsdlDef, serviceName); + } + + if ( endpointName != null && service != null ) { + port = service.getPort(endpointName); + } + + boolean isWSDL = true; + + if ( (interfaceName != null && portType == null) || + ( serviceName != null && service == null ) || + ( endpointName != null && (service == null || port == null)) ) { + isWSDL = false; + } + + return isWSDL; + } + /** + * creates a binding definition that contains a service engine binding elements in the specified + * wsdl definition for a portType. It will try to find/create the binding element with interface + * local name with a "_JBISEBinding" suffix and add service engine binding element to it if it + * is not present. + * @param wsdl wsdl definition + * @param interfaceName portType qname to which the binding is created. + * @return a Binding contains service engine binding that is created for the portType. + */ + public Binding create${artifactId}Binding(Definition wsdl, QName interfaceName) { + QName bindingQName = new QName(wsdl.getQName().getNamespaceURI(), + interfaceName.getLocalPart() + "_JBISEBinding"); + Binding binding = wsdl.getBinding(bindingQName); + if ( binding == null ) { + binding = wsdl.createBinding(); + binding.setQName(bindingQName); + binding.setPortType(wsdl.getPortType(interfaceName)); + binding.setUndefined(false); + + ExtensibilityElement bindingExt = + SEBindingExt.SEBindingExtImpl.addExtensibilityElement(wsdl, binding); + + wsdl.addBinding(binding); + } + return binding; + } + /** + * creates port and binding elements that provide the the service engine binding for a service. + * @param wsdl wsdl definition + * @param interfaceName portType qname to which the binding is created. + * @param serviceName service under which the port definition bound to the service engine binding + * should be created. + * @param endpointName port name. + * @return a Binding contains service engine binding that is created for the portType. + */ + public Binding create${artifactId}Binding(Definition wsdl, QName interfaceName, QName serviceName, String endpointName ) { + Binding binding = null; + Service service = findService(wsdl, serviceName); + if ( service == null ) { + return null; + } + Port port = service.getPort(endpointName); + if ( port != null ) { + binding = port.getBinding(); + } else { + // create port + port = wsdl.createPort(); + port.setName(endpointName); + binding = create${artifactId}Binding(wsdl, interfaceName); + port.setBinding(binding); + service.addPort(port); + } + return binding; + } + /** prints the wsdl to text from the wsdl definition */ + public static void printWSDL(PrintWriter out, Definition def) { + try { + WSDLFactory factory = WSDLFactory.newInstance(); + WSDLWriter wsdlWriter = factory.newWSDLWriter(); + wsdlWriter.writeWSDL(def, out); + } catch (WSDLException ex) { + ex.printStackTrace(out); + } + } + /** prints the wsdl to text from the wsdl definition */ + public static String printWSDLToString(Definition def) { + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + printWSDL(out, def); + out.close(); + return writer.getBuffer().toString(); + } + /** returns an existing namespace prefix or create one if not exists for the corresponding namespaceURI */ + public static String getNamespacePrefix(Definition def, String namespaceURI, String defPrefix) { + String prefix = null; + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + Set keySet = def.getNamespaces().keySet(); + String newPrefix = "ns"; + if ( defPrefix != null && defPrefix.trim().length() > 0 ){ + newPrefix = defPrefix; + } + prefix = newPrefix; + for ( int i=0; i < Integer.MAX_VALUE; ++i) { + if (!keySet.contains(prefix)) { + break; + } else { + prefix = newPrefix + i; + } + } + } + return prefix; + } + + /** + * creates and adds the jbi service engine binding extensibility element to the wsdl definition + * under specified binding definition. + */ + public static void addExtensibilityElement(Definition wsdlDef, + ElementExtensible extensibleEl, ExtensibilityElement extEl, String defPrefix) { + QName elementType = extEl.getElementType(); + String namespaceURI = elementType.getNamespaceURI(); + String prefix = wsdlDef.getPrefix(namespaceURI); + if ( prefix == null ) { + // no namespace prefix defined. create one. + prefix = WSDLProcessor.getNamespacePrefix(wsdlDef, namespaceURI, defPrefix); + wsdlDef.addNamespace(prefix, namespaceURI); + } + extensibleEl.addExtensibilityElement(extEl); + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/enginetest/ServiceEngineTest.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/enginetest/ServiceEngineTest.java new file mode 100644 index 000000000..926d7af97 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/enginetest/ServiceEngineTest.java @@ -0,0 +1,54 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ${artifactId}Test.java + */ + +package enginetest; + +import net.openesb.component.${artifactId}.test.JBIComponentTestClient; +import net.openesb.component.${artifactId}.test.SOAPBindingTestClient; +import java.util.Properties; + import junit.framework.TestCase; + +/** + * The test method in this testcase uses the SOAPBindingTestClient to send the + * input document to the echo service provided by service engine via soap binding + * component and receives the output document which will be placed in test results + * directory under the same package as this test case. + * @see com.sun.jbi.sample.component.test.SOAPBindingTestClinet + * @author chikkala + */ +public class ServiceEngineTest + extends TestCase +{ + public ServiceEngineTest(String testName) { + super(testName); + } + + public void test1() throws Exception { + String testPropertiesPath = "test1.properties"; + JBIComponentTestClient testClient = new SOAPBindingTestClient(); + Properties testProps = testClient.loadTestProperties(this.getClass(), testPropertiesPath); + testClient.testService(testProps); + } + + public void test2() throws Exception { + String testPropertiesPath = "test2.properties"; + JBIComponentTestClient testClient = new SOAPBindingTestClient(); + Properties testProps = testClient.loadTestProperties(this.getClass(), testPropertiesPath); + testClient.testService(testProps); + } + + public static void main(String[] args) { + try { + ServiceEngineTest compTest = new ServiceEngineTest("ServiceEngineTest"); + compTest.test1(); + compTest.test2(); + } catch(Exception ex) { + ex.printStackTrace(); + } + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/enginetest/test1.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/enginetest/test1.properties new file mode 100644 index 000000000..fd5ee2403 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/enginetest/test1.properties @@ -0,0 +1,11 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +input.file=test1Input.xml +${symbol_pound} expected.file=Expected.xml +output.file=test1Output.xml +soap.binding.inbound.endpoint.address.location=http://localhost:12010/ServiceEngine/greetings +soap.binding.soapaction=sayHello +fail.on.soap.fault=true + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/enginetest/test1Input.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/enginetest/test1Input.xml new file mode 100644 index 000000000..b1a3ecc9e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/enginetest/test1Input.xml @@ -0,0 +1,15 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + Srinivasan + Chikkala + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/enginetest/test2.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/enginetest/test2.properties new file mode 100644 index 000000000..5a35303e5 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/enginetest/test2.properties @@ -0,0 +1,11 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +input.file=test2Input.xml +${symbol_pound} expected.file=Expected.xml +output.file=test2Output.xml +soap.binding.inbound.endpoint.address.location=http://localhost:12010/ServiceEngine/greetings +soap.binding.soapaction=sayGoodbye +fail.on.soap.fault=true + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/enginetest/test2Input.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/enginetest/test2Input.xml new file mode 100644 index 000000000..47952104c --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/enginetest/test2Input.xml @@ -0,0 +1,15 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + Srinivasan + Chikkala + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java new file mode 100644 index 000000000..919ad6829 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java @@ -0,0 +1,298 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JBIComponentTestClient.java + */ + +package net.openesb.component.${artifactId}.test; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Properties; + +/** + * This class implements the base framework for the testing the JBI components. + * Testing the JBI component involves may require deploying a service to the + * component(s) to enable the service provided by the test component and then + * invoking the service provided by the test component. If the test component is + * a binding component, then a service provider component such as sample service + * engine is required to test the component end to end. If the test component is a + * service engine, then the service on the test component can be invoked via + * soap/http binding component. + * + * This class provides the utilites to read the test properties, read the input + * message from the file and save the output to the file. The testService + * method implemented here can be executed as the test for the component. The + * testService method calls the invokeService method with the input document and + * expects a output document or error that will be saved to the output file. + * The method invokeService should be implemented by the extended test classes to + * inplement a suitable service consumer implemenation for the test compoent. + * See JMXBindingTestClient.java or SOAPBidningTestClient.java for more details + * on how to implement a partucular test service consumer. + * + * @author chikkala + */ +public abstract class JBIComponentTestClient { + + public static final String TEST_PROPS_FILE_PROP = "test.properties.file"; + public static final String TEST_RESULTS_DIR_PROP = "test.results.dir"; + public static final String TEST_SRC_DIR_PROP = "test.src.dir"; + + public static final String TEST_PACKAGE_PROP = "test.package.name"; + + public static final String INPUT_FILE_PROP = "input.file"; + public static final String EXPECTED_FILE_PROP = "expected.file"; + public static final String OUTPUT_FILE_PROP = "output.file"; + + public static final String DEF_TEST_PROP_FILE = "test.properties"; + public static final String DEF_INPUT_FILE = "Input.xml"; + public static final String DEF_OUTPUT_FILE = "Output.xml"; + public static final String DEF_TEST_RESULTS_DIR = "test-results"; + + public JBIComponentTestClient() { + } + /** + * returns the absolute resource path w.r.t. the packagePath if the resource name + * is relative else return the resourceName as it is. + * @param package name ( dot separated ) + * @param resourcName dot separated name or a absolute resource path + * @return abosolute resource path with path separator + */ + public static String resolveResourcePath(String packageName, String resourceName) { + String resourcePath = resourceName; + if ( !resourceName.startsWith("/")) { + // it is relative resource file. resolve it w.r.t. testPackage + String pkgDir = packageName.trim().replace('.', '/'); + if ( pkgDir.length() != 0 ) { + pkgDir += "/"; + } + resourcePath = "/" + pkgDir + resourceName; + } + return resourcePath; + } + /** + * loads the resource file as properties. + * @param testPackage package name where this test belongs + * @param testPropPath resource path relative to testPackage or absolute resource path + */ + public Properties loadTestProperties(String testPackage, String testPropPath) throws IOException { + String propsResourcePath = resolveResourcePath(testPackage, testPropPath); + + InputStream testPropIS = null; + try { + testPropIS = this.getClass().getResourceAsStream(propsResourcePath); + Properties testProps = new Properties(); + testProps.load(testPropIS); + testProps.setProperty(TEST_PACKAGE_PROP, testPackage); + return testProps; + } finally { + if ( testPropIS != null ) { + try { + testPropIS.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + } + /** + * load default test properties file in the testClass package. + * @param testClass Class where to look for the default test properties + * @param testPropPath resource path relative to testPackage or absolute resource path + * @return Properties test properties + */ + public Properties loadTestProperties(Class testClass, String testPropPath) throws IOException { + return loadTestProperties(testClass.getPackage().getName(), testPropPath ); + } + /** + * load default test properties file in the testClass package. + * @param testClass Class where to look for the default test properties + * @return Properties test properties + */ + public Properties loadTestProperties(Class testClass) throws IOException { + return loadTestProperties(testClass.getPackage().getName(), DEF_TEST_PROP_FILE ); + } + /** + * loads the resource file to string bugger + * @param inputFile resource file path + */ + public StringBuffer loadResourceFile(String resourcePath) throws FileNotFoundException, IOException { + + InputStream inputIS = null; + InputStreamReader inputReader = null; + BufferedReader reader = null; + StringWriter strWriter = null; + PrintWriter writer = null; + try { + inputIS = this.getClass().getResourceAsStream(resourcePath); + inputReader = new InputStreamReader(inputIS); + reader = new BufferedReader(inputReader); + strWriter = new StringWriter(); + writer = new PrintWriter(strWriter); + for ( String line = null; (line = reader.readLine()) != null ; ) { + writer.println(line); + } + writer.close(); + strWriter.close(); + return strWriter.getBuffer(); + } finally { + if ( inputIS != null ) { + try { + inputIS.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + } + + /** + * reads data from the reader and saves to file + * @param reader reader from which to read the data and save to file + * @param outputFilePath absolute file path + */ + public void saveOutputToFile(Reader reader, String outputFilePath) throws IOException { + + BufferedReader buff = null; + FileWriter fileWriter = null; + PrintWriter writer = null; + try { + buff = new BufferedReader(reader); + fileWriter = new FileWriter(outputFilePath); + writer = new PrintWriter(fileWriter); + for ( String line = null; (line = buff.readLine()) != null ; ) { + writer.println(line); + } + } finally { + if ( writer != null ) { + writer.close(); + } + if ( fileWriter != null ) { + fileWriter.close(); + } + } + } + + /** + * resource path. + */ + public String getInputFileResourcePath(Properties testProps) { + + String testPkg = testProps.getProperty(TEST_PACKAGE_PROP, ""); + String inputFile = testProps.getProperty(INPUT_FILE_PROP, DEF_INPUT_FILE); + String resourcePath = resolveResourcePath(testPkg, inputFile); + return resourcePath; + } + /** + * return resource path + */ + public String getExpectedFileResourcePath(Properties testProps) { + + String testPkg = testProps.getProperty(TEST_PACKAGE_PROP, ""); + String resourcePath = null; + String expFile = testProps.getProperty(EXPECTED_FILE_PROP, null); + if ( expFile != null ) { + resourcePath = resolveResourcePath(testPkg, expFile); + } + return resourcePath; + } + /** + * return the absolute path to the output file + */ + public String getOutputFilePath(Properties testProps) { + + String defPackage = this.getClass().getPackage().getName(); + String testPackage = testProps.getProperty(TEST_PACKAGE_PROP, defPackage); + String testPackageDir = testPackage.replace('.','/'); + String outputFile = testProps.getProperty(OUTPUT_FILE_PROP, DEF_OUTPUT_FILE); + + String userHomeDir = System.getProperty("user.home", ""); + String userDir = System.getProperty("user.dir", userHomeDir); + String defResultsDir = userDir + "/" + DEF_TEST_RESULTS_DIR; + String sysResultDir = System.getProperty(TEST_RESULTS_DIR_PROP, defResultsDir); + String resultDir = testProps.getProperty(TEST_RESULTS_DIR_PROP, sysResultDir); + + File outputDir = new File(resultDir, testPackageDir); + // System.out.println("Creating the test results output dir " + outputDir); + outputDir.mkdirs(); + return (new File(outputDir, outputFile)).getAbsolutePath(); + } + + /** + * This is the method where the actual service invocation code based on the + * type of client will be implemented. testService method calls this method + * after preparing the test input and then processes the output returned by + * this method to complte the test. + * @param inputDoc + * @param testProps + * @throws java.lang.Exception + * @return + */ + public abstract StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception; + + /** + * abstract method implemented by the extended classes to compare the output + * document with the expected output to determine the test is a failure or + * success. + * @param outputDoc + * @param expectedDoc + * @param testProps + * @throws java.lang.Exception + */ + public abstract void compareWithExpectedOutput(StringBuffer outputDoc, + StringBuffer expectedDoc, Properties testProps) throws Exception; + + /** + * This is the main test method that a test case will call to test the + * service. The standard steps that required to invoke the service and + * process the output will be done in this method. Each test case creates + * the test Properties required for that test and executes this method for + * testing the service by passing the test properties to it. This method + * prepares the input and executes the invokeService method to invoke a + * service with the prepared input. It then processes the return value from + * the invokeService to complete the test. + * + * @param testProps + * @throws java.lang.Exception + */ + public void testService(Properties testProps) throws Exception { + + String inFilePath = getInputFileResourcePath(testProps); + String outFilePath = getOutputFilePath(testProps); + String expFilePath = getExpectedFileResourcePath(testProps); + File outDir = (new File(outFilePath)).getParentFile(); + outDir.mkdirs(); + + StringBuffer outputDoc = new StringBuffer(); + + try { + StringBuffer inputDoc = loadResourceFile(inFilePath); + outputDoc = invokeService(inputDoc, testProps); + if ( expFilePath != null ) { + StringBuffer expOutputDoc = loadResourceFile(expFilePath); + compareWithExpectedOutput(inputDoc, expOutputDoc, testProps); + } + } catch (Exception ex) { + StringWriter out = new StringWriter(); + ex.printStackTrace(new PrintWriter(out)); + outputDoc.append(out.getBuffer()); + throw ex; + } finally { + if ( outputDoc != null ) { + System.out.println(outputDoc); + this.saveOutputToFile(new StringReader(outputDoc.toString()), outFilePath); + } + } + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java new file mode 100644 index 000000000..7cc8c103e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java @@ -0,0 +1,136 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingTestClient.java + */ + +package net.openesb.component.${artifactId}.test; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanException; +import javax.management.MBeanServerConnection; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.management.ReflectionException; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; + +/** + * This class extends the JBIComponentTestClient and implements the invokeService + * method to test the proxy service consumer implementation by a binding component + * that can communicate with the external service consumers using JMX interface. + * @author chikkala + */ +public class JMXBindingTestClient extends JBIComponentTestClient { + + public static final String CONSUMER_EP_INBOUND_OPERATION_PROP = "consumer.jmx.bc.ep.operation"; + public static final String CONSUMER_EP_ADDRESS_MBEAN_PROP = "consumer.jmx.bc.ep.address.mbean"; + public static final String CONSUMER_EP_ADDRESS_URL_PROP = "consumer.jmx.bc.ep.address.serviceURL"; + public static final String CONSUMER_EP_ADDRESS_USERNAME_PROP = "consumer.jmx.bc.ep.address.username"; + public static final String CONSUMER_EP_ADDRESS_PASSWORD_PROP = "consumer.jmx.bc.ep.address.password"; + + public static final String PROVIDER_EP_INBOUND_OPERATION_PROP = "provider.jmx.bc.ep.operation"; + public static final String PROVIDER_EP_ADDRESS_MBEAN_PROP = "provider.jmx.bc.ep.address.mbean"; + public static final String PROVIDER_EP_ADDRESS_URL_PROP = "provider.jmx.bc.ep.address.serviceURL"; + public static final String PROVIDER_EP_ADDRESS_USERNAME_PROP = "provider.jmx.bc.ep.address.username"; + public static final String PROVIDER_EP_ADDRESS_PASSWORD_PROP = "provider.jmx.bc.ep.address.password"; + + + /** + * Creates a new instance of JMXBindingTestClient + */ + public JMXBindingTestClient() { + super(); + } + /** + * creates jmx connection to send the input message to the binding component. + */ + public static MBeanServerConnection getJMXConnection(Properties testProps) + throws MalformedURLException, IOException { + + String jmxUrl = testProps.getProperty(CONSUMER_EP_ADDRESS_URL_PROP); + String username = testProps.getProperty(CONSUMER_EP_ADDRESS_USERNAME_PROP); + String password = testProps.getProperty(CONSUMER_EP_ADDRESS_PASSWORD_PROP); + + Map env = new HashMap(); + if ( username != null ) { + String [] credentials = new String [] {username, password}; + env.put("jmx.remote.credentials", credentials); + env.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, JMXBindingTestClient.class.getClassLoader()); + } + JMXServiceURL serviceURL = new JMXServiceURL(jmxUrl); + JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, env); + MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection(); + return mbeanServerConnection; + } + /** + * constructs the jmx mbean objectname + */ + public static ObjectName createJMXEndpointMBeanObjectName(String endpointAddressMBean) throws MalformedObjectNameException { + // String objectName = JMX_DOMAIN + ":" + JMX_ENDPOINT_ADDRESS_KEY + "=" + endpointAddressMBean; + return new ObjectName(endpointAddressMBean); + } + /** + * invokes a jmx mbean to send message. + */ + public static StringBuffer invokeSendMessage(MBeanServerConnection jmxConn, ObjectName epAddressName, + String operation, StringBuffer inputDoc) + throws MalformedObjectNameException, InstanceNotFoundException, + MBeanException, ReflectionException, IOException { + StringBuffer outDoc = null; + + Object result = null; + String mbeanOperation = "sendMessage"; + + Object[] params = new Object[2]; + params[0] = operation; + params[1] = inputDoc; + + String[] signature = new String[2]; + signature[0] = "java.lang.String"; + signature[1] = "java.lang.StringBuffer"; + + result = jmxConn.invoke(epAddressName, mbeanOperation, params, signature); + if ( result != null ) { + outDoc = (StringBuffer)result; + } + + return outDoc; + } + /** + * invokes the service via jmx interface. + */ + public StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception { + + ObjectName epAddressName = new ObjectName(testProps.getProperty(CONSUMER_EP_ADDRESS_MBEAN_PROP)); + String operation = testProps.getProperty(CONSUMER_EP_INBOUND_OPERATION_PROP); + + MBeanServerConnection jmxConn = getJMXConnection(testProps); + StringBuffer outputDoc = null; + try { + outputDoc = invokeSendMessage(jmxConn, epAddressName, operation, inputDoc); + } catch (MBeanException ex) { + Exception targetEx = ex.getTargetException(); + if ( targetEx != null ) { + throw targetEx; + } else { + throw ex; + } + } + return outputDoc; + } + /** no expected output comparison implemented */ + public void compareWithExpectedOutput(StringBuffer inputDoc, + StringBuffer expectedDoc, + Properties testProps) throws Exception { + // throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java new file mode 100644 index 000000000..28f534612 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java @@ -0,0 +1,159 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * SOAPBindingTestClient.java + */ + +package net.openesb.component.${artifactId}.test; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Properties; +import javax.xml.soap.MessageFactory; +import javax.xml.soap.MimeHeaders; +import javax.xml.soap.SOAPConnection; +import javax.xml.soap.SOAPConnectionFactory; +import javax.xml.soap.SOAPException; +import javax.xml.soap.SOAPFault; +import javax.xml.soap.SOAPMessage; +import javax.xml.soap.SOAPPart; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +/** + * This class extends the JBIComponentTestClient and implements the invokeService + * method to test the Service Engine via SOAP Binding by invoking the service using + * SOAP Client that sends the message to the service provider via soaphttp binding. + * + * @author chikkala + */ +public class SOAPBindingTestClient extends JBIComponentTestClient { + + private static final String ADDRESS_PROP = "soap.binding.inbound.endpoint.address.location"; + private static final String SOAP_ACTION_PROP = "soap.binding.soapaction"; + private static final String FAIL_ON_SOAP_FAULT_PROP = "fail.on.soap.fault"; + + private static MessageFactory messageFactory; + private static SOAPConnectionFactory soapConnFactory; + private static SOAPConnection connection; + + public SOAPBindingTestClient() throws SOAPException { + init(); + } + /** initializes SOAP client */ + private synchronized void init() throws SOAPException { + if ( messageFactory == null ) { + messageFactory = MessageFactory.newInstance(); + } + if ( soapConnFactory == null ) { + soapConnFactory = SOAPConnectionFactory.newInstance(); + } + if ( connection == null ) { + connection = soapConnFactory.createConnection(); + } + } + + /** + * read in a soap message from the given input file + */ + private static SOAPMessage loadMessage(Reader inReader) throws SOAPException, IOException { + //Create and populate the message from a file + SOAPMessage message = messageFactory.createMessage(); + SOAPPart soapPart = message.getSOAPPart(); + StreamSource preppedMsgSrc = new StreamSource(inReader); + soapPart.setContent(preppedMsgSrc); + message.saveChanges(); + return message; + } + /** saves the SOAP message as xml text to a writer */ + private static void saveMessage(SOAPMessage response, Writer outWriter) + throws TransformerConfigurationException, SOAPException, TransformerException { + + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + transformerFactory.setAttribute("indent-number", new Integer(2)); + Transformer transformer = transformerFactory.newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + + SOAPPart replySOAPPart = response.getSOAPPart(); + Source sourceContent = replySOAPPart.getContent(); + StreamResult result = new StreamResult(outWriter); + try { + transformer.transform(sourceContent, result); + } catch (TransformerException ex) { + ex.printStackTrace(); + } + } + /** + * Send a soap message + * @param destination URL to send to + * @param message message to send + * @param expectedHttpStatus expected http status code or null if success is expected + * @return reply soap message + */ + private static SOAPMessage sendMessage(String destination, SOAPMessage message, String soapAction) throws SOAPException { + + // Add soapAction if not null + if (soapAction != null) { + MimeHeaders hd = message.getMimeHeaders(); + hd.setHeader("SOAPAction", soapAction); + } + // Send the message and get a reply + SOAPMessage reply = null; + reply = connection.call(message, destination); + return reply; + } + /** check the xml text in the StringBuffer passed contains SOAP Fault. */ + public boolean isSOAPFault(StringBuffer msgBuff) { + SOAPFault soapFault = null; + try { + SOAPMessage inMsg = loadMessage(new StringReader(msgBuff.toString())); + soapFault = inMsg.getSOAPBody().getFault(); + } catch (Exception ex) { + // any exception, means either no fault elem or invalid xml + } + return (soapFault != null); + } + /** + * invokes the service ny sending the input message and return the output + * message returned by the service. + */ + public StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception { + + String soapAction = testProps.getProperty(SOAP_ACTION_PROP); + String destination = testProps.getProperty(ADDRESS_PROP); + SOAPMessage inMsg = loadMessage(new StringReader(inputDoc.toString())); + SOAPMessage outMsg = sendMessage(destination, inMsg, soapAction); + StringWriter out = new StringWriter(); + saveMessage(outMsg, out); + StringBuffer outDoc = out.getBuffer(); + Boolean failOnSoapFault = Boolean.valueOf(testProps.getProperty(FAIL_ON_SOAP_FAULT_PROP, "false")); + if ( failOnSoapFault ) { + if (isSOAPFault(outDoc)) { + StringBuffer errBuff = new StringBuffer("${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} SOAP FAULT ${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} ${symbol_escape}n"); + errBuff.append(outDoc); + throw new Exception(errBuff.toString()); + } + } + return outDoc; + } + /** comparing the received output document with the expected document. throw + * exception if the docs are not same. throwing the exception in this method + * fails the test. + */ + public void compareWithExpectedOutput(StringBuffer outputDoc, + StringBuffer expectedDoc, + Properties testProps) throws Exception { + // throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/build.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/build.properties new file mode 100644 index 000000000..945269943 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/build.properties @@ -0,0 +1,22 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} Build properties for the service assembly builds +${symbol_pound} user.properties.file=../../user.properties +src.dir=src +${symbol_pound} This directory is removed when the project is cleaned: +build.dir=build +service.assembly.name=testSA + +${symbol_pound}no.deps=true set the no.deps property if there are no SUs to build +${symbol_pound} for each testSU define the properties here. +${symbol_pound} dependent BC SU projects dependency +${symbol_pound} service unit name +service.unit.name.testSUBC=testSUBC +${symbol_pound} service unit project directory +project.testSUBC=testSUBC + +${symbol_pound} service unit name +service.unit.name.testSUSE=testSUSE +${symbol_pound} service unit project directory +project.testSUSE=testSUSE diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/build.xml new file mode 100644 index 000000000..02f75e641 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/build.xml @@ -0,0 +1,140 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.assembly.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/src/META-INF/jbi.xml new file mode 100644 index 000000000..ed9f610e9 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/src/META-INF/jbi.xml @@ -0,0 +1,44 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + ${artifactId}_TestSA + This is a test Service Assembly to test Engine + + + + + ${artifactId}_TestSUBC + This service unit enables soap inbound endpoint for a service in service engine + + + testSUBC.zip + sun-http-binding + + + + + ${artifactId}_TestSUSE + This service unit enables greetings service provider in service engine + + + testSUSE.zip + ${artifactId} + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/build.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/build.properties new file mode 100644 index 000000000..1bfd81c69 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/build.properties @@ -0,0 +1,10 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} Build properties for the service unit builds +src.dir=src +${symbol_pound} This directory is removed when the project is cleaned: +${symbol_pound}build.dir=../../../build/test/testSU/build +build.dir=build +service.unit.name=testSUSE + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/build.xml new file mode 100644 index 000000000..777fb3cf9 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/build.xml @@ -0,0 +1,74 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/build/testSUBC.zip b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/build/testSUBC.zip new file mode 100644 index 000000000..f4205815d Binary files /dev/null and b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/build/testSUBC.zip differ diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/build/testSUBC/Greetings.wsdl b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/build/testSUBC/Greetings.wsdl new file mode 100644 index 000000000..038d91bcd --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/build/testSUBC/Greetings.wsdl @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml new file mode 100644 index 000000000..05f4f9bef --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml @@ -0,0 +1,17 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/src/Greetings.wsdl b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/src/Greetings.wsdl new file mode 100644 index 000000000..8a160abd0 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/src/Greetings.wsdl @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml new file mode 100644 index 000000000..05f4f9bef --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml @@ -0,0 +1,17 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build.properties new file mode 100644 index 000000000..1bfd81c69 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build.properties @@ -0,0 +1,10 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} Build properties for the service unit builds +src.dir=src +${symbol_pound} This directory is removed when the project is cleaned: +${symbol_pound}build.dir=../../../build/test/testSU/build +build.dir=build +service.unit.name=testSUSE + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build.xml new file mode 100644 index 000000000..846415d3a --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build.xml @@ -0,0 +1,74 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE.zip b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE.zip new file mode 100644 index 000000000..2db1a3a5c Binary files /dev/null and b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE.zip differ diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE/Greetings.wsdl b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE/Greetings.wsdl new file mode 100644 index 000000000..038d91bcd --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE/Greetings.wsdl @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml new file mode 100644 index 000000000..8235893ee --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml @@ -0,0 +1,17 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE/goodbye.xsl b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE/goodbye.xsl new file mode 100644 index 000000000..c60e39b73 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE/goodbye.xsl @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + Goodbye ! Have a great time. + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE/hello.xsl b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE/hello.xsl new file mode 100644 index 000000000..994b66f98 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE/hello.xsl @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + Hello ! + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE/xsltmap.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE/xsltmap.properties new file mode 100644 index 000000000..44baf5452 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/build/testSUSE/xsltmap.properties @@ -0,0 +1,31 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} properties will be used to find the xslt file that will be used for invoking a +${symbol_pound} service operation. +${symbol_pound} The "xsltmap.properties" file should contain two types of properties +${symbol_pound} 1. for namespace prefix to namespaceURI map that starts with "xmlns." prefix like +${symbol_pound} "xmlns.tns-prefix=http://www.sun.com/jbi/examples/sample-service/echo" +${symbol_pound} 2. a service description to xslt file properties with syntax like +${symbol_pound} "{tns-prefix}service-name=xslt_file_name" and +${symbol_pound} "{tns-prefix}service-name.{tns-prefix}operation-name=xslt_file_name" and +${symbol_pound} "{tns-prefix}service-name.{tns-prefix}interface-name.operation-name=xslt_file_name" . +${symbol_pound} the service description property is a "." delimited tokens that represents +${symbol_pound} a serive or interface qname and a operation name. To locate xslt file either with +${symbol_pound} service qname or service qname and operaton or serivice qname and interface qname +${symbol_pound} and operation, all the three properties specified above should be there for each xslt file. +${symbol_pound} + +xmlns.greet1=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greet2=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greettypes=http://www.sun.com/jbi/examples/sample-service/greetings/types +${symbol_pound} just service level default settings +{greet2}greetService=hello.xsl +${symbol_pound} service and operation +{greet2}greetService.{greet1}sayHello=hello.xsl +${symbol_pound} service, interface, operation +{greet2}greetService.{greet1}greetings.sayHello=hello.xsl +${symbol_pound} service and operation +{greet2}greetService.{greet1}sayGoodbye=goodbye.xsl +${symbol_pound} service, interface, operation +{greet2}greetService.{greet1}greetings.sayGoodbye=goodbye.xsl diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/Greetings.wsdl b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/Greetings.wsdl new file mode 100644 index 000000000..8a160abd0 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/Greetings.wsdl @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml new file mode 100644 index 000000000..8235893ee --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml @@ -0,0 +1,17 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/goodbye.xsl b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/goodbye.xsl new file mode 100644 index 000000000..c60e39b73 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/goodbye.xsl @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + Goodbye ! Have a great time. + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/hello.xsl b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/hello.xsl new file mode 100644 index 000000000..994b66f98 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/hello.xsl @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + Hello ! + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/xsltmap.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/xsltmap.properties new file mode 100644 index 000000000..44baf5452 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/xsltmap.properties @@ -0,0 +1,31 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} properties will be used to find the xslt file that will be used for invoking a +${symbol_pound} service operation. +${symbol_pound} The "xsltmap.properties" file should contain two types of properties +${symbol_pound} 1. for namespace prefix to namespaceURI map that starts with "xmlns." prefix like +${symbol_pound} "xmlns.tns-prefix=http://www.sun.com/jbi/examples/sample-service/echo" +${symbol_pound} 2. a service description to xslt file properties with syntax like +${symbol_pound} "{tns-prefix}service-name=xslt_file_name" and +${symbol_pound} "{tns-prefix}service-name.{tns-prefix}operation-name=xslt_file_name" and +${symbol_pound} "{tns-prefix}service-name.{tns-prefix}interface-name.operation-name=xslt_file_name" . +${symbol_pound} the service description property is a "." delimited tokens that represents +${symbol_pound} a serive or interface qname and a operation name. To locate xslt file either with +${symbol_pound} service qname or service qname and operaton or serivice qname and interface qname +${symbol_pound} and operation, all the three properties specified above should be there for each xslt file. +${symbol_pound} + +xmlns.greet1=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greet2=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greettypes=http://www.sun.com/jbi/examples/sample-service/greetings/types +${symbol_pound} just service level default settings +{greet2}greetService=hello.xsl +${symbol_pound} service and operation +{greet2}greetService.{greet1}sayHello=hello.xsl +${symbol_pound} service, interface, operation +{greet2}greetService.{greet1}greetings.sayHello=hello.xsl +${symbol_pound} service and operation +{greet2}greetService.{greet1}sayGoodbye=goodbye.xsl +${symbol_pound} service, interface, operation +{greet2}greetService.{greet1}greetings.sayGoodbye=goodbye.xsl diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/archetype.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/archetype.properties new file mode 100644 index 000000000..c7bdacd1c --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/archetype.properties @@ -0,0 +1,6 @@ +#Tue Jul 30 12:05:58 IST 2013 +package=it.pkg +version=0.1-SNAPSHOT +groupId=archetype.it +artifactId=ServiceEngine-archetype +glassfishLocation=C:\\GlassFishESBv22\\glassfish diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/goal.txt b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/goal.txt new file mode 100644 index 000000000..e69de29bb diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/build.log b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/build.log new file mode 100644 index 000000000..e69de29bb diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/build.xml new file mode 100644 index 000000000..577e396e4 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/build.xml @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project ServiceEngine-archetype. + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/install-params.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/install-params.properties new file mode 100644 index 000000000..e69de29bb diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/m2nbbuild-impl.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/m2nbbuild-impl.xml new file mode 100644 index 000000000..9687b905b --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/m2nbbuild-impl.xml @@ -0,0 +1,130 @@ + + + + + This project compile, package and test the JBI Components when invoked from Maven2. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/m2nbbuild.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/m2nbbuild.properties new file mode 100644 index 000000000..5bab5aa6b --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/m2nbbuild.properties @@ -0,0 +1,45 @@ +# build properties file to set/override the properties of the netbeans project +# build properties when the netbeans build is called from the maven build lifecycle. +# Netbeans project when build from the IDE, uses a build.properties from the user.dir +# of the Netbeans IDE to resolve some of the properties used in the project such as +# the libraries classpath. +# When invoking the Netbeans project build from maven, this build.properties file +# is not available. So, you can add the properties defined in ide build properties +# that this project uses here. +# + +# default local repository settings. If the repository location is different +# -D command line option should override this (e.g. mvn -Dmaven.repo.local=/my/m2/repository +maven.repo.local=${user.home}/.m2/repository +# begin jbi admin settings +# set the below properties if you want to override the properties from nbproject/project.properties +# that sets the application server admin settings. +# +# jbi.as.home=C:/Sun/glassfish-v2-b58g +# jbi.host=localhost +# jbi.port=4848 +# jbi.username=admin +# jbi.password=adminadmin +# end jbi admin settings +# + +# classpath settings +junit.ant.task.classpath=${maven.repo.local}/ant/ant-junit/1.6.5/ant-junit-1.6.5.jar +junit.runtime.classpath=${maven.repo.local}/junit/junit/3.8.2/junit-3.8.2.jar +libs.junit.classpath=${junit.runtime.classpath}:${junit.ant.task.classpath} +libs.jbi-cdk-ant-tasks.classpath=${maven.repo.local}/open-esb/jbi-cdk/jbi-cdk-ant-tasks/0.1-SNAPSHOT/jbi-cdk-ant-tasks-0.1-SNAPSHOT.jar + +libs.jbi.classpath=${maven.repo.local}/open-esb/jbi/1.0/jbi-1.0.jar +libs.wsdl4j.162.classpath=${maven.repo.local}/wsdl4j/wsdl4j/1.6.2/wsdl4j-1.6.2.jar +# libs.jaxws21.classpath=${jbi.as.home}/lib/javaee.jar:${jbi.as.home}/lib/webservices-rt.jar +libs.jaxws21.classpath=\ +${maven.repo.local}/javax/activation/activation/1.1/activation-1.1.jar:\ +${maven.repo.local}/javax/xml/soap/saaj-api/1.3/saaj-api-1.3.jar:\ +${maven.repo.local}/javax/xml/ws/jaxws-api/2.1/jaxws-api-2.1.jar:\ +${maven.repo.local}/com/sun/xml/messaging/saaj/saaj-impl/1.3/saaj-impl-1.3.jar:\ +${maven.repo.local}/com/sun/xml/ws/jaxws-rt/2.1.2/jaxws-rt-2.1.2.jar + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/m2nbbuild.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/m2nbbuild.xml new file mode 100644 index 000000000..6557242cf --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/m2nbbuild.xml @@ -0,0 +1,34 @@ + + + + + + This project compile, package and test the JBI Components when invoked from Maven2. + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/build-impl.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/build-impl.xml new file mode 100644 index 000000000..379b61c75 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/build-impl.xml @@ -0,0 +1,551 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + Inside: postArchTypeGen - Post task is getting executed! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Inside: postArchTypeGen - Post task executed successfully! + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/genfiles.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/genfiles.properties new file mode 100644 index 000000000..2e46a992c --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=ac78c060 +build.xml.script.CRC32=9068f2c7 +build.xml.stylesheet.CRC32=8add101f@1.0 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=ac78c060 +nbproject/build-impl.xml.script.CRC32=d15987fd +nbproject/build-impl.xml.stylesheet.CRC32=4ed53ee0@1.0 diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/jbi_admin.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/jbi_admin.xml new file mode 100644 index 000000000..623507a02 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/jbi_admin.xml @@ -0,0 +1,501 @@ + + + + + +This ant script contains the jbi ant tasks and the targets and properties using +which the jbi admin commands can be performed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Usage : ant -f <fullpath>/jbi_admin.xml [options] [target] + options: -D<property>=<value> + Specify a property/value pairs as options that are valid for the target. + target : ant target name in jbi_admin.xml + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/jbiadmin-impl.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/jbiadmin-impl.xml new file mode 100644 index 000000000..cde39fb8b --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/jbiadmin-impl.xml @@ -0,0 +1,336 @@ + + + Install, uninstall, reinstall, start, stop, shutdown jbi components. + + + + + + + + + + + + + + Must set jbi.host + Must set jbi.port + Must set jbi.username + Must set jbi.password + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/private/private.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/private/private.properties new file mode 100644 index 000000000..f4fdfea51 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/private/private.properties @@ -0,0 +1,3 @@ +javac.debug=true +javadoc.preview=true +user.properties.file=D:\\softwares\\openesb_logicoy_last_working57\\.netbeans\\openesb\\build.properties diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/private/retriever/catalog.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/private/retriever/catalog.xml new file mode 100644 index 000000000..e69de29bb diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/project.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/project.properties new file mode 100644 index 000000000..1d28e94eb --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/project.properties @@ -0,0 +1,90 @@ +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.predist.dir=${build.dir}/predist +build.predist.jar=${build.predist.dir}/component.jar +build.predist.lib.dir=${build.predist.dir}/lib +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.dir=${build.dir}/test +build.test.results.dir=${build.dir}/test/results +conf.dir=src/conf +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ServiceEngine-archetype.zip +dist.javadoc.dir=${dist.dir}/javadoc +jar.compress=false +javac.classpath=\ + ${libs.jbi.classpath}:\ + ${jbi.component.sharedlibs.classpath}:\ + ${jbi.component.lib.classpath} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.6 +javac.target=1.6 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.jaxws21.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +jbi.ant.tasks.classpath=\ + ${jbi.as.home}/lib/sun-appserv-ant.jar:\ + ${jbi.as.home}/jbi/lib/jbi-ant-tasks.jar +#jbi.as.home=D:\\softwares\\openesb_logicoy_last_working53\\glassfish +jbi.as.home=C:\GlassFishESBv22\glassfish +#jbi.as.instance.id=[D:\\softwares\\openesb_logicoy_last_working53\\glassfish]deployer:Sun:AppServer::localhost:4848 +jbi.as.instance.id=[C:\GlassFishESBv22\glassfish]deployer:Sun:AppServer::localhost:4848 +jbi.component.bootstrap.class=ServiceEngine-archetype.ProviderSEInstaller +jbi.component.class=ServiceEngine-archetype.ProviderSERuntime +jbi.component.description=Description of service engine : ServiceEngine-archetype +jbi.component.lib.classpath=\ + ${libs.wsdl4j.162.classpath} +jbi.component.name=ServiceEngine-archetype +jbi.component.sharedlibs.classpath= +jbi.component.type=service-engine +jbi.host=localhost +jbi.install.params.file=install-params.properties +jbi.install.with.params=false +jbi.password=this really long string is used to identify a password that has been stored in the Keyring +jbi.port=4848 +jbi.soap.binding.name=sun-http-binding +jbi.username=admin +meta.inf.dir=${conf.dir}/META-INF +platform.active=default_platform +project.jbi.deploy.plugin=./deploy-plugin +project.testSA=test/testSA +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +src.dir=src/java +test-sys-prop.test.results.dir=${build.test.results.dir} +test-sys-prop.test.src.dir=test-sys-prop.test.src.dir +test.src.dir=test/java +testSA.enabled=true +testSA.name=ServiceEngine-archetype_TestSA diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/project.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/project.xml new file mode 100644 index 000000000..5a82a69e2 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/nbproject/project.xml @@ -0,0 +1,17 @@ + + + org.netbeans.modules.jbi.apisupport.project.jbicomponent + + + ServiceEngine-archetype + service-engine + 1.6.5 + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/pom.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/pom.xml new file mode 100644 index 000000000..f6911fd30 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/pom.xml @@ -0,0 +1,282 @@ + + + + 4.0.0 + archetype.it + ServiceEngine-archetype + jar + 0.1-SNAPSHOT + JBI Component[ServiceEngine-archetype] + Maven project for JBI Component that contains the + maven and netbeans build setup and component code to build and test the JBI Component. + http://open-esb.org + + build + src/java + test/java + build/classes + build/test/classes + package + + + org.apache.maven.plugins + maven-compiler-plugin + + true + 1.5 + 1.5 + + + **/*.java + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + + **/*.* + + + + + maven-surefire-plugin + 2.1.3 + true + + + true + + **/bindingtest/*.java + **/enginetest/*.java + + + + + + maven-antrun-plugin + 1.2 + + + m2nbbuild-compile + compile + + run + + + + + + + + + m2nbbuild-compile-test + test-compile + + run + + + + + + + + + m2nbbuild-package + package + + run + + + + + + + + + m2nbbuild-utest + test + + run + + + + + + + + + m2nbbuild-itest + integration-test + + run + + + + + + + + + m2nbbuild-clean + clean + + run + + + + + + + + + + default-cli + + run + + + + !!!!!!!!!!!!!!!!!!!!!! Moving Files and organizing package !!!!!!!!!!!!!!!!!!!!!!!! + + + + + + + + + ant + ant-nodeps + 1.6.5 + + + ant + ant-junit + 1.6.5 + test + + + junit + junit + 3.8.2 + test + + + + + + + + + maven2-repo1 + Maven2 Central Repository + http://repo1.maven.org/maven2 + + + download-java-net-maven2-repository + download.java.net Maven 2.x repository + http://download.java.net/maven/2/ + + + maven-repository.dev.java.net-repository + https://maven-repository.dev.java.net/nonav/repository/ + legacy + + + ws-zones + ws.zones maven repository + http://ws.zones.apache.org/repository2/ + + + apache.org + Maven Snapshots + http://people.apache.org/repo/m2-snapshot-repository + + false + + + + + + + + + apache.org + Maven Plugin Snapshots + http://people.apache.org/repo/m2-snapshot-repository + + false + + + + + + + + ant + ant-nodeps + 1.6.5 + + + ant + ant-junit + 1.6.5 + test + + + junit + junit + 3.8.2 + test + + + org.apache.maven + maven-ant-tasks + 2.0.7 + + + open-esb.jbi-cdk + jbi-cdk-ant-tasks + 1.0-SNAPSHOT + + + open-esb + jbi + 1.0 + + + wsdl4j + wsdl4j + 1.6.2 + + + com.sun.xml.ws + jaxws-rt + 2.1.2 + test + + + + + ${maven.repo.local} + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/conf/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/conf/META-INF/jbi.xml new file mode 100644 index 000000000..1f29286a1 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/conf/META-INF/jbi.xml @@ -0,0 +1,42 @@ + + + + + + + ServiceEngine-archetype + Description of service engine : ServiceEngine-archetype + + + net.openesb.component.ServiceEngine-archetype.ProviderSERuntime + + + component.jar + + lib/wsdl4j-1.6.2.jar + + + net.openesb.component.ServiceEngine-archetype.ProviderSEInstaller + + + component.jar + + lib/wsdl4j-1.6.2.jar + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSEComponentLifeCycle.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSEComponentLifeCycle.java new file mode 100644 index 000000000..1f439ae06 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSEComponentLifeCycle.java @@ -0,0 +1,49 @@ +/* + * ProviderSEComponentLifeCycle.java + */ +package net.openesb.component.ServiceEngine-archetype; + +import net.openesb.component.ServiceEngine-archetype.common.BasicComponentLifeCycle; +import net.openesb.component.ServiceEngine-archetype.common.DefaultMessageExchangeReceiver; +import net.openesb.component.ServiceEngine-archetype.common.MessageExchangeReceiver; +import net.openesb.component.ServiceEngine-archetype.common.RuntimeContext; +import javax.jbi.JBIException; +import javax.jbi.component.Component; + +/** + * This class extends the basic ComponentLifeCycle implementation to provide + * component specific implementation of the ComponentLifeCycle. + * + * @see javax.jbi.ComponentLifeCycle + * @see com.sun.jbi.sample.component.common.BasicComponentLifeCycle + * @author chikkala + */ +public class ProviderSEComponentLifeCycle extends BasicComponentLifeCycle { + + /** + * constructor + */ + public ProviderSEComponentLifeCycle(Component compRuntime) { + super(compRuntime); + } + + /** + * creates DefaultMessageExchangeReceiver to handles receiving and + * processing the message exchanges from the delivery channel. + */ + @Override + protected MessageExchangeReceiver createMessageExchangeReceiver() { + return new DefaultMessageExchangeReceiver(); + } + + /** + * chance to extended classes to do the component specific init + * + * @throws javax.jbi.JBIException + */ + @Override + protected void doInit() throws JBIException { + // NOOP + RuntimeContext.getInstance().setLogger(this.getClass().getName(), null); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSEEndpoint.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSEEndpoint.java new file mode 100644 index 000000000..4bd540df4 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSEEndpoint.java @@ -0,0 +1,98 @@ +/* + * ProviderSEEndpoint.java + */ +package net.openesb.component.ServiceEngine-archetype; + +import net.openesb.component.ServiceEngine-archetype.common.MessageExchangeHandler; +import net.openesb.component.ServiceEngine-archetype.common.RuntimeHelper; +import net.openesb.component.ServiceEngine-archetype.common.MessageExchangeListener; +import net.openesb.component.ServiceEngine-archetype.common.deployment.ProviderEndpoint; +import net.openesb.component.ServiceEngine-archetype.common.deployment.SUDescriptor; +import javax.jbi.JBIException; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.wsdl.Definition; + +/** + * This class extends the ProviderEndpoint to implement component specific + * endpoint configuration. It implements the MessageExchangeListener to receive + * message exchange notifications from the MessageExchangeSupport fired by + * MessageExchangeReceiver and process it using a message exchange handler. + * + * This endpoint is configured for a service provided by this component which + * can receive a xml document and apply xslt transformation and send the results + * back in a InOut message exchange to complete a service invocation on this + * endpoint. + * + * @author chikkala + */ +public class ProviderSEEndpoint extends ProviderEndpoint implements MessageExchangeListener { + + private XSLTFileLocator mXsltFileLocator; + private XSLTService mXsltService; + + /** + * Creates a new instance of XSLTProviderEndpoint + */ + public ProviderSEEndpoint(SUDescriptor.Provides provides, Definition wsdlDef, ProviderSEServiceUnit su) { + super(provides, wsdlDef, su); + } + + /** + * XSLT transformation service used in transformation of the xml documents + * received on this endpoint. + */ + public XSLTService getXSLTService() { + return this.mXsltService; + } + + /** + * returns the XSLTFileLocator object that is created to find the xslt file + * to be used for a particular service operation invocation by looking at + * the mapping file specified in the service unit that deploys this + * endpoint. + */ + public XSLTFileLocator getXSLTFileLocator() { + return this.mXsltFileLocator; + } + + @Override + public void doInit() throws JBIException { + RuntimeHelper.getLogger().info("ProviderSEEndpoint:doInit called"); + ProviderSEServiceUnit su = (ProviderSEServiceUnit) this.getServiceUnit(); + this.mXsltFileLocator = su.getXsltFileLocator(); + this.mXsltService = XSLTService.XSLTServiceImpl.getInstance(); + } + + /** + * creates the message exchange handler that will be used to process the + * message exchange received for this endpoint. + */ + @Override + public MessageExchangeHandler createMessageExchangeHandler() { + return new ProviderSEMessageExchangeHandler(this); + } + + /** + * returns the implementation of the message exchange listener which the + * MessageExchangeSupport invokes when a message exchange is received from + * delivery channel by MessageExchangeReceiver. + */ + @Override + protected MessageExchangeListener createMessageExchangeListener() { + return this; + } + + /** + * implementation of the message exchange received method of the listener. + */ + public void messageExchangeReceived(ExchangeStatus status, MessageExchange me) { + try { + RuntimeHelper.getLogger().fine("MXListener.MessageExchangeReceived: with Status: " + status); + processMessageExchangeWithHandler(status, me); + // processMessageExchange(me); + } catch (Exception ex) { + ex.printStackTrace(); + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSEInstaller.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSEInstaller.java new file mode 100644 index 000000000..cb5e197e4 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSEInstaller.java @@ -0,0 +1,31 @@ + /* + * ProviderSEInstaller.java + */ +package net.openesb.component.ServiceEngine-archetype; + +import net.openesb.component.ServiceEngine-archetype.common.ComponentInstaller; + +/** + * This class extends the ComponentInstaller that implements the + * javax.jbi.component.Bootstrap for a component installation contract. + * + * If the default implemenation of the javax.jbi.component.Bootstrap in + * com.sun.jbi.sample.component.common.ComponentInstaller is not sufficient for + * this components install, uninstall and upgrade requirements, override the + * default implementation here to add component specific installation and + * upgrade tasks such as initializing configuration mbean and creating resources + * specific to component or upgrade workspace and service units during upgrading + * the component. + * + * @see javax.jbi.Bootstrap + * @see com.sun.jbi.sample.component.common.ComponentInstaller + * @author chikkala + */ +public class ProviderSEInstaller extends ComponentInstaller { + + /** + * Constructor to create the MyEngineInstaller. + */ + public ProviderSEInstaller() { + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSEMessageExchangeHandler.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSEMessageExchangeHandler.java new file mode 100644 index 000000000..8e6d9abfd --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSEMessageExchangeHandler.java @@ -0,0 +1,168 @@ +/* + * ProviderSEMessageExchangeHandler.java + * + */ +package net.openesb.component.ServiceEngine-archetype; + +import net.openesb.component.ServiceEngine-archetype.common.AbstractMessageExchangeHandler; +import net.openesb.component.ServiceEngine-archetype.common.RuntimeHelper; +import net.openesb.component.ServiceEngine-archetype.common.wsdl.WSDL11JBIWrapper; +import java.io.StringReader; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.Fault; +import javax.jbi.messaging.InOut; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Source; + +/** + * This class extends the AbstractMessageExchangeHandler to implement the + * component specific message exchange processing on the provider side in a + * service engine. + * + * @author chikkala + */ +public class ProviderSEMessageExchangeHandler extends AbstractMessageExchangeHandler { + + private ProviderSEEndpoint mEndpoint; + + /** + * Creates a new instance of ProviderSEMXHandler + */ + public ProviderSEMessageExchangeHandler(ProviderSEEndpoint endpoint) { + this.mEndpoint = endpoint; + } + + protected Logger getLogger() { + return this.mEndpoint.getLogger(); + } + + protected DeliveryChannel getDeliveryChannel() { + return this.mEndpoint.getDeliveryChannel(); + } + + protected void validateMessageExchange() throws MessagingException { + MessageExchange msgExchange = this.getMessageExchange(); + + if (this.getMessageExchange() == null) { + throw new MessagingException("MessageExchange Object is null in MessageExchageHandler"); + } + + if (MessageExchange.Role.CONSUMER.equals(msgExchange.getRole())) { + throw new MessagingException("Provider Message Exchange Handler can not have MessageExchange with CONSUMER Role"); + } + + if (!(msgExchange instanceof InOut)) { + throw new MessagingException("InOut Message Exchange Handler MessageExchange object should be instanceof javax.jbi.messaging.InOut "); + } + } + + protected void processError(Exception ex) { + MessageExchange msgExchange = this.getMessageExchange(); + Exception errEx = msgExchange.getError(); // get the error and print + RuntimeHelper.getLogger().info( + "InOut Message Exchange Provider received Error: " + errEx.getMessage()); + msgExchange.getError().printStackTrace(); + } + + protected void processDone() { + MessageExchange msgExchange = this.getMessageExchange(); + RuntimeHelper.getLogger().info("InOut Message Exchange Provider received DONE :" + + " END of service invocation"); + } + + protected void processFault(Fault fault) { + MessageExchange msgExchange = this.getMessageExchange(); + RuntimeHelper.logError("InOut Message Exchange Provider Handler can not receive Fault on Provider side"); + } + + protected void processMessage() { + try { + processInMessageOnProvider((InOut) this.getMessageExchange()); + } catch (JBIException ex) { + ex.printStackTrace(); + } + } + + protected void processInMessageOnProvider(InOut inOutExchange) throws JBIException { + RuntimeHelper.getLogger().fine("Processing In Message on Provider side " + inOutExchange); + // receive IN message. + NormalizedMessage inMsg = inOutExchange.getInMessage(); + NormalizedMessage outMsg = null; + Fault fault = null; + Source inContent = null; + Source outContent = null; + Source faultContent = null; + String faultAsText = null; + // process in message + inContent = inMsg.getContent(); + // invoke the service operation + try { + QName opName = inOutExchange.getOperation(); + QName svcName = inOutExchange.getEndpoint().getServiceName(); + RuntimeHelper.getLogger().fine("xslt service info " + svcName + opName); + + XSLTFileLocator xsltFileLocator = this.mEndpoint.getXSLTFileLocator(); + XSLTService xsltService = this.mEndpoint.getXSLTService(); + + String xsltPath = xsltFileLocator.findXsltFile(svcName, opName); + RuntimeHelper.getLogger().fine("XsltPath " + xsltPath); + if (xsltPath == null) { + RuntimeHelper.getLogger().fine(" No XSLT File found in MAP " + + xsltFileLocator.printMap()); + } + outContent = xsltService.transform(inContent, xsltPath); + + } catch (Exception ex) { + // exception invoking the operation. so, set exception text as fault content. + ex.printStackTrace(); + faultAsText = RuntimeHelper.getExceptionAsText(ex); + String faultText = RuntimeHelper.getExceptionAsXmlText(ex); + faultContent = RuntimeHelper.createDOMSource(new StringReader(faultText)); + } + // set out or fault message + if (outContent != null) { + // set the out message content. + outMsg = inOutExchange.createMessage(); + inOutExchange.setOutMessage(outMsg); + normalizeOutMessage(inOutExchange, outMsg, outContent); + // outMsg.setContent(outContent); + } else if (faultContent != null) { + fault = inOutExchange.createFault(); + inOutExchange.setFault(fault); + fault.setContent(faultContent); // may need to normalize the content. + } + // send out or fault message. + // this.getDeliveryChannel().sendSync(inOutExchange, SEND_SYNC_TIMEOUT); + this.send(); + } + + private void normalizeOutMessage(MessageExchange me, NormalizedMessage normMsg, Source msgSrc) throws MessagingException { + try { + // DOMSource wrappedSource = wrapOutputMessage(me, msgSrc); + WSDL11JBIWrapper outWrapper = WSDL11JBIWrapper.createOutputWrapper( + this.mEndpoint.getWSDLOperation(me.getOperation())); + + // check if the output from the transformer is in a wrapped form + WSDL11JBIWrapper wrapper = WSDL11JBIWrapper.sourceToWrapper( + RuntimeHelper.sourceToDOMSource(msgSrc)); + if (wrapper != null) { + outWrapper.appendParts(wrapper.getParts()); + } else { + outWrapper.appendPart(RuntimeHelper.sourceToDOMSource(msgSrc)); + } + + normMsg.setContent(outWrapper.toDOMSource()); + + } catch (MessagingException ex) { + throw ex; + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSERuntime.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSERuntime.java new file mode 100644 index 000000000..fdad11739 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSERuntime.java @@ -0,0 +1,53 @@ +/* + * ProviderSERuntime.java + */ +package net.openesb.component.ServiceEngine-archetype; + +import net.openesb.component.ServiceEngine-archetype.common.ComponentRuntime; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.component.ServiceUnitManager; + +/** + * This class extends the ComponentRuntime that implements + * javax.jbi.component.Component interface required for the component contract + * at runtime. + * + * This class provides the component specific ComponentLifeCycle implementation + * as well as the component specific ServiceUnitManager implementation. + * + * Add any additional component runtime specific functionality here. + * + * @see javax.jbi.component.Component + * @see com.sun.jbi.sample.component.common.ComponentRuntime + * @see com.sun.jbi.sample.component.common.BasicComponentLifecycle + * @see + * com.sun.jbi.sample.component.common.deployment.AbstractServiceUnitManager + * @author chikkala + */ +public class ProviderSERuntime extends ComponentRuntime { + + /** + * Creates a new instance of MyEngineRuntime + */ + public ProviderSERuntime() { + super(); + } + + /** + * overriding the parent's createComponentLifeCycle to create component + * specific component lifecycle implementation. + */ + @Override + protected ComponentLifeCycle createComponentLifeCycle() { + return new ProviderSEComponentLifeCycle(this); + } + + /** + * overrides the parent's createServiceUnitManager to create component + * specific service unit manager + */ + @Override + protected ServiceUnitManager createServiceUnitManager() { + return new ProviderSESUManager(this); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSESUManager.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSESUManager.java new file mode 100644 index 000000000..e5350b2f8 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSESUManager.java @@ -0,0 +1,46 @@ +/* + * ProviderSESUManager.java + */ +package net.openesb.component.ServiceEngine-archetype; + +import net.openesb.component.ServiceEngine-archetype.common.RuntimeHelper; +import net.openesb.component.ServiceEngine-archetype.common.deployment.AbstractServiceUnitManager; +import net.openesb.component.ServiceEngine-archetype.common.deployment.ServiceUnit; +import java.util.logging.Logger; +import javax.jbi.management.DeploymentException; + +/** + * This class extends the AbstractServiceUnitManager to implement component + * specific service unit manager by creating the component specific ServiceUnit + * implementation. + * + * @see + * com.sun.jbi.sample.component.common.deployment.AbstractServiceUnitManager + * @see com.sun.jbi.sample.component.common.deployment.ServiceUnit + * @author chikkala + */ +public class ProviderSESUManager extends AbstractServiceUnitManager { + + private ProviderSERuntime mRuntime; + + /** + * Creates a new instance of ProviderSESUManager + */ + public ProviderSESUManager(ProviderSERuntime compRuntime) { + super(); + this.mRuntime = compRuntime; + } + + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + + protected String getComponentName() { + return RuntimeHelper.getComponentName(); + } + //TODO implement ProviderSEServiceUnit + + protected ServiceUnit createServiceUnit(String suName, String suRootPath) throws DeploymentException { + return new ProviderSEServiceUnit(suName, suRootPath); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSEServiceUnit.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSEServiceUnit.java new file mode 100644 index 000000000..14f80d8db --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/ProviderSEServiceUnit.java @@ -0,0 +1,60 @@ +/* + * ProviderSEServiceUnit.java + * + */ +package net.openesb.component.ServiceEngine-archetype; + +import net.openesb.component.ServiceEngine-archetype.common.deployment.ServiceUnit; +import net.openesb.component.ServiceEngine-archetype.common.deployment.ProviderEndpoint; +import net.openesb.component.ServiceEngine-archetype.common.deployment.SUDescriptor.Provides; +import javax.jbi.management.DeploymentException; +import javax.wsdl.Definition; + +/** + * This class extends the ServiceUnit to implement the component specific + * service unit processing. It creates the component specific ProviderEndpoint + * implementation to configure the service provider endpoint on this component + * deployed in the service unit. It also processes the deployment artifacts that + * are specific to the service provided by the component. + * + * @author chikkala + */ +public class ProviderSEServiceUnit extends ServiceUnit { + + private XSLTFileLocator mXsltFileLocator; + + /** + * Creates a new instance of ProviderSEServiceUnit + */ + public ProviderSEServiceUnit(String suName, String suRootPath) { + super(suName, suRootPath); + } + + protected XSLTFileLocator getXsltFileLocator() { + return this.mXsltFileLocator; + } + + @Override + protected ProviderEndpoint createProviderEndpoint(Provides provides, Definition wsdlDef) { + return new ProviderSEEndpoint(provides, wsdlDef, this); + } + + /** + * load and validates the component specific deployment artifacts. It loads + * the xsltmap properties into XSLTFileLocator which will be used to find + * the xslt file corresponding to a service operation. + */ + @Override + protected void loadOtherArtifacts() throws DeploymentException { + super.loadOtherArtifacts(); + // load any component specific service unit artifacts + if (this.mXsltFileLocator == null) { + try { + this.mXsltFileLocator = + new XSLTFileLocator(this.getSURootPath(), "xsltmap.properties"); + } catch (Exception ex) { + throw new DeploymentException(ex); + } + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/XSLTFileLocator.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/XSLTFileLocator.java new file mode 100644 index 000000000..a9ea5c3ac --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/XSLTFileLocator.java @@ -0,0 +1,207 @@ +/* + * XSLTFileLocator.java + */ +package net.openesb.component.ServiceEngine-archetype; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import javax.xml.namespace.QName; + +/** + * This class represents the component specific deployment artifact which reads + * the deployed "xsltmap.properties" file in the service unit and processes it + * to find the xslt file to be used for a particular operation on a service + * provided by the deployment. + *

+ * The "xsltmap.properties" file should contain two types of properties
+ * 1.for namespace prefix to namespaceURI map that starts with "xmlns." prefix like
+ *   "xmlns.tns-prefix=http://www.sun.com/jbi/examples/sample-service/echo"
+ * 2. a service description to xslt file properties with syntax like
+ *   "{tns-prefix}service-name=xslt_file_name"  and
+ *   "{tns-prefix}service-name.{tns-prefix}operation-name=xslt_file_name" and
+ *   "{tns-prefix}service-name.{tns-prefix}interface-name.operation-name=xslt_file_name" .
+ * the service description property is a "." delimited tokens that represents a serive
+ * or interface qname and a operation name. To locate xslt file either with service qname
+ * or service qname and operaton or serivice qname and interface qname and operation,
+ * all the three properties specified above should be there for each xslt file. for example,
+ *  xmlns.echo1=http://www.sun.com/jbi/examples/sample-service/echo
+ *  xmlns.echo2=http://www.sun.com/jbi/examples/sample-service/echo
+ *  {echo2}echoService=echo.xsl
+ *  {echo2}echoService.{echo1}echo=echo.xsl
+ *  {echo2}echoService.{echo1}echo.echo=echo.xsl
+ * 
+ * + * @author chikkala + */ +public class XSLTFileLocator { + + private Map mXsltFileMap; + + /** + * Creates a new instance of XsltLocator + */ + public XSLTFileLocator(String rootPath, String mapFile) throws Exception { + this.mXsltFileMap = new HashMap(); + initXsltLocator(rootPath, mapFile); + } + + private void initXsltLocator(String rootPath, String mapFilePath) throws Exception { + @SuppressWarnings("unchecked") + Map mapProps = loadMappingProperties(rootPath, mapFilePath); + + Map nsMap = new HashMap(); + Map xsltMap = new HashMap(); + + for (String name : mapProps.keySet()) { + String value = mapProps.get(name); + if (name.startsWith("{")) { + xsltMap.put(name, value); + } else if (name.startsWith("xmlns.")) { + String xmlns = name.substring(6); + nsMap.put(xmlns, value); + } + } + + for (String name : xsltMap.keySet()) { + String value = xsltMap.get(name); + String[] tokens = name.split("\\."); + String svcName = null; + String intrName = null; + String opName = null; + + if (tokens.length == 1) { + svcName = expandQName(tokens[0], nsMap); + } else if (tokens.length == 2) { + svcName = expandQName(tokens[0], nsMap); + opName = expandQName(tokens[1], nsMap); + } else if (tokens.length == 3) { + svcName = expandQName(tokens[0], nsMap); + intrName = expandQName(tokens[1], nsMap); + opName = tokens[2]; + } else { + System.out.println("invalid property name in xslt map property" + name); + } + + StringBuffer buff = new StringBuffer(); + buff.append(svcName); + if (intrName != null) { + buff.append("."); + buff.append(intrName); + } + if (opName != null) { + buff.append("."); + buff.append(opName); + } + File file = new File(rootPath, value); + String xsltFile = file.getAbsolutePath(); + this.mXsltFileMap.put(buff.toString(), xsltFile); + } + } + + private String expandQName(String qname, Map xmlnsMap) { + + // qname passed is "{prefix}localname" + QName temp = QName.valueOf(qname); + String prefix = temp.getNamespaceURI(); + String nsURI = xmlnsMap.get(prefix); + if (nsURI == null) { + nsURI = prefix; // just use the prefix as it is. + } + QName realQName = new QName(nsURI, temp.getLocalPart()); + return realQName.toString(); + } + + private Map loadMappingProperties(String rootPath, String mapFilePath) throws Exception { + File mapFile = new File(rootPath, mapFilePath); + Properties mapProps = new Properties(); + if (!mapFile.exists()) { + throw new Exception("Mapping file not found " + mapFilePath); + } + FileInputStream inStream = null; + try { + inStream = new FileInputStream(mapFile); + mapProps.load(inStream); + } catch (FileNotFoundException ex) { + ex.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); + } finally { + if (inStream != null) { + try { + inStream.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + return mapProps; + } + + /** + * return the xslt file mapped to either service name or service qname + + * operation qname + * + * @param serviceQName must be non null qname + * @param opQName can be null the xslt file can be located at service level. + */ + public String findXsltFile(QName serviceQName, QName opQName) { + StringBuffer buff = new StringBuffer(); + buff.append(serviceQName.toString()); + if (opQName != null) { + buff.append("."); + // workaround for the http soap bc bug which does not set the namespace + // uri on the op name. for time being use the serviceQName's namespace + String namespaceURI = opQName.getNamespaceURI(); + if (namespaceURI == null || namespaceURI.length() == 0) { + QName tempOp = + new QName(serviceQName.getNamespaceURI(), opQName.getLocalPart()); + buff.append(tempOp.toString()); + } else { + buff.append(opQName.toString()); + } + } + String xsltFile = this.mXsltFileMap.get(buff.toString()); + return xsltFile; + } + + /** + * return the xslt file mapped to either service name or service qname + + * interface qname + operation + * + * @param serviceQName must be non null service qname + * @param intrQName interface qname + * @param opName operation name ( not a qname) + */ + public String findXsltFile(QName serviceQName, QName intrQName, String opName) { + StringBuffer buff = new StringBuffer(); + buff.append(serviceQName.toString()); + if (intrQName != null) { + buff.append("."); + buff.append(intrQName.toString()); + } + if (opName != null) { + buff.append("."); + buff.append(opName); + } + String xsltFile = this.mXsltFileMap.get(buff.toString()); + return xsltFile; + } + + public String printMap() { + StringWriter buff = new StringWriter(); + PrintWriter out = new PrintWriter(buff); + for (String key : this.mXsltFileMap.keySet()) { + out.println("Key= " + key); + out.println("XsltFile= " + this.mXsltFileMap.get(key)); + } + out.close(); + return buff.getBuffer().toString(); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/XSLTService.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/XSLTService.java new file mode 100644 index 000000000..0b55945c8 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/XSLTService.java @@ -0,0 +1,105 @@ +/* + * XSLTService.java + */ +package net.openesb.component.ServiceEngine-archetype; + +import net.openesb.component.ServiceEngine-archetype.common.RuntimeHelper; +import java.io.File; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Properties; +import java.util.logging.Logger; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import org.w3c.dom.Document; + +/** + * This is a sample service implementation that takes the input as xml document + * and the xslt file to apply the xslt transformation on the input xml and + * return the transformed output xml. This implementation of the service is + * invoked when a InOut message exchange is processed to invoke a service + * provided by the engine. + * + * @author chikkala + */ +public interface XSLTService { + + /** + * this operation takes the input xml document and constructs the output xml + * document by applying the xslt in the file specified in xsltPath + * + * @param inputDoc input xml document + * @param xsltPath absolute file path of xslt file. + * @return transformed output xml document + */ + Source transform(Source inputDoc, String xsltPath) throws Exception; + + /** + * This class implements the echo service operations which the service + * engine will invoke when a InOut message exchange is processed to invoke a + * service provided by the engine. + */ + public static class XSLTServiceImpl implements XSLTService { + + private XSLTServiceImpl() { + } + + /** + * accessor to create/locate the service implementation + * + * @return echo service implementation + */ + public static XSLTService getInstance() { + return new XSLTServiceImpl(); + } + + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + + /** + * this operation takes the input xml document and constructs the output + * xml document with the same data to implement the echo. + * + * @param inputDoc input document + * @return output document + */ + public Source transform(Source inputDoc, String xsltPath) throws Exception { + Document outDoc = null; + StringBuffer inBuff = RuntimeHelper.readFromSource(inputDoc); + + getLogger().fine("############### TRANSFORMER INPUT MESSAGE BEGIN #################"); + getLogger().fine(inBuff.toString()); + getLogger().fine("############### TRANSFORMER INPUT MESSAGE END ##################"); + + TransformerFactory tf = null; + tf = TransformerFactory.newInstance(); + StreamSource xsltSource = new StreamSource(new File(xsltPath)); + Transformer xformer = tf.newTransformer(xsltSource); + + Properties params = new Properties(); //TODO get the pramas from the user file + for (Object name : params.keySet()) { + xformer.setParameter((String) name, params.get(name)); + } + StringWriter writer = new StringWriter(); + StreamResult result = new StreamResult(writer); + + DOMSource xmlSource = new DOMSource(RuntimeHelper.buildDOMDocument(new StringReader(inBuff.toString()))); + + xformer.transform(xmlSource, result); + + getLogger().fine("############### TRANSFORMER OUTPUT MESSAGE BEGIN #################"); + getLogger().fine(writer.getBuffer().toString()); + getLogger().fine("############### TRANSFORMER OUTPUT MESSAGE END ##################"); + + outDoc = RuntimeHelper.buildDOMDocument(new StringReader(writer.getBuffer().toString())); + DOMSource outSource = new DOMSource(outDoc); + + return outSource; + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java new file mode 100644 index 000000000..103e5c3b9 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java @@ -0,0 +1,138 @@ +/* + * AbstractMessageExchangeHandler.java + * + */ + +package net.openesb.component.ServiceEngine-archetype.common; + +import java.io.StringReader; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.Fault; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; +import javax.xml.namespace.QName; + +/** + * This class is an abstract implementation of the MessageExchangeHandler which + * provides the base implementation of the ME processing and provides hooks to + * extended classes to implement component specific processing. + * + * @author chikkala + */ +public abstract class AbstractMessageExchangeHandler implements MessageExchangeHandler { + + public static String IN_MESSAGE = "in"; + public static String OUT_MESSAGE = "out"; + + private MessageExchange mMessageExchange; + private ExchangeStatus mStatus; + /** Creates a new instance of AbstractMessageExchangeHandler */ + protected AbstractMessageExchangeHandler() { + this.mMessageExchange = null; + } + + protected abstract Logger getLogger(); + protected abstract DeliveryChannel getDeliveryChannel(); + protected abstract void validateMessageExchange() throws MessagingException; + protected abstract void processError(Exception ex); + protected abstract void processDone(); + protected abstract void processMessage(); + protected abstract void processFault(Fault fault); + + public final MessageExchange getMessageExchange() { + return this.mMessageExchange; + } + + public final void setMessageExchange(MessageExchange msgExchange) { + this.mMessageExchange = msgExchange; + } + + public final ExchangeStatus getMessageExchangeStatus() { + if ( this.mStatus != null ) { + return this.mStatus; + } else if ( this.mMessageExchange != null ) { + return this.mMessageExchange.getStatus(); + } else { + return null; + } + } + + public final void setMessageExchangeStatus(ExchangeStatus status) { + this.mStatus = status; + } + + protected void send() throws MessagingException { + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected boolean sendSync(long timeout) throws MessagingException { + return this.getDeliveryChannel().sendSync(this.mMessageExchange, timeout); + } + + protected void sendDone() throws MessagingException { + this.mMessageExchange.setStatus(ExchangeStatus.DONE); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void sendError(Exception ex) throws MessagingException { + this.mMessageExchange.setError(ex); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void sendFault(Exception ex, QName type, String name) throws MessagingException { + Fault fault = this.mMessageExchange.createFault(); + if ( ex != null ) { + String xmlText = RuntimeHelper.getExceptionAsXmlText(ex); + fault.setContent(RuntimeHelper.createDOMSource(new StringReader(xmlText))); + } + this.mMessageExchange.setFault(fault); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void processActive() { + Fault fault = this.getMessageExchange().getFault(); + if ( fault != null ) { + processFault(fault); + } else { + processMessage(); + } + } + /** + * implementation of the MessageExchangeHandler#processMessageExchange method. + */ + public void processMessageExchange(ExchangeStatus status, MessageExchange msgEx) { + + getLogger().fine("MessageExchangeHandler.processMessageExchange:status: " + status ); + + this.setMessageExchangeStatus(status); + this.setMessageExchange(msgEx); + + try { + validateMessageExchange(); + } catch (MessagingException ex) { + getLogger().log(Level.FINE, "Invalid message exchange for processing ", ex); + if ( this.getMessageExchange() != null ) { + try { + sendError(ex); + } catch (MessagingException errEx) { + getLogger().log(Level.FINE, "Can not send invalid message exchange error", errEx); + } + } + return; + } + + MessageExchange msgExchange = this.getMessageExchange(); + + if (ExchangeStatus.ACTIVE.equals(status) ) { + processActive(); + } else if (ExchangeStatus.DONE.equals(status) ) { + processDone(); + } else if (ExchangeStatus.ERROR.equals(status) ) { + processError(msgExchange.getError()); + } + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java new file mode 100644 index 000000000..2b05babe7 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java @@ -0,0 +1,395 @@ +/* + * AbstractComponentLifeCycle.java + */ + +package net.openesb.component.ServiceEngine-archetype.common; + +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.component.Component; +import javax.jbi.component.ComponentContext; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.MessagingException; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.StandardMBean; + +/** + * This class implements the javax.jbi.component.ComponentLifeCycle. This is an + * abstract class that keeps the reference to the component context and the lifecycle + * extension mbeans. It implements the lifecycle method and provide the extended methods + * for each lifecycle methods to implement component specific functionality. + *

+ * It makes sure that the mininum initialization required for the component + * lifecycle is implemented by this class or the classes extending this class. + *

+ * Another important functionality implemented in this class is that it initializes the global + * RuntimeContext for the component with the ComponentContext passed by the JBI runtime and the + * opened delivery channel to make them available globally to any class in the component implementation + * that may need it during component lifecycle + *

+ * Service engine or a binding component lifecycle implementation can directly extend + * this class for their required functionality and override some of the methods to provide + * their own implementation. + * + * @see javax.jbi.ComponentLifeCycle + * @author chikkala + */ +public class BasicComponentLifeCycle implements ComponentLifeCycle { + /** reference to the component runtime */ + private Component mCompRuntime; + /** component context */ + private ComponentContext mComponentContext; + /** Extension Mbean Name*/ + private ObjectName mExtensionMBeanName; + /** Extension Mbean Implementation*/ + private StandardMBean mExtensionMBeanImpl; + /** a message receiver that accepts messages from delivery channel */ + private MessageExchangeReceiver mMsgExchReceiver; + + /** + * constructor for the ComponentLifecycle implementation. + * @param compRuntime + */ + protected BasicComponentLifeCycle(Component compRuntime) { + this.mCompRuntime = compRuntime; + } + /** + * @return Component + */ + public final Component getComponentRuntime() { + return this.mCompRuntime; + } + /** + * @return ComponentContext component context. + */ + public final ComponentContext getComponentContext() { + return mComponentContext; + } + /** + * @return component name + */ + protected String getComponentName() { + return (this.mComponentContext != null) ? + this.mComponentContext.getComponentName() : null; + } + /////////////////////////////////////////////////////////////////////////// + // ComponentLifeCycle interface implemenation + /////////////////////////////////////////////////////////////////////////// + + /** + * Initializes the component lifecycle. This method makes sure that the + * component context passed by the jbi runtime is saved in the lifecycle + * object before calling the other component initialization methods to + * completely initialize the component. + * @param context Component context + * @see javax.jbi.component.ComponentLifeCycle#init(javax.jbi.component.ComponentContext) + * @throws javax.jbi.JBIException on error + */ + public final void init(ComponentContext context) throws JBIException { + + if ( context == null ) { + throw new JBIException("Null Component Context received in " + + "Component Lifecycle init "); + } + this.mComponentContext = context; // 0. save the component context passed by jbi framework. + // initialize the content + initGlobalContext(); // 1. Initialize component runtime context. + registerExtensionMBean(); // 2. Create and register extension mbean. + openDeliveryChannel(); // 3. Open delivery channel. + initMessageExchangeReceiver(); // 4. Create message exchange receiver. + doInit(); // 5. Do any component specific initialization such + // as static service providers and consumers initialization. + + this.getLogger().fine("Component " + this.getComponentName() + " initialized"); + } + + /** + * Starts the component. Extended classes can override/implement the methods called + * in this method to provide component specify start functionality. + * + * @see javax.jbi.component.ComponentLifeCycle#start() + * @throws javax.jbi.JBIException on error + */ + public final void start() throws JBIException { + + doStart(); // 1. do any other component specific start tasks such as + // activating any static service providers and consumers. + startMessageExchangeProcessing(); // 2. begin accepting and processing message exchanges. + + this.getLogger().fine("Component " + this.getComponentName() + " started"); + } + + /** + * Stop the component.Extended classes can override/implement the methods called + * in this method to provide component specify stop functionality. + * @throws javax.jbi.JBIException + * @see javax.jbi.component.ComponentLifeCycle#stop() + */ + public final void stop() throws JBIException { + + stopMessageExchangeProcessing(); // 1. stop accepting and processing message exchanges. + doStop(); // 2. do any other component specific stop tasks such as + // deactivating any static service providers and consumers. + this.getLogger().fine("Component " + this.getComponentName() + " stopped."); + } + + /** + * Shut down the component. Extended classes can override/implement the methods called + * in this method to provide component specify shut down functionality. + * @throws javax.jbi.JBIException + * @see javax.jbi.component.ComponentLifeCycle#shutDown() + */ + public final void shutDown() throws JBIException { + // clean up all resources. + shutdownMessageExchangeReceiver(); // 1. remove the message receiver. + closeDeliveryChannel(); // 2. close delivery channel + unregisterExtensionMBean(); // 3. unregister and remove extension mbean if exists. + doShutDown(); // 4. do any other component specific clean up tasks such + // as clean any static service providers and consumer resource. + this.getLogger().fine("Component " + this.getComponentName() + " shut down"); + } + /** + * create jmx object name for the extension mbean. default implementation does + * not required to have the extension mbean. + * @return ObjectName of the extension mbean + */ + protected ObjectName createExtensionMBeanName() { + return null; + } + /** + * gets the reference to the extension mbean name. + * @see javax.jbi.component.ComponentLifeCycle#getExtensionMBeanName() + * @return ObjectName of the extension mbean objectname or null if component + * does not support extension mbean + */ + public final ObjectName getExtensionMBeanName() { + if ( this.mExtensionMBeanName == null ) { + this.mExtensionMBeanName = this.createExtensionMBeanName(); + } + return this.mExtensionMBeanName; + } + /** + * create mbean implementation for the extension mbean as a StandardMBean. default + * implementation does not require the extension mbean + * @return the ExtensionMBean implementation as StandardMBean + */ + protected StandardMBean createExtensionMBean() { + return null; + } + /** + * gets the reference to the extension mbean. + * @return extension mbean implementation or null if component does not support. + */ + protected final StandardMBean getExtensionMBean() { + if ( this.mExtensionMBeanImpl == null ) { + this.mExtensionMBeanImpl = this.createExtensionMBean(); + } + return this.mExtensionMBeanImpl; + } + /** + * if there is an extension mbean supported by the component, then register + * it with the mbean server. + * @throws JBIException on error registering mbean + */ + protected final void registerExtensionMBean() throws JBIException { + // creatre the extension mbean's object name + ObjectName mbeanName = this.getExtensionMBeanName(); + // create the extension mbean implemenation. + StandardMBean mbeanImpl = this.getExtensionMBean(); + + if ( mbeanName == null || mbeanImpl == null ) { + this.getLogger().fine(this.getComponentName() + + " Does not have Extension MBean implemenation "); + return; + } + // register with mbean only if object name and implementation are non null + try { + MBeanServer mbServer = RuntimeHelper.getComponentContext().getMBeanServer(); + mbServer.registerMBean(mbeanImpl, mbeanName); + } catch (Exception e) { + throw new JBIException("Failed to register Extension MBean for " + + this.getComponentName(), e); + } + } + /** + * remove the registered extension mbean from the mbean server if any. + */ + protected final void unregisterExtensionMBean() { + ObjectName mbeanName = this.getExtensionMBeanName(); + if ( mbeanName == null ) { + return; + } + try { + MBeanServer mbServer = RuntimeHelper.getComponentContext().getMBeanServer(); + mbServer.unregisterMBean(mbeanName); + } catch (Exception e) { + this.getLogger().log(Level.WARNING, + "Failed to unregister Extension MBean from MBeanServer for " + this.getComponentName(), e); + } + } + /** + * creates MessageExchangeReceiver implementation that handles receiving and processing + * the message exchanges from the delivery channel. Component should implement + * this method to provide the MessageReceiver. + * + * Component may return null indicating that they don't need the message receiver + * that can receive and process message exchanges from delivery channel. For example, + * components that have only service consumers which send a synchronous messages to + * providers don't need this. + * + * @throws java.lang.Exception + * @return MessageExchangeReceiver implementation. null if the component does not support it. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle#createMessageExchangeReceiver + */ + protected MessageExchangeReceiver createMessageExchangeReceiver() { + return null; + } + /** + * returns the message exchange receiver implementation reference + * @return MessageExchangeReceiver interface + */ + protected final MessageExchangeReceiver getMessageExchangeReceiver() { + if ( this.mMsgExchReceiver == null ) { + this.mMsgExchReceiver = createMessageExchangeReceiver(); + } + return this.mMsgExchReceiver; + } + /** + * creates a message receiver object as part of the component initialization. + * @throws javax.jbi.JBIException + */ + protected void initMessageExchangeReceiver() throws JBIException { + // create and initialize the MessageExchangeReceiver + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.initReceiver(); + } + } + /** + * allows the component to accept the message exchange objects from the + * delivery channel and process it as part of the component startup process. + * @throws javax.jbi.JBIException + */ + protected void startMessageExchangeProcessing() throws JBIException { + // start message processing + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.startProcessing(); + } + } + /** + * stops the component from accepting the message exchange objects from the + * delivery channel as part of the component stop process + * @throws javax.jbi.JBIException + */ + protected void stopMessageExchangeProcessing() throws JBIException { + // stop message processing + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.stopProcessing(); + } + } + /** + * removes the message receiver as part of the component shutdown process + * @throws javax.jbi.JBIException + */ + protected void shutdownMessageExchangeReceiver() throws JBIException { + // clean up message processing. + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.shutdownReceiver(); + } + } + /** + * Returns logger initialized from the component context or a default logger. + * @return Logger + */ + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** + * initializes the RuntimeContext during component init lifecycle phase. This + * includes setting the ComponentContext and loggers etc. extended classes must + * save the component context in the RuntimeContext in this methods implementation. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle#initGlobalContext + */ + protected void initGlobalContext() { + RuntimeContext.getInstance().setComponentContext(this.getComponentContext()); + RuntimeContext.getInstance().setLogger(this.getClass().getName(), null); + } + /** opens the delivery channel to accept or send message exchange objects + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle#openDeliveryChannel + */ + protected void openDeliveryChannel() { + try { + DeliveryChannel channel = this.getComponentContext().getDeliveryChannel(); + RuntimeContext.getInstance().setDeliveryChannel(channel); + } catch (MessagingException ex) { + ex.printStackTrace(); + } + } + /** closes the delivery channel as part of the component shutdown process. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle#closeDeliveryChannel + */ + protected void closeDeliveryChannel() { + // closes delivery channel and remove the reference. + try { + DeliveryChannel channel = RuntimeHelper.getDeliveryChannel(); + if ( channel != null ) { + channel.close(); + } + } catch (MessagingException ex) { + ex.printStackTrace(); + } finally { + RuntimeContext.getInstance().setDeliveryChannel(null); + } + } + /** + * chance to extended classes to do any extra component specific init tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * initialized here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle#init method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle#init + */ + protected void doInit() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific start tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * activated here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle#start method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle#start + */ + protected void doStart() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific stop tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * deactivated here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle#stop method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle#stop + */ + protected void doStop() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific shutdown tasks.If the component + * supports static service providers or consumers without deployment support, they can be + * cleaned up here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle#shutdown method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle#shutdown + */ + protected void doShutDown() throws JBIException { + //NOOP + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/ComponentInstaller.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/ComponentInstaller.java new file mode 100644 index 000000000..04848ffa1 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/ComponentInstaller.java @@ -0,0 +1,272 @@ + /* + * ComponentInstaller.java + */ +package net.openesb.component.ServiceEngine-archetype.common; + +import java.util.List; +import java.util.logging.Level; +import javax.jbi.component.Bootstrap; +import javax.jbi.component.InstallationContext; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.StandardMBean; + +/** + * This class implements the javax.jbi.component.Bootstrap. This class implements + * the minimum required functionality for component installation contract + * of the jbi component in the jbi environment. It also takes care of maintaining + * the installation context reference and installation specific logger creation and + * installation extension mbean registration and unregistration during initialization + * and cleanup. Extended classes only need to supply the mbean name and its implementation + * object for the installation extensions. + * + * It makes sure that the installation context and the loggers are available to + * the classes extended from this class to add more installation specific functionality. + * + * Service engine or a binding component installation implementation can directly use + * this class or extend this class to add more functionality to their installation + * process. + * + * @see javax.jbi.Bootstrap + * @author chikkala + */ +public class ComponentInstaller implements Bootstrap { + /** default logger*/ + private Logger mDefLogger; + /** bootstrap logger */ + private Logger mBTLogger ; + /** Installation Context . */ + private InstallationContext mInstallationContext; + /** Extension Mbean Name*/ + private ObjectName mExtensionMBeanName; + /** Extension Mbean Implementation*/ + private StandardMBean mExtensionMBeanImpl; + + /** Constructor to create the ComponentInstaller. */ + public ComponentInstaller() { + } + /** + * @return InstallationContext of the component. + */ + public final InstallationContext getInstallationContext() { + return this.mInstallationContext; + } + protected String getComponentName() { + return (this.mInstallationContext != null) ? + this.mInstallationContext.getComponentName() : null; + } + /** + * @return logger initialized from the installation context or a default + * logger. + */ + protected Logger getLogger() { + // try init bootstrap logger + if (this.mBTLogger == null && this.mInstallationContext != null ) { + try { + this.mBTLogger = + this.mInstallationContext.getContext().getLogger(this.getClass().getName(), null); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + // init default logger if required + if ( this.mBTLogger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (this.mBTLogger != null) ? this.mBTLogger : this.mDefLogger; + } + /** + * Initializes the installation environment for a component. + * @see javax.jbi.component.Bootstrap#init(javax.jbi.component.InstallationContext) + */ + public final void init(InstallationContext installContext) throws javax.jbi.JBIException { + + if ( installContext == null ) { + throw new JBIException("Null Installation Context received in " + + "Component Bootstrap initialization"); + } + // save the installation context reference passed by the jbi framework. + this.mInstallationContext = installContext; + registerExtensionMBean(); // create and register extension mbean + doInit(); // do any other extra initialization required specific to the component installation. + // initialize logger + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component Installer initialized"); + } + /** + * default implementation just logs the method call. extended classes should override this. + * @see javax.jbi.component.Bootstrap#onInstall() + */ + public void onInstall() throws javax.jbi.JBIException { + //TODO: do required initializaton and resource creation + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component installed."); + } + /** + * default implementation just logs the method call. + * @see javax.jbi.component.Bootstrap#onUninstall() + */ + public void onUninstall() throws javax.jbi.JBIException { + //TODO: do clean up the resource and other stuff. + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component uninstalled"); + } + /** + * default noop implementation of the cleanup. + * @see javax.jbi.component.Bootstrap#cleanUp() + */ + public final void cleanUp() throws javax.jbi.JBIException { + + unregisterExtensionMBean(); // unregister extension mbean and remove it + doCleanUp(); // do any other extra cleanup specific to the component installation. + this.getLogger().fine( this.mInstallationContext.getComponentName() + + " Component Installer Cleaned up"); + } + + /** + * create jmx object name for the extension mbean. Extended classes should + * return the component specific installer extension mbean name here. + */ + protected ObjectName createExtensionMBeanName() { + return null; + } + /** + * default implementation that does not have extension mbean return null. + * @see javax.jbi.component.Bootstrap#getExtensionMBeanName() + */ + public final javax.management.ObjectName getExtensionMBeanName() { + if ( this.mExtensionMBeanName == null ) { + this.mExtensionMBeanName = createExtensionMBeanName(); + } + return this.mExtensionMBeanName; + } + /** + * create mbean implementation for the extension mbean as a StandardMBean. Extended + * classes should return the installer extension mbean implementation as the + * standard mbean. + */ + protected StandardMBean createExtensionMBean() { + return null; + } + /** + * returns the installation extension mbean implementation. + * @return StandardMBean for the extension mbean implementation. + */ + protected final StandardMBean getExtensionMBean() { + if ( this.mExtensionMBeanImpl == null ) { + this.mExtensionMBeanImpl = this.createExtensionMBean(); + } + return this.mExtensionMBeanImpl; + } + /** + * Chance to extended classes to do the component installation specific init. + * Installation context will be initialized before calling this method. So, + * initialize other things if required in this method. + * @throws javax.jbi.JBIException on error + * @see com.sun.jbi.sample.component.common.ComponentInstaller#init( + * javax.jbi.component.InstallationContext) + */ + protected void doInit() throws JBIException { + this.getLogger().info(this.getInstallationContext().getComponentName() + + " : Component Installer initialized"); + } + /** + * Chance to extended classes to do the component installation specific cleanup. + * ExtensionMbean will be unregistered before calling this method. + * @throws javax.jbi.JBIException on error + * @see com.sun.jbi.sample.component.common.ComponentInstaller#cleanUp( + * javax.jbi.component.InstallationContext) + */ + protected void doCleanUp() throws JBIException { + this.getLogger().fine(this.getInstallationContext().getComponentName() + + " : Component Installer doCleanUp"); + } + /** + * if there is an extension mbean supported by the component, then register + * it with the mbean server. + */ + protected void registerExtensionMBean() throws JBIException { + // creatre the installation extension mbean's object name + ObjectName mbeanName = this.getExtensionMBeanName(); + // create the extension mbean implemenation if the object name is created. + StandardMBean mbeanImpl = this.getExtensionMBean(); + + if ( mbeanName == null || mbeanImpl == null ) { + this.getLogger().fine(this.getComponentName() + + " Does not have Installation Extension MBean implemenation "); + return; + } + // register with mbean only if object name and implementation are non null + try { + MBeanServer mbServer = this.getInstallationContext().getContext().getMBeanServer(); + mbServer.registerMBean(mbeanImpl, mbeanName); + } catch (Exception e) { + throw new JBIException("Failed to register Installation Extension MBean for " + + this.getComponentName(), e); + } + } + /** + * remove the registered extension mbean from the mbean server. + */ + protected void unregisterExtensionMBean() { + ObjectName mbeanName = this.getExtensionMBeanName(); + if ( mbeanName == null ) { + return; + } + try { + MBeanServer mbServer = this.getInstallationContext().getContext().getMBeanServer(); + mbServer.unregisterMBean(mbeanName); + } catch (Exception e) { + this.getLogger().log(Level.WARNING, + "Failed to unregister Installation extension MBean for " + this.getComponentName(), e); + } + } + /** + * This method is called by the JBI runtime to allow a component to upgrade + * it's workspace and any existing Service Units to match the new version of + * the component. The JBI runtime copies the existing workspace root to the + * new workspace root prior to calling this method, so that the component + * can examine the contents of the workspace root to determine the version + * of the component from which the upgrade is being made. All updates to the + * workspace root are done in-place; in the event of a failure, the JBI + * runtime reverts back to the original workspace root, the original install + * root, and the original Service Unit roots for the component. + * + * Note1: The component must ensure that it never holds open references + * to any files in the workspace root or any of the Service Unit roots upon + * returning from this method. Failure to do so will cause problems when + * the runtime attempts to complete the upgrade processing. + * + * Note2: The installation context that is normally initialized + * by the runtime by calling #init method of the javax.jbi.Bootstrap interface + * before install and uninstall will not be called before calling this + * upgrade method. So, installation context can not be used in this method's + * implementation. + * + * Note3: Since there won't be any installation context available, the logger + * that returned from the #getLogger method is a default logger created using + * the package name of this class or extended class if the method is overridden + * in the extended class. + * + * @param workspaceRoot the workspace root for the new version of the + * component that will replace the currently installed version. This is + * populated with the contents of the original workspace root and the + * component must update it to match the new version of the component. + * @param serviceUnitRoots a list of directory paths to all of the Service + * Units currently deployed to the component. The component must update all + * of these to match the new version of the component. + * @exception JBIException when there is an error requiring that the upgrade + * be terminated. + */ + public void upgrade(String workspaceRoot, List serviceUnitRoots) + throws javax.jbi.JBIException + { + //TODO: override this method in the extended class to handle the + // workspace root and service unit roots upgrade according to the + // component's requirement. + this.getLogger().fine("Default upgrade implementation. " + + "TODO: Implement workspace root and service unit roots upgrade."); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/ComponentRuntime.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/ComponentRuntime.java new file mode 100644 index 000000000..6631df0ea --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/ComponentRuntime.java @@ -0,0 +1,171 @@ +/* + * ComponentRuntime.java + */ +package net.openesb.component.ServiceEngine-archetype.common; + +import java.util.logging.Logger; +import javax.jbi.component.Component; +import javax.jbi.component.ComponentContext; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.component.ServiceUnitManager; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.servicedesc.ServiceEndpoint; +import org.w3c.dom.Document; +import org.w3c.dom.DocumentFragment; + +/** + * This class implements javax.jbi.component.Component interface which is + * responsible for creating the Component Lifecycle implementation and the + * ServiceUnitManager implementation for the jbi component. + * + * This class makes sure that non null component lifecycle implementation is + * returns by this class or any classes extended from this class which is + * required as a component contract. It also provides default implementation of + * all methods of the Component interface which the extended classes can + * override to add more functionality. + * + * @see javax.jbi.component.Component + * @author chikkala + */ +public class ComponentRuntime implements Component { + /** Component LifeCycle implementation */ + private ComponentLifeCycle mLifeCycle; + /** ServiceUnitManager implementation */ + private ServiceUnitManager mSUManager; + /** default logger*/ + private Logger mDefLogger; + + /** Creates a new instance of ComponentImpl */ + public ComponentRuntime() { + this.mLifeCycle = null; + this.mSUManager = null; + } + /** + * returns the ComponentContext. Any component runtime class extended from + * this class can override this method to return their own reference to the + * ComponentContext. + * @return ComponentContext component context. + */ + public ComponentContext getComponentContext() { + ComponentContext ctx = null; + if ( this.mLifeCycle != null && this.mLifeCycle instanceof BasicComponentLifeCycle ) { + ctx = ((BasicComponentLifeCycle) this.mLifeCycle).getComponentContext(); + } + return ctx; + } + /** + * Returns logger initialized from the component context or a default logger. + * @return Logger + */ + public Logger getLogger() { + Logger logger = null; + if ( this.mLifeCycle != null && this.mLifeCycle instanceof BasicComponentLifeCycle ) { + logger = ((BasicComponentLifeCycle) this.mLifeCycle).getLogger(); + } + // init default logger if required + if ( logger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (logger != null) ? logger : this.mDefLogger; + } + /** + * return the ComponentLifeCycle implementation. if returned null, the + * ComponentLifeCycleImpl will be used as the component lifecycle + * Extended classes can override this method and do their own ComponentLifecyle + * specific creation. + */ + protected ComponentLifeCycle createComponentLifeCycle() { + return new BasicComponentLifeCycle(this); + } + /** + * Get the life cycle control interface for this component. + * + * @return the life cycle control interface for this component + * @see javax.jbi.Component#getLifeCycle() + */ + public final ComponentLifeCycle getLifeCycle() { + if ( this.mLifeCycle == null ) { + this.mLifeCycle = createComponentLifeCycle(); + if ( this.mLifeCycle == null ) { + this.getLogger().fine("Creating basic component lifecycle implemenation"); + // use the default ComponentLifeCycle Impl if a component + // specific implementation return null in createComponentLifeCycle. + this.mLifeCycle = new BasicComponentLifeCycle(this); + } + } + return this.mLifeCycle; + } + /** + * if this component supports service unit deployment, then return the + * service unit manager, else return null. + * Extended classes can override this method and do their own ServiceUnitManager + * specific creation. + */ + protected ServiceUnitManager createServiceUnitManager() { + return null; + } + /** + * Get the Service Unit manager for this component. + * + * @return the ServiceUnitManager for this component, or + * null if there is none. + * @see javax.jbi.Component#getServiceUnitManager() + */ + public final ServiceUnitManager getServiceUnitManager() { + if ( this.mSUManager == null ) { + this.mSUManager = createServiceUnitManager(); + } + return this.mSUManager; + } + /** + * Retrieves a DOM representation containing metadata which describes the + * service provided by this component, through the given endpoint. + * + * Default implementation does not support service description. + * + * @see javax.jbi.Component#getServiceDescription(javax.jbi.servicedesc.ServiceEndpoint) + */ + public Document getServiceDescription(ServiceEndpoint serviceEndpoint) { + return null; + } + /** + * This method is called by JBI to check if this component, in the role of + * provider of the service indicated by the given exchange, can actually + * perform the operation desired. + * + * Default implementation has no policy and allows all exchanges with consumer. + * + * @see javax.jbi.Component#isExchangeWithProviderOkay( + * javax.jbi.servicedesc.ServiceEndpoint, javax.jbi.messaging.MessageExchange) + */ + public boolean isExchangeWithConsumerOkay( + ServiceEndpoint serviceEndpoint, MessageExchange messageExchange) { + return true; + } + /** + * This method is called by JBI to check if this component, in the role of + * consumer of the service indicated by the given exchange, can actually + * interact with the provider properly. The provider is described by the + * given endpoint and the service description supplied by that endpoint. + * + * Default implementation has no policy and allows all exchanges with provider. + * + * @see javax.jbi.Component#isExchangeWithProviderOkay( + * javax.jbi.servicedesc.ServiceEndpoint, javax.jbi.messaging.MessageExchange) + */ + public boolean isExchangeWithProviderOkay( + ServiceEndpoint serviceEndpoint, MessageExchange messageExchange) { + return true; + } + /** + * Resolve the given endpoint reference. + * + * Default implementation does not have any XML dialect. So can not resolve the + * endpoint from the document fragment. + * + * @see javax.jbi.Component#resolveEndpointReference(org.w3c.dom.DocumentFragment) + */ + public ServiceEndpoint resolveEndpointReference(DocumentFragment documentFragment) { + return null; + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java new file mode 100644 index 000000000..7a9b7cf4a --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java @@ -0,0 +1,177 @@ +/* + * DefaultMessageExchangeReceiver.java + * + */ + +package net.openesb.component.ServiceEngine-archetype.common; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import javax.jbi.JBIException; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; + +/** + * This class implements MessageExchangeReceiver interface. This is a default implementation that + * demonstrates the multi-threaded environment to receive and process message exchanges from the + * delivery channel. It uses a main thread to receive message exchanges from the delivery channel + * and then processes the received message exchanges in a individual threads from the thread pool. + * The controller methods of MessageExchangeReceiver controls the main thread and the thread pool + * execution. + * + * @author chikkala + */ +public class DefaultMessageExchangeReceiver implements MessageExchangeReceiver { + + /** delivery channel accept time out */ + private final static long DC_ACCEPT_TIME_OUT = 3000; // milliseconds + /** receiver thread wait time before polling for messages after woke up **/ + private final static long RECEIVER_WAIT_TIME = 2000; // milliseconds + /** receiver thread wait time before force shutdown */ + private final static long RECEIVER_SHUTDOWN_WAIT_TIME = 10; // seconds + /** handler threads wait time before forced shutdown */ + private final static long HANDLERS_SHUTDOWN_WAIT_TIME = 30; // seconds + /** handler thread pool size */ + private final static int HANDLER_THREAD_POOL_SIZE = 5; + /** receiver thread accept message exchange condition */ + private Boolean mCanAccept = false; + /** receiver thread termination condition */ + private Boolean mContinue = true; + /** receiver thread executor service */ + private ExecutorService mReceiverThreadMgr; + /** handler thread executor service */ + private ExecutorService mHandlerThreadPool; + + /** no default constructor for extended classes */ + public DefaultMessageExchangeReceiver() { + } + /** + * this method is called from the ComponentLifecyle.init method of the AbstractComponentLifecycle + * to initialize the message exchange receiving resources such as threads and thread pools + * throws JBIException on error + */ + public final void initReceiver() throws JBIException { + + this.mHandlerThreadPool = Executors.newFixedThreadPool(HANDLER_THREAD_POOL_SIZE); + this.mReceiverThreadMgr = Executors.newSingleThreadExecutor(); + + this.mReceiverThreadMgr.execute(new Runnable() { + public void run() { + Thread t = Thread.currentThread(); + while ( mContinue ) { + if (mCanAccept) { + receiveAndProcessMessageExchange(); + } else { + try { + t.sleep(RECEIVER_WAIT_TIME); + } catch (InterruptedException interruptException) { + // someone must have interrupted this thread + // do nothing + RuntimeHelper.logDebug("Interrupted the MessageReceiverThread in Sleep"); + } + } + } + } + }); + } + /** + * this method is called from the ComponentLifecyle.shutdown method of the AbstractComponentLifecycle + * to cleanup the message exchange receiving resources such as threads and thread pools. + * throws JBIException on error + */ + public final void shutdownReceiver() throws JBIException { + + synchronized ( mContinue ) { + mContinue = false; + } + boolean terminated = false; + try { + this.mReceiverThreadMgr.shutdown(); + terminated = this.mReceiverThreadMgr.awaitTermination( + RECEIVER_SHUTDOWN_WAIT_TIME, TimeUnit.SECONDS); + } catch (InterruptedException ex) { + RuntimeHelper.logDebug(ex); + } finally { + if ( !terminated ) { + RuntimeHelper.logDebug("Message Receiver not shutdown. Forcing shutdown"); + this.mReceiverThreadMgr.shutdownNow(); + } + } + shutdownHandlers(); + } + /** + * shutdown all the working threads from the thread pool. + */ + private final void shutdownHandlers() throws JBIException { + + boolean terminated = false; + try { + this.mHandlerThreadPool.shutdown(); + terminated = this.mHandlerThreadPool.awaitTermination( + HANDLERS_SHUTDOWN_WAIT_TIME, TimeUnit.SECONDS); + } catch (InterruptedException ex) { + RuntimeHelper.logDebug(ex); + } finally { + if ( !terminated ) { + RuntimeHelper.logDebug("Handler threads not shutdown. Forcing shutdown"); + this.mHandlerThreadPool.shutdownNow(); + } + } + } + /** + * this method is called from the ComponentLifecyle.start method of the AbstractComponentLifecycle + * to start receiving the message exchanges from the delivery channel and process them. + * throws JBIException on error + */ + public final void startProcessing() throws JBIException { + + synchronized ( this.mCanAccept ) { + this.mCanAccept = true; + } + } + /** + * this method is called from the ComponentLifecyle.stop method of the AbstractComponentLifecycle + * to stop receiving the message exchanges from the delivery channel. + * throws JBIException on error + */ + public final void stopProcessing() throws JBIException { + + synchronized ( this.mCanAccept ) { + this.mCanAccept = false; + } + } + + protected MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeHelper.getMessageExchangeSupport(); + } + + private void receiveAndProcessMessageExchange() { + try { + DeliveryChannel channel = RuntimeHelper.getDeliveryChannel(); + if ( channel == null ) { + RuntimeHelper.logDebug("DeliveryChannel Not Opened for receiving messages"); + return; + } + final MessageExchange msgExchange = channel.accept(DC_ACCEPT_TIME_OUT); + if ( msgExchange == null ) { + // delivery channel timeout occurred. do nothing. + // RuntimeHelper.logDebug("DeliveryChannel returned null message exchange from accept"); + return; + } + final ExchangeStatus status = msgExchange.getStatus(); + // process message exchange in a separate thread + this.mHandlerThreadPool.execute(new Runnable() { + public void run() { + getMessageExchangeSupport().fireMessageExchangeReceived(status, msgExchange); + } + }); + + } catch (MessagingException ex) { + RuntimeHelper.logWarning(ex); + ex.printStackTrace(); + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java new file mode 100644 index 000000000..2288d287e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java @@ -0,0 +1,28 @@ +/* + * MessageExchangeHandler.java + * + */ + +package net.openesb.component.ServiceEngine-archetype.common; + +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; + +/** + * This interface is a Handler to perform message exchanges when the component + * receives the MessageExchange object from the delivery channel. + * Implementation of this interface should implement the processing of + * the active, error, done status of the MessageExchange object according to + * the MEP for which the MessageExchange object is created. + * + * @author chikkala + */ +public interface MessageExchangeHandler { + /** + * this method will be invoked to process the MessageExchange + * object. + * @param msgExchange MessageExchange object to process. + */ + void processMessageExchange(ExchangeStatus status, MessageExchange msgExchange); + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/MessageExchangeListener.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/MessageExchangeListener.java new file mode 100644 index 000000000..8098dfbb9 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/MessageExchangeListener.java @@ -0,0 +1,33 @@ +/* + * MessageExchangeListener.java + */ + +package net.openesb.component.ServiceEngine-archetype.common; + +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; + +/** + * This interface defines the notification mechanism with which the message exchange object received + * from the delivery channel is processed by the interesting parties. A particular service endpoint + * implementation would first register the implementation of this interface with MessageExchangeSupport + * to get the notification of a received message exchange on a particular service endpoint and the + * implementation of the interface would process the message exchange when notified. + * + * When the com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver receives the message exchange + * object, it asks the MessageExchangeSupport to notify the MessageExchangeLister that is registered for the + * received message exchange object to process the message exchange object. + * @see com.sun.jbi.sample.component.common.MessageExchangeSupport + * @see com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @author chikkala + */ +public interface MessageExchangeListener { + /** + * MessageExchangeSupport will call this method to notify the lister implementation that a + * message exchange is received from the delivery channel. + * @param me MessageExchange Object + */ + void messageExchangeReceived(ExchangeStatus status, MessageExchange me); +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java new file mode 100644 index 000000000..b60587454 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java @@ -0,0 +1,44 @@ +/* + * MessageExchangeReceiver.java + * + */ + +package net.openesb.component.ServiceEngine-archetype.common; + +import javax.jbi.JBIException; + +/** + * This interface provides the methods can controls the receiving and processing of the message + * exchange objects from the delivery channel during the component lifecycle operations. + * The implementation of this interface can use multi-threaded environment to receive and process + * message exchanges from the delivery channel during the component lifecycle. + * @see com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver + * @author chikkala + */ +public interface MessageExchangeReceiver { + /** + * this method is called from the ComponentLifecyle.init method of the AbstractComponentLifecycle + * to initialize the message exchange receiving resources such as threads and thread pools + * throws JBIException on error + */ + void initReceiver() throws JBIException; + /** + * this method is called from the ComponentLifecyle.start method of the AbstractComponentLifecycle + * to start receiving the message exchanges from the delivery channel and process them. + * throws JBIException on error + */ + void startProcessing() throws JBIException; + /** + * this method is called from the ComponentLifecyle.stop method of the AbstractComponentLifecycle + * to stop receiving the message exchanges from the delivery channel. + * throws JBIException on error + */ + void stopProcessing() throws JBIException; + /** + * this method is called from the ComponentLifecyle.shutdown method of the AbstractComponentLifecycle + * to cleanup the message exchange receiving resources such as threads and thread pools. + * throws JBIException on error + */ + void shutdownReceiver() throws JBIException; + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java new file mode 100644 index 000000000..3297b3430 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java @@ -0,0 +1,167 @@ +/* + * MessageExchangeSupport.java + * + */ + +package net.openesb.component.ServiceEngine-archetype.common; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessageExchange.Role; +import javax.xml.namespace.QName; + +/** + * This class supports the registering and unregistering MessageExchangeListeners and the + * MessageExchangeHandlers that can be used to process the received message exchange from a + * delivery channel. A global reference to this class will be created in RuntimeContext object to + * provide access to this class from any where in the component runtime. + * + * A ProviderEndpoint or ConsumerEndpoint interested in a MessageExchange received from a delivery + * channel for a particular service endpoint will register the MessageExchangeListener with this + * class. The DefaultMessageExchangeReceiver when received a message exchange object from the delivery + * channel uses MessageExchangeSupport.processMessageExchange method to notify the registered listener. + * + * The MessageExchangeListener implementation ( ProviderEndpoint or ConsumerEndpoint ) while processing + * received message ( messageExchangeReceived()) will create and register the message exchange handlers + * to process the message exchange. + * + * @see RuntimeContext#getMessageExchangeSupport + * @see RuntimeHelper#getMessageExchangeSupport + * @see DefaultMessageExchangeReceiver#receiveAndProcessMessageExchange + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @author chikkala + */ +public class MessageExchangeSupport { + /** listener map to notify a message exchange received event */ + private Map mListeners; + /** handlers that can process the message exchange */ + private Map mHandlers; + /** Creates a new instance of MessageExchangeSupport */ + public MessageExchangeSupport() { + this.mListeners = Collections.synchronizedMap(new HashMap()); + this.mHandlers = Collections.synchronizedMap(new HashMap()); + } + /** + * generates key that will be used to store the MessageExchangeListener objects. + * @param serviceName QName of the service + * @param endpointName endpoint name of the service. + */ + public String createListenerKey(Role role, QName interfaceName, QName serviceName, String endpointName) { + + StringBuffer strBuff = new StringBuffer(); + strBuff.append(interfaceName).append("+"); + strBuff.append(serviceName).append("+"); + strBuff.append(endpointName).append("+"); + String roleType = null; + if ( Role.CONSUMER.equals(role) ) { + roleType = "CONSUMER"; + } else if ( Role.PROVIDER.equals(role) ) { + roleType = "PROVIDER"; + } + strBuff.append(roleType); + return strBuff.toString(); + } + /** + * adds message exchange listener who are interested in receiving the notification when the + * message exchange is received from delivery channel. The listener can be registered with the + * following combination of the parameters: (role,interfaceName,serviceName, endpointName), + * (role,interfaceName,null, null), (role, null,serviceName, endpointName), (role, null,serviceName, null) + * + * @param role role of the message exchange listener PROVIDER or CONSUMER - can not be null. + * @param interfaceName QName of the interface ( protType ) - can be null if the serviceName is not null + * @param serviceName QName of the service - can be null if interfaceName is not null. + * @param endpointName endpoint name of the service. - can be null if the serviceName is not null. + * @param listener MessageExchangeListener object + */ + public synchronized void addMessageExchangeListener(Role role, QName interfaceName, QName serviceName, String endpointName, MessageExchangeListener listener) { + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + this.mListeners.put(key, listener); + } + /** + * removes any message exchange listener registered for the service endpoint specified by the serviceName and + * endpoint name. + * @param serviceName QName of the service + * @param endpointName endpoint name of the service. + */ + public synchronized void removeMessageExchangeListener(Role role, QName interfaceName, QName serviceName, String endpointName) { + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + MessageExchangeListener listener = this.mListeners.remove(key); + if ( listener == null ) { + RuntimeHelper.getLogger().fine("No message exchange listener removed with key " + key); + } + } + /** + * finds the MessageExchangeListner registers for the endpoint for which the message exchange is + * received and call the method on the listener + */ + public boolean fireMessageExchangeReceived(ExchangeStatus status, MessageExchange me) { + boolean notified = false; + Role role = me.getRole(); + QName interfaceName = me.getInterfaceName(); + QName serviceName = me.getEndpoint().getServiceName(); + String endpointName = me.getEndpoint().getEndpointName(); + // lookup with complete service description ( role + interface + service + endpoint ) + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + MessageExchangeListener listener = this.mListeners.get(key); + + if ( listener == null ) { // lookup with role+interface name + key = createListenerKey(role, interfaceName, null, null); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { // lookup with role + serviceName + endpointName + key = createListenerKey(role, null, serviceName, endpointName); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { // lookup with with role + serviceName + key = createListenerKey(role, null, serviceName, null); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { + RuntimeHelper.getLogger().fine("Could not find listener for message exchange" + me); + notified = false; + } else { + listener.messageExchangeReceived(status,me); + notified = true; + } + return notified; + } + /** + * registers the MessageExchangeHandler implementation against the message exchange id. + * @param me MessageExchange for which the handler need to be assigned + * @param handler MessageExchangeHandler implementation that will be registers. + */ + public synchronized void addMessageExchangeHandler(MessageExchange me, MessageExchangeHandler handler) { + this.mHandlers.put(me.getExchangeId(), handler); + } + /** + * removes the MessageExchangeHandler for the particular message exchange object + */ + public synchronized void removeMessageExchangeHandler(MessageExchange me) { + MessageExchangeHandler handler = this.mHandlers.remove(me.getExchangeId()); + if ( handler == null ) { + RuntimeHelper.getLogger().fine("No MessageExchangeHandler found for removing " + me.getExchangeId()); + } + } + /** + * looks up the registered message exchange handler for the message exchange object + * @param me MessageExchangeHandler. + */ + public synchronized MessageExchangeHandler findMessageExchangeHandler(MessageExchange me) { + return this.mHandlers.get(me.getExchangeId()); + } + /** + * looks up the registered message exchange handler for the message exchange object with Id + * @param exchangeId message exchange object's id + */ + public synchronized MessageExchangeHandler findMessageExchangeHandler(String exchangeId) { + return this.mHandlers.get(exchangeId); + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/RuntimeContext.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/RuntimeContext.java new file mode 100644 index 000000000..ecab3761e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/RuntimeContext.java @@ -0,0 +1,173 @@ +/* + * RuntimeContext.java + * + */ + +package net.openesb.component.ServiceEngine-archetype.common; + +import java.util.logging.Logger; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; + +/** + * This class is global context for all the component runtime to store and + * retrieve the information that should be available anywhere in the component runtime. + * + * Each instance variable of this class will be initialized at various points of the + * component runtime using setter methods on this class. + * + * The two important objects that will be initialized and available from this context are + * ComponentContext and the opened DeliveryChannel objects both of which will be set from the + * implementation {@link BasicComponentLifeCycle}. + * + * Note that the ComponentContext from this global context will not be available until + * the jbi framework calls the init method of the ComponentLifeCycle of the component and + * then intern the implementation of the init method sets the context. + * + * @see BasicComponentLifeCycle#initGlobalContext + * @see BasicComponentLifeCycle#openDeliveryChannel + * @see BasicComponentLifeCycle#closeDeliveryChannel + * @author chikkala + */ +public final class RuntimeContext { + /** RuntimeContext singleton instance */ + private static RuntimeContext sRuntimeContext; + /** default logger*/ + private Logger mDefLogger; + /** Logger object. */ + private Logger mLogger; + /** Holds value of property ComponentContext. */ + private ComponentContext mComponentContext; + /** Holds value of property DeliveryChannel. */ + private DeliveryChannel mDeliveryChannel; + /** MessageExchange processing support **/ + private MessageExchangeSupport mMESupport; + + /** outside code can not instantiate RuntimeContext */ + private RuntimeContext() { + } + /** + * @return RuntimeContext instance. + */ + public static RuntimeContext getInstance() { + if ( sRuntimeContext == null ) { + synchronized (RuntimeContext.class) { + if ( sRuntimeContext == null ) { + sRuntimeContext = new RuntimeContext(); + } + } + } + return sRuntimeContext; + } + /** + * Getter for to obtaining ComponentContext from any where in the component runtime. + * @return ComponentContext. + */ + public ComponentContext getComponentContext() { + return this.mComponentContext; + } + /** + * Sets the Component context reference in Runtime context for global access + * any class in the component runtime. + * com.sun.jbi.sample.component.common.AbstractComponentLifeCycle#initContext + * method implementation should call this method to set the global context. + * see com.sun.jbi.sample.component.common.DefaultComponentLifeCycle#initContext + * for details. + * @param componentContext New value of property ComponentContext. + * @see BasicComponentLifeCycle#initGlobalContext + */ + public void setComponentContext(ComponentContext componentContext) { + if ( this.mComponentContext != null ) { + (new IllegalStateException("Component Context already " + + "initialized in RuntimeContext")).printStackTrace(); + } + this.mComponentContext = componentContext; + } + /** + * Getter for obtaining opened delivery channel from any where in the component runtime. + * @return DeliveryChannel. + */ + public DeliveryChannel getDeliveryChannel() { + return this.mDeliveryChannel; + } + /** + * Sets the opened delivery channel reference in Runtime context for global access + * any class in the component runtime. + * com.sun.jbi.sample.component.common.AbstractComponentLifeCycle#initContext + * method implementation should call this method to set the global context. + * see com.sun.jbi.sample.component.common.DefaultComponentLifeCycle#initContext + * for details. + * + * @param componentContext New value of property ComponentContext. + */ + public void setDeliveryChannel(DeliveryChannel deliveryChannel) { + if ( deliveryChannel != null && this.mDeliveryChannel != null ) { + (new IllegalStateException("Delivery Channel already " + + "initialized in RuntimeContext")).printStackTrace(); + } + this.mDeliveryChannel = deliveryChannel; + } + /** + * Sets the logger. + * + * @param name name for the Logger. + * @param resourceBundle resource bundle for the logger. can be null. + */ + public void setLogger(String name, String resourceBundle) { + + if (this.mComponentContext != null) { + // get the logger from component context if the component context is not null + try { + this.mLogger = this.mComponentContext.getLogger(name, resourceBundle); + } catch (Exception ex) { + ex.printStackTrace(); + } + } else { + this.mDefLogger = Logger.getLogger(name, resourceBundle); + } + } + /** + * Returns the logger. + * + * @return Logger + */ + public Logger getLogger() { + + // try init logger + if (this.mLogger == null && this.mComponentContext != null ) { + try { + this.mLogger = + this.mComponentContext.getLogger(this.getClass().getName(), null); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + // init default logger if required + if ( this.mLogger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (this.mLogger != null) ? this.mLogger : this.mDefLogger; + } + /** + * Returns the Component Name if the ComponentContext is set. else null + * @return component name + */ + public String getComponentName() { + String componentName = null; + if (this.mComponentContext != null) { + componentName = this.mComponentContext.getComponentName(); + } + return componentName; + } + /** + * Global MessageExchangeSupport reference. Various classes in the common + * component runtime would use this method to obtain the MessageExchangeSupport + * for processing message exchange objects received from delivery channel. + */ + public MessageExchangeSupport getMessageExchangeSupport() { + if ( this.mMESupport == null ) { + this.mMESupport = new MessageExchangeSupport(); + } + return this.mMESupport; + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/RuntimeHelper.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/RuntimeHelper.java new file mode 100644 index 000000000..633ce58ca --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/RuntimeHelper.java @@ -0,0 +1,357 @@ +/* + * RuntimeHelper.java + */ + +package net.openesb.component.ServiceEngine-archetype.common; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stream.StreamResult; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * This is a helper class that have bunch of methods for xml processing. + * @author chikkala + */ +public class RuntimeHelper { + + public static Logger getLogger() { + return RuntimeContext.getInstance().getLogger(); + } + + public static void logWarning(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.WARNING, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().warning(logObj.toString()); + } + } + + public static void logError(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.SEVERE, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().severe(logObj.toString()); + } + } + + public static void logDebug(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.FINER, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().finer(logObj.toString()); + } + } + + public static String getComponentName() { + return RuntimeContext.getInstance().getComponentName(); + } + public static ComponentContext getComponentContext() { + return RuntimeContext.getInstance().getComponentContext(); + } + public static DeliveryChannel getDeliveryChannel() { + return RuntimeContext.getInstance().getDeliveryChannel(); + } + + public static MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeContext.getInstance().getMessageExchangeSupport(); + } + + /** + * return the DOM Document + * @param xmlReader Reader + * @return dom document + * @throws Exception on parser exception or any other exception + */ + public static Document buildDOMDocument(Reader xmlReader) throws Exception { + InputSource xmlSource = new InputSource(xmlReader); + return buildDOMDocument(xmlSource); + } + /** + * return the DOM Document + * @param xmlReader Reader + * @return dom document + * @throws Exception on parser exception or any other exception + */ + public static Document buildDOMDocument(InputSource xmlSource) throws Exception { + Document xmlDoc = null; + DocumentBuilderFactory docBuilderFactory = + DocumentBuilderFactory.newInstance(); + docBuilderFactory.setValidating(false); + docBuilderFactory.setNamespaceAware(true); + DocumentBuilder docBuilder = + docBuilderFactory.newDocumentBuilder(); + docBuilder.setErrorHandler( new DefaultHandler() { + public void fatalError(SAXParseException e) + throws SAXException { + throw new SAXException(e.getMessage()); + } + }); + + docBuilder.setEntityResolver(new EntityResolver() { + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException, IOException { + StringReader reader = + new StringReader(""); // NOI18N + InputSource source = new InputSource(reader); + source.setPublicId(publicId); + source.setSystemId(systemId); + return source; + } + }); + + xmlDoc = docBuilder.parse(xmlSource); + + return xmlDoc; + } + /** + * reads xml text from DOMSource to StringBuffer + */ + public static StringBuffer readFromDOMSource(DOMSource domSource) { + + StringWriter writer = new StringWriter(); + + TransformerFactory tFactory = TransformerFactory.newInstance(); + Transformer trans = null; + try { + trans = tFactory.newTransformer(); + trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, + "yes"); + trans.setOutputProperty(OutputKeys.INDENT, "yes"); + StreamResult result = new StreamResult(writer); + trans.transform(domSource, result); + } catch (TransformerConfigurationException ex) { + ex.printStackTrace(); + } catch (TransformerException ex) { + ex.printStackTrace(); + } + + return writer.getBuffer(); + } + /** + * reads the xml text from InputSource into a StringBuffer + */ + public static StringBuffer readFromInputSource(InputSource inSource) { + + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + InputStream inStream = inSource.getByteStream(); + Reader reader = inSource.getCharacterStream(); + if ( reader == null ) { + reader = new InputStreamReader(inStream); + } + BufferedReader buff = new BufferedReader(reader); + try { + + for ( String line = null; (line = buff.readLine()) != null ; ) { + out.println(line); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + + return writer.getBuffer(); + } + /** + * reads xml from from DOM, SAX or Stream Source into a string buffer + */ + public static StringBuffer readFromSource(Source source) { + if ( source instanceof DOMSource ) { + return readFromDOMSource((DOMSource)source); + } else { + InputSource inSource = SAXSource.sourceToInputSource(source); + if ( inSource != null ) { + return readFromInputSource(inSource); + } else { + return null; + } + } + } + /** + * creates a DOMSource from the xml text read from the reader. + */ + public static DOMSource createDOMSource(Reader xmlReader) { + Document doc = null; + try { + doc = buildDOMDocument(xmlReader); + } catch (Exception ex) { + ex.printStackTrace(); + } + return new DOMSource(doc); + } + /** + * creates a DOMSource from any source. If the source itself is DOMSource, + * the source is returned as it is as DOMSource. + */ + public static DOMSource sourceToDOMSource(Source source) { + if ( source instanceof DOMSource) { + return (DOMSource) source; + } + InputSource xmlSource = SAXSource.sourceToInputSource(source); + Document doc = null; + try { + doc = buildDOMDocument(xmlSource); + } catch (Exception ex) { + ex.printStackTrace(); + } + return new DOMSource(doc); + } + /** + * converts the ex stracktrace to string. + */ + public static StringBuffer getExceptionStackTrace(Exception ex) { + StringWriter strWriter = new StringWriter(); + if ( ex != null ) { + PrintWriter out = new PrintWriter(strWriter); + ex.printStackTrace(out); + } + return strWriter.getBuffer(); + } + /** + * may be used to set the exception as fault content. + */ + public static String getExceptionAsXmlText(Exception ex) { + String message = replaceXmlEscapeCharsToEntityRefereces(ex.getMessage()); + String stackTrace = replaceXmlEscapeCharsToEntityRefereces( + getExceptionStackTrace(ex).toString()); + String exXmlText = + "" + + "" + message + "" + + "" + stackTrace + "" + + "" ; + return exXmlText; + } + + /** + * may be used to set the exception as fault content. + */ + public static String getExceptionAsText(Exception ex) { + String message = replaceXmlEscapeCharsToEntityRefereces(ex.getMessage()); + String stackTrace = replaceXmlEscapeCharsToEntityRefereces( + getExceptionStackTrace(ex).toString()); + StringBuffer buff = new StringBuffer(); + buff.append(message); + buff.append(System.getProperty("line.separator", "\n")); + buff.append(stackTrace); + return buff.toString(); + } + + + /** + * For attribute values which denote a QName, i.e. include a namespace prefix, + * resolve the value into a QName. + * If a namespace can not be resolved, it is set to empty - it does not + * result in an exception + * @param attrValue the string value of the attribute + * @param element the element the attribute belongs to + */ + public static QName resolveAttrQName(String attrValue, Element element) { + int aColonLoc = attrValue.indexOf(":"); + String aLocalName = attrValue; + String aPrefix = null; + String aNS = null; + if (aColonLoc > -1) { + aPrefix = attrValue.substring(0, aColonLoc); + aLocalName = attrValue.substring(aColonLoc + 1); + + // Traverse up the hierarchy until a namespace definition is found + // or the top of the document is reached. + Node currNode = element; + while ((aNS == null || aNS.equals("")) && currNode != null) { + if (currNode.getNodeType() == Node.ELEMENT_NODE) { + aNS = ((Element) currNode).getAttribute("xmlns:" + aPrefix); + } + currNode = currNode.getParentNode(); + } + } + + QName qName = new QName(aNS, aLocalName, aPrefix); + + return qName; + } + + /** + * replaces the xml entity references with the xml escape chars + * @param xmlString Text with the xml escape chars + * @param Text with the xml entity references + */ + public static String replaceXmlEscapeCharsToEntityRefereces(String xmlString) { + if ( xmlString == null ) { + return xmlString; + } + + // just convert < , > and & only + StringBuffer sbuff = new StringBuffer(2 * xmlString.length()); + for ( int i = 0; i < xmlString.length(); ++i ) { + switch ( xmlString.charAt(i) ) { + case '&': sbuff.append("&"); + break; + case '<': sbuff.append("<"); + break; + case '>': sbuff.append(">"); + break; + default: sbuff.append( xmlString.charAt(i) ); + } + } + return sbuff.toString(); + } + + /** + * return Element node from a document node or non document. Use to extract + * the message root element. + * @root node from which the Element node will be extracted. + * @return Element node. + */ + public static Element getElement(Node root) { + Element msgEl = null; + if ( root instanceof Document) { + msgEl = ((Document)root).getDocumentElement(); + } else if (root instanceof Element) { + msgEl = (Element)root; + } else { + NodeList nodeList = root.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if ( node instanceof Element ) { + msgEl = (Element) node; + break; + } + } + } + return msgEl; + } + + public static Element getElement(DOMSource domSource) { + return getElement(domSource.getNode()); + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java new file mode 100644 index 000000000..5880a9c61 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java @@ -0,0 +1,309 @@ +/* + * AbstractServiceUnitManager.java + * + */ + +package net.openesb.component.ServiceEngine-archetype.common.deployment; + +import net.openesb.component.ServiceEngine-archetype.common.RuntimeHelper; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.component.ServiceUnitManager; +import javax.jbi.management.DeploymentException; + +/** + * This is an abstract class that implements {@link javax.jbi.component.ServiceUnitManager} to provide a + * service unit deployment support for the component. The implementation supported by this service + * unit manager and related classes in this package provides WSDL1.1 based service unit deployment + * in the component. + * + * @see javax.jbi.component.ServiceUnitManager + * @see ServiceUnit + * + * @author chikkala + */ +public abstract class AbstractServiceUnitManager implements ServiceUnitManager { + + /** Map of ServiceUnit Name to the ServiceUnit Object for all the service units + * deployed in the component */ + private Map mSUMap; + + /** Creates a new instance of AbstractSUManager */ + protected AbstractServiceUnitManager() { + this.mSUMap = Collections.synchronizedMap(new HashMap()); + } + /** returns the component name + * @return component name. + */ + protected abstract String getComponentName(); + /** + * @return Logger + */ + protected abstract Logger getLogger(); + /** + * returns the creation of the ServiceUnit implementation specific to the service unit deployment + * for the component. + * @param suName service unit name + * @param suRootPath service unit root path + * @param concrete implementation of the ServiceUnit class. + */ + protected abstract ServiceUnit createServiceUnit(String suName, String suRootPath) + throws DeploymentException; + /** + * returns the service unit object deployed by the specified name. or null if not deployed. + * @param suName service unit name to look for + * @param ServiceUnit object for the suName. or null if not present. + */ + private ServiceUnit getServiceUnit(String suName) { + return this.mSUMap.get(suName); + } + /** + * lookup for the deployed service unit. If not there, throws a deployment exception. + * @param suName service unit name + * @return ServiceUnit object + * @throws DeploymentException if the service unit is not present. + */ + private ServiceUnit findServiceUnit(String suName) throws DeploymentException { + ServiceUnit serviceUnit = getServiceUnit(suName); + if ( serviceUnit == null ) { + throw new DeploymentException("Service unit " + suName + " does not exist"); + } + return serviceUnit; + } + /** + * add the service unit object to the list of deployed service units. if there is already a + * service unit present with the name, throws a deployment exception. + * @param su service unit to add + * @return ServiceUnit object that is added. + * @throws DeploymentException if the service unit already present. + */ + private ServiceUnit addServiceUnit(ServiceUnit su) throws DeploymentException { + String suName = su.getName(); + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU != null ) { + throw new DeploymentException("Service unit " + suName + "already exists"); + } + this.mSUMap.put(suName, su); + return su; + } + /** + * removes service unit object from the list of deployed service units. if there is no + * service unit present with the name, throws a deployment exception. + * @param su service unit to add + * @return ServiceUnit object that is being removed. + * @throws DeploymentException if the service unit already present. + */ + private ServiceUnit removeServiceUnit(ServiceUnit su) throws DeploymentException { + String suName = su.getName(); + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU == null ) { + throw new DeploymentException("Service unit " + suName + " does not exist"); + } + return this.mSUMap.remove(suName); + } + /** + * creates the concrete service unit implementation and calls the load method on it to initialize + * the created service unit. + * @param suName service unit name to create + * @param suRootPath service unit root path. + * @return ServiceUnit that is created and loaded. + */ + private ServiceUnit loadServiceUnit(String suName, String suRootPath) throws DeploymentException { + ServiceUnit serviceUnit = createServiceUnit(suName, suRootPath); + serviceUnit.doLoad(); + return serviceUnit; + } + /** + * deploys a service unit. it creates and loads the service unit object for the suName and then call + * doDeploy on the service unit and adds it to the deployed service unit list + * @return result as jbi management xml + * @throws DeploymentException if there is an error deploying. + */ + private synchronized String deployServiceUnit(String suName, String suRootPath) throws DeploymentException { + String result = suName; + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU != null ) { + throw new DeploymentException("Service unit " + suName + "already exists"); + } + ServiceUnit serviceUnit = loadServiceUnit(suName, suRootPath); + serviceUnit.doDeploy(); + addServiceUnit(serviceUnit); + return result; + } + /** + * Deploy a Service Unit to the component. + * @see javax.jbi.component.ServiceUnitManager#deploy(String, String); + */ + public final String deploy(String suName, String suRootPath) throws DeploymentException { + this.getLogger().fine("Deploying service unit " + suName + " with suRootPath " + suRootPath); + String compName = this.getComponentName(); + boolean isSuccess = true; + String mainMsg = "Successfully deployed service unit " + suName; + Exception errEx = null; + try { + deployServiceUnit(suName, suRootPath); + } catch (Exception ex) { + isSuccess = false; + errEx = ex; + mainMsg = "Failed to deploy service unit " + suName ; + this.getLogger().log(Level.FINE, mainMsg, ex); + } + return createComponentTaskResultXML(compName, "deployTask", isSuccess, mainMsg, errEx); + } + + /** + * undeploys the service unit. it looks up the existing deployed service unit and call doUndeploy + * on it and then removes from the deployed service unit list. + */ + private synchronized String undeployServiceUnit(String suName, String suRootPath) throws DeploymentException { + String result = suName; + ServiceUnit serviceUnit = findServiceUnit(suName); + serviceUnit.doUndeploy(); + removeServiceUnit(serviceUnit); + return result; + } + /** + * Undeploy a service unit from the component. + * @see javax.jbi.component.ServiceUnitManager#undeploy(String, String); + */ + public final String undeploy(String suName, String suRootPath) throws DeploymentException { + this.getLogger().fine("Undeploying service unit " + suName + " with suRootPath " + suRootPath); + String compName = this.getComponentName(); + boolean isSuccess = true; + String mainMsg = "Successfully undeployed service unit " + suName; + Exception errEx = null; + try { + undeployServiceUnit(suName, suRootPath); + } catch (Exception ex) { + isSuccess = false; + errEx = ex; + mainMsg = "Failed to undeploy service unit " + suName ; + this.getLogger().log(Level.FINE, mainMsg, errEx); + } + return createComponentTaskResultXML(compName, "undeployTask", isSuccess, mainMsg, errEx); + } + /** + * Initialize the given deployed service unit. + * @see javax.jbi.component.ServiceUnitManager#init(String, String); */ + public final void init(String suName, String suRootPath) + throws DeploymentException { + this.getLogger().fine("Initializing service unit " + suName + " with suRootPath " + suRootPath); + String result = suName; + ServiceUnit serviceUnit = getServiceUnit(suName); + if ( serviceUnit == null ) { // if the service unit not exists, create and add + serviceUnit = loadServiceUnit(suName, suRootPath); // create and load service unit + addServiceUnit(serviceUnit); // add service unit to existing service units + } + serviceUnit.doInit(); // Do Service unit initialization tasks + this.getLogger().fine("Service unit initialized:" + suName); + } + /** + * Shut down the deployment. + * @see javax.jbi.component.ServiceUnitManager#shutdown(String); + */ + public final void shutDown(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doShutdown(); // Do Service unit shutdown tasks + this.getLogger().fine("Service unit shut down:" + suName); + } + /** + * Start the deployed service unit. + * @see javax.jbi.component.ServiceUnitManager#start(String); + */ + public final void start(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doStart(); // Do service unit start tasks. + this.getLogger().fine("Service unit started:" + suName ); + } + /** + * Stop the deployed service unit. + * @see javax.jbi.component.ServiceUnitManager#stop(String); + */ + public final void stop(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doStop(); // do service unit stop tasks + this.getLogger().fine("Service unit stopped: " + suName + " stopped."); + } + + /** + * helper method to create result message as jbi management message xml. + * @param componentName name of the component for this xml. + * @param taskId task id + * @param isSuccess true to format a success result, false to format a failed result. + * @param mainMsg main result message + * @param errEx Exception, null if there is no exception in failure message. + * @return XML string. + */ + protected static String createComponentTaskResultXML( + String componentName, String taskId, boolean isSuccess, String mainMsg, Exception errEx ) { + + String exMsgXml = getComponentTaskResultExceptionXML(errEx); + String mainMsgXmlEsc = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces(mainMsg); + String taskResult = isSuccess ? "SUCCESS" : "FAILED"; + String msgType = isSuccess ? "INFO" : "ERROR"; + + String xmlResult = + "" + + " " + componentName + "" + + " " + + " " + + " " + taskId + "" + + " " + taskResult + "" + + " " + msgType + "" + + " " + + " " + + " SU_MGR_MSG_ID" + + " " + mainMsgXmlEsc + "" + + " " + + " " + + exMsgXml + + " " + + " " + + ""; + + return xmlResult; + } + /** + * converts the exception to the jbi management message xml chunk. + */ + private static String getComponentTaskResultExceptionXML(Exception errEx) { + StringBuffer exMsgBuff = new StringBuffer(); + if ( errEx == null ) { + return exMsgBuff.toString(); // empty string. + } + + List exList = new ArrayList(); + int exLevel = 0; + for ( Throwable cause = errEx ; cause != null ; cause = cause.getCause() ) { + String causeMsg = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces( + cause.getMessage()); + StringWriter stBuff = new StringWriter(); + PrintWriter stOut = new PrintWriter(stBuff); + StackTraceElement[] stList = cause.getStackTrace(); + for (StackTraceElement stEl : stList) { + stOut.println(stEl.toString()); + } + stOut.close(); + String causeStackTrace = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces( + stBuff.getBuffer().toString()); + + exMsgBuff.append(""); + exMsgBuff.append(" " + exLevel + ""); + exMsgBuff.append(" " + "SU_MGR_EXP_ID"); + exMsgBuff.append(" " + causeMsg + ""); + exMsgBuff.append(" "); + exMsgBuff.append(" " + causeStackTrace + ""); + exMsgBuff.append(""); + ++exLevel; + } + + return exMsgBuff.toString(); + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java new file mode 100644 index 000000000..425c7c875 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java @@ -0,0 +1,205 @@ +/* + * ConsumerEndpoint.java + */ + +package net.openesb.component.ServiceEngine-archetype.common.deployment; + +import javax.jbi.JBIException; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.InOnly; +import javax.jbi.messaging.InOut; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.messaging.MessageExchangeFactory; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +/** + * This class extends from Endpoint class and implements lifecycle methods functionality required for the + * endpoint for a service consumer. {@link ServiceUnit#createConsumerEndpoint} creates the object of this + * type to implement the service consumer functionality. + * + * @see ServiceUnit#createConsumerEndpoint + * @author chikkala + */ + +public class ConsumerEndpoint extends Endpoint { + /** + * This constructor initializes the endpoint with CONSUMER role and makes sure that the service + * description passed to it is of consumer description. + */ + protected ConsumerEndpoint(SUDescriptor.Consumes consumes, Definition wsdlDef, ServiceUnit su) { + super(Role.CONSUMER, consumes, wsdlDef, su); + } + /** + * constructor that does not need service unit information. useful for creating the endpoint for + * static services provided by the component. + */ + protected ConsumerEndpoint(SUDescriptor.Consumes consumes, Definition wsdlDef) { + this(consumes, wsdlDef, null); + } + public final void init() throws JBIException { + getLogger().fine("ConsumerEndpoint: init called"); + doInit(); //1. initialize the endpiont resources + addMessageExchangeListener(); //2. register message exchange linster. + } + public final void activate() throws JBIException { + getLogger().fine("ConsumerEndpoint: activate called"); + //1. do common ativation tasks. + doActivate(); //2. do any other activation related tasks. + } + + public final void deactivate() throws JBIException { + getLogger().fine("ConsumerEndpoint: deactivate called"); + //1. do common deactivation tasks. + doDeactivate(); //2. do any other deactivation related tasks. + } + + public final void clean() throws JBIException { + getLogger().fine("ConsumerEndpoint: clean called"); + removeMessageExchangeListener(); //1. remove message exchange listener + doClean(); //2. clean up any other resources. + } + + protected void doInit() throws JBIException { + //NOOP + } + protected void doActivate() throws JBIException { + //NOOP + } + protected void doDeactivate() throws JBIException { + //NOOP + } + protected void doClean() throws JBIException { + //NOOP + } + + /** + * helper method to find the active ServiceEndpiont for the service described with the + * serviceDescriptor. This method looks for the Active ServiceEndpoint using interface or + * service name or service name and the endpoint name. + */ + public ServiceEndpoint findServiceEndpoint() { + + QName serviceType = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + + ServiceEndpoint [] refs = null; + ServiceEndpoint serviceEndpoint = null; + ComponentContext compContext = this.getComponentContext(); + + if ( compContext == null ) { + this.getLogger().info("Null Component context. Can not find ServiceEndpoint"); + return null; + } + // lookup ServiceEndpiont with concrete service(serice qname + endpoint name). + if ( serviceName != null && endpointName != null ) { + this.getLogger().info("Looking for ServiceEndpoint with:" + + " ServiceName: " + serviceName + " EndpointName: " + endpointName); + serviceEndpoint = compContext.getEndpoint(serviceName, endpointName); + } + // else lookup ServiceEndpiont with Service Name + if ( serviceEndpoint == null && serviceName != null && endpointName == null) { + this.getLogger().info("Looking for ServiceEndpoint with Service name: " + serviceName); + refs = compContext.getEndpointsForService(serviceName); + if ( refs != null && refs.length > 0 ) { + serviceEndpoint = refs[0]; + } + } + // else lookup ServiceEndpont with serviceType + if ( serviceEndpoint == null && serviceType != null && + serviceName == null && endpointName == null) { + this.getLogger().info("Looking for ServiceEndpoint with Service type: " + serviceType); + refs = compContext.getEndpoints(serviceType); + if ( refs != null && refs.length > 0 ) { + serviceEndpoint = refs[0]; + } + } + + return serviceEndpoint; + } + + /** + * this method creates a InOutMessageExchange Object and sets the required + * data on the MessageExchange object including the create and set the Normalized + * message object to hold the input message on the MessageExchange object. + */ + public InOut createInOutMessageExchange(QName operation) + throws MessagingException, JBIException { + + ServiceEndpoint serviceEndpoint = null; + // find a ServiceEndpoint activated by the Service Providers for this service + serviceEndpoint = findServiceEndpoint(); + + if ( serviceEndpoint == null ) { + // if not found a activated ServiceEndpoint for this service, throw exception. + throw new JBIException("Can not find an Active ServiceEndpoint for \n" + this.getService()); + } else { + this.setServiceEndpoint(serviceEndpoint); + } + + InOut inOutME = null; + DeliveryChannel channel = this.getDeliveryChannel(); + // create message exchange factory for the endpiont + MessageExchangeFactory factory = channel.createExchangeFactory(serviceEndpoint); + // create INOUT Message Exchange + inOutME = factory.createInOutExchange(); + // set operation + inOutME.setOperation(operation); + // set interface if that is not set + if ( inOutME.getInterfaceName() == null ) { + inOutME.setInterfaceName(this.getService().getInterface()); + } + // create IN Nomralized Message + NormalizedMessage inMsg = inOutME.createMessage(); + // set IN Normalized message on message exchange + inOutME.setInMessage(inMsg); + + return inOutME; + } + + /** + * this method creates a InOnlyMessageExchange Object and sets the required + * data on the MessageExchange object including the create and set the Normalized + * message object to hold the input message on the MessageExchange object. + */ + public InOnly createInOnlyMessageExchange(QName operation) + throws MessagingException, JBIException { + + ServiceEndpoint serviceEndpoint = null; + // find a ServiceEndpoint activated by the Service Providers for this service + serviceEndpoint = findServiceEndpoint(); + + if ( serviceEndpoint == null ) { + // if not found a activated ServiceEndpoint for this service, throw exception. + throw new JBIException("Can not find an Active ServiceEndpoint for \n" + this.getService()); + } else { + this.setServiceEndpoint(serviceEndpoint); + } + + InOnly inOnlyME = null; + DeliveryChannel channel = this.getDeliveryChannel(); + // create message exchange factory for the endpiont + MessageExchangeFactory factory = channel.createExchangeFactory(serviceEndpoint); + // create INOUT Message Exchange + inOnlyME = factory.createInOnlyExchange(); + // set operation + inOnlyME.setOperation(operation); + // set interface if that is not set + if ( inOnlyME.getInterfaceName() == null ) { + inOnlyME.setInterfaceName(this.getService().getInterface()); + } + // create IN Nomralized Message + NormalizedMessage inMsg = inOnlyME.createMessage(); + // set IN Normalized message on message exchange + inOnlyME.setInMessage(inMsg); + + return inOnlyME; + } + + +} \ No newline at end of file diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/Endpoint.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/Endpoint.java new file mode 100644 index 000000000..261897d19 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/Endpoint.java @@ -0,0 +1,286 @@ +/* + * Endpoint.java + * + */ + +package net.openesb.component.ServiceEngine-archetype.common.deployment; + +import net.openesb.component.ServiceEngine-archetype.common.MessageExchangeHandler; +import net.openesb.component.ServiceEngine-archetype.common.MessageExchangeListener; +import net.openesb.component.ServiceEngine-archetype.common.MessageExchangeSupport; +import net.openesb.component.ServiceEngine-archetype.common.RuntimeHelper; +import net.openesb.component.ServiceEngine-archetype.common.wsdl.WSDLProcessor; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.xml.namespace.QName; + +/** + * This is an abstract class that represents the Endpoint defined for service provisioning or + * consumption in a jbi component. It stores the required service description ( wsdl definition, + * role, service unit to which it belongs etc) and defines the lifecycle operations {@link #init}, + * {@link #activate}, {@link #deactivate}, {@link #clean} to control a service endpoint that + * provides or consumes the service. + *

+ * Extended classes implement the abstract methods defined in this class to implement the endpoint + * functionality by providing the functionality to process the deployment artifacts specific to this + * endpoint, configure the endpoint to send/receive messages to/from delivery channel and process them + * according to the specific service implementation. + * + * @author chikkala + */ +public abstract class Endpoint { + /** Role of this endpoint. CONSUMER or PROVIDER */ + private Role mRole; + /** Service description from the SU descriptor for which this endpoint is configured */ + private SUDescriptor.Service mService; + /** WSDL definition corresponding to this endpoint */ + private Definition mWsdlDef; + /** service endpoint corresponding to this endpoint */ + private ServiceEndpoint mServiceEndpoint; + /** service unit from which this endpoint is created */ + private ServiceUnit mSU; // can be null + /** private constructor to force extended classes to use the parameterized constructor */ + private Endpoint() { + } + /** Creates a new instance of Endpoint + * @param role CONSUMER or PRVODER role. + * @param service service description from the su descriptor + * @param wsdl wsdl definition corresponding to this endpoint + * @param su service unit object which created this endpoint. + */ + protected Endpoint(Role role, SUDescriptor.Service service, Definition wsdl, ServiceUnit su) { + this.mService = service; + this.mRole = role; + this.mWsdlDef = wsdl; + this.mSU = su; + } + /** Creates a new instance of Endpoint without service unit. may be useful for static endpoints that + * are not part of the deployment + * @param role CONSUMER or PRVODER role. + * @param service service info from the su descriptor + * @param wsdl wsdl definition corresponding to this endpoint + */ + protected Endpoint(Role role, SUDescriptor.Service service, Definition wsdl) { + this(role, service, wsdl, null); + } + /** + * should be called to initialize any resources related to this endpoint object + * throws JBIException + */ + public abstract void init() throws JBIException; + /** + * activates the endpoint to send/receive messages + * throws JBIException + */ + public abstract void activate() throws JBIException; + /** + * deactivates the endpoint + * throws JBIException + */ + public abstract void deactivate() throws JBIException; + /** + * clean endpoint + * throws JBIException + */ + public abstract void clean() throws JBIException; + + public final Role getRole() { + return this.mRole; + } + public final boolean isProvider() { + return (Role.PROVIDER.equals(this.getRole())); + } + public final boolean isConsumer() { + return (Role.CONSUMER.equals(this.getRole())); + } + public final Definition getWSDL() { + return this.mWsdlDef; + } + public final SUDescriptor.Service getService() { + return this.mService; + } + public final ServiceEndpoint getServiceEndpoint() { + return this.mServiceEndpoint; + } + protected final void setServiceEndpoint(ServiceEndpoint svcEP) { + this.mServiceEndpoint = svcEP; + } + public final ServiceUnit getServiceUnit() { + return this.mSU; + } + /** + * generates an ID that would uniquely identify this endpoint implementation. Use as a key to map + * any information to store that is related to this endpoint. + */ + public final String getID() { + StringBuffer strBuff = new StringBuffer(); + strBuff.append(this.mService.getInterface()).append("+"); + strBuff.append(this.mService.getServiceName()).append("+"); + strBuff.append(this.mService.getEndpointName()).append("+"); + String roleType = null; + if ( Role.CONSUMER.equals(this.mRole) ) { + roleType = "CONSUMER"; + } else if ( Role.PROVIDER.equals(this.mRole) ) { + roleType = "PROVIDER"; + } + strBuff.append(roleType); + return strBuff.toString(); + } + + @Override + public String toString() { + return "Endpoint : " + "\n" + this.mService; + } + /** + * checks if this endpoint is configured for the binding component or service engine. + */ + public boolean isForBindingComponent() { + boolean isForBindingComponent = false; + if ( this.mSU != null ) { + try { + isForBindingComponent = this.mSU.getSUDescriptor().isForBindingComponent(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + return isForBindingComponent; + } + + public QName getOperationQName(String opName) { + return new QName(this.getService().getInterface().getNamespaceURI(), opName); + } + + public Operation getWSDLOperation(QName opQName) { + String opName = null; + if ( opQName != null ) { + opName = opQName.getLocalPart(); + } + Operation operation = WSDLProcessor.findOperation(this.getWSDL(), + this.getService().getInterface(), opName); + return operation; + } + + public Binding getWSDLBinding() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + if ( serviceName != null ) { + return WSDLProcessor.findServiceBinding(this.getWSDL(), serviceName, endpointName); + } else { + return WSDLProcessor.findInterfaceBinding(this.getWSDL(), interfaceName, null); + } + } + /** @return logger */ + public Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** @return ComponentContext */ + public ComponentContext getComponentContext() { + return RuntimeHelper.getComponentContext(); + } + /** @return DeliveryChannel */ + public DeliveryChannel getDeliveryChannel() { + return RuntimeHelper.getDeliveryChannel(); + } + /** + * helper function to get the MessageExchangeSupport object + */ + public MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeHelper.getMessageExchangeSupport(); + } + + public MessageExchangeHandler createMessageExchangeHandler() { + return null; + } + /** + * creates the message exchange listener. Extended classes should return + * MessageExchangeListener implementation. + * @return MessageExchangeListener or null. + * + */ + protected MessageExchangeListener createMessageExchangeListener() { + return null; + } + /** + * Creates and adds message exchange listener to receive message exchange received notification. + */ + protected void addMessageExchangeListener() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + MessageExchangeListener meListener = createMessageExchangeListener(); + MessageExchangeSupport meListenerSupport = getMessageExchangeSupport(); + if ( meListenerSupport != null && meListener != null ) { + meListenerSupport.addMessageExchangeListener( + this.getRole(), interfaceName, serviceName, endpointName, meListener); + if ( serviceName != null ) { + meListenerSupport.addMessageExchangeListener( + this.getRole(), null, serviceName, endpointName, meListener); + } + } + } + /** + * Removes message exchange listener from the MessageExchangeSupport. + */ + protected void removeMessageExchangeListener() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + MessageExchangeSupport meListenerSupport = getMessageExchangeSupport(); + if ( meListenerSupport != null ) { + meListenerSupport.removeMessageExchangeListener( + this.getRole(), interfaceName, serviceName, endpointName); + if ( serviceName != null ) { + meListenerSupport.removeMessageExchangeListener( + this.getRole(), null, serviceName, endpointName); + } + } + } + + public final boolean processMessageExchangeWithHandler(ExchangeStatus status, MessageExchange me) { + + //1. lookup handler + //2. if not there create one and register + //3. call process message exchange on it + //4. check status. if that is the end, remove the handler + + MessageExchangeSupport support = this.getMessageExchangeSupport(); + if ( support == null ) { + getLogger().fine("No MessageExchangeSupport present"); + return false; + } + MessageExchangeHandler handler = support.findMessageExchangeHandler(me); + if ( handler == null ) { + handler = this.createMessageExchangeHandler(); + if ( handler == null ) { + getLogger().fine("MessageExchangeHandler not supported"); + return false; + } + support.addMessageExchangeHandler(me, handler); + } + + handler.processMessageExchange(status, me); + + getLogger().fine("XXX MX Handler processed ME with STATUS: " + status); + + if (!ExchangeStatus.ACTIVE.equals(status) ) { + // DONE or ERROR means done with the me. + getLogger().fine("End of ME processing. STATUS: " + status + + ". Removing the MX Handler ..."); + support.removeMessageExchangeHandler(me); + } + + return true; + } + +} + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java new file mode 100644 index 000000000..ec4b11155 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java @@ -0,0 +1,104 @@ +/* + * ProviderEndpoint.java + * + */ + +package net.openesb.component.ServiceEngine-archetype.common.deployment; + +import net.openesb.component.ServiceEngine-archetype.common.deployment.SUDescriptor.Service; +import javax.jbi.JBIException; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Definition; + +/** + * This class extends from Endpoint class and implements lifecycle methods functionality required for the + * endpoint for a service provider. {@link ServiceUnit#createProviderEndpoint} creates the object of this + * type to implement the service provider functionality. It makes sure that this class or the extended + * classes will activate or deactivate the ServiceEndpoint corresponding to the service + * provided by the endpoint is performed during the activate and deactivate method calls as part of the + * endpoint lifecycle. + * + * @see ServiceUnit#createProviderEndpoint + * @author chikkala + */ + +public class ProviderEndpoint extends Endpoint { + /** + * This constructor initializes the endpoint with PROVIDER role and makes sure that the service + * description passed to it is of provider description. + */ + protected ProviderEndpoint(SUDescriptor.Provides provides, Definition wsdlDef, ServiceUnit su) { + super(Role.PROVIDER, provides, wsdlDef, su); + } + /** + * constructor that does not need service unit information. useful for creating the endpoint for + * static services provided by the component. + */ + protected ProviderEndpoint(SUDescriptor.Provides provides, Definition wsdlDef) { + this(provides, wsdlDef, null); + } + /** + * initializes the endpoint and creates and registers the MessageExchangeListener with + * MessageExchangeSupport. + */ + public final void init() throws JBIException { + getLogger().fine("ProviderEndpiont: init called"); + doInit(); //1. initialize the endpiont resources + addMessageExchangeListener(); //2. register message exchange linster. + } + /** + * calls activatesServiceEndpoint for the Provider. + */ + public final void activate() throws JBIException { + getLogger().fine("ProviderEndpiont: activate called"); + activateServiceEndpoint(); //1. activate service endpoint in NMR + doActivate(); //2. do any other activation related tasks. + } + /** + * calls deactivateServiceEndpoint for the Provider. + */ + public final void deactivate() throws JBIException { + getLogger().fine("ProviderEndpiont: deactivate called"); + deactivateServiceEndpoint(); //1. deactivates the service endpoint in NMR + doDeactivate(); //2. do any other deactivation related tasks. + } + /** + * removes the message exchange listener. cleans up other resources + */ + public final void clean() throws JBIException { + getLogger().fine("ProviderEndpiont: clean called"); + removeMessageExchangeListener(); //1. remove message exchange listener + doClean(); //2. clean up any other resources. + } + /** + * Activates the ServiceEndpoint with NMR + */ + private void activateServiceEndpoint() throws JBIException { + Service service = this.getService(); + ServiceEndpoint svcEP = this.getComponentContext().activateEndpoint( + service.getServiceName(), service.getEndpointName()); + this.setServiceEndpoint(svcEP); + } + /** + * Deactivates ServiceEndpoint in NMR + */ + private void deactivateServiceEndpoint() throws JBIException { + this.getComponentContext().deactivateEndpoint(this.getServiceEndpoint()); + this.setServiceEndpoint(null); + } + + protected void doInit() throws JBIException { + //NOOP + } + protected void doActivate() throws JBIException { + //NOOP + } + protected void doDeactivate() throws JBIException { + //NOOP + } + protected void doClean() throws JBIException { + //NOOP + } + +} \ No newline at end of file diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java new file mode 100644 index 000000000..859de8570 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java @@ -0,0 +1,361 @@ +/* + * SUDescriptor.java + */ + +package net.openesb.component.ServiceEngine-archetype.common.deployment; + +import net.openesb.component.ServiceEngine-archetype.common.RuntimeHelper; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import javax.jbi.management.DeploymentException; +import javax.xml.namespace.QName; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * This interface represent the service unit descriptor (jbi.xml) model. This will be used in + * ServiceUnit implementation to find the services provided and consumed by this service unit. + * {@link SUDescriptorFactory#getSUDescriptor} method reads the jbi.xml in the service unit to + * to the implementation of this interface. + * + * @see SUDescriptorFactory + * @see Consumes + * @see Provides + * @see ServiceUnit + * + * @author chikkala + */ +public interface SUDescriptor { + + Collection getProvidedServices(); + + Collection getConsumedServices(); + + boolean isForBindingComponent(); + + /** + * base interface that models the service information described in the service unit descriptor for + * consumed services and provided services. + */ + public interface Service { + /** + * Getter for property interfaceQName. + * @return Value of property interfaceQName. + */ + QName getInterface(); + /** + * Getter for property serviceName. + * @return Value of property serviceName. + */ + QName getServiceName(); + /** + * Getter for property endpointName. + * @return Value of property endpointName. + */ + String getEndpointName(); + } + /** + * marker interface that represents the provided services in the service unit + */ + public interface Provides extends Service { + } + /** + * this interface represents the consumed service information in the su descriptor. + */ + public interface Consumes extends Service { + + public final static String STANDARD_LINK = "standard"; + public final static String SOFT_LINK = "soft"; + public final static String HARD_LINK = "hard"; + /** + * Getter for property linkType. + * @return Value of property linkType. + */ + String getLinkType(); + } + /** + * This is a factory class that can build the Service Unit Descriptor model from the jbi.xml + */ + public static class SUDescriptorFactory { + + protected final static String JBI_TAG_NAME = "services"; + protected final static String SERVICES_TAG_NAME = "services"; + protected final static String BC_TAG_NAME = "binding-component"; + protected final static String PROVIDES_TAG_NAME = "provides"; + protected final static String CONSUMES_TAG_NAME = "consumes"; + protected final static String INTERFACE_TAG_NAME = "interface-name"; + protected final static String SERVICE_TAG_NAME = "service-name"; + protected final static String ENDPOINT_TAG_NAME = "endpoint-name"; + protected final static String LINK_TYPE_TAG_NAME = "link-type"; + /** + * method that builds the Service unit descriptor model from the jbi.xml + */ + public static SUDescriptor getSUDescriptor(String jbiXmlPath) throws Exception { + FileReader reader = null; + try { + reader = new FileReader(jbiXmlPath); + SUDescriptor suDesc = getSUDescriptor(reader); + return suDesc; + } finally { + if ( reader != null ) { + try { + reader.close(); + } catch (IOException ex) { + // ignore + } + } + } + } + /** + * method that builds the Service unit descriptor model from the jbi.xml + */ + public static SUDescriptor getSUDescriptor(Reader reader) throws Exception { + SUDescriptor suDescriptor = null; + Document suDescDoc = RuntimeHelper.buildDOMDocument(reader); + Element jbiEl = suDescDoc.getDocumentElement(); + if (JBI_TAG_NAME.equals(jbiEl.getTagName())) { + throw new DeploymentException("Invalid service unit descriptor : no jbi root element"); + } + + NodeList servicesNL = jbiEl.getElementsByTagName(SERVICES_TAG_NAME); + if (servicesNL != null && servicesNL.getLength() == 1) { + Element servicesEl = (Element) servicesNL.item(0); + suDescriptor = SUDescriptorImpl.createSUDescriptor(servicesEl); + } else { + throw new DeploymentException("Invalid service unit descriptor : invalid services element"); + } + + return suDescriptor; + } + + } + /** + * This class implements SUDescriptor + */ + public static class SUDescriptorImpl implements SUDescriptor { + + private List mConsumedList; + private List mProvidedList; + private boolean mIsForBindingComponent; + + protected SUDescriptorImpl(boolean isForBindingComponent) { + this.mIsForBindingComponent = isForBindingComponent; + this.mConsumedList = new ArrayList(); + this.mProvidedList = new ArrayList(); + } + + protected void addProvidedService(Provides provides) { + this.mProvidedList.add(provides); + } + + protected void addConsumedService(Consumes consumes) { + this.mConsumedList.add(consumes); + } + + public Collection getProvidedServices() { + // return unmodifiable collection + return Collections.unmodifiableCollection(this.mProvidedList); + } + + public Collection getConsumedServices() { + // return unmodifiable collection + return Collections.unmodifiableCollection(this.mConsumedList); + } + + public boolean isForBindingComponent() { + return this.mIsForBindingComponent; + } + + protected static SUDescriptor createSUDescriptor(Element servicesEl) throws Exception { + boolean isForBC = false; + String bcTagString = servicesEl.getAttribute(SUDescriptorFactory.BC_TAG_NAME); + isForBC = Boolean.valueOf(bcTagString).booleanValue(); + SUDescriptorImpl suDesc = new SUDescriptorImpl(isForBC); + // add consumes + NodeList consumesNL = servicesEl.getElementsByTagName(SUDescriptorFactory.CONSUMES_TAG_NAME); + for ( int i=0; i < consumesNL.getLength(); ++i) { + Element consumesEl = (Element) consumesNL.item(i); + Consumes consumes = ConsumedService.createConsumedService(consumesEl); + suDesc.addConsumedService(consumes); + } + // add provides + NodeList providesNL = servicesEl.getElementsByTagName(SUDescriptorFactory.PROVIDES_TAG_NAME); + for ( int i=0; i < providesNL.getLength(); ++i) { + Element providesEl = (Element) providesNL.item(i); + Provides provides = ProvidedService.createProvidedService(providesEl); + suDesc.addProvidedService(provides); + } + + return suDesc; + } + } + /** + * Base class that implements the Service interface + */ + public static abstract class AbstractService implements Service { + + private QName mInterface; + private QName mServiceName; + private String mEndpointName; + + private AbstractService() { + } + /** + * Getter for property interfaceQName. + * @return Value of property interfaceQName. + */ + public QName getInterface() { + return this.mInterface; + } + + /** + * Setter for property interfaceQName. + * @param interfaceQName New value of property interfaceQName. + */ + protected void setInterface(QName interfaceQName) { + this.mInterface = interfaceQName; + } + + /** + * Getter for property serviceName. + * @return Value of property serviceName. + */ + public QName getServiceName() { + return this.mServiceName; + } + + /** + * Setter for property serviceName. + * @param serviceName New value of property serviceName. + */ + protected void setServiceName(QName serviceName) { + this.mServiceName = serviceName; + } + + /** + * Getter for property endpointName. + * @return Value of property endpointName. + */ + public String getEndpointName() { + return this.mEndpointName; + } + + /** + * Setter for property endpointName. + * @param endpointName New value of property endpointName. + */ + protected void setEndpointName(String endpointName) { + this.mEndpointName = endpointName; + } + + } + /** + * This class implements the Provides interface + */ + public static class ProvidedService + extends AbstractService + implements Provides { + protected ProvidedService(QName interfaceQName, QName serviceName, String endpointName) { + this.setInterface(interfaceQName); + this.setServiceName(serviceName); + this.setEndpointName(endpointName); + } + + @Override + public String toString() { + return "Provides :" + + "\n\t interface-name= " + getInterface() + + "\n\t service-name= " + getServiceName() + + "\n\t endpont-name= " + getEndpointName(); + } + + protected static Provides createProvidedService(Element providesEl) throws Exception { + + String ifName = providesEl.getAttribute(SUDescriptorFactory.INTERFACE_TAG_NAME); + String serviceName = providesEl.getAttribute(SUDescriptorFactory.SERVICE_TAG_NAME); + String endpointName = providesEl.getAttribute(SUDescriptorFactory.ENDPOINT_TAG_NAME); + if ( ifName == null || serviceName == null || endpointName == null ) { + throw new Exception("Invalid provides element: missing " + SUDescriptorFactory.INTERFACE_TAG_NAME + + " or " + SUDescriptorFactory.SERVICE_TAG_NAME + " or " + SUDescriptorFactory.ENDPOINT_TAG_NAME ); + } + QName ifQName = RuntimeHelper.resolveAttrQName(ifName, providesEl); + QName serviceQName = RuntimeHelper.resolveAttrQName(serviceName, providesEl); + + return new ProvidedService(ifQName, serviceQName, endpointName); + } + } + /** + * This class implements the Consumes interface. + */ + public static class ConsumedService + extends AbstractService + implements Consumes { + private String mLinkType; + protected ConsumedService(QName interfaceQName, + QName serviceName, String endpointName, String linkType) { + this.setInterface(interfaceQName); + this.setServiceName(serviceName); + this.setEndpointName(endpointName); + this.mLinkType = linkType; + } + + /** + * Getter for property linkType. + * @return Value of property linkType. + */ + public String getLinkType() { + return this.mLinkType; + } + + @Override + public String toString() { + return "Cosumes :" + + "\n\t interface-name= " + getInterface() + + "\n\t service-name= " + getServiceName() + + "\n\t endpont-name= " + getEndpointName() + + "\n\t link-type= " + getLinkType(); + } + + protected static Consumes createConsumedService(Element consumesEl) throws Exception { + + String ifName = consumesEl.getAttribute(SUDescriptorFactory.INTERFACE_TAG_NAME); + String serviceName = consumesEl.getAttribute(SUDescriptorFactory.SERVICE_TAG_NAME); + String endpointName = consumesEl.getAttribute(SUDescriptorFactory.ENDPOINT_TAG_NAME); + String linkType = consumesEl.getAttribute(SUDescriptorFactory.LINK_TYPE_TAG_NAME); + if ( linkType == null || linkType.trim().length() == 0 ) { + linkType = STANDARD_LINK; + } + + if ( ifName == null ) { + throw new Exception("Invalid consumes element: missing " + + SUDescriptorFactory.INTERFACE_TAG_NAME ); + } + if ( serviceName == null || endpointName == null ) { + throw new Exception("Invalid consumes element: missing " + + SUDescriptorFactory.SERVICE_TAG_NAME + " or " + + SUDescriptorFactory.ENDPOINT_TAG_NAME ); + } + + QName ifQName = RuntimeHelper.resolveAttrQName(ifName, consumesEl); + QName serviceQName = null; + if ( serviceName != null ) { + serviceQName = RuntimeHelper.resolveAttrQName(serviceName, consumesEl); + } + if ( serviceQName != null && endpointName != null && linkType != null ) { + if (!(STANDARD_LINK.equals(linkType) || + SOFT_LINK.equals(linkType) || HARD_LINK.equals(linkType)) ) { + throw new Exception("Invalid consumes attribute value" + + SUDescriptorFactory.LINK_TYPE_TAG_NAME + "=" + linkType); + } + } + return new ConsumedService(ifQName, serviceQName, endpointName, linkType); + } + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java new file mode 100644 index 000000000..f7bd96d2c --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java @@ -0,0 +1,461 @@ +/* + * ServiceUnit.java + * + */ + +package net.openesb.component.ServiceEngine-archetype.common.deployment; + +import net.openesb.component.ServiceEngine-archetype.common.RuntimeHelper; +import net.openesb.component.ServiceEngine-archetype.common.deployment.SUDescriptor.Consumes; +import net.openesb.component.ServiceEngine-archetype.common.deployment.SUDescriptor.Provides; +import net.openesb.component.ServiceEngine-archetype.common.deployment.SUDescriptor.Service; +import net.openesb.component.ServiceEngine-archetype.common.wsdl.WSDLProcessor; +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.management.DeploymentException; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; + +/** + * This is an abstract class that implements the service unit functionality in the component which + * processes the service unit artifacts and implement the actual service unit lifecycle functionality. + * The AbstractServiceUnitManager and its extended classes that implement the ServiceUnitManager + * functionality creates and maintains the reference to the concrete implementation of this class to + * invoke the functionality implemented by this class and its concrete implementation during the + * execution of the ServiceUnitMangers lifecycle methods by the jbi runtime. + *

+ * The main lifecycle methods of this class that will be called by the ServiceUnitManger implementation + * during the service unit deployment lifecycle are {@link #doload}, {@link #doDeploy}, {@link #doUndeploy}, + * {@link #doInit}, {@link #doStart}, {@link #doStop} and {@link #doShutdown} + *

+ * Service unit processing supported by this implementation is based on wsdl 1.1 deployments where the + * services provided and consumed in this service unit are described using wsdl 1.1 definitions. + *

+ * The main service unit artifacts that will be processed during deployment lifecycle of the service + * unit are 1.Service unit descriptor(jbi.xml) that describes the services provided and consumed by + * this service unit. 2.WSDL 1.1 document that describes the service definition 3.Component specific + * configurations related to services provided and consumed by this service unit. + *

+ * When the service unit is for Binding Component, the component specific configurations are read + * from the WSDL1.1 extensions defined in the WSDL document corresponding to the service provider + * or consumer deployed with this service unit. + *

+ * When the service unit is for Service Engine, the component specific configurations are read + * from the deployment artifacts such as xslt files and mapping files in the service unit zip file + * along with the WSDL document corresponding to the service provider or consumer deployed with this + * service unit. + * + * @see SUDescriptor + * @see Endpoint + * @see ProviderEndpoint + * @see ConsumerEndpoint + * @see WSDLProcessor + * @author chikkala + */ +public abstract class ServiceUnit { + /** Service Unit Name */ + private String mSUName; + /** Service Unit Root path passed by jbi runtime */ + private String mSURootPath; + /** service unit descriptor model unmarshalled from service unit jbi.xml */ + private SUDescriptor mSUDescriptor; + /** Map of Endpoint Key to ProviderEndpoint configurations in this service unit */ + private Map mProviderEndpointMap; + /** Map of Endpoint Key to ConsumerEndpoint configurations in this service unit */ + private Map mConsumerEndpointMap; + /** Map of Service Key to the WSDL Definition in this service unit */ + private Map mWSDLMap; + /** WSDLProcessor configured for this service unit to process wsdls in the service unit */ + private WSDLProcessor mWSDLProcessor; + /** + * + * @param suName + * @param suRootPath + */ + protected ServiceUnit(String suName, String suRootPath) { + this.mSUName = suName; + this.mSURootPath = suRootPath; + this.mSUDescriptor = null; + this.mWSDLMap = new HashMap(); + this.mProviderEndpointMap = new HashMap(); + this.mConsumerEndpointMap = new HashMap(); + } + /** returns service unit name + * @return service unit name + */ + public String getName() { + return this.mSUName; + } + /** returns service unit root path where the su artifacts are unzipped by the jbi runtime + * @return path to the service unit root directory. + */ + public String getSURootPath() { + return this.mSURootPath; + } + protected SUDescriptor createSUDescriptor() throws Exception { + File jbiXmlFile = new File(this.getSURootPath(), "META-INF/jbi.xml"); + String jbiXmlPath = jbiXmlFile.getAbsolutePath(); + return SUDescriptor.SUDescriptorFactory.getSUDescriptor(jbiXmlPath); + } + /** return the Service unit descriptor model that was read from the jbi.xml + * @return SUDescriptor + */ + public SUDescriptor getSUDescriptor() throws Exception { + if ( this.mSUDescriptor == null ) { + this.mSUDescriptor = createSUDescriptor(); + } + return this.mSUDescriptor; + } + public ProviderEndpoint getProviderEndpoint(String providerID) { + return this.mProviderEndpointMap.get(providerID); + } + public Collection getProviderEndpoints() { + return Collections.unmodifiableCollection(this.mProviderEndpointMap.values()); + } + public ConsumerEndpoint getConsumerEndpoint(String cosumerID) { + return this.mConsumerEndpointMap.get(cosumerID); + } + + public Collection getConsumerEndpoints() { + return Collections.unmodifiableCollection(this.mConsumerEndpointMap.values()); + } + /** + * @return Logger + */ + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** + * extended classes implement this method to create the su specific WSDLProcessor. for examples, + * a su supporting binding component may have wsdl extensions that it want to registry for reading + * the configurations from the wsdl file. + * @return WSDLProcessor + * @see com.sun.jbi.sample.component.common.wsdl.WSDLProcessor + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + */ + protected WSDLProcessor createWSDLProcessor() { + return new WSDLProcessor(this.getSURootPath()); + } + /** + * return the WSDLProcessor reference by creates if it is not yet created. + * @return WSDLProcessor. + */ + public final WSDLProcessor getWSDLProcessor() { + if ( this.mWSDLProcessor == null ) { + this.mWSDLProcessor = createWSDLProcessor(); + } + return this.mWSDLProcessor; + } + /** + * loads the service unit artifacts into the SU model. AbstractServiceUnitManager implementation + * calls this method during the during deploy and init lifecycle methods when the service unit + * object is newly created. + */ + public void doLoad() throws DeploymentException { + try { + SUDescriptor suDesc = getSUDescriptor(); // load jbi.xml + loadServiceDefinitions(); // check if the wsdls are valid for corresponding services. + loadOtherArtifacts(); // additional validations specific to component deployment features. + loadEndpoints(); // create endpoints + } catch ( DeploymentException jbiEx) { + throw jbiEx; + } catch (Exception ex) { + throw new DeploymentException(ex); + } + } + /** extended classes implement this method to perform the su specific deployment related tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doDeploy() throws DeploymentException { + // NOOP. doLoad has done it all. + this.getLogger().fine("ServiceUnit.doDeploy"); + } + /** extended classes implement this method to perform the su specific undeployment related tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doUndeploy() throws DeploymentException { + //NOOP + this.getLogger().fine("ServiceUnit.doUndeploy"); + } + /** extended classes implement this method to perform the su specific initialization tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doInit() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doInit"); + this.doInitEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on start in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doStart() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doStart"); + this.doActivateEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on stop in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doStop() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doStop"); + this.doDeactivateEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on shutdown in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doShutdown() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doShutdown"); + this.doCleanEndpoints(); + } + /** + * create the ProviderEndpoint that implement the service provider implementation specific to this su. + * @return ProviderEndpoint or null if the SU does not support the service provider access + */ + protected ProviderEndpoint createProviderEndpoint(Provides provides, Definition wsdlDef) { + return null; + } + /** + * create the ProviderEndpoint that implement the service consumer implementation specific to this su. + * @return ConsumerEndpoint or null if the SU does not support the service consumer access + */ + protected ConsumerEndpoint createConsumerEndpoint(Consumes consumes, Definition wsdlDef) { + return null; + } + /** + * generates the key based on the service to store the wsdl definitions . + */ + protected String getServiceKey(Service service) { + StringBuffer strBuff = new StringBuffer(); + strBuff.append(service.getInterface()).append("+"); + strBuff.append(service.getServiceName()).append("+"); + strBuff.append(service.getEndpointName()); + return strBuff.toString(); + } + /** + * looks up the wsdl definition loaded for this service. + */ + protected Definition findWSDLFor(Service service) throws WSDLException { + Definition wsdlDef = null; + String key = this.getServiceKey(service); + wsdlDef = this.mWSDLMap.get(key); + return wsdlDef; + } + + protected Definition findWSDL(List wsdlList, Service service, boolean ignoreEndpointLookup) { + Definition foundDef = null; + for ( Definition def : wsdlList ) { + if ( WSDLProcessor.isWSDLFor(def, service.getInterface(), service.getServiceName(), + ((ignoreEndpointLookup) ? null : service.getEndpointName()) ) ) { + foundDef = def; + break; + } + } + return foundDef; + } + /** + * loads the WSDL definitions corresponds to the service providers and consumers defined in the + * service unit descriptor. + */ + protected void loadServiceDefinitions() throws Exception { + + this.mWSDLMap = new HashMap(); + + WSDLProcessor wsdlProcessor = getWSDLProcessor(); + List wsdlList = wsdlProcessor.readWSDLs(this.getSURootPath()); + this.getLogger().fine("Number of wsdl definitions in service unit " + wsdlList.size()); + + List services = new ArrayList(); + services.addAll(this.getSUDescriptor().getProvidedServices()); + services.addAll(this.getSUDescriptor().getConsumedServices()); + + boolean isForBinding = this.getSUDescriptor().isForBindingComponent(); + this.getLogger().fine("Is this service unit for Binding? " + isForBinding); + + for ( Service service : services ) { + this.getLogger().fine("Looking up WSDL for service " + service); + boolean ignoreEndpointLookup = false; + boolean providerAtEngine = false; + if ( !isForBinding && service instanceof Provides ) { + ignoreEndpointLookup = true; + providerAtEngine = true; + } + Definition def = findWSDL(wsdlList, service, ignoreEndpointLookup); + if ( def == null ) { + throw new Exception("WSDL Definition not found for " + service); + } + this.mWSDLMap.put(getServiceKey(service), def); + if ( providerAtEngine ) { + // provider at engine. so add engine binding and endpoint to the wsdl + wsdlProcessor.createServiceEngine-archetypeBinding(def, + service.getInterface(), service.getServiceName(), service.getEndpointName()); + } + } + } + /** extended classes implement this method to perform the su specific artifacts validation in + * this method implementation. + * @throws DeploymentException on error. + */ + protected void loadOtherArtifacts() throws DeploymentException { + // nothing to validate further. + this.getLogger().fine("ServiceUnit.loadOtherArtifacts"); + } + /** + * creates ProviderEndpoint and ConsumerEndpoint objects corresponding to the service providers + * and consumers described in the su descriptor ( jbi.xml ) + */ + protected void loadEndpoints() throws Exception { + + this.mProviderEndpointMap = new HashMap(); + this.mConsumerEndpointMap = new HashMap(); + + Collection providesList = this.getSUDescriptor().getProvidedServices(); + for ( Provides provides : providesList ) { + Definition wsdlDef = findWSDLFor(provides); + if ( wsdlDef == null ) { + throw new DeploymentException("WSDL Definitions not found for " + provides); + } + ProviderEndpoint provider = createProviderEndpoint(provides, wsdlDef); + this.mProviderEndpointMap.put(provider.getID(), provider); + } + + Collection consumesList = this.getSUDescriptor().getConsumedServices(); + for ( Consumes consumes : consumesList ) { + Definition wsdlDef = findWSDLFor(consumes); + if ( wsdlDef == null ) { + throw new DeploymentException("WSDL Definitions not found for " + consumes); + } + ConsumerEndpoint consumer = createConsumerEndpoint(consumes, wsdlDef); + this.mConsumerEndpointMap.put(consumer.getID(), consumer); + } + } + /** + * initializes the Endpoint objects created corresponding to the consumer and providers defined + * in the su descriptor + */ + protected void doInitEndpoints() throws DeploymentException { + // init endpoints. if any initialization fails, rollback the already inited endpoints + List initedEndpoints = new ArrayList(); + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getProviderEndpoints()); + allEndpoints.addAll(this.getConsumerEndpoints()); + + for ( Endpoint endpoint : allEndpoints ) { + try { + endpoint.init(); + initedEndpoints.add(endpoint); + } catch ( Exception initEx) { + doCleanEndpoints(initedEndpoints); + throw new DeploymentException(initEx); + } + } + + } + /** + * invokes activates method of all provider and consumer endpoint object in this su. if there is + * and error activating any one the endpoints, it deactivates the already activated ones and throws + * the error + */ + protected void doActivateEndpoints() throws DeploymentException { + // activate providers first and then consumers + List activatedEndpoints = new ArrayList(); + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getProviderEndpoints()); + allEndpoints.addAll(this.getConsumerEndpoints()); + + for ( Endpoint endpoint : allEndpoints ) { + try { + endpoint.activate(); + activatedEndpoints.add(endpoint); + } catch ( Exception actEx) { + doDeactivateEndpoints(activatedEndpoints); + throw new DeploymentException(actEx); + } + } + } + /** + * invokes deactivate method on the list of Endpoint objects passed to this method + */ + protected void doDeactivateEndpoints(List endpoints) { + for ( Endpoint endpoint : endpoints ) { + try { + endpoint.deactivate(); + } catch(Exception ex) { + // ignore the exception and log it. + this.getLogger().log(Level.FINE, ex.getMessage(), ex); + } + } + } + /** + * invokes deactivate method on the all consumer and provider endpoint objects + */ + protected void doDeactivateEndpoints() { + // deactivate consumers first and then the providers + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getConsumerEndpoints()); + allEndpoints.addAll(this.getProviderEndpoints()); + doDeactivateEndpoints(allEndpoints); + } + /** + * invokes clean method on the list of endpoint objects + */ + protected void doCleanEndpoints(List endpoints) { + for ( Endpoint endpoint : endpoints ) { + try { + endpoint.clean(); + } catch(Exception ex) { + // ignore the exception and log it. + this.getLogger().log(Level.FINE, ex.getMessage(), ex); + } + } + } + /** + * invokes clean method on the all consumer and provider endpoint objects in this su. + */ + protected void doCleanEndpoints() { + + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getConsumerEndpoints()); + allEndpoints.addAll(this.getProviderEndpoints()); + doCleanEndpoints(allEndpoints); + } + /** + * prints the service unit description + */ + protected final String printDetails() { + + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + + out.println("ServiceUnit Name : " + this.getName()); + out.println("ServiceUnit Root : " + this.getSURootPath()); + + SUDescriptor suDesc = null; + try { + suDesc = this.getSUDescriptor(); + for ( SUDescriptor.Consumes consumer : suDesc.getConsumedServices()) { + out.println(consumer); + } + for ( SUDescriptor.Provides provides : suDesc.getProvidedServices()) { + out.println(provides); + } + } catch (Exception ex) { + ex.printStackTrace(out); + } + return writer.getBuffer().toString(); + } + + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java new file mode 100644 index 000000000..ea83df638 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java @@ -0,0 +1,41 @@ +/* + * AbstractExtensibilityElement.java + */ + +package net.openesb.component.ServiceEngine-archetype.common.wsdl; + +import javax.wsdl.extensions.ExtensibilityElement; +import javax.xml.namespace.QName; + +/** + * This is an abstract class which can be extended to create jwsdl (wsdl4j's) extension elements model to + * read/write the wsdl extension elements in wsdl 1.1 xml. + * + * @author chikkala + */ +public abstract class AbstractExtensibilityElement implements ExtensibilityElement, java.io.Serializable { + public static final long serialVersionUID = 1; + private QName mElementType; + private Boolean mRequired; + + /** Creates a new instance of AbstractExtensibilityElement */ + protected AbstractExtensibilityElement() { + } + + public void setElementType(QName elementType) { + this.mElementType = elementType; + } + + public QName getElementType() { + return this.mElementType; + } + + public void setRequired(Boolean required) { + this.mRequired = required; + } + + public Boolean getRequired() { + return this.mRequired; + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java new file mode 100644 index 000000000..f958a6a4b --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java @@ -0,0 +1,42 @@ +/* + * AbstractExtensionRegistry.java + */ + +package net.openesb.component.ServiceEngine-archetype.common.wsdl; + +import java.util.List; +import javax.wsdl.extensions.ExtensionRegistry; + +/** + * This is the abstract class used to add the wsdl extension serializers and deserializers to the + * wsdl extension registry configured to read/write wsdl extensions into a know java model. + * @see AbstractExtensionSerializer + * @see WSDLProcessor + * @author chikkala + */ +public abstract class AbstractExtensionRegistry extends ExtensionRegistry { + + /** Creates a new instance of AbstractSerializer + * it calls the createSerializers method to get the list of + * serializers and then call registerSerializer on each AbstractExtensionSerializer + * to register them with this registry. + * @see AbstractExtensionSerializer#registerSerializer + */ + protected AbstractExtensionRegistry() { + super(); + List list = createSerializers(); + for (AbstractExtensionSerializer ser : list ) { + ser.registerSerializer(this); + } + // register ServiceEngine-archetype Binding serializers + AbstractExtensionSerializer seBindingSer = new SEBindingExt.SEBindingExtSerializer(); + seBindingSer.registerSerializer(this); + } + /** + * create wsdl extension serializers for each extension element to register with the extension + * registry. + * @return List of AbstractExtensionSerializer objects for serializing/deserializing the wsdl extensions. + * @see AbstractExtensionSerializer + */ + protected abstract List createSerializers(); +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java new file mode 100644 index 000000000..98b448d70 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java @@ -0,0 +1,120 @@ +/* + * AbstractExtensionSerializer.java + */ + +package net.openesb.component.ServiceEngine-archetype.common.wsdl; + +import java.io.PrintWriter; +import java.io.Serializable; +import java.util.Set; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionDeserializer; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.extensions.ExtensionSerializer; +import javax.xml.namespace.QName; +import org.w3c.dom.Attr; +import org.w3c.dom.Element; + +/** + * This class is an abstract class that should be extended to implements extension serializer and + * deserializer. This class implements the code required for registering the serializer and deserializer + * implemented by this class. THe AbstractExtensionRegistry class calls the #registerSerializer method + * to register the concrete implementation of this class with extension registry. + * @see AbstractExtensionRegistry + * @author chikkala + */ +public abstract class AbstractExtensionSerializer + implements ExtensionSerializer, ExtensionDeserializer, Serializable { + + public static final long serialVersionUID = 1; + + private Class mParentType; + private Class mExtensionType; + private QName mElementType; + + /** Creates a new instance of AbstractSerializer */ + public AbstractExtensionSerializer(Class parentType, QName elementType, Class extensionType) { + this.mParentType = parentType; + this.mElementType = elementType; + this.mExtensionType = extensionType; + } + + public Class getParentType() { + return this.mParentType; + } + public QName getElementType() { + return this.mElementType; + } + public Class getExtensionType() { + return this.mExtensionType; + } + + public void registerSerializer(ExtensionRegistry extReg) { + extReg.registerSerializer(this.mParentType, this.mElementType, this); + extReg.registerDeserializer(this.mParentType, this.mElementType, this); + extReg.mapExtensionTypes(this.mParentType, this.mElementType, this.mExtensionType); + } + + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg ) throws WSDLException { + // DO NOTHING. Binding component runtime does not need to serialize the wsdl extensions. + } + + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + return null; + } + + public static String getAttribute(Element el, String attrName) { + String attrValue = null; + Attr attr = el.getAttributeNode(attrName); + if ( attr != null ) { + attrValue = attr.getValue(); + } + return attrValue; + } + + protected String getNamespacePrefix(Definition def, String namespaceURI, String defPrefix) { + String prefix = null; + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + Set keySet = def.getNamespaces().keySet(); + String newPrefix = "ns"; + if ( defPrefix != null && defPrefix.trim().length() > 0 ){ + newPrefix = defPrefix; + } + prefix = newPrefix; + for ( int i=0; i < Integer.MAX_VALUE; ++i) { + if (!keySet.contains(prefix)) { + break; + } else { + prefix = newPrefix + i; + } + } + } + return prefix; + } + /** + * @return the name with the prefix defined for the namespaceURI in the wsdl definition. + * @throws WSDLException if the prefix not found in the wsdl definition. note that the + * default prefix is an empty string. + */ + protected String getQualifiedName(Definition def, + String namespaceURI, String localName) throws WSDLException { + String prefix = null; + if (namespaceURI != null && !namespaceURI.equals("")) { + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + throw new WSDLException(WSDLException.OTHER_ERROR, + "Can not find prefix in WSDL Definition for " + namespaceURI); + } + } + if ( prefix != null && !prefix.equals("")) { + return prefix + ":" + localName; + } else { + return localName; + } + } +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java new file mode 100644 index 000000000..55d9e358e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java @@ -0,0 +1,226 @@ +/* + * AbstractNormalizer.java + */ + +package net.openesb.component.ServiceEngine-archetype.common.wsdl; + +import java.util.ArrayList; +import java.util.List; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Part; +import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.dom.DOMSource; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * This is an abstract class that implements most of the functionality to normalize the binding protocol + * specific concrete message to jbi wrapper and and denormalize jbi wrapper to the concrete binding + * protocol specific message. + *

+ * The extended classes specific to particular binding protocol will be used when a jbi binding + * component is sending and receiving messages from the external service providers and consumers using + * a particular binding protocol known to this class. Extended implementation of this class should make + * use of the helper methods in this class in normalizing and denormalizing the messages. + * @see JMXBindingNormalizer + * @author chikkala + */ +public abstract class AbstractNormalizer { + + public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/"; + /** wsdl definition to use when normalizing and denormalizing */ + private Definition mWSDL; + /** Binding definition to use when normalizing and denormalizing */ + private Binding mBinding; + + private AbstractNormalizer() {} + /** Creates a new instance of JMXBCNormalizer */ + public AbstractNormalizer(Definition wsdl, Binding binding) { + this.mWSDL = wsdl; + this.mBinding = binding; + } + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete mssage of a particular binding protocol. + */ + public abstract void normalizeInput(Operation operation, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete message of a particular binding protocol. + */ + public abstract void normalizeOutput(Operation operation, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete message of a particular binding protocol. + */ + public abstract void normalizeFault(Operation operation, String faultName, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * denormalize the normalized message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be de-normalized. + * @param normMsg NormalizedMessage which should be used to create de-normalized message. + */ + public abstract DOMSource denormalizeInput(Operation operation, NormalizedMessage normMsg) + throws MessagingException; + /** + * denormalize the normalized message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be denormalized. + * @param normMsg NormalizedMessage which should be used to create denormalized message. + */ + public abstract DOMSource denormalizeOutput(Operation operation, NormalizedMessage normMsg) + throws MessagingException; + + /** + * denormalized the normalized fault message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be denormalized. + * @param normMsg NormalizedMessage which should be used to create denormalized message. + */ + public abstract DOMSource denormalizeFault(Operation operation, String faultName, NormalizedMessage normMsg) + throws MessagingException; + /** + * @return the wsdl definition to use in normalizing and denormalizing the message + */ + protected Definition getWSDL() { + return this.mWSDL; + } + /** + * @return the wsdl binding definition to use in normalizing and denormalizing the message + */ + protected Binding getBinding() { + return this.mBinding; + } + /** + * create and add message parts to the jbiWrapper according to the abstract message model. This + * method assumes that the each element in the msgParts list passed to it is mapped to the part + * of the abstract wsdl message and uses the type or element attribute of the abstract message to + * determine whether the element is actual part element or a wrapped part type. + * Use this method in normalizing the concrete protocol specific message to jbi wrapper message. + * @param jbiWrapper object that holds the jbi wrapper information. + * @param wsdlMsg abstract message from the wsdl definition + * @param msgParts actual message parts from the concrete message + */ + protected void addMessagePartsToJBIWrapper(WSDL11JBIWrapper jbiWrapper, Message wsdlMsg, List msgParts) throws MessagingException { + List wsdlParts = wsdlMsg.getOrderedParts(null); + for ( int i=0; i < wsdlParts.size(); ++i ) { + Part wsdlPart = (Part) wsdlParts.get(i); + if ( i >= msgParts.size() ) { + throw new MessagingException("missing message content for part " + wsdlPart.getName()); + } + Element msgPart = msgParts.get(i); + if ( wsdlPart.getElementName() != null ) { + jbiWrapper.appendPart(msgPart); + } else { + // it is type. + // check the element name is same as part + if ( !wsdlPart.getName().equals(msgPart.getLocalName()) ) { + throw new MessagingException("mismatched message content for part " + wsdlPart.getName()); + } + if ( !wsdlMsg.getQName().getNamespaceURI().equals(msgPart.getNamespaceURI()) ) { + throw new MessagingException("mismatched message content namespace for part " + wsdlPart.getName()); + } + // check the content is text or element. + List partContent = getChildElements(msgPart); + if ( partContent.size() > 0 ) { + // add content as part elements + jbiWrapper.appendPart(partContent); + } else { + // add the content as text + jbiWrapper.appendPart(msgPart.getTextContent()); + } + } + } + } + /** + * extracts the message parts from the jbiWrapper according to the abstract wsdl message + * definition passed to it. Use this method in denormalizing the jbi wrapper message into the + * binding protocol specific concrete message. + * @param jbiWrapper jbi wrapper object that contains message parts and the message type information. + * @param wsdlMsg abstract wsdl message definition to use in constructing the part elements. + */ + protected List getMessagePartsFromJBIWrapper(WSDL11JBIWrapper jbiWrapper, Message wsdlMsg) + throws MessagingException, ParserConfigurationException { + + List msgParts = new ArrayList(); + int jbiPartCount = jbiWrapper.getPartCount(); + List wsdlParts = wsdlMsg.getOrderedParts(null); + QName msgType = jbiWrapper.getType(); + if (!wsdlMsg.getQName().getNamespaceURI().equals(msgType.getNamespaceURI())) { + throw new MessagingException("Namespace mismatch between jbi wrapper message type and wsdl message"); + } + Document newDoc = jbiWrapper.getDocumentBuilder().newDocument(); + for ( int i=0; i < wsdlParts.size(); ++i ) { + Part wsdlPart = (Part) wsdlParts.get(i); + if ( i >= jbiPartCount ) { + throw new MessagingException("missing message content for part " + wsdlPart.getName()); + } + if ( wsdlPart.getElementName() != null ) { + msgParts.add(jbiWrapper.getPartAsElement(i)); + } else { + // it is type. create a new element for a typed part + // check the element name is same as part + String prefix = msgType.getPrefix(); + String nsURI = msgType.getNamespaceURI(); + String localName = wsdlPart.getName(); + Element partEl = newDoc.createElementNS(nsURI, prefix + ":" + localName); + partEl.setAttributeNS(XMLNS_NS, "xmlns:"+prefix, nsURI); + NodeList partContent = jbiWrapper.getPart(i); + appendChildren(partEl, partContent, newDoc, true); + msgParts.add(partEl); + } + } + return msgParts; + } + /** + * utility method that can append the nodeList passed to it to the element children. + * @param el element node to which the nodeList should be appended + * @param doc the document object that should be used to import the nodeList + * @param importNode true if the nodeList should be imported while appending the nodeList to the + * element children. false if no import is necessary. + */ + protected void appendChildren(Element el, NodeList nodeList, Document doc, boolean importNode) { + + for ( int pIdx = 0; pIdx < nodeList.getLength(); ++pIdx) { + Node node = nodeList.item(pIdx); + if ( importNode ) { + node = doc.importNode(node, true); + } + el.appendChild(node); + } + } + /** + * @param el element from which to extract the child elements + * @return List list of child Element nodes. + */ + protected List getChildElements(Element el) { + List list = new ArrayList(); + NodeList nodeList = el.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if (!(node instanceof Element) ){ + continue; + } + list.add((Element)node); + } + return list; + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java new file mode 100644 index 000000000..2cede99c7 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java @@ -0,0 +1,96 @@ +/* + * SEBindingExt.java + */ + +package net.openesb.component.ServiceEngine-archetype.common.wsdl; + +import java.io.PrintWriter; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation classes implement wsdl 1.1 extension model for the + * jbi service engine binding that is defined in jsr 208(sec. 5.5.6.1). to read/write concrete binding + * element in the wsdl definition for the service endpoint binding provided by the service engine. + * The wsdl definition with this binding information can be used in providing the service provider + * metadata returned by the service engine in Component.getServiceDescription. + *

+ * AbstractExtensionRegistry by default include this extension serializers in the + * registry to read/write this service engine binding type in the wsdl definition. + *

+ * During a service unit deployment/initialization in the service engine, the deployed wsdl definition + * is loaded and modified to provide this binding for the service provided by the engine. + * + * @see WSDLProcessor#createServiceEngine-archetypeBinding + * @see AbstractExtensionRegistry + * @see com.sun.jbi.sample.component.common.deployment.ServiceUnit#loadServiceDefinitions + * @author chikkala + */ +public interface SEBindingExt extends ExtensibilityElement, java.io.Serializable { + + public static final String NS_URI = "http://java.sun.com/xml/ns/jbi/binding/service+engine"; + public static final String NS_DEF_PREFIX = "jbise"; + /** Element names. */ + public static final String EL_BINDING_EXT = "binding"; + /**Qualified element names.*/ + public static final QName QN_BINDING_EXT = new QName(NS_URI, EL_BINDING_EXT); + + public static class SEBindingExtImpl extends AbstractExtensibilityElement implements SEBindingExt { + + public SEBindingExtImpl() { + setElementType(QN_BINDING_EXT); + } + @Override + public String toString() { + StringBuffer buff = new StringBuffer(); + buff.append("<"+NS_DEF_PREFIX+":"+EL_BINDING_EXT); + buff.append("/>"); + return buff.toString(); + } + /** + * creates and adds the jbi service engine binding extensibility element to the wsdl definition + * under specified binding definition. + */ + public static SEBindingExtImpl addExtensibilityElement(Definition wsdlDef, Binding binding) { + SEBindingExtImpl bindingExt = new SEBindingExt.SEBindingExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, binding, bindingExt, SEBindingExt.NS_DEF_PREFIX); + return bindingExt; + } + } + /** + * serializer and descrializer implementation for the binding extension element. + */ + public static class SEBindingExtSerializer extends AbstractExtensionSerializer { + + public SEBindingExtSerializer() { + super(Binding.class, QN_BINDING_EXT, SEBindingExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + SEBindingExt extObj = (SEBindingExt)extReg.createExtension(parentType, elementType); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg ) throws WSDLException { + + String elName = getQualifiedName(def, NS_URI, EL_BINDING_EXT); + + SEBindingExt extObj = (SEBindingExt)extension; + + StringBuffer buff = new StringBuffer(); + buff.append("<" + elName ); + buff.append("/>"); + pw.println(buff.toString()); + } + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java new file mode 100644 index 000000000..40480696c --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java @@ -0,0 +1,468 @@ +/* + * WSDL11JBIWrapper.java + * + */ + +package net.openesb.component.ServiceEngine-archetype.common.wsdl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.dom.DOMSource; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +/** + * This class wraps the wsdl11 messages to the jbi wrapper message suitable for + * processing in the wsdl2.0 model of the normalized message in jbi as defined in jsr208 like + * + * + * + * + * + * + * + * + * + * + * @author chikkala + */ +public class WSDL11JBIWrapper { + + public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/"; + public static final String WRAPPER_NAMESPACE = "http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper"; + public static final String DEF_NS_PREFIX = "jbiwrp"; + public static final String DEF_MESSAGE_NS_PREFIX = "msgns"; + public static final String JBI_MESSAGE_EL = "message"; + public static final String JBI_PART_EL = "part"; + public static final String VERSION_ATTR = "version"; + public static final String VERSION_ATTR_VALUE = "1.0"; + public static final String TYPE_ATTR = "type"; + public static final String NAME_ATTR = "name"; + + private static DocumentBuilder sDocBuilder = null; + /** qname of message attribute from wsdl:input, wsdl:output or wsdl:fault */ + private QName mType; + /** optional name attribute from wsdl:input, wsdl:output or wsdl:fault */ + private String mName; + /** each parts contents as node list */ + List mPartConentList = new ArrayList(); + + /** Creates a new instance of WSDL11JBIWrapper */ + public WSDL11JBIWrapper() { + } + /** creates the namespace aware document builder. extended classes can override this method + * to return the doc builder created else where. + */ + protected DocumentBuilder createDocumentBuilder() throws ParserConfigurationException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + return factory.newDocumentBuilder(); + } + /** return the document builder + * @return DocumentBuilder + */ + public final DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { + if ( WSDL11JBIWrapper.sDocBuilder == null ) { + WSDL11JBIWrapper.sDocBuilder = createDocumentBuilder(); + } + return WSDL11JBIWrapper.sDocBuilder; + } + /** + * @return type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + */ + public QName getType() { + return this.mType; + } + /** + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + */ + public void setType(QName type) { + this.mType = type; + } + /** @return name attribute from wsdl:input, wsdl:output or wsdl:fault. or null if not set. */ + public String getName() { + return this.mName; + } + /** + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault. can be null. + */ + public void setName(String name) { + this.mName = name; + } + /** + * appends part content as node list + */ + public void appendPart(NodeList partContent) { + this.mPartConentList.add(partContent); + } + /** + * append part content from the List of nodes + */ + public void appendPart(List partContent) { + this.mPartConentList.add(new NodeListImpl(partContent)); + } + /** + * append part content as element + */ + public void appendPart(Element partContent) { + this.mPartConentList.add(new NodeListImpl(partContent)); + } + /** + * append part content from DOMSource + */ + public void appendPart(DOMSource partContent) { + Element partConentEl = getElement(partContent.getNode()); + this.mPartConentList.add(new NodeListImpl(partConentEl)); + } + /** + * append part content as text node. + */ + public void appendPart(String partContent) { + Text textContent = null; + try { + textContent = this.getDocumentBuilder().newDocument().createTextNode(partContent); + } catch (ParserConfigurationException ex) { + ex.printStackTrace(); + } + if ( textContent != null ) { + this.mPartConentList.add(new NodeListImpl(textContent)); + } + } + /** + * append list of part contents each is a NodeList to the parts + */ + public void appendParts(List partContentList) { + this.mPartConentList.addAll(partContentList); + } + /** + * returned the ordered list of part contents. + */ + public List getParts() { + return Collections.unmodifiableList(this.mPartConentList); + } + /** + * return the number of parts + */ + public int getPartCount() { + return this.mPartConentList.size(); + } + /** + * return the part content at a particular index as NodeList. + */ + public NodeList getPart(int idx) { + return this.mPartConentList.get(idx); + } + /** + * return part context at a particular index as text + */ + public String getPartAsText(int idx) { + NodeList partNodes = getPart(idx); + Document doc; + try { + doc = this.getDocumentBuilder().newDocument(); + Element el = doc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_PART_EL); + for ( int i=0; i < partNodes.getLength(); ++i) { + el.appendChild(partNodes.item(i)); + } + return el.getTextContent(); + } catch (ParserConfigurationException ex) { + return null; + } + } + /** + * return part context at a particular index as Element + */ + public Element getPartAsElement(int idx) { + Element contentEl = null; + NodeList partNodes = getPart(idx); + for ( int i=0; i < partNodes.getLength(); ++i) { + Node node = partNodes.item(i); + if ( node instanceof Element) { + contentEl = (Element)node; + break; + } + } + return contentEl; + } + /** + * creates Document from this wrapper object. Before calling this method, + * the type, name (optional) and parts contents should be set. + * @return Document containing the wsdl 11 wrapper xml + */ + public Document toDocument() throws ParserConfigurationException { + + Document wrapperDoc = getDocumentBuilder().newDocument(); + Element jbiMessage = wrapperDoc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_MESSAGE_EL); + jbiMessage.setAttribute(VERSION_ATTR, VERSION_ATTR_VALUE); + wrapperDoc.appendChild(jbiMessage); + + QName type = this.getType(); + if ( type == null ) { + type = new QName("", "", DEF_MESSAGE_NS_PREFIX); + } + // set the jbiMessage attributes + String prefix = type.getPrefix(); + if (prefix == null || prefix.length() == 0) { + prefix = DEF_MESSAGE_NS_PREFIX; + } + jbiMessage.setAttribute(TYPE_ATTR, prefix + ":" + type.getLocalPart()); + jbiMessage.setAttributeNS( XMLNS_NS, "xmlns:" + prefix, type.getNamespaceURI()); + + String name = this.getName(); + if (name != null && name.trim().length() > 0 ) { + jbiMessage.setAttribute(NAME_ATTR, name); + } + + List partContentList = this.getParts(); + for ( NodeList nodeList : partContentList ) { + // set jbi part message + Element jbiPart = wrapperDoc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_PART_EL); + jbiMessage.appendChild(jbiPart); + for ( int i =0; i < nodeList.getLength(); ++i ) { + Node importedMsgNode = wrapperDoc.importNode(nodeList.item(i), true); + jbiPart.appendChild(importedMsgNode); + } + } + + return wrapperDoc; + + } + /** + * creates DOMSource from this wrapper object. Before calling this method, + * the type, name (optional) and parts contents should be set. + * @return DOMSource containing the wsdl 11 wrapper xml + */ + public DOMSource toDOMSource() throws ParserConfigurationException { + DOMSource wrappedSource = new DOMSource(); + wrappedSource.setNode(toDocument()); + return wrappedSource; + } + /** + * return Element node from a document node or non document. Use to extract + * the message root element. + * @root node from which the Element node will be extracted. + * @return Element node. + */ + public static Element getElement(Node root) { + Element msgEl = null; + if ( root instanceof Document) { + msgEl = ((Document)root).getDocumentElement(); + } else if (root instanceof Element) { + msgEl = (Element)root; + } else { + NodeList nodeList = root.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if ( node instanceof Element ) { + msgEl = (Element) node; + break; + } + } + } + return msgEl; + } + /** + * creates wrapper object from the DOMSource that has wsdl 11 wrapper xml. + * @param wrappedMsg wsdl 11 wrapper xml as DOMSource + * @return WSDL11JBIWrapper representing the wrapper xml. + */ + public static WSDL11JBIWrapper sourceToWrapper(DOMSource wrappedMsg) { + Element jbiMessage = getElement(wrappedMsg.getNode()); + if ( jbiMessage == null ) { + return null; + } + String nsURI = jbiMessage.getNamespaceURI(); + String tagName = jbiMessage.getLocalName(); + if (!WRAPPER_NAMESPACE.equals(nsURI) || !JBI_MESSAGE_EL.equals(tagName)) { + return null; + } + String name = jbiMessage.getAttribute(NAME_ATTR); + String typeQN = jbiMessage.getAttribute(TYPE_ATTR); + String typePrefix = ""; + String typeName = ""; + if ( typeQN != null && typeQN.trim().length() > 0 ) { + int idx = typeQN.indexOf(':'); + if ( idx >= 0 ) { + typePrefix = typeQN.substring(0, idx); + if ( typeQN.length() > idx ) { + typeName = typeQN.substring(idx+1); + } + } else { + typePrefix = ""; + typeName = typeQN; + } + } + String typeURI = jbiMessage.getAttribute("xmlns:" + typePrefix); + QName typeQName = new QName(typeURI, typeName, typePrefix); + + WSDL11JBIWrapper wrapper = new WSDL11JBIWrapper(); + wrapper.setName(name); + wrapper.setType(typeQName); + NodeList jbiPartList = jbiMessage.getElementsByTagNameNS(WRAPPER_NAMESPACE, JBI_PART_EL); + for ( int i=0; i < jbiPartList.getLength(); ++i) { + Node jbiPart = jbiPartList.item(i); + wrapper.appendPart(jbiPart.getChildNodes()); + } + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object and sets the type and name of the object + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name ) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = new WSDL11JBIWrapper(); + wrapper.setName(name); + wrapper.setType(type); + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object. useful when the message has one part and the + * part content has multiple child element. + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @param partContent part content as node list + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name, NodeList partContent) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name); + wrapper.appendPart(partContent); + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object. useful when the message has one part and the + * part content is a single element + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @param partContent part content as node list + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name, Element msgEl) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name, new WSDL11JBIWrapper.NodeListImpl(msgEl)); + return wrapper; + } + + public static WSDL11JBIWrapper createWrapper(QName type, String name, DOMSource inputSource) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name); + Node msgNode = getElement(inputSource.getNode()); + NodeList nodeList = new WSDL11JBIWrapper.NodeListImpl(msgNode); + wrapper.appendPart(nodeList); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations input element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createInputWrapper(Operation operation) throws ParserConfigurationException { + QName type = null; + String name = null; + + Input input = operation.getInput(); + if ( input == null ) { + return null; + } + name = input.getName(); + Message wsdlMsg = input.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations output element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createOutputWrapper(Operation operation) throws ParserConfigurationException { + QName type = null; + String name = null; + + Output output = operation.getOutput(); + if ( output == null) { + return null; + } + name = output.getName(); + Message wsdlMsg = output.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations output element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @param faultName fault name, can be null to look for the fault with no name. + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createFaultWrapper(Operation operation, String faultName) throws ParserConfigurationException { + QName type = null; + String name = null; + @SuppressWarnings("unchecked") + Map faultMap = operation.getFaults(); + Fault fault = faultMap.get(faultName); + + if ( fault == null ) { + return null; + } + name = fault.getName(); + Message wsdlMsg = fault.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * NodeList implementation. + */ + public static class NodeListImpl extends ArrayList implements NodeList { + + public NodeListImpl() { + super(); + } + + public NodeListImpl(Node aNode) { + super(); + if (aNode != null) { + this.add(aNode); + } + } + + public NodeListImpl(List nodes) { + if (nodes != null) { + this.addAll(nodes); + } + } + + public int getLength() { + return this.size(); + } + + public Node item(int idx) { + return this.get(idx); + } + + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java new file mode 100644 index 000000000..311dc0c26 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java @@ -0,0 +1,416 @@ +/* + * WSDLProcessor.java + */ + +package net.openesb.component.ServiceEngine-archetype.common.wsdl; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ElementExtensible; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.wsdl.xml.WSDLWriter; +import javax.xml.namespace.QName; + +/** + * This class is used to configure jwsdl(wsdl4j) to read and process wsdl documents with wsdl extensions. + * It provides set of helper methods to read and process the wsdl definitions from files with .wsdl + * extension from a specified directory. + *

+ * A Binding Component that is processing the wsdl extensions for its deployment configuration would + * extend this class and provide the required ExtensionRegistry that will have the extension serializers + * and deserializers configured to read/write the extensions from/to the java model. + *

+ * A Service Engine that is processing the wsdl during deployment can directly use this class + * to process the wsdl as the default implementation returned by this class configures the wsdl extension + * registry to read/write the service engine binding extensions. + * + * @see AbstractExtensionRegistry + * @see SEBindingExt + * @author chikkala + */ +public class WSDLProcessor { + + private String mXmlCatalogPath = "xml-catalog.xml"; + private String mWsdlDirPath = ""; + private WSDLReader mReader; + + /** Creates a new instance of WSDLProcessor + */ + public WSDLProcessor(String wsdlDir) { + this(wsdlDir, null); + } + /** Creates a new instance of WSDLProcessor + */ + public WSDLProcessor(String wsdlDir, String xmlCatPath) { + if ( wsdlDir != null ) { + this.mWsdlDirPath = wsdlDir; + } + if ( xmlCatPath != null ) { + this.mXmlCatalogPath = xmlCatPath; + } + } + /** @return directory path from which this class reads the wsdl files with .wsdl as file extension. */ + public String getWSDLDirectory() { + return this.mWsdlDirPath; + } + /** path to the xml catalog file in the service unit which can be used for Catalog-based entity + * and URI resolution. + */ + public String getXmlCatelogPath() { + return this.mXmlCatalogPath; + } + /** wsdl extension registry required for processing the wsdl extensions in the wsdl definition to + * java model. Binding component that is processing the wsdl extensions for its deployment + * configuration would provide the required ExtensionRegistry that will have the extension serializers + * and deserializers configured to read/write the extensions from/to the java model. + * @return ExtensionSerializer + * @see AbstractExtensionSerializer + */ + protected ExtensionRegistry getExtensionRegistry() { + return new AbstractExtensionRegistry() { + protected List createSerializers() { + return new ArrayList(); + } + }; + } + /** + * @return the WSDLReader configured with extension registry to process the wsdl extensions. + */ + public final WSDLReader getWSDLReader() throws WSDLException { + if ( this.mReader == null ) { + WSDLFactory factory = WSDLFactory.newInstance(); + this.mReader = factory.newWSDLReader(); + // reader.setFeature("javax.wsdl.verbose", true); + // reader.setFeature("javax.wsdl.importDocuments", true); + this.mReader.setExtensionRegistry(getExtensionRegistry()); + } + return this.mReader; + } + /** + * reads the wsdl file and returns the wsdl definition jwsdl model. + * @param wsldFilePath relative path to wsdl file from the the root wsdl directory returns from + * #getWSDLDirectory in the service unit or or absolute path . + * @return Definition + */ + public Definition readWSDL(String wsdlFilePath) throws WSDLException { + File wsdlFile = new File(wsdlFilePath); + if ( !wsdlFile.isAbsolute() ) { + wsdlFile = new File(this.mWsdlDirPath, wsdlFilePath); + } + return getWSDLReader().readWSDL(wsdlFile.getAbsolutePath()); + } + /** + * reads the files with .wsdl file extension in a directory. If the directory should + * be searched recursively, it searches this directory, all child directories of this + * directory and then to their child directories recursively. + * @param dir directory file to search for .wsdl files + * @param rec if set to true, it recursively searches the directory. if set to false, only + * this directory is searched. + * @return List of Files with .wsdl extension. + */ + public List listWSDLFiles(File dir, final boolean rec) throws IOException { + if ( dir == null || !dir.isDirectory()) { + throw new IOException(dir + " is not a directory for looking up wsdl files"); + } + List wsdlList = new ArrayList(); + File[] files = dir.listFiles(new FileFilter() { + public boolean accept(File pathname) { + if ( rec && pathname.isDirectory()) { + return true; + } else { + String name = pathname.getName(); + int idx = name.lastIndexOf('.'); + if ( idx < 0 ) { + return false; + } + String ext = name.substring(idx); + return ".wsdl".equalsIgnoreCase(ext); + } + } + }); + for ( File file : files ) { + if ( rec && file.isDirectory()) { + List wsdlFiles = listWSDLFiles(file, rec); + wsdlList.addAll(wsdlFiles); + } else { + wsdlList.add(file); + } + } + return wsdlList; + } + /** + * reads the files with .wsdl file extension in a directory fromDir and return the list of + * wsdl definitions corresponding to them. + * @param fromDir path to the directory relative to the root wsdl directory returns from + * #getWSDLDirectory or the absolute path to the directory. + */ + public List readWSDLs(String fromDir) throws WSDLException { + if ( fromDir == null ) { fromDir = ""; } + File wsdlDir = new File(fromDir); + if (!wsdlDir.isAbsolute()) { + wsdlDir = new File(this.mWsdlDirPath, fromDir); + } + + List wsdlFiles = new ArrayList(); + try { + wsdlFiles = listWSDLFiles(wsdlDir, true); + } catch (IOException ioEx) { + throw new WSDLException("WSDLFileReadError", ioEx.getMessage(),ioEx); + } + + List wsdlPaths = new ArrayList(); + for ( File wsdlFile : wsdlFiles) { + wsdlPaths.add(wsdlFile.getAbsolutePath()); + } + Collections.sort(wsdlPaths); + + List wsdlList = new ArrayList(); + for ( String wsdlPath : wsdlPaths ) { + Definition wsdlDef = readWSDL(wsdlPath); + wsdlList.add(wsdlDef); + } + return wsdlList; + } + /** + * finds PortType using port type ( interface ) qname. + */ + public static PortType findInterface(Definition wsdlDef, QName interfaceName) { + return wsdlDef.getPortType(interfaceName); + } + /** finds the Service using service qname */ + public static Service findService(Definition wsdlDef, QName serviceName) { + return wsdlDef.getService(serviceName); + } + /** finds the wsdl port using service qname and endpoint name */ + public static Port findServiceEndpoint(Definition wsdlDef, QName serviceName, String endpointName) { + Service service = null; + Port port = null; + service = findService(wsdlDef, serviceName); + if ( service != null ) { + port = service.getPort(endpointName); + } + return port; + } + /** + * finds the binding definition to which the service with serviceName and endpointName was bound. + */ + public static Binding findServiceBinding(Definition wsdlDef, QName serviceName, String endpointName) { + Binding binding = null; + Port port = findServiceEndpoint(wsdlDef, serviceName, endpointName); + if ( port != null ) { + binding = port.getBinding(); + } + return binding; + } + /** + * finds the binding definition using the interface(portType) qname with a + */ + public static Binding findInterfaceBinding(Definition wsdlDef, + QName interfaceQName, QName extQName) { + Map bindingMap = wsdlDef.getBindings(); + @SuppressWarnings("unchecked") + Collection bindings = bindingMap.values(); + for ( Binding binding : bindings ) { + if ( binding.getPortType().getQName().equals(interfaceQName)) { + return binding; + } + } + return null; + } + + /** + * find the wsdl4j operation corresponds to the interface+operation. + * @param wsdlDef wsdl definition + * @param portTypeQName portType QName + * @param opName operation name. if null, first operation in the portType + * is returned. + * @return Operation corresponding to the portType+opName + */ + public static Operation findOperation(Definition wsdlDef, + QName portTypeQName, String opName) { + Operation operation = null; + PortType portType = wsdlDef.getPortType(portTypeQName); + if ( portType != null ) { + if ( opName != null ) { + operation = portType.getOperation(opName, null, null); + } else { + @SuppressWarnings("unchecked") + List list = portType.getOperations(); + if ( list != null && list.size() > 0 ) { + operation = list.get(0); + } + } + } + return operation; + } + /** + * verifies whether the wsdl definition contains the specified service descriptions or not. Used + * to locate the wsdl definition for the services describes in service unit deployment + * descriptor(jbi.xm). + * @param interfaceName portType qname to find in the definition. can be null if you are trying to + * find only service endpoint description. + * @param serviceName qname for the service to find in this wsdl. can be null if + * you are trying to find only portType (abstract service) description. + * @param endpointName port name to find in the service definition. null if only + * service with any port should be looked up. + * + * @return true if the wsdl definition contains the specified service description. + */ + public static boolean isWSDLFor(Definition wsdlDef, + QName interfaceName, QName serviceName, String endpointName) { + PortType portType = null; + Service service = null; + Port port = null; + if ( interfaceName != null ) { + portType = findInterface(wsdlDef, interfaceName); + } + + if ( serviceName != null ) { + service = findService(wsdlDef, serviceName); + } + + if ( endpointName != null && service != null ) { + port = service.getPort(endpointName); + } + + boolean isWSDL = true; + + if ( (interfaceName != null && portType == null) || + ( serviceName != null && service == null ) || + ( endpointName != null && (service == null || port == null)) ) { + isWSDL = false; + } + + return isWSDL; + } + /** + * creates a binding definition that contains a service engine binding elements in the specified + * wsdl definition for a portType. It will try to find/create the binding element with interface + * local name with a "_JBISEBinding" suffix and add service engine binding element to it if it + * is not present. + * @param wsdl wsdl definition + * @param interfaceName portType qname to which the binding is created. + * @return a Binding contains service engine binding that is created for the portType. + */ + public Binding createServiceEngine-archetypeBinding(Definition wsdl, QName interfaceName) { + QName bindingQName = new QName(wsdl.getQName().getNamespaceURI(), + interfaceName.getLocalPart() + "_JBISEBinding"); + Binding binding = wsdl.getBinding(bindingQName); + if ( binding == null ) { + binding = wsdl.createBinding(); + binding.setQName(bindingQName); + binding.setPortType(wsdl.getPortType(interfaceName)); + binding.setUndefined(false); + + ExtensibilityElement bindingExt = + SEBindingExt.SEBindingExtImpl.addExtensibilityElement(wsdl, binding); + + wsdl.addBinding(binding); + } + return binding; + } + /** + * creates port and binding elements that provide the the service engine binding for a service. + * @param wsdl wsdl definition + * @param interfaceName portType qname to which the binding is created. + * @param serviceName service under which the port definition bound to the service engine binding + * should be created. + * @param endpointName port name. + * @return a Binding contains service engine binding that is created for the portType. + */ + public Binding createServiceEngine-archetypeBinding(Definition wsdl, QName interfaceName, QName serviceName, String endpointName ) { + Binding binding = null; + Service service = findService(wsdl, serviceName); + if ( service == null ) { + return null; + } + Port port = service.getPort(endpointName); + if ( port != null ) { + binding = port.getBinding(); + } else { + // create port + port = wsdl.createPort(); + port.setName(endpointName); + binding = createServiceEngine-archetypeBinding(wsdl, interfaceName); + port.setBinding(binding); + service.addPort(port); + } + return binding; + } + /** prints the wsdl to text from the wsdl definition */ + public static void printWSDL(PrintWriter out, Definition def) { + try { + WSDLFactory factory = WSDLFactory.newInstance(); + WSDLWriter wsdlWriter = factory.newWSDLWriter(); + wsdlWriter.writeWSDL(def, out); + } catch (WSDLException ex) { + ex.printStackTrace(out); + } + } + /** prints the wsdl to text from the wsdl definition */ + public static String printWSDLToString(Definition def) { + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + printWSDL(out, def); + out.close(); + return writer.getBuffer().toString(); + } + /** returns an existing namespace prefix or create one if not exists for the corresponding namespaceURI */ + public static String getNamespacePrefix(Definition def, String namespaceURI, String defPrefix) { + String prefix = null; + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + Set keySet = def.getNamespaces().keySet(); + String newPrefix = "ns"; + if ( defPrefix != null && defPrefix.trim().length() > 0 ){ + newPrefix = defPrefix; + } + prefix = newPrefix; + for ( int i=0; i < Integer.MAX_VALUE; ++i) { + if (!keySet.contains(prefix)) { + break; + } else { + prefix = newPrefix + i; + } + } + } + return prefix; + } + + /** + * creates and adds the jbi service engine binding extensibility element to the wsdl definition + * under specified binding definition. + */ + public static void addExtensibilityElement(Definition wsdlDef, + ElementExtensible extensibleEl, ExtensibilityElement extEl, String defPrefix) { + QName elementType = extEl.getElementType(); + String namespaceURI = elementType.getNamespaceURI(); + String prefix = wsdlDef.getPrefix(namespaceURI); + if ( prefix == null ) { + // no namespace prefix defined. create one. + prefix = WSDLProcessor.getNamespacePrefix(wsdlDef, namespaceURI, defPrefix); + wsdlDef.addNamespace(prefix, namespaceURI); + } + extensibleEl.addExtensibilityElement(extEl); + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/enginetest/ServiceEngineTest.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/enginetest/ServiceEngineTest.java new file mode 100644 index 000000000..fd9622623 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/enginetest/ServiceEngineTest.java @@ -0,0 +1,51 @@ +/* + * ServiceEngine-archetypeTest.java + */ + +package enginetest; + +import net.openesb.component.ServiceEngine-archetype.test.JBIComponentTestClient; +import net.openesb.component.ServiceEngine-archetype.test.SOAPBindingTestClient; +import java.util.Properties; + import junit.framework.TestCase; + +/** + * The test method in this testcase uses the SOAPBindingTestClient to send the + * input document to the echo service provided by service engine via soap binding + * component and receives the output document which will be placed in test results + * directory under the same package as this test case. + * @see com.sun.jbi.sample.component.test.SOAPBindingTestClinet + * @author chikkala + */ +public class ServiceEngineTest + extends TestCase +{ + public ServiceEngineTest(String testName) { + super(testName); + } + + public void test1() throws Exception { + String testPropertiesPath = "test1.properties"; + JBIComponentTestClient testClient = new SOAPBindingTestClient(); + Properties testProps = testClient.loadTestProperties(this.getClass(), testPropertiesPath); + testClient.testService(testProps); + } + + public void test2() throws Exception { + String testPropertiesPath = "test2.properties"; + JBIComponentTestClient testClient = new SOAPBindingTestClient(); + Properties testProps = testClient.loadTestProperties(this.getClass(), testPropertiesPath); + testClient.testService(testProps); + } + + public static void main(String[] args) { + try { + ServiceEngineTest compTest = new ServiceEngineTest("ServiceEngineTest"); + compTest.test1(); + compTest.test2(); + } catch(Exception ex) { + ex.printStackTrace(); + } + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/enginetest/test1.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/enginetest/test1.properties new file mode 100644 index 000000000..4a9f71699 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/enginetest/test1.properties @@ -0,0 +1,8 @@ +input.file=test1Input.xml +# expected.file=Expected.xml +output.file=test1Output.xml +soap.binding.inbound.endpoint.address.location=http://localhost:12010/ServiceEngine/greetings +soap.binding.soapaction=sayHello +fail.on.soap.fault=true + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/enginetest/test1Input.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/enginetest/test1Input.xml new file mode 100644 index 000000000..123c4fcb8 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/enginetest/test1Input.xml @@ -0,0 +1,12 @@ + + + + + + Srinivasan + Chikkala + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/enginetest/test2.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/enginetest/test2.properties new file mode 100644 index 000000000..584b79c72 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/enginetest/test2.properties @@ -0,0 +1,8 @@ +input.file=test2Input.xml +# expected.file=Expected.xml +output.file=test2Output.xml +soap.binding.inbound.endpoint.address.location=http://localhost:12010/ServiceEngine/greetings +soap.binding.soapaction=sayGoodbye +fail.on.soap.fault=true + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/enginetest/test2Input.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/enginetest/test2Input.xml new file mode 100644 index 000000000..c9ea58761 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/enginetest/test2Input.xml @@ -0,0 +1,12 @@ + + + + + + Srinivasan + Chikkala + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java new file mode 100644 index 000000000..b8137523c --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java @@ -0,0 +1,295 @@ +/* + * JBIComponentTestClient.java + */ + +package net.openesb.component.ServiceEngine-archetype.test; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Properties; + +/** + * This class implements the base framework for the testing the JBI components. + * Testing the JBI component involves may require deploying a service to the + * component(s) to enable the service provided by the test component and then + * invoking the service provided by the test component. If the test component is + * a binding component, then a service provider component such as sample service + * engine is required to test the component end to end. If the test component is a + * service engine, then the service on the test component can be invoked via + * soap/http binding component. + * + * This class provides the utilites to read the test properties, read the input + * message from the file and save the output to the file. The testService + * method implemented here can be executed as the test for the component. The + * testService method calls the invokeService method with the input document and + * expects a output document or error that will be saved to the output file. + * The method invokeService should be implemented by the extended test classes to + * inplement a suitable service consumer implemenation for the test compoent. + * See JMXBindingTestClient.java or SOAPBidningTestClient.java for more details + * on how to implement a partucular test service consumer. + * + * @author chikkala + */ +public abstract class JBIComponentTestClient { + + public static final String TEST_PROPS_FILE_PROP = "test.properties.file"; + public static final String TEST_RESULTS_DIR_PROP = "test.results.dir"; + public static final String TEST_SRC_DIR_PROP = "test.src.dir"; + + public static final String TEST_PACKAGE_PROP = "test.package.name"; + + public static final String INPUT_FILE_PROP = "input.file"; + public static final String EXPECTED_FILE_PROP = "expected.file"; + public static final String OUTPUT_FILE_PROP = "output.file"; + + public static final String DEF_TEST_PROP_FILE = "test.properties"; + public static final String DEF_INPUT_FILE = "Input.xml"; + public static final String DEF_OUTPUT_FILE = "Output.xml"; + public static final String DEF_TEST_RESULTS_DIR = "test-results"; + + public JBIComponentTestClient() { + } + /** + * returns the absolute resource path w.r.t. the packagePath if the resource name + * is relative else return the resourceName as it is. + * @param package name ( dot separated ) + * @param resourcName dot separated name or a absolute resource path + * @return abosolute resource path with path separator + */ + public static String resolveResourcePath(String packageName, String resourceName) { + String resourcePath = resourceName; + if ( !resourceName.startsWith("/")) { + // it is relative resource file. resolve it w.r.t. testPackage + String pkgDir = packageName.trim().replace('.', '/'); + if ( pkgDir.length() != 0 ) { + pkgDir += "/"; + } + resourcePath = "/" + pkgDir + resourceName; + } + return resourcePath; + } + /** + * loads the resource file as properties. + * @param testPackage package name where this test belongs + * @param testPropPath resource path relative to testPackage or absolute resource path + */ + public Properties loadTestProperties(String testPackage, String testPropPath) throws IOException { + String propsResourcePath = resolveResourcePath(testPackage, testPropPath); + + InputStream testPropIS = null; + try { + testPropIS = this.getClass().getResourceAsStream(propsResourcePath); + Properties testProps = new Properties(); + testProps.load(testPropIS); + testProps.setProperty(TEST_PACKAGE_PROP, testPackage); + return testProps; + } finally { + if ( testPropIS != null ) { + try { + testPropIS.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + } + /** + * load default test properties file in the testClass package. + * @param testClass Class where to look for the default test properties + * @param testPropPath resource path relative to testPackage or absolute resource path + * @return Properties test properties + */ + public Properties loadTestProperties(Class testClass, String testPropPath) throws IOException { + return loadTestProperties(testClass.getPackage().getName(), testPropPath ); + } + /** + * load default test properties file in the testClass package. + * @param testClass Class where to look for the default test properties + * @return Properties test properties + */ + public Properties loadTestProperties(Class testClass) throws IOException { + return loadTestProperties(testClass.getPackage().getName(), DEF_TEST_PROP_FILE ); + } + /** + * loads the resource file to string bugger + * @param inputFile resource file path + */ + public StringBuffer loadResourceFile(String resourcePath) throws FileNotFoundException, IOException { + + InputStream inputIS = null; + InputStreamReader inputReader = null; + BufferedReader reader = null; + StringWriter strWriter = null; + PrintWriter writer = null; + try { + inputIS = this.getClass().getResourceAsStream(resourcePath); + inputReader = new InputStreamReader(inputIS); + reader = new BufferedReader(inputReader); + strWriter = new StringWriter(); + writer = new PrintWriter(strWriter); + for ( String line = null; (line = reader.readLine()) != null ; ) { + writer.println(line); + } + writer.close(); + strWriter.close(); + return strWriter.getBuffer(); + } finally { + if ( inputIS != null ) { + try { + inputIS.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + } + + /** + * reads data from the reader and saves to file + * @param reader reader from which to read the data and save to file + * @param outputFilePath absolute file path + */ + public void saveOutputToFile(Reader reader, String outputFilePath) throws IOException { + + BufferedReader buff = null; + FileWriter fileWriter = null; + PrintWriter writer = null; + try { + buff = new BufferedReader(reader); + fileWriter = new FileWriter(outputFilePath); + writer = new PrintWriter(fileWriter); + for ( String line = null; (line = buff.readLine()) != null ; ) { + writer.println(line); + } + } finally { + if ( writer != null ) { + writer.close(); + } + if ( fileWriter != null ) { + fileWriter.close(); + } + } + } + + /** + * resource path. + */ + public String getInputFileResourcePath(Properties testProps) { + + String testPkg = testProps.getProperty(TEST_PACKAGE_PROP, ""); + String inputFile = testProps.getProperty(INPUT_FILE_PROP, DEF_INPUT_FILE); + String resourcePath = resolveResourcePath(testPkg, inputFile); + return resourcePath; + } + /** + * return resource path + */ + public String getExpectedFileResourcePath(Properties testProps) { + + String testPkg = testProps.getProperty(TEST_PACKAGE_PROP, ""); + String resourcePath = null; + String expFile = testProps.getProperty(EXPECTED_FILE_PROP, null); + if ( expFile != null ) { + resourcePath = resolveResourcePath(testPkg, expFile); + } + return resourcePath; + } + /** + * return the absolute path to the output file + */ + public String getOutputFilePath(Properties testProps) { + + String defPackage = this.getClass().getPackage().getName(); + String testPackage = testProps.getProperty(TEST_PACKAGE_PROP, defPackage); + String testPackageDir = testPackage.replace('.','/'); + String outputFile = testProps.getProperty(OUTPUT_FILE_PROP, DEF_OUTPUT_FILE); + + String userHomeDir = System.getProperty("user.home", ""); + String userDir = System.getProperty("user.dir", userHomeDir); + String defResultsDir = userDir + "/" + DEF_TEST_RESULTS_DIR; + String sysResultDir = System.getProperty(TEST_RESULTS_DIR_PROP, defResultsDir); + String resultDir = testProps.getProperty(TEST_RESULTS_DIR_PROP, sysResultDir); + + File outputDir = new File(resultDir, testPackageDir); + // System.out.println("Creating the test results output dir " + outputDir); + outputDir.mkdirs(); + return (new File(outputDir, outputFile)).getAbsolutePath(); + } + + /** + * This is the method where the actual service invocation code based on the + * type of client will be implemented. testService method calls this method + * after preparing the test input and then processes the output returned by + * this method to complte the test. + * @param inputDoc + * @param testProps + * @throws java.lang.Exception + * @return + */ + public abstract StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception; + + /** + * abstract method implemented by the extended classes to compare the output + * document with the expected output to determine the test is a failure or + * success. + * @param outputDoc + * @param expectedDoc + * @param testProps + * @throws java.lang.Exception + */ + public abstract void compareWithExpectedOutput(StringBuffer outputDoc, + StringBuffer expectedDoc, Properties testProps) throws Exception; + + /** + * This is the main test method that a test case will call to test the + * service. The standard steps that required to invoke the service and + * process the output will be done in this method. Each test case creates + * the test Properties required for that test and executes this method for + * testing the service by passing the test properties to it. This method + * prepares the input and executes the invokeService method to invoke a + * service with the prepared input. It then processes the return value from + * the invokeService to complete the test. + * + * @param testProps + * @throws java.lang.Exception + */ + public void testService(Properties testProps) throws Exception { + + String inFilePath = getInputFileResourcePath(testProps); + String outFilePath = getOutputFilePath(testProps); + String expFilePath = getExpectedFileResourcePath(testProps); + File outDir = (new File(outFilePath)).getParentFile(); + outDir.mkdirs(); + + StringBuffer outputDoc = new StringBuffer(); + + try { + StringBuffer inputDoc = loadResourceFile(inFilePath); + outputDoc = invokeService(inputDoc, testProps); + if ( expFilePath != null ) { + StringBuffer expOutputDoc = loadResourceFile(expFilePath); + compareWithExpectedOutput(inputDoc, expOutputDoc, testProps); + } + } catch (Exception ex) { + StringWriter out = new StringWriter(); + ex.printStackTrace(new PrintWriter(out)); + outputDoc.append(out.getBuffer()); + throw ex; + } finally { + if ( outputDoc != null ) { + System.out.println(outputDoc); + this.saveOutputToFile(new StringReader(outputDoc.toString()), outFilePath); + } + } + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java new file mode 100644 index 000000000..32cc645ff --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java @@ -0,0 +1,133 @@ +/* + * JMXBindingTestClient.java + */ + +package net.openesb.component.ServiceEngine-archetype.test; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanException; +import javax.management.MBeanServerConnection; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.management.ReflectionException; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; + +/** + * This class extends the JBIComponentTestClient and implements the invokeService + * method to test the proxy service consumer implementation by a binding component + * that can communicate with the external service consumers using JMX interface. + * @author chikkala + */ +public class JMXBindingTestClient extends JBIComponentTestClient { + + public static final String CONSUMER_EP_INBOUND_OPERATION_PROP = "consumer.jmx.bc.ep.operation"; + public static final String CONSUMER_EP_ADDRESS_MBEAN_PROP = "consumer.jmx.bc.ep.address.mbean"; + public static final String CONSUMER_EP_ADDRESS_URL_PROP = "consumer.jmx.bc.ep.address.serviceURL"; + public static final String CONSUMER_EP_ADDRESS_USERNAME_PROP = "consumer.jmx.bc.ep.address.username"; + public static final String CONSUMER_EP_ADDRESS_PASSWORD_PROP = "consumer.jmx.bc.ep.address.password"; + + public static final String PROVIDER_EP_INBOUND_OPERATION_PROP = "provider.jmx.bc.ep.operation"; + public static final String PROVIDER_EP_ADDRESS_MBEAN_PROP = "provider.jmx.bc.ep.address.mbean"; + public static final String PROVIDER_EP_ADDRESS_URL_PROP = "provider.jmx.bc.ep.address.serviceURL"; + public static final String PROVIDER_EP_ADDRESS_USERNAME_PROP = "provider.jmx.bc.ep.address.username"; + public static final String PROVIDER_EP_ADDRESS_PASSWORD_PROP = "provider.jmx.bc.ep.address.password"; + + + /** + * Creates a new instance of JMXBindingTestClient + */ + public JMXBindingTestClient() { + super(); + } + /** + * creates jmx connection to send the input message to the binding component. + */ + public static MBeanServerConnection getJMXConnection(Properties testProps) + throws MalformedURLException, IOException { + + String jmxUrl = testProps.getProperty(CONSUMER_EP_ADDRESS_URL_PROP); + String username = testProps.getProperty(CONSUMER_EP_ADDRESS_USERNAME_PROP); + String password = testProps.getProperty(CONSUMER_EP_ADDRESS_PASSWORD_PROP); + + Map env = new HashMap(); + if ( username != null ) { + String [] credentials = new String [] {username, password}; + env.put("jmx.remote.credentials", credentials); + env.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, JMXBindingTestClient.class.getClassLoader()); + } + JMXServiceURL serviceURL = new JMXServiceURL(jmxUrl); + JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, env); + MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection(); + return mbeanServerConnection; + } + /** + * constructs the jmx mbean objectname + */ + public static ObjectName createJMXEndpointMBeanObjectName(String endpointAddressMBean) throws MalformedObjectNameException { + // String objectName = JMX_DOMAIN + ":" + JMX_ENDPOINT_ADDRESS_KEY + "=" + endpointAddressMBean; + return new ObjectName(endpointAddressMBean); + } + /** + * invokes a jmx mbean to send message. + */ + public static StringBuffer invokeSendMessage(MBeanServerConnection jmxConn, ObjectName epAddressName, + String operation, StringBuffer inputDoc) + throws MalformedObjectNameException, InstanceNotFoundException, + MBeanException, ReflectionException, IOException { + StringBuffer outDoc = null; + + Object result = null; + String mbeanOperation = "sendMessage"; + + Object[] params = new Object[2]; + params[0] = operation; + params[1] = inputDoc; + + String[] signature = new String[2]; + signature[0] = "java.lang.String"; + signature[1] = "java.lang.StringBuffer"; + + result = jmxConn.invoke(epAddressName, mbeanOperation, params, signature); + if ( result != null ) { + outDoc = (StringBuffer)result; + } + + return outDoc; + } + /** + * invokes the service via jmx interface. + */ + public StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception { + + ObjectName epAddressName = new ObjectName(testProps.getProperty(CONSUMER_EP_ADDRESS_MBEAN_PROP)); + String operation = testProps.getProperty(CONSUMER_EP_INBOUND_OPERATION_PROP); + + MBeanServerConnection jmxConn = getJMXConnection(testProps); + StringBuffer outputDoc = null; + try { + outputDoc = invokeSendMessage(jmxConn, epAddressName, operation, inputDoc); + } catch (MBeanException ex) { + Exception targetEx = ex.getTargetException(); + if ( targetEx != null ) { + throw targetEx; + } else { + throw ex; + } + } + return outputDoc; + } + /** no expected output comparison implemented */ + public void compareWithExpectedOutput(StringBuffer inputDoc, + StringBuffer expectedDoc, + Properties testProps) throws Exception { + // throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java new file mode 100644 index 000000000..c84a6f78a --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java @@ -0,0 +1,156 @@ +/* + * SOAPBindingTestClient.java + */ + +package net.openesb.component.ServiceEngine-archetype.test; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Properties; +import javax.xml.soap.MessageFactory; +import javax.xml.soap.MimeHeaders; +import javax.xml.soap.SOAPConnection; +import javax.xml.soap.SOAPConnectionFactory; +import javax.xml.soap.SOAPException; +import javax.xml.soap.SOAPFault; +import javax.xml.soap.SOAPMessage; +import javax.xml.soap.SOAPPart; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +/** + * This class extends the JBIComponentTestClient and implements the invokeService + * method to test the Service Engine via SOAP Binding by invoking the service using + * SOAP Client that sends the message to the service provider via soaphttp binding. + * + * @author chikkala + */ +public class SOAPBindingTestClient extends JBIComponentTestClient { + + private static final String ADDRESS_PROP = "soap.binding.inbound.endpoint.address.location"; + private static final String SOAP_ACTION_PROP = "soap.binding.soapaction"; + private static final String FAIL_ON_SOAP_FAULT_PROP = "fail.on.soap.fault"; + + private static MessageFactory messageFactory; + private static SOAPConnectionFactory soapConnFactory; + private static SOAPConnection connection; + + public SOAPBindingTestClient() throws SOAPException { + init(); + } + /** initializes SOAP client */ + private synchronized void init() throws SOAPException { + if ( messageFactory == null ) { + messageFactory = MessageFactory.newInstance(); + } + if ( soapConnFactory == null ) { + soapConnFactory = SOAPConnectionFactory.newInstance(); + } + if ( connection == null ) { + connection = soapConnFactory.createConnection(); + } + } + + /** + * read in a soap message from the given input file + */ + private static SOAPMessage loadMessage(Reader inReader) throws SOAPException, IOException { + //Create and populate the message from a file + SOAPMessage message = messageFactory.createMessage(); + SOAPPart soapPart = message.getSOAPPart(); + StreamSource preppedMsgSrc = new StreamSource(inReader); + soapPart.setContent(preppedMsgSrc); + message.saveChanges(); + return message; + } + /** saves the SOAP message as xml text to a writer */ + private static void saveMessage(SOAPMessage response, Writer outWriter) + throws TransformerConfigurationException, SOAPException, TransformerException { + + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + transformerFactory.setAttribute("indent-number", new Integer(2)); + Transformer transformer = transformerFactory.newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + + SOAPPart replySOAPPart = response.getSOAPPart(); + Source sourceContent = replySOAPPart.getContent(); + StreamResult result = new StreamResult(outWriter); + try { + transformer.transform(sourceContent, result); + } catch (TransformerException ex) { + ex.printStackTrace(); + } + } + /** + * Send a soap message + * @param destination URL to send to + * @param message message to send + * @param expectedHttpStatus expected http status code or null if success is expected + * @return reply soap message + */ + private static SOAPMessage sendMessage(String destination, SOAPMessage message, String soapAction) throws SOAPException { + + // Add soapAction if not null + if (soapAction != null) { + MimeHeaders hd = message.getMimeHeaders(); + hd.setHeader("SOAPAction", soapAction); + } + // Send the message and get a reply + SOAPMessage reply = null; + reply = connection.call(message, destination); + return reply; + } + /** check the xml text in the StringBuffer passed contains SOAP Fault. */ + public boolean isSOAPFault(StringBuffer msgBuff) { + SOAPFault soapFault = null; + try { + SOAPMessage inMsg = loadMessage(new StringReader(msgBuff.toString())); + soapFault = inMsg.getSOAPBody().getFault(); + } catch (Exception ex) { + // any exception, means either no fault elem or invalid xml + } + return (soapFault != null); + } + /** + * invokes the service ny sending the input message and return the output + * message returned by the service. + */ + public StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception { + + String soapAction = testProps.getProperty(SOAP_ACTION_PROP); + String destination = testProps.getProperty(ADDRESS_PROP); + SOAPMessage inMsg = loadMessage(new StringReader(inputDoc.toString())); + SOAPMessage outMsg = sendMessage(destination, inMsg, soapAction); + StringWriter out = new StringWriter(); + saveMessage(outMsg, out); + StringBuffer outDoc = out.getBuffer(); + Boolean failOnSoapFault = Boolean.valueOf(testProps.getProperty(FAIL_ON_SOAP_FAULT_PROP, "false")); + if ( failOnSoapFault ) { + if (isSOAPFault(outDoc)) { + StringBuffer errBuff = new StringBuffer("########## SOAP FAULT ############ \n"); + errBuff.append(outDoc); + throw new Exception(errBuff.toString()); + } + } + return outDoc; + } + /** comparing the received output document with the expected document. throw + * exception if the docs are not same. throwing the exception in this method + * fails the test. + */ + public void compareWithExpectedOutput(StringBuffer outputDoc, + StringBuffer expectedDoc, + Properties testProps) throws Exception { + // throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/build.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/build.properties new file mode 100644 index 000000000..8770a8330 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/build.properties @@ -0,0 +1,19 @@ +# Build properties for the service assembly builds +# user.properties.file=../../user.properties +src.dir=src +# This directory is removed when the project is cleaned: +build.dir=build +service.assembly.name=testSA + +#no.deps=true set the no.deps property if there are no SUs to build +# for each testSU define the properties here. +# dependent BC SU projects dependency +# service unit name +service.unit.name.testSUBC=testSUBC +# service unit project directory +project.testSUBC=testSUBC + +# service unit name +service.unit.name.testSUSE=testSUSE +# service unit project directory +project.testSUSE=testSUSE diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/build.xml new file mode 100644 index 000000000..12d519c6a --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/build.xml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.assembly.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/src/META-INF/jbi.xml new file mode 100644 index 000000000..e19a6cf78 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/src/META-INF/jbi.xml @@ -0,0 +1,41 @@ + + + + + ServiceEngine-archetype_TestSA + This is a test Service Assembly to test Engine + + + + + ServiceEngine-archetype_TestSUBC + This service unit enables soap inbound endpoint for a service in service engine + + + testSUBC.zip + sun-http-binding + + + + + ServiceEngine-archetype_TestSUSE + This service unit enables greetings service provider in service engine + + + testSUSE.zip + ServiceEngine-archetype + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/build.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/build.properties new file mode 100644 index 000000000..387359c01 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/build.properties @@ -0,0 +1,7 @@ +# Build properties for the service unit builds +src.dir=src +# This directory is removed when the project is cleaned: +#build.dir=../../../build/test/testSU/build +build.dir=build +service.unit.name=testSUSE + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/build.xml new file mode 100644 index 000000000..4c4b3d9a1 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/build/testSUBC.zip b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/build/testSUBC.zip new file mode 100644 index 000000000..f4205815d Binary files /dev/null and b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/build/testSUBC.zip differ diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/build/testSUBC/Greetings.wsdl b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/build/testSUBC/Greetings.wsdl new file mode 100644 index 000000000..038d91bcd --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/build/testSUBC/Greetings.wsdl @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml new file mode 100644 index 000000000..d468f995e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/build/testSUBC/META-INF/jbi.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/src/Greetings.wsdl b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/src/Greetings.wsdl new file mode 100644 index 000000000..8a160abd0 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/src/Greetings.wsdl @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/src/META-INF/jbi.xml new file mode 100644 index 000000000..d468f995e --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUBC/src/META-INF/jbi.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build.properties new file mode 100644 index 000000000..387359c01 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build.properties @@ -0,0 +1,7 @@ +# Build properties for the service unit builds +src.dir=src +# This directory is removed when the project is cleaned: +#build.dir=../../../build/test/testSU/build +build.dir=build +service.unit.name=testSUSE + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build.xml new file mode 100644 index 000000000..38fc64f50 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE.zip b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE.zip new file mode 100644 index 000000000..2db1a3a5c Binary files /dev/null and b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE.zip differ diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE/Greetings.wsdl b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE/Greetings.wsdl new file mode 100644 index 000000000..038d91bcd --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE/Greetings.wsdl @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml new file mode 100644 index 000000000..f9b3498bc --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE/META-INF/jbi.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE/goodbye.xsl b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE/goodbye.xsl new file mode 100644 index 000000000..c60e39b73 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE/goodbye.xsl @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + Goodbye ! Have a great time. + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE/hello.xsl b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE/hello.xsl new file mode 100644 index 000000000..994b66f98 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE/hello.xsl @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + Hello ! + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE/xsltmap.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE/xsltmap.properties new file mode 100644 index 000000000..06e4b6631 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/build/testSUSE/xsltmap.properties @@ -0,0 +1,28 @@ +# properties will be used to find the xslt file that will be used for invoking a +# service operation. +# The "xsltmap.properties" file should contain two types of properties +# 1. for namespace prefix to namespaceURI map that starts with "xmlns." prefix like +# "xmlns.tns-prefix=http://www.sun.com/jbi/examples/sample-service/echo" +# 2. a service description to xslt file properties with syntax like +# "{tns-prefix}service-name=xslt_file_name" and +# "{tns-prefix}service-name.{tns-prefix}operation-name=xslt_file_name" and +# "{tns-prefix}service-name.{tns-prefix}interface-name.operation-name=xslt_file_name" . +# the service description property is a "." delimited tokens that represents +# a serive or interface qname and a operation name. To locate xslt file either with +# service qname or service qname and operaton or serivice qname and interface qname +# and operation, all the three properties specified above should be there for each xslt file. +# + +xmlns.greet1=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greet2=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greettypes=http://www.sun.com/jbi/examples/sample-service/greetings/types +# just service level default settings +{greet2}greetService=hello.xsl +# service and operation +{greet2}greetService.{greet1}sayHello=hello.xsl +# service, interface, operation +{greet2}greetService.{greet1}greetings.sayHello=hello.xsl +# service and operation +{greet2}greetService.{greet1}sayGoodbye=goodbye.xsl +# service, interface, operation +{greet2}greetService.{greet1}greetings.sayGoodbye=goodbye.xsl diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/src/Greetings.wsdl b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/src/Greetings.wsdl new file mode 100644 index 000000000..8a160abd0 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/src/Greetings.wsdl @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/src/META-INF/jbi.xml new file mode 100644 index 000000000..f9b3498bc --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/src/META-INF/jbi.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/src/goodbye.xsl b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/src/goodbye.xsl new file mode 100644 index 000000000..c60e39b73 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/src/goodbye.xsl @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + Goodbye ! Have a great time. + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/src/hello.xsl b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/src/hello.xsl new file mode 100644 index 000000000..994b66f98 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/src/hello.xsl @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + Hello ! + + + + + diff --git a/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/src/xsltmap.properties b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/src/xsltmap.properties new file mode 100644 index 000000000..06e4b6631 --- /dev/null +++ b/maven-archtype-v2/maven-archetype-service-engine-v2/target/test-classes/projects/basic/project/ServiceEngine-archetype/test/testSA/testSUSE/src/xsltmap.properties @@ -0,0 +1,28 @@ +# properties will be used to find the xslt file that will be used for invoking a +# service operation. +# The "xsltmap.properties" file should contain two types of properties +# 1. for namespace prefix to namespaceURI map that starts with "xmlns." prefix like +# "xmlns.tns-prefix=http://www.sun.com/jbi/examples/sample-service/echo" +# 2. a service description to xslt file properties with syntax like +# "{tns-prefix}service-name=xslt_file_name" and +# "{tns-prefix}service-name.{tns-prefix}operation-name=xslt_file_name" and +# "{tns-prefix}service-name.{tns-prefix}interface-name.operation-name=xslt_file_name" . +# the service description property is a "." delimited tokens that represents +# a serive or interface qname and a operation name. To locate xslt file either with +# service qname or service qname and operaton or serivice qname and interface qname +# and operation, all the three properties specified above should be there for each xslt file. +# + +xmlns.greet1=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greet2=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greettypes=http://www.sun.com/jbi/examples/sample-service/greetings/types +# just service level default settings +{greet2}greetService=hello.xsl +# service and operation +{greet2}greetService.{greet1}sayHello=hello.xsl +# service, interface, operation +{greet2}greetService.{greet1}greetings.sayHello=hello.xsl +# service and operation +{greet2}greetService.{greet1}sayGoodbye=goodbye.xsl +# service, interface, operation +{greet2}greetService.{greet1}greetings.sayGoodbye=goodbye.xsl diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/pom.xml b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/pom.xml new file mode 100644 index 000000000..603bf268f --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + open-jbi-components + BindingComponent-Plugin-archetype + 1.0-SNAPSHOT + maven-archetype + + BindingComponent-Plugin-archetype + + + + + org.apache.maven.archetype + archetype-packaging + 2.2 + + + + + + + maven-archetype-plugin + 2.2 + + + + + + Maven project for JBI Component that contains the + maven and netbeans build setup and component code to build and test the JBI Component. + + http://open-esb.org + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/META-INF/maven/archetype-metadata.xml b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 000000000..417c58560 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,69 @@ + + + + + deploy-plugin/nbproject + + **/*.xml + **/*.properties + + + + deploy-plugin/src + + **/*.java + **/*.xml + **/*.properties + + + + nbproject + + **/*.xml + **/*.properties + + + + nbproject/private + + **/*.xml + **/*.properties + + + + deploy-plugin + + **/*.xml + + + + deploy-plugin/src + + **/*.ExtensibilityElementTemplateProvider + **/*.ElementFactory + **/*.png + **/*.ValidatorSchemaFactory + **/*.Validator + **/*.xsd + + + + deploy-plugin + + **/*.mf + + + + + + build.xml + install-params.properties + m2nbbuild-impl.xml + m2nbbuild.properties + m2nbbuild.xml + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/build.xml b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/build.xml new file mode 100644 index 000000000..14afd1d29 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/build.xml @@ -0,0 +1,72 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + Builds, tests, and runs the project ${artifactId}. + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/build.xml b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/build.xml new file mode 100644 index 000000000..12e9743bf --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/build.xml @@ -0,0 +1,11 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + Builds, tests, and runs the project ${artifactId}. + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/manifest.mf b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/manifest.mf new file mode 100644 index 000000000..7b9bf6601 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/manifest.mf @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: ${artifactId} +OpenIDE-Module-Layer: ${artifactId}/layer.xml +OpenIDE-Module-Localizing-Bundle: ${artifactId}/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml new file mode 100644 index 000000000..37d0e9fcf --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml @@ -0,0 +1,30 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/genfiles.properties b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/genfiles.properties new file mode 100644 index 000000000..c0843e42b --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/genfiles.properties @@ -0,0 +1,11 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +build.xml.data.CRC32=43b76edb +build.xml.script.CRC32=09d16688 +build.xml.stylesheet.CRC32=a56c6a5b@2.50.1 +${symbol_pound} This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +${symbol_pound} Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=43b76edb +nbproject/build-impl.xml.script.CRC32=899b03af +nbproject/build-impl.xml.stylesheet.CRC32=68e521fc@2.50.1 diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/platform.properties b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/platform.properties new file mode 100644 index 000000000..7ac9923fb --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/platform.properties @@ -0,0 +1,4 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +nbplatform.active=default diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/private/platform-private.properties b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/private/platform-private.properties new file mode 100644 index 000000000..3ac32342a --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/private/platform-private.properties @@ -0,0 +1,4 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +user.properties.file=D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working57${symbol_escape}${symbol_escape}.netbeans${symbol_escape}${symbol_escape}openesb${symbol_escape}${symbol_escape}build.properties diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.properties b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.properties new file mode 100644 index 000000000..a5e2da3b1 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.properties @@ -0,0 +1,7 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +javac.compilerargs=-Xlint -Xlint:-serial +javac.source=1.5 +nbm.homepage=http://www.netbeans.org +nbm.module.author=logicoyparam diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml new file mode 100644 index 000000000..671ff920b --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml @@ -0,0 +1,59 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + org.netbeans.modules.apisupport.project + + + ${artifactId} + + + + org.netbeans.modules.xml.schema.model + + + + 1 + 1.2 + + + + org.netbeans.modules.xml.wsdl.bindingsupport.api + + + + 1.0 + + + + org.netbeans.modules.xml.wsdl.model + + + + 1 + 1.2 + + + + org.netbeans.modules.xml.xam + + + + 1 + 1.2 + + + + org.openide.util + + + + 7.9.0.1 + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.modules.xml.wsdl.bindingsupport.spi.ExtensibilityElementTemplateProvider b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.modules.xml.wsdl.bindingsupport.spi.ExtensibilityElementTemplateProvider new file mode 100644 index 000000000..5d706f033 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.modules.xml.wsdl.bindingsupport.spi.ExtensibilityElementTemplateProvider @@ -0,0 +1 @@ +cname.template.WSDLExtTemplateProvider diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.modules.xml.wsdl.model.spi.ElementFactory b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.modules.xml.wsdl.model.spi.ElementFactory new file mode 100644 index 000000000..90f3ddb3c --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.modules.xml.wsdl.model.spi.ElementFactory @@ -0,0 +1,6 @@ +cname.model.ExtElementFactoryProvider$BindingExtFactory +cname.model.ExtElementFactoryProvider$OperationExtFactory +cname.model.ExtElementFactoryProvider$InputExtFactory +cname.model.ExtElementFactoryProvider$OutputExtFactory +cname.model.ExtElementFactoryProvider$FaultExtFactory +cname.model.ExtElementFactoryProvider$PortExtFactory diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.modules.xml.wsdl.validator.spi.ValidatorSchemaFactory b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.modules.xml.wsdl.validator.spi.ValidatorSchemaFactory new file mode 100644 index 000000000..5caf7af1f --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.modules.xml.wsdl.validator.spi.ValidatorSchemaFactory @@ -0,0 +1 @@ +cname.validator.WSDLExtValidatorSchemaFactory diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.modules.xml.xam.spi.Validator b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.modules.xml.xam.spi.Validator new file mode 100644 index 000000000..695264745 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/META-INF/services/org.netbeans.modules.xml.xam.spi.Validator @@ -0,0 +1,2 @@ +cname.validator.WSDLExtValidator + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/BindingComponentWsdlExt.xsd b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/BindingComponentWsdlExt.xsd new file mode 100644 index 000000000..82c1c9ba8 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/BindingComponentWsdlExt.xsd @@ -0,0 +1,115 @@ + + + + + + + + + "binding" defines a protocol based binding details. + + + + + + + + + + + + + + "operation" defines the protocol based binding operation details. + + + + + + + + + + + + + + + + "input" defines the protocol based binding input details. + + + + + + + + + + + + + + + "output" defines the protocol based binding output details. + + + + + + + + + + + + + + + "fault" defines the protocol based binding fault details. + + + + + + + + + + + + + + + "address" indicates protocol based binding port details. + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/Bundle.properties b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/Bundle.properties new file mode 100644 index 000000000..446e39e02 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/Bundle.properties @@ -0,0 +1,21 @@ +# binding component deployment plugin resource bundle +# binding deploy plugin +OpenIDE-Module-Name=JBI Deployment Plugin[${artifactId}] +# deployment plugin +OpenIDE-Module-Short-Description=Binding component deployment plugin for ${artifactId} +# deployment plugin for adding wsdl extensions related to the binding component to the wsdl editor +OpenIDE-Module-Long-Description=Deployment plugin for adding wsdl extensions related to this binding component to the wsdl editor +# category +OpenIDE-Module-Display-Category=CAPS + +# WSDLEditor mapping names for the Binding +WSDLEditor/Binding/${artifactId}BindingExt=${artifactId} Binding +WSDLEditor/BindingOperation/${artifactId}OperationExt=${artifactId} Binding Operation extension +WSDLEditor/BindingOperationInput/${artifactId}InputExt=${artifactId} Binding Input extension +WSDLEditor/BindingOperationOutput/${artifactId}OutputExt=${artifactId} Binding Output extension +WSDLEditor/BindingOperationFault/${artifactId}FaultExt=${artifactId} Binding Fault extension +WSDLEditor/ServicePort/${artifactId}PortExt=${artifactId} Service Port extension + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/layer.xml b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/layer.xml new file mode 100644 index 000000000..54dd3a897 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/layer.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/BindingExt.java b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/BindingExt.java new file mode 100644 index 000000000..3d50c6f9e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/BindingExt.java @@ -0,0 +1,47 @@ +/* + * BindingExt.java + */ +package net.openesb.component.${artifactId}.model; + +import org.netbeans.modules.xml.wsdl.model.Binding; +import org.netbeans.modules.xml.wsdl.model.WSDLModel; +import org.netbeans.modules.xml.xam.Component; +import org.w3c.dom.Element; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * extension element. + * + * @author chikkala + */ +public interface BindingExt extends ExtComponent { + +//TODO: define get/set methods for properties for BindingExt if the extension element has attributes. + /** + * This class is an implementation of BindingExt interface that provides + * java model for binding extensibility element. + */ + public static class BindingExtImpl extends ExtModelImpl implements BindingExt { + + public BindingExtImpl(WSDLModel model, Element e) { + super(model, e); + } + + public BindingExtImpl(WSDLModel model) { + this(model, createPrefixedElement(QN_BINDING_EXT, model)); + } + + public void accept(ExtVisitor visitor) { + visitor.visit(this); + } + + @Override + public boolean canBeAddedTo(Component target) { + if (target instanceof Binding) { + return true; + } + return false; + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/ExtAttribute.java b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/ExtAttribute.java new file mode 100644 index 000000000..58abbf15c --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/ExtAttribute.java @@ -0,0 +1,53 @@ +/* + * ExtAttribute.java + */ +package net.openesb.component.${artifactId}.model; + +import org.netbeans.modules.xml.xam.dom.Attribute; + +/** + * @author chikkala + */ +public enum ExtAttribute implements Attribute, ExtConstants { + + //TODO: define any additional extension elements attributes here + ACTION(ATTR_ACTION), + SERVICE_URL(ATTR_SERVICE_URL), + USERNAME(ATTR_USERNAME), + PASSWORD(ATTR_PASSWORD), + MBEAN(ATTR_MBEAN); + private String name; + private Class type; + private Class subtype; + + ExtAttribute(String name) { + this(name, String.class); + } + + ExtAttribute(String name, Class type) { + this(name, type, null); + } + + ExtAttribute(String name, Class type, Class subtype) { + this.name = name; + this.type = type; + this.subtype = subtype; + } + + @Override + public String toString() { + return name; + } + + public Class getType() { + return type; + } + + public String getName() { + return name; + } + + public Class getMemberType() { + return subtype; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/ExtComponent.java b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/ExtComponent.java new file mode 100644 index 000000000..cf3f28f42 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/ExtComponent.java @@ -0,0 +1,35 @@ +/* + * ExtComponent.java + */ +package net.openesb.component.${artifactId}.model; + +import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement; +import org.netbeans.modules.xml.wsdl.model.WSDLModel; +import org.netbeans.modules.xml.wsdl.model.spi.GenericExtensibilityElement; +import org.w3c.dom.Element; + +/** + * This is the base class for the extension model + * + * @author chikkala + */ +public interface ExtComponent extends ExtConstants, ExtensibilityElement { + + void accept(ExtVisitor visitor); + + /** + * this class is the base class for the extension model objects + */ + public static abstract class ExtModelImpl + extends GenericExtensibilityElement implements ExtComponent { + + public ExtModelImpl(WSDLModel model, Element e) { + super(model, e); + } + + @Override + protected String getNamespaceURI() { + return NS_URI; + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/ExtConstants.java b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/ExtConstants.java new file mode 100644 index 000000000..3e00176d2 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/ExtConstants.java @@ -0,0 +1,47 @@ +/* + * ExtConstants.java + * + */ +package net.openesb.component.${artifactId}.model; + +import javax.xml.namespace.QName; + +/** + * This interface defines the constants for the namespace, elements, attributes + * and qnames corresponding to the wsdl extensions that this component + * processes. These constants will be used in the wsdl extension model used to + * process a particular wsdl extensions. + * + * @author chikkala + */ +public interface ExtConstants { + + public static final String NS_URI_WSDL = "http://schemas.xmlsoap.org/wsdl/"; + public static final String NS_URI_XMLNS = "http://www.w3.org/2000/xmlns/"; + /** + * wsdl extension namespace processed by this wsdl extension model + */ + public static final String NS_URI = "http://java.sun.com/jbi/wsdl-extensions/sample/jmx-bc/"; + public static final String NS_DEF_PREFIX = "jmxbc"; + // wsdl extension element names. + public static final String EL_BINDING_EXT = "binding"; + public static final String EL_OPERATION_EXT = "operation"; + public static final String EL_INPUT_EXT = "input"; + public static final String EL_OUTPUT_EXT = "output"; + public static final String EL_FAULT_EXT = "fault"; + public static final String EL_PORT_EXT = "address"; + // Qualified wsdl extension element names. + public static final QName QN_BINDING_EXT = new QName(NS_URI, EL_BINDING_EXT); + public static final QName QN_OPERATION_EXT = new QName(NS_URI, EL_OPERATION_EXT); + public static final QName QN_INPUT_EXT = new QName(NS_URI, EL_INPUT_EXT); + public static final QName QN_OUTPUT_EXT = new QName(NS_URI, EL_OUTPUT_EXT); + public static final QName QN_FAULT_EXT = new QName(NS_URI, EL_FAULT_EXT); + public static final QName QN_PORT_EXT = new QName(NS_URI, EL_PORT_EXT); + //TODO: define any additional extension element attribute names here. + // wsdl extension elements attribute names. + public static final String ATTR_ACTION = "action"; + public static final String ATTR_SERVICE_URL = "serviceURL"; + public static final String ATTR_USERNAME = "username"; + public static final String ATTR_PASSWORD = "password"; + public static final String ATTR_MBEAN = "mbean"; +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/ExtElementFactoryProvider.java b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/ExtElementFactoryProvider.java new file mode 100644 index 000000000..0d3711cc4 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/ExtElementFactoryProvider.java @@ -0,0 +1,85 @@ +/* + * ExtElementFactoryProvider + */ +package net.openesb.component.${artifactId}.model; + +import java.util.Collections; +import java.util.Set; +import javax.xml.namespace.QName; +import org.netbeans.modules.xml.wsdl.model.WSDLComponent; +import org.netbeans.modules.xml.wsdl.model.spi.ElementFactory; +import org.w3c.dom.Element; + +/** + * Factory class that has wsdl extension elements model factories + * + * @author chikkala + */ +public class ExtElementFactoryProvider { + + public static class BindingExtFactory extends ElementFactory { + + public Set getElementQNames() { + return Collections.singleton(ExtConstants.QN_BINDING_EXT); + } + + public WSDLComponent create(WSDLComponent context, Element element) { + return new BindingExt.BindingExtImpl(context.getModel(), element); + } + } + + public static class OperationExtFactory extends ElementFactory { + + public Set getElementQNames() { + return Collections.singleton(ExtConstants.QN_OPERATION_EXT); + } + + public WSDLComponent create(WSDLComponent context, Element element) { + return new OperationExt.OperationExtImpl(context.getModel(), element); + } + } + + public static class InputExtFactory extends ElementFactory { + + public Set getElementQNames() { + return Collections.singleton(ExtConstants.QN_INPUT_EXT); + } + + public WSDLComponent create(WSDLComponent context, Element element) { + return new InputExt.InputExtImpl(context.getModel(), element); + } + } + + public static class OutputExtFactory extends ElementFactory { + + public Set getElementQNames() { + return Collections.singleton(ExtConstants.QN_OUTPUT_EXT); + } + + public WSDLComponent create(WSDLComponent context, Element element) { + return new OutputExt.OutputExtImpl(context.getModel(), element); + } + } + + public static class FaultExtFactory extends ElementFactory { + + public Set getElementQNames() { + return Collections.singleton(ExtConstants.QN_FAULT_EXT); + } + + public WSDLComponent create(WSDLComponent context, Element element) { + return new FaultExt.FaultExtImpl(context.getModel(), element); + } + } + + public static class PortExtFactory extends ElementFactory { + + public Set getElementQNames() { + return Collections.singleton(ExtConstants.QN_PORT_EXT); + } + + public WSDLComponent create(WSDLComponent context, Element element) { + return new PortExt.PortExtImpl(context.getModel(), element); + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/ExtVisitor.java b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/ExtVisitor.java new file mode 100644 index 000000000..606b4da96 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/ExtVisitor.java @@ -0,0 +1,25 @@ +/* + * ExtVisitor.java + */ +package net.openesb.component.${artifactId}.model; + +/** + * This interface provides the visitor pattern to validate the extension model + * objects. + * + * @author chikkala + */ +public interface ExtVisitor { + + void visit(BindingExt bindingExt); + + void visit(OperationExt operationExt); + + void visit(InputExt inputExt); + + void visit(OutputExt outputExt); + + void visit(FaultExt faultExt); + + void visit(PortExt portExt); +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/FaultExt.java b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/FaultExt.java new file mode 100644 index 000000000..7816822ac --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/FaultExt.java @@ -0,0 +1,47 @@ +/* + * FaultExt.java + */ +package net.openesb.component.${artifactId}.model; + +import org.netbeans.modules.xml.wsdl.model.BindingFault; +import org.netbeans.modules.xml.wsdl.model.WSDLModel; +import org.netbeans.modules.xml.xam.Component; +import org.w3c.dom.Element; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * operation fault extension element. + * + * @author chikkala + */ +public interface FaultExt extends ExtComponent { + +//TODO: define get/set methods for properties for FaultExt if the extension element has attributes. + /** + * This class is an implementation of FaultExt interface that provides java + * model for binding operation fault extensibility element. + */ + public static class FaultExtImpl extends ExtModelImpl implements FaultExt { + + public FaultExtImpl(WSDLModel model, Element e) { + super(model, e); + } + + public FaultExtImpl(WSDLModel model) { + this(model, createPrefixedElement(QN_FAULT_EXT, model)); + } + + public void accept(ExtVisitor visitor) { + visitor.visit(this); + } + + @Override + public boolean canBeAddedTo(Component target) { + if (target instanceof BindingFault) { + return true; + } + return false; + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/InputExt.java b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/InputExt.java new file mode 100644 index 000000000..4aeb4fcd7 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/InputExt.java @@ -0,0 +1,47 @@ +/* + * InputExt.java + */ +package net.openesb.component.${artifactId}.model; + +import org.netbeans.modules.xml.wsdl.model.BindingInput; +import org.netbeans.modules.xml.wsdl.model.WSDLModel; +import org.netbeans.modules.xml.xam.Component; +import org.w3c.dom.Element; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * operation input extension element. + * + * @author chikkala + */ +public interface InputExt extends ExtComponent { + +//TODO: define get/set methods for properties for InputExt if the extension element has attributes. + /** + * This class is an implementation of InputExt interface that provides java + * model for binding operation input extensibility element. + */ + public static class InputExtImpl extends ExtModelImpl implements InputExt { + + public InputExtImpl(WSDLModel model, Element e) { + super(model, e); + } + + public InputExtImpl(WSDLModel model) { + this(model, createPrefixedElement(QN_INPUT_EXT, model)); + } + + public void accept(ExtVisitor visitor) { + visitor.visit(this); + } + + @Override + public boolean canBeAddedTo(Component target) { + if (target instanceof BindingInput) { + return true; + } + return false; + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/OperationExt.java b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/OperationExt.java new file mode 100644 index 000000000..408774e38 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/OperationExt.java @@ -0,0 +1,68 @@ +/* + * OperationExt.java + */ +package net.openesb.component.${artifactId}.model; + +import org.netbeans.modules.xml.wsdl.model.BindingOperation; +import org.netbeans.modules.xml.wsdl.model.WSDLModel; +import org.netbeans.modules.xml.xam.Component; +import org.w3c.dom.Element; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * operation extension element. + * + * @author chikkala + */ +public interface OperationExt extends ExtComponent { + + /** + * Getter for property action. + * + * @return Value of property action. + */ + public String getAction(); + + /** + * Setter for property action. + * + * @param action New value of property action. + */ + public void setAction(String action); + + /** + * This class is an implementation of OperationExt interface that provides + * java model for binding operation extensibility element. + */ + public static class OperationExtImpl extends ExtModelImpl implements OperationExt { + + public OperationExtImpl(WSDLModel model, Element e) { + super(model, e); + } + + public OperationExtImpl(WSDLModel model) { + this(model, createPrefixedElement(QN_OPERATION_EXT, model)); + } + + public void accept(ExtVisitor visitor) { + visitor.visit(this); + } + + @Override + public boolean canBeAddedTo(Component target) { + if (target instanceof BindingOperation) { + return true; + } + return false; + } + + public String getAction() { + return getAttribute(ExtAttribute.ACTION); + } + + public void setAction(String action) { + setAttribute(ATTR_ACTION, ExtAttribute.ACTION, action); + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/OutputExt.java b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/OutputExt.java new file mode 100644 index 000000000..70c9ff12b --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/OutputExt.java @@ -0,0 +1,47 @@ +/* + * OutputExt.java + */ +package net.openesb.component.${artifactId}.model; + +import org.netbeans.modules.xml.wsdl.model.BindingOutput; +import org.netbeans.modules.xml.wsdl.model.WSDLModel; +import org.netbeans.modules.xml.xam.Component; +import org.w3c.dom.Element; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * operation output extension element. + * + * @author chikkala + */ +public interface OutputExt extends ExtComponent { + +//TODO: define get/set methods for properties for OutputExt if the extension element has attributes. + /** + * This class is an implementation of OutputExt interface that provides java + * model for binding operation output extension element. + */ + public static class OutputExtImpl extends ExtModelImpl implements OutputExt { + + public OutputExtImpl(WSDLModel model, Element e) { + super(model, e); + } + + public OutputExtImpl(WSDLModel model) { + this(model, createPrefixedElement(QN_OUTPUT_EXT, model)); + } + + public void accept(ExtVisitor visitor) { + visitor.visit(this); + } + + @Override + public boolean canBeAddedTo(Component target) { + if (target instanceof BindingOutput) { + return true; + } + return false; + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/PortExt.java b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/PortExt.java new file mode 100644 index 000000000..b2e817bac --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/model/PortExt.java @@ -0,0 +1,134 @@ +/* + * PortExt.java + */ +package net.openesb.component.${artifactId}.model; + +import org.netbeans.modules.xml.wsdl.model.Port; +import org.netbeans.modules.xml.wsdl.model.WSDLModel; +import org.netbeans.modules.xml.xam.Component; +import org.w3c.dom.Element; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for service + * port extension element. + * + * @author chikkala + */ +public interface PortExt extends ExtComponent { + + /** + * Getter for property serviceURL. + * + * @return Value of property serviceURL. + */ + public String getServiceURL(); + + /** + * Setter for property serviceURL. + * + * @param serviceURL New value of property serviceURL. + */ + public void setServiceURL(String serviceURL); + + /** + * Getter for property username. + * + * @return Value of property username. + */ + public String getUsername(); + + /** + * Setter for property username. + * + * @param username New value of property username. + */ + public void setUsername(String username); + + /** + * Getter for property password. + * + * @return Value of property password. + */ + public String getPassword(); + + /** + * Setter for property password. + * + * @param password New value of property password. + */ + public void setPassword(String password); + + /** + * Getter for property name. + * + * @return Value of property name. + */ + public String getMBean(); + + /** + * Setter for property mbean. + * + * @param name New value of property mbean. + */ + public void setMBean(String mbean); + + /** + * This class is an implementation of PortExt interface that provides java + * model for service port extensibility element. + */ + public static class PortExtImpl extends ExtModelImpl implements PortExt { + + public PortExtImpl(WSDLModel model, Element e) { + super(model, e); + } + + public PortExtImpl(WSDLModel model) { + this(model, createPrefixedElement(QN_PORT_EXT, model)); + } + + public void accept(ExtVisitor visitor) { + visitor.visit(this); + } + + @Override + public boolean canBeAddedTo(Component target) { + if (target instanceof Port) { + return true; + } + return false; + } + + public String getServiceURL() { + return getAttribute(ExtAttribute.SERVICE_URL); + } + + public void setServiceURL(String serviceURL) { + setAttribute(ATTR_SERVICE_URL, ExtAttribute.SERVICE_URL, serviceURL); + } + + public String getUsername() { + return getAttribute(ExtAttribute.USERNAME); + } + + public void setUsername(String username) { + setAttribute(ATTR_USERNAME, ExtAttribute.USERNAME, username); + } + + public String getPassword() { + return getAttribute(ExtAttribute.PASSWORD); + } + + public void setPassword(String password) { + setAttribute(ATTR_PASSWORD, ExtAttribute.PASSWORD, password); + } + + public String getMBean() { + return getAttribute(ExtAttribute.MBEAN); + } + + public void setMBean(String mbean) { + setAttribute(ATTR_MBEAN, ExtAttribute.MBEAN, mbean); + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/binding-ext.png b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/binding-ext.png new file mode 100644 index 000000000..c378d1276 Binary files /dev/null and b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/binding-ext.png differ diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/fault-ext.png b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/fault-ext.png new file mode 100644 index 000000000..493433031 Binary files /dev/null and b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/fault-ext.png differ diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/input-ext.png b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/input-ext.png new file mode 100644 index 000000000..559909e3d Binary files /dev/null and b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/input-ext.png differ diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/operation-ext.png b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/operation-ext.png new file mode 100644 index 000000000..5c63b31f7 Binary files /dev/null and b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/operation-ext.png differ diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/output-ext.png b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/output-ext.png new file mode 100644 index 000000000..559909e3d Binary files /dev/null and b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/output-ext.png differ diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/port-ext.png b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/port-ext.png new file mode 100644 index 000000000..a6b7f8415 Binary files /dev/null and b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/resources/port-ext.png differ diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/template/Bundle.properties b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/template/Bundle.properties new file mode 100644 index 000000000..6e61ecc5a --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/template/Bundle.properties @@ -0,0 +1,12 @@ +# WSDL Wizard template resources for this biding extensions +#template group name. must be jbi component name for which this template is present. +TEMPLATEGROUP_name=BINDINGCOMPONENT +# wsdl extension prefix i18n property. TEMPLATEGROUP_prefix_{wsdlext_prefix} +# wsdlext_prefix is the prefix attribute value of templateGroup element in the template.xml +TEMPLATEGROUP_prefix_bindingcomponent=bindingcomponent +# template name i18n property. An entry per template element in the template.xml +# TEMPLATE_name_{t_name} t_name is the name attribute value of the template element in the template.xml +TEMPLATE_name_mybcTransport=mybc Transport + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/template/WSDLExtTemplateProvider.java b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/template/WSDLExtTemplateProvider.java new file mode 100644 index 000000000..dcd434326 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/template/WSDLExtTemplateProvider.java @@ -0,0 +1,24 @@ +/* + * WSDLExtTemplateProvider.java + */ +package net.openesb.component.${artifactId}.template; + +import java.io.InputStream; +import org.netbeans.modules.xml.wsdl.bindingsupport.spi.ExtensibilityElementTemplateProvider; +import org.openide.util.NbBundle; + +/** + * @author chikkala + */ +public class WSDLExtTemplateProvider extends ExtensibilityElementTemplateProvider { + + private final String templateUrl = "template.xml"; // relative path. + + public InputStream getTemplateInputStream() { + return this.getClass().getResourceAsStream(templateUrl); + } + + public String getLocalizedMessage(String str, Object[] objects) { + return NbBundle.getMessage(this.getClass(), str, objects); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/template/template.xml b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/template/template.xml new file mode 100644 index 000000000..7beeb0eba --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/template/template.xml @@ -0,0 +1,71 @@ + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/validator/WSDLExtValidator.java b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/validator/WSDLExtValidator.java new file mode 100644 index 000000000..3f2119f66 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/validator/WSDLExtValidator.java @@ -0,0 +1,229 @@ +/* + * WSDLExtValidator.java + */ +package net.openesb.component.${artifactId}.validator; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import net.openesb.component.${artifactId}.model.BindingExt; +import net.openesb.component.${artifactId}.model.ExtVisitor; +import net.openesb.component.${artifactId}.model.FaultExt; +import net.openesb.component.${artifactId}.model.InputExt; +import net.openesb.component.${artifactId}.model.OperationExt; +import net.openesb.component.${artifactId}.model.OutputExt; +import net.openesb.component.${artifactId}.model.PortExt; +import org.netbeans.modules.xml.wsdl.model.Binding; +import org.netbeans.modules.xml.wsdl.model.BindingFault; +import org.netbeans.modules.xml.wsdl.model.BindingInput; +import org.netbeans.modules.xml.wsdl.model.BindingOperation; +import org.netbeans.modules.xml.wsdl.model.BindingOutput; +import org.netbeans.modules.xml.wsdl.model.Definitions; +import org.netbeans.modules.xml.wsdl.model.Port; +import org.netbeans.modules.xml.wsdl.model.Service; +import org.netbeans.modules.xml.wsdl.model.WSDLModel; +import org.netbeans.modules.xml.xam.Model; +import org.netbeans.modules.xml.xam.Model.State; +import org.netbeans.modules.xml.xam.spi.Validation; +import org.netbeans.modules.xml.xam.spi.Validation.ValidationType; +import org.netbeans.modules.xml.xam.spi.ValidationResult; +import org.netbeans.modules.xml.xam.spi.Validator; +import org.netbeans.modules.xml.xam.spi.Validator.ResultItem; +import org.openide.util.NbBundle; + +/** + * This class implements the wsdl model validation with respect to the wsdl + * extension elements supported by the specific wsdl extension namespace. + * + * @author ${user} + */ +public class WSDLExtValidator implements Validator, ExtVisitor { + + public static final Set EMPTY_RESULT_ITEM = Collections.emptySet(); + public static final Set EMPTY_MODEL = Collections.emptySet(); + public static final ValidationResult EMPTY_RESULT = new ValidationResult(EMPTY_RESULT_ITEM, EMPTY_MODEL); + private Validation mValidation; + private ValidationType mValidationType; + private ValidationResult mValidationResult; + + public WSDLExtValidator() { + } + + /** + * @return name of the validation service. + */ + public String getName() { + return getClass().getName(); + } + + /** + * Validates given model. + * + * @param model model to validate. + * @param validation reference to the validation context. + * @param validationType the type of validation to perform + * @return ValidationResult. + */ + public ValidationResult validate(Model model, Validation validation, ValidationType validationType) { + + mValidation = validation; + mValidationType = validationType; + + HashSet results = new HashSet(); + HashSet models = new HashSet(); + models.add(model); + + mValidationResult = new ValidationResult(results, models); + + if (model instanceof WSDLModel) { + WSDLModel wsdlModel = (WSDLModel) model; + + if (model.getState() == State.NOT_WELL_FORMED) { + return EMPTY_RESULT; + } + + validateWSDLModel(wsdlModel, results); // validate WSDL Model + } + // Clear out our state + mValidation = null; + mValidationType = null; + + return mValidationResult; + } + + /** + * this method validates the WSDLModel and updates the result set with the + * possible ERRORs, ADVICEs or WARNINGS It calls each wsdl extension element + * models visitor method to validate each extension element. Modify this + * method to add more validations such as scope and limit of the extension + * elements etc. + */ + public void validateWSDLModel(WSDLModel wsdlModel, HashSet results) { + //TODO: add any specific validations such as extension element size etc in addition + // to the element validation itself. + Definitions defs = wsdlModel.getDefinitions(); + // for each binding + for (Binding binding : defs.getBindings()) { + // validate binding extensions + for (BindingExt bindingExt : binding.getExtensibilityElements(BindingExt.class)) { + bindingExt.accept(this); + } + // for each binding operation + for (BindingOperation bindingOp : binding.getBindingOperations()) { + // validate binding operation extensions + for (OperationExt operationExt : bindingOp.getExtensibilityElements(OperationExt.class)) { + operationExt.accept(this); + } + // validate binidng operation input extensions + BindingInput bindingInput = bindingOp.getBindingInput(); + if (bindingInput != null) { + for (InputExt inputExt : bindingInput.getExtensibilityElements(InputExt.class)) { + inputExt.accept(this); + } + } + // validate binding operation output extensions + BindingOutput bindingOutput = bindingOp.getBindingOutput(); + if (bindingOutput != null) { + for (OutputExt outputExt : bindingOutput.getExtensibilityElements(OutputExt.class)) { + outputExt.accept(this); + } + } + // validate binding operation fault extensions + for (BindingFault bindingFault : bindingOp.getBindingFaults()) { + for (FaultExt faultExt : bindingFault.getExtensibilityElements(FaultExt.class)) { + faultExt.accept(this); + } + } + } + } + // for each service + for (Service service : defs.getServices()) { + // for each port + for (Port port : service.getPorts()) { + // validate port extension + for (PortExt portExt : port.getExtensibilityElements(PortExt.class)) { + portExt.accept(this); + } + } + } + } + + public void visit(BindingExt bindingExt) { + Collection results = mValidationResult.getValidationResult(); + //TODO: validate attributes and other required things and add appropriate results. + // + //results.add( + // new Validator.ResultItem(this, // validator + // Validator.ResultType.ERROR, // .ADVICE | .ERROR | .WARNING + // bindingExt, // Validated object + // NbBundle.getMessage(this.getClass(), "I18NKEY") // I18Ned message + // )); + // + } + + public void visit(OperationExt operationExt) { + Collection results = mValidationResult.getValidationResult(); + //TODO: validate attributes and other required things and add appropriate results. + // + //results.add( + // new Validator.ResultItem(this, // validator + // Validator.ResultType.ERROR, // .ADVICE | .ERROR | .WARNING + // operationExt, // Validated object + // NbBundle.getMessage(this.getClass(), "I18NKEY") // I18Ned message + // )); + // + } + + public void visit(InputExt inputExt) { + Collection results = mValidationResult.getValidationResult(); + //TODO: validate attributes and other required things and add appropriate results. + // + //results.add( + // new Validator.ResultItem(this, // validator + // Validator.ResultType.ERROR, // .ADVICE | .ERROR | .WARNING + // inputExt, // Validated object + // NbBundle.getMessage(this.getClass(), "I18NKEY") // I18Ned message + // )); + // + } + + public void visit(OutputExt outputExt) { + Collection results = mValidationResult.getValidationResult(); + //TODO: validate attributes and other required things and add appropriate results. + // + //results.add( + // new Validator.ResultItem(this, // validator + // Validator.ResultType.ERROR, // .ADVICE | .ERROR | .WARNING + // outputExt, // Validated object + // NbBundle.getMessage(this.getClass(), "I18NKEY") // I18Ned message + // )); + // + } + + public void visit(FaultExt faultExt) { + Collection results = mValidationResult.getValidationResult(); + //TODO: validate attributes and other required things and add appropriate results. + // + //results.add( + // new Validator.ResultItem(this, // validator + // Validator.ResultType.ERROR, // .ADVICE | .ERROR | .WARNING + // faultExt, // Validated object + // NbBundle.getMessage(this.getClass(), "I18NKEY") // I18Ned message + // )); + // + } + + public void visit(PortExt portExt) { + Collection results = mValidationResult.getValidationResult(); + //TODO: validate attributes and other required things and add appropriate results. + // + //results.add( + // new Validator.ResultItem(this, // validator + // Validator.ResultType.ERROR, // .ADVICE | .ERROR | .WARNING + // portExt, // Validated object + // NbBundle.getMessage(this.getClass(), "I18NKEY") // I18Ned message + // )); + // + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/validator/WSDLExtValidatorSchemaFactory.java b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/validator/WSDLExtValidatorSchemaFactory.java new file mode 100644 index 000000000..c9fa35498 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/deploy-plugin/src/net/openesb/component/cname/validator/WSDLExtValidatorSchemaFactory.java @@ -0,0 +1,43 @@ +/* + * WSDLExtValidatorSchemaFactory.java + */ +package net.openesb.component.${artifactId}.validator; + +import java.io.InputStream; +import java.io.InputStream; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; +import org.netbeans.modules.xml.wsdl.validator.spi.ValidatorSchemaFactory; + +/** + * This class implements ValidatorSchemaFactory interface. + * + * @author chikkala + */ +public class WSDLExtValidatorSchemaFactory extends ValidatorSchemaFactory { + + private final String NS_URL = + "http://java.sun.com/jbi/wsdl-extensions/sample/jmx-bc/"; + private final String wsdlExtXSDResourcePath = + "/${artifactId}/mybcWsdlExt.xsd"; + + ; + + public String getNamespaceURI() { + return NS_URL; + } + + public InputStream getSchemaInputStream() { + return this.getClass().getResourceAsStream(wsdlExtXSDResourcePath); + } + + /** + * Returns the Inputstream related to this schema + */ + public Source getSchemaSource() { + InputStream in = this.getClass().getResourceAsStream(wsdlExtXSDResourcePath); + Source s = new StreamSource(in); + s.setSystemId(this.getClass().getResource(wsdlExtXSDResourcePath).toString()); + return s; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/install-params.properties b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/install-params.properties new file mode 100644 index 000000000..712a6a3ac --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/install-params.properties @@ -0,0 +1,3 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/m2nbbuild-impl.xml b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/m2nbbuild-impl.xml new file mode 100644 index 000000000..9793203c4 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/m2nbbuild-impl.xml @@ -0,0 +1,130 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + This project compile, package and test the JBI Components when invoked from Maven2. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/m2nbbuild.properties b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/m2nbbuild.properties new file mode 100644 index 000000000..663de1bb9 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/m2nbbuild.properties @@ -0,0 +1,48 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} build properties file to set/override the properties of the netbeans project +${symbol_pound} build properties when the netbeans build is called from the maven build lifecycle. +${symbol_pound} Netbeans project when build from the IDE, uses a build.properties from the user.dir +${symbol_pound} of the Netbeans IDE to resolve some of the properties used in the project such as +${symbol_pound} the libraries classpath. +${symbol_pound} When invoking the Netbeans project build from maven, this build.properties file +${symbol_pound} is not available. So, you can add the properties defined in ide build properties +${symbol_pound} that this project uses here. +${symbol_pound} + +${symbol_pound} default local repository settings. If the repository location is different +${symbol_pound} -D command line option should override this (e.g. mvn -Dmaven.repo.local=/my/m2/repository +maven.repo.local=${symbol_dollar}{user.home}/.m2/repository +${symbol_pound} begin jbi admin settings +${symbol_pound} set the below properties if you want to override the properties from nbproject/project.properties +${symbol_pound} that sets the application server admin settings. +${symbol_pound} +${symbol_pound} jbi.as.home=C:/Sun/glassfish-v2-b58g +${symbol_pound} jbi.host=localhost +${symbol_pound} jbi.port=4848 +${symbol_pound} jbi.username=admin +${symbol_pound} jbi.password=adminadmin +${symbol_pound} end jbi admin settings +${symbol_pound} + +${symbol_pound} classpath settings +junit.ant.task.classpath=${symbol_dollar}{maven.repo.local}/ant/ant-junit/1.6.5/ant-junit-1.6.5.jar +junit.runtime.classpath=${symbol_dollar}{maven.repo.local}/junit/junit/3.8.2/junit-3.8.2.jar +libs.junit.classpath=${symbol_dollar}{junit.runtime.classpath}:${symbol_dollar}{junit.ant.task.classpath} +libs.jbi-cdk-ant-tasks.classpath=${symbol_dollar}{maven.repo.local}/open-esb/jbi-cdk/jbi-cdk-ant-tasks/${version}/jbi-cdk-ant-tasks-${version}.jar + +libs.jbi.classpath=${symbol_dollar}{maven.repo.local}/open-esb/jbi/1.0/jbi-1.0.jar +libs.wsdl4j.162.classpath=${symbol_dollar}{maven.repo.local}/wsdl4j/wsdl4j/1.6.2/wsdl4j-1.6.2.jar +${symbol_pound} libs.jaxws21.classpath=${symbol_dollar}{jbi.as.home}/lib/javaee.jar:${symbol_dollar}{jbi.as.home}/lib/webservices-rt.jar +libs.jaxws21.classpath=${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/activation/activation/1.1/activation-1.1.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/xml/soap/saaj-api/1.3/saaj-api-1.3.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/xml/ws/jaxws-api/2.1/jaxws-api-2.1.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/com/sun/xml/messaging/saaj/saaj-impl/1.3/saaj-impl-1.3.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/com/sun/xml/ws/jaxws-rt/2.1.2/jaxws-rt-2.1.2.jar + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/m2nbbuild.xml b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/m2nbbuild.xml new file mode 100644 index 000000000..31217d15d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/m2nbbuild.xml @@ -0,0 +1,37 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + This project compile, package and test the JBI Components when invoked from Maven2. + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/build-impl.xml b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/build-impl.xml new file mode 100644 index 000000000..e71fb3578 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/build-impl.xml @@ -0,0 +1,558 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + Inside: postArchTypeGen - Post task is getting executed! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Inside: postArchTypeGen - Post task executed successfully! + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/genfiles.properties b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/genfiles.properties new file mode 100644 index 000000000..6d932c0a5 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/genfiles.properties @@ -0,0 +1,11 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +build.xml.data.CRC32=818aaa7f +build.xml.script.CRC32=d992673d +build.xml.stylesheet.CRC32=8add101f@1.0 +${symbol_pound} This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +${symbol_pound} Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=818aaa7f +nbproject/build-impl.xml.script.CRC32=52f42474 +nbproject/build-impl.xml.stylesheet.CRC32=4ed53ee0@1.0 diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/jbi_admin.xml b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/jbi_admin.xml new file mode 100644 index 000000000..7c2588b9e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/jbi_admin.xml @@ -0,0 +1,504 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + +This ant script contains the jbi ant tasks and the targets and properties using +which the jbi admin commands can be performed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Usage : ant -f <fullpath>/jbi_admin.xml [options] [target] + options: -D<property>=<value> + Specify a property/value pairs as options that are valid for the target. + target : ant target name in jbi_admin.xml + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/jbiadmin-impl.xml b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/jbiadmin-impl.xml new file mode 100644 index 000000000..7e7dca2ae --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/jbiadmin-impl.xml @@ -0,0 +1,339 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + Install, uninstall, reinstall, start, stop, shutdown jbi components. + + + + + + + + + + + + + + Must set jbi.host + Must set jbi.port + Must set jbi.username + Must set jbi.password + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/private/private.properties b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/private/private.properties new file mode 100644 index 000000000..e540325d5 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/private/private.properties @@ -0,0 +1,6 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +javac.debug=true +javadoc.preview=true +user.properties.file=D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working57${symbol_escape}${symbol_escape}.netbeans${symbol_escape}${symbol_escape}openesb${symbol_escape}${symbol_escape}build.properties diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/private/retriever/catalog.xml b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/private/retriever/catalog.xml new file mode 100644 index 000000000..712a6a3ac --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/private/retriever/catalog.xml @@ -0,0 +1,3 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/project.properties b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/project.properties new file mode 100644 index 000000000..d9b87e775 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/project.properties @@ -0,0 +1,91 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +build.classes.dir=${symbol_dollar}{build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +${symbol_pound} This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${symbol_dollar}{build.dir}/generated +build.predist.dir=${symbol_dollar}{build.dir}/predist +build.predist.jar=${symbol_dollar}{build.predist.dir}/component.jar +build.predist.lib.dir=${symbol_dollar}{build.predist.dir}/lib +${symbol_pound} Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${symbol_dollar}{build.dir}/test/classes +build.test.dir=${symbol_dollar}{build.dir}/test +build.test.results.dir=${symbol_dollar}{build.dir}/test/results +conf.dir=src/conf +debug.classpath=${symbol_escape} + ${symbol_dollar}{run.classpath} +debug.test.classpath=${symbol_escape} + ${symbol_dollar}{run.test.classpath} +${symbol_pound} This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${symbol_dollar}{dist.dir}/${artifactId}.zip +dist.javadoc.dir=${symbol_dollar}{dist.dir}/javadoc +jar.compress=false +javac.classpath=${symbol_escape} + ${symbol_dollar}{libs.jbi.classpath}:${symbol_escape} + ${symbol_dollar}{jbi.component.sharedlibs.classpath}:${symbol_escape} + ${symbol_dollar}{jbi.component.lib.classpath} +${symbol_pound} Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.6 +javac.target=1.6 +javac.test.classpath=${symbol_escape} + ${symbol_dollar}{javac.classpath}:${symbol_escape} + ${symbol_dollar}{build.classes.dir}:${symbol_escape} + ${symbol_dollar}{libs.junit.classpath}:${symbol_escape} + ${symbol_dollar}{libs.jaxws21.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +jbi.ant.tasks.classpath=${symbol_escape} + ${symbol_dollar}{jbi.as.home}/lib/sun-appserv-ant.jar:${symbol_escape} + ${symbol_dollar}{jbi.as.home}/jbi/lib/jbi-ant-tasks.jar +jbi.as.home=D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working53${symbol_escape}${symbol_escape}glassfish +jbi.as.instance.id=[D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working53${symbol_escape}${symbol_escape}glassfish]deployer:Sun:AppServer::localhost:4848 +jbi.component.bootstrap.class=cname.JMXBindingInstaller +jbi.component.class=cname.JMXBindingRuntime +jbi.component.description=Description of binding component : ${artifactId} +jbi.component.lib.classpath=${symbol_escape} + ${symbol_dollar}{libs.wsdl4j.162.classpath} +jbi.component.name=${artifactId} +jbi.component.sharedlibs.classpath= +jbi.component.type=binding-component +jbi.host=localhost +jbi.install.params.file=install-params.properties +jbi.install.with.params=false +jbi.password=this really long string is used to identify a password that has been stored in the Keyring +jbi.port=4848 +jbi.soap.binding.name=sun-http-binding +jbi.username=admin +meta.inf.dir=${symbol_dollar}{conf.dir}/META-INF +platform.active=default_platform +project.jbi.deploy.plugin=./deploy-plugin +project.testSA=test/testSA +run.classpath=${symbol_escape} + ${symbol_dollar}{javac.classpath}:${symbol_escape} + ${symbol_dollar}{build.classes.dir} +${symbol_pound} Space-separated list of JVM arguments used when running the project +${symbol_pound} (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +${symbol_pound} or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=${symbol_escape} + ${symbol_dollar}{javac.test.classpath}:${symbol_escape} + ${symbol_dollar}{build.test.classes.dir} +src.dir=src/java +test-sys-prop.test.results.dir=${symbol_dollar}{build.test.results.dir} +test-sys-prop.test.src.dir=test-sys-prop.test.src.dir +test.src.dir=test/java +testSA.enabled=true +testSA.name=${artifactId}_TestSA diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/project.xml b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/project.xml new file mode 100644 index 000000000..12b71aa1c --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/nbproject/project.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + org.netbeans.modules.jbi.apisupport.project.jbicomponent + + + ${artifactId} + binding-component + 1.6.5 + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/pom.xml b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 000000000..04d8bb61d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,171 @@ + + + + 4.0.0 + ${groupId} + ${artifactId} + jar + ${version} + JBI Component[BindingComponent] + Maven project for JBI Component that contains the + maven and netbeans build setup and component code to build and test the JBI Component. + http://open-esb.org + + build + src/java + test/java + build/classes + build/test/classes + package + + + + maven-antrun-plugin + 1.2 + + + default-cli + + run + + + + !!!!!!!!!!!!!!!!!!!!!! Moving Files and organizing package !!!!!!!!!!!!!!!!!!!!!!!! + + + + + + + + + ant + ant-nodeps + 1.6.5 + + + ant + ant-junit + 1.6.5 + test + + + junit + junit + 3.8.2 + test + + + + + + + + + maven2-repo1 + Maven2 Central Repository + http://repo1.maven.org/maven2 + + + download-java-net-maven2-repository + download.java.net Maven 2.x repository + http://download.java.net/maven/2/ + + + maven-repository.dev.java.net-repository + https://maven-repository.dev.java.net/nonav/repository/ + legacy + + + ws-zones + ws.zones maven repository + http://ws.zones.apache.org/repository2/ + + + apache.org + Maven Snapshots + http://people.apache.org/repo/m2-snapshot-repository + + false + + + + + + + + + apache.org + Maven Plugin Snapshots + http://people.apache.org/repo/m2-snapshot-repository + + false + + + + + + + + ant + ant-nodeps + 1.6.5 + + + ant + ant-junit + 1.6.5 + test + + + junit + junit + 3.8.2 + test + + + org.apache.maven + maven-ant-tasks + 2.0.7 + + + open-esb.jbi-cdk + jbi-cdk-ant-tasks + 1.0-SNAPSHOT + + + open-esb + jbi + 1.0 + + + wsdl4j + wsdl4j + 1.6.2 + + + com.sun.xml.ws + jaxws-rt + 2.1.2 + test + + + + + ${maven.repo.local} + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/test/resources/projects/basic/archetype.properties b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/test/resources/projects/basic/archetype.properties new file mode 100644 index 000000000..112db0dc2 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/test/resources/projects/basic/archetype.properties @@ -0,0 +1,5 @@ +#Wed Jul 24 14:12:01 IST 2013 +package=it.pkg +version=0.1-SNAPSHOT +groupId=archetype.it +artifactId=basic diff --git a/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/test/resources/projects/basic/goal.txt b/maven-archtype-v2/maven-archtype-binding-component-plugin-v2/src/test/resources/projects/basic/goal.txt new file mode 100644 index 000000000..e69de29bb diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/pom.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/pom.xml new file mode 100644 index 000000000..11eb1f5e9 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + open-jbi-components + BindingComponent-archetype + 1.0-SNAPSHOT + maven-archetype + + BindingComponent-archetype + + + + + org.apache.maven.archetype + archetype-packaging + 2.2 + + + + + + + maven-archetype-plugin + 2.2 + + + + + + Maven project for JBI Component that contains the + maven and netbeans build setup and component code to build and test the JBI Component. + + http://open-esb.org + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/META-INF/maven/archetype-metadata.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 000000000..e3cafbf91 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,76 @@ + + + + + C:\\GlassFishESBv22\\glassfish + + + + + test/java + + **/*.xml + **/*.java + **/*.properties + + + + src/java + + **/*.java + + + + src/java + + **/*.xsd + + + + test/testSA + + **/*.xml + **/*.properties + + + + nbproject + + **/*.xml + **/*.properties + + + + src/conf + + **/*.xml + + + + nbproject/private + + **/*.xml + **/*.properties + + + + test/testSA + + **/*.xsl + **/*.wsdl + + + + + + build.xml + install-params.properties + m2nbbuild-impl.xml + m2nbbuild.properties + m2nbbuild.xml + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build.xml new file mode 100644 index 000000000..14afd1d29 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build.xml @@ -0,0 +1,72 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + Builds, tests, and runs the project ${artifactId}. + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/pom.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/pom.xml new file mode 100644 index 000000000..1e58b6067 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/pom.xml @@ -0,0 +1,38 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + 4.0.0 + + ${package} + ${artifactId}-archetype + ${version} + maven-archetype + + ${artifactId}-archetype + + + + + org.apache.maven.archetype + archetype-packaging + 2.2 + + + + + + + maven-archetype-plugin + 2.2 + + + + + + Maven project for JBI Component that contains the + maven and netbeans build setup and component code to build and test the JBI Component. + + http://open-esb.org + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml new file mode 100644 index 000000000..c493031be --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml @@ -0,0 +1,33 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml new file mode 100644 index 000000000..99e45731e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml @@ -0,0 +1,62 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + org.netbeans.modules.apisupport.project + + + ${symbol_dollar}{artifactId} + + + + org.netbeans.modules.xml.schema.model + + + + 1 + 1.2 + + + + org.netbeans.modules.xml.wsdl.bindingsupport.api + + + + 1.0 + + + + org.netbeans.modules.xml.wsdl.model + + + + 1 + 1.2 + + + + org.netbeans.modules.xml.xam + + + + 1 + 1.2 + + + + org.openide.util + + + + 7.9.0.1 + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/bindingtest/test1Input.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/bindingtest/test1Input.xml new file mode 100644 index 000000000..a54d4d390 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/bindingtest/test1Input.xml @@ -0,0 +1,15 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + Srinivasan + Chikkala + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/bindingtest/test2Input.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/bindingtest/test2Input.xml new file mode 100644 index 000000000..6233ab78e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/bindingtest/test2Input.xml @@ -0,0 +1,15 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + Srinivasan + Chikkala + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/build.xml new file mode 100644 index 000000000..5456aa8f2 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/build.xml @@ -0,0 +1,143 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.assembly.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml new file mode 100644 index 000000000..63b89125f --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml @@ -0,0 +1,47 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + ${symbol_dollar}{artifactId}_TestSA + This is a test Service Assembly to test Binding + + + + + ${symbol_dollar}{artifactId}_TestSUBC + This service unit enables inbound endpoint in the JMXBinding for a service in service engine + + + testSUBC.zip + ${symbol_dollar}{artifactId} + + + + + ${symbol_dollar}{artifactId}_TestSUSE + This service unit enables greetings service provider in the service engine + + + testSUSE.zip + ServiceEngine + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml new file mode 100644 index 000000000..96e95745f --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml @@ -0,0 +1,77 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml new file mode 100644 index 000000000..539a5efbf --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml new file mode 100644 index 000000000..75340ea7d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml @@ -0,0 +1,77 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml new file mode 100644 index 000000000..324002052 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/m2nbbuild-impl.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/m2nbbuild-impl.xml new file mode 100644 index 000000000..d7dabc84f --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/m2nbbuild-impl.xml @@ -0,0 +1,130 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + This project compile, package and test the JBI Components when invoked from Maven2. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/m2nbbuild.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/m2nbbuild.properties new file mode 100644 index 000000000..663de1bb9 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/m2nbbuild.properties @@ -0,0 +1,48 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} build properties file to set/override the properties of the netbeans project +${symbol_pound} build properties when the netbeans build is called from the maven build lifecycle. +${symbol_pound} Netbeans project when build from the IDE, uses a build.properties from the user.dir +${symbol_pound} of the Netbeans IDE to resolve some of the properties used in the project such as +${symbol_pound} the libraries classpath. +${symbol_pound} When invoking the Netbeans project build from maven, this build.properties file +${symbol_pound} is not available. So, you can add the properties defined in ide build properties +${symbol_pound} that this project uses here. +${symbol_pound} + +${symbol_pound} default local repository settings. If the repository location is different +${symbol_pound} -D command line option should override this (e.g. mvn -Dmaven.repo.local=/my/m2/repository +maven.repo.local=${symbol_dollar}{user.home}/.m2/repository +${symbol_pound} begin jbi admin settings +${symbol_pound} set the below properties if you want to override the properties from nbproject/project.properties +${symbol_pound} that sets the application server admin settings. +${symbol_pound} +${symbol_pound} jbi.as.home=C:/Sun/glassfish-v2-b58g +${symbol_pound} jbi.host=localhost +${symbol_pound} jbi.port=4848 +${symbol_pound} jbi.username=admin +${symbol_pound} jbi.password=adminadmin +${symbol_pound} end jbi admin settings +${symbol_pound} + +${symbol_pound} classpath settings +junit.ant.task.classpath=${symbol_dollar}{maven.repo.local}/ant/ant-junit/1.6.5/ant-junit-1.6.5.jar +junit.runtime.classpath=${symbol_dollar}{maven.repo.local}/junit/junit/3.8.2/junit-3.8.2.jar +libs.junit.classpath=${symbol_dollar}{junit.runtime.classpath}:${symbol_dollar}{junit.ant.task.classpath} +libs.jbi-cdk-ant-tasks.classpath=${symbol_dollar}{maven.repo.local}/open-esb/jbi-cdk/jbi-cdk-ant-tasks/${version}/jbi-cdk-ant-tasks-${version}.jar + +libs.jbi.classpath=${symbol_dollar}{maven.repo.local}/open-esb/jbi/1.0/jbi-1.0.jar +libs.wsdl4j.162.classpath=${symbol_dollar}{maven.repo.local}/wsdl4j/wsdl4j/1.6.2/wsdl4j-1.6.2.jar +${symbol_pound} libs.jaxws21.classpath=${symbol_dollar}{jbi.as.home}/lib/javaee.jar:${symbol_dollar}{jbi.as.home}/lib/webservices-rt.jar +libs.jaxws21.classpath=${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/activation/activation/1.1/activation-1.1.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/xml/soap/saaj-api/1.3/saaj-api-1.3.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/xml/ws/jaxws-api/2.1/jaxws-api-2.1.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/com/sun/xml/messaging/saaj/saaj-impl/1.3/saaj-impl-1.3.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/com/sun/xml/ws/jaxws-rt/2.1.2/jaxws-rt-2.1.2.jar + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/m2nbbuild.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/m2nbbuild.xml new file mode 100644 index 000000000..31217d15d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/m2nbbuild.xml @@ -0,0 +1,37 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + This project compile, package and test the JBI Components when invoked from Maven2. + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/build-impl.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/build-impl.xml new file mode 100644 index 000000000..096c6dd04 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/build-impl.xml @@ -0,0 +1,557 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Inside: postArchTypeGen - Post task is getting executed! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Inside: postArchTypeGen - Post task executed successfully! + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/genfiles.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/genfiles.properties new file mode 100644 index 000000000..ac5cc7404 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/genfiles.properties @@ -0,0 +1,11 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +build.xml.data.CRC32=f37ab647 +build.xml.script.CRC32=9068f2c7 +build.xml.stylesheet.CRC32=8add101f@1.0 +${symbol_pound} This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +${symbol_pound} Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=f37ab647 +nbproject/build-impl.xml.script.CRC32=d15987fd +nbproject/build-impl.xml.stylesheet.CRC32=4ed53ee0@1.0 diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/jbi_admin.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/jbi_admin.xml new file mode 100644 index 000000000..8a7d2a523 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/jbi_admin.xml @@ -0,0 +1,504 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + +This ant script contains the jbi ant tasks and the targets and properties using +which the jbi admin commands can be performed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Usage : ant -f <fullpath>/jbi_admin.xml [options] [target] + options: -D<property>=<value> + Specify a property/value pairs as options that are valid for the target. + target : ant target name in jbi_admin.xml + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/jbiadmin-impl.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/jbiadmin-impl.xml new file mode 100644 index 000000000..7e7dca2ae --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/jbiadmin-impl.xml @@ -0,0 +1,339 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + Install, uninstall, reinstall, start, stop, shutdown jbi components. + + + + + + + + + + + + + + Must set jbi.host + Must set jbi.port + Must set jbi.username + Must set jbi.password + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/private/private.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/private/private.properties new file mode 100644 index 000000000..e540325d5 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/private/private.properties @@ -0,0 +1,6 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +javac.debug=true +javadoc.preview=true +user.properties.file=D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working57${symbol_escape}${symbol_escape}.netbeans${symbol_escape}${symbol_escape}openesb${symbol_escape}${symbol_escape}build.properties diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/project.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/project.properties new file mode 100644 index 000000000..7237a56d7 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/project.properties @@ -0,0 +1,93 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +build.classes.dir=${symbol_dollar}{build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +${symbol_pound} This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${symbol_dollar}{build.dir}/generated +build.predist.dir=${symbol_dollar}{build.dir}/predist +build.predist.jar=${symbol_dollar}{build.predist.dir}/component.jar +build.predist.lib.dir=${symbol_dollar}{build.predist.dir}/lib +${symbol_pound} Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${symbol_dollar}{build.dir}/test/classes +build.test.dir=${symbol_dollar}{build.dir}/test +build.test.results.dir=${symbol_dollar}{build.dir}/test/results +conf.dir=src/conf +debug.classpath=${symbol_escape} + ${symbol_dollar}{run.classpath} +debug.test.classpath=${symbol_escape} + ${symbol_dollar}{run.test.classpath} +${symbol_pound} This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${symbol_dollar}{dist.dir}/${artifactId}.zip +dist.javadoc.dir=${symbol_dollar}{dist.dir}/javadoc +jar.compress=false +javac.classpath=${symbol_escape} + ${symbol_dollar}{libs.jbi.classpath}:${symbol_escape} + ${symbol_dollar}{jbi.component.sharedlibs.classpath}:${symbol_escape} + ${symbol_dollar}{jbi.component.lib.classpath} +${symbol_pound} Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.6 +javac.target=1.6 +javac.test.classpath=${symbol_escape} + ${symbol_dollar}{javac.classpath}:${symbol_escape} + ${symbol_dollar}{build.classes.dir}:${symbol_escape} + ${symbol_dollar}{libs.junit.classpath}:${symbol_escape} + ${symbol_dollar}{libs.jaxws21.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +jbi.ant.tasks.classpath=${symbol_escape} + ${symbol_dollar}{jbi.as.home}/lib/sun-appserv-ant.jar:${symbol_escape} + ${symbol_dollar}{jbi.as.home}/jbi/lib/jbi-ant-tasks.jar +#jbi.as.home=D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working53${symbol_escape}${symbol_escape}glassfish +jbi.as.home=${glassfishLocation} +#jbi.as.instance.id=[D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working53${symbol_escape}${symbol_escape}glassfish]deployer:Sun:AppServer::localhost:4848 +jbi.as.instance.id=[${glassfishLocation}]deployer:Sun:AppServer::localhost:4848 +jbi.component.bootstrap.class=${artifactId}.JMXBindingInstaller +jbi.component.class=${artifactId}.JMXBindingRuntime +jbi.component.description=Description of binding component : ${artifactId} +jbi.component.lib.classpath=${symbol_escape} + ${symbol_dollar}{libs.wsdl4j.162.classpath} +jbi.component.name=${artifactId} +jbi.component.sharedlibs.classpath= +jbi.component.type=binding-component +jbi.host=localhost +jbi.install.params.file=install-params.properties +jbi.install.with.params=false +jbi.password=this really long string is used to identify a password that has been stored in the Keyring +jbi.port=4848 +jbi.soap.binding.name=sun-http-binding +jbi.username=admin +meta.inf.dir=${symbol_dollar}{conf.dir}/META-INF +platform.active=default_platform +project.jbi.deploy.plugin=./deploy-plugin +project.testSA=test/testSA +run.classpath=${symbol_escape} + ${symbol_dollar}{javac.classpath}:${symbol_escape} + ${symbol_dollar}{build.classes.dir} +${symbol_pound} Space-separated list of JVM arguments used when running the project +${symbol_pound} (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +${symbol_pound} or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=${symbol_escape} + ${symbol_dollar}{javac.test.classpath}:${symbol_escape} + ${symbol_dollar}{build.test.classes.dir} +src.dir=src/java +test-sys-prop.test.results.dir=${symbol_dollar}{build.test.results.dir} +test-sys-prop.test.src.dir=test-sys-prop.test.src.dir +test.src.dir=test/java +testSA.enabled=true +testSA.name=${artifactId}_TestSA diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/project.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/project.xml new file mode 100644 index 000000000..12b71aa1c --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/nbproject/project.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + org.netbeans.modules.jbi.apisupport.project.jbicomponent + + + ${artifactId} + binding-component + 1.6.5 + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/pom.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 000000000..7ae109163 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,268 @@ + + + + 4.0.0 + ${groupId} + ${artifactId} + jar + ${version} + JBI Component[${artifactId}] + Maven project for JBI Component that contains the + maven and netbeans build setup and component code to build and test the JBI Component. + http://open-esb.org + + build + src/java + test/java + build/classes + build/test/classes + package + + + org.apache.maven.plugins + maven-compiler-plugin + + true + 1.5 + 1.5 + + + **/*.java + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + + **/*.* + + + + + maven-surefire-plugin + 2.1.3 + true + + + true + + **/bindingtest/*.java + **/enginetest/*.java + + + + + + maven-antrun-plugin + 1.2 + + + m2nbbuild-compile + compile + run + + + + + + + + m2nbbuild-compile-test + test-compile + run + + + + + + + + m2nbbuild-package + package + run + + + + + + + + m2nbbuild-utest + test + run + + + + + + + + m2nbbuild-itest + integration-test + run + + + + + + + + m2nbbuild-clean + clean + run + + + + + + + default-cli + + run + + + + !!!!!!!!!!!!!!!!!!!!!! Moving Files and organizing package !!!!!!!!!!!!!!!!!!!!!!!! + + + + + + + + + + ant + ant-nodeps + 1.6.5 + + + ant + ant-junit + 1.6.5 + test + + + junit + junit + 3.8.2 + test + + + + + + + + + maven2-repo1 + Maven2 Central Repository + http://repo1.maven.org/maven2 + + + download-java-net-maven2-repository + download.java.net Maven 2.x repository + http://download.java.net/maven/2/ + + + maven-repository.dev.java.net-repository + https://maven-repository.dev.java.net/nonav/repository/ + legacy + + + ws-zones + ws.zones maven repository + http://ws.zones.apache.org/repository2/ + + + apache.org + Maven Snapshots + http://people.apache.org/repo/m2-snapshot-repository + + false + + + + + + + + + apache.org + Maven Plugin Snapshots + http://people.apache.org/repo/m2-snapshot-repository + + false + + + + + + + + ant + ant-nodeps + 1.6.5 + + + ant + ant-junit + 1.6.5 + test + + + junit + junit + 3.8.2 + test + + + org.apache.maven + maven-ant-tasks + 2.0.7 + + + open-esb.jbi-cdk + jbi-cdk-ant-tasks + 1.0-SNAPSHOT + + + open-esb + jbi + 1.0 + + + wsdl4j + wsdl4j + 1.6.2 + + + com.sun.xml.ws + jaxws-rt + 2.1.2 + test + + + + + ${maven.repo.local} + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/conf/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/conf/META-INF/jbi.xml new file mode 100644 index 000000000..6c38687ee --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/conf/META-INF/jbi.xml @@ -0,0 +1,45 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + ${artifactId} + Description of binding component : ${artifactId} + + + net.openesb.component.${artifactId}.JMXBindingRuntime + + + component.jar + + lib/wsdl4j-1.6.2.jar + + + net.openesb.component.${artifactId}.JMXBindingInstaller + + + component.jar + + lib/wsdl4j-1.6.2.jar + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingComponentLifeCycle.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingComponentLifeCycle.java new file mode 100644 index 000000000..d4e017183 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingComponentLifeCycle.java @@ -0,0 +1,52 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMX${artifactId}LifeCycle.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.BasicComponentLifeCycle; +import net.openesb.component.${artifactId}.common.DefaultMessageExchangeReceiver; +import net.openesb.component.${artifactId}.common.MessageExchangeReceiver; +import net.openesb.component.${artifactId}.common.RuntimeContext; +import javax.jbi.JBIException; +import javax.jbi.component.Component; + +/** + * This class extends the basic ComponentLifeCycle implementation to provide + * component specific implementation of the ComponentLifeCycle. + * + * @see javax.jbi.ComponentLifeCycle + * @see com.sun.jbi.sample.component.common.BasicComponentLifeCycle + * @author chikkala + */ +public class JMXBindingComponentLifeCycle extends BasicComponentLifeCycle { + + /** + * constructor for the ComponentLifecycle implementation. + */ + public JMXBindingComponentLifeCycle(Component compRuntime) { + super(compRuntime); + } + + /** + * creates DefaultMessageExchangeReceiver to handles receiving and + * processing the message exchanges from the delivery channel. + */ + @Override + protected MessageExchangeReceiver createMessageExchangeReceiver() { + return new DefaultMessageExchangeReceiver(); + } + + /** + * chance to extended classes to do the component specific init + * + * @throws javax.jbi.JBIException + */ + @Override + protected void doInit() throws JBIException { + // NOOP + RuntimeContext.getInstance().setLogger(this.getClass().getName(), null); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingConsumerEndpoint.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingConsumerEndpoint.java new file mode 100644 index 000000000..3a0711150 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingConsumerEndpoint.java @@ -0,0 +1,153 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingConsumerEndpoint.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.wsdlext.PortExt; +import net.openesb.component.${artifactId}.wsdlext.WSDLExtHelper; +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.deployment.ConsumerEndpoint; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor; +import net.openesb.component.${artifactId}.common.deployment.ServiceUnit; +import javax.jbi.JBIException; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanRegistrationException; +import javax.management.ObjectName; +import javax.management.StandardMBean; +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +/** + * This class extends ConsumerEndpoint to implement the component specific + * consumer endpoint configuration. It uses JMXBindingConsumerProxy to receive + * messages from external service consumers and initiate the InOut message + * exchange. This implementation shows how a synchronous send/receive from the + * delivery channel will be used in InOut message exchange in a service + * invocation by the external consumers. + * + * @author chikkala + */ +public class JMXBindingConsumerEndpoint extends ConsumerEndpoint { + + private ObjectName mJMXEndpointMBeanName; + private JMXEndpointMBean mJMXEndpointMBean; + + /** + * Creates a new instance of XSLTProviderEndpoint + */ + public JMXBindingConsumerEndpoint(SUDescriptor.Consumes consumes, Definition wsdlDef, ServiceUnit su) { + super(consumes, wsdlDef, su); + } + + @Override + protected void doInit() throws JBIException { + RuntimeHelper.getLogger().fine("JMXBindingEndpoint(Consumer): init called"); + this.initJMXEndpoint(); + } + + @Override + protected void doActivate() throws JBIException { + RuntimeHelper.getLogger().fine("JMXBindingEndpoint(Consumer): activate called"); + this.activateJMXEndpoint(); + } + + @Override + protected void doDeactivate() throws JBIException { + RuntimeHelper.getLogger().fine("JMXBindingEndpoint(Consumer): deactivate called"); + this.deactivateJMXEndpoint(); + } + + @Override + protected void doClean() throws JBIException { + RuntimeHelper.getLogger().fine("JMXBindingEndpoint(Consumer): clean called"); + this.cleanJMXEndpoint(); + } + + /** + * creates the JMXEndpointMBean implementation. + */ + protected JMXEndpointMBean createJMXEndpointMBean() { + // JMX EndpointMBean implementation that initiates in-out message exchange. + return new JMXBindingConsumerProxy(this); + } + + /** + * get the mbean object name from the endpoint address of the jmx wsdl + * extension element + */ + protected ObjectName createJMXEndpointMBeanName() throws JBIException { + ObjectName mbeanObjectName = null; + try { + mbeanObjectName = new ObjectName(findMBeanNameFromWSDL()); + } catch (Exception ex) { + throw new JBIException(ex); + } + return mbeanObjectName; + } + + public final ObjectName getJMXEndpointMBeanName() { + return this.mJMXEndpointMBeanName; + } + + public final JMXEndpointMBean getJMXEndpointMBean() { + return this.mJMXEndpointMBean; + } + + protected final void initJMXEndpoint() throws JBIException { + // create jmx mbean resources + this.mJMXEndpointMBeanName = createJMXEndpointMBeanName(); + this.mJMXEndpointMBean = createJMXEndpointMBean(); + } + + protected final void activateJMXEndpoint() throws JBIException { + // open jmx connectivity to external consumers by registering the + // external endpoint mbean implementation. + try { + StandardMBean mbean = new StandardMBean(this.mJMXEndpointMBean, JMXEndpointMBean.class); + this.getComponentContext().getMBeanServer().registerMBean(mbean, this.mJMXEndpointMBeanName); + } catch (Exception ex) { + throw new JBIException(ex); + } + } + + protected final void deactivateJMXEndpoint() throws JBIException { + // close the jmx connectivity to external consumers by unregistering + // the external endpoint mbean. + try { + this.getComponentContext().getMBeanServer().unregisterMBean(this.mJMXEndpointMBeanName); + } catch (InstanceNotFoundException ex) { + ex.printStackTrace(); + } catch (MBeanRegistrationException ex) { + ex.printStackTrace(); + } + } + + protected final void cleanJMXEndpoint() throws JBIException { + // release jmx mbean resources + this.mJMXEndpointMBean = null; + this.mJMXEndpointMBeanName = null; + } + + /** + * get the mbean object name from the endpoint address of the jmx wsdl + * extension element + */ + protected String findMBeanNameFromWSDL() { + String mbeanName = null; + try { + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + Definition def = this.getWSDL(); + PortExt address = WSDLExtHelper.getPortExt(def, serviceName, endpointName); + if (address != null) { + mbeanName = address.getMBean(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + return mbeanName; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingConsumerProxy.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingConsumerProxy.java new file mode 100644 index 000000000..180f4d45d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingConsumerProxy.java @@ -0,0 +1,237 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingConsumerProxy.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.deployment.ConsumerEndpoint; +import java.io.StringReader; +import javax.jbi.JBIException; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.Fault; +import javax.jbi.messaging.InOnly; +import javax.jbi.messaging.InOut; +import javax.jbi.messaging.NormalizedMessage; +import javax.wsdl.Operation; +import javax.wsdl.OperationType; +import javax.xml.namespace.QName; +import javax.xml.transform.Source; + +/** + * This class acts as a proxy to the external service consumer that can receive + * messages from the external consumer using JMX interface and then initiate the + * InOut message exchange to invoke a service provided by the component in the + * jbi environment. + * + * this code shows how a synchronous send/receive messages from the delivery + * channel can be used in InOut message exchange to complete a service + * invocation. + * + * @author chikkala + */ +public class JMXBindingConsumerProxy implements JMXEndpointMBean { + + /** + * Synchronous send timeout + */ + private static final long SEND_SYNC_TIMEOUT = 60000; + private ConsumerEndpoint mEndpoint; + private JMXBindingNormalizer mNormalizer; + + /** + * Creates a new instance of JMXEndpointMBeanImpl + */ + public JMXBindingConsumerProxy(ConsumerEndpoint endpoint) { + this.mEndpoint = endpoint; + this.mNormalizer = new JMXBindingNormalizer(endpoint.getWSDL(), endpoint.getWSDLBinding()); + } + + public StringBuffer sendMessage(String operation, StringBuffer inputDoc) throws Exception { + // when receive input from external service consumer, + // 1. normalized the message, 2. send in-out message exchange. 3. denormalize out message. + Source inMsgSource = RuntimeHelper.createDOMSource(new StringReader(inputDoc.toString())); + QName operationQName = this.mEndpoint.getOperationQName(operation); + Source out = initiateMessageExchange(operationQName, inMsgSource); + StringBuffer outBuff = null; + if (out != null) { + // read the denormalized out message to string buffer. + outBuff = RuntimeHelper.readFromSource(out); + } + // return the out message content to the external service consumer. + return outBuff; + } + + public Source initiateMessageExchange(QName operation, Source inSource) throws JBIException { + // 1. Decide what type of message exchange needed for this operation. + Source outSource = null; + try { + Operation wsdlOp = this.mEndpoint.getWSDLOperation(operation); + if (OperationType.REQUEST_RESPONSE.equals(wsdlOp.getStyle())) { + outSource = doInOutMessageExchange(operation, inSource); + } else if (OperationType.ONE_WAY.equals(wsdlOp.getStyle())) { + doInOnlyMessageExchange(operation, inSource); + } else { + throw new JBIException("Unsupported MEP " + wsdlOp.getStyle() + + "for operation " + operation); + } + return outSource; + } catch (Exception ex) { + throw new JBIException(ex); + } + } + + /** + * invokes the service provider with in-only message exchange sent to + * delivery channel by the consumer + * + * @param operation operation name on a service + * @param inSource input xml document for the InOut operation + * @throws java.lang.Exception if any error occurs in invoking the operation + * on the service. + * @return output xml document as a Source object received from InOut + * operation of the service invoked. + */ + private void doInOnlyMessageExchange(QName operation, Source inSource) + throws Exception { + // 2. normalized the message. + // 3. locate service endpoint + // 4. create message exchange according to the Opeations MEP + + // get the component context and the delivery channel for preparing to send message + ComponentContext compContext = this.mEndpoint.getComponentContext(); + DeliveryChannel channel = this.mEndpoint.getDeliveryChannel(); + // create INOUT Message Exchange + InOnly inOnlyME = this.mEndpoint.createInOnlyMessageExchange(operation); + // set the content of the IN normalized message ( Normalize the message ) + NormalizedMessage inMsg = inOnlyME.getInMessage(); + Operation wsdlOperation = this.mEndpoint.getWSDLOperation(inOnlyME.getOperation()); + this.mNormalizer.normalizeInput(wsdlOperation, inMsg, RuntimeHelper.sourceToDOMSource(inSource)); + // send the message exchange and wait for response + boolean isSent = channel.sendSync(inOnlyME, SEND_SYNC_TIMEOUT); + if (!isSent) { + throw new Exception("JMXBinding:Timeout occured in sending the message to provider"); + } + // check if you got a done message or error ( done or error are only allowed in in-only) + // process the Message Exchange to check for done or error message and + // complete InOut message exchange with provider + //TODO: put this below code in processInOnlyMessageExchangeOnConsumer() + ExchangeStatus status = inOnlyME.getStatus(); + this.mEndpoint.getLogger().fine("Consumer:InOnly:Processing Message Exchange with status " + status); + if (ExchangeStatus.DONE.equals(status)) { + this.mEndpoint.getLogger().fine("Consumer: Completed the INONLY MessageExchange"); + return; + } else if (ExchangeStatus.ERROR.equals(status)) { + // error can occur any time. so just return the error back to client. + Exception serverSideEx = inOnlyME.getError(); + StringBuffer exMsgBuff = RuntimeHelper.getExceptionStackTrace(serverSideEx); + throw new Exception("Consumer:INONLY Message Exchange status ERROR.${symbol_escape}n" + exMsgBuff); + } else { + // any other status is error. + throw new Exception("Consumer:INONLY Message Exchange error. status: " + status); + } + } + + /** + * invokes service provider with in-out message exchange sent to delivery + * channel by the consumer + * + * @param operation operation name on a service + * @param inSource input xml document for the InOut operation + * @throws java.lang.Exception if any error occurs in invoking the operation + * on the service. + * @return output xml document as a Source object received from InOut + * operation of the service invoked. + */ + private Source doInOutMessageExchange(QName operation, Source inSource) + throws Exception { + // 2. normalized the message. + // 3. locate service endpoint + // 4. create message exchange according to the Opeations MEP + + // get the component context and the delivery channel for preparing to send message + ComponentContext compContext = this.mEndpoint.getComponentContext(); + DeliveryChannel channel = this.mEndpoint.getDeliveryChannel(); + // create INOUT Message Exchange + InOut inOutME = this.mEndpoint.createInOutMessageExchange(operation); + // set the content of the IN normalized message ( Normalize the message ) + NormalizedMessage inMsg = inOutME.getInMessage(); + Operation wsdlOperation = this.mEndpoint.getWSDLOperation(inOutME.getOperation()); + this.mNormalizer.normalizeInput(wsdlOperation, inMsg, RuntimeHelper.sourceToDOMSource(inSource)); + // send the message exchange and wait for response + boolean isSent = channel.sendSync(inOutME, SEND_SYNC_TIMEOUT); + if (!isSent) { + throw new Exception("JMXBinding:Timeout occured in sending the message to provider"); + } + // check if you got a out message or fault or error + // process the Message Exchange to get the output message and + // complete InOut message exchange with provider + NormalizedMessage outMsg = processInOutMessageExchangeOnConsumer(inOutME); + Source outSource = this.mNormalizer.denormalizeOutput(wsdlOperation, outMsg); + return outSource; + } + + /** + * takes the InOut message exchange received from sendSync call and + * processes it further to complete InOut message exchange with provider and + * returns the out message or throws exception in case of error or faults. + */ + private NormalizedMessage processInOutMessageExchangeOnConsumer(InOut inoutExchange) + throws Exception { + // InOut MessageExchange processing on consumer side + // 1. ACTIVE status receives a fault or out message, + // send the done status to complete message exchange + // return the fault/out message to external consumer + // 2. can not receive DONE status + // 3. when received ERROR status, return the error to consumer. + + // process the message exchange based on its state. + ExchangeStatus status = inoutExchange.getStatus(); + this.mEndpoint.getLogger().fine("Consumer:Processing Message Exchange with status " + status); + + if (ExchangeStatus.ACTIVE.equals(status)) { + + Fault fault = inoutExchange.getFault(); + NormalizedMessage outMsg = inoutExchange.getOutMessage(); + + // send done to complete message exchange. + DeliveryChannel channel = this.mEndpoint.getDeliveryChannel(); + inoutExchange.setStatus(ExchangeStatus.DONE); + channel.send(inoutExchange); + this.mEndpoint.getLogger().fine("Consumer: Completed the INOUT MessageExchange"); + + // process fault or out message + if (fault != null) { + // throw an exception if there is a fault message. + Source faultContent = fault.getContent(); + StringBuffer faultContentBuff = null; + if (faultContent != null) { + faultContentBuff = RuntimeHelper.readFromSource(faultContent); + } + throw new Exception("Consumer:INOUT message exchange Fault ${symbol_escape}n" + + faultContentBuff); + } + + // return the outMessage for processing + if (outMsg != null) { + return outMsg; + } else { + throw new Exception("Consumer: Null Out message in INOUT message exchange. "); + } + } else if (ExchangeStatus.DONE.equals(status)) { + // can not get DONE on Consumer side in INOUT message exchange. + throw new Exception("Consumer: Illegal status DONE on INOUT message exchange"); + } else if (ExchangeStatus.ERROR.equals(status)) { + // error can occur any time. so just return the error back to client. + Exception serverSideEx = inoutExchange.getError(); + StringBuffer exMsgBuff = RuntimeHelper.getExceptionStackTrace(serverSideEx); + throw new Exception("Consumer:INOUT Message Exchange status ERROR.${symbol_escape}n" + exMsgBuff); + } else { + throw new Exception("Consumer:INOUT Message Exchange error. status: " + status); + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingInstaller.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingInstaller.java new file mode 100644 index 000000000..e1b6f21e9 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingInstaller.java @@ -0,0 +1,34 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + /* + * JMXBindingInstaller.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.ComponentInstaller; + +/** + * This class extends the ComponentInstaller that implements the + * javax.jbi.component.Bootstrap for a component installation contract. + * + * If the default implemenation of the javax.jbi.component.Bootstrap in + * com.sun.jbi.sample.component.common.ComponentInstaller is not sufficient for + * this components install, uninstall and upgrade requirements, override the + * default implementation here to add component specific installation and + * upgrade tasks such as initializing configuration mbean and creating resources + * specific to component or upgrade workspace and service units during upgrading + * the component. + * + * @see javax.jbi.Bootstrap + * @see com.sun.jbi.sample.component.common.ComponentInstaller + * @author chikkala + */ +public class JMXBindingInstaller extends ComponentInstaller { + + /** + * Constructor to create the ComponentInstaller. + */ + public JMXBindingInstaller() { + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingNormalizer.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingNormalizer.java new file mode 100644 index 000000000..7452d3dca --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingNormalizer.java @@ -0,0 +1,242 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingNormalizer.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.wsdl.AbstractNormalizer; +import net.openesb.component.${artifactId}.common.wsdl.WSDL11JBIWrapper; +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import java.util.List; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.dom.DOMSource; +import org.w3c.dom.DOMException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * This class is a concrete implementation of the AbstractNormalizer to + * implement normalize jmx binding specific concrete messages to jbi wrapper + * messages and denormalize the jbi wrapper messages to jmx binding specific + * messages. The jmx binding concrete message has "message" as the root element + * that contains the part elements as its children. for example + * + * + * + * + * This is the sample code that demonstrate how to normalize and denormalize + * messages to/from jbi wrapper from/to concrete messages specific to a binding + * protocol + * + * @author chikkala + */ +public class JMXBindingNormalizer extends AbstractNormalizer { + + public static final String JMXBC_MSG_NS = "http://java.sun.com/jbi/sample/jmx-bc/envelope/"; + public static final String DEF_NS_PREFIX = "jmxbc"; + public static final String MESSAGE_EL = "message"; + + /** + * Creates a new instance of JMXBCNormalizer + */ + public JMXBindingNormalizer(Definition wsdl, Binding binding) { + super(wsdl, binding); + } + + /** + * normalizes the jmx binding protocol specific concrete message to jbi + * normalized message + */ + public void normalizeInput(Operation operation, NormalizedMessage normMsg, + DOMSource msgSource) throws MessagingException { + try { + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.createInputWrapper(operation); + Input input = operation.getInput(); + Message wsdlMsg = input.getMessage(); + //TODO: get the binding input extension here if needed. + Element jmxMessage = RuntimeHelper.getElement(msgSource); + + if (!JMXBC_MSG_NS.equals(jmxMessage.getNamespaceURI()) + || !MESSAGE_EL.equals(jmxMessage.getLocalName())) { + throw new MessagingException("invalid root element for jmxbc envelope"); + } + List jmxMsgParts = getChildElements(jmxMessage); + + addMessagePartsToJBIWrapper(jbiWrapper, wsdlMsg, jmxMsgParts); + + DOMSource wrappedSource = jbiWrapper.toDOMSource(); + normMsg.setContent(wrappedSource); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } + + /** + * normalizes the jmx binding protocol specific concrete message to jbi + * normalized message + */ + public void normalizeOutput(Operation operation, NormalizedMessage normMsg, + DOMSource msgSource) throws MessagingException { + try { + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.createInputWrapper(operation); + Output output = operation.getOutput(); + Message wsdlMsg = output.getMessage(); + //TODO: get the binding output extension here if needed. + Element jmxMessage = RuntimeHelper.getElement(msgSource); + + if (!JMXBC_MSG_NS.equals(jmxMessage.getNamespaceURI()) + || !MESSAGE_EL.equals(jmxMessage.getLocalName())) { + throw new MessagingException("invalid root element for jmxbc envelope"); + } + List jmxMsgParts = getChildElements(jmxMessage); + + addMessagePartsToJBIWrapper(jbiWrapper, wsdlMsg, jmxMsgParts); + + DOMSource wrappedSource = jbiWrapper.toDOMSource(); + normMsg.setContent(wrappedSource); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } + + /** + * normalizes the jmx binding protocol specific concrete message to jbi + * normalized message + */ + public void normalizeFault(Operation operation, String faultName, NormalizedMessage normMsg, + DOMSource msgSource) throws MessagingException { + try { + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.createInputWrapper(operation); + Fault wsdlFault = operation.getFault(faultName); + Message wsdlMsg = wsdlFault.getMessage(); + //TODO: get the binding fault extension here if needed. + Element jmxMessage = RuntimeHelper.getElement(msgSource); + + if (!JMXBC_MSG_NS.equals(jmxMessage.getNamespaceURI()) + || !MESSAGE_EL.equals(jmxMessage.getLocalName())) { + throw new MessagingException("invalid root element for jmxbc envelope"); + } + List jmxMsgParts = getChildElements(jmxMessage); + + addMessagePartsToJBIWrapper(jbiWrapper, wsdlMsg, jmxMsgParts); + + DOMSource wrappedSource = jbiWrapper.toDOMSource(); + normMsg.setContent(wrappedSource); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } + + /** + * denormalizes the jbi message to the jmx binding protocol specific + * concrete message. + */ + public DOMSource denormalizeInput(Operation operation, NormalizedMessage normMsg) + throws MessagingException { + try { + + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.sourceToWrapper( + RuntimeHelper.sourceToDOMSource(normMsg.getContent())); + Input input = operation.getInput(); + Message wsdlMsg = input.getMessage(); + //TODO: get the binding input extension here if needed. + + Document jmxMsgDoc = jbiWrapper.getDocumentBuilder().newDocument(); + Element jmxMessage = jmxMsgDoc.createElementNS(JMXBC_MSG_NS, DEF_NS_PREFIX + ":" + MESSAGE_EL); + jmxMessage.setAttributeNS(XMLNS_NS, "xmlns:" + DEF_NS_PREFIX, JMXBC_MSG_NS); + jmxMsgDoc.appendChild(jmxMessage); + + List jmxMsgParts = getMessagePartsFromJBIWrapper(jbiWrapper, wsdlMsg); + for (int i = 0; i < jmxMsgParts.size(); ++i) { + jmxMessage.appendChild(jmxMsgDoc.importNode(jmxMsgParts.get(i), true)); + } + + DOMSource unwrappedSource = new DOMSource(jmxMsgDoc); + return unwrappedSource; + } catch (DOMException ex) { + throw new MessagingException(ex); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } + + /** + * denormalizes the jbi message to the jmx binding protocol specific + * concrete message. + */ + public DOMSource denormalizeOutput(Operation operation, NormalizedMessage normMsg) + throws MessagingException { + try { + + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.sourceToWrapper( + RuntimeHelper.sourceToDOMSource(normMsg.getContent())); + Output output = operation.getOutput(); + Message wsdlMsg = output.getMessage(); + //TODO: get the binding output extension here if needed. + + Document jmxMsgDoc = jbiWrapper.getDocumentBuilder().newDocument(); + Element jmxMessage = jmxMsgDoc.createElementNS(JMXBC_MSG_NS, DEF_NS_PREFIX + ":" + MESSAGE_EL); + jmxMessage.setAttributeNS(XMLNS_NS, "xmlns:" + DEF_NS_PREFIX, JMXBC_MSG_NS); + + List jmxMsgParts = getMessagePartsFromJBIWrapper(jbiWrapper, wsdlMsg); + + for (int i = 0; i < jmxMsgParts.size(); ++i) { + jmxMessage.appendChild(jmxMsgDoc.importNode(jmxMsgParts.get(i), true)); + } + jmxMsgDoc.appendChild(jmxMessage); + DOMSource unwrappedSource = new DOMSource(jmxMsgDoc); + return unwrappedSource; + } catch (DOMException ex) { + throw new MessagingException(ex); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } + + /** + * denormalizes the jbi message to the jmx binding protocol specific + * concrete message. + */ + public DOMSource denormalizeFault(Operation operation, String faultName, NormalizedMessage normMsg) + throws MessagingException { + try { + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.sourceToWrapper( + RuntimeHelper.sourceToDOMSource(normMsg.getContent())); + Fault wsdlFault = operation.getFault(faultName); + Message wsdlMsg = wsdlFault.getMessage(); + //TODO: get the binding fault extension here if needed. + + Document jmxMsgDoc = jbiWrapper.getDocumentBuilder().newDocument(); + Element jmxMessage = jmxMsgDoc.createElementNS(JMXBC_MSG_NS, DEF_NS_PREFIX + ":" + MESSAGE_EL); + jmxMessage.setAttributeNS(XMLNS_NS, "xmlns:" + DEF_NS_PREFIX, JMXBC_MSG_NS); + + List jmxMsgParts = getMessagePartsFromJBIWrapper(jbiWrapper, wsdlMsg); + + for (int i = 0; i < jmxMsgParts.size(); ++i) { + jmxMessage.appendChild(jmxMsgDoc.importNode(jmxMsgParts.get(i), true)); + } + jmxMsgDoc.appendChild(jmxMessage); + DOMSource unwrappedSource = new DOMSource(jmxMsgDoc); + return unwrappedSource; + } catch (DOMException ex) { + throw new MessagingException(ex); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingProviderEndpoint.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingProviderEndpoint.java new file mode 100644 index 000000000..e6ab7f172 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingProviderEndpoint.java @@ -0,0 +1,87 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingProviderEndpoint.java + * + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.wsdlext.PortExt; +import net.openesb.component.${artifactId}.wsdlext.WSDLExtHelper; +import net.openesb.component.${artifactId}.common.MessageExchangeHandler; +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.MessageExchangeListener; +import net.openesb.component.${artifactId}.common.deployment.ProviderEndpoint; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor; +import net.openesb.component.${artifactId}.common.deployment.ServiceUnit; +import java.util.logging.Level; +import javax.jbi.JBIException; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +/** + * This class extends the ProviderEndpoint to implement component specific + * endpoint configuration. It implements the MessageExchangeListener to receive + * message exchange notifications from the MessageExchangeSupport fired by + * MessageExchangeReceiver and process it using a message exchange handler to + * show how an asynchronous processing of message exchange can be done. + * + * This endpoint uses the JMXBindingProviderProxy as a message exchange handler + * that can invoke the external provider to send a message and receive the + * response in a InOut message exchange. + * + * @author chikkala + */ +public class JMXBindingProviderEndpoint extends ProviderEndpoint implements MessageExchangeListener { + + JMXBindingProviderProxy mProviderProxy; + + /** + * Creates a new instance of XSLTProviderEndpoint + */ + public JMXBindingProviderEndpoint(SUDescriptor.Provides provides, Definition wsdlDef, ServiceUnit su) { + super(provides, wsdlDef, su); + } + + @Override + public void doInit() throws JBIException { + RuntimeHelper.getLogger().info("JMXBindingProviderEndpoint:doInit called"); + this.mProviderProxy = new JMXBindingProviderProxy(this); + } + + @Override + public MessageExchangeHandler createMessageExchangeHandler() { + return this.mProviderProxy; + } + + @Override + protected MessageExchangeListener createMessageExchangeListener() { + return this; + } + + public void messageExchangeReceived(ExchangeStatus status, MessageExchange me) { + try { + RuntimeHelper.getLogger().fine("MXListener.MessageExchangeReceived: with Status: " + status); + processMessageExchangeWithHandler(status, me); + // processMessageExchange(me); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public PortExt getJMXProviderInfo() { + PortExt portExt = null; + try { + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + Definition def = this.getWSDL(); + portExt = WSDLExtHelper.getPortExt(def, serviceName, endpointName); + } catch (Exception ex) { + getLogger().log(Level.FINE, ex.getMessage(), ex); + } + return portExt; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingProviderProxy.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingProviderProxy.java new file mode 100644 index 000000000..1d263da33 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingProviderProxy.java @@ -0,0 +1,235 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingProviderProxy.java + * + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.wsdlext.PortExt; +import net.openesb.component.${artifactId}.common.AbstractMessageExchangeHandler; +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import java.io.IOException; +import java.io.StringReader; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.Fault; +import javax.jbi.messaging.InOut; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; +import javax.wsdl.Operation; +import javax.xml.namespace.QName; +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMSource; + +/** + * This is a provider side implementation of the message exchange handler on a + * binding component which acts as a service provider proxy for the external + * provider. During the message exchange processing of the InOut message + * exchange, this handler acting as a proxy to the external provider invokes the + * service operation on the external provider and does required normalization + * and denormalization in processing out and in messages received from or send + * to the external service provider. + * + * @author chikkala + */ +public class JMXBindingProviderProxy extends AbstractMessageExchangeHandler { + + private JMXBindingProviderEndpoint mEndpoint; + private String mServiceURL; + private String mUsername; + private String mPassword; + private String mMBeanName; + private JMXBindingNormalizer mNormalizer; + + /** + * Creates a new instance of ProviderSEMXHandler + */ + public JMXBindingProviderProxy(JMXBindingProviderEndpoint endpoint) { + + this.mEndpoint = endpoint; + + PortExt jmxInfo = this.mEndpoint.getJMXProviderInfo(); + this.mServiceURL = jmxInfo.getServiceURL(); + this.mUsername = jmxInfo.getUsername(); + this.mPassword = jmxInfo.getPassword(); + this.mMBeanName = jmxInfo.getMBean(); + + this.mNormalizer = new JMXBindingNormalizer(endpoint.getWSDL(), endpoint.getWSDLBinding()); + } + + protected Logger getLogger() { + return this.mEndpoint.getLogger(); + } + + protected DeliveryChannel getDeliveryChannel() { + return this.mEndpoint.getDeliveryChannel(); + } + + protected void validateMessageExchange() throws MessagingException { + MessageExchange msgExchange = this.getMessageExchange(); + + if (this.getMessageExchange() == null) { + throw new MessagingException("MessageExchange Object is null in MessageExchageHandler"); + } + + if (MessageExchange.Role.CONSUMER.equals(msgExchange.getRole())) { + throw new MessagingException("Provider Message Exchange Handler can not have MessageExchange with CONSUMER Role"); + } + + if (!(msgExchange instanceof InOut)) { + throw new MessagingException("InOut Message Exchange Handler MessageExchange object should be instanceof javax.jbi.messaging.InOut "); + } + } + + protected void processError(Exception ex) { + MessageExchange msgExchange = this.getMessageExchange(); + Exception errEx = msgExchange.getError(); // get the error and print + RuntimeHelper.getLogger().info( + "InOut Message Exchange Provider received Error: " + errEx.getMessage()); + msgExchange.getError().printStackTrace(); + } + + protected void processDone() { + MessageExchange msgExchange = this.getMessageExchange(); + RuntimeHelper.getLogger().info("InOut Message Exchange Provider received DONE :" + + " END of service invocation"); + } + + protected void processFault(Fault fault) { + MessageExchange msgExchange = this.getMessageExchange(); + RuntimeHelper.logError("InOut Message Exchange Provider Handler can not receive Fault on Provider side"); + } + + protected void processMessage() { + try { + processInMessageOnProvider((InOut) this.getMessageExchange()); + } catch (JBIException ex) { + ex.printStackTrace(); + } + } + + protected void processInMessageOnProvider(InOut inOutExchange) throws JBIException { + RuntimeHelper.getLogger().fine("Processing In Message on Provider side " + inOutExchange); + // receive IN message. + NormalizedMessage inMsg = inOutExchange.getInMessage(); + NormalizedMessage outMsg = null; + Fault fault = null; + DOMSource inContent = null; + DOMSource outContent = null; + Source faultContent = null; + String faultAsText = null; + + QName opName = inOutExchange.getOperation(); + QName svcName = inOutExchange.getEndpoint().getServiceName(); + Operation wsdlOperation = this.mEndpoint.getWSDLOperation(opName); + + // process in message + // invoke the service operation + try { + inContent = this.mNormalizer.denormalizeInput(wsdlOperation, inMsg); + StringBuffer outputDoc = invokeOperation(opName.getLocalPart(), + RuntimeHelper.readFromDOMSource(inContent)); + outContent = RuntimeHelper.createDOMSource(new StringReader(outputDoc.toString())); + } catch (Exception ex) { + // exception invoking the operation. so, set exception text as fault content. + ex.printStackTrace(); + faultAsText = RuntimeHelper.getExceptionAsText(ex); + String faultText = RuntimeHelper.getExceptionAsXmlText(ex); + faultContent = RuntimeHelper.createDOMSource(new StringReader(faultText)); + } + // set out or fault message + if (outContent != null) { + // set the out message content. + outMsg = inOutExchange.createMessage(); + inOutExchange.setOutMessage(outMsg); + this.mNormalizer.normalizeOutput(wsdlOperation, outMsg, outContent); + // outMsg.setContent(outContent); + } else if (faultContent != null) { + fault = inOutExchange.createFault(); + inOutExchange.setFault(fault); + fault.setContent(faultContent); // may need to normalize the content. + } + // send out or fault message. + this.send(); + } + + protected StringBuffer invokeOperation(String operation, StringBuffer inputDoc) throws MessagingException { + try { + StringBuffer outputDoc = invokeSendMessage(this.mServiceURL, this.mUsername, this.mPassword, + this.mMBeanName, operation, inputDoc); + return outputDoc; + } catch (Exception ex) { + ex.printStackTrace(); + throw new MessagingException(ex); + } + } + + /** + * invokes a jmx mbean to send message. + */ + protected StringBuffer invokeSendMessage(String serviceURL, String username, String password, + String mbeanName, String operation, StringBuffer inputDoc) + throws MessagingException { + + JMXConnector jmxConnector = null; + MBeanServerConnection jmxConn = null; + JMXServiceURL jmxURL = null; + ObjectName epAddressName = null; + + Map env = new HashMap(); + if (username != null) { + String[] credentials = new String[]{username, password}; + env.put("jmx.remote.credentials", credentials); + env.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, this.getClass().getClassLoader()); + } + + StringBuffer outDoc = null; + + Object result = null; + String mbeanOperation = "sendMessage"; + + Object[] params = new Object[2]; + params[0] = operation; + params[1] = inputDoc; + + String[] signature = new String[2]; + signature[0] = "java.lang.String"; + signature[1] = "java.lang.StringBuffer"; + + try { + jmxURL = new JMXServiceURL(serviceURL); + epAddressName = new ObjectName(mbeanName); + + jmxConnector = JMXConnectorFactory.connect(jmxURL, env); + jmxConn = jmxConnector.getMBeanServerConnection(); + + result = jmxConn.invoke(epAddressName, mbeanOperation, params, signature); + if (result != null) { + outDoc = (StringBuffer) result; + } + } catch (Exception ex) { + throw new MessagingException(ex); + } finally { + if (jmxConnector != null) { + try { + jmxConnector.close(); + } catch (IOException ex) { + RuntimeHelper.logDebug(ex); + // ingore + } + } + } + return outDoc; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingRuntime.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingRuntime.java new file mode 100644 index 000000000..a3252887e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingRuntime.java @@ -0,0 +1,57 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingRuntime.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.ComponentRuntime; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.component.ServiceUnitManager; + +/** + * This class extends the ComponentRuntime that implements + * javax.jbi.component.Component interface required for the component contract + * at runtime. + * + * This class provides the component specific ComponentLifeCycle implementation + * as well as the component specific ServiceUnitManager implementation. + * + * Add any additional component runtime specific functionality here. + * + * @see javax.jbi.component.Component + * @see com.sun.jbi.sample.component.common.ComponentRuntime + * @see com.sun.jbi.sample.component.common.BasicComponentLifecycle + * @see + * com.sun.jbi.sample.component.common.deployment.AbstractServiceUnitManager + * @author chikkala + */ +public class JMXBindingRuntime extends ComponentRuntime { + + /** + * Creates a new instance of MyBindingRuntime + */ + public JMXBindingRuntime() { + super(); + } + + /** + * overriding the parent's createComponentLifeCycle to create MyBinding + * specific component lifecycle implementation. + */ + @Override + protected ComponentLifeCycle createComponentLifeCycle() { + return new JMXBindingComponentLifeCycle(this); + } + + /** + * if this component supports service unit deployment, then return the + * service unit manager, else return null. Extended classes can override + * this method and do their own ServiceUnitManager specific creation. + */ + @Override + protected ServiceUnitManager createServiceUnitManager() { + return new JMXBindingSUManager(this); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingSUManager.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingSUManager.java new file mode 100644 index 000000000..75968c59a --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingSUManager.java @@ -0,0 +1,51 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingSUManager.java + * + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.deployment.AbstractServiceUnitManager; +import net.openesb.component.${artifactId}.common.deployment.ServiceUnit; +import java.util.logging.Logger; +import javax.jbi.management.DeploymentException; + +/** + * This class extends the AbstractServiceUnitManager to implement component + * specific service unit manager by creating the component specific ServiceUnit + * implementation. + * + * @see + * com.sun.jbi.sample.component.common.deployment.AbstractServiceUnitManager + * @see com.sun.jbi.sample.component.common.deployment.ServiceUnit + * + * @author chikkala + */ +public class JMXBindingSUManager extends AbstractServiceUnitManager { + + private JMXBindingRuntime mRuntime; + + /** + * Creates a new instance of JMXBindingSUManager + */ + public JMXBindingSUManager(JMXBindingRuntime compRuntime) { + super(); + this.mRuntime = compRuntime; + } + + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + + protected String getComponentName() { + return RuntimeHelper.getComponentName(); + } + + //TODO implement ProviderSEServiceUnit + protected ServiceUnit createServiceUnit(String suName, String suRootPath) throws DeploymentException { + return new JMXBindingServiceUnit(suName, suRootPath); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingServiceUnit.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingServiceUnit.java new file mode 100644 index 000000000..9175742ba --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingServiceUnit.java @@ -0,0 +1,55 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingServiceUnit.java + * + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.deployment.ConsumerEndpoint; +import net.openesb.component.${artifactId}.common.deployment.ProviderEndpoint; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Consumes; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Provides; +import net.openesb.component.${artifactId}.common.deployment.ServiceUnit; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import javax.jbi.management.DeploymentException; +import javax.wsdl.Definition; + +/** + * This class extends the ServiceUnit to implement the component specific + * service unit processing. It creates the component specific ProviderEndpoint + * and ConsumerEndpoint implementation to configure the service provider and + * consumer endpoints on this component deployed in the service unit. + * + * @author chikkala + */ +public class JMXBindingServiceUnit extends ServiceUnit { + + /** + * Creates a new instance of ProviderSEServiceUnit + */ + public JMXBindingServiceUnit(String suName, String suRootPath) { + super(suName, suRootPath); + } + + @Override + protected WSDLProcessor createWSDLProcessor() { + return new JMXBindingWSDLProcessor(this.getSURootPath()); + } + + @Override + protected ConsumerEndpoint createConsumerEndpoint(Consumes consumes, Definition wsdlDef) { + return new JMXBindingConsumerEndpoint(consumes, wsdlDef, this); + } + + @Override + protected ProviderEndpoint createProviderEndpoint(Provides provides, Definition wsdlDef) { + return new JMXBindingProviderEndpoint(provides, wsdlDef, this); + } + + @Override + protected void loadOtherArtifacts() throws DeploymentException { + //TODO: load any component specific service unit artifacts + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingWSDLProcessor.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingWSDLProcessor.java new file mode 100644 index 000000000..67b92ee50 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXBindingWSDLProcessor.java @@ -0,0 +1,43 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingWSDLProcessor.java + * + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.wsdlext.WSDLExtensionRegistry; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import javax.wsdl.extensions.ExtensionRegistry; + +/** + * This class extends form the WSDLProcessor to configure the wsdl processor use + * the wsdl extension registry configured to process the binding specific + * extension elements in the wsdl documents. + * + * WSDLExtensionRegistry that is created here has the wsdl extension model + * required to process the extension elements specific to the binding used by + * this binding component. + * + * @author chikkala + */ +public class JMXBindingWSDLProcessor extends WSDLProcessor { + + private WSDLExtensionRegistry mExtRegistry; + + /** + * Creates a new instance of JMXBindingWSDLProcessor + */ + public JMXBindingWSDLProcessor(String wsdlDir) { + super(wsdlDir); + } + + @Override + protected ExtensionRegistry getExtensionRegistry() { + if (this.mExtRegistry == null) { + this.mExtRegistry = new WSDLExtensionRegistry(); + } + return this.mExtRegistry; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXEndpointMBean.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXEndpointMBean.java new file mode 100644 index 000000000..3c14041e8 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/JMXEndpointMBean.java @@ -0,0 +1,41 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXEndpointMBean.java + */ +package net.openesb.component.${artifactId}; + +/** + * The sample BC implemented as a jmx binding component exposes this interface + * as a external connectivity (endpoint address) to the external service + * consumers that can exchange messages over jmx protocol to invoke services + * provided inside jbi environment. + * + * A jmx client can send a message by invoking this method using jmx management + * interface. When this mbean method is executed in the BC as a result of mbean + * call from the jmx client, the BC acts as a proxy service consumer inside the + * jbi environment and starts a message exchange with the service provider. + * + * If the operation being executed is a InOut operation, the BC should return + * the Out or Fault message from the InOut message exchange as a return value to + * complete invocation of the service by the external consumer. + * + * @author chikkala + */ +public interface JMXEndpointMBean { + + /** + * This method will be called by a jmx client as a service consumer to send + * message to the echo service provider to invoke the service for a InOut + * message exchange. + * + * @param operation operation name on a service + * @param inputDoc input xml document for the InOut operation + * @return output xml document in a StringBuffer received from InOut + * operation of the service invoked. or null if the operation is InOnly. + * @throws java.lang.Exception if any error occurs in invoking the operation + * on the service. + */ + StringBuffer sendMessage(String operation, StringBuffer inputDoc) throws Exception; +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java new file mode 100644 index 000000000..4987029b3 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java @@ -0,0 +1,141 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractMessageExchangeHandler.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import java.io.StringReader; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.Fault; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; +import javax.xml.namespace.QName; + +/** + * This class is an abstract implementation of the MessageExchangeHandler which + * provides the base implementation of the ME processing and provides hooks to + * extended classes to implement component specific processing. + * + * @author chikkala + */ +public abstract class AbstractMessageExchangeHandler implements MessageExchangeHandler { + + public static String IN_MESSAGE = "in"; + public static String OUT_MESSAGE = "out"; + + private MessageExchange mMessageExchange; + private ExchangeStatus mStatus; + /** Creates a new instance of AbstractMessageExchangeHandler */ + protected AbstractMessageExchangeHandler() { + this.mMessageExchange = null; + } + + protected abstract Logger getLogger(); + protected abstract DeliveryChannel getDeliveryChannel(); + protected abstract void validateMessageExchange() throws MessagingException; + protected abstract void processError(Exception ex); + protected abstract void processDone(); + protected abstract void processMessage(); + protected abstract void processFault(Fault fault); + + public final MessageExchange getMessageExchange() { + return this.mMessageExchange; + } + + public final void setMessageExchange(MessageExchange msgExchange) { + this.mMessageExchange = msgExchange; + } + + public final ExchangeStatus getMessageExchangeStatus() { + if ( this.mStatus != null ) { + return this.mStatus; + } else if ( this.mMessageExchange != null ) { + return this.mMessageExchange.getStatus(); + } else { + return null; + } + } + + public final void setMessageExchangeStatus(ExchangeStatus status) { + this.mStatus = status; + } + + protected void send() throws MessagingException { + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected boolean sendSync(long timeout) throws MessagingException { + return this.getDeliveryChannel().sendSync(this.mMessageExchange, timeout); + } + + protected void sendDone() throws MessagingException { + this.mMessageExchange.setStatus(ExchangeStatus.DONE); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void sendError(Exception ex) throws MessagingException { + this.mMessageExchange.setError(ex); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void sendFault(Exception ex, QName type, String name) throws MessagingException { + Fault fault = this.mMessageExchange.createFault(); + if ( ex != null ) { + String xmlText = RuntimeHelper.getExceptionAsXmlText(ex); + fault.setContent(RuntimeHelper.createDOMSource(new StringReader(xmlText))); + } + this.mMessageExchange.setFault(fault); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void processActive() { + Fault fault = this.getMessageExchange().getFault(); + if ( fault != null ) { + processFault(fault); + } else { + processMessage(); + } + } + /** + * implementation of the MessageExchangeHandler${symbol_pound}processMessageExchange method. + */ + public void processMessageExchange(ExchangeStatus status, MessageExchange msgEx) { + + getLogger().fine("MessageExchangeHandler.processMessageExchange:status: " + status ); + + this.setMessageExchangeStatus(status); + this.setMessageExchange(msgEx); + + try { + validateMessageExchange(); + } catch (MessagingException ex) { + getLogger().log(Level.FINE, "Invalid message exchange for processing ", ex); + if ( this.getMessageExchange() != null ) { + try { + sendError(ex); + } catch (MessagingException errEx) { + getLogger().log(Level.FINE, "Can not send invalid message exchange error", errEx); + } + } + return; + } + + MessageExchange msgExchange = this.getMessageExchange(); + + if (ExchangeStatus.ACTIVE.equals(status) ) { + processActive(); + } else if (ExchangeStatus.DONE.equals(status) ) { + processDone(); + } else if (ExchangeStatus.ERROR.equals(status) ) { + processError(msgExchange.getError()); + } + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java new file mode 100644 index 000000000..d76fbe0f9 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java @@ -0,0 +1,398 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractComponentLifeCycle.java + */ + +package net.openesb.component.${artifactId}.common; + +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.component.Component; +import javax.jbi.component.ComponentContext; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.MessagingException; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.StandardMBean; + +/** + * This class implements the javax.jbi.component.ComponentLifeCycle. This is an + * abstract class that keeps the reference to the component context and the lifecycle + * extension mbeans. It implements the lifecycle method and provide the extended methods + * for each lifecycle methods to implement component specific functionality. + *

+ * It makes sure that the mininum initialization required for the component + * lifecycle is implemented by this class or the classes extending this class. + *

+ * Another important functionality implemented in this class is that it initializes the global + * RuntimeContext for the component with the ComponentContext passed by the JBI runtime and the + * opened delivery channel to make them available globally to any class in the component implementation + * that may need it during component lifecycle + *

+ * Service engine or a binding component lifecycle implementation can directly extend + * this class for their required functionality and override some of the methods to provide + * their own implementation. + * + * @see javax.jbi.ComponentLifeCycle + * @author chikkala + */ +public class BasicComponentLifeCycle implements ComponentLifeCycle { + /** reference to the component runtime */ + private Component mCompRuntime; + /** component context */ + private ComponentContext mComponentContext; + /** Extension Mbean Name*/ + private ObjectName mExtensionMBeanName; + /** Extension Mbean Implementation*/ + private StandardMBean mExtensionMBeanImpl; + /** a message receiver that accepts messages from delivery channel */ + private MessageExchangeReceiver mMsgExchReceiver; + + /** + * constructor for the ComponentLifecycle implementation. + * @param compRuntime + */ + protected BasicComponentLifeCycle(Component compRuntime) { + this.mCompRuntime = compRuntime; + } + /** + * @return Component + */ + public final Component getComponentRuntime() { + return this.mCompRuntime; + } + /** + * @return ComponentContext component context. + */ + public final ComponentContext getComponentContext() { + return mComponentContext; + } + /** + * @return component name + */ + protected String getComponentName() { + return (this.mComponentContext != null) ? + this.mComponentContext.getComponentName() : null; + } + /////////////////////////////////////////////////////////////////////////// + // ComponentLifeCycle interface implemenation + /////////////////////////////////////////////////////////////////////////// + + /** + * Initializes the component lifecycle. This method makes sure that the + * component context passed by the jbi runtime is saved in the lifecycle + * object before calling the other component initialization methods to + * completely initialize the component. + * @param context Component context + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}init(javax.jbi.component.ComponentContext) + * @throws javax.jbi.JBIException on error + */ + public final void init(ComponentContext context) throws JBIException { + + if ( context == null ) { + throw new JBIException("Null Component Context received in " + + "Component Lifecycle init "); + } + this.mComponentContext = context; // 0. save the component context passed by jbi framework. + // initialize the content + initGlobalContext(); // 1. Initialize component runtime context. + registerExtensionMBean(); // 2. Create and register extension mbean. + openDeliveryChannel(); // 3. Open delivery channel. + initMessageExchangeReceiver(); // 4. Create message exchange receiver. + doInit(); // 5. Do any component specific initialization such + // as static service providers and consumers initialization. + + this.getLogger().fine("Component " + this.getComponentName() + " initialized"); + } + + /** + * Starts the component. Extended classes can override/implement the methods called + * in this method to provide component specify start functionality. + * + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}start() + * @throws javax.jbi.JBIException on error + */ + public final void start() throws JBIException { + + doStart(); // 1. do any other component specific start tasks such as + // activating any static service providers and consumers. + startMessageExchangeProcessing(); // 2. begin accepting and processing message exchanges. + + this.getLogger().fine("Component " + this.getComponentName() + " started"); + } + + /** + * Stop the component.Extended classes can override/implement the methods called + * in this method to provide component specify stop functionality. + * @throws javax.jbi.JBIException + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}stop() + */ + public final void stop() throws JBIException { + + stopMessageExchangeProcessing(); // 1. stop accepting and processing message exchanges. + doStop(); // 2. do any other component specific stop tasks such as + // deactivating any static service providers and consumers. + this.getLogger().fine("Component " + this.getComponentName() + " stopped."); + } + + /** + * Shut down the component. Extended classes can override/implement the methods called + * in this method to provide component specify shut down functionality. + * @throws javax.jbi.JBIException + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}shutDown() + */ + public final void shutDown() throws JBIException { + // clean up all resources. + shutdownMessageExchangeReceiver(); // 1. remove the message receiver. + closeDeliveryChannel(); // 2. close delivery channel + unregisterExtensionMBean(); // 3. unregister and remove extension mbean if exists. + doShutDown(); // 4. do any other component specific clean up tasks such + // as clean any static service providers and consumer resource. + this.getLogger().fine("Component " + this.getComponentName() + " shut down"); + } + /** + * create jmx object name for the extension mbean. default implementation does + * not required to have the extension mbean. + * @return ObjectName of the extension mbean + */ + protected ObjectName createExtensionMBeanName() { + return null; + } + /** + * gets the reference to the extension mbean name. + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}getExtensionMBeanName() + * @return ObjectName of the extension mbean objectname or null if component + * does not support extension mbean + */ + public final ObjectName getExtensionMBeanName() { + if ( this.mExtensionMBeanName == null ) { + this.mExtensionMBeanName = this.createExtensionMBeanName(); + } + return this.mExtensionMBeanName; + } + /** + * create mbean implementation for the extension mbean as a StandardMBean. default + * implementation does not require the extension mbean + * @return the ExtensionMBean implementation as StandardMBean + */ + protected StandardMBean createExtensionMBean() { + return null; + } + /** + * gets the reference to the extension mbean. + * @return extension mbean implementation or null if component does not support. + */ + protected final StandardMBean getExtensionMBean() { + if ( this.mExtensionMBeanImpl == null ) { + this.mExtensionMBeanImpl = this.createExtensionMBean(); + } + return this.mExtensionMBeanImpl; + } + /** + * if there is an extension mbean supported by the component, then register + * it with the mbean server. + * @throws JBIException on error registering mbean + */ + protected final void registerExtensionMBean() throws JBIException { + // creatre the extension mbean's object name + ObjectName mbeanName = this.getExtensionMBeanName(); + // create the extension mbean implemenation. + StandardMBean mbeanImpl = this.getExtensionMBean(); + + if ( mbeanName == null || mbeanImpl == null ) { + this.getLogger().fine(this.getComponentName() + + " Does not have Extension MBean implemenation "); + return; + } + // register with mbean only if object name and implementation are non null + try { + MBeanServer mbServer = RuntimeHelper.getComponentContext().getMBeanServer(); + mbServer.registerMBean(mbeanImpl, mbeanName); + } catch (Exception e) { + throw new JBIException("Failed to register Extension MBean for " + + this.getComponentName(), e); + } + } + /** + * remove the registered extension mbean from the mbean server if any. + */ + protected final void unregisterExtensionMBean() { + ObjectName mbeanName = this.getExtensionMBeanName(); + if ( mbeanName == null ) { + return; + } + try { + MBeanServer mbServer = RuntimeHelper.getComponentContext().getMBeanServer(); + mbServer.unregisterMBean(mbeanName); + } catch (Exception e) { + this.getLogger().log(Level.WARNING, + "Failed to unregister Extension MBean from MBeanServer for " + this.getComponentName(), e); + } + } + /** + * creates MessageExchangeReceiver implementation that handles receiving and processing + * the message exchanges from the delivery channel. Component should implement + * this method to provide the MessageReceiver. + * + * Component may return null indicating that they don't need the message receiver + * that can receive and process message exchanges from delivery channel. For example, + * components that have only service consumers which send a synchronous messages to + * providers don't need this. + * + * @throws java.lang.Exception + * @return MessageExchangeReceiver implementation. null if the component does not support it. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle${symbol_pound}createMessageExchangeReceiver + */ + protected MessageExchangeReceiver createMessageExchangeReceiver() { + return null; + } + /** + * returns the message exchange receiver implementation reference + * @return MessageExchangeReceiver interface + */ + protected final MessageExchangeReceiver getMessageExchangeReceiver() { + if ( this.mMsgExchReceiver == null ) { + this.mMsgExchReceiver = createMessageExchangeReceiver(); + } + return this.mMsgExchReceiver; + } + /** + * creates a message receiver object as part of the component initialization. + * @throws javax.jbi.JBIException + */ + protected void initMessageExchangeReceiver() throws JBIException { + // create and initialize the MessageExchangeReceiver + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.initReceiver(); + } + } + /** + * allows the component to accept the message exchange objects from the + * delivery channel and process it as part of the component startup process. + * @throws javax.jbi.JBIException + */ + protected void startMessageExchangeProcessing() throws JBIException { + // start message processing + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.startProcessing(); + } + } + /** + * stops the component from accepting the message exchange objects from the + * delivery channel as part of the component stop process + * @throws javax.jbi.JBIException + */ + protected void stopMessageExchangeProcessing() throws JBIException { + // stop message processing + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.stopProcessing(); + } + } + /** + * removes the message receiver as part of the component shutdown process + * @throws javax.jbi.JBIException + */ + protected void shutdownMessageExchangeReceiver() throws JBIException { + // clean up message processing. + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.shutdownReceiver(); + } + } + /** + * Returns logger initialized from the component context or a default logger. + * @return Logger + */ + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** + * initializes the RuntimeContext during component init lifecycle phase. This + * includes setting the ComponentContext and loggers etc. extended classes must + * save the component context in the RuntimeContext in this methods implementation. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle${symbol_pound}initGlobalContext + */ + protected void initGlobalContext() { + RuntimeContext.getInstance().setComponentContext(this.getComponentContext()); + RuntimeContext.getInstance().setLogger(this.getClass().getName(), null); + } + /** opens the delivery channel to accept or send message exchange objects + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle${symbol_pound}openDeliveryChannel + */ + protected void openDeliveryChannel() { + try { + DeliveryChannel channel = this.getComponentContext().getDeliveryChannel(); + RuntimeContext.getInstance().setDeliveryChannel(channel); + } catch (MessagingException ex) { + ex.printStackTrace(); + } + } + /** closes the delivery channel as part of the component shutdown process. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle${symbol_pound}closeDeliveryChannel + */ + protected void closeDeliveryChannel() { + // closes delivery channel and remove the reference. + try { + DeliveryChannel channel = RuntimeHelper.getDeliveryChannel(); + if ( channel != null ) { + channel.close(); + } + } catch (MessagingException ex) { + ex.printStackTrace(); + } finally { + RuntimeContext.getInstance().setDeliveryChannel(null); + } + } + /** + * chance to extended classes to do any extra component specific init tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * initialized here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle${symbol_pound}init method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle${symbol_pound}init + */ + protected void doInit() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific start tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * activated here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle${symbol_pound}start method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle${symbol_pound}start + */ + protected void doStart() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific stop tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * deactivated here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle${symbol_pound}stop method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle${symbol_pound}stop + */ + protected void doStop() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific shutdown tasks.If the component + * supports static service providers or consumers without deployment support, they can be + * cleaned up here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle${symbol_pound}shutdown method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle${symbol_pound}shutdown + */ + protected void doShutDown() throws JBIException { + //NOOP + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/ComponentInstaller.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/ComponentInstaller.java new file mode 100644 index 000000000..7e44dc053 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/ComponentInstaller.java @@ -0,0 +1,275 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + /* + * ComponentInstaller.java + */ +package net.openesb.component.${artifactId}.common; + +import java.util.List; +import java.util.logging.Level; +import javax.jbi.component.Bootstrap; +import javax.jbi.component.InstallationContext; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.StandardMBean; + +/** + * This class implements the javax.jbi.component.Bootstrap. This class implements + * the minimum required functionality for component installation contract + * of the jbi component in the jbi environment. It also takes care of maintaining + * the installation context reference and installation specific logger creation and + * installation extension mbean registration and unregistration during initialization + * and cleanup. Extended classes only need to supply the mbean name and its implementation + * object for the installation extensions. + * + * It makes sure that the installation context and the loggers are available to + * the classes extended from this class to add more installation specific functionality. + * + * Service engine or a binding component installation implementation can directly use + * this class or extend this class to add more functionality to their installation + * process. + * + * @see javax.jbi.Bootstrap + * @author chikkala + */ +public class ComponentInstaller implements Bootstrap { + /** default logger*/ + private Logger mDefLogger; + /** bootstrap logger */ + private Logger mBTLogger ; + /** Installation Context . */ + private InstallationContext mInstallationContext; + /** Extension Mbean Name*/ + private ObjectName mExtensionMBeanName; + /** Extension Mbean Implementation*/ + private StandardMBean mExtensionMBeanImpl; + + /** Constructor to create the ComponentInstaller. */ + public ComponentInstaller() { + } + /** + * @return InstallationContext of the component. + */ + public final InstallationContext getInstallationContext() { + return this.mInstallationContext; + } + protected String getComponentName() { + return (this.mInstallationContext != null) ? + this.mInstallationContext.getComponentName() : null; + } + /** + * @return logger initialized from the installation context or a default + * logger. + */ + protected Logger getLogger() { + // try init bootstrap logger + if (this.mBTLogger == null && this.mInstallationContext != null ) { + try { + this.mBTLogger = + this.mInstallationContext.getContext().getLogger(this.getClass().getName(), null); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + // init default logger if required + if ( this.mBTLogger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (this.mBTLogger != null) ? this.mBTLogger : this.mDefLogger; + } + /** + * Initializes the installation environment for a component. + * @see javax.jbi.component.Bootstrap${symbol_pound}init(javax.jbi.component.InstallationContext) + */ + public final void init(InstallationContext installContext) throws javax.jbi.JBIException { + + if ( installContext == null ) { + throw new JBIException("Null Installation Context received in " + + "Component Bootstrap initialization"); + } + // save the installation context reference passed by the jbi framework. + this.mInstallationContext = installContext; + registerExtensionMBean(); // create and register extension mbean + doInit(); // do any other extra initialization required specific to the component installation. + // initialize logger + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component Installer initialized"); + } + /** + * default implementation just logs the method call. extended classes should override this. + * @see javax.jbi.component.Bootstrap${symbol_pound}onInstall() + */ + public void onInstall() throws javax.jbi.JBIException { + //TODO: do required initializaton and resource creation + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component installed."); + } + /** + * default implementation just logs the method call. + * @see javax.jbi.component.Bootstrap${symbol_pound}onUninstall() + */ + public void onUninstall() throws javax.jbi.JBIException { + //TODO: do clean up the resource and other stuff. + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component uninstalled"); + } + /** + * default noop implementation of the cleanup. + * @see javax.jbi.component.Bootstrap${symbol_pound}cleanUp() + */ + public final void cleanUp() throws javax.jbi.JBIException { + + unregisterExtensionMBean(); // unregister extension mbean and remove it + doCleanUp(); // do any other extra cleanup specific to the component installation. + this.getLogger().fine( this.mInstallationContext.getComponentName() + + " Component Installer Cleaned up"); + } + + /** + * create jmx object name for the extension mbean. Extended classes should + * return the component specific installer extension mbean name here. + */ + protected ObjectName createExtensionMBeanName() { + return null; + } + /** + * default implementation that does not have extension mbean return null. + * @see javax.jbi.component.Bootstrap${symbol_pound}getExtensionMBeanName() + */ + public final javax.management.ObjectName getExtensionMBeanName() { + if ( this.mExtensionMBeanName == null ) { + this.mExtensionMBeanName = createExtensionMBeanName(); + } + return this.mExtensionMBeanName; + } + /** + * create mbean implementation for the extension mbean as a StandardMBean. Extended + * classes should return the installer extension mbean implementation as the + * standard mbean. + */ + protected StandardMBean createExtensionMBean() { + return null; + } + /** + * returns the installation extension mbean implementation. + * @return StandardMBean for the extension mbean implementation. + */ + protected final StandardMBean getExtensionMBean() { + if ( this.mExtensionMBeanImpl == null ) { + this.mExtensionMBeanImpl = this.createExtensionMBean(); + } + return this.mExtensionMBeanImpl; + } + /** + * Chance to extended classes to do the component installation specific init. + * Installation context will be initialized before calling this method. So, + * initialize other things if required in this method. + * @throws javax.jbi.JBIException on error + * @see com.sun.jbi.sample.component.common.ComponentInstaller${symbol_pound}init( + * javax.jbi.component.InstallationContext) + */ + protected void doInit() throws JBIException { + this.getLogger().info(this.getInstallationContext().getComponentName() + + " : Component Installer initialized"); + } + /** + * Chance to extended classes to do the component installation specific cleanup. + * ExtensionMbean will be unregistered before calling this method. + * @throws javax.jbi.JBIException on error + * @see com.sun.jbi.sample.component.common.ComponentInstaller${symbol_pound}cleanUp( + * javax.jbi.component.InstallationContext) + */ + protected void doCleanUp() throws JBIException { + this.getLogger().fine(this.getInstallationContext().getComponentName() + + " : Component Installer doCleanUp"); + } + /** + * if there is an extension mbean supported by the component, then register + * it with the mbean server. + */ + protected void registerExtensionMBean() throws JBIException { + // creatre the installation extension mbean's object name + ObjectName mbeanName = this.getExtensionMBeanName(); + // create the extension mbean implemenation if the object name is created. + StandardMBean mbeanImpl = this.getExtensionMBean(); + + if ( mbeanName == null || mbeanImpl == null ) { + this.getLogger().fine(this.getComponentName() + + " Does not have Installation Extension MBean implemenation "); + return; + } + // register with mbean only if object name and implementation are non null + try { + MBeanServer mbServer = this.getInstallationContext().getContext().getMBeanServer(); + mbServer.registerMBean(mbeanImpl, mbeanName); + } catch (Exception e) { + throw new JBIException("Failed to register Installation Extension MBean for " + + this.getComponentName(), e); + } + } + /** + * remove the registered extension mbean from the mbean server. + */ + protected void unregisterExtensionMBean() { + ObjectName mbeanName = this.getExtensionMBeanName(); + if ( mbeanName == null ) { + return; + } + try { + MBeanServer mbServer = this.getInstallationContext().getContext().getMBeanServer(); + mbServer.unregisterMBean(mbeanName); + } catch (Exception e) { + this.getLogger().log(Level.WARNING, + "Failed to unregister Installation extension MBean for " + this.getComponentName(), e); + } + } + /** + * This method is called by the JBI runtime to allow a component to upgrade + * it's workspace and any existing Service Units to match the new version of + * the component. The JBI runtime copies the existing workspace root to the + * new workspace root prior to calling this method, so that the component + * can examine the contents of the workspace root to determine the version + * of the component from which the upgrade is being made. All updates to the + * workspace root are done in-place; in the event of a failure, the JBI + * runtime reverts back to the original workspace root, the original install + * root, and the original Service Unit roots for the component. + * + * Note1: The component must ensure that it never holds open references + * to any files in the workspace root or any of the Service Unit roots upon + * returning from this method. Failure to do so will cause problems when + * the runtime attempts to complete the upgrade processing. + * + * Note2: The installation context that is normally initialized + * by the runtime by calling ${symbol_pound}init method of the javax.jbi.Bootstrap interface + * before install and uninstall will not be called before calling this + * upgrade method. So, installation context can not be used in this method's + * implementation. + * + * Note3: Since there won't be any installation context available, the logger + * that returned from the ${symbol_pound}getLogger method is a default logger created using + * the package name of this class or extended class if the method is overridden + * in the extended class. + * + * @param workspaceRoot the workspace root for the new version of the + * component that will replace the currently installed version. This is + * populated with the contents of the original workspace root and the + * component must update it to match the new version of the component. + * @param serviceUnitRoots a list of directory paths to all of the Service + * Units currently deployed to the component. The component must update all + * of these to match the new version of the component. + * @exception JBIException when there is an error requiring that the upgrade + * be terminated. + */ + public void upgrade(String workspaceRoot, List serviceUnitRoots) + throws javax.jbi.JBIException + { + //TODO: override this method in the extended class to handle the + // workspace root and service unit roots upgrade according to the + // component's requirement. + this.getLogger().fine("Default upgrade implementation. " + + "TODO: Implement workspace root and service unit roots upgrade."); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/ComponentRuntime.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/ComponentRuntime.java new file mode 100644 index 000000000..5c32ce274 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/ComponentRuntime.java @@ -0,0 +1,174 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ComponentRuntime.java + */ +package net.openesb.component.${artifactId}.common; + +import java.util.logging.Logger; +import javax.jbi.component.Component; +import javax.jbi.component.ComponentContext; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.component.ServiceUnitManager; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.servicedesc.ServiceEndpoint; +import org.w3c.dom.Document; +import org.w3c.dom.DocumentFragment; + +/** + * This class implements javax.jbi.component.Component interface which is + * responsible for creating the Component Lifecycle implementation and the + * ServiceUnitManager implementation for the jbi component. + * + * This class makes sure that non null component lifecycle implementation is + * returns by this class or any classes extended from this class which is + * required as a component contract. It also provides default implementation of + * all methods of the Component interface which the extended classes can + * override to add more functionality. + * + * @see javax.jbi.component.Component + * @author chikkala + */ +public class ComponentRuntime implements Component { + /** Component LifeCycle implementation */ + private ComponentLifeCycle mLifeCycle; + /** ServiceUnitManager implementation */ + private ServiceUnitManager mSUManager; + /** default logger*/ + private Logger mDefLogger; + + /** Creates a new instance of ComponentImpl */ + public ComponentRuntime() { + this.mLifeCycle = null; + this.mSUManager = null; + } + /** + * returns the ComponentContext. Any component runtime class extended from + * this class can override this method to return their own reference to the + * ComponentContext. + * @return ComponentContext component context. + */ + public ComponentContext getComponentContext() { + ComponentContext ctx = null; + if ( this.mLifeCycle != null && this.mLifeCycle instanceof BasicComponentLifeCycle ) { + ctx = ((BasicComponentLifeCycle) this.mLifeCycle).getComponentContext(); + } + return ctx; + } + /** + * Returns logger initialized from the component context or a default logger. + * @return Logger + */ + public Logger getLogger() { + Logger logger = null; + if ( this.mLifeCycle != null && this.mLifeCycle instanceof BasicComponentLifeCycle ) { + logger = ((BasicComponentLifeCycle) this.mLifeCycle).getLogger(); + } + // init default logger if required + if ( logger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (logger != null) ? logger : this.mDefLogger; + } + /** + * return the ComponentLifeCycle implementation. if returned null, the + * ComponentLifeCycleImpl will be used as the component lifecycle + * Extended classes can override this method and do their own ComponentLifecyle + * specific creation. + */ + protected ComponentLifeCycle createComponentLifeCycle() { + return new BasicComponentLifeCycle(this); + } + /** + * Get the life cycle control interface for this component. + * + * @return the life cycle control interface for this component + * @see javax.jbi.Component${symbol_pound}getLifeCycle() + */ + public final ComponentLifeCycle getLifeCycle() { + if ( this.mLifeCycle == null ) { + this.mLifeCycle = createComponentLifeCycle(); + if ( this.mLifeCycle == null ) { + this.getLogger().fine("Creating basic component lifecycle implemenation"); + // use the default ComponentLifeCycle Impl if a component + // specific implementation return null in createComponentLifeCycle. + this.mLifeCycle = new BasicComponentLifeCycle(this); + } + } + return this.mLifeCycle; + } + /** + * if this component supports service unit deployment, then return the + * service unit manager, else return null. + * Extended classes can override this method and do their own ServiceUnitManager + * specific creation. + */ + protected ServiceUnitManager createServiceUnitManager() { + return null; + } + /** + * Get the Service Unit manager for this component. + * + * @return the ServiceUnitManager for this component, or + * null if there is none. + * @see javax.jbi.Component${symbol_pound}getServiceUnitManager() + */ + public final ServiceUnitManager getServiceUnitManager() { + if ( this.mSUManager == null ) { + this.mSUManager = createServiceUnitManager(); + } + return this.mSUManager; + } + /** + * Retrieves a DOM representation containing metadata which describes the + * service provided by this component, through the given endpoint. + * + * Default implementation does not support service description. + * + * @see javax.jbi.Component${symbol_pound}getServiceDescription(javax.jbi.servicedesc.ServiceEndpoint) + */ + public Document getServiceDescription(ServiceEndpoint serviceEndpoint) { + return null; + } + /** + * This method is called by JBI to check if this component, in the role of + * provider of the service indicated by the given exchange, can actually + * perform the operation desired. + * + * Default implementation has no policy and allows all exchanges with consumer. + * + * @see javax.jbi.Component${symbol_pound}isExchangeWithProviderOkay( + * javax.jbi.servicedesc.ServiceEndpoint, javax.jbi.messaging.MessageExchange) + */ + public boolean isExchangeWithConsumerOkay( + ServiceEndpoint serviceEndpoint, MessageExchange messageExchange) { + return true; + } + /** + * This method is called by JBI to check if this component, in the role of + * consumer of the service indicated by the given exchange, can actually + * interact with the provider properly. The provider is described by the + * given endpoint and the service description supplied by that endpoint. + * + * Default implementation has no policy and allows all exchanges with provider. + * + * @see javax.jbi.Component${symbol_pound}isExchangeWithProviderOkay( + * javax.jbi.servicedesc.ServiceEndpoint, javax.jbi.messaging.MessageExchange) + */ + public boolean isExchangeWithProviderOkay( + ServiceEndpoint serviceEndpoint, MessageExchange messageExchange) { + return true; + } + /** + * Resolve the given endpoint reference. + * + * Default implementation does not have any XML dialect. So can not resolve the + * endpoint from the document fragment. + * + * @see javax.jbi.Component${symbol_pound}resolveEndpointReference(org.w3c.dom.DocumentFragment) + */ + public ServiceEndpoint resolveEndpointReference(DocumentFragment documentFragment) { + return null; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java new file mode 100644 index 000000000..51c85bc6e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java @@ -0,0 +1,180 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * DefaultMessageExchangeReceiver.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import javax.jbi.JBIException; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; + +/** + * This class implements MessageExchangeReceiver interface. This is a default implementation that + * demonstrates the multi-threaded environment to receive and process message exchanges from the + * delivery channel. It uses a main thread to receive message exchanges from the delivery channel + * and then processes the received message exchanges in a individual threads from the thread pool. + * The controller methods of MessageExchangeReceiver controls the main thread and the thread pool + * execution. + * + * @author chikkala + */ +public class DefaultMessageExchangeReceiver implements MessageExchangeReceiver { + + /** delivery channel accept time out */ + private final static long DC_ACCEPT_TIME_OUT = 3000; // milliseconds + /** receiver thread wait time before polling for messages after woke up **/ + private final static long RECEIVER_WAIT_TIME = 2000; // milliseconds + /** receiver thread wait time before force shutdown */ + private final static long RECEIVER_SHUTDOWN_WAIT_TIME = 10; // seconds + /** handler threads wait time before forced shutdown */ + private final static long HANDLERS_SHUTDOWN_WAIT_TIME = 30; // seconds + /** handler thread pool size */ + private final static int HANDLER_THREAD_POOL_SIZE = 5; + /** receiver thread accept message exchange condition */ + private Boolean mCanAccept = false; + /** receiver thread termination condition */ + private Boolean mContinue = true; + /** receiver thread executor service */ + private ExecutorService mReceiverThreadMgr; + /** handler thread executor service */ + private ExecutorService mHandlerThreadPool; + + /** no default constructor for extended classes */ + public DefaultMessageExchangeReceiver() { + } + /** + * this method is called from the ComponentLifecyle.init method of the AbstractComponentLifecycle + * to initialize the message exchange receiving resources such as threads and thread pools + * throws JBIException on error + */ + public final void initReceiver() throws JBIException { + + this.mHandlerThreadPool = Executors.newFixedThreadPool(HANDLER_THREAD_POOL_SIZE); + this.mReceiverThreadMgr = Executors.newSingleThreadExecutor(); + + this.mReceiverThreadMgr.execute(new Runnable() { + public void run() { + Thread t = Thread.currentThread(); + while ( mContinue ) { + if (mCanAccept) { + receiveAndProcessMessageExchange(); + } else { + try { + t.sleep(RECEIVER_WAIT_TIME); + } catch (InterruptedException interruptException) { + // someone must have interrupted this thread + // do nothing + RuntimeHelper.logDebug("Interrupted the MessageReceiverThread in Sleep"); + } + } + } + } + }); + } + /** + * this method is called from the ComponentLifecyle.shutdown method of the AbstractComponentLifecycle + * to cleanup the message exchange receiving resources such as threads and thread pools. + * throws JBIException on error + */ + public final void shutdownReceiver() throws JBIException { + + synchronized ( mContinue ) { + mContinue = false; + } + boolean terminated = false; + try { + this.mReceiverThreadMgr.shutdown(); + terminated = this.mReceiverThreadMgr.awaitTermination( + RECEIVER_SHUTDOWN_WAIT_TIME, TimeUnit.SECONDS); + } catch (InterruptedException ex) { + RuntimeHelper.logDebug(ex); + } finally { + if ( !terminated ) { + RuntimeHelper.logDebug("Message Receiver not shutdown. Forcing shutdown"); + this.mReceiverThreadMgr.shutdownNow(); + } + } + shutdownHandlers(); + } + /** + * shutdown all the working threads from the thread pool. + */ + private final void shutdownHandlers() throws JBIException { + + boolean terminated = false; + try { + this.mHandlerThreadPool.shutdown(); + terminated = this.mHandlerThreadPool.awaitTermination( + HANDLERS_SHUTDOWN_WAIT_TIME, TimeUnit.SECONDS); + } catch (InterruptedException ex) { + RuntimeHelper.logDebug(ex); + } finally { + if ( !terminated ) { + RuntimeHelper.logDebug("Handler threads not shutdown. Forcing shutdown"); + this.mHandlerThreadPool.shutdownNow(); + } + } + } + /** + * this method is called from the ComponentLifecyle.start method of the AbstractComponentLifecycle + * to start receiving the message exchanges from the delivery channel and process them. + * throws JBIException on error + */ + public final void startProcessing() throws JBIException { + + synchronized ( this.mCanAccept ) { + this.mCanAccept = true; + } + } + /** + * this method is called from the ComponentLifecyle.stop method of the AbstractComponentLifecycle + * to stop receiving the message exchanges from the delivery channel. + * throws JBIException on error + */ + public final void stopProcessing() throws JBIException { + + synchronized ( this.mCanAccept ) { + this.mCanAccept = false; + } + } + + protected MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeHelper.getMessageExchangeSupport(); + } + + private void receiveAndProcessMessageExchange() { + try { + DeliveryChannel channel = RuntimeHelper.getDeliveryChannel(); + if ( channel == null ) { + RuntimeHelper.logDebug("DeliveryChannel Not Opened for receiving messages"); + return; + } + final MessageExchange msgExchange = channel.accept(DC_ACCEPT_TIME_OUT); + if ( msgExchange == null ) { + // delivery channel timeout occurred. do nothing. + // RuntimeHelper.logDebug("DeliveryChannel returned null message exchange from accept"); + return; + } + final ExchangeStatus status = msgExchange.getStatus(); + // process message exchange in a separate thread + this.mHandlerThreadPool.execute(new Runnable() { + public void run() { + getMessageExchangeSupport().fireMessageExchangeReceived(status, msgExchange); + } + }); + + } catch (MessagingException ex) { + RuntimeHelper.logWarning(ex); + ex.printStackTrace(); + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java new file mode 100644 index 000000000..fed6c987d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java @@ -0,0 +1,31 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * MessageExchangeHandler.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; + +/** + * This interface is a Handler to perform message exchanges when the component + * receives the MessageExchange object from the delivery channel. + * Implementation of this interface should implement the processing of + * the active, error, done status of the MessageExchange object according to + * the MEP for which the MessageExchange object is created. + * + * @author chikkala + */ +public interface MessageExchangeHandler { + /** + * this method will be invoked to process the MessageExchange + * object. + * @param msgExchange MessageExchange object to process. + */ + void processMessageExchange(ExchangeStatus status, MessageExchange msgExchange); + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeListener.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeListener.java new file mode 100644 index 000000000..c27c1f221 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeListener.java @@ -0,0 +1,36 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * MessageExchangeListener.java + */ + +package net.openesb.component.${artifactId}.common; + +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; + +/** + * This interface defines the notification mechanism with which the message exchange object received + * from the delivery channel is processed by the interesting parties. A particular service endpoint + * implementation would first register the implementation of this interface with MessageExchangeSupport + * to get the notification of a received message exchange on a particular service endpoint and the + * implementation of the interface would process the message exchange when notified. + * + * When the com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver receives the message exchange + * object, it asks the MessageExchangeSupport to notify the MessageExchangeLister that is registered for the + * received message exchange object to process the message exchange object. + * @see com.sun.jbi.sample.component.common.MessageExchangeSupport + * @see com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @author chikkala + */ +public interface MessageExchangeListener { + /** + * MessageExchangeSupport will call this method to notify the lister implementation that a + * message exchange is received from the delivery channel. + * @param me MessageExchange Object + */ + void messageExchangeReceived(ExchangeStatus status, MessageExchange me); +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java new file mode 100644 index 000000000..607146abd --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java @@ -0,0 +1,47 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * MessageExchangeReceiver.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import javax.jbi.JBIException; + +/** + * This interface provides the methods can controls the receiving and processing of the message + * exchange objects from the delivery channel during the component lifecycle operations. + * The implementation of this interface can use multi-threaded environment to receive and process + * message exchanges from the delivery channel during the component lifecycle. + * @see com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver + * @author chikkala + */ +public interface MessageExchangeReceiver { + /** + * this method is called from the ComponentLifecyle.init method of the AbstractComponentLifecycle + * to initialize the message exchange receiving resources such as threads and thread pools + * throws JBIException on error + */ + void initReceiver() throws JBIException; + /** + * this method is called from the ComponentLifecyle.start method of the AbstractComponentLifecycle + * to start receiving the message exchanges from the delivery channel and process them. + * throws JBIException on error + */ + void startProcessing() throws JBIException; + /** + * this method is called from the ComponentLifecyle.stop method of the AbstractComponentLifecycle + * to stop receiving the message exchanges from the delivery channel. + * throws JBIException on error + */ + void stopProcessing() throws JBIException; + /** + * this method is called from the ComponentLifecyle.shutdown method of the AbstractComponentLifecycle + * to cleanup the message exchange receiving resources such as threads and thread pools. + * throws JBIException on error + */ + void shutdownReceiver() throws JBIException; + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java new file mode 100644 index 000000000..bddf9a8b1 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java @@ -0,0 +1,170 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * MessageExchangeSupport.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessageExchange.Role; +import javax.xml.namespace.QName; + +/** + * This class supports the registering and unregistering MessageExchangeListeners and the + * MessageExchangeHandlers that can be used to process the received message exchange from a + * delivery channel. A global reference to this class will be created in RuntimeContext object to + * provide access to this class from any where in the component runtime. + * + * A ProviderEndpoint or ConsumerEndpoint interested in a MessageExchange received from a delivery + * channel for a particular service endpoint will register the MessageExchangeListener with this + * class. The DefaultMessageExchangeReceiver when received a message exchange object from the delivery + * channel uses MessageExchangeSupport.processMessageExchange method to notify the registered listener. + * + * The MessageExchangeListener implementation ( ProviderEndpoint or ConsumerEndpoint ) while processing + * received message ( messageExchangeReceived()) will create and register the message exchange handlers + * to process the message exchange. + * + * @see RuntimeContext${symbol_pound}getMessageExchangeSupport + * @see RuntimeHelper${symbol_pound}getMessageExchangeSupport + * @see DefaultMessageExchangeReceiver${symbol_pound}receiveAndProcessMessageExchange + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @author chikkala + */ +public class MessageExchangeSupport { + /** listener map to notify a message exchange received event */ + private Map mListeners; + /** handlers that can process the message exchange */ + private Map mHandlers; + /** Creates a new instance of MessageExchangeSupport */ + public MessageExchangeSupport() { + this.mListeners = Collections.synchronizedMap(new HashMap()); + this.mHandlers = Collections.synchronizedMap(new HashMap()); + } + /** + * generates key that will be used to store the MessageExchangeListener objects. + * @param serviceName QName of the service + * @param endpointName endpoint name of the service. + */ + public String createListenerKey(Role role, QName interfaceName, QName serviceName, String endpointName) { + + StringBuffer strBuff = new StringBuffer(); + strBuff.append(interfaceName).append("+"); + strBuff.append(serviceName).append("+"); + strBuff.append(endpointName).append("+"); + String roleType = null; + if ( Role.CONSUMER.equals(role) ) { + roleType = "CONSUMER"; + } else if ( Role.PROVIDER.equals(role) ) { + roleType = "PROVIDER"; + } + strBuff.append(roleType); + return strBuff.toString(); + } + /** + * adds message exchange listener who are interested in receiving the notification when the + * message exchange is received from delivery channel. The listener can be registered with the + * following combination of the parameters: (role,interfaceName,serviceName, endpointName), + * (role,interfaceName,null, null), (role, null,serviceName, endpointName), (role, null,serviceName, null) + * + * @param role role of the message exchange listener PROVIDER or CONSUMER - can not be null. + * @param interfaceName QName of the interface ( protType ) - can be null if the serviceName is not null + * @param serviceName QName of the service - can be null if interfaceName is not null. + * @param endpointName endpoint name of the service. - can be null if the serviceName is not null. + * @param listener MessageExchangeListener object + */ + public synchronized void addMessageExchangeListener(Role role, QName interfaceName, QName serviceName, String endpointName, MessageExchangeListener listener) { + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + this.mListeners.put(key, listener); + } + /** + * removes any message exchange listener registered for the service endpoint specified by the serviceName and + * endpoint name. + * @param serviceName QName of the service + * @param endpointName endpoint name of the service. + */ + public synchronized void removeMessageExchangeListener(Role role, QName interfaceName, QName serviceName, String endpointName) { + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + MessageExchangeListener listener = this.mListeners.remove(key); + if ( listener == null ) { + RuntimeHelper.getLogger().fine("No message exchange listener removed with key " + key); + } + } + /** + * finds the MessageExchangeListner registers for the endpoint for which the message exchange is + * received and call the method on the listener + */ + public boolean fireMessageExchangeReceived(ExchangeStatus status, MessageExchange me) { + boolean notified = false; + Role role = me.getRole(); + QName interfaceName = me.getInterfaceName(); + QName serviceName = me.getEndpoint().getServiceName(); + String endpointName = me.getEndpoint().getEndpointName(); + // lookup with complete service description ( role + interface + service + endpoint ) + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + MessageExchangeListener listener = this.mListeners.get(key); + + if ( listener == null ) { // lookup with role+interface name + key = createListenerKey(role, interfaceName, null, null); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { // lookup with role + serviceName + endpointName + key = createListenerKey(role, null, serviceName, endpointName); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { // lookup with with role + serviceName + key = createListenerKey(role, null, serviceName, null); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { + RuntimeHelper.getLogger().fine("Could not find listener for message exchange" + me); + notified = false; + } else { + listener.messageExchangeReceived(status,me); + notified = true; + } + return notified; + } + /** + * registers the MessageExchangeHandler implementation against the message exchange id. + * @param me MessageExchange for which the handler need to be assigned + * @param handler MessageExchangeHandler implementation that will be registers. + */ + public synchronized void addMessageExchangeHandler(MessageExchange me, MessageExchangeHandler handler) { + this.mHandlers.put(me.getExchangeId(), handler); + } + /** + * removes the MessageExchangeHandler for the particular message exchange object + */ + public synchronized void removeMessageExchangeHandler(MessageExchange me) { + MessageExchangeHandler handler = this.mHandlers.remove(me.getExchangeId()); + if ( handler == null ) { + RuntimeHelper.getLogger().fine("No MessageExchangeHandler found for removing " + me.getExchangeId()); + } + } + /** + * looks up the registered message exchange handler for the message exchange object + * @param me MessageExchangeHandler. + */ + public synchronized MessageExchangeHandler findMessageExchangeHandler(MessageExchange me) { + return this.mHandlers.get(me.getExchangeId()); + } + /** + * looks up the registered message exchange handler for the message exchange object with Id + * @param exchangeId message exchange object's id + */ + public synchronized MessageExchangeHandler findMessageExchangeHandler(String exchangeId) { + return this.mHandlers.get(exchangeId); + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeContext.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeContext.java new file mode 100644 index 000000000..be75c7b7d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeContext.java @@ -0,0 +1,176 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * RuntimeContext.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import java.util.logging.Logger; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; + +/** + * This class is global context for all the component runtime to store and + * retrieve the information that should be available anywhere in the component runtime. + * + * Each instance variable of this class will be initialized at various points of the + * component runtime using setter methods on this class. + * + * The two important objects that will be initialized and available from this context are + * ComponentContext and the opened DeliveryChannel objects both of which will be set from the + * implementation {@link BasicComponentLifeCycle}. + * + * Note that the ComponentContext from this global context will not be available until + * the jbi framework calls the init method of the ComponentLifeCycle of the component and + * then intern the implementation of the init method sets the context. + * + * @see BasicComponentLifeCycle${symbol_pound}initGlobalContext + * @see BasicComponentLifeCycle${symbol_pound}openDeliveryChannel + * @see BasicComponentLifeCycle${symbol_pound}closeDeliveryChannel + * @author chikkala + */ +public final class RuntimeContext { + /** RuntimeContext singleton instance */ + private static RuntimeContext sRuntimeContext; + /** default logger*/ + private Logger mDefLogger; + /** Logger object. */ + private Logger mLogger; + /** Holds value of property ComponentContext. */ + private ComponentContext mComponentContext; + /** Holds value of property DeliveryChannel. */ + private DeliveryChannel mDeliveryChannel; + /** MessageExchange processing support **/ + private MessageExchangeSupport mMESupport; + + /** outside code can not instantiate RuntimeContext */ + private RuntimeContext() { + } + /** + * @return RuntimeContext instance. + */ + public static RuntimeContext getInstance() { + if ( sRuntimeContext == null ) { + synchronized (RuntimeContext.class) { + if ( sRuntimeContext == null ) { + sRuntimeContext = new RuntimeContext(); + } + } + } + return sRuntimeContext; + } + /** + * Getter for to obtaining ComponentContext from any where in the component runtime. + * @return ComponentContext. + */ + public ComponentContext getComponentContext() { + return this.mComponentContext; + } + /** + * Sets the Component context reference in Runtime context for global access + * any class in the component runtime. + * com.sun.jbi.sample.component.common.AbstractComponentLifeCycle${symbol_pound}initContext + * method implementation should call this method to set the global context. + * see com.sun.jbi.sample.component.common.DefaultComponentLifeCycle${symbol_pound}initContext + * for details. + * @param componentContext New value of property ComponentContext. + * @see BasicComponentLifeCycle${symbol_pound}initGlobalContext + */ + public void setComponentContext(ComponentContext componentContext) { + if ( this.mComponentContext != null ) { + (new IllegalStateException("Component Context already " + + "initialized in RuntimeContext")).printStackTrace(); + } + this.mComponentContext = componentContext; + } + /** + * Getter for obtaining opened delivery channel from any where in the component runtime. + * @return DeliveryChannel. + */ + public DeliveryChannel getDeliveryChannel() { + return this.mDeliveryChannel; + } + /** + * Sets the opened delivery channel reference in Runtime context for global access + * any class in the component runtime. + * com.sun.jbi.sample.component.common.AbstractComponentLifeCycle${symbol_pound}initContext + * method implementation should call this method to set the global context. + * see com.sun.jbi.sample.component.common.DefaultComponentLifeCycle${symbol_pound}initContext + * for details. + * + * @param componentContext New value of property ComponentContext. + */ + public void setDeliveryChannel(DeliveryChannel deliveryChannel) { + if ( deliveryChannel != null && this.mDeliveryChannel != null ) { + (new IllegalStateException("Delivery Channel already " + + "initialized in RuntimeContext")).printStackTrace(); + } + this.mDeliveryChannel = deliveryChannel; + } + /** + * Sets the logger. + * + * @param name name for the Logger. + * @param resourceBundle resource bundle for the logger. can be null. + */ + public void setLogger(String name, String resourceBundle) { + + if (this.mComponentContext != null) { + // get the logger from component context if the component context is not null + try { + this.mLogger = this.mComponentContext.getLogger(name, resourceBundle); + } catch (Exception ex) { + ex.printStackTrace(); + } + } else { + this.mDefLogger = Logger.getLogger(name, resourceBundle); + } + } + /** + * Returns the logger. + * + * @return Logger + */ + public Logger getLogger() { + + // try init logger + if (this.mLogger == null && this.mComponentContext != null ) { + try { + this.mLogger = + this.mComponentContext.getLogger(this.getClass().getName(), null); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + // init default logger if required + if ( this.mLogger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (this.mLogger != null) ? this.mLogger : this.mDefLogger; + } + /** + * Returns the Component Name if the ComponentContext is set. else null + * @return component name + */ + public String getComponentName() { + String componentName = null; + if (this.mComponentContext != null) { + componentName = this.mComponentContext.getComponentName(); + } + return componentName; + } + /** + * Global MessageExchangeSupport reference. Various classes in the common + * component runtime would use this method to obtain the MessageExchangeSupport + * for processing message exchange objects received from delivery channel. + */ + public MessageExchangeSupport getMessageExchangeSupport() { + if ( this.mMESupport == null ) { + this.mMESupport = new MessageExchangeSupport(); + } + return this.mMESupport; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeHelper.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeHelper.java new file mode 100644 index 000000000..f12c2b2f4 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeHelper.java @@ -0,0 +1,360 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * RuntimeHelper.java + */ + +package net.openesb.component.${artifactId}.common; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stream.StreamResult; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * This is a helper class that have bunch of methods for xml processing. + * @author chikkala + */ +public class RuntimeHelper { + + public static Logger getLogger() { + return RuntimeContext.getInstance().getLogger(); + } + + public static void logWarning(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.WARNING, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().warning(logObj.toString()); + } + } + + public static void logError(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.SEVERE, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().severe(logObj.toString()); + } + } + + public static void logDebug(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.FINER, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().finer(logObj.toString()); + } + } + + public static String getComponentName() { + return RuntimeContext.getInstance().getComponentName(); + } + public static ComponentContext getComponentContext() { + return RuntimeContext.getInstance().getComponentContext(); + } + public static DeliveryChannel getDeliveryChannel() { + return RuntimeContext.getInstance().getDeliveryChannel(); + } + + public static MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeContext.getInstance().getMessageExchangeSupport(); + } + + /** + * return the DOM Document + * @param xmlReader Reader + * @return dom document + * @throws Exception on parser exception or any other exception + */ + public static Document buildDOMDocument(Reader xmlReader) throws Exception { + InputSource xmlSource = new InputSource(xmlReader); + return buildDOMDocument(xmlSource); + } + /** + * return the DOM Document + * @param xmlReader Reader + * @return dom document + * @throws Exception on parser exception or any other exception + */ + public static Document buildDOMDocument(InputSource xmlSource) throws Exception { + Document xmlDoc = null; + DocumentBuilderFactory docBuilderFactory = + DocumentBuilderFactory.newInstance(); + docBuilderFactory.setValidating(false); + docBuilderFactory.setNamespaceAware(true); + DocumentBuilder docBuilder = + docBuilderFactory.newDocumentBuilder(); + docBuilder.setErrorHandler( new DefaultHandler() { + public void fatalError(SAXParseException e) + throws SAXException { + throw new SAXException(e.getMessage()); + } + }); + + docBuilder.setEntityResolver(new EntityResolver() { + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException, IOException { + StringReader reader = + new StringReader(""); // NOI18N + InputSource source = new InputSource(reader); + source.setPublicId(publicId); + source.setSystemId(systemId); + return source; + } + }); + + xmlDoc = docBuilder.parse(xmlSource); + + return xmlDoc; + } + /** + * reads xml text from DOMSource to StringBuffer + */ + public static StringBuffer readFromDOMSource(DOMSource domSource) { + + StringWriter writer = new StringWriter(); + + TransformerFactory tFactory = TransformerFactory.newInstance(); + Transformer trans = null; + try { + trans = tFactory.newTransformer(); + trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, + "yes"); + trans.setOutputProperty(OutputKeys.INDENT, "yes"); + StreamResult result = new StreamResult(writer); + trans.transform(domSource, result); + } catch (TransformerConfigurationException ex) { + ex.printStackTrace(); + } catch (TransformerException ex) { + ex.printStackTrace(); + } + + return writer.getBuffer(); + } + /** + * reads the xml text from InputSource into a StringBuffer + */ + public static StringBuffer readFromInputSource(InputSource inSource) { + + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + InputStream inStream = inSource.getByteStream(); + Reader reader = inSource.getCharacterStream(); + if ( reader == null ) { + reader = new InputStreamReader(inStream); + } + BufferedReader buff = new BufferedReader(reader); + try { + + for ( String line = null; (line = buff.readLine()) != null ; ) { + out.println(line); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + + return writer.getBuffer(); + } + /** + * reads xml from from DOM, SAX or Stream Source into a string buffer + */ + public static StringBuffer readFromSource(Source source) { + if ( source instanceof DOMSource ) { + return readFromDOMSource((DOMSource)source); + } else { + InputSource inSource = SAXSource.sourceToInputSource(source); + if ( inSource != null ) { + return readFromInputSource(inSource); + } else { + return null; + } + } + } + /** + * creates a DOMSource from the xml text read from the reader. + */ + public static DOMSource createDOMSource(Reader xmlReader) { + Document doc = null; + try { + doc = buildDOMDocument(xmlReader); + } catch (Exception ex) { + ex.printStackTrace(); + } + return new DOMSource(doc); + } + /** + * creates a DOMSource from any source. If the source itself is DOMSource, + * the source is returned as it is as DOMSource. + */ + public static DOMSource sourceToDOMSource(Source source) { + if ( source instanceof DOMSource) { + return (DOMSource) source; + } + InputSource xmlSource = SAXSource.sourceToInputSource(source); + Document doc = null; + try { + doc = buildDOMDocument(xmlSource); + } catch (Exception ex) { + ex.printStackTrace(); + } + return new DOMSource(doc); + } + /** + * converts the ex stracktrace to string. + */ + public static StringBuffer getExceptionStackTrace(Exception ex) { + StringWriter strWriter = new StringWriter(); + if ( ex != null ) { + PrintWriter out = new PrintWriter(strWriter); + ex.printStackTrace(out); + } + return strWriter.getBuffer(); + } + /** + * may be used to set the exception as fault content. + */ + public static String getExceptionAsXmlText(Exception ex) { + String message = replaceXmlEscapeCharsToEntityRefereces(ex.getMessage()); + String stackTrace = replaceXmlEscapeCharsToEntityRefereces( + getExceptionStackTrace(ex).toString()); + String exXmlText = + "" + + "" + message + "" + + "" + stackTrace + "" + + "" ; + return exXmlText; + } + + /** + * may be used to set the exception as fault content. + */ + public static String getExceptionAsText(Exception ex) { + String message = replaceXmlEscapeCharsToEntityRefereces(ex.getMessage()); + String stackTrace = replaceXmlEscapeCharsToEntityRefereces( + getExceptionStackTrace(ex).toString()); + StringBuffer buff = new StringBuffer(); + buff.append(message); + buff.append(System.getProperty("line.separator", "${symbol_escape}n")); + buff.append(stackTrace); + return buff.toString(); + } + + + /** + * For attribute values which denote a QName, i.e. include a namespace prefix, + * resolve the value into a QName. + * If a namespace can not be resolved, it is set to empty - it does not + * result in an exception + * @param attrValue the string value of the attribute + * @param element the element the attribute belongs to + */ + public static QName resolveAttrQName(String attrValue, Element element) { + int aColonLoc = attrValue.indexOf(":"); + String aLocalName = attrValue; + String aPrefix = null; + String aNS = null; + if (aColonLoc > -1) { + aPrefix = attrValue.substring(0, aColonLoc); + aLocalName = attrValue.substring(aColonLoc + 1); + + // Traverse up the hierarchy until a namespace definition is found + // or the top of the document is reached. + Node currNode = element; + while ((aNS == null || aNS.equals("")) && currNode != null) { + if (currNode.getNodeType() == Node.ELEMENT_NODE) { + aNS = ((Element) currNode).getAttribute("xmlns:" + aPrefix); + } + currNode = currNode.getParentNode(); + } + } + + QName qName = new QName(aNS, aLocalName, aPrefix); + + return qName; + } + + /** + * replaces the xml entity references with the xml escape chars + * @param xmlString Text with the xml escape chars + * @param Text with the xml entity references + */ + public static String replaceXmlEscapeCharsToEntityRefereces(String xmlString) { + if ( xmlString == null ) { + return xmlString; + } + + // just convert < , > and & only + StringBuffer sbuff = new StringBuffer(2 * xmlString.length()); + for ( int i = 0; i < xmlString.length(); ++i ) { + switch ( xmlString.charAt(i) ) { + case '&': sbuff.append("&"); + break; + case '<': sbuff.append("<"); + break; + case '>': sbuff.append(">"); + break; + default: sbuff.append( xmlString.charAt(i) ); + } + } + return sbuff.toString(); + } + + /** + * return Element node from a document node or non document. Use to extract + * the message root element. + * @root node from which the Element node will be extracted. + * @return Element node. + */ + public static Element getElement(Node root) { + Element msgEl = null; + if ( root instanceof Document) { + msgEl = ((Document)root).getDocumentElement(); + } else if (root instanceof Element) { + msgEl = (Element)root; + } else { + NodeList nodeList = root.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if ( node instanceof Element ) { + msgEl = (Element) node; + break; + } + } + } + return msgEl; + } + + public static Element getElement(DOMSource domSource) { + return getElement(domSource.getNode()); + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java new file mode 100644 index 000000000..fd0fc4f79 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java @@ -0,0 +1,312 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractServiceUnitManager.java + * + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.component.ServiceUnitManager; +import javax.jbi.management.DeploymentException; + +/** + * This is an abstract class that implements {@link javax.jbi.component.ServiceUnitManager} to provide a + * service unit deployment support for the component. The implementation supported by this service + * unit manager and related classes in this package provides WSDL1.1 based service unit deployment + * in the component. + * + * @see javax.jbi.component.ServiceUnitManager + * @see ServiceUnit + * + * @author chikkala + */ +public abstract class AbstractServiceUnitManager implements ServiceUnitManager { + + /** Map of ServiceUnit Name to the ServiceUnit Object for all the service units + * deployed in the component */ + private Map mSUMap; + + /** Creates a new instance of AbstractSUManager */ + protected AbstractServiceUnitManager() { + this.mSUMap = Collections.synchronizedMap(new HashMap()); + } + /** returns the component name + * @return component name. + */ + protected abstract String getComponentName(); + /** + * @return Logger + */ + protected abstract Logger getLogger(); + /** + * returns the creation of the ServiceUnit implementation specific to the service unit deployment + * for the component. + * @param suName service unit name + * @param suRootPath service unit root path + * @param concrete implementation of the ServiceUnit class. + */ + protected abstract ServiceUnit createServiceUnit(String suName, String suRootPath) + throws DeploymentException; + /** + * returns the service unit object deployed by the specified name. or null if not deployed. + * @param suName service unit name to look for + * @param ServiceUnit object for the suName. or null if not present. + */ + private ServiceUnit getServiceUnit(String suName) { + return this.mSUMap.get(suName); + } + /** + * lookup for the deployed service unit. If not there, throws a deployment exception. + * @param suName service unit name + * @return ServiceUnit object + * @throws DeploymentException if the service unit is not present. + */ + private ServiceUnit findServiceUnit(String suName) throws DeploymentException { + ServiceUnit serviceUnit = getServiceUnit(suName); + if ( serviceUnit == null ) { + throw new DeploymentException("Service unit " + suName + " does not exist"); + } + return serviceUnit; + } + /** + * add the service unit object to the list of deployed service units. if there is already a + * service unit present with the name, throws a deployment exception. + * @param su service unit to add + * @return ServiceUnit object that is added. + * @throws DeploymentException if the service unit already present. + */ + private ServiceUnit addServiceUnit(ServiceUnit su) throws DeploymentException { + String suName = su.getName(); + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU != null ) { + throw new DeploymentException("Service unit " + suName + "already exists"); + } + this.mSUMap.put(suName, su); + return su; + } + /** + * removes service unit object from the list of deployed service units. if there is no + * service unit present with the name, throws a deployment exception. + * @param su service unit to add + * @return ServiceUnit object that is being removed. + * @throws DeploymentException if the service unit already present. + */ + private ServiceUnit removeServiceUnit(ServiceUnit su) throws DeploymentException { + String suName = su.getName(); + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU == null ) { + throw new DeploymentException("Service unit " + suName + " does not exist"); + } + return this.mSUMap.remove(suName); + } + /** + * creates the concrete service unit implementation and calls the load method on it to initialize + * the created service unit. + * @param suName service unit name to create + * @param suRootPath service unit root path. + * @return ServiceUnit that is created and loaded. + */ + private ServiceUnit loadServiceUnit(String suName, String suRootPath) throws DeploymentException { + ServiceUnit serviceUnit = createServiceUnit(suName, suRootPath); + serviceUnit.doLoad(); + return serviceUnit; + } + /** + * deploys a service unit. it creates and loads the service unit object for the suName and then call + * doDeploy on the service unit and adds it to the deployed service unit list + * @return result as jbi management xml + * @throws DeploymentException if there is an error deploying. + */ + private synchronized String deployServiceUnit(String suName, String suRootPath) throws DeploymentException { + String result = suName; + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU != null ) { + throw new DeploymentException("Service unit " + suName + "already exists"); + } + ServiceUnit serviceUnit = loadServiceUnit(suName, suRootPath); + serviceUnit.doDeploy(); + addServiceUnit(serviceUnit); + return result; + } + /** + * Deploy a Service Unit to the component. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}deploy(String, String); + */ + public final String deploy(String suName, String suRootPath) throws DeploymentException { + this.getLogger().fine("Deploying service unit " + suName + " with suRootPath " + suRootPath); + String compName = this.getComponentName(); + boolean isSuccess = true; + String mainMsg = "Successfully deployed service unit " + suName; + Exception errEx = null; + try { + deployServiceUnit(suName, suRootPath); + } catch (Exception ex) { + isSuccess = false; + errEx = ex; + mainMsg = "Failed to deploy service unit " + suName ; + this.getLogger().log(Level.FINE, mainMsg, ex); + } + return createComponentTaskResultXML(compName, "deployTask", isSuccess, mainMsg, errEx); + } + + /** + * undeploys the service unit. it looks up the existing deployed service unit and call doUndeploy + * on it and then removes from the deployed service unit list. + */ + private synchronized String undeployServiceUnit(String suName, String suRootPath) throws DeploymentException { + String result = suName; + ServiceUnit serviceUnit = findServiceUnit(suName); + serviceUnit.doUndeploy(); + removeServiceUnit(serviceUnit); + return result; + } + /** + * Undeploy a service unit from the component. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}undeploy(String, String); + */ + public final String undeploy(String suName, String suRootPath) throws DeploymentException { + this.getLogger().fine("Undeploying service unit " + suName + " with suRootPath " + suRootPath); + String compName = this.getComponentName(); + boolean isSuccess = true; + String mainMsg = "Successfully undeployed service unit " + suName; + Exception errEx = null; + try { + undeployServiceUnit(suName, suRootPath); + } catch (Exception ex) { + isSuccess = false; + errEx = ex; + mainMsg = "Failed to undeploy service unit " + suName ; + this.getLogger().log(Level.FINE, mainMsg, errEx); + } + return createComponentTaskResultXML(compName, "undeployTask", isSuccess, mainMsg, errEx); + } + /** + * Initialize the given deployed service unit. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}init(String, String); */ + public final void init(String suName, String suRootPath) + throws DeploymentException { + this.getLogger().fine("Initializing service unit " + suName + " with suRootPath " + suRootPath); + String result = suName; + ServiceUnit serviceUnit = getServiceUnit(suName); + if ( serviceUnit == null ) { // if the service unit not exists, create and add + serviceUnit = loadServiceUnit(suName, suRootPath); // create and load service unit + addServiceUnit(serviceUnit); // add service unit to existing service units + } + serviceUnit.doInit(); // Do Service unit initialization tasks + this.getLogger().fine("Service unit initialized:" + suName); + } + /** + * Shut down the deployment. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}shutdown(String); + */ + public final void shutDown(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doShutdown(); // Do Service unit shutdown tasks + this.getLogger().fine("Service unit shut down:" + suName); + } + /** + * Start the deployed service unit. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}start(String); + */ + public final void start(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doStart(); // Do service unit start tasks. + this.getLogger().fine("Service unit started:" + suName ); + } + /** + * Stop the deployed service unit. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}stop(String); + */ + public final void stop(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doStop(); // do service unit stop tasks + this.getLogger().fine("Service unit stopped: " + suName + " stopped."); + } + + /** + * helper method to create result message as jbi management message xml. + * @param componentName name of the component for this xml. + * @param taskId task id + * @param isSuccess true to format a success result, false to format a failed result. + * @param mainMsg main result message + * @param errEx Exception, null if there is no exception in failure message. + * @return XML string. + */ + protected static String createComponentTaskResultXML( + String componentName, String taskId, boolean isSuccess, String mainMsg, Exception errEx ) { + + String exMsgXml = getComponentTaskResultExceptionXML(errEx); + String mainMsgXmlEsc = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces(mainMsg); + String taskResult = isSuccess ? "SUCCESS" : "FAILED"; + String msgType = isSuccess ? "INFO" : "ERROR"; + + String xmlResult = + "" + + " " + componentName + "" + + " " + + " " + + " " + taskId + "" + + " " + taskResult + "" + + " " + msgType + "" + + " " + + " " + + " SU_MGR_MSG_ID" + + " " + mainMsgXmlEsc + "" + + " " + + " " + + exMsgXml + + " " + + " " + + ""; + + return xmlResult; + } + /** + * converts the exception to the jbi management message xml chunk. + */ + private static String getComponentTaskResultExceptionXML(Exception errEx) { + StringBuffer exMsgBuff = new StringBuffer(); + if ( errEx == null ) { + return exMsgBuff.toString(); // empty string. + } + + List exList = new ArrayList(); + int exLevel = 0; + for ( Throwable cause = errEx ; cause != null ; cause = cause.getCause() ) { + String causeMsg = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces( + cause.getMessage()); + StringWriter stBuff = new StringWriter(); + PrintWriter stOut = new PrintWriter(stBuff); + StackTraceElement[] stList = cause.getStackTrace(); + for (StackTraceElement stEl : stList) { + stOut.println(stEl.toString()); + } + stOut.close(); + String causeStackTrace = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces( + stBuff.getBuffer().toString()); + + exMsgBuff.append(""); + exMsgBuff.append(" " + exLevel + ""); + exMsgBuff.append(" " + "SU_MGR_EXP_ID"); + exMsgBuff.append(" " + causeMsg + ""); + exMsgBuff.append(" "); + exMsgBuff.append(" " + causeStackTrace + ""); + exMsgBuff.append(""); + ++exLevel; + } + + return exMsgBuff.toString(); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java new file mode 100644 index 000000000..e9537ca9e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java @@ -0,0 +1,208 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ConsumerEndpoint.java + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import javax.jbi.JBIException; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.InOnly; +import javax.jbi.messaging.InOut; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.messaging.MessageExchangeFactory; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +/** + * This class extends from Endpoint class and implements lifecycle methods functionality required for the + * endpoint for a service consumer. {@link ServiceUnit${symbol_pound}createConsumerEndpoint} creates the object of this + * type to implement the service consumer functionality. + * + * @see ServiceUnit${symbol_pound}createConsumerEndpoint + * @author chikkala + */ + +public class ConsumerEndpoint extends Endpoint { + /** + * This constructor initializes the endpoint with CONSUMER role and makes sure that the service + * description passed to it is of consumer description. + */ + protected ConsumerEndpoint(SUDescriptor.Consumes consumes, Definition wsdlDef, ServiceUnit su) { + super(Role.CONSUMER, consumes, wsdlDef, su); + } + /** + * constructor that does not need service unit information. useful for creating the endpoint for + * static services provided by the component. + */ + protected ConsumerEndpoint(SUDescriptor.Consumes consumes, Definition wsdlDef) { + this(consumes, wsdlDef, null); + } + public final void init() throws JBIException { + getLogger().fine("ConsumerEndpoint: init called"); + doInit(); //1. initialize the endpiont resources + addMessageExchangeListener(); //2. register message exchange linster. + } + public final void activate() throws JBIException { + getLogger().fine("ConsumerEndpoint: activate called"); + //1. do common ativation tasks. + doActivate(); //2. do any other activation related tasks. + } + + public final void deactivate() throws JBIException { + getLogger().fine("ConsumerEndpoint: deactivate called"); + //1. do common deactivation tasks. + doDeactivate(); //2. do any other deactivation related tasks. + } + + public final void clean() throws JBIException { + getLogger().fine("ConsumerEndpoint: clean called"); + removeMessageExchangeListener(); //1. remove message exchange listener + doClean(); //2. clean up any other resources. + } + + protected void doInit() throws JBIException { + //NOOP + } + protected void doActivate() throws JBIException { + //NOOP + } + protected void doDeactivate() throws JBIException { + //NOOP + } + protected void doClean() throws JBIException { + //NOOP + } + + /** + * helper method to find the active ServiceEndpiont for the service described with the + * serviceDescriptor. This method looks for the Active ServiceEndpoint using interface or + * service name or service name and the endpoint name. + */ + public ServiceEndpoint findServiceEndpoint() { + + QName serviceType = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + + ServiceEndpoint [] refs = null; + ServiceEndpoint serviceEndpoint = null; + ComponentContext compContext = this.getComponentContext(); + + if ( compContext == null ) { + this.getLogger().info("Null Component context. Can not find ServiceEndpoint"); + return null; + } + // lookup ServiceEndpiont with concrete service(serice qname + endpoint name). + if ( serviceName != null && endpointName != null ) { + this.getLogger().info("Looking for ServiceEndpoint with:" + + " ServiceName: " + serviceName + " EndpointName: " + endpointName); + serviceEndpoint = compContext.getEndpoint(serviceName, endpointName); + } + // else lookup ServiceEndpiont with Service Name + if ( serviceEndpoint == null && serviceName != null && endpointName == null) { + this.getLogger().info("Looking for ServiceEndpoint with Service name: " + serviceName); + refs = compContext.getEndpointsForService(serviceName); + if ( refs != null && refs.length > 0 ) { + serviceEndpoint = refs[0]; + } + } + // else lookup ServiceEndpont with serviceType + if ( serviceEndpoint == null && serviceType != null && + serviceName == null && endpointName == null) { + this.getLogger().info("Looking for ServiceEndpoint with Service type: " + serviceType); + refs = compContext.getEndpoints(serviceType); + if ( refs != null && refs.length > 0 ) { + serviceEndpoint = refs[0]; + } + } + + return serviceEndpoint; + } + + /** + * this method creates a InOutMessageExchange Object and sets the required + * data on the MessageExchange object including the create and set the Normalized + * message object to hold the input message on the MessageExchange object. + */ + public InOut createInOutMessageExchange(QName operation) + throws MessagingException, JBIException { + + ServiceEndpoint serviceEndpoint = null; + // find a ServiceEndpoint activated by the Service Providers for this service + serviceEndpoint = findServiceEndpoint(); + + if ( serviceEndpoint == null ) { + // if not found a activated ServiceEndpoint for this service, throw exception. + throw new JBIException("Can not find an Active ServiceEndpoint for ${symbol_escape}n" + this.getService()); + } else { + this.setServiceEndpoint(serviceEndpoint); + } + + InOut inOutME = null; + DeliveryChannel channel = this.getDeliveryChannel(); + // create message exchange factory for the endpiont + MessageExchangeFactory factory = channel.createExchangeFactory(serviceEndpoint); + // create INOUT Message Exchange + inOutME = factory.createInOutExchange(); + // set operation + inOutME.setOperation(operation); + // set interface if that is not set + if ( inOutME.getInterfaceName() == null ) { + inOutME.setInterfaceName(this.getService().getInterface()); + } + // create IN Nomralized Message + NormalizedMessage inMsg = inOutME.createMessage(); + // set IN Normalized message on message exchange + inOutME.setInMessage(inMsg); + + return inOutME; + } + + /** + * this method creates a InOnlyMessageExchange Object and sets the required + * data on the MessageExchange object including the create and set the Normalized + * message object to hold the input message on the MessageExchange object. + */ + public InOnly createInOnlyMessageExchange(QName operation) + throws MessagingException, JBIException { + + ServiceEndpoint serviceEndpoint = null; + // find a ServiceEndpoint activated by the Service Providers for this service + serviceEndpoint = findServiceEndpoint(); + + if ( serviceEndpoint == null ) { + // if not found a activated ServiceEndpoint for this service, throw exception. + throw new JBIException("Can not find an Active ServiceEndpoint for ${symbol_escape}n" + this.getService()); + } else { + this.setServiceEndpoint(serviceEndpoint); + } + + InOnly inOnlyME = null; + DeliveryChannel channel = this.getDeliveryChannel(); + // create message exchange factory for the endpiont + MessageExchangeFactory factory = channel.createExchangeFactory(serviceEndpoint); + // create INOUT Message Exchange + inOnlyME = factory.createInOnlyExchange(); + // set operation + inOnlyME.setOperation(operation); + // set interface if that is not set + if ( inOnlyME.getInterfaceName() == null ) { + inOnlyME.setInterfaceName(this.getService().getInterface()); + } + // create IN Nomralized Message + NormalizedMessage inMsg = inOnlyME.createMessage(); + // set IN Normalized message on message exchange + inOnlyME.setInMessage(inMsg); + + return inOnlyME; + } + + +} \ No newline at end of file diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/Endpoint.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/Endpoint.java new file mode 100644 index 000000000..3aac0f8e2 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/Endpoint.java @@ -0,0 +1,289 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * Endpoint.java + * + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.MessageExchangeHandler; +import net.openesb.component.${artifactId}.common.MessageExchangeListener; +import net.openesb.component.${artifactId}.common.MessageExchangeSupport; +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.xml.namespace.QName; + +/** + * This is an abstract class that represents the Endpoint defined for service provisioning or + * consumption in a jbi component. It stores the required service description ( wsdl definition, + * role, service unit to which it belongs etc) and defines the lifecycle operations {@link ${symbol_pound}init}, + * {@link ${symbol_pound}activate}, {@link ${symbol_pound}deactivate}, {@link ${symbol_pound}clean} to control a service endpoint that + * provides or consumes the service. + *

+ * Extended classes implement the abstract methods defined in this class to implement the endpoint + * functionality by providing the functionality to process the deployment artifacts specific to this + * endpoint, configure the endpoint to send/receive messages to/from delivery channel and process them + * according to the specific service implementation. + * + * @author chikkala + */ +public abstract class Endpoint { + /** Role of this endpoint. CONSUMER or PROVIDER */ + private Role mRole; + /** Service description from the SU descriptor for which this endpoint is configured */ + private SUDescriptor.Service mService; + /** WSDL definition corresponding to this endpoint */ + private Definition mWsdlDef; + /** service endpoint corresponding to this endpoint */ + private ServiceEndpoint mServiceEndpoint; + /** service unit from which this endpoint is created */ + private ServiceUnit mSU; // can be null + /** private constructor to force extended classes to use the parameterized constructor */ + private Endpoint() { + } + /** Creates a new instance of Endpoint + * @param role CONSUMER or PRVODER role. + * @param service service description from the su descriptor + * @param wsdl wsdl definition corresponding to this endpoint + * @param su service unit object which created this endpoint. + */ + protected Endpoint(Role role, SUDescriptor.Service service, Definition wsdl, ServiceUnit su) { + this.mService = service; + this.mRole = role; + this.mWsdlDef = wsdl; + this.mSU = su; + } + /** Creates a new instance of Endpoint without service unit. may be useful for static endpoints that + * are not part of the deployment + * @param role CONSUMER or PRVODER role. + * @param service service info from the su descriptor + * @param wsdl wsdl definition corresponding to this endpoint + */ + protected Endpoint(Role role, SUDescriptor.Service service, Definition wsdl) { + this(role, service, wsdl, null); + } + /** + * should be called to initialize any resources related to this endpoint object + * throws JBIException + */ + public abstract void init() throws JBIException; + /** + * activates the endpoint to send/receive messages + * throws JBIException + */ + public abstract void activate() throws JBIException; + /** + * deactivates the endpoint + * throws JBIException + */ + public abstract void deactivate() throws JBIException; + /** + * clean endpoint + * throws JBIException + */ + public abstract void clean() throws JBIException; + + public final Role getRole() { + return this.mRole; + } + public final boolean isProvider() { + return (Role.PROVIDER.equals(this.getRole())); + } + public final boolean isConsumer() { + return (Role.CONSUMER.equals(this.getRole())); + } + public final Definition getWSDL() { + return this.mWsdlDef; + } + public final SUDescriptor.Service getService() { + return this.mService; + } + public final ServiceEndpoint getServiceEndpoint() { + return this.mServiceEndpoint; + } + protected final void setServiceEndpoint(ServiceEndpoint svcEP) { + this.mServiceEndpoint = svcEP; + } + public final ServiceUnit getServiceUnit() { + return this.mSU; + } + /** + * generates an ID that would uniquely identify this endpoint implementation. Use as a key to map + * any information to store that is related to this endpoint. + */ + public final String getID() { + StringBuffer strBuff = new StringBuffer(); + strBuff.append(this.mService.getInterface()).append("+"); + strBuff.append(this.mService.getServiceName()).append("+"); + strBuff.append(this.mService.getEndpointName()).append("+"); + String roleType = null; + if ( Role.CONSUMER.equals(this.mRole) ) { + roleType = "CONSUMER"; + } else if ( Role.PROVIDER.equals(this.mRole) ) { + roleType = "PROVIDER"; + } + strBuff.append(roleType); + return strBuff.toString(); + } + + @Override + public String toString() { + return "Endpoint : " + "${symbol_escape}n" + this.mService; + } + /** + * checks if this endpoint is configured for the binding component or service engine. + */ + public boolean isFor${artifactId}() { + boolean isFor${artifactId} = false; + if ( this.mSU != null ) { + try { + isFor${artifactId} = this.mSU.getSUDescriptor().isFor${artifactId}(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + return isFor${artifactId}; + } + + public QName getOperationQName(String opName) { + return new QName(this.getService().getInterface().getNamespaceURI(), opName); + } + + public Operation getWSDLOperation(QName opQName) { + String opName = null; + if ( opQName != null ) { + opName = opQName.getLocalPart(); + } + Operation operation = WSDLProcessor.findOperation(this.getWSDL(), + this.getService().getInterface(), opName); + return operation; + } + + public Binding getWSDLBinding() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + if ( serviceName != null ) { + return WSDLProcessor.findServiceBinding(this.getWSDL(), serviceName, endpointName); + } else { + return WSDLProcessor.findInterfaceBinding(this.getWSDL(), interfaceName, null); + } + } + /** @return logger */ + public Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** @return ComponentContext */ + public ComponentContext getComponentContext() { + return RuntimeHelper.getComponentContext(); + } + /** @return DeliveryChannel */ + public DeliveryChannel getDeliveryChannel() { + return RuntimeHelper.getDeliveryChannel(); + } + /** + * helper function to get the MessageExchangeSupport object + */ + public MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeHelper.getMessageExchangeSupport(); + } + + public MessageExchangeHandler createMessageExchangeHandler() { + return null; + } + /** + * creates the message exchange listener. Extended classes should return + * MessageExchangeListener implementation. + * @return MessageExchangeListener or null. + * + */ + protected MessageExchangeListener createMessageExchangeListener() { + return null; + } + /** + * Creates and adds message exchange listener to receive message exchange received notification. + */ + protected void addMessageExchangeListener() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + MessageExchangeListener meListener = createMessageExchangeListener(); + MessageExchangeSupport meListenerSupport = getMessageExchangeSupport(); + if ( meListenerSupport != null && meListener != null ) { + meListenerSupport.addMessageExchangeListener( + this.getRole(), interfaceName, serviceName, endpointName, meListener); + if ( serviceName != null ) { + meListenerSupport.addMessageExchangeListener( + this.getRole(), null, serviceName, endpointName, meListener); + } + } + } + /** + * Removes message exchange listener from the MessageExchangeSupport. + */ + protected void removeMessageExchangeListener() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + MessageExchangeSupport meListenerSupport = getMessageExchangeSupport(); + if ( meListenerSupport != null ) { + meListenerSupport.removeMessageExchangeListener( + this.getRole(), interfaceName, serviceName, endpointName); + if ( serviceName != null ) { + meListenerSupport.removeMessageExchangeListener( + this.getRole(), null, serviceName, endpointName); + } + } + } + + public final boolean processMessageExchangeWithHandler(ExchangeStatus status, MessageExchange me) { + + //1. lookup handler + //2. if not there create one and register + //3. call process message exchange on it + //4. check status. if that is the end, remove the handler + + MessageExchangeSupport support = this.getMessageExchangeSupport(); + if ( support == null ) { + getLogger().fine("No MessageExchangeSupport present"); + return false; + } + MessageExchangeHandler handler = support.findMessageExchangeHandler(me); + if ( handler == null ) { + handler = this.createMessageExchangeHandler(); + if ( handler == null ) { + getLogger().fine("MessageExchangeHandler not supported"); + return false; + } + support.addMessageExchangeHandler(me, handler); + } + + handler.processMessageExchange(status, me); + + getLogger().fine("XXX MX Handler processed ME with STATUS: " + status); + + if (!ExchangeStatus.ACTIVE.equals(status) ) { + // DONE or ERROR means done with the me. + getLogger().fine("End of ME processing. STATUS: " + status + + ". Removing the MX Handler ..."); + support.removeMessageExchangeHandler(me); + } + + return true; + } + +} + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java new file mode 100644 index 000000000..4bd932fc1 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java @@ -0,0 +1,107 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ProviderEndpoint.java + * + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Service; +import javax.jbi.JBIException; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Definition; + +/** + * This class extends from Endpoint class and implements lifecycle methods functionality required for the + * endpoint for a service provider. {@link ServiceUnit${symbol_pound}createProviderEndpoint} creates the object of this + * type to implement the service provider functionality. It makes sure that this class or the extended + * classes will activate or deactivate the ServiceEndpoint corresponding to the service + * provided by the endpoint is performed during the activate and deactivate method calls as part of the + * endpoint lifecycle. + * + * @see ServiceUnit${symbol_pound}createProviderEndpoint + * @author chikkala + */ + +public class ProviderEndpoint extends Endpoint { + /** + * This constructor initializes the endpoint with PROVIDER role and makes sure that the service + * description passed to it is of provider description. + */ + protected ProviderEndpoint(SUDescriptor.Provides provides, Definition wsdlDef, ServiceUnit su) { + super(Role.PROVIDER, provides, wsdlDef, su); + } + /** + * constructor that does not need service unit information. useful for creating the endpoint for + * static services provided by the component. + */ + protected ProviderEndpoint(SUDescriptor.Provides provides, Definition wsdlDef) { + this(provides, wsdlDef, null); + } + /** + * initializes the endpoint and creates and registers the MessageExchangeListener with + * MessageExchangeSupport. + */ + public final void init() throws JBIException { + getLogger().fine("ProviderEndpiont: init called"); + doInit(); //1. initialize the endpiont resources + addMessageExchangeListener(); //2. register message exchange linster. + } + /** + * calls activatesServiceEndpoint for the Provider. + */ + public final void activate() throws JBIException { + getLogger().fine("ProviderEndpiont: activate called"); + activateServiceEndpoint(); //1. activate service endpoint in NMR + doActivate(); //2. do any other activation related tasks. + } + /** + * calls deactivateServiceEndpoint for the Provider. + */ + public final void deactivate() throws JBIException { + getLogger().fine("ProviderEndpiont: deactivate called"); + deactivateServiceEndpoint(); //1. deactivates the service endpoint in NMR + doDeactivate(); //2. do any other deactivation related tasks. + } + /** + * removes the message exchange listener. cleans up other resources + */ + public final void clean() throws JBIException { + getLogger().fine("ProviderEndpiont: clean called"); + removeMessageExchangeListener(); //1. remove message exchange listener + doClean(); //2. clean up any other resources. + } + /** + * Activates the ServiceEndpoint with NMR + */ + private void activateServiceEndpoint() throws JBIException { + Service service = this.getService(); + ServiceEndpoint svcEP = this.getComponentContext().activateEndpoint( + service.getServiceName(), service.getEndpointName()); + this.setServiceEndpoint(svcEP); + } + /** + * Deactivates ServiceEndpoint in NMR + */ + private void deactivateServiceEndpoint() throws JBIException { + this.getComponentContext().deactivateEndpoint(this.getServiceEndpoint()); + this.setServiceEndpoint(null); + } + + protected void doInit() throws JBIException { + //NOOP + } + protected void doActivate() throws JBIException { + //NOOP + } + protected void doDeactivate() throws JBIException { + //NOOP + } + protected void doClean() throws JBIException { + //NOOP + } + +} \ No newline at end of file diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java new file mode 100644 index 000000000..3710afa62 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java @@ -0,0 +1,364 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * SUDescriptor.java + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import javax.jbi.management.DeploymentException; +import javax.xml.namespace.QName; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * This interface represent the service unit descriptor (jbi.xml) model. This will be used in + * ServiceUnit implementation to find the services provided and consumed by this service unit. + * {@link SUDescriptorFactory${symbol_pound}getSUDescriptor} method reads the jbi.xml in the service unit to + * to the implementation of this interface. + * + * @see SUDescriptorFactory + * @see Consumes + * @see Provides + * @see ServiceUnit + * + * @author chikkala + */ +public interface SUDescriptor { + + Collection getProvidedServices(); + + Collection getConsumedServices(); + + boolean isFor${artifactId}(); + + /** + * base interface that models the service information described in the service unit descriptor for + * consumed services and provided services. + */ + public interface Service { + /** + * Getter for property interfaceQName. + * @return Value of property interfaceQName. + */ + QName getInterface(); + /** + * Getter for property serviceName. + * @return Value of property serviceName. + */ + QName getServiceName(); + /** + * Getter for property endpointName. + * @return Value of property endpointName. + */ + String getEndpointName(); + } + /** + * marker interface that represents the provided services in the service unit + */ + public interface Provides extends Service { + } + /** + * this interface represents the consumed service information in the su descriptor. + */ + public interface Consumes extends Service { + + public final static String STANDARD_LINK = "standard"; + public final static String SOFT_LINK = "soft"; + public final static String HARD_LINK = "hard"; + /** + * Getter for property linkType. + * @return Value of property linkType. + */ + String getLinkType(); + } + /** + * This is a factory class that can build the Service Unit Descriptor model from the jbi.xml + */ + public static class SUDescriptorFactory { + + protected final static String JBI_TAG_NAME = "services"; + protected final static String SERVICES_TAG_NAME = "services"; + protected final static String BC_TAG_NAME = "binding-component"; + protected final static String PROVIDES_TAG_NAME = "provides"; + protected final static String CONSUMES_TAG_NAME = "consumes"; + protected final static String INTERFACE_TAG_NAME = "interface-name"; + protected final static String SERVICE_TAG_NAME = "service-name"; + protected final static String ENDPOINT_TAG_NAME = "endpoint-name"; + protected final static String LINK_TYPE_TAG_NAME = "link-type"; + /** + * method that builds the Service unit descriptor model from the jbi.xml + */ + public static SUDescriptor getSUDescriptor(String jbiXmlPath) throws Exception { + FileReader reader = null; + try { + reader = new FileReader(jbiXmlPath); + SUDescriptor suDesc = getSUDescriptor(reader); + return suDesc; + } finally { + if ( reader != null ) { + try { + reader.close(); + } catch (IOException ex) { + // ignore + } + } + } + } + /** + * method that builds the Service unit descriptor model from the jbi.xml + */ + public static SUDescriptor getSUDescriptor(Reader reader) throws Exception { + SUDescriptor suDescriptor = null; + Document suDescDoc = RuntimeHelper.buildDOMDocument(reader); + Element jbiEl = suDescDoc.getDocumentElement(); + if (JBI_TAG_NAME.equals(jbiEl.getTagName())) { + throw new DeploymentException("Invalid service unit descriptor : no jbi root element"); + } + + NodeList servicesNL = jbiEl.getElementsByTagName(SERVICES_TAG_NAME); + if (servicesNL != null && servicesNL.getLength() == 1) { + Element servicesEl = (Element) servicesNL.item(0); + suDescriptor = SUDescriptorImpl.createSUDescriptor(servicesEl); + } else { + throw new DeploymentException("Invalid service unit descriptor : invalid services element"); + } + + return suDescriptor; + } + + } + /** + * This class implements SUDescriptor + */ + public static class SUDescriptorImpl implements SUDescriptor { + + private List mConsumedList; + private List mProvidedList; + private boolean mIsFor${artifactId}; + + protected SUDescriptorImpl(boolean isFor${artifactId}) { + this.mIsFor${artifactId} = isFor${artifactId}; + this.mConsumedList = new ArrayList(); + this.mProvidedList = new ArrayList(); + } + + protected void addProvidedService(Provides provides) { + this.mProvidedList.add(provides); + } + + protected void addConsumedService(Consumes consumes) { + this.mConsumedList.add(consumes); + } + + public Collection getProvidedServices() { + // return unmodifiable collection + return Collections.unmodifiableCollection(this.mProvidedList); + } + + public Collection getConsumedServices() { + // return unmodifiable collection + return Collections.unmodifiableCollection(this.mConsumedList); + } + + public boolean isFor${artifactId}() { + return this.mIsFor${artifactId}; + } + + protected static SUDescriptor createSUDescriptor(Element servicesEl) throws Exception { + boolean isForBC = false; + String bcTagString = servicesEl.getAttribute(SUDescriptorFactory.BC_TAG_NAME); + isForBC = Boolean.valueOf(bcTagString).booleanValue(); + SUDescriptorImpl suDesc = new SUDescriptorImpl(isForBC); + // add consumes + NodeList consumesNL = servicesEl.getElementsByTagName(SUDescriptorFactory.CONSUMES_TAG_NAME); + for ( int i=0; i < consumesNL.getLength(); ++i) { + Element consumesEl = (Element) consumesNL.item(i); + Consumes consumes = ConsumedService.createConsumedService(consumesEl); + suDesc.addConsumedService(consumes); + } + // add provides + NodeList providesNL = servicesEl.getElementsByTagName(SUDescriptorFactory.PROVIDES_TAG_NAME); + for ( int i=0; i < providesNL.getLength(); ++i) { + Element providesEl = (Element) providesNL.item(i); + Provides provides = ProvidedService.createProvidedService(providesEl); + suDesc.addProvidedService(provides); + } + + return suDesc; + } + } + /** + * Base class that implements the Service interface + */ + public static abstract class AbstractService implements Service { + + private QName mInterface; + private QName mServiceName; + private String mEndpointName; + + private AbstractService() { + } + /** + * Getter for property interfaceQName. + * @return Value of property interfaceQName. + */ + public QName getInterface() { + return this.mInterface; + } + + /** + * Setter for property interfaceQName. + * @param interfaceQName New value of property interfaceQName. + */ + protected void setInterface(QName interfaceQName) { + this.mInterface = interfaceQName; + } + + /** + * Getter for property serviceName. + * @return Value of property serviceName. + */ + public QName getServiceName() { + return this.mServiceName; + } + + /** + * Setter for property serviceName. + * @param serviceName New value of property serviceName. + */ + protected void setServiceName(QName serviceName) { + this.mServiceName = serviceName; + } + + /** + * Getter for property endpointName. + * @return Value of property endpointName. + */ + public String getEndpointName() { + return this.mEndpointName; + } + + /** + * Setter for property endpointName. + * @param endpointName New value of property endpointName. + */ + protected void setEndpointName(String endpointName) { + this.mEndpointName = endpointName; + } + + } + /** + * This class implements the Provides interface + */ + public static class ProvidedService + extends AbstractService + implements Provides { + protected ProvidedService(QName interfaceQName, QName serviceName, String endpointName) { + this.setInterface(interfaceQName); + this.setServiceName(serviceName); + this.setEndpointName(endpointName); + } + + @Override + public String toString() { + return "Provides :" + + "${symbol_escape}n${symbol_escape}t interface-name= " + getInterface() + + "${symbol_escape}n${symbol_escape}t service-name= " + getServiceName() + + "${symbol_escape}n${symbol_escape}t endpont-name= " + getEndpointName(); + } + + protected static Provides createProvidedService(Element providesEl) throws Exception { + + String ifName = providesEl.getAttribute(SUDescriptorFactory.INTERFACE_TAG_NAME); + String serviceName = providesEl.getAttribute(SUDescriptorFactory.SERVICE_TAG_NAME); + String endpointName = providesEl.getAttribute(SUDescriptorFactory.ENDPOINT_TAG_NAME); + if ( ifName == null || serviceName == null || endpointName == null ) { + throw new Exception("Invalid provides element: missing " + SUDescriptorFactory.INTERFACE_TAG_NAME + + " or " + SUDescriptorFactory.SERVICE_TAG_NAME + " or " + SUDescriptorFactory.ENDPOINT_TAG_NAME ); + } + QName ifQName = RuntimeHelper.resolveAttrQName(ifName, providesEl); + QName serviceQName = RuntimeHelper.resolveAttrQName(serviceName, providesEl); + + return new ProvidedService(ifQName, serviceQName, endpointName); + } + } + /** + * This class implements the Consumes interface. + */ + public static class ConsumedService + extends AbstractService + implements Consumes { + private String mLinkType; + protected ConsumedService(QName interfaceQName, + QName serviceName, String endpointName, String linkType) { + this.setInterface(interfaceQName); + this.setServiceName(serviceName); + this.setEndpointName(endpointName); + this.mLinkType = linkType; + } + + /** + * Getter for property linkType. + * @return Value of property linkType. + */ + public String getLinkType() { + return this.mLinkType; + } + + @Override + public String toString() { + return "Cosumes :" + + "${symbol_escape}n${symbol_escape}t interface-name= " + getInterface() + + "${symbol_escape}n${symbol_escape}t service-name= " + getServiceName() + + "${symbol_escape}n${symbol_escape}t endpont-name= " + getEndpointName() + + "${symbol_escape}n${symbol_escape}t link-type= " + getLinkType(); + } + + protected static Consumes createConsumedService(Element consumesEl) throws Exception { + + String ifName = consumesEl.getAttribute(SUDescriptorFactory.INTERFACE_TAG_NAME); + String serviceName = consumesEl.getAttribute(SUDescriptorFactory.SERVICE_TAG_NAME); + String endpointName = consumesEl.getAttribute(SUDescriptorFactory.ENDPOINT_TAG_NAME); + String linkType = consumesEl.getAttribute(SUDescriptorFactory.LINK_TYPE_TAG_NAME); + if ( linkType == null || linkType.trim().length() == 0 ) { + linkType = STANDARD_LINK; + } + + if ( ifName == null ) { + throw new Exception("Invalid consumes element: missing " + + SUDescriptorFactory.INTERFACE_TAG_NAME ); + } + if ( serviceName == null || endpointName == null ) { + throw new Exception("Invalid consumes element: missing " + + SUDescriptorFactory.SERVICE_TAG_NAME + " or " + + SUDescriptorFactory.ENDPOINT_TAG_NAME ); + } + + QName ifQName = RuntimeHelper.resolveAttrQName(ifName, consumesEl); + QName serviceQName = null; + if ( serviceName != null ) { + serviceQName = RuntimeHelper.resolveAttrQName(serviceName, consumesEl); + } + if ( serviceQName != null && endpointName != null && linkType != null ) { + if (!(STANDARD_LINK.equals(linkType) || + SOFT_LINK.equals(linkType) || HARD_LINK.equals(linkType)) ) { + throw new Exception("Invalid consumes attribute value" + + SUDescriptorFactory.LINK_TYPE_TAG_NAME + "=" + linkType); + } + } + return new ConsumedService(ifQName, serviceQName, endpointName, linkType); + } + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java new file mode 100644 index 000000000..1794d9333 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java @@ -0,0 +1,464 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ServiceUnit.java + * + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Consumes; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Provides; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Service; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.management.DeploymentException; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; + +/** + * This is an abstract class that implements the service unit functionality in the component which + * processes the service unit artifacts and implement the actual service unit lifecycle functionality. + * The AbstractServiceUnitManager and its extended classes that implement the ServiceUnitManager + * functionality creates and maintains the reference to the concrete implementation of this class to + * invoke the functionality implemented by this class and its concrete implementation during the + * execution of the ServiceUnitMangers lifecycle methods by the jbi runtime. + *

+ * The main lifecycle methods of this class that will be called by the ServiceUnitManger implementation + * during the service unit deployment lifecycle are {@link ${symbol_pound}doload}, {@link ${symbol_pound}doDeploy}, {@link ${symbol_pound}doUndeploy}, + * {@link ${symbol_pound}doInit}, {@link ${symbol_pound}doStart}, {@link ${symbol_pound}doStop} and {@link ${symbol_pound}doShutdown} + *

+ * Service unit processing supported by this implementation is based on wsdl 1.1 deployments where the + * services provided and consumed in this service unit are described using wsdl 1.1 definitions. + *

+ * The main service unit artifacts that will be processed during deployment lifecycle of the service + * unit are 1.Service unit descriptor(jbi.xml) that describes the services provided and consumed by + * this service unit. 2.WSDL 1.1 document that describes the service definition 3.Component specific + * configurations related to services provided and consumed by this service unit. + *

+ * When the service unit is for Binding Component, the component specific configurations are read + * from the WSDL1.1 extensions defined in the WSDL document corresponding to the service provider + * or consumer deployed with this service unit. + *

+ * When the service unit is for Service Engine, the component specific configurations are read + * from the deployment artifacts such as xslt files and mapping files in the service unit zip file + * along with the WSDL document corresponding to the service provider or consumer deployed with this + * service unit. + * + * @see SUDescriptor + * @see Endpoint + * @see ProviderEndpoint + * @see ConsumerEndpoint + * @see WSDLProcessor + * @author chikkala + */ +public abstract class ServiceUnit { + /** Service Unit Name */ + private String mSUName; + /** Service Unit Root path passed by jbi runtime */ + private String mSURootPath; + /** service unit descriptor model unmarshalled from service unit jbi.xml */ + private SUDescriptor mSUDescriptor; + /** Map of Endpoint Key to ProviderEndpoint configurations in this service unit */ + private Map mProviderEndpointMap; + /** Map of Endpoint Key to ConsumerEndpoint configurations in this service unit */ + private Map mConsumerEndpointMap; + /** Map of Service Key to the WSDL Definition in this service unit */ + private Map mWSDLMap; + /** WSDLProcessor configured for this service unit to process wsdls in the service unit */ + private WSDLProcessor mWSDLProcessor; + /** + * + * @param suName + * @param suRootPath + */ + protected ServiceUnit(String suName, String suRootPath) { + this.mSUName = suName; + this.mSURootPath = suRootPath; + this.mSUDescriptor = null; + this.mWSDLMap = new HashMap(); + this.mProviderEndpointMap = new HashMap(); + this.mConsumerEndpointMap = new HashMap(); + } + /** returns service unit name + * @return service unit name + */ + public String getName() { + return this.mSUName; + } + /** returns service unit root path where the su artifacts are unzipped by the jbi runtime + * @return path to the service unit root directory. + */ + public String getSURootPath() { + return this.mSURootPath; + } + protected SUDescriptor createSUDescriptor() throws Exception { + File jbiXmlFile = new File(this.getSURootPath(), "META-INF/jbi.xml"); + String jbiXmlPath = jbiXmlFile.getAbsolutePath(); + return SUDescriptor.SUDescriptorFactory.getSUDescriptor(jbiXmlPath); + } + /** return the Service unit descriptor model that was read from the jbi.xml + * @return SUDescriptor + */ + public SUDescriptor getSUDescriptor() throws Exception { + if ( this.mSUDescriptor == null ) { + this.mSUDescriptor = createSUDescriptor(); + } + return this.mSUDescriptor; + } + public ProviderEndpoint getProviderEndpoint(String providerID) { + return this.mProviderEndpointMap.get(providerID); + } + public Collection getProviderEndpoints() { + return Collections.unmodifiableCollection(this.mProviderEndpointMap.values()); + } + public ConsumerEndpoint getConsumerEndpoint(String cosumerID) { + return this.mConsumerEndpointMap.get(cosumerID); + } + + public Collection getConsumerEndpoints() { + return Collections.unmodifiableCollection(this.mConsumerEndpointMap.values()); + } + /** + * @return Logger + */ + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** + * extended classes implement this method to create the su specific WSDLProcessor. for examples, + * a su supporting binding component may have wsdl extensions that it want to registry for reading + * the configurations from the wsdl file. + * @return WSDLProcessor + * @see com.sun.jbi.sample.component.common.wsdl.WSDLProcessor + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + */ + protected WSDLProcessor createWSDLProcessor() { + return new WSDLProcessor(this.getSURootPath()); + } + /** + * return the WSDLProcessor reference by creates if it is not yet created. + * @return WSDLProcessor. + */ + public final WSDLProcessor getWSDLProcessor() { + if ( this.mWSDLProcessor == null ) { + this.mWSDLProcessor = createWSDLProcessor(); + } + return this.mWSDLProcessor; + } + /** + * loads the service unit artifacts into the SU model. AbstractServiceUnitManager implementation + * calls this method during the during deploy and init lifecycle methods when the service unit + * object is newly created. + */ + public void doLoad() throws DeploymentException { + try { + SUDescriptor suDesc = getSUDescriptor(); // load jbi.xml + loadServiceDefinitions(); // check if the wsdls are valid for corresponding services. + loadOtherArtifacts(); // additional validations specific to component deployment features. + loadEndpoints(); // create endpoints + } catch ( DeploymentException jbiEx) { + throw jbiEx; + } catch (Exception ex) { + throw new DeploymentException(ex); + } + } + /** extended classes implement this method to perform the su specific deployment related tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doDeploy() throws DeploymentException { + // NOOP. doLoad has done it all. + this.getLogger().fine("ServiceUnit.doDeploy"); + } + /** extended classes implement this method to perform the su specific undeployment related tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doUndeploy() throws DeploymentException { + //NOOP + this.getLogger().fine("ServiceUnit.doUndeploy"); + } + /** extended classes implement this method to perform the su specific initialization tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doInit() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doInit"); + this.doInitEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on start in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doStart() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doStart"); + this.doActivateEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on stop in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doStop() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doStop"); + this.doDeactivateEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on shutdown in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doShutdown() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doShutdown"); + this.doCleanEndpoints(); + } + /** + * create the ProviderEndpoint that implement the service provider implementation specific to this su. + * @return ProviderEndpoint or null if the SU does not support the service provider access + */ + protected ProviderEndpoint createProviderEndpoint(Provides provides, Definition wsdlDef) { + return null; + } + /** + * create the ProviderEndpoint that implement the service consumer implementation specific to this su. + * @return ConsumerEndpoint or null if the SU does not support the service consumer access + */ + protected ConsumerEndpoint createConsumerEndpoint(Consumes consumes, Definition wsdlDef) { + return null; + } + /** + * generates the key based on the service to store the wsdl definitions . + */ + protected String getServiceKey(Service service) { + StringBuffer strBuff = new StringBuffer(); + strBuff.append(service.getInterface()).append("+"); + strBuff.append(service.getServiceName()).append("+"); + strBuff.append(service.getEndpointName()); + return strBuff.toString(); + } + /** + * looks up the wsdl definition loaded for this service. + */ + protected Definition findWSDLFor(Service service) throws WSDLException { + Definition wsdlDef = null; + String key = this.getServiceKey(service); + wsdlDef = this.mWSDLMap.get(key); + return wsdlDef; + } + + protected Definition findWSDL(List wsdlList, Service service, boolean ignoreEndpointLookup) { + Definition foundDef = null; + for ( Definition def : wsdlList ) { + if ( WSDLProcessor.isWSDLFor(def, service.getInterface(), service.getServiceName(), + ((ignoreEndpointLookup) ? null : service.getEndpointName()) ) ) { + foundDef = def; + break; + } + } + return foundDef; + } + /** + * loads the WSDL definitions corresponds to the service providers and consumers defined in the + * service unit descriptor. + */ + protected void loadServiceDefinitions() throws Exception { + + this.mWSDLMap = new HashMap(); + + WSDLProcessor wsdlProcessor = getWSDLProcessor(); + List wsdlList = wsdlProcessor.readWSDLs(this.getSURootPath()); + this.getLogger().fine("Number of wsdl definitions in service unit " + wsdlList.size()); + + List services = new ArrayList(); + services.addAll(this.getSUDescriptor().getProvidedServices()); + services.addAll(this.getSUDescriptor().getConsumedServices()); + + boolean isForBinding = this.getSUDescriptor().isFor${artifactId}(); + this.getLogger().fine("Is this service unit for Binding? " + isForBinding); + + for ( Service service : services ) { + this.getLogger().fine("Looking up WSDL for service " + service); + boolean ignoreEndpointLookup = false; + boolean providerAtEngine = false; + if ( !isForBinding && service instanceof Provides ) { + ignoreEndpointLookup = true; + providerAtEngine = true; + } + Definition def = findWSDL(wsdlList, service, ignoreEndpointLookup); + if ( def == null ) { + throw new Exception("WSDL Definition not found for " + service); + } + this.mWSDLMap.put(getServiceKey(service), def); + if ( providerAtEngine ) { + // provider at engine. so add engine binding and endpoint to the wsdl + wsdlProcessor.createServiceEngineBinding(def, + service.getInterface(), service.getServiceName(), service.getEndpointName()); + } + } + } + /** extended classes implement this method to perform the su specific artifacts validation in + * this method implementation. + * @throws DeploymentException on error. + */ + protected void loadOtherArtifacts() throws DeploymentException { + // nothing to validate further. + this.getLogger().fine("ServiceUnit.loadOtherArtifacts"); + } + /** + * creates ProviderEndpoint and ConsumerEndpoint objects corresponding to the service providers + * and consumers described in the su descriptor ( jbi.xml ) + */ + protected void loadEndpoints() throws Exception { + + this.mProviderEndpointMap = new HashMap(); + this.mConsumerEndpointMap = new HashMap(); + + Collection providesList = this.getSUDescriptor().getProvidedServices(); + for ( Provides provides : providesList ) { + Definition wsdlDef = findWSDLFor(provides); + if ( wsdlDef == null ) { + throw new DeploymentException("WSDL Definitions not found for " + provides); + } + ProviderEndpoint provider = createProviderEndpoint(provides, wsdlDef); + this.mProviderEndpointMap.put(provider.getID(), provider); + } + + Collection consumesList = this.getSUDescriptor().getConsumedServices(); + for ( Consumes consumes : consumesList ) { + Definition wsdlDef = findWSDLFor(consumes); + if ( wsdlDef == null ) { + throw new DeploymentException("WSDL Definitions not found for " + consumes); + } + ConsumerEndpoint consumer = createConsumerEndpoint(consumes, wsdlDef); + this.mConsumerEndpointMap.put(consumer.getID(), consumer); + } + } + /** + * initializes the Endpoint objects created corresponding to the consumer and providers defined + * in the su descriptor + */ + protected void doInitEndpoints() throws DeploymentException { + // init endpoints. if any initialization fails, rollback the already inited endpoints + List initedEndpoints = new ArrayList(); + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getProviderEndpoints()); + allEndpoints.addAll(this.getConsumerEndpoints()); + + for ( Endpoint endpoint : allEndpoints ) { + try { + endpoint.init(); + initedEndpoints.add(endpoint); + } catch ( Exception initEx) { + doCleanEndpoints(initedEndpoints); + throw new DeploymentException(initEx); + } + } + + } + /** + * invokes activates method of all provider and consumer endpoint object in this su. if there is + * and error activating any one the endpoints, it deactivates the already activated ones and throws + * the error + */ + protected void doActivateEndpoints() throws DeploymentException { + // activate providers first and then consumers + List activatedEndpoints = new ArrayList(); + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getProviderEndpoints()); + allEndpoints.addAll(this.getConsumerEndpoints()); + + for ( Endpoint endpoint : allEndpoints ) { + try { + endpoint.activate(); + activatedEndpoints.add(endpoint); + } catch ( Exception actEx) { + doDeactivateEndpoints(activatedEndpoints); + throw new DeploymentException(actEx); + } + } + } + /** + * invokes deactivate method on the list of Endpoint objects passed to this method + */ + protected void doDeactivateEndpoints(List endpoints) { + for ( Endpoint endpoint : endpoints ) { + try { + endpoint.deactivate(); + } catch(Exception ex) { + // ignore the exception and log it. + this.getLogger().log(Level.FINE, ex.getMessage(), ex); + } + } + } + /** + * invokes deactivate method on the all consumer and provider endpoint objects + */ + protected void doDeactivateEndpoints() { + // deactivate consumers first and then the providers + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getConsumerEndpoints()); + allEndpoints.addAll(this.getProviderEndpoints()); + doDeactivateEndpoints(allEndpoints); + } + /** + * invokes clean method on the list of endpoint objects + */ + protected void doCleanEndpoints(List endpoints) { + for ( Endpoint endpoint : endpoints ) { + try { + endpoint.clean(); + } catch(Exception ex) { + // ignore the exception and log it. + this.getLogger().log(Level.FINE, ex.getMessage(), ex); + } + } + } + /** + * invokes clean method on the all consumer and provider endpoint objects in this su. + */ + protected void doCleanEndpoints() { + + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getConsumerEndpoints()); + allEndpoints.addAll(this.getProviderEndpoints()); + doCleanEndpoints(allEndpoints); + } + /** + * prints the service unit description + */ + protected final String printDetails() { + + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + + out.println("ServiceUnit Name : " + this.getName()); + out.println("ServiceUnit Root : " + this.getSURootPath()); + + SUDescriptor suDesc = null; + try { + suDesc = this.getSUDescriptor(); + for ( SUDescriptor.Consumes consumer : suDesc.getConsumedServices()) { + out.println(consumer); + } + for ( SUDescriptor.Provides provides : suDesc.getProvidedServices()) { + out.println(provides); + } + } catch (Exception ex) { + ex.printStackTrace(out); + } + return writer.getBuffer().toString(); + } + + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java new file mode 100644 index 000000000..67bbf5a45 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java @@ -0,0 +1,44 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractExtensibilityElement.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import javax.wsdl.extensions.ExtensibilityElement; +import javax.xml.namespace.QName; + +/** + * This is an abstract class which can be extended to create jwsdl (wsdl4j's) extension elements model to + * read/write the wsdl extension elements in wsdl 1.1 xml. + * + * @author chikkala + */ +public abstract class AbstractExtensibilityElement implements ExtensibilityElement, java.io.Serializable { + public static final long serialVersionUID = 1; + private QName mElementType; + private Boolean mRequired; + + /** Creates a new instance of AbstractExtensibilityElement */ + protected AbstractExtensibilityElement() { + } + + public void setElementType(QName elementType) { + this.mElementType = elementType; + } + + public QName getElementType() { + return this.mElementType; + } + + public void setRequired(Boolean required) { + this.mRequired = required; + } + + public Boolean getRequired() { + return this.mRequired; + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java new file mode 100644 index 000000000..0882bd65f --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java @@ -0,0 +1,45 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractExtensionRegistry.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.util.List; +import javax.wsdl.extensions.ExtensionRegistry; + +/** + * This is the abstract class used to add the wsdl extension serializers and deserializers to the + * wsdl extension registry configured to read/write wsdl extensions into a know java model. + * @see AbstractExtensionSerializer + * @see WSDLProcessor + * @author chikkala + */ +public abstract class AbstractExtensionRegistry extends ExtensionRegistry { + + /** Creates a new instance of AbstractSerializer + * it calls the createSerializers method to get the list of + * serializers and then call registerSerializer on each AbstractExtensionSerializer + * to register them with this registry. + * @see AbstractExtensionSerializer${symbol_pound}registerSerializer + */ + protected AbstractExtensionRegistry() { + super(); + List list = createSerializers(); + for (AbstractExtensionSerializer ser : list ) { + ser.registerSerializer(this); + } + // register ServiceEngine Binding serializers + AbstractExtensionSerializer seBindingSer = new SEBindingExt.SEBindingExtSerializer(); + seBindingSer.registerSerializer(this); + } + /** + * create wsdl extension serializers for each extension element to register with the extension + * registry. + * @return List of AbstractExtensionSerializer objects for serializing/deserializing the wsdl extensions. + * @see AbstractExtensionSerializer + */ + protected abstract List createSerializers(); +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java new file mode 100644 index 000000000..4ac1b37d6 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java @@ -0,0 +1,123 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractExtensionSerializer.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.io.PrintWriter; +import java.io.Serializable; +import java.util.Set; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionDeserializer; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.extensions.ExtensionSerializer; +import javax.xml.namespace.QName; +import org.w3c.dom.Attr; +import org.w3c.dom.Element; + +/** + * This class is an abstract class that should be extended to implements extension serializer and + * deserializer. This class implements the code required for registering the serializer and deserializer + * implemented by this class. THe AbstractExtensionRegistry class calls the ${symbol_pound}registerSerializer method + * to register the concrete implementation of this class with extension registry. + * @see AbstractExtensionRegistry + * @author chikkala + */ +public abstract class AbstractExtensionSerializer + implements ExtensionSerializer, ExtensionDeserializer, Serializable { + + public static final long serialVersionUID = 1; + + private Class mParentType; + private Class mExtensionType; + private QName mElementType; + + /** Creates a new instance of AbstractSerializer */ + public AbstractExtensionSerializer(Class parentType, QName elementType, Class extensionType) { + this.mParentType = parentType; + this.mElementType = elementType; + this.mExtensionType = extensionType; + } + + public Class getParentType() { + return this.mParentType; + } + public QName getElementType() { + return this.mElementType; + } + public Class getExtensionType() { + return this.mExtensionType; + } + + public void registerSerializer(ExtensionRegistry extReg) { + extReg.registerSerializer(this.mParentType, this.mElementType, this); + extReg.registerDeserializer(this.mParentType, this.mElementType, this); + extReg.mapExtensionTypes(this.mParentType, this.mElementType, this.mExtensionType); + } + + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg ) throws WSDLException { + // DO NOTHING. Binding component runtime does not need to serialize the wsdl extensions. + } + + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + return null; + } + + public static String getAttribute(Element el, String attrName) { + String attrValue = null; + Attr attr = el.getAttributeNode(attrName); + if ( attr != null ) { + attrValue = attr.getValue(); + } + return attrValue; + } + + protected String getNamespacePrefix(Definition def, String namespaceURI, String defPrefix) { + String prefix = null; + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + Set keySet = def.getNamespaces().keySet(); + String newPrefix = "ns"; + if ( defPrefix != null && defPrefix.trim().length() > 0 ){ + newPrefix = defPrefix; + } + prefix = newPrefix; + for ( int i=0; i < Integer.MAX_VALUE; ++i) { + if (!keySet.contains(prefix)) { + break; + } else { + prefix = newPrefix + i; + } + } + } + return prefix; + } + /** + * @return the name with the prefix defined for the namespaceURI in the wsdl definition. + * @throws WSDLException if the prefix not found in the wsdl definition. note that the + * default prefix is an empty string. + */ + protected String getQualifiedName(Definition def, + String namespaceURI, String localName) throws WSDLException { + String prefix = null; + if (namespaceURI != null && !namespaceURI.equals("")) { + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + throw new WSDLException(WSDLException.OTHER_ERROR, + "Can not find prefix in WSDL Definition for " + namespaceURI); + } + } + if ( prefix != null && !prefix.equals("")) { + return prefix + ":" + localName; + } else { + return localName; + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java new file mode 100644 index 000000000..b10800550 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java @@ -0,0 +1,229 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractNormalizer.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.util.ArrayList; +import java.util.List; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Part; +import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.dom.DOMSource; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * This is an abstract class that implements most of the functionality to normalize the binding protocol + * specific concrete message to jbi wrapper and and denormalize jbi wrapper to the concrete binding + * protocol specific message. + *

+ * The extended classes specific to particular binding protocol will be used when a jbi binding + * component is sending and receiving messages from the external service providers and consumers using + * a particular binding protocol known to this class. Extended implementation of this class should make + * use of the helper methods in this class in normalizing and denormalizing the messages. + * @see JMXBindingNormalizer + * @author chikkala + */ +public abstract class AbstractNormalizer { + + public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/"; + /** wsdl definition to use when normalizing and denormalizing */ + private Definition mWSDL; + /** Binding definition to use when normalizing and denormalizing */ + private Binding mBinding; + + private AbstractNormalizer() {} + /** Creates a new instance of JMXBCNormalizer */ + public AbstractNormalizer(Definition wsdl, Binding binding) { + this.mWSDL = wsdl; + this.mBinding = binding; + } + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete mssage of a particular binding protocol. + */ + public abstract void normalizeInput(Operation operation, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete message of a particular binding protocol. + */ + public abstract void normalizeOutput(Operation operation, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete message of a particular binding protocol. + */ + public abstract void normalizeFault(Operation operation, String faultName, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * denormalize the normalized message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be de-normalized. + * @param normMsg NormalizedMessage which should be used to create de-normalized message. + */ + public abstract DOMSource denormalizeInput(Operation operation, NormalizedMessage normMsg) + throws MessagingException; + /** + * denormalize the normalized message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be denormalized. + * @param normMsg NormalizedMessage which should be used to create denormalized message. + */ + public abstract DOMSource denormalizeOutput(Operation operation, NormalizedMessage normMsg) + throws MessagingException; + + /** + * denormalized the normalized fault message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be denormalized. + * @param normMsg NormalizedMessage which should be used to create denormalized message. + */ + public abstract DOMSource denormalizeFault(Operation operation, String faultName, NormalizedMessage normMsg) + throws MessagingException; + /** + * @return the wsdl definition to use in normalizing and denormalizing the message + */ + protected Definition getWSDL() { + return this.mWSDL; + } + /** + * @return the wsdl binding definition to use in normalizing and denormalizing the message + */ + protected Binding getBinding() { + return this.mBinding; + } + /** + * create and add message parts to the jbiWrapper according to the abstract message model. This + * method assumes that the each element in the msgParts list passed to it is mapped to the part + * of the abstract wsdl message and uses the type or element attribute of the abstract message to + * determine whether the element is actual part element or a wrapped part type. + * Use this method in normalizing the concrete protocol specific message to jbi wrapper message. + * @param jbiWrapper object that holds the jbi wrapper information. + * @param wsdlMsg abstract message from the wsdl definition + * @param msgParts actual message parts from the concrete message + */ + protected void addMessagePartsToJBIWrapper(WSDL11JBIWrapper jbiWrapper, Message wsdlMsg, List msgParts) throws MessagingException { + List wsdlParts = wsdlMsg.getOrderedParts(null); + for ( int i=0; i < wsdlParts.size(); ++i ) { + Part wsdlPart = (Part) wsdlParts.get(i); + if ( i >= msgParts.size() ) { + throw new MessagingException("missing message content for part " + wsdlPart.getName()); + } + Element msgPart = msgParts.get(i); + if ( wsdlPart.getElementName() != null ) { + jbiWrapper.appendPart(msgPart); + } else { + // it is type. + // check the element name is same as part + if ( !wsdlPart.getName().equals(msgPart.getLocalName()) ) { + throw new MessagingException("mismatched message content for part " + wsdlPart.getName()); + } + if ( !wsdlMsg.getQName().getNamespaceURI().equals(msgPart.getNamespaceURI()) ) { + throw new MessagingException("mismatched message content namespace for part " + wsdlPart.getName()); + } + // check the content is text or element. + List partContent = getChildElements(msgPart); + if ( partContent.size() > 0 ) { + // add content as part elements + jbiWrapper.appendPart(partContent); + } else { + // add the content as text + jbiWrapper.appendPart(msgPart.getTextContent()); + } + } + } + } + /** + * extracts the message parts from the jbiWrapper according to the abstract wsdl message + * definition passed to it. Use this method in denormalizing the jbi wrapper message into the + * binding protocol specific concrete message. + * @param jbiWrapper jbi wrapper object that contains message parts and the message type information. + * @param wsdlMsg abstract wsdl message definition to use in constructing the part elements. + */ + protected List getMessagePartsFromJBIWrapper(WSDL11JBIWrapper jbiWrapper, Message wsdlMsg) + throws MessagingException, ParserConfigurationException { + + List msgParts = new ArrayList(); + int jbiPartCount = jbiWrapper.getPartCount(); + List wsdlParts = wsdlMsg.getOrderedParts(null); + QName msgType = jbiWrapper.getType(); + if (!wsdlMsg.getQName().getNamespaceURI().equals(msgType.getNamespaceURI())) { + throw new MessagingException("Namespace mismatch between jbi wrapper message type and wsdl message"); + } + Document newDoc = jbiWrapper.getDocumentBuilder().newDocument(); + for ( int i=0; i < wsdlParts.size(); ++i ) { + Part wsdlPart = (Part) wsdlParts.get(i); + if ( i >= jbiPartCount ) { + throw new MessagingException("missing message content for part " + wsdlPart.getName()); + } + if ( wsdlPart.getElementName() != null ) { + msgParts.add(jbiWrapper.getPartAsElement(i)); + } else { + // it is type. create a new element for a typed part + // check the element name is same as part + String prefix = msgType.getPrefix(); + String nsURI = msgType.getNamespaceURI(); + String localName = wsdlPart.getName(); + Element partEl = newDoc.createElementNS(nsURI, prefix + ":" + localName); + partEl.setAttributeNS(XMLNS_NS, "xmlns:"+prefix, nsURI); + NodeList partContent = jbiWrapper.getPart(i); + appendChildren(partEl, partContent, newDoc, true); + msgParts.add(partEl); + } + } + return msgParts; + } + /** + * utility method that can append the nodeList passed to it to the element children. + * @param el element node to which the nodeList should be appended + * @param doc the document object that should be used to import the nodeList + * @param importNode true if the nodeList should be imported while appending the nodeList to the + * element children. false if no import is necessary. + */ + protected void appendChildren(Element el, NodeList nodeList, Document doc, boolean importNode) { + + for ( int pIdx = 0; pIdx < nodeList.getLength(); ++pIdx) { + Node node = nodeList.item(pIdx); + if ( importNode ) { + node = doc.importNode(node, true); + } + el.appendChild(node); + } + } + /** + * @param el element from which to extract the child elements + * @return List list of child Element nodes. + */ + protected List getChildElements(Element el) { + List list = new ArrayList(); + NodeList nodeList = el.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if (!(node instanceof Element) ){ + continue; + } + list.add((Element)node); + } + return list; + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java new file mode 100644 index 000000000..de59e0360 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java @@ -0,0 +1,99 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * SEBindingExt.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.io.PrintWriter; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation classes implement wsdl 1.1 extension model for the + * jbi service engine binding that is defined in jsr 208(sec. 5.5.6.1). to read/write concrete binding + * element in the wsdl definition for the service endpoint binding provided by the service engine. + * The wsdl definition with this binding information can be used in providing the service provider + * metadata returned by the service engine in Component.getServiceDescription. + *

+ * AbstractExtensionRegistry by default include this extension serializers in the + * registry to read/write this service engine binding type in the wsdl definition. + *

+ * During a service unit deployment/initialization in the service engine, the deployed wsdl definition + * is loaded and modified to provide this binding for the service provided by the engine. + * + * @see WSDLProcessor${symbol_pound}createServiceEngineBinding + * @see AbstractExtensionRegistry + * @see com.sun.jbi.sample.component.common.deployment.ServiceUnit${symbol_pound}loadServiceDefinitions + * @author chikkala + */ +public interface SEBindingExt extends ExtensibilityElement, java.io.Serializable { + + public static final String NS_URI = "http://java.sun.com/xml/ns/jbi/binding/service+engine"; + public static final String NS_DEF_PREFIX = "jbise"; + /** Element names. */ + public static final String EL_BINDING_EXT = "binding"; + /**Qualified element names.*/ + public static final QName QN_BINDING_EXT = new QName(NS_URI, EL_BINDING_EXT); + + public static class SEBindingExtImpl extends AbstractExtensibilityElement implements SEBindingExt { + + public SEBindingExtImpl() { + setElementType(QN_BINDING_EXT); + } + @Override + public String toString() { + StringBuffer buff = new StringBuffer(); + buff.append("<"+NS_DEF_PREFIX+":"+EL_BINDING_EXT); + buff.append("/>"); + return buff.toString(); + } + /** + * creates and adds the jbi service engine binding extensibility element to the wsdl definition + * under specified binding definition. + */ + public static SEBindingExtImpl addExtensibilityElement(Definition wsdlDef, Binding binding) { + SEBindingExtImpl bindingExt = new SEBindingExt.SEBindingExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, binding, bindingExt, SEBindingExt.NS_DEF_PREFIX); + return bindingExt; + } + } + /** + * serializer and descrializer implementation for the binding extension element. + */ + public static class SEBindingExtSerializer extends AbstractExtensionSerializer { + + public SEBindingExtSerializer() { + super(Binding.class, QN_BINDING_EXT, SEBindingExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + SEBindingExt extObj = (SEBindingExt)extReg.createExtension(parentType, elementType); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg ) throws WSDLException { + + String elName = getQualifiedName(def, NS_URI, EL_BINDING_EXT); + + SEBindingExt extObj = (SEBindingExt)extension; + + StringBuffer buff = new StringBuffer(); + buff.append("<" + elName ); + buff.append("/>"); + pw.println(buff.toString()); + } + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java new file mode 100644 index 000000000..92606104d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java @@ -0,0 +1,471 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * WSDL11JBIWrapper.java + * + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.dom.DOMSource; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +/** + * This class wraps the wsdl11 messages to the jbi wrapper message suitable for + * processing in the wsdl2.0 model of the normalized message in jbi as defined in jsr208 like + * + * + * + * + * + * + * + * + * + * + * @author chikkala + */ +public class WSDL11JBIWrapper { + + public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/"; + public static final String WRAPPER_NAMESPACE = "http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper"; + public static final String DEF_NS_PREFIX = "jbiwrp"; + public static final String DEF_MESSAGE_NS_PREFIX = "msgns"; + public static final String JBI_MESSAGE_EL = "message"; + public static final String JBI_PART_EL = "part"; + public static final String VERSION_ATTR = "version"; + public static final String VERSION_ATTR_VALUE = "1.0"; + public static final String TYPE_ATTR = "type"; + public static final String NAME_ATTR = "name"; + + private static DocumentBuilder sDocBuilder = null; + /** qname of message attribute from wsdl:input, wsdl:output or wsdl:fault */ + private QName mType; + /** optional name attribute from wsdl:input, wsdl:output or wsdl:fault */ + private String mName; + /** each parts contents as node list */ + List mPartConentList = new ArrayList(); + + /** Creates a new instance of WSDL11JBIWrapper */ + public WSDL11JBIWrapper() { + } + /** creates the namespace aware document builder. extended classes can override this method + * to return the doc builder created else where. + */ + protected DocumentBuilder createDocumentBuilder() throws ParserConfigurationException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + return factory.newDocumentBuilder(); + } + /** return the document builder + * @return DocumentBuilder + */ + public final DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { + if ( WSDL11JBIWrapper.sDocBuilder == null ) { + WSDL11JBIWrapper.sDocBuilder = createDocumentBuilder(); + } + return WSDL11JBIWrapper.sDocBuilder; + } + /** + * @return type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + */ + public QName getType() { + return this.mType; + } + /** + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + */ + public void setType(QName type) { + this.mType = type; + } + /** @return name attribute from wsdl:input, wsdl:output or wsdl:fault. or null if not set. */ + public String getName() { + return this.mName; + } + /** + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault. can be null. + */ + public void setName(String name) { + this.mName = name; + } + /** + * appends part content as node list + */ + public void appendPart(NodeList partContent) { + this.mPartConentList.add(partContent); + } + /** + * append part content from the List of nodes + */ + public void appendPart(List partContent) { + this.mPartConentList.add(new NodeListImpl(partContent)); + } + /** + * append part content as element + */ + public void appendPart(Element partContent) { + this.mPartConentList.add(new NodeListImpl(partContent)); + } + /** + * append part content from DOMSource + */ + public void appendPart(DOMSource partContent) { + Element partConentEl = getElement(partContent.getNode()); + this.mPartConentList.add(new NodeListImpl(partConentEl)); + } + /** + * append part content as text node. + */ + public void appendPart(String partContent) { + Text textContent = null; + try { + textContent = this.getDocumentBuilder().newDocument().createTextNode(partContent); + } catch (ParserConfigurationException ex) { + ex.printStackTrace(); + } + if ( textContent != null ) { + this.mPartConentList.add(new NodeListImpl(textContent)); + } + } + /** + * append list of part contents each is a NodeList to the parts + */ + public void appendParts(List partContentList) { + this.mPartConentList.addAll(partContentList); + } + /** + * returned the ordered list of part contents. + */ + public List getParts() { + return Collections.unmodifiableList(this.mPartConentList); + } + /** + * return the number of parts + */ + public int getPartCount() { + return this.mPartConentList.size(); + } + /** + * return the part content at a particular index as NodeList. + */ + public NodeList getPart(int idx) { + return this.mPartConentList.get(idx); + } + /** + * return part context at a particular index as text + */ + public String getPartAsText(int idx) { + NodeList partNodes = getPart(idx); + Document doc; + try { + doc = this.getDocumentBuilder().newDocument(); + Element el = doc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_PART_EL); + for ( int i=0; i < partNodes.getLength(); ++i) { + el.appendChild(partNodes.item(i)); + } + return el.getTextContent(); + } catch (ParserConfigurationException ex) { + return null; + } + } + /** + * return part context at a particular index as Element + */ + public Element getPartAsElement(int idx) { + Element contentEl = null; + NodeList partNodes = getPart(idx); + for ( int i=0; i < partNodes.getLength(); ++i) { + Node node = partNodes.item(i); + if ( node instanceof Element) { + contentEl = (Element)node; + break; + } + } + return contentEl; + } + /** + * creates Document from this wrapper object. Before calling this method, + * the type, name (optional) and parts contents should be set. + * @return Document containing the wsdl 11 wrapper xml + */ + public Document toDocument() throws ParserConfigurationException { + + Document wrapperDoc = getDocumentBuilder().newDocument(); + Element jbiMessage = wrapperDoc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_MESSAGE_EL); + jbiMessage.setAttribute(VERSION_ATTR, VERSION_ATTR_VALUE); + wrapperDoc.appendChild(jbiMessage); + + QName type = this.getType(); + if ( type == null ) { + type = new QName("", "", DEF_MESSAGE_NS_PREFIX); + } + // set the jbiMessage attributes + String prefix = type.getPrefix(); + if (prefix == null || prefix.length() == 0) { + prefix = DEF_MESSAGE_NS_PREFIX; + } + jbiMessage.setAttribute(TYPE_ATTR, prefix + ":" + type.getLocalPart()); + jbiMessage.setAttributeNS( XMLNS_NS, "xmlns:" + prefix, type.getNamespaceURI()); + + String name = this.getName(); + if (name != null && name.trim().length() > 0 ) { + jbiMessage.setAttribute(NAME_ATTR, name); + } + + List partContentList = this.getParts(); + for ( NodeList nodeList : partContentList ) { + // set jbi part message + Element jbiPart = wrapperDoc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_PART_EL); + jbiMessage.appendChild(jbiPart); + for ( int i =0; i < nodeList.getLength(); ++i ) { + Node importedMsgNode = wrapperDoc.importNode(nodeList.item(i), true); + jbiPart.appendChild(importedMsgNode); + } + } + + return wrapperDoc; + + } + /** + * creates DOMSource from this wrapper object. Before calling this method, + * the type, name (optional) and parts contents should be set. + * @return DOMSource containing the wsdl 11 wrapper xml + */ + public DOMSource toDOMSource() throws ParserConfigurationException { + DOMSource wrappedSource = new DOMSource(); + wrappedSource.setNode(toDocument()); + return wrappedSource; + } + /** + * return Element node from a document node or non document. Use to extract + * the message root element. + * @root node from which the Element node will be extracted. + * @return Element node. + */ + public static Element getElement(Node root) { + Element msgEl = null; + if ( root instanceof Document) { + msgEl = ((Document)root).getDocumentElement(); + } else if (root instanceof Element) { + msgEl = (Element)root; + } else { + NodeList nodeList = root.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if ( node instanceof Element ) { + msgEl = (Element) node; + break; + } + } + } + return msgEl; + } + /** + * creates wrapper object from the DOMSource that has wsdl 11 wrapper xml. + * @param wrappedMsg wsdl 11 wrapper xml as DOMSource + * @return WSDL11JBIWrapper representing the wrapper xml. + */ + public static WSDL11JBIWrapper sourceToWrapper(DOMSource wrappedMsg) { + Element jbiMessage = getElement(wrappedMsg.getNode()); + if ( jbiMessage == null ) { + return null; + } + String nsURI = jbiMessage.getNamespaceURI(); + String tagName = jbiMessage.getLocalName(); + if (!WRAPPER_NAMESPACE.equals(nsURI) || !JBI_MESSAGE_EL.equals(tagName)) { + return null; + } + String name = jbiMessage.getAttribute(NAME_ATTR); + String typeQN = jbiMessage.getAttribute(TYPE_ATTR); + String typePrefix = ""; + String typeName = ""; + if ( typeQN != null && typeQN.trim().length() > 0 ) { + int idx = typeQN.indexOf(':'); + if ( idx >= 0 ) { + typePrefix = typeQN.substring(0, idx); + if ( typeQN.length() > idx ) { + typeName = typeQN.substring(idx+1); + } + } else { + typePrefix = ""; + typeName = typeQN; + } + } + String typeURI = jbiMessage.getAttribute("xmlns:" + typePrefix); + QName typeQName = new QName(typeURI, typeName, typePrefix); + + WSDL11JBIWrapper wrapper = new WSDL11JBIWrapper(); + wrapper.setName(name); + wrapper.setType(typeQName); + NodeList jbiPartList = jbiMessage.getElementsByTagNameNS(WRAPPER_NAMESPACE, JBI_PART_EL); + for ( int i=0; i < jbiPartList.getLength(); ++i) { + Node jbiPart = jbiPartList.item(i); + wrapper.appendPart(jbiPart.getChildNodes()); + } + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object and sets the type and name of the object + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name ) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = new WSDL11JBIWrapper(); + wrapper.setName(name); + wrapper.setType(type); + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object. useful when the message has one part and the + * part content has multiple child element. + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @param partContent part content as node list + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name, NodeList partContent) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name); + wrapper.appendPart(partContent); + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object. useful when the message has one part and the + * part content is a single element + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @param partContent part content as node list + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name, Element msgEl) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name, new WSDL11JBIWrapper.NodeListImpl(msgEl)); + return wrapper; + } + + public static WSDL11JBIWrapper createWrapper(QName type, String name, DOMSource inputSource) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name); + Node msgNode = getElement(inputSource.getNode()); + NodeList nodeList = new WSDL11JBIWrapper.NodeListImpl(msgNode); + wrapper.appendPart(nodeList); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations input element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createInputWrapper(Operation operation) throws ParserConfigurationException { + QName type = null; + String name = null; + + Input input = operation.getInput(); + if ( input == null ) { + return null; + } + name = input.getName(); + Message wsdlMsg = input.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations output element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createOutputWrapper(Operation operation) throws ParserConfigurationException { + QName type = null; + String name = null; + + Output output = operation.getOutput(); + if ( output == null) { + return null; + } + name = output.getName(); + Message wsdlMsg = output.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations output element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @param faultName fault name, can be null to look for the fault with no name. + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createFaultWrapper(Operation operation, String faultName) throws ParserConfigurationException { + QName type = null; + String name = null; + @SuppressWarnings("unchecked") + Map faultMap = operation.getFaults(); + Fault fault = faultMap.get(faultName); + + if ( fault == null ) { + return null; + } + name = fault.getName(); + Message wsdlMsg = fault.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * NodeList implementation. + */ + public static class NodeListImpl extends ArrayList implements NodeList { + + public NodeListImpl() { + super(); + } + + public NodeListImpl(Node aNode) { + super(); + if (aNode != null) { + this.add(aNode); + } + } + + public NodeListImpl(List nodes) { + if (nodes != null) { + this.addAll(nodes); + } + } + + public int getLength() { + return this.size(); + } + + public Node item(int idx) { + return this.get(idx); + } + + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java new file mode 100644 index 000000000..b5a1bb331 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java @@ -0,0 +1,419 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * WSDLProcessor.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ElementExtensible; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.wsdl.xml.WSDLWriter; +import javax.xml.namespace.QName; + +/** + * This class is used to configure jwsdl(wsdl4j) to read and process wsdl documents with wsdl extensions. + * It provides set of helper methods to read and process the wsdl definitions from files with .wsdl + * extension from a specified directory. + *

+ * A Binding Component that is processing the wsdl extensions for its deployment configuration would + * extend this class and provide the required ExtensionRegistry that will have the extension serializers + * and deserializers configured to read/write the extensions from/to the java model. + *

+ * A Service Engine that is processing the wsdl during deployment can directly use this class + * to process the wsdl as the default implementation returned by this class configures the wsdl extension + * registry to read/write the service engine binding extensions. + * + * @see AbstractExtensionRegistry + * @see SEBindingExt + * @author chikkala + */ +public class WSDLProcessor { + + private String mXmlCatalogPath = "xml-catalog.xml"; + private String mWsdlDirPath = ""; + private WSDLReader mReader; + + /** Creates a new instance of WSDLProcessor + */ + public WSDLProcessor(String wsdlDir) { + this(wsdlDir, null); + } + /** Creates a new instance of WSDLProcessor + */ + public WSDLProcessor(String wsdlDir, String xmlCatPath) { + if ( wsdlDir != null ) { + this.mWsdlDirPath = wsdlDir; + } + if ( xmlCatPath != null ) { + this.mXmlCatalogPath = xmlCatPath; + } + } + /** @return directory path from which this class reads the wsdl files with .wsdl as file extension. */ + public String getWSDLDirectory() { + return this.mWsdlDirPath; + } + /** path to the xml catalog file in the service unit which can be used for Catalog-based entity + * and URI resolution. + */ + public String getXmlCatelogPath() { + return this.mXmlCatalogPath; + } + /** wsdl extension registry required for processing the wsdl extensions in the wsdl definition to + * java model. Binding component that is processing the wsdl extensions for its deployment + * configuration would provide the required ExtensionRegistry that will have the extension serializers + * and deserializers configured to read/write the extensions from/to the java model. + * @return ExtensionSerializer + * @see AbstractExtensionSerializer + */ + protected ExtensionRegistry getExtensionRegistry() { + return new AbstractExtensionRegistry() { + protected List createSerializers() { + return new ArrayList(); + } + }; + } + /** + * @return the WSDLReader configured with extension registry to process the wsdl extensions. + */ + public final WSDLReader getWSDLReader() throws WSDLException { + if ( this.mReader == null ) { + WSDLFactory factory = WSDLFactory.newInstance(); + this.mReader = factory.newWSDLReader(); + // reader.setFeature("javax.wsdl.verbose", true); + // reader.setFeature("javax.wsdl.importDocuments", true); + this.mReader.setExtensionRegistry(getExtensionRegistry()); + } + return this.mReader; + } + /** + * reads the wsdl file and returns the wsdl definition jwsdl model. + * @param wsldFilePath relative path to wsdl file from the the root wsdl directory returns from + * ${symbol_pound}getWSDLDirectory in the service unit or or absolute path . + * @return Definition + */ + public Definition readWSDL(String wsdlFilePath) throws WSDLException { + File wsdlFile = new File(wsdlFilePath); + if ( !wsdlFile.isAbsolute() ) { + wsdlFile = new File(this.mWsdlDirPath, wsdlFilePath); + } + return getWSDLReader().readWSDL(wsdlFile.getAbsolutePath()); + } + /** + * reads the files with .wsdl file extension in a directory. If the directory should + * be searched recursively, it searches this directory, all child directories of this + * directory and then to their child directories recursively. + * @param dir directory file to search for .wsdl files + * @param rec if set to true, it recursively searches the directory. if set to false, only + * this directory is searched. + * @return List of Files with .wsdl extension. + */ + public List listWSDLFiles(File dir, final boolean rec) throws IOException { + if ( dir == null || !dir.isDirectory()) { + throw new IOException(dir + " is not a directory for looking up wsdl files"); + } + List wsdlList = new ArrayList(); + File[] files = dir.listFiles(new FileFilter() { + public boolean accept(File pathname) { + if ( rec && pathname.isDirectory()) { + return true; + } else { + String name = pathname.getName(); + int idx = name.lastIndexOf('.'); + if ( idx < 0 ) { + return false; + } + String ext = name.substring(idx); + return ".wsdl".equalsIgnoreCase(ext); + } + } + }); + for ( File file : files ) { + if ( rec && file.isDirectory()) { + List wsdlFiles = listWSDLFiles(file, rec); + wsdlList.addAll(wsdlFiles); + } else { + wsdlList.add(file); + } + } + return wsdlList; + } + /** + * reads the files with .wsdl file extension in a directory fromDir and return the list of + * wsdl definitions corresponding to them. + * @param fromDir path to the directory relative to the root wsdl directory returns from + * ${symbol_pound}getWSDLDirectory or the absolute path to the directory. + */ + public List readWSDLs(String fromDir) throws WSDLException { + if ( fromDir == null ) { fromDir = ""; } + File wsdlDir = new File(fromDir); + if (!wsdlDir.isAbsolute()) { + wsdlDir = new File(this.mWsdlDirPath, fromDir); + } + + List wsdlFiles = new ArrayList(); + try { + wsdlFiles = listWSDLFiles(wsdlDir, true); + } catch (IOException ioEx) { + throw new WSDLException("WSDLFileReadError", ioEx.getMessage(),ioEx); + } + + List wsdlPaths = new ArrayList(); + for ( File wsdlFile : wsdlFiles) { + wsdlPaths.add(wsdlFile.getAbsolutePath()); + } + Collections.sort(wsdlPaths); + + List wsdlList = new ArrayList(); + for ( String wsdlPath : wsdlPaths ) { + Definition wsdlDef = readWSDL(wsdlPath); + wsdlList.add(wsdlDef); + } + return wsdlList; + } + /** + * finds PortType using port type ( interface ) qname. + */ + public static PortType findInterface(Definition wsdlDef, QName interfaceName) { + return wsdlDef.getPortType(interfaceName); + } + /** finds the Service using service qname */ + public static Service findService(Definition wsdlDef, QName serviceName) { + return wsdlDef.getService(serviceName); + } + /** finds the wsdl port using service qname and endpoint name */ + public static Port findServiceEndpoint(Definition wsdlDef, QName serviceName, String endpointName) { + Service service = null; + Port port = null; + service = findService(wsdlDef, serviceName); + if ( service != null ) { + port = service.getPort(endpointName); + } + return port; + } + /** + * finds the binding definition to which the service with serviceName and endpointName was bound. + */ + public static Binding findServiceBinding(Definition wsdlDef, QName serviceName, String endpointName) { + Binding binding = null; + Port port = findServiceEndpoint(wsdlDef, serviceName, endpointName); + if ( port != null ) { + binding = port.getBinding(); + } + return binding; + } + /** + * finds the binding definition using the interface(portType) qname with a + */ + public static Binding findInterfaceBinding(Definition wsdlDef, + QName interfaceQName, QName extQName) { + Map bindingMap = wsdlDef.getBindings(); + @SuppressWarnings("unchecked") + Collection bindings = bindingMap.values(); + for ( Binding binding : bindings ) { + if ( binding.getPortType().getQName().equals(interfaceQName)) { + return binding; + } + } + return null; + } + + /** + * find the wsdl4j operation corresponds to the interface+operation. + * @param wsdlDef wsdl definition + * @param portTypeQName portType QName + * @param opName operation name. if null, first operation in the portType + * is returned. + * @return Operation corresponding to the portType+opName + */ + public static Operation findOperation(Definition wsdlDef, + QName portTypeQName, String opName) { + Operation operation = null; + PortType portType = wsdlDef.getPortType(portTypeQName); + if ( portType != null ) { + if ( opName != null ) { + operation = portType.getOperation(opName, null, null); + } else { + @SuppressWarnings("unchecked") + List list = portType.getOperations(); + if ( list != null && list.size() > 0 ) { + operation = list.get(0); + } + } + } + return operation; + } + /** + * verifies whether the wsdl definition contains the specified service descriptions or not. Used + * to locate the wsdl definition for the services describes in service unit deployment + * descriptor(jbi.xm). + * @param interfaceName portType qname to find in the definition. can be null if you are trying to + * find only service endpoint description. + * @param serviceName qname for the service to find in this wsdl. can be null if + * you are trying to find only portType (abstract service) description. + * @param endpointName port name to find in the service definition. null if only + * service with any port should be looked up. + * + * @return true if the wsdl definition contains the specified service description. + */ + public static boolean isWSDLFor(Definition wsdlDef, + QName interfaceName, QName serviceName, String endpointName) { + PortType portType = null; + Service service = null; + Port port = null; + if ( interfaceName != null ) { + portType = findInterface(wsdlDef, interfaceName); + } + + if ( serviceName != null ) { + service = findService(wsdlDef, serviceName); + } + + if ( endpointName != null && service != null ) { + port = service.getPort(endpointName); + } + + boolean isWSDL = true; + + if ( (interfaceName != null && portType == null) || + ( serviceName != null && service == null ) || + ( endpointName != null && (service == null || port == null)) ) { + isWSDL = false; + } + + return isWSDL; + } + /** + * creates a binding definition that contains a service engine binding elements in the specified + * wsdl definition for a portType. It will try to find/create the binding element with interface + * local name with a "_JBISEBinding" suffix and add service engine binding element to it if it + * is not present. + * @param wsdl wsdl definition + * @param interfaceName portType qname to which the binding is created. + * @return a Binding contains service engine binding that is created for the portType. + */ + public Binding createServiceEngineBinding(Definition wsdl, QName interfaceName) { + QName bindingQName = new QName(wsdl.getQName().getNamespaceURI(), + interfaceName.getLocalPart() + "_JBISEBinding"); + Binding binding = wsdl.getBinding(bindingQName); + if ( binding == null ) { + binding = wsdl.createBinding(); + binding.setQName(bindingQName); + binding.setPortType(wsdl.getPortType(interfaceName)); + binding.setUndefined(false); + + ExtensibilityElement bindingExt = + SEBindingExt.SEBindingExtImpl.addExtensibilityElement(wsdl, binding); + + wsdl.addBinding(binding); + } + return binding; + } + /** + * creates port and binding elements that provide the the service engine binding for a service. + * @param wsdl wsdl definition + * @param interfaceName portType qname to which the binding is created. + * @param serviceName service under which the port definition bound to the service engine binding + * should be created. + * @param endpointName port name. + * @return a Binding contains service engine binding that is created for the portType. + */ + public Binding createServiceEngineBinding(Definition wsdl, QName interfaceName, QName serviceName, String endpointName ) { + Binding binding = null; + Service service = findService(wsdl, serviceName); + if ( service == null ) { + return null; + } + Port port = service.getPort(endpointName); + if ( port != null ) { + binding = port.getBinding(); + } else { + // create port + port = wsdl.createPort(); + port.setName(endpointName); + binding = createServiceEngineBinding(wsdl, interfaceName); + port.setBinding(binding); + service.addPort(port); + } + return binding; + } + /** prints the wsdl to text from the wsdl definition */ + public static void printWSDL(PrintWriter out, Definition def) { + try { + WSDLFactory factory = WSDLFactory.newInstance(); + WSDLWriter wsdlWriter = factory.newWSDLWriter(); + wsdlWriter.writeWSDL(def, out); + } catch (WSDLException ex) { + ex.printStackTrace(out); + } + } + /** prints the wsdl to text from the wsdl definition */ + public static String printWSDLToString(Definition def) { + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + printWSDL(out, def); + out.close(); + return writer.getBuffer().toString(); + } + /** returns an existing namespace prefix or create one if not exists for the corresponding namespaceURI */ + public static String getNamespacePrefix(Definition def, String namespaceURI, String defPrefix) { + String prefix = null; + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + Set keySet = def.getNamespaces().keySet(); + String newPrefix = "ns"; + if ( defPrefix != null && defPrefix.trim().length() > 0 ){ + newPrefix = defPrefix; + } + prefix = newPrefix; + for ( int i=0; i < Integer.MAX_VALUE; ++i) { + if (!keySet.contains(prefix)) { + break; + } else { + prefix = newPrefix + i; + } + } + } + return prefix; + } + + /** + * creates and adds the jbi service engine binding extensibility element to the wsdl definition + * under specified binding definition. + */ + public static void addExtensibilityElement(Definition wsdlDef, + ElementExtensible extensibleEl, ExtensibilityElement extEl, String defPrefix) { + QName elementType = extEl.getElementType(); + String namespaceURI = elementType.getNamespaceURI(); + String prefix = wsdlDef.getPrefix(namespaceURI); + if ( prefix == null ) { + // no namespace prefix defined. create one. + prefix = WSDLProcessor.getNamespacePrefix(wsdlDef, namespaceURI, defPrefix); + wsdlDef.addNamespace(prefix, namespaceURI); + } + extensibleEl.addExtensibilityElement(extEl); + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/BindingExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/BindingExt.java new file mode 100644 index 000000000..f61d31f64 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/BindingExt.java @@ -0,0 +1,101 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * BindingExt.java + */ +package net.openesb.component.${artifactId}.wsdlext; + +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * extension element. The inner classes BindingExtImpl implements the interface + * and the BindingExtSerializer provides the serializer and deserializer + * implementation. The implementation and serializer classes will be registered + * with the ExtensionRegistry to process the binding extension element in the + * wsdl definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface BindingExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + //TODO: define get/set methods for properties for BindingExt if the extension element has attributes. + + /** + * This class is an implementation of BindingExt interface that provides + * java model for binding extensibility element. + */ + public static class BindingExtImpl extends AbstractExtensibilityElement implements BindingExt { + + public BindingExtImpl() { + setElementType(QN_BINDING_EXT); + } + + /** + * creates and adds the binding extensibility element to the wsdl + * definition + */ + public static BindingExtImpl addExtensibilityElement(Definition wsdlDef, Binding binding) { + BindingExtImpl bindingExt = new BindingExt.BindingExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, binding, bindingExt, NS_DEF_PREFIX); + return bindingExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * binding extensibility element. + */ + public static class BindingExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public BindingExtSerializer() { + super(Binding.class, QN_BINDING_EXT, BindingExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + BindingExt extObj = (BindingExt) extReg.createExtension(parentType, elementType); + //TODO: set any attributes from the el to extension object + // String myAttr = el.getAttribute(ATTR_MY_ATTR); + // extObj.setMyAttr(myAttr); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + BindingExt extObj = (BindingExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_BINDING_EXT); + buff.append("<" + elName); + + //TODO: append any attributes from extension obj to the element + // String myAttr = extObj.getMyAttr(); + // if ( myAttr != null && myAttr.trim().length() > 0 ) { + // buff.append(" myAttr=${symbol_escape}"" + myAttr + "${symbol_escape}""); + // } + // + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/ExtConstants.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/ExtConstants.java new file mode 100644 index 000000000..2a7b8d153 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/ExtConstants.java @@ -0,0 +1,52 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ExtConstants.java + * + */ +package net.openesb.component.${artifactId}.wsdlext; + +import javax.xml.namespace.QName; + +/** + * This interface defines the constants for the namespace, elements, attributes + * and qnames corresponding to the wsdl extensions that this component + * processes. These constants will be used in the wsdl extension model used to + * process a particular wsdl extensions. + * + * @see WSDLExtensionRegistry + * @see PortExt + * @see BindingExt + * @author chikkala + */ +public interface ExtConstants { + + public static final String NS_URI_WSDL = "http://schemas.xmlsoap.org/wsdl/"; + public static final String NS_URI_XMLNS = "http://www.w3.org/2000/xmlns/"; + /** + * wsdl extension namespace processed by this wsdl extension model + */ + public static final String NS_URI = "http://java.sun.com/jbi/wsdl-extensions/sample/jmx-bc/"; + public static final String NS_DEF_PREFIX = "jmxbc"; + // wsdl extension element names. + public static final String EL_BINDING_EXT = "binding"; + public static final String EL_OPERATION_EXT = "operation"; + public static final String EL_INPUT_EXT = "input"; + public static final String EL_OUTPUT_EXT = "output"; + public static final String EL_FAULT_EXT = "fault"; + public static final String EL_PORT_EXT = "address"; + // Qualified wsdl extension element names. + public static final QName QN_BINDING_EXT = new QName(NS_URI, EL_BINDING_EXT); + public static final QName QN_OPERATION_EXT = new QName(NS_URI, EL_OPERATION_EXT); + public static final QName QN_INPUT_EXT = new QName(NS_URI, EL_INPUT_EXT); + public static final QName QN_OUTPUT_EXT = new QName(NS_URI, EL_OUTPUT_EXT); + public static final QName QN_FAULT_EXT = new QName(NS_URI, EL_FAULT_EXT); + public static final QName QN_PORT_EXT = new QName(NS_URI, EL_PORT_EXT); + // wsdl extension elements attribute names. + public static final String ATTR_ACTION = "action"; + public static final String ATTR_SERVICE_URL = "serviceURL"; + public static final String ATTR_USERNAME = "username"; + public static final String ATTR_PASSWORD = "password"; + public static final String ATTR_MBEAN = "mbean"; +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/FaultExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/FaultExt.java new file mode 100644 index 000000000..051573122 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/FaultExt.java @@ -0,0 +1,101 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * FaultExt.java + */ +package net.openesb.component.${artifactId}.wsdlext; + +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.BindingFault; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * operation fault extension element. The inner classes FaultExtImpl implements + * the interface and the FaultExtSerializer provides the serializer and + * deserializer implementation. The implemenation and serializer classes will be + * registered with the ExtensionRegistry to process the binding operation fault + * extension element in the wsdl definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface FaultExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + + //TODO: define getter methods for properties for FaultExt if the extension element has attributes. + /** + * This class is an implementation of FaultExt interface that provides java + * model for binding operation fault extensibility element. + */ + public static class FaultExtImpl extends AbstractExtensibilityElement implements FaultExt { + + public FaultExtImpl() { + setElementType(QN_FAULT_EXT); + } + + /** + * creates and adds the binding operation fault extensibility element to + * the wsdl definition + */ + public static FaultExtImpl addExtensibilityElement(Definition wsdlDef, BindingFault fault) { + FaultExtImpl faultExt = new FaultExt.FaultExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, fault, faultExt, NS_DEF_PREFIX); + return faultExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * binding operation fault extensibility element. + */ + public static class FaultExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public FaultExtSerializer() { + super(BindingFault.class, QN_FAULT_EXT, FaultExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + FaultExt extObj = (FaultExt) extReg.createExtension(parentType, elementType); + //TODO: set any attributes from the el to extension object + // String myAttr = el.getAttribute(ATTR_MY_ATTR); + // extObj.setMyAttr(myAttr); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + FaultExt extObj = (FaultExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_FAULT_EXT); + buff.append("<" + elName); + + //TODO: append any attributes from extension obj to the element + // String myAttr = extObj.getMyAttr(); + // if ( myAttr != null && myAttr.trim().length() > 0 ) { + // buff.append(" myAttr=${symbol_escape}"" + myAttr + "${symbol_escape}""); + // } + // + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/InputExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/InputExt.java new file mode 100644 index 000000000..bb4f45078 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/InputExt.java @@ -0,0 +1,101 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * InputExt.java + */ +package net.openesb.component.${artifactId}.wsdlext; + +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.BindingInput; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * operation input extension element. The inner classes InputExtImpl implements + * the interface and the InputExtSerializer provides the serislizer and + * deserializer implementation. The implementation and serializer classes will + * be registered with the ExtensionRegistry to process the binding operation + * input extension element in the wsdl definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface InputExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + + //TODO: define get/set methods for properties for InputExt if the extension element has attributes. + /** + * This class is an implementation of InputExt interface that provides java + * model for binding operation input extensibility element. + */ + public static class InputExtImpl extends AbstractExtensibilityElement implements InputExt { + + public InputExtImpl() { + setElementType(QN_INPUT_EXT); + } + + /** + * creates and adds the binding operation fault extensibility element to + * the wsdl definition + */ + public static InputExtImpl addExtensibilityElement(Definition wsdlDef, BindingInput input) { + InputExtImpl inputExt = new InputExt.InputExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, input, inputExt, NS_DEF_PREFIX); + return inputExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * binding operation input extensibility element. + */ + public static class InputExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public InputExtSerializer() { + super(BindingInput.class, QN_INPUT_EXT, InputExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + InputExt extObj = (InputExt) extReg.createExtension(parentType, elementType); + //TODO: set any attributes from the el to extension object + // String myAttr = el.getAttribute(ATTR_MY_ATTR); + // extObj.setMyAttr(myAttr); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + InputExt extObj = (InputExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_INPUT_EXT); + buff.append("<" + elName); + + //TODO: append any attributes from extension obj to the element + // String myAttr = extObj.getMyAttr(); + // if ( myAttr != null && myAttr.trim().length() > 0 ) { + // buff.append(" myAttr=${symbol_escape}"" + myAttr + "${symbol_escape}""); + // } + // + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/OperationExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/OperationExt.java new file mode 100644 index 000000000..c7fd384a4 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/OperationExt.java @@ -0,0 +1,121 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * OperationExt.java + */ +package net.openesb.component.${artifactId}.wsdlext; + +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * operation extension element. The inner classes OperationImpl implements the + * interface and the OperationExtSerializer provides the serilizer and + * deserializer implementation. The implementation and serializer classes will + * be registered with the ExtensionRegistry to process the binding operation + * extension element in the wsdl definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface OperationExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + + /** + * Getter for property action. + * + * @return Value of property action. + */ + public String getAction(); + + /** + * Setter for property action. + * + * @param action New value of property action. + */ + public void setAction(String action); + + /** + * This class is an implementation of OperationExt interface that provides + * java model for binding operation extensibility element. + */ + public static class OperationExtImpl extends AbstractExtensibilityElement implements OperationExt { + + private String mAction; + + public OperationExtImpl() { + setElementType(QN_OPERATION_EXT); + } + + public String getAction() { + return this.mAction; + } + + public void setAction(String action) { + this.mAction = action; + } + + /** + * creates and adds the binding operation fault extensibility element to + * the wsdl definition + */ + public static OperationExtImpl addExtensibilityElement(Definition wsdlDef, BindingOperation operation) { + OperationExtImpl operationExt = new OperationExt.OperationExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, operation, operationExt, NS_DEF_PREFIX); + return operationExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * binding operation extensibility element. + */ + public static class OperationExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public OperationExtSerializer() { + super(BindingOperation.class, QN_OPERATION_EXT, OperationExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + OperationExt extObj = (OperationExt) extReg.createExtension(parentType, elementType); + String action = el.getAttribute(ATTR_ACTION); + extObj.setAction(action); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + OperationExt extObj = (OperationExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_OPERATION_EXT); + buff.append("<" + elName); + + String action = extObj.getAction(); + if (action != null && action.trim().length() > 0) { + buff.append(" " + ATTR_ACTION + "=${symbol_escape}"" + action + "${symbol_escape}""); + } + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/OutputExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/OutputExt.java new file mode 100644 index 000000000..7c88fc9de --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/OutputExt.java @@ -0,0 +1,101 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * OutputExt.java + */ +package net.openesb.component.${artifactId}.wsdlext; + +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.BindingOutput; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * operation output extension element. The inner classes OutputExtImpl + * implements the interface and the OutputExtSerializer provides the serilizer + * and deserializer implementation. The implementation and serializer classes + * will be registered with the ExtensionRegistry to process the binding + * operation output extension element in the wsdl definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface OutputExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + + //TODO: define get/set methods for properties for OutputExt if the extension element has attributes. + /** + * This class is an implementation of OutputExt interface that provides java + * model for binding operation output extensibility element. + */ + public static class OutputExtImpl extends AbstractExtensibilityElement implements OutputExt { + + public OutputExtImpl() { + setElementType(QN_OUTPUT_EXT); + } + + /** + * creates and adds the binding operation fault extensibility element to + * the wsdl definition + */ + public static OutputExtImpl addExtensibilityElement(Definition wsdlDef, BindingOutput output) { + OutputExtImpl OutputExt = new OutputExt.OutputExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, output, OutputExt, NS_DEF_PREFIX); + return OutputExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * binding operation output extensibility element. + */ + public static class OutputExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public OutputExtSerializer() { + super(BindingOutput.class, QN_OUTPUT_EXT, OutputExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + OutputExt extObj = (OutputExt) extReg.createExtension(parentType, elementType); + //TODO: set any attributes from the el to extension object + // String myAttr = el.getAttribute(ATTR_MY_ATTR); + // extObj.setMyAttr(myAttr); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + OutputExt extObj = (OutputExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_OUTPUT_EXT); + buff.append("<" + elName); + + //TODO: append any attributes from extension obj to the element + // String myAttr = extObj.getMyAttr(); + // if ( myAttr != null && myAttr.trim().length() > 0 ) { + // buff.append(" myAttr=${symbol_escape}"" + myAttr + "${symbol_escape}""); + // } + // + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/PortExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/PortExt.java new file mode 100644 index 000000000..ca5ce4b09 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/PortExt.java @@ -0,0 +1,217 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * PortExt.java + */ +package net.openesb.component.${artifactId}.wsdlext; + +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for port + * extension element. The inner classes PortExtImpl implements the interface and + * the PortExtSerializer provides the serializer and deserializer implemenation. + * The implementation and serializer classes will be registered with the + * ExtensionRegistry to process the port extension element in the wsdl + * definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface PortExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + + /** + * Getter for property serviceURL. + * + * @return Value of property serviceURL. + */ + public String getServiceURL(); + + /** + * Setter for property serviceURL. + * + * @param serviceURL New value of property serviceURL. + */ + public void setServiceURL(String serviceURL); + + /** + * Getter for property username. + * + * @return Value of property username. + */ + public String getUsername(); + + /** + * Setter for property username. + * + * @param username New value of property username. + */ + public void setUsername(String username); + + /** + * Getter for property password. + * + * @return Value of property password. + */ + public String getPassword(); + + /** + * Setter for property password. + * + * @param password New value of property password. + */ + public void setPassword(String password); + + /** + * Getter for property name. + * + * @return Value of property name. + */ + public String getMBean(); + + /** + * Setter for property mbean. + * + * @param name New value of property mbean. + */ + public void setMBean(String mbean); + + /** + * This class is an implementation of PortExt interface that provides java + * model for port extensibility element. + */ + public static class PortExtImpl + extends AbstractExtensibilityElement implements PortExt { + + private String mServiceURL; + private String mUsername; + private String mPassword; + private String mMBean; + + public PortExtImpl() { + setElementType(QN_PORT_EXT); + } + + public String getServiceURL() { + return this.mServiceURL; + } + + public void setServiceURL(String serviceURL) { + this.mServiceURL = serviceURL; + } + + public String getUsername() { + return this.mUsername; + } + + public void setUsername(String username) { + this.mUsername = username; + } + + public String getPassword() { + return this.mPassword; + } + + public void setPassword(String password) { + this.mPassword = password; + } + + public String getMBean() { + return this.mMBean; + } + + public void setMBean(String mbean) { + this.mMBean = mbean; + } + + /** + * creates and adds the port extensibility element to the wsdl + * definition + */ + public static PortExtImpl addExtensibilityElement(Definition wsdlDef, Port port) { + PortExtImpl portExt = new PortExt.PortExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, port, portExt, NS_DEF_PREFIX); + return portExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * port extensibility element. + */ + public static class PortExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public PortExtSerializer() { + super(Port.class, QN_PORT_EXT, PortExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + PortExt extObj = (PortExt) extReg.createExtension(parentType, elementType); + + String serviceURL = el.getAttribute(ATTR_SERVICE_URL); + extObj.setServiceURL(serviceURL); + + String mbean = el.getAttribute(ATTR_MBEAN); + extObj.setMBean(mbean); + + String username = el.getAttribute(ATTR_USERNAME); + extObj.setUsername(username); + + String password = el.getAttribute(ATTR_PASSWORD); + extObj.setPassword(password); + + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + PortExt extObj = (PortExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_PORT_EXT); + buff.append("<" + elName); + + String serviceURL = extObj.getServiceURL(); + if (serviceURL != null && serviceURL.trim().length() > 0) { + buff.append(" " + ATTR_SERVICE_URL + "=${symbol_escape}"" + serviceURL + "${symbol_escape}""); + } + + String mbean = extObj.getMBean(); + if (mbean != null && mbean.trim().length() > 0) { + buff.append(" " + ATTR_MBEAN + "=${symbol_escape}"" + mbean + "${symbol_escape}""); + } + + String username = extObj.getUsername(); + if (username != null && username.trim().length() > 0) { + buff.append(" " + ATTR_USERNAME + "=${symbol_escape}"" + username + "${symbol_escape}""); + } + + String password = extObj.getUsername(); + if (password != null && password.trim().length() > 0) { + buff.append(" " + ATTR_PASSWORD + "=${symbol_escape}"" + password + "${symbol_escape}""); + } + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtHelper.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtHelper.java new file mode 100644 index 000000000..c73d4e3f6 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtHelper.java @@ -0,0 +1,223 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * WSDLExtHelper.java + */ +package net.openesb.component.${artifactId}.wsdlext; + +import java.util.List; +import javax.wsdl.Binding; +import javax.wsdl.BindingFault; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.xml.namespace.QName; + +/** + * This class is a helper class for processing the wsdl extensions. It has + * methods that help locate the extension elements and return the java models + * corresponds to the extension elements. + * + * @author chikkala + */ +public final class WSDLExtHelper { + + /** + * creates the java object for the port extension element. + * + * @param def wsdl definition + * @param serviceName QName of the service + * @param endpointName name of the port under which to lookup for the port + * extension. + * @return java object for the port extension element + */ + public static PortExt getPortExt(Definition def, QName serviceName, String endpointName) { + PortExt portExt = null; + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + @SuppressWarnings("unchecked") + List extElList = port.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof PortExt) { + portExt = (PortExt) extEl; + break; + } + } + return portExt; + } + + /** + * creates the java object for the binding extension element. + * + * @param def wsdl definition + * @param binding binding under which to lookup for the binding extension. + * @return java object for the port extension element + */ + public static BindingExt getBindingExt(Definition def, Binding binding) { + BindingExt bindingExt = null; + @SuppressWarnings("unchecked") + List extElList = binding.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof BindingExt) { + bindingExt = (BindingExt) extEl; + break; + } + } + return bindingExt; + } + + /** + * creates the java object for the binding extension element. + * + * @param def wsdl definition + * @param serviceName QName of the service + * @param endpointName name of the port that references the binding. + * @return java object for the port extension element + */ + public static BindingExt getBindingExt(Definition def, QName serviceName, String endpointName) { + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + Binding binding = port.getBinding(); + return getBindingExt(def, binding); + } + + /** + * @return OperationExt java object corresponding to the operation extension + * element under binding + */ + public static OperationExt getOperationExt(Definition def, Binding binding, String operation) { + OperationExt operationExt = null; + BindingOperation bindingOp = binding.getBindingOperation(operation, null, null); + if (bindingOp != null) { + @SuppressWarnings("unchecked") + List extElList = bindingOp.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof OperationExt) { + operationExt = (OperationExt) extEl; + break; + } + } + } + return operationExt; + } + + /** + * @return OperationExt java object corresponding to the operation extension + * element under binding + */ + public static OperationExt getOperationExt(Definition def, QName serviceName, String endpointName, String operation) { + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + Binding binding = port.getBinding(); + return getOperationExt(def, binding, operation); + } + + /** + * @return InputExt java object corresponding to input extension element of + * the the binding operation under binding + */ + public static InputExt getInputExt(Definition def, Binding binding, + String operation, String input) { + InputExt inputExt = null; + BindingOperation bindingOp = binding.getBindingOperation(operation, input, null); + if (bindingOp != null) { + BindingInput bindingInput = bindingOp.getBindingInput(); + @SuppressWarnings("unchecked") + List extElList = bindingInput.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof InputExt) { + inputExt = (InputExt) extEl; + break; + } + } + } + return inputExt; + } + + /** + * @return InputExt java object corresponding to input extension element of + * the the binding operation under binding + */ + public static InputExt getInputExt(Definition def, + QName serviceName, String endpointName, String operation, String input) { + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + Binding binding = port.getBinding(); + return getInputExt(def, binding, operation, input); + } + + /** + * @return OutputExt java object corresponding to output extension element + * of the the binding operation under binding + */ + public static OutputExt getOutputExt(Definition def, Binding binding, + String operation, String output) { + OutputExt outputExt = null; + BindingOperation bindingOp = binding.getBindingOperation(operation, null, output); + if (bindingOp != null) { + BindingOutput bindingOutput = bindingOp.getBindingOutput(); + @SuppressWarnings("unchecked") + List extElList = bindingOutput.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof OutputExt) { + outputExt = (OutputExt) extEl; + break; + } + } + } + return outputExt; + } + + /** + * @return OutputExt java object corresponding to output extension element + * of the the binding operation under binding + */ + public static OutputExt getOutputExt(Definition def, + QName serviceName, String endpointName, String operation, String output) { + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + Binding binding = port.getBinding(); + return getOutputExt(def, binding, operation, output); + } + + /** + * @return FaultExt java object corresponding to fault extension element of + * the the binding operation under binding + */ + public static FaultExt getFaultExt(Definition def, Binding binding, + String operation, String faultName) { + FaultExt faultExt = null; + BindingOperation bindingOp = binding.getBindingOperation(operation, null, null); + if (bindingOp != null) { + BindingFault bindingFault = bindingOp.getBindingFault(faultName); + if (bindingFault != null) { + @SuppressWarnings("unchecked") + List extElList = bindingFault.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof FaultExt) { + faultExt = (FaultExt) extEl; + break; + } + } + } + } + return faultExt; + } + + /** + * @return FaultExt java object corresponding to fault extension element of + * the the binding operation under binding + */ + public static FaultExt getFaultExt(Definition def, + QName serviceName, String endpointName, String operation, String faultName) { + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + Binding binding = port.getBinding(); + return getFaultExt(def, binding, operation, faultName); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtension.xsd b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtension.xsd new file mode 100644 index 000000000..1311a03c9 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtension.xsd @@ -0,0 +1,98 @@ + + + + + + + + + "binding" defines a protocol based binding details. + + + + + + + + + + + + + + "operation" defines the protocol based binding operation details. + + + + + + + + + + + + + + + "input" defines the protocol based binding input details. + + + + + + + + + + + + + + "output" defines the protocol based binding output details. + + + + + + + + + + + + + + "fault" defines the protocol based binding fault details. + + + + + + + + + + + + + + "address" indicates protocol based binding port details. + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtensionRegistry.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtensionRegistry.java new file mode 100644 index 000000000..36154acfb --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtensionRegistry.java @@ -0,0 +1,46 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * WSDLExtensionRegistry.java + */ +package net.openesb.component.${artifactId}.wsdlext; + +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensionRegistry; +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensionSerializer; +import java.util.ArrayList; +import java.util.List; + +/** + * This class extends + * AbstractExtensionRegistry to create the serializers and deserializers + * for processing wsdl extensions. + * + * @see AbstractExtensionRegistry + * @author chikkala + */ +public class WSDLExtensionRegistry extends AbstractExtensionRegistry { + + /** + * Creates a new instance of JMXBindingExtensionRegistry + */ + public WSDLExtensionRegistry() { + super(); + } + + /** + * creates serializers and deserializers for all the extension elements + */ + protected List createSerializers() { + List list = new ArrayList(); + + list.add(new BindingExt.BindingExtSerializer()); + list.add(new OperationExt.OperationExtSerializer()); + list.add(new InputExt.InputExtSerializer()); + list.add(new OutputExt.OutputExtSerializer()); + list.add(new FaultExt.FaultExtSerializer()); + list.add(new PortExt.PortExtSerializer()); + + return list; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/bindingtest/BindingComponentTest.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/bindingtest/BindingComponentTest.java new file mode 100644 index 000000000..defb6afd4 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/bindingtest/BindingComponentTest.java @@ -0,0 +1,55 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ${artifactId}Test.java + */ +package bindingtest; +import net.openesb.component.${artifactId}.test.JBIComponentTestClient; +import net.openesb.component.${artifactId}.test.JMXBindingTestClient; +import java.util.Properties; + import junit.framework.TestCase; + +/** + * The test method in this testcase uses the JMXBindingTestClient to send the + * input document to the echo service provided by service engine via the binding + * component by sending the input to the binding using jmx interface. The output + * received from the service invocation will be placed in test results directory + * under the same package as this test case. + * @see com.sun.jbi.sample.component.test.JMXBindingTestClinet + * + * @author chikkala + */ +public class BindingComponentTest + extends TestCase +{ + + public BindingComponentTest(String testName) { + super(testName); + } + + public void test1() throws Exception { + String testPropertiesPath = "test1.properties"; + JBIComponentTestClient testClient = new JMXBindingTestClient(); + Properties testProps = testClient.loadTestProperties(this.getClass(), testPropertiesPath); + testClient.testService(testProps); + } + + public void test2() throws Exception { + String testPropertiesPath = "test2.properties"; + JBIComponentTestClient testClient = new JMXBindingTestClient(); + Properties testProps = testClient.loadTestProperties(this.getClass(), testPropertiesPath); + testClient.testService(testProps); + } + + public static void main(String[] args) { + try { + BindingComponentTest compTest = new BindingComponentTest("BindingComponentTest"); + compTest.test1(); + compTest.test2(); + } catch(Exception ex) { + ex.printStackTrace(); + } + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/bindingtest/test1.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/bindingtest/test1.properties new file mode 100644 index 000000000..02707a88a --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/bindingtest/test1.properties @@ -0,0 +1,16 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} Sample ResourceBundle properties file + +${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} test properties for testing the binding component +input.file=test1Input.xml +${symbol_pound}exptected.file=Expected.xml +output.file=test1Output.xml + +consumer.jmx.bc.ep.operation=sayHello +consumer.jmx.bc.ep.address.mbean=com.sun.jbi.sample.jmxbc:jmxbc-ep-address=BindingComponent/greetings +consumer.jmx.bc.ep.address.serviceURL=service:jmx:rmi:///jndi/rmi://localhost:8686/jmxrmi +consumer.jmx.bc.ep.address.username=admin +consumer.jmx.bc.ep.address.password=this really long string is used to identify a password that has been stored in the Keyring + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/bindingtest/test1Input.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/bindingtest/test1Input.xml new file mode 100644 index 000000000..ac1004c3e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/bindingtest/test1Input.xml @@ -0,0 +1,12 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + Srinivasan + Chikkala + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/bindingtest/test2.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/bindingtest/test2.properties new file mode 100644 index 000000000..4921dee72 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/bindingtest/test2.properties @@ -0,0 +1,15 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} Sample ResourceBundle properties file + +${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} test properties for testing the binding component +input.file=test2Input.xml +${symbol_pound}exptected.file=Expected.xml +output.file=test2Output.xml + +consumer.jmx.bc.ep.operation=sayGoodbye +consumer.jmx.bc.ep.address.mbean=com.sun.jbi.sample.jmxbc:jmxbc-ep-address=BindingComponent/greetings +consumer.jmx.bc.ep.address.serviceURL=service:jmx:rmi:///jndi/rmi://localhost:8686/jmxrmi +consumer.jmx.bc.ep.address.username=admin +consumer.jmx.bc.ep.address.password=this really long string is used to identify a password that has been stored in the Keyring diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/bindingtest/test2Input.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/bindingtest/test2Input.xml new file mode 100644 index 000000000..31058414d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/bindingtest/test2Input.xml @@ -0,0 +1,12 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + Srinivasan + Chikkala + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java new file mode 100644 index 000000000..919ad6829 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java @@ -0,0 +1,298 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JBIComponentTestClient.java + */ + +package net.openesb.component.${artifactId}.test; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Properties; + +/** + * This class implements the base framework for the testing the JBI components. + * Testing the JBI component involves may require deploying a service to the + * component(s) to enable the service provided by the test component and then + * invoking the service provided by the test component. If the test component is + * a binding component, then a service provider component such as sample service + * engine is required to test the component end to end. If the test component is a + * service engine, then the service on the test component can be invoked via + * soap/http binding component. + * + * This class provides the utilites to read the test properties, read the input + * message from the file and save the output to the file. The testService + * method implemented here can be executed as the test for the component. The + * testService method calls the invokeService method with the input document and + * expects a output document or error that will be saved to the output file. + * The method invokeService should be implemented by the extended test classes to + * inplement a suitable service consumer implemenation for the test compoent. + * See JMXBindingTestClient.java or SOAPBidningTestClient.java for more details + * on how to implement a partucular test service consumer. + * + * @author chikkala + */ +public abstract class JBIComponentTestClient { + + public static final String TEST_PROPS_FILE_PROP = "test.properties.file"; + public static final String TEST_RESULTS_DIR_PROP = "test.results.dir"; + public static final String TEST_SRC_DIR_PROP = "test.src.dir"; + + public static final String TEST_PACKAGE_PROP = "test.package.name"; + + public static final String INPUT_FILE_PROP = "input.file"; + public static final String EXPECTED_FILE_PROP = "expected.file"; + public static final String OUTPUT_FILE_PROP = "output.file"; + + public static final String DEF_TEST_PROP_FILE = "test.properties"; + public static final String DEF_INPUT_FILE = "Input.xml"; + public static final String DEF_OUTPUT_FILE = "Output.xml"; + public static final String DEF_TEST_RESULTS_DIR = "test-results"; + + public JBIComponentTestClient() { + } + /** + * returns the absolute resource path w.r.t. the packagePath if the resource name + * is relative else return the resourceName as it is. + * @param package name ( dot separated ) + * @param resourcName dot separated name or a absolute resource path + * @return abosolute resource path with path separator + */ + public static String resolveResourcePath(String packageName, String resourceName) { + String resourcePath = resourceName; + if ( !resourceName.startsWith("/")) { + // it is relative resource file. resolve it w.r.t. testPackage + String pkgDir = packageName.trim().replace('.', '/'); + if ( pkgDir.length() != 0 ) { + pkgDir += "/"; + } + resourcePath = "/" + pkgDir + resourceName; + } + return resourcePath; + } + /** + * loads the resource file as properties. + * @param testPackage package name where this test belongs + * @param testPropPath resource path relative to testPackage or absolute resource path + */ + public Properties loadTestProperties(String testPackage, String testPropPath) throws IOException { + String propsResourcePath = resolveResourcePath(testPackage, testPropPath); + + InputStream testPropIS = null; + try { + testPropIS = this.getClass().getResourceAsStream(propsResourcePath); + Properties testProps = new Properties(); + testProps.load(testPropIS); + testProps.setProperty(TEST_PACKAGE_PROP, testPackage); + return testProps; + } finally { + if ( testPropIS != null ) { + try { + testPropIS.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + } + /** + * load default test properties file in the testClass package. + * @param testClass Class where to look for the default test properties + * @param testPropPath resource path relative to testPackage or absolute resource path + * @return Properties test properties + */ + public Properties loadTestProperties(Class testClass, String testPropPath) throws IOException { + return loadTestProperties(testClass.getPackage().getName(), testPropPath ); + } + /** + * load default test properties file in the testClass package. + * @param testClass Class where to look for the default test properties + * @return Properties test properties + */ + public Properties loadTestProperties(Class testClass) throws IOException { + return loadTestProperties(testClass.getPackage().getName(), DEF_TEST_PROP_FILE ); + } + /** + * loads the resource file to string bugger + * @param inputFile resource file path + */ + public StringBuffer loadResourceFile(String resourcePath) throws FileNotFoundException, IOException { + + InputStream inputIS = null; + InputStreamReader inputReader = null; + BufferedReader reader = null; + StringWriter strWriter = null; + PrintWriter writer = null; + try { + inputIS = this.getClass().getResourceAsStream(resourcePath); + inputReader = new InputStreamReader(inputIS); + reader = new BufferedReader(inputReader); + strWriter = new StringWriter(); + writer = new PrintWriter(strWriter); + for ( String line = null; (line = reader.readLine()) != null ; ) { + writer.println(line); + } + writer.close(); + strWriter.close(); + return strWriter.getBuffer(); + } finally { + if ( inputIS != null ) { + try { + inputIS.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + } + + /** + * reads data from the reader and saves to file + * @param reader reader from which to read the data and save to file + * @param outputFilePath absolute file path + */ + public void saveOutputToFile(Reader reader, String outputFilePath) throws IOException { + + BufferedReader buff = null; + FileWriter fileWriter = null; + PrintWriter writer = null; + try { + buff = new BufferedReader(reader); + fileWriter = new FileWriter(outputFilePath); + writer = new PrintWriter(fileWriter); + for ( String line = null; (line = buff.readLine()) != null ; ) { + writer.println(line); + } + } finally { + if ( writer != null ) { + writer.close(); + } + if ( fileWriter != null ) { + fileWriter.close(); + } + } + } + + /** + * resource path. + */ + public String getInputFileResourcePath(Properties testProps) { + + String testPkg = testProps.getProperty(TEST_PACKAGE_PROP, ""); + String inputFile = testProps.getProperty(INPUT_FILE_PROP, DEF_INPUT_FILE); + String resourcePath = resolveResourcePath(testPkg, inputFile); + return resourcePath; + } + /** + * return resource path + */ + public String getExpectedFileResourcePath(Properties testProps) { + + String testPkg = testProps.getProperty(TEST_PACKAGE_PROP, ""); + String resourcePath = null; + String expFile = testProps.getProperty(EXPECTED_FILE_PROP, null); + if ( expFile != null ) { + resourcePath = resolveResourcePath(testPkg, expFile); + } + return resourcePath; + } + /** + * return the absolute path to the output file + */ + public String getOutputFilePath(Properties testProps) { + + String defPackage = this.getClass().getPackage().getName(); + String testPackage = testProps.getProperty(TEST_PACKAGE_PROP, defPackage); + String testPackageDir = testPackage.replace('.','/'); + String outputFile = testProps.getProperty(OUTPUT_FILE_PROP, DEF_OUTPUT_FILE); + + String userHomeDir = System.getProperty("user.home", ""); + String userDir = System.getProperty("user.dir", userHomeDir); + String defResultsDir = userDir + "/" + DEF_TEST_RESULTS_DIR; + String sysResultDir = System.getProperty(TEST_RESULTS_DIR_PROP, defResultsDir); + String resultDir = testProps.getProperty(TEST_RESULTS_DIR_PROP, sysResultDir); + + File outputDir = new File(resultDir, testPackageDir); + // System.out.println("Creating the test results output dir " + outputDir); + outputDir.mkdirs(); + return (new File(outputDir, outputFile)).getAbsolutePath(); + } + + /** + * This is the method where the actual service invocation code based on the + * type of client will be implemented. testService method calls this method + * after preparing the test input and then processes the output returned by + * this method to complte the test. + * @param inputDoc + * @param testProps + * @throws java.lang.Exception + * @return + */ + public abstract StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception; + + /** + * abstract method implemented by the extended classes to compare the output + * document with the expected output to determine the test is a failure or + * success. + * @param outputDoc + * @param expectedDoc + * @param testProps + * @throws java.lang.Exception + */ + public abstract void compareWithExpectedOutput(StringBuffer outputDoc, + StringBuffer expectedDoc, Properties testProps) throws Exception; + + /** + * This is the main test method that a test case will call to test the + * service. The standard steps that required to invoke the service and + * process the output will be done in this method. Each test case creates + * the test Properties required for that test and executes this method for + * testing the service by passing the test properties to it. This method + * prepares the input and executes the invokeService method to invoke a + * service with the prepared input. It then processes the return value from + * the invokeService to complete the test. + * + * @param testProps + * @throws java.lang.Exception + */ + public void testService(Properties testProps) throws Exception { + + String inFilePath = getInputFileResourcePath(testProps); + String outFilePath = getOutputFilePath(testProps); + String expFilePath = getExpectedFileResourcePath(testProps); + File outDir = (new File(outFilePath)).getParentFile(); + outDir.mkdirs(); + + StringBuffer outputDoc = new StringBuffer(); + + try { + StringBuffer inputDoc = loadResourceFile(inFilePath); + outputDoc = invokeService(inputDoc, testProps); + if ( expFilePath != null ) { + StringBuffer expOutputDoc = loadResourceFile(expFilePath); + compareWithExpectedOutput(inputDoc, expOutputDoc, testProps); + } + } catch (Exception ex) { + StringWriter out = new StringWriter(); + ex.printStackTrace(new PrintWriter(out)); + outputDoc.append(out.getBuffer()); + throw ex; + } finally { + if ( outputDoc != null ) { + System.out.println(outputDoc); + this.saveOutputToFile(new StringReader(outputDoc.toString()), outFilePath); + } + } + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java new file mode 100644 index 000000000..7cc8c103e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java @@ -0,0 +1,136 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingTestClient.java + */ + +package net.openesb.component.${artifactId}.test; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanException; +import javax.management.MBeanServerConnection; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.management.ReflectionException; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; + +/** + * This class extends the JBIComponentTestClient and implements the invokeService + * method to test the proxy service consumer implementation by a binding component + * that can communicate with the external service consumers using JMX interface. + * @author chikkala + */ +public class JMXBindingTestClient extends JBIComponentTestClient { + + public static final String CONSUMER_EP_INBOUND_OPERATION_PROP = "consumer.jmx.bc.ep.operation"; + public static final String CONSUMER_EP_ADDRESS_MBEAN_PROP = "consumer.jmx.bc.ep.address.mbean"; + public static final String CONSUMER_EP_ADDRESS_URL_PROP = "consumer.jmx.bc.ep.address.serviceURL"; + public static final String CONSUMER_EP_ADDRESS_USERNAME_PROP = "consumer.jmx.bc.ep.address.username"; + public static final String CONSUMER_EP_ADDRESS_PASSWORD_PROP = "consumer.jmx.bc.ep.address.password"; + + public static final String PROVIDER_EP_INBOUND_OPERATION_PROP = "provider.jmx.bc.ep.operation"; + public static final String PROVIDER_EP_ADDRESS_MBEAN_PROP = "provider.jmx.bc.ep.address.mbean"; + public static final String PROVIDER_EP_ADDRESS_URL_PROP = "provider.jmx.bc.ep.address.serviceURL"; + public static final String PROVIDER_EP_ADDRESS_USERNAME_PROP = "provider.jmx.bc.ep.address.username"; + public static final String PROVIDER_EP_ADDRESS_PASSWORD_PROP = "provider.jmx.bc.ep.address.password"; + + + /** + * Creates a new instance of JMXBindingTestClient + */ + public JMXBindingTestClient() { + super(); + } + /** + * creates jmx connection to send the input message to the binding component. + */ + public static MBeanServerConnection getJMXConnection(Properties testProps) + throws MalformedURLException, IOException { + + String jmxUrl = testProps.getProperty(CONSUMER_EP_ADDRESS_URL_PROP); + String username = testProps.getProperty(CONSUMER_EP_ADDRESS_USERNAME_PROP); + String password = testProps.getProperty(CONSUMER_EP_ADDRESS_PASSWORD_PROP); + + Map env = new HashMap(); + if ( username != null ) { + String [] credentials = new String [] {username, password}; + env.put("jmx.remote.credentials", credentials); + env.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, JMXBindingTestClient.class.getClassLoader()); + } + JMXServiceURL serviceURL = new JMXServiceURL(jmxUrl); + JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, env); + MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection(); + return mbeanServerConnection; + } + /** + * constructs the jmx mbean objectname + */ + public static ObjectName createJMXEndpointMBeanObjectName(String endpointAddressMBean) throws MalformedObjectNameException { + // String objectName = JMX_DOMAIN + ":" + JMX_ENDPOINT_ADDRESS_KEY + "=" + endpointAddressMBean; + return new ObjectName(endpointAddressMBean); + } + /** + * invokes a jmx mbean to send message. + */ + public static StringBuffer invokeSendMessage(MBeanServerConnection jmxConn, ObjectName epAddressName, + String operation, StringBuffer inputDoc) + throws MalformedObjectNameException, InstanceNotFoundException, + MBeanException, ReflectionException, IOException { + StringBuffer outDoc = null; + + Object result = null; + String mbeanOperation = "sendMessage"; + + Object[] params = new Object[2]; + params[0] = operation; + params[1] = inputDoc; + + String[] signature = new String[2]; + signature[0] = "java.lang.String"; + signature[1] = "java.lang.StringBuffer"; + + result = jmxConn.invoke(epAddressName, mbeanOperation, params, signature); + if ( result != null ) { + outDoc = (StringBuffer)result; + } + + return outDoc; + } + /** + * invokes the service via jmx interface. + */ + public StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception { + + ObjectName epAddressName = new ObjectName(testProps.getProperty(CONSUMER_EP_ADDRESS_MBEAN_PROP)); + String operation = testProps.getProperty(CONSUMER_EP_INBOUND_OPERATION_PROP); + + MBeanServerConnection jmxConn = getJMXConnection(testProps); + StringBuffer outputDoc = null; + try { + outputDoc = invokeSendMessage(jmxConn, epAddressName, operation, inputDoc); + } catch (MBeanException ex) { + Exception targetEx = ex.getTargetException(); + if ( targetEx != null ) { + throw targetEx; + } else { + throw ex; + } + } + return outputDoc; + } + /** no expected output comparison implemented */ + public void compareWithExpectedOutput(StringBuffer inputDoc, + StringBuffer expectedDoc, + Properties testProps) throws Exception { + // throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java new file mode 100644 index 000000000..28f534612 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java @@ -0,0 +1,159 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * SOAPBindingTestClient.java + */ + +package net.openesb.component.${artifactId}.test; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Properties; +import javax.xml.soap.MessageFactory; +import javax.xml.soap.MimeHeaders; +import javax.xml.soap.SOAPConnection; +import javax.xml.soap.SOAPConnectionFactory; +import javax.xml.soap.SOAPException; +import javax.xml.soap.SOAPFault; +import javax.xml.soap.SOAPMessage; +import javax.xml.soap.SOAPPart; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +/** + * This class extends the JBIComponentTestClient and implements the invokeService + * method to test the Service Engine via SOAP Binding by invoking the service using + * SOAP Client that sends the message to the service provider via soaphttp binding. + * + * @author chikkala + */ +public class SOAPBindingTestClient extends JBIComponentTestClient { + + private static final String ADDRESS_PROP = "soap.binding.inbound.endpoint.address.location"; + private static final String SOAP_ACTION_PROP = "soap.binding.soapaction"; + private static final String FAIL_ON_SOAP_FAULT_PROP = "fail.on.soap.fault"; + + private static MessageFactory messageFactory; + private static SOAPConnectionFactory soapConnFactory; + private static SOAPConnection connection; + + public SOAPBindingTestClient() throws SOAPException { + init(); + } + /** initializes SOAP client */ + private synchronized void init() throws SOAPException { + if ( messageFactory == null ) { + messageFactory = MessageFactory.newInstance(); + } + if ( soapConnFactory == null ) { + soapConnFactory = SOAPConnectionFactory.newInstance(); + } + if ( connection == null ) { + connection = soapConnFactory.createConnection(); + } + } + + /** + * read in a soap message from the given input file + */ + private static SOAPMessage loadMessage(Reader inReader) throws SOAPException, IOException { + //Create and populate the message from a file + SOAPMessage message = messageFactory.createMessage(); + SOAPPart soapPart = message.getSOAPPart(); + StreamSource preppedMsgSrc = new StreamSource(inReader); + soapPart.setContent(preppedMsgSrc); + message.saveChanges(); + return message; + } + /** saves the SOAP message as xml text to a writer */ + private static void saveMessage(SOAPMessage response, Writer outWriter) + throws TransformerConfigurationException, SOAPException, TransformerException { + + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + transformerFactory.setAttribute("indent-number", new Integer(2)); + Transformer transformer = transformerFactory.newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + + SOAPPart replySOAPPart = response.getSOAPPart(); + Source sourceContent = replySOAPPart.getContent(); + StreamResult result = new StreamResult(outWriter); + try { + transformer.transform(sourceContent, result); + } catch (TransformerException ex) { + ex.printStackTrace(); + } + } + /** + * Send a soap message + * @param destination URL to send to + * @param message message to send + * @param expectedHttpStatus expected http status code or null if success is expected + * @return reply soap message + */ + private static SOAPMessage sendMessage(String destination, SOAPMessage message, String soapAction) throws SOAPException { + + // Add soapAction if not null + if (soapAction != null) { + MimeHeaders hd = message.getMimeHeaders(); + hd.setHeader("SOAPAction", soapAction); + } + // Send the message and get a reply + SOAPMessage reply = null; + reply = connection.call(message, destination); + return reply; + } + /** check the xml text in the StringBuffer passed contains SOAP Fault. */ + public boolean isSOAPFault(StringBuffer msgBuff) { + SOAPFault soapFault = null; + try { + SOAPMessage inMsg = loadMessage(new StringReader(msgBuff.toString())); + soapFault = inMsg.getSOAPBody().getFault(); + } catch (Exception ex) { + // any exception, means either no fault elem or invalid xml + } + return (soapFault != null); + } + /** + * invokes the service ny sending the input message and return the output + * message returned by the service. + */ + public StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception { + + String soapAction = testProps.getProperty(SOAP_ACTION_PROP); + String destination = testProps.getProperty(ADDRESS_PROP); + SOAPMessage inMsg = loadMessage(new StringReader(inputDoc.toString())); + SOAPMessage outMsg = sendMessage(destination, inMsg, soapAction); + StringWriter out = new StringWriter(); + saveMessage(outMsg, out); + StringBuffer outDoc = out.getBuffer(); + Boolean failOnSoapFault = Boolean.valueOf(testProps.getProperty(FAIL_ON_SOAP_FAULT_PROP, "false")); + if ( failOnSoapFault ) { + if (isSOAPFault(outDoc)) { + StringBuffer errBuff = new StringBuffer("${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} SOAP FAULT ${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} ${symbol_escape}n"); + errBuff.append(outDoc); + throw new Exception(errBuff.toString()); + } + } + return outDoc; + } + /** comparing the received output document with the expected document. throw + * exception if the docs are not same. throwing the exception in this method + * fails the test. + */ + public void compareWithExpectedOutput(StringBuffer outputDoc, + StringBuffer expectedDoc, + Properties testProps) throws Exception { + // throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/build.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/build.properties new file mode 100644 index 000000000..945269943 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/build.properties @@ -0,0 +1,22 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} Build properties for the service assembly builds +${symbol_pound} user.properties.file=../../user.properties +src.dir=src +${symbol_pound} This directory is removed when the project is cleaned: +build.dir=build +service.assembly.name=testSA + +${symbol_pound}no.deps=true set the no.deps property if there are no SUs to build +${symbol_pound} for each testSU define the properties here. +${symbol_pound} dependent BC SU projects dependency +${symbol_pound} service unit name +service.unit.name.testSUBC=testSUBC +${symbol_pound} service unit project directory +project.testSUBC=testSUBC + +${symbol_pound} service unit name +service.unit.name.testSUSE=testSUSE +${symbol_pound} service unit project directory +project.testSUSE=testSUSE diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/build.xml new file mode 100644 index 000000000..02f75e641 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/build.xml @@ -0,0 +1,140 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.assembly.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml new file mode 100644 index 000000000..3ced1c59e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml @@ -0,0 +1,44 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + ${artifactId}_TestSA + This is a test Service Assembly to test Binding + + + + + ${artifactId}_TestSUBC + This service unit enables inbound endpoint in the JMXBinding for a service in service engine + + + testSUBC.zip + ${artifactId} + + + + + ${artifactId}_TestSUSE + This service unit enables greetings service provider in the service engine + + + testSUSE.zip + ServiceEngine + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build.properties new file mode 100644 index 000000000..caaefb87b --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build.properties @@ -0,0 +1,10 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} Build properties for the service unit builds +src.dir=src +${symbol_pound} This directory is removed when the project is cleaned: +${symbol_pound}build.dir=../../../build/test/testSU/build +build.dir=build +service.unit.name=testSUBC + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml new file mode 100644 index 000000000..777fb3cf9 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml @@ -0,0 +1,74 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/src/Greetings.wsdl b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/src/Greetings.wsdl new file mode 100644 index 000000000..cf1d4ccc3 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/src/Greetings.wsdl @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml new file mode 100644 index 000000000..112a9decb --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml @@ -0,0 +1,17 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build.properties new file mode 100644 index 000000000..1bfd81c69 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build.properties @@ -0,0 +1,10 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} Build properties for the service unit builds +src.dir=src +${symbol_pound} This directory is removed when the project is cleaned: +${symbol_pound}build.dir=../../../build/test/testSU/build +build.dir=build +service.unit.name=testSUSE + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml new file mode 100644 index 000000000..846415d3a --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml @@ -0,0 +1,74 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/Greetings.wsdl b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/Greetings.wsdl new file mode 100644 index 000000000..9c6322558 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/Greetings.wsdl @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml new file mode 100644 index 000000000..e1edc9a96 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml @@ -0,0 +1,17 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/goodbye.xsl b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/goodbye.xsl new file mode 100644 index 000000000..c60e39b73 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/goodbye.xsl @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + Goodbye ! Have a great time. + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/hello.xsl b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/hello.xsl new file mode 100644 index 000000000..994b66f98 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/hello.xsl @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + Hello ! + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/xsltmap.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/xsltmap.properties new file mode 100644 index 000000000..44baf5452 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/main/resources/archetype-resources/test/testSA/testSUSE/src/xsltmap.properties @@ -0,0 +1,31 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} properties will be used to find the xslt file that will be used for invoking a +${symbol_pound} service operation. +${symbol_pound} The "xsltmap.properties" file should contain two types of properties +${symbol_pound} 1. for namespace prefix to namespaceURI map that starts with "xmlns." prefix like +${symbol_pound} "xmlns.tns-prefix=http://www.sun.com/jbi/examples/sample-service/echo" +${symbol_pound} 2. a service description to xslt file properties with syntax like +${symbol_pound} "{tns-prefix}service-name=xslt_file_name" and +${symbol_pound} "{tns-prefix}service-name.{tns-prefix}operation-name=xslt_file_name" and +${symbol_pound} "{tns-prefix}service-name.{tns-prefix}interface-name.operation-name=xslt_file_name" . +${symbol_pound} the service description property is a "." delimited tokens that represents +${symbol_pound} a serive or interface qname and a operation name. To locate xslt file either with +${symbol_pound} service qname or service qname and operaton or serivice qname and interface qname +${symbol_pound} and operation, all the three properties specified above should be there for each xslt file. +${symbol_pound} + +xmlns.greet1=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greet2=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greettypes=http://www.sun.com/jbi/examples/sample-service/greetings/types +${symbol_pound} just service level default settings +{greet2}greetService=hello.xsl +${symbol_pound} service and operation +{greet2}greetService.{greet1}sayHello=hello.xsl +${symbol_pound} service, interface, operation +{greet2}greetService.{greet1}greetings.sayHello=hello.xsl +${symbol_pound} service and operation +{greet2}greetService.{greet1}sayGoodbye=goodbye.xsl +${symbol_pound} service, interface, operation +{greet2}greetService.{greet1}greetings.sayGoodbye=goodbye.xsl diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/test/resources/projects/basic/archetype.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/src/test/resources/projects/basic/archetype.properties new file mode 100644 index 000000000..cdd05f905 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/src/test/resources/projects/basic/archetype.properties @@ -0,0 +1,6 @@ +#Tue Jul 30 12:43:25 IST 2013 +package=it.pkg +version=0.1-SNAPSHOT +groupId=archetype.it +artifactId=BindingComponent-archetype +glassfishLocation=C:\\GlassFishESBv22\\glassfish \ No newline at end of file diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/src/test/resources/projects/basic/goal.txt b/maven-archtype-v2/maven-archtype-binding-component-v2/src/test/resources/projects/basic/goal.txt new file mode 100644 index 000000000..e69de29bb diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/BindingComponent-archetype-1.0-SNAPSHOT.jar b/maven-archtype-v2/maven-archtype-binding-component-v2/target/BindingComponent-archetype-1.0-SNAPSHOT.jar new file mode 100644 index 000000000..5914d262b Binary files /dev/null and b/maven-archtype-v2/maven-archtype-binding-component-v2/target/BindingComponent-archetype-1.0-SNAPSHOT.jar differ diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/META-INF/maven/archetype-metadata.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/META-INF/maven/archetype-metadata.xml new file mode 100644 index 000000000..e3cafbf91 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,76 @@ + + + + + C:\\GlassFishESBv22\\glassfish + + + + + test/java + + **/*.xml + **/*.java + **/*.properties + + + + src/java + + **/*.java + + + + src/java + + **/*.xsd + + + + test/testSA + + **/*.xml + **/*.properties + + + + nbproject + + **/*.xml + **/*.properties + + + + src/conf + + **/*.xml + + + + nbproject/private + + **/*.xml + **/*.properties + + + + test/testSA + + **/*.xsl + **/*.wsdl + + + + + + build.xml + install-params.properties + m2nbbuild-impl.xml + m2nbbuild.properties + m2nbbuild.xml + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build.xml new file mode 100644 index 000000000..14afd1d29 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build.xml @@ -0,0 +1,72 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + Builds, tests, and runs the project ${artifactId}. + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/pom.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/pom.xml new file mode 100644 index 000000000..1e58b6067 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/pom.xml @@ -0,0 +1,38 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + 4.0.0 + + ${package} + ${artifactId}-archetype + ${version} + maven-archetype + + ${artifactId}-archetype + + + + + org.apache.maven.archetype + archetype-packaging + 2.2 + + + + + + + maven-archetype-plugin + 2.2 + + + + + + Maven project for JBI Component that contains the + maven and netbeans build setup and component code to build and test the JBI Component. + + http://open-esb.org + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml new file mode 100644 index 000000000..c493031be --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/build-impl.xml @@ -0,0 +1,33 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml new file mode 100644 index 000000000..99e45731e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/deploy-plugin/nbproject/project.xml @@ -0,0 +1,62 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + org.netbeans.modules.apisupport.project + + + ${symbol_dollar}{artifactId} + + + + org.netbeans.modules.xml.schema.model + + + + 1 + 1.2 + + + + org.netbeans.modules.xml.wsdl.bindingsupport.api + + + + 1.0 + + + + org.netbeans.modules.xml.wsdl.model + + + + 1 + 1.2 + + + + org.netbeans.modules.xml.xam + + + + 1 + 1.2 + + + + org.openide.util + + + + 7.9.0.1 + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/bindingtest/test1Input.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/bindingtest/test1Input.xml new file mode 100644 index 000000000..a54d4d390 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/bindingtest/test1Input.xml @@ -0,0 +1,15 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + Srinivasan + Chikkala + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/bindingtest/test2Input.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/bindingtest/test2Input.xml new file mode 100644 index 000000000..6233ab78e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/java/bindingtest/test2Input.xml @@ -0,0 +1,15 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + Srinivasan + Chikkala + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/build.xml new file mode 100644 index 000000000..5456aa8f2 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/build.xml @@ -0,0 +1,143 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.assembly.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml new file mode 100644 index 000000000..63b89125f --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/src/META-INF/jbi.xml @@ -0,0 +1,47 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + ${symbol_dollar}{artifactId}_TestSA + This is a test Service Assembly to test Binding + + + + + ${symbol_dollar}{artifactId}_TestSUBC + This service unit enables inbound endpoint in the JMXBinding for a service in service engine + + + testSUBC.zip + ${symbol_dollar}{artifactId} + + + + + ${symbol_dollar}{artifactId}_TestSUSE + This service unit enables greetings service provider in the service engine + + + testSUSE.zip + ServiceEngine + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml new file mode 100644 index 000000000..96e95745f --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/build.xml @@ -0,0 +1,77 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml new file mode 100644 index 000000000..539a5efbf --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml new file mode 100644 index 000000000..75340ea7d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/build.xml @@ -0,0 +1,77 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml new file mode 100644 index 000000000..324002052 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/build/generated-sources/archetype/src/main/resources/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound}set( ${symbol_dollar}symbol_pound = '${symbol_pound}' ) +${symbol_pound}set( ${symbol_dollar}symbol_dollar = '${symbol_dollar}' ) +${symbol_pound}set( ${symbol_dollar}symbol_escape = '${symbol_escape}' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/m2nbbuild-impl.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/m2nbbuild-impl.xml new file mode 100644 index 000000000..d7dabc84f --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/m2nbbuild-impl.xml @@ -0,0 +1,130 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + This project compile, package and test the JBI Components when invoked from Maven2. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/m2nbbuild.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/m2nbbuild.properties new file mode 100644 index 000000000..663de1bb9 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/m2nbbuild.properties @@ -0,0 +1,48 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} build properties file to set/override the properties of the netbeans project +${symbol_pound} build properties when the netbeans build is called from the maven build lifecycle. +${symbol_pound} Netbeans project when build from the IDE, uses a build.properties from the user.dir +${symbol_pound} of the Netbeans IDE to resolve some of the properties used in the project such as +${symbol_pound} the libraries classpath. +${symbol_pound} When invoking the Netbeans project build from maven, this build.properties file +${symbol_pound} is not available. So, you can add the properties defined in ide build properties +${symbol_pound} that this project uses here. +${symbol_pound} + +${symbol_pound} default local repository settings. If the repository location is different +${symbol_pound} -D command line option should override this (e.g. mvn -Dmaven.repo.local=/my/m2/repository +maven.repo.local=${symbol_dollar}{user.home}/.m2/repository +${symbol_pound} begin jbi admin settings +${symbol_pound} set the below properties if you want to override the properties from nbproject/project.properties +${symbol_pound} that sets the application server admin settings. +${symbol_pound} +${symbol_pound} jbi.as.home=C:/Sun/glassfish-v2-b58g +${symbol_pound} jbi.host=localhost +${symbol_pound} jbi.port=4848 +${symbol_pound} jbi.username=admin +${symbol_pound} jbi.password=adminadmin +${symbol_pound} end jbi admin settings +${symbol_pound} + +${symbol_pound} classpath settings +junit.ant.task.classpath=${symbol_dollar}{maven.repo.local}/ant/ant-junit/1.6.5/ant-junit-1.6.5.jar +junit.runtime.classpath=${symbol_dollar}{maven.repo.local}/junit/junit/3.8.2/junit-3.8.2.jar +libs.junit.classpath=${symbol_dollar}{junit.runtime.classpath}:${symbol_dollar}{junit.ant.task.classpath} +libs.jbi-cdk-ant-tasks.classpath=${symbol_dollar}{maven.repo.local}/open-esb/jbi-cdk/jbi-cdk-ant-tasks/${version}/jbi-cdk-ant-tasks-${version}.jar + +libs.jbi.classpath=${symbol_dollar}{maven.repo.local}/open-esb/jbi/1.0/jbi-1.0.jar +libs.wsdl4j.162.classpath=${symbol_dollar}{maven.repo.local}/wsdl4j/wsdl4j/1.6.2/wsdl4j-1.6.2.jar +${symbol_pound} libs.jaxws21.classpath=${symbol_dollar}{jbi.as.home}/lib/javaee.jar:${symbol_dollar}{jbi.as.home}/lib/webservices-rt.jar +libs.jaxws21.classpath=${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/activation/activation/1.1/activation-1.1.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/xml/soap/saaj-api/1.3/saaj-api-1.3.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/javax/xml/ws/jaxws-api/2.1/jaxws-api-2.1.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/com/sun/xml/messaging/saaj/saaj-impl/1.3/saaj-impl-1.3.jar:${symbol_escape} +${symbol_dollar}{maven.repo.local}/com/sun/xml/ws/jaxws-rt/2.1.2/jaxws-rt-2.1.2.jar + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/m2nbbuild.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/m2nbbuild.xml new file mode 100644 index 000000000..31217d15d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/m2nbbuild.xml @@ -0,0 +1,37 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + This project compile, package and test the JBI Components when invoked from Maven2. + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/build-impl.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/build-impl.xml new file mode 100644 index 000000000..096c6dd04 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/build-impl.xml @@ -0,0 +1,557 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Inside: postArchTypeGen - Post task is getting executed! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Inside: postArchTypeGen - Post task executed successfully! + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/genfiles.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/genfiles.properties new file mode 100644 index 000000000..ac5cc7404 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/genfiles.properties @@ -0,0 +1,11 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +build.xml.data.CRC32=f37ab647 +build.xml.script.CRC32=9068f2c7 +build.xml.stylesheet.CRC32=8add101f@1.0 +${symbol_pound} This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +${symbol_pound} Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=f37ab647 +nbproject/build-impl.xml.script.CRC32=d15987fd +nbproject/build-impl.xml.stylesheet.CRC32=4ed53ee0@1.0 diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/jbi_admin.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/jbi_admin.xml new file mode 100644 index 000000000..8a7d2a523 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/jbi_admin.xml @@ -0,0 +1,504 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + +This ant script contains the jbi ant tasks and the targets and properties using +which the jbi admin commands can be performed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Usage : ant -f <fullpath>/jbi_admin.xml [options] [target] + options: -D<property>=<value> + Specify a property/value pairs as options that are valid for the target. + target : ant target name in jbi_admin.xml + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/jbiadmin-impl.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/jbiadmin-impl.xml new file mode 100644 index 000000000..7e7dca2ae --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/jbiadmin-impl.xml @@ -0,0 +1,339 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + Install, uninstall, reinstall, start, stop, shutdown jbi components. + + + + + + + + + + + + + + Must set jbi.host + Must set jbi.port + Must set jbi.username + Must set jbi.password + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/private/private.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/private/private.properties new file mode 100644 index 000000000..e540325d5 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/private/private.properties @@ -0,0 +1,6 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +javac.debug=true +javadoc.preview=true +user.properties.file=D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working57${symbol_escape}${symbol_escape}.netbeans${symbol_escape}${symbol_escape}openesb${symbol_escape}${symbol_escape}build.properties diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/project.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/project.properties new file mode 100644 index 000000000..7237a56d7 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/project.properties @@ -0,0 +1,93 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +build.classes.dir=${symbol_dollar}{build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +${symbol_pound} This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${symbol_dollar}{build.dir}/generated +build.predist.dir=${symbol_dollar}{build.dir}/predist +build.predist.jar=${symbol_dollar}{build.predist.dir}/component.jar +build.predist.lib.dir=${symbol_dollar}{build.predist.dir}/lib +${symbol_pound} Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${symbol_dollar}{build.dir}/test/classes +build.test.dir=${symbol_dollar}{build.dir}/test +build.test.results.dir=${symbol_dollar}{build.dir}/test/results +conf.dir=src/conf +debug.classpath=${symbol_escape} + ${symbol_dollar}{run.classpath} +debug.test.classpath=${symbol_escape} + ${symbol_dollar}{run.test.classpath} +${symbol_pound} This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${symbol_dollar}{dist.dir}/${artifactId}.zip +dist.javadoc.dir=${symbol_dollar}{dist.dir}/javadoc +jar.compress=false +javac.classpath=${symbol_escape} + ${symbol_dollar}{libs.jbi.classpath}:${symbol_escape} + ${symbol_dollar}{jbi.component.sharedlibs.classpath}:${symbol_escape} + ${symbol_dollar}{jbi.component.lib.classpath} +${symbol_pound} Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.6 +javac.target=1.6 +javac.test.classpath=${symbol_escape} + ${symbol_dollar}{javac.classpath}:${symbol_escape} + ${symbol_dollar}{build.classes.dir}:${symbol_escape} + ${symbol_dollar}{libs.junit.classpath}:${symbol_escape} + ${symbol_dollar}{libs.jaxws21.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +jbi.ant.tasks.classpath=${symbol_escape} + ${symbol_dollar}{jbi.as.home}/lib/sun-appserv-ant.jar:${symbol_escape} + ${symbol_dollar}{jbi.as.home}/jbi/lib/jbi-ant-tasks.jar +#jbi.as.home=D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working53${symbol_escape}${symbol_escape}glassfish +jbi.as.home=${glassfishLocation} +#jbi.as.instance.id=[D:${symbol_escape}${symbol_escape}softwares${symbol_escape}${symbol_escape}openesb_logicoy_last_working53${symbol_escape}${symbol_escape}glassfish]deployer:Sun:AppServer::localhost:4848 +jbi.as.instance.id=[${glassfishLocation}]deployer:Sun:AppServer::localhost:4848 +jbi.component.bootstrap.class=${artifactId}.JMXBindingInstaller +jbi.component.class=${artifactId}.JMXBindingRuntime +jbi.component.description=Description of binding component : ${artifactId} +jbi.component.lib.classpath=${symbol_escape} + ${symbol_dollar}{libs.wsdl4j.162.classpath} +jbi.component.name=${artifactId} +jbi.component.sharedlibs.classpath= +jbi.component.type=binding-component +jbi.host=localhost +jbi.install.params.file=install-params.properties +jbi.install.with.params=false +jbi.password=this really long string is used to identify a password that has been stored in the Keyring +jbi.port=4848 +jbi.soap.binding.name=sun-http-binding +jbi.username=admin +meta.inf.dir=${symbol_dollar}{conf.dir}/META-INF +platform.active=default_platform +project.jbi.deploy.plugin=./deploy-plugin +project.testSA=test/testSA +run.classpath=${symbol_escape} + ${symbol_dollar}{javac.classpath}:${symbol_escape} + ${symbol_dollar}{build.classes.dir} +${symbol_pound} Space-separated list of JVM arguments used when running the project +${symbol_pound} (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +${symbol_pound} or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=${symbol_escape} + ${symbol_dollar}{javac.test.classpath}:${symbol_escape} + ${symbol_dollar}{build.test.classes.dir} +src.dir=src/java +test-sys-prop.test.results.dir=${symbol_dollar}{build.test.results.dir} +test-sys-prop.test.src.dir=test-sys-prop.test.src.dir +test.src.dir=test/java +testSA.enabled=true +testSA.name=${artifactId}_TestSA diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/project.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/project.xml new file mode 100644 index 000000000..12b71aa1c --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/nbproject/project.xml @@ -0,0 +1,20 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + org.netbeans.modules.jbi.apisupport.project.jbicomponent + + + ${artifactId} + binding-component + 1.6.5 + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/pom.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/pom.xml new file mode 100644 index 000000000..7ae109163 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/pom.xml @@ -0,0 +1,268 @@ + + + + 4.0.0 + ${groupId} + ${artifactId} + jar + ${version} + JBI Component[${artifactId}] + Maven project for JBI Component that contains the + maven and netbeans build setup and component code to build and test the JBI Component. + http://open-esb.org + + build + src/java + test/java + build/classes + build/test/classes + package + + + org.apache.maven.plugins + maven-compiler-plugin + + true + 1.5 + 1.5 + + + **/*.java + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + + **/*.* + + + + + maven-surefire-plugin + 2.1.3 + true + + + true + + **/bindingtest/*.java + **/enginetest/*.java + + + + + + maven-antrun-plugin + 1.2 + + + m2nbbuild-compile + compile + run + + + + + + + + m2nbbuild-compile-test + test-compile + run + + + + + + + + m2nbbuild-package + package + run + + + + + + + + m2nbbuild-utest + test + run + + + + + + + + m2nbbuild-itest + integration-test + run + + + + + + + + m2nbbuild-clean + clean + run + + + + + + + default-cli + + run + + + + !!!!!!!!!!!!!!!!!!!!!! Moving Files and organizing package !!!!!!!!!!!!!!!!!!!!!!!! + + + + + + + + + + ant + ant-nodeps + 1.6.5 + + + ant + ant-junit + 1.6.5 + test + + + junit + junit + 3.8.2 + test + + + + + + + + + maven2-repo1 + Maven2 Central Repository + http://repo1.maven.org/maven2 + + + download-java-net-maven2-repository + download.java.net Maven 2.x repository + http://download.java.net/maven/2/ + + + maven-repository.dev.java.net-repository + https://maven-repository.dev.java.net/nonav/repository/ + legacy + + + ws-zones + ws.zones maven repository + http://ws.zones.apache.org/repository2/ + + + apache.org + Maven Snapshots + http://people.apache.org/repo/m2-snapshot-repository + + false + + + + + + + + + apache.org + Maven Plugin Snapshots + http://people.apache.org/repo/m2-snapshot-repository + + false + + + + + + + + ant + ant-nodeps + 1.6.5 + + + ant + ant-junit + 1.6.5 + test + + + junit + junit + 3.8.2 + test + + + org.apache.maven + maven-ant-tasks + 2.0.7 + + + open-esb.jbi-cdk + jbi-cdk-ant-tasks + 1.0-SNAPSHOT + + + open-esb + jbi + 1.0 + + + wsdl4j + wsdl4j + 1.6.2 + + + com.sun.xml.ws + jaxws-rt + 2.1.2 + test + + + + + ${maven.repo.local} + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/conf/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/conf/META-INF/jbi.xml new file mode 100644 index 000000000..6c38687ee --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/conf/META-INF/jbi.xml @@ -0,0 +1,45 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + ${artifactId} + Description of binding component : ${artifactId} + + + net.openesb.component.${artifactId}.JMXBindingRuntime + + + component.jar + + lib/wsdl4j-1.6.2.jar + + + net.openesb.component.${artifactId}.JMXBindingInstaller + + + component.jar + + lib/wsdl4j-1.6.2.jar + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingComponentLifeCycle.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingComponentLifeCycle.java new file mode 100644 index 000000000..d4e017183 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingComponentLifeCycle.java @@ -0,0 +1,52 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMX${artifactId}LifeCycle.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.BasicComponentLifeCycle; +import net.openesb.component.${artifactId}.common.DefaultMessageExchangeReceiver; +import net.openesb.component.${artifactId}.common.MessageExchangeReceiver; +import net.openesb.component.${artifactId}.common.RuntimeContext; +import javax.jbi.JBIException; +import javax.jbi.component.Component; + +/** + * This class extends the basic ComponentLifeCycle implementation to provide + * component specific implementation of the ComponentLifeCycle. + * + * @see javax.jbi.ComponentLifeCycle + * @see com.sun.jbi.sample.component.common.BasicComponentLifeCycle + * @author chikkala + */ +public class JMXBindingComponentLifeCycle extends BasicComponentLifeCycle { + + /** + * constructor for the ComponentLifecycle implementation. + */ + public JMXBindingComponentLifeCycle(Component compRuntime) { + super(compRuntime); + } + + /** + * creates DefaultMessageExchangeReceiver to handles receiving and + * processing the message exchanges from the delivery channel. + */ + @Override + protected MessageExchangeReceiver createMessageExchangeReceiver() { + return new DefaultMessageExchangeReceiver(); + } + + /** + * chance to extended classes to do the component specific init + * + * @throws javax.jbi.JBIException + */ + @Override + protected void doInit() throws JBIException { + // NOOP + RuntimeContext.getInstance().setLogger(this.getClass().getName(), null); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingConsumerEndpoint.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingConsumerEndpoint.java new file mode 100644 index 000000000..3a0711150 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingConsumerEndpoint.java @@ -0,0 +1,153 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingConsumerEndpoint.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.wsdlext.PortExt; +import net.openesb.component.${artifactId}.wsdlext.WSDLExtHelper; +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.deployment.ConsumerEndpoint; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor; +import net.openesb.component.${artifactId}.common.deployment.ServiceUnit; +import javax.jbi.JBIException; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanRegistrationException; +import javax.management.ObjectName; +import javax.management.StandardMBean; +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +/** + * This class extends ConsumerEndpoint to implement the component specific + * consumer endpoint configuration. It uses JMXBindingConsumerProxy to receive + * messages from external service consumers and initiate the InOut message + * exchange. This implementation shows how a synchronous send/receive from the + * delivery channel will be used in InOut message exchange in a service + * invocation by the external consumers. + * + * @author chikkala + */ +public class JMXBindingConsumerEndpoint extends ConsumerEndpoint { + + private ObjectName mJMXEndpointMBeanName; + private JMXEndpointMBean mJMXEndpointMBean; + + /** + * Creates a new instance of XSLTProviderEndpoint + */ + public JMXBindingConsumerEndpoint(SUDescriptor.Consumes consumes, Definition wsdlDef, ServiceUnit su) { + super(consumes, wsdlDef, su); + } + + @Override + protected void doInit() throws JBIException { + RuntimeHelper.getLogger().fine("JMXBindingEndpoint(Consumer): init called"); + this.initJMXEndpoint(); + } + + @Override + protected void doActivate() throws JBIException { + RuntimeHelper.getLogger().fine("JMXBindingEndpoint(Consumer): activate called"); + this.activateJMXEndpoint(); + } + + @Override + protected void doDeactivate() throws JBIException { + RuntimeHelper.getLogger().fine("JMXBindingEndpoint(Consumer): deactivate called"); + this.deactivateJMXEndpoint(); + } + + @Override + protected void doClean() throws JBIException { + RuntimeHelper.getLogger().fine("JMXBindingEndpoint(Consumer): clean called"); + this.cleanJMXEndpoint(); + } + + /** + * creates the JMXEndpointMBean implementation. + */ + protected JMXEndpointMBean createJMXEndpointMBean() { + // JMX EndpointMBean implementation that initiates in-out message exchange. + return new JMXBindingConsumerProxy(this); + } + + /** + * get the mbean object name from the endpoint address of the jmx wsdl + * extension element + */ + protected ObjectName createJMXEndpointMBeanName() throws JBIException { + ObjectName mbeanObjectName = null; + try { + mbeanObjectName = new ObjectName(findMBeanNameFromWSDL()); + } catch (Exception ex) { + throw new JBIException(ex); + } + return mbeanObjectName; + } + + public final ObjectName getJMXEndpointMBeanName() { + return this.mJMXEndpointMBeanName; + } + + public final JMXEndpointMBean getJMXEndpointMBean() { + return this.mJMXEndpointMBean; + } + + protected final void initJMXEndpoint() throws JBIException { + // create jmx mbean resources + this.mJMXEndpointMBeanName = createJMXEndpointMBeanName(); + this.mJMXEndpointMBean = createJMXEndpointMBean(); + } + + protected final void activateJMXEndpoint() throws JBIException { + // open jmx connectivity to external consumers by registering the + // external endpoint mbean implementation. + try { + StandardMBean mbean = new StandardMBean(this.mJMXEndpointMBean, JMXEndpointMBean.class); + this.getComponentContext().getMBeanServer().registerMBean(mbean, this.mJMXEndpointMBeanName); + } catch (Exception ex) { + throw new JBIException(ex); + } + } + + protected final void deactivateJMXEndpoint() throws JBIException { + // close the jmx connectivity to external consumers by unregistering + // the external endpoint mbean. + try { + this.getComponentContext().getMBeanServer().unregisterMBean(this.mJMXEndpointMBeanName); + } catch (InstanceNotFoundException ex) { + ex.printStackTrace(); + } catch (MBeanRegistrationException ex) { + ex.printStackTrace(); + } + } + + protected final void cleanJMXEndpoint() throws JBIException { + // release jmx mbean resources + this.mJMXEndpointMBean = null; + this.mJMXEndpointMBeanName = null; + } + + /** + * get the mbean object name from the endpoint address of the jmx wsdl + * extension element + */ + protected String findMBeanNameFromWSDL() { + String mbeanName = null; + try { + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + Definition def = this.getWSDL(); + PortExt address = WSDLExtHelper.getPortExt(def, serviceName, endpointName); + if (address != null) { + mbeanName = address.getMBean(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + return mbeanName; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingConsumerProxy.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingConsumerProxy.java new file mode 100644 index 000000000..180f4d45d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingConsumerProxy.java @@ -0,0 +1,237 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingConsumerProxy.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.deployment.ConsumerEndpoint; +import java.io.StringReader; +import javax.jbi.JBIException; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.Fault; +import javax.jbi.messaging.InOnly; +import javax.jbi.messaging.InOut; +import javax.jbi.messaging.NormalizedMessage; +import javax.wsdl.Operation; +import javax.wsdl.OperationType; +import javax.xml.namespace.QName; +import javax.xml.transform.Source; + +/** + * This class acts as a proxy to the external service consumer that can receive + * messages from the external consumer using JMX interface and then initiate the + * InOut message exchange to invoke a service provided by the component in the + * jbi environment. + * + * this code shows how a synchronous send/receive messages from the delivery + * channel can be used in InOut message exchange to complete a service + * invocation. + * + * @author chikkala + */ +public class JMXBindingConsumerProxy implements JMXEndpointMBean { + + /** + * Synchronous send timeout + */ + private static final long SEND_SYNC_TIMEOUT = 60000; + private ConsumerEndpoint mEndpoint; + private JMXBindingNormalizer mNormalizer; + + /** + * Creates a new instance of JMXEndpointMBeanImpl + */ + public JMXBindingConsumerProxy(ConsumerEndpoint endpoint) { + this.mEndpoint = endpoint; + this.mNormalizer = new JMXBindingNormalizer(endpoint.getWSDL(), endpoint.getWSDLBinding()); + } + + public StringBuffer sendMessage(String operation, StringBuffer inputDoc) throws Exception { + // when receive input from external service consumer, + // 1. normalized the message, 2. send in-out message exchange. 3. denormalize out message. + Source inMsgSource = RuntimeHelper.createDOMSource(new StringReader(inputDoc.toString())); + QName operationQName = this.mEndpoint.getOperationQName(operation); + Source out = initiateMessageExchange(operationQName, inMsgSource); + StringBuffer outBuff = null; + if (out != null) { + // read the denormalized out message to string buffer. + outBuff = RuntimeHelper.readFromSource(out); + } + // return the out message content to the external service consumer. + return outBuff; + } + + public Source initiateMessageExchange(QName operation, Source inSource) throws JBIException { + // 1. Decide what type of message exchange needed for this operation. + Source outSource = null; + try { + Operation wsdlOp = this.mEndpoint.getWSDLOperation(operation); + if (OperationType.REQUEST_RESPONSE.equals(wsdlOp.getStyle())) { + outSource = doInOutMessageExchange(operation, inSource); + } else if (OperationType.ONE_WAY.equals(wsdlOp.getStyle())) { + doInOnlyMessageExchange(operation, inSource); + } else { + throw new JBIException("Unsupported MEP " + wsdlOp.getStyle() + + "for operation " + operation); + } + return outSource; + } catch (Exception ex) { + throw new JBIException(ex); + } + } + + /** + * invokes the service provider with in-only message exchange sent to + * delivery channel by the consumer + * + * @param operation operation name on a service + * @param inSource input xml document for the InOut operation + * @throws java.lang.Exception if any error occurs in invoking the operation + * on the service. + * @return output xml document as a Source object received from InOut + * operation of the service invoked. + */ + private void doInOnlyMessageExchange(QName operation, Source inSource) + throws Exception { + // 2. normalized the message. + // 3. locate service endpoint + // 4. create message exchange according to the Opeations MEP + + // get the component context and the delivery channel for preparing to send message + ComponentContext compContext = this.mEndpoint.getComponentContext(); + DeliveryChannel channel = this.mEndpoint.getDeliveryChannel(); + // create INOUT Message Exchange + InOnly inOnlyME = this.mEndpoint.createInOnlyMessageExchange(operation); + // set the content of the IN normalized message ( Normalize the message ) + NormalizedMessage inMsg = inOnlyME.getInMessage(); + Operation wsdlOperation = this.mEndpoint.getWSDLOperation(inOnlyME.getOperation()); + this.mNormalizer.normalizeInput(wsdlOperation, inMsg, RuntimeHelper.sourceToDOMSource(inSource)); + // send the message exchange and wait for response + boolean isSent = channel.sendSync(inOnlyME, SEND_SYNC_TIMEOUT); + if (!isSent) { + throw new Exception("JMXBinding:Timeout occured in sending the message to provider"); + } + // check if you got a done message or error ( done or error are only allowed in in-only) + // process the Message Exchange to check for done or error message and + // complete InOut message exchange with provider + //TODO: put this below code in processInOnlyMessageExchangeOnConsumer() + ExchangeStatus status = inOnlyME.getStatus(); + this.mEndpoint.getLogger().fine("Consumer:InOnly:Processing Message Exchange with status " + status); + if (ExchangeStatus.DONE.equals(status)) { + this.mEndpoint.getLogger().fine("Consumer: Completed the INONLY MessageExchange"); + return; + } else if (ExchangeStatus.ERROR.equals(status)) { + // error can occur any time. so just return the error back to client. + Exception serverSideEx = inOnlyME.getError(); + StringBuffer exMsgBuff = RuntimeHelper.getExceptionStackTrace(serverSideEx); + throw new Exception("Consumer:INONLY Message Exchange status ERROR.${symbol_escape}n" + exMsgBuff); + } else { + // any other status is error. + throw new Exception("Consumer:INONLY Message Exchange error. status: " + status); + } + } + + /** + * invokes service provider with in-out message exchange sent to delivery + * channel by the consumer + * + * @param operation operation name on a service + * @param inSource input xml document for the InOut operation + * @throws java.lang.Exception if any error occurs in invoking the operation + * on the service. + * @return output xml document as a Source object received from InOut + * operation of the service invoked. + */ + private Source doInOutMessageExchange(QName operation, Source inSource) + throws Exception { + // 2. normalized the message. + // 3. locate service endpoint + // 4. create message exchange according to the Opeations MEP + + // get the component context and the delivery channel for preparing to send message + ComponentContext compContext = this.mEndpoint.getComponentContext(); + DeliveryChannel channel = this.mEndpoint.getDeliveryChannel(); + // create INOUT Message Exchange + InOut inOutME = this.mEndpoint.createInOutMessageExchange(operation); + // set the content of the IN normalized message ( Normalize the message ) + NormalizedMessage inMsg = inOutME.getInMessage(); + Operation wsdlOperation = this.mEndpoint.getWSDLOperation(inOutME.getOperation()); + this.mNormalizer.normalizeInput(wsdlOperation, inMsg, RuntimeHelper.sourceToDOMSource(inSource)); + // send the message exchange and wait for response + boolean isSent = channel.sendSync(inOutME, SEND_SYNC_TIMEOUT); + if (!isSent) { + throw new Exception("JMXBinding:Timeout occured in sending the message to provider"); + } + // check if you got a out message or fault or error + // process the Message Exchange to get the output message and + // complete InOut message exchange with provider + NormalizedMessage outMsg = processInOutMessageExchangeOnConsumer(inOutME); + Source outSource = this.mNormalizer.denormalizeOutput(wsdlOperation, outMsg); + return outSource; + } + + /** + * takes the InOut message exchange received from sendSync call and + * processes it further to complete InOut message exchange with provider and + * returns the out message or throws exception in case of error or faults. + */ + private NormalizedMessage processInOutMessageExchangeOnConsumer(InOut inoutExchange) + throws Exception { + // InOut MessageExchange processing on consumer side + // 1. ACTIVE status receives a fault or out message, + // send the done status to complete message exchange + // return the fault/out message to external consumer + // 2. can not receive DONE status + // 3. when received ERROR status, return the error to consumer. + + // process the message exchange based on its state. + ExchangeStatus status = inoutExchange.getStatus(); + this.mEndpoint.getLogger().fine("Consumer:Processing Message Exchange with status " + status); + + if (ExchangeStatus.ACTIVE.equals(status)) { + + Fault fault = inoutExchange.getFault(); + NormalizedMessage outMsg = inoutExchange.getOutMessage(); + + // send done to complete message exchange. + DeliveryChannel channel = this.mEndpoint.getDeliveryChannel(); + inoutExchange.setStatus(ExchangeStatus.DONE); + channel.send(inoutExchange); + this.mEndpoint.getLogger().fine("Consumer: Completed the INOUT MessageExchange"); + + // process fault or out message + if (fault != null) { + // throw an exception if there is a fault message. + Source faultContent = fault.getContent(); + StringBuffer faultContentBuff = null; + if (faultContent != null) { + faultContentBuff = RuntimeHelper.readFromSource(faultContent); + } + throw new Exception("Consumer:INOUT message exchange Fault ${symbol_escape}n" + + faultContentBuff); + } + + // return the outMessage for processing + if (outMsg != null) { + return outMsg; + } else { + throw new Exception("Consumer: Null Out message in INOUT message exchange. "); + } + } else if (ExchangeStatus.DONE.equals(status)) { + // can not get DONE on Consumer side in INOUT message exchange. + throw new Exception("Consumer: Illegal status DONE on INOUT message exchange"); + } else if (ExchangeStatus.ERROR.equals(status)) { + // error can occur any time. so just return the error back to client. + Exception serverSideEx = inoutExchange.getError(); + StringBuffer exMsgBuff = RuntimeHelper.getExceptionStackTrace(serverSideEx); + throw new Exception("Consumer:INOUT Message Exchange status ERROR.${symbol_escape}n" + exMsgBuff); + } else { + throw new Exception("Consumer:INOUT Message Exchange error. status: " + status); + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingInstaller.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingInstaller.java new file mode 100644 index 000000000..e1b6f21e9 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingInstaller.java @@ -0,0 +1,34 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + /* + * JMXBindingInstaller.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.ComponentInstaller; + +/** + * This class extends the ComponentInstaller that implements the + * javax.jbi.component.Bootstrap for a component installation contract. + * + * If the default implemenation of the javax.jbi.component.Bootstrap in + * com.sun.jbi.sample.component.common.ComponentInstaller is not sufficient for + * this components install, uninstall and upgrade requirements, override the + * default implementation here to add component specific installation and + * upgrade tasks such as initializing configuration mbean and creating resources + * specific to component or upgrade workspace and service units during upgrading + * the component. + * + * @see javax.jbi.Bootstrap + * @see com.sun.jbi.sample.component.common.ComponentInstaller + * @author chikkala + */ +public class JMXBindingInstaller extends ComponentInstaller { + + /** + * Constructor to create the ComponentInstaller. + */ + public JMXBindingInstaller() { + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingNormalizer.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingNormalizer.java new file mode 100644 index 000000000..7452d3dca --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingNormalizer.java @@ -0,0 +1,242 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingNormalizer.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.wsdl.AbstractNormalizer; +import net.openesb.component.${artifactId}.common.wsdl.WSDL11JBIWrapper; +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import java.util.List; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.dom.DOMSource; +import org.w3c.dom.DOMException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * This class is a concrete implementation of the AbstractNormalizer to + * implement normalize jmx binding specific concrete messages to jbi wrapper + * messages and denormalize the jbi wrapper messages to jmx binding specific + * messages. The jmx binding concrete message has "message" as the root element + * that contains the part elements as its children. for example + * + * + * + * + * This is the sample code that demonstrate how to normalize and denormalize + * messages to/from jbi wrapper from/to concrete messages specific to a binding + * protocol + * + * @author chikkala + */ +public class JMXBindingNormalizer extends AbstractNormalizer { + + public static final String JMXBC_MSG_NS = "http://java.sun.com/jbi/sample/jmx-bc/envelope/"; + public static final String DEF_NS_PREFIX = "jmxbc"; + public static final String MESSAGE_EL = "message"; + + /** + * Creates a new instance of JMXBCNormalizer + */ + public JMXBindingNormalizer(Definition wsdl, Binding binding) { + super(wsdl, binding); + } + + /** + * normalizes the jmx binding protocol specific concrete message to jbi + * normalized message + */ + public void normalizeInput(Operation operation, NormalizedMessage normMsg, + DOMSource msgSource) throws MessagingException { + try { + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.createInputWrapper(operation); + Input input = operation.getInput(); + Message wsdlMsg = input.getMessage(); + //TODO: get the binding input extension here if needed. + Element jmxMessage = RuntimeHelper.getElement(msgSource); + + if (!JMXBC_MSG_NS.equals(jmxMessage.getNamespaceURI()) + || !MESSAGE_EL.equals(jmxMessage.getLocalName())) { + throw new MessagingException("invalid root element for jmxbc envelope"); + } + List jmxMsgParts = getChildElements(jmxMessage); + + addMessagePartsToJBIWrapper(jbiWrapper, wsdlMsg, jmxMsgParts); + + DOMSource wrappedSource = jbiWrapper.toDOMSource(); + normMsg.setContent(wrappedSource); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } + + /** + * normalizes the jmx binding protocol specific concrete message to jbi + * normalized message + */ + public void normalizeOutput(Operation operation, NormalizedMessage normMsg, + DOMSource msgSource) throws MessagingException { + try { + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.createInputWrapper(operation); + Output output = operation.getOutput(); + Message wsdlMsg = output.getMessage(); + //TODO: get the binding output extension here if needed. + Element jmxMessage = RuntimeHelper.getElement(msgSource); + + if (!JMXBC_MSG_NS.equals(jmxMessage.getNamespaceURI()) + || !MESSAGE_EL.equals(jmxMessage.getLocalName())) { + throw new MessagingException("invalid root element for jmxbc envelope"); + } + List jmxMsgParts = getChildElements(jmxMessage); + + addMessagePartsToJBIWrapper(jbiWrapper, wsdlMsg, jmxMsgParts); + + DOMSource wrappedSource = jbiWrapper.toDOMSource(); + normMsg.setContent(wrappedSource); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } + + /** + * normalizes the jmx binding protocol specific concrete message to jbi + * normalized message + */ + public void normalizeFault(Operation operation, String faultName, NormalizedMessage normMsg, + DOMSource msgSource) throws MessagingException { + try { + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.createInputWrapper(operation); + Fault wsdlFault = operation.getFault(faultName); + Message wsdlMsg = wsdlFault.getMessage(); + //TODO: get the binding fault extension here if needed. + Element jmxMessage = RuntimeHelper.getElement(msgSource); + + if (!JMXBC_MSG_NS.equals(jmxMessage.getNamespaceURI()) + || !MESSAGE_EL.equals(jmxMessage.getLocalName())) { + throw new MessagingException("invalid root element for jmxbc envelope"); + } + List jmxMsgParts = getChildElements(jmxMessage); + + addMessagePartsToJBIWrapper(jbiWrapper, wsdlMsg, jmxMsgParts); + + DOMSource wrappedSource = jbiWrapper.toDOMSource(); + normMsg.setContent(wrappedSource); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } + + /** + * denormalizes the jbi message to the jmx binding protocol specific + * concrete message. + */ + public DOMSource denormalizeInput(Operation operation, NormalizedMessage normMsg) + throws MessagingException { + try { + + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.sourceToWrapper( + RuntimeHelper.sourceToDOMSource(normMsg.getContent())); + Input input = operation.getInput(); + Message wsdlMsg = input.getMessage(); + //TODO: get the binding input extension here if needed. + + Document jmxMsgDoc = jbiWrapper.getDocumentBuilder().newDocument(); + Element jmxMessage = jmxMsgDoc.createElementNS(JMXBC_MSG_NS, DEF_NS_PREFIX + ":" + MESSAGE_EL); + jmxMessage.setAttributeNS(XMLNS_NS, "xmlns:" + DEF_NS_PREFIX, JMXBC_MSG_NS); + jmxMsgDoc.appendChild(jmxMessage); + + List jmxMsgParts = getMessagePartsFromJBIWrapper(jbiWrapper, wsdlMsg); + for (int i = 0; i < jmxMsgParts.size(); ++i) { + jmxMessage.appendChild(jmxMsgDoc.importNode(jmxMsgParts.get(i), true)); + } + + DOMSource unwrappedSource = new DOMSource(jmxMsgDoc); + return unwrappedSource; + } catch (DOMException ex) { + throw new MessagingException(ex); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } + + /** + * denormalizes the jbi message to the jmx binding protocol specific + * concrete message. + */ + public DOMSource denormalizeOutput(Operation operation, NormalizedMessage normMsg) + throws MessagingException { + try { + + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.sourceToWrapper( + RuntimeHelper.sourceToDOMSource(normMsg.getContent())); + Output output = operation.getOutput(); + Message wsdlMsg = output.getMessage(); + //TODO: get the binding output extension here if needed. + + Document jmxMsgDoc = jbiWrapper.getDocumentBuilder().newDocument(); + Element jmxMessage = jmxMsgDoc.createElementNS(JMXBC_MSG_NS, DEF_NS_PREFIX + ":" + MESSAGE_EL); + jmxMessage.setAttributeNS(XMLNS_NS, "xmlns:" + DEF_NS_PREFIX, JMXBC_MSG_NS); + + List jmxMsgParts = getMessagePartsFromJBIWrapper(jbiWrapper, wsdlMsg); + + for (int i = 0; i < jmxMsgParts.size(); ++i) { + jmxMessage.appendChild(jmxMsgDoc.importNode(jmxMsgParts.get(i), true)); + } + jmxMsgDoc.appendChild(jmxMessage); + DOMSource unwrappedSource = new DOMSource(jmxMsgDoc); + return unwrappedSource; + } catch (DOMException ex) { + throw new MessagingException(ex); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } + + /** + * denormalizes the jbi message to the jmx binding protocol specific + * concrete message. + */ + public DOMSource denormalizeFault(Operation operation, String faultName, NormalizedMessage normMsg) + throws MessagingException { + try { + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.sourceToWrapper( + RuntimeHelper.sourceToDOMSource(normMsg.getContent())); + Fault wsdlFault = operation.getFault(faultName); + Message wsdlMsg = wsdlFault.getMessage(); + //TODO: get the binding fault extension here if needed. + + Document jmxMsgDoc = jbiWrapper.getDocumentBuilder().newDocument(); + Element jmxMessage = jmxMsgDoc.createElementNS(JMXBC_MSG_NS, DEF_NS_PREFIX + ":" + MESSAGE_EL); + jmxMessage.setAttributeNS(XMLNS_NS, "xmlns:" + DEF_NS_PREFIX, JMXBC_MSG_NS); + + List jmxMsgParts = getMessagePartsFromJBIWrapper(jbiWrapper, wsdlMsg); + + for (int i = 0; i < jmxMsgParts.size(); ++i) { + jmxMessage.appendChild(jmxMsgDoc.importNode(jmxMsgParts.get(i), true)); + } + jmxMsgDoc.appendChild(jmxMessage); + DOMSource unwrappedSource = new DOMSource(jmxMsgDoc); + return unwrappedSource; + } catch (DOMException ex) { + throw new MessagingException(ex); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingProviderEndpoint.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingProviderEndpoint.java new file mode 100644 index 000000000..e6ab7f172 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingProviderEndpoint.java @@ -0,0 +1,87 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingProviderEndpoint.java + * + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.wsdlext.PortExt; +import net.openesb.component.${artifactId}.wsdlext.WSDLExtHelper; +import net.openesb.component.${artifactId}.common.MessageExchangeHandler; +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.MessageExchangeListener; +import net.openesb.component.${artifactId}.common.deployment.ProviderEndpoint; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor; +import net.openesb.component.${artifactId}.common.deployment.ServiceUnit; +import java.util.logging.Level; +import javax.jbi.JBIException; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +/** + * This class extends the ProviderEndpoint to implement component specific + * endpoint configuration. It implements the MessageExchangeListener to receive + * message exchange notifications from the MessageExchangeSupport fired by + * MessageExchangeReceiver and process it using a message exchange handler to + * show how an asynchronous processing of message exchange can be done. + * + * This endpoint uses the JMXBindingProviderProxy as a message exchange handler + * that can invoke the external provider to send a message and receive the + * response in a InOut message exchange. + * + * @author chikkala + */ +public class JMXBindingProviderEndpoint extends ProviderEndpoint implements MessageExchangeListener { + + JMXBindingProviderProxy mProviderProxy; + + /** + * Creates a new instance of XSLTProviderEndpoint + */ + public JMXBindingProviderEndpoint(SUDescriptor.Provides provides, Definition wsdlDef, ServiceUnit su) { + super(provides, wsdlDef, su); + } + + @Override + public void doInit() throws JBIException { + RuntimeHelper.getLogger().info("JMXBindingProviderEndpoint:doInit called"); + this.mProviderProxy = new JMXBindingProviderProxy(this); + } + + @Override + public MessageExchangeHandler createMessageExchangeHandler() { + return this.mProviderProxy; + } + + @Override + protected MessageExchangeListener createMessageExchangeListener() { + return this; + } + + public void messageExchangeReceived(ExchangeStatus status, MessageExchange me) { + try { + RuntimeHelper.getLogger().fine("MXListener.MessageExchangeReceived: with Status: " + status); + processMessageExchangeWithHandler(status, me); + // processMessageExchange(me); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public PortExt getJMXProviderInfo() { + PortExt portExt = null; + try { + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + Definition def = this.getWSDL(); + portExt = WSDLExtHelper.getPortExt(def, serviceName, endpointName); + } catch (Exception ex) { + getLogger().log(Level.FINE, ex.getMessage(), ex); + } + return portExt; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingProviderProxy.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingProviderProxy.java new file mode 100644 index 000000000..1d263da33 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingProviderProxy.java @@ -0,0 +1,235 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingProviderProxy.java + * + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.wsdlext.PortExt; +import net.openesb.component.${artifactId}.common.AbstractMessageExchangeHandler; +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import java.io.IOException; +import java.io.StringReader; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.Fault; +import javax.jbi.messaging.InOut; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; +import javax.wsdl.Operation; +import javax.xml.namespace.QName; +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMSource; + +/** + * This is a provider side implementation of the message exchange handler on a + * binding component which acts as a service provider proxy for the external + * provider. During the message exchange processing of the InOut message + * exchange, this handler acting as a proxy to the external provider invokes the + * service operation on the external provider and does required normalization + * and denormalization in processing out and in messages received from or send + * to the external service provider. + * + * @author chikkala + */ +public class JMXBindingProviderProxy extends AbstractMessageExchangeHandler { + + private JMXBindingProviderEndpoint mEndpoint; + private String mServiceURL; + private String mUsername; + private String mPassword; + private String mMBeanName; + private JMXBindingNormalizer mNormalizer; + + /** + * Creates a new instance of ProviderSEMXHandler + */ + public JMXBindingProviderProxy(JMXBindingProviderEndpoint endpoint) { + + this.mEndpoint = endpoint; + + PortExt jmxInfo = this.mEndpoint.getJMXProviderInfo(); + this.mServiceURL = jmxInfo.getServiceURL(); + this.mUsername = jmxInfo.getUsername(); + this.mPassword = jmxInfo.getPassword(); + this.mMBeanName = jmxInfo.getMBean(); + + this.mNormalizer = new JMXBindingNormalizer(endpoint.getWSDL(), endpoint.getWSDLBinding()); + } + + protected Logger getLogger() { + return this.mEndpoint.getLogger(); + } + + protected DeliveryChannel getDeliveryChannel() { + return this.mEndpoint.getDeliveryChannel(); + } + + protected void validateMessageExchange() throws MessagingException { + MessageExchange msgExchange = this.getMessageExchange(); + + if (this.getMessageExchange() == null) { + throw new MessagingException("MessageExchange Object is null in MessageExchageHandler"); + } + + if (MessageExchange.Role.CONSUMER.equals(msgExchange.getRole())) { + throw new MessagingException("Provider Message Exchange Handler can not have MessageExchange with CONSUMER Role"); + } + + if (!(msgExchange instanceof InOut)) { + throw new MessagingException("InOut Message Exchange Handler MessageExchange object should be instanceof javax.jbi.messaging.InOut "); + } + } + + protected void processError(Exception ex) { + MessageExchange msgExchange = this.getMessageExchange(); + Exception errEx = msgExchange.getError(); // get the error and print + RuntimeHelper.getLogger().info( + "InOut Message Exchange Provider received Error: " + errEx.getMessage()); + msgExchange.getError().printStackTrace(); + } + + protected void processDone() { + MessageExchange msgExchange = this.getMessageExchange(); + RuntimeHelper.getLogger().info("InOut Message Exchange Provider received DONE :" + + " END of service invocation"); + } + + protected void processFault(Fault fault) { + MessageExchange msgExchange = this.getMessageExchange(); + RuntimeHelper.logError("InOut Message Exchange Provider Handler can not receive Fault on Provider side"); + } + + protected void processMessage() { + try { + processInMessageOnProvider((InOut) this.getMessageExchange()); + } catch (JBIException ex) { + ex.printStackTrace(); + } + } + + protected void processInMessageOnProvider(InOut inOutExchange) throws JBIException { + RuntimeHelper.getLogger().fine("Processing In Message on Provider side " + inOutExchange); + // receive IN message. + NormalizedMessage inMsg = inOutExchange.getInMessage(); + NormalizedMessage outMsg = null; + Fault fault = null; + DOMSource inContent = null; + DOMSource outContent = null; + Source faultContent = null; + String faultAsText = null; + + QName opName = inOutExchange.getOperation(); + QName svcName = inOutExchange.getEndpoint().getServiceName(); + Operation wsdlOperation = this.mEndpoint.getWSDLOperation(opName); + + // process in message + // invoke the service operation + try { + inContent = this.mNormalizer.denormalizeInput(wsdlOperation, inMsg); + StringBuffer outputDoc = invokeOperation(opName.getLocalPart(), + RuntimeHelper.readFromDOMSource(inContent)); + outContent = RuntimeHelper.createDOMSource(new StringReader(outputDoc.toString())); + } catch (Exception ex) { + // exception invoking the operation. so, set exception text as fault content. + ex.printStackTrace(); + faultAsText = RuntimeHelper.getExceptionAsText(ex); + String faultText = RuntimeHelper.getExceptionAsXmlText(ex); + faultContent = RuntimeHelper.createDOMSource(new StringReader(faultText)); + } + // set out or fault message + if (outContent != null) { + // set the out message content. + outMsg = inOutExchange.createMessage(); + inOutExchange.setOutMessage(outMsg); + this.mNormalizer.normalizeOutput(wsdlOperation, outMsg, outContent); + // outMsg.setContent(outContent); + } else if (faultContent != null) { + fault = inOutExchange.createFault(); + inOutExchange.setFault(fault); + fault.setContent(faultContent); // may need to normalize the content. + } + // send out or fault message. + this.send(); + } + + protected StringBuffer invokeOperation(String operation, StringBuffer inputDoc) throws MessagingException { + try { + StringBuffer outputDoc = invokeSendMessage(this.mServiceURL, this.mUsername, this.mPassword, + this.mMBeanName, operation, inputDoc); + return outputDoc; + } catch (Exception ex) { + ex.printStackTrace(); + throw new MessagingException(ex); + } + } + + /** + * invokes a jmx mbean to send message. + */ + protected StringBuffer invokeSendMessage(String serviceURL, String username, String password, + String mbeanName, String operation, StringBuffer inputDoc) + throws MessagingException { + + JMXConnector jmxConnector = null; + MBeanServerConnection jmxConn = null; + JMXServiceURL jmxURL = null; + ObjectName epAddressName = null; + + Map env = new HashMap(); + if (username != null) { + String[] credentials = new String[]{username, password}; + env.put("jmx.remote.credentials", credentials); + env.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, this.getClass().getClassLoader()); + } + + StringBuffer outDoc = null; + + Object result = null; + String mbeanOperation = "sendMessage"; + + Object[] params = new Object[2]; + params[0] = operation; + params[1] = inputDoc; + + String[] signature = new String[2]; + signature[0] = "java.lang.String"; + signature[1] = "java.lang.StringBuffer"; + + try { + jmxURL = new JMXServiceURL(serviceURL); + epAddressName = new ObjectName(mbeanName); + + jmxConnector = JMXConnectorFactory.connect(jmxURL, env); + jmxConn = jmxConnector.getMBeanServerConnection(); + + result = jmxConn.invoke(epAddressName, mbeanOperation, params, signature); + if (result != null) { + outDoc = (StringBuffer) result; + } + } catch (Exception ex) { + throw new MessagingException(ex); + } finally { + if (jmxConnector != null) { + try { + jmxConnector.close(); + } catch (IOException ex) { + RuntimeHelper.logDebug(ex); + // ingore + } + } + } + return outDoc; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingRuntime.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingRuntime.java new file mode 100644 index 000000000..a3252887e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingRuntime.java @@ -0,0 +1,57 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingRuntime.java + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.ComponentRuntime; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.component.ServiceUnitManager; + +/** + * This class extends the ComponentRuntime that implements + * javax.jbi.component.Component interface required for the component contract + * at runtime. + * + * This class provides the component specific ComponentLifeCycle implementation + * as well as the component specific ServiceUnitManager implementation. + * + * Add any additional component runtime specific functionality here. + * + * @see javax.jbi.component.Component + * @see com.sun.jbi.sample.component.common.ComponentRuntime + * @see com.sun.jbi.sample.component.common.BasicComponentLifecycle + * @see + * com.sun.jbi.sample.component.common.deployment.AbstractServiceUnitManager + * @author chikkala + */ +public class JMXBindingRuntime extends ComponentRuntime { + + /** + * Creates a new instance of MyBindingRuntime + */ + public JMXBindingRuntime() { + super(); + } + + /** + * overriding the parent's createComponentLifeCycle to create MyBinding + * specific component lifecycle implementation. + */ + @Override + protected ComponentLifeCycle createComponentLifeCycle() { + return new JMXBindingComponentLifeCycle(this); + } + + /** + * if this component supports service unit deployment, then return the + * service unit manager, else return null. Extended classes can override + * this method and do their own ServiceUnitManager specific creation. + */ + @Override + protected ServiceUnitManager createServiceUnitManager() { + return new JMXBindingSUManager(this); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingSUManager.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingSUManager.java new file mode 100644 index 000000000..75968c59a --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingSUManager.java @@ -0,0 +1,51 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingSUManager.java + * + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.deployment.AbstractServiceUnitManager; +import net.openesb.component.${artifactId}.common.deployment.ServiceUnit; +import java.util.logging.Logger; +import javax.jbi.management.DeploymentException; + +/** + * This class extends the AbstractServiceUnitManager to implement component + * specific service unit manager by creating the component specific ServiceUnit + * implementation. + * + * @see + * com.sun.jbi.sample.component.common.deployment.AbstractServiceUnitManager + * @see com.sun.jbi.sample.component.common.deployment.ServiceUnit + * + * @author chikkala + */ +public class JMXBindingSUManager extends AbstractServiceUnitManager { + + private JMXBindingRuntime mRuntime; + + /** + * Creates a new instance of JMXBindingSUManager + */ + public JMXBindingSUManager(JMXBindingRuntime compRuntime) { + super(); + this.mRuntime = compRuntime; + } + + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + + protected String getComponentName() { + return RuntimeHelper.getComponentName(); + } + + //TODO implement ProviderSEServiceUnit + protected ServiceUnit createServiceUnit(String suName, String suRootPath) throws DeploymentException { + return new JMXBindingServiceUnit(suName, suRootPath); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingServiceUnit.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingServiceUnit.java new file mode 100644 index 000000000..9175742ba --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingServiceUnit.java @@ -0,0 +1,55 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingServiceUnit.java + * + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.common.deployment.ConsumerEndpoint; +import net.openesb.component.${artifactId}.common.deployment.ProviderEndpoint; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Consumes; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Provides; +import net.openesb.component.${artifactId}.common.deployment.ServiceUnit; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import javax.jbi.management.DeploymentException; +import javax.wsdl.Definition; + +/** + * This class extends the ServiceUnit to implement the component specific + * service unit processing. It creates the component specific ProviderEndpoint + * and ConsumerEndpoint implementation to configure the service provider and + * consumer endpoints on this component deployed in the service unit. + * + * @author chikkala + */ +public class JMXBindingServiceUnit extends ServiceUnit { + + /** + * Creates a new instance of ProviderSEServiceUnit + */ + public JMXBindingServiceUnit(String suName, String suRootPath) { + super(suName, suRootPath); + } + + @Override + protected WSDLProcessor createWSDLProcessor() { + return new JMXBindingWSDLProcessor(this.getSURootPath()); + } + + @Override + protected ConsumerEndpoint createConsumerEndpoint(Consumes consumes, Definition wsdlDef) { + return new JMXBindingConsumerEndpoint(consumes, wsdlDef, this); + } + + @Override + protected ProviderEndpoint createProviderEndpoint(Provides provides, Definition wsdlDef) { + return new JMXBindingProviderEndpoint(provides, wsdlDef, this); + } + + @Override + protected void loadOtherArtifacts() throws DeploymentException { + //TODO: load any component specific service unit artifacts + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingWSDLProcessor.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingWSDLProcessor.java new file mode 100644 index 000000000..67b92ee50 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXBindingWSDLProcessor.java @@ -0,0 +1,43 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingWSDLProcessor.java + * + */ +package net.openesb.component.${artifactId}; + +import net.openesb.component.${artifactId}.wsdlext.WSDLExtensionRegistry; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import javax.wsdl.extensions.ExtensionRegistry; + +/** + * This class extends form the WSDLProcessor to configure the wsdl processor use + * the wsdl extension registry configured to process the binding specific + * extension elements in the wsdl documents. + * + * WSDLExtensionRegistry that is created here has the wsdl extension model + * required to process the extension elements specific to the binding used by + * this binding component. + * + * @author chikkala + */ +public class JMXBindingWSDLProcessor extends WSDLProcessor { + + private WSDLExtensionRegistry mExtRegistry; + + /** + * Creates a new instance of JMXBindingWSDLProcessor + */ + public JMXBindingWSDLProcessor(String wsdlDir) { + super(wsdlDir); + } + + @Override + protected ExtensionRegistry getExtensionRegistry() { + if (this.mExtRegistry == null) { + this.mExtRegistry = new WSDLExtensionRegistry(); + } + return this.mExtRegistry; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXEndpointMBean.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXEndpointMBean.java new file mode 100644 index 000000000..3c14041e8 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/JMXEndpointMBean.java @@ -0,0 +1,41 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXEndpointMBean.java + */ +package net.openesb.component.${artifactId}; + +/** + * The sample BC implemented as a jmx binding component exposes this interface + * as a external connectivity (endpoint address) to the external service + * consumers that can exchange messages over jmx protocol to invoke services + * provided inside jbi environment. + * + * A jmx client can send a message by invoking this method using jmx management + * interface. When this mbean method is executed in the BC as a result of mbean + * call from the jmx client, the BC acts as a proxy service consumer inside the + * jbi environment and starts a message exchange with the service provider. + * + * If the operation being executed is a InOut operation, the BC should return + * the Out or Fault message from the InOut message exchange as a return value to + * complete invocation of the service by the external consumer. + * + * @author chikkala + */ +public interface JMXEndpointMBean { + + /** + * This method will be called by a jmx client as a service consumer to send + * message to the echo service provider to invoke the service for a InOut + * message exchange. + * + * @param operation operation name on a service + * @param inputDoc input xml document for the InOut operation + * @return output xml document in a StringBuffer received from InOut + * operation of the service invoked. or null if the operation is InOnly. + * @throws java.lang.Exception if any error occurs in invoking the operation + * on the service. + */ + StringBuffer sendMessage(String operation, StringBuffer inputDoc) throws Exception; +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java new file mode 100644 index 000000000..4987029b3 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java @@ -0,0 +1,141 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractMessageExchangeHandler.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import java.io.StringReader; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.Fault; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; +import javax.xml.namespace.QName; + +/** + * This class is an abstract implementation of the MessageExchangeHandler which + * provides the base implementation of the ME processing and provides hooks to + * extended classes to implement component specific processing. + * + * @author chikkala + */ +public abstract class AbstractMessageExchangeHandler implements MessageExchangeHandler { + + public static String IN_MESSAGE = "in"; + public static String OUT_MESSAGE = "out"; + + private MessageExchange mMessageExchange; + private ExchangeStatus mStatus; + /** Creates a new instance of AbstractMessageExchangeHandler */ + protected AbstractMessageExchangeHandler() { + this.mMessageExchange = null; + } + + protected abstract Logger getLogger(); + protected abstract DeliveryChannel getDeliveryChannel(); + protected abstract void validateMessageExchange() throws MessagingException; + protected abstract void processError(Exception ex); + protected abstract void processDone(); + protected abstract void processMessage(); + protected abstract void processFault(Fault fault); + + public final MessageExchange getMessageExchange() { + return this.mMessageExchange; + } + + public final void setMessageExchange(MessageExchange msgExchange) { + this.mMessageExchange = msgExchange; + } + + public final ExchangeStatus getMessageExchangeStatus() { + if ( this.mStatus != null ) { + return this.mStatus; + } else if ( this.mMessageExchange != null ) { + return this.mMessageExchange.getStatus(); + } else { + return null; + } + } + + public final void setMessageExchangeStatus(ExchangeStatus status) { + this.mStatus = status; + } + + protected void send() throws MessagingException { + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected boolean sendSync(long timeout) throws MessagingException { + return this.getDeliveryChannel().sendSync(this.mMessageExchange, timeout); + } + + protected void sendDone() throws MessagingException { + this.mMessageExchange.setStatus(ExchangeStatus.DONE); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void sendError(Exception ex) throws MessagingException { + this.mMessageExchange.setError(ex); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void sendFault(Exception ex, QName type, String name) throws MessagingException { + Fault fault = this.mMessageExchange.createFault(); + if ( ex != null ) { + String xmlText = RuntimeHelper.getExceptionAsXmlText(ex); + fault.setContent(RuntimeHelper.createDOMSource(new StringReader(xmlText))); + } + this.mMessageExchange.setFault(fault); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void processActive() { + Fault fault = this.getMessageExchange().getFault(); + if ( fault != null ) { + processFault(fault); + } else { + processMessage(); + } + } + /** + * implementation of the MessageExchangeHandler${symbol_pound}processMessageExchange method. + */ + public void processMessageExchange(ExchangeStatus status, MessageExchange msgEx) { + + getLogger().fine("MessageExchangeHandler.processMessageExchange:status: " + status ); + + this.setMessageExchangeStatus(status); + this.setMessageExchange(msgEx); + + try { + validateMessageExchange(); + } catch (MessagingException ex) { + getLogger().log(Level.FINE, "Invalid message exchange for processing ", ex); + if ( this.getMessageExchange() != null ) { + try { + sendError(ex); + } catch (MessagingException errEx) { + getLogger().log(Level.FINE, "Can not send invalid message exchange error", errEx); + } + } + return; + } + + MessageExchange msgExchange = this.getMessageExchange(); + + if (ExchangeStatus.ACTIVE.equals(status) ) { + processActive(); + } else if (ExchangeStatus.DONE.equals(status) ) { + processDone(); + } else if (ExchangeStatus.ERROR.equals(status) ) { + processError(msgExchange.getError()); + } + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java new file mode 100644 index 000000000..d76fbe0f9 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java @@ -0,0 +1,398 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractComponentLifeCycle.java + */ + +package net.openesb.component.${artifactId}.common; + +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.component.Component; +import javax.jbi.component.ComponentContext; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.MessagingException; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.StandardMBean; + +/** + * This class implements the javax.jbi.component.ComponentLifeCycle. This is an + * abstract class that keeps the reference to the component context and the lifecycle + * extension mbeans. It implements the lifecycle method and provide the extended methods + * for each lifecycle methods to implement component specific functionality. + *

+ * It makes sure that the mininum initialization required for the component + * lifecycle is implemented by this class or the classes extending this class. + *

+ * Another important functionality implemented in this class is that it initializes the global + * RuntimeContext for the component with the ComponentContext passed by the JBI runtime and the + * opened delivery channel to make them available globally to any class in the component implementation + * that may need it during component lifecycle + *

+ * Service engine or a binding component lifecycle implementation can directly extend + * this class for their required functionality and override some of the methods to provide + * their own implementation. + * + * @see javax.jbi.ComponentLifeCycle + * @author chikkala + */ +public class BasicComponentLifeCycle implements ComponentLifeCycle { + /** reference to the component runtime */ + private Component mCompRuntime; + /** component context */ + private ComponentContext mComponentContext; + /** Extension Mbean Name*/ + private ObjectName mExtensionMBeanName; + /** Extension Mbean Implementation*/ + private StandardMBean mExtensionMBeanImpl; + /** a message receiver that accepts messages from delivery channel */ + private MessageExchangeReceiver mMsgExchReceiver; + + /** + * constructor for the ComponentLifecycle implementation. + * @param compRuntime + */ + protected BasicComponentLifeCycle(Component compRuntime) { + this.mCompRuntime = compRuntime; + } + /** + * @return Component + */ + public final Component getComponentRuntime() { + return this.mCompRuntime; + } + /** + * @return ComponentContext component context. + */ + public final ComponentContext getComponentContext() { + return mComponentContext; + } + /** + * @return component name + */ + protected String getComponentName() { + return (this.mComponentContext != null) ? + this.mComponentContext.getComponentName() : null; + } + /////////////////////////////////////////////////////////////////////////// + // ComponentLifeCycle interface implemenation + /////////////////////////////////////////////////////////////////////////// + + /** + * Initializes the component lifecycle. This method makes sure that the + * component context passed by the jbi runtime is saved in the lifecycle + * object before calling the other component initialization methods to + * completely initialize the component. + * @param context Component context + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}init(javax.jbi.component.ComponentContext) + * @throws javax.jbi.JBIException on error + */ + public final void init(ComponentContext context) throws JBIException { + + if ( context == null ) { + throw new JBIException("Null Component Context received in " + + "Component Lifecycle init "); + } + this.mComponentContext = context; // 0. save the component context passed by jbi framework. + // initialize the content + initGlobalContext(); // 1. Initialize component runtime context. + registerExtensionMBean(); // 2. Create and register extension mbean. + openDeliveryChannel(); // 3. Open delivery channel. + initMessageExchangeReceiver(); // 4. Create message exchange receiver. + doInit(); // 5. Do any component specific initialization such + // as static service providers and consumers initialization. + + this.getLogger().fine("Component " + this.getComponentName() + " initialized"); + } + + /** + * Starts the component. Extended classes can override/implement the methods called + * in this method to provide component specify start functionality. + * + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}start() + * @throws javax.jbi.JBIException on error + */ + public final void start() throws JBIException { + + doStart(); // 1. do any other component specific start tasks such as + // activating any static service providers and consumers. + startMessageExchangeProcessing(); // 2. begin accepting and processing message exchanges. + + this.getLogger().fine("Component " + this.getComponentName() + " started"); + } + + /** + * Stop the component.Extended classes can override/implement the methods called + * in this method to provide component specify stop functionality. + * @throws javax.jbi.JBIException + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}stop() + */ + public final void stop() throws JBIException { + + stopMessageExchangeProcessing(); // 1. stop accepting and processing message exchanges. + doStop(); // 2. do any other component specific stop tasks such as + // deactivating any static service providers and consumers. + this.getLogger().fine("Component " + this.getComponentName() + " stopped."); + } + + /** + * Shut down the component. Extended classes can override/implement the methods called + * in this method to provide component specify shut down functionality. + * @throws javax.jbi.JBIException + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}shutDown() + */ + public final void shutDown() throws JBIException { + // clean up all resources. + shutdownMessageExchangeReceiver(); // 1. remove the message receiver. + closeDeliveryChannel(); // 2. close delivery channel + unregisterExtensionMBean(); // 3. unregister and remove extension mbean if exists. + doShutDown(); // 4. do any other component specific clean up tasks such + // as clean any static service providers and consumer resource. + this.getLogger().fine("Component " + this.getComponentName() + " shut down"); + } + /** + * create jmx object name for the extension mbean. default implementation does + * not required to have the extension mbean. + * @return ObjectName of the extension mbean + */ + protected ObjectName createExtensionMBeanName() { + return null; + } + /** + * gets the reference to the extension mbean name. + * @see javax.jbi.component.ComponentLifeCycle${symbol_pound}getExtensionMBeanName() + * @return ObjectName of the extension mbean objectname or null if component + * does not support extension mbean + */ + public final ObjectName getExtensionMBeanName() { + if ( this.mExtensionMBeanName == null ) { + this.mExtensionMBeanName = this.createExtensionMBeanName(); + } + return this.mExtensionMBeanName; + } + /** + * create mbean implementation for the extension mbean as a StandardMBean. default + * implementation does not require the extension mbean + * @return the ExtensionMBean implementation as StandardMBean + */ + protected StandardMBean createExtensionMBean() { + return null; + } + /** + * gets the reference to the extension mbean. + * @return extension mbean implementation or null if component does not support. + */ + protected final StandardMBean getExtensionMBean() { + if ( this.mExtensionMBeanImpl == null ) { + this.mExtensionMBeanImpl = this.createExtensionMBean(); + } + return this.mExtensionMBeanImpl; + } + /** + * if there is an extension mbean supported by the component, then register + * it with the mbean server. + * @throws JBIException on error registering mbean + */ + protected final void registerExtensionMBean() throws JBIException { + // creatre the extension mbean's object name + ObjectName mbeanName = this.getExtensionMBeanName(); + // create the extension mbean implemenation. + StandardMBean mbeanImpl = this.getExtensionMBean(); + + if ( mbeanName == null || mbeanImpl == null ) { + this.getLogger().fine(this.getComponentName() + + " Does not have Extension MBean implemenation "); + return; + } + // register with mbean only if object name and implementation are non null + try { + MBeanServer mbServer = RuntimeHelper.getComponentContext().getMBeanServer(); + mbServer.registerMBean(mbeanImpl, mbeanName); + } catch (Exception e) { + throw new JBIException("Failed to register Extension MBean for " + + this.getComponentName(), e); + } + } + /** + * remove the registered extension mbean from the mbean server if any. + */ + protected final void unregisterExtensionMBean() { + ObjectName mbeanName = this.getExtensionMBeanName(); + if ( mbeanName == null ) { + return; + } + try { + MBeanServer mbServer = RuntimeHelper.getComponentContext().getMBeanServer(); + mbServer.unregisterMBean(mbeanName); + } catch (Exception e) { + this.getLogger().log(Level.WARNING, + "Failed to unregister Extension MBean from MBeanServer for " + this.getComponentName(), e); + } + } + /** + * creates MessageExchangeReceiver implementation that handles receiving and processing + * the message exchanges from the delivery channel. Component should implement + * this method to provide the MessageReceiver. + * + * Component may return null indicating that they don't need the message receiver + * that can receive and process message exchanges from delivery channel. For example, + * components that have only service consumers which send a synchronous messages to + * providers don't need this. + * + * @throws java.lang.Exception + * @return MessageExchangeReceiver implementation. null if the component does not support it. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle${symbol_pound}createMessageExchangeReceiver + */ + protected MessageExchangeReceiver createMessageExchangeReceiver() { + return null; + } + /** + * returns the message exchange receiver implementation reference + * @return MessageExchangeReceiver interface + */ + protected final MessageExchangeReceiver getMessageExchangeReceiver() { + if ( this.mMsgExchReceiver == null ) { + this.mMsgExchReceiver = createMessageExchangeReceiver(); + } + return this.mMsgExchReceiver; + } + /** + * creates a message receiver object as part of the component initialization. + * @throws javax.jbi.JBIException + */ + protected void initMessageExchangeReceiver() throws JBIException { + // create and initialize the MessageExchangeReceiver + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.initReceiver(); + } + } + /** + * allows the component to accept the message exchange objects from the + * delivery channel and process it as part of the component startup process. + * @throws javax.jbi.JBIException + */ + protected void startMessageExchangeProcessing() throws JBIException { + // start message processing + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.startProcessing(); + } + } + /** + * stops the component from accepting the message exchange objects from the + * delivery channel as part of the component stop process + * @throws javax.jbi.JBIException + */ + protected void stopMessageExchangeProcessing() throws JBIException { + // stop message processing + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.stopProcessing(); + } + } + /** + * removes the message receiver as part of the component shutdown process + * @throws javax.jbi.JBIException + */ + protected void shutdownMessageExchangeReceiver() throws JBIException { + // clean up message processing. + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.shutdownReceiver(); + } + } + /** + * Returns logger initialized from the component context or a default logger. + * @return Logger + */ + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** + * initializes the RuntimeContext during component init lifecycle phase. This + * includes setting the ComponentContext and loggers etc. extended classes must + * save the component context in the RuntimeContext in this methods implementation. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle${symbol_pound}initGlobalContext + */ + protected void initGlobalContext() { + RuntimeContext.getInstance().setComponentContext(this.getComponentContext()); + RuntimeContext.getInstance().setLogger(this.getClass().getName(), null); + } + /** opens the delivery channel to accept or send message exchange objects + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle${symbol_pound}openDeliveryChannel + */ + protected void openDeliveryChannel() { + try { + DeliveryChannel channel = this.getComponentContext().getDeliveryChannel(); + RuntimeContext.getInstance().setDeliveryChannel(channel); + } catch (MessagingException ex) { + ex.printStackTrace(); + } + } + /** closes the delivery channel as part of the component shutdown process. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle${symbol_pound}closeDeliveryChannel + */ + protected void closeDeliveryChannel() { + // closes delivery channel and remove the reference. + try { + DeliveryChannel channel = RuntimeHelper.getDeliveryChannel(); + if ( channel != null ) { + channel.close(); + } + } catch (MessagingException ex) { + ex.printStackTrace(); + } finally { + RuntimeContext.getInstance().setDeliveryChannel(null); + } + } + /** + * chance to extended classes to do any extra component specific init tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * initialized here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle${symbol_pound}init method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle${symbol_pound}init + */ + protected void doInit() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific start tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * activated here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle${symbol_pound}start method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle${symbol_pound}start + */ + protected void doStart() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific stop tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * deactivated here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle${symbol_pound}stop method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle${symbol_pound}stop + */ + protected void doStop() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific shutdown tasks.If the component + * supports static service providers or consumers without deployment support, they can be + * cleaned up here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle${symbol_pound}shutdown method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle${symbol_pound}shutdown + */ + protected void doShutDown() throws JBIException { + //NOOP + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/ComponentInstaller.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/ComponentInstaller.java new file mode 100644 index 000000000..7e44dc053 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/ComponentInstaller.java @@ -0,0 +1,275 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + /* + * ComponentInstaller.java + */ +package net.openesb.component.${artifactId}.common; + +import java.util.List; +import java.util.logging.Level; +import javax.jbi.component.Bootstrap; +import javax.jbi.component.InstallationContext; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.StandardMBean; + +/** + * This class implements the javax.jbi.component.Bootstrap. This class implements + * the minimum required functionality for component installation contract + * of the jbi component in the jbi environment. It also takes care of maintaining + * the installation context reference and installation specific logger creation and + * installation extension mbean registration and unregistration during initialization + * and cleanup. Extended classes only need to supply the mbean name and its implementation + * object for the installation extensions. + * + * It makes sure that the installation context and the loggers are available to + * the classes extended from this class to add more installation specific functionality. + * + * Service engine or a binding component installation implementation can directly use + * this class or extend this class to add more functionality to their installation + * process. + * + * @see javax.jbi.Bootstrap + * @author chikkala + */ +public class ComponentInstaller implements Bootstrap { + /** default logger*/ + private Logger mDefLogger; + /** bootstrap logger */ + private Logger mBTLogger ; + /** Installation Context . */ + private InstallationContext mInstallationContext; + /** Extension Mbean Name*/ + private ObjectName mExtensionMBeanName; + /** Extension Mbean Implementation*/ + private StandardMBean mExtensionMBeanImpl; + + /** Constructor to create the ComponentInstaller. */ + public ComponentInstaller() { + } + /** + * @return InstallationContext of the component. + */ + public final InstallationContext getInstallationContext() { + return this.mInstallationContext; + } + protected String getComponentName() { + return (this.mInstallationContext != null) ? + this.mInstallationContext.getComponentName() : null; + } + /** + * @return logger initialized from the installation context or a default + * logger. + */ + protected Logger getLogger() { + // try init bootstrap logger + if (this.mBTLogger == null && this.mInstallationContext != null ) { + try { + this.mBTLogger = + this.mInstallationContext.getContext().getLogger(this.getClass().getName(), null); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + // init default logger if required + if ( this.mBTLogger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (this.mBTLogger != null) ? this.mBTLogger : this.mDefLogger; + } + /** + * Initializes the installation environment for a component. + * @see javax.jbi.component.Bootstrap${symbol_pound}init(javax.jbi.component.InstallationContext) + */ + public final void init(InstallationContext installContext) throws javax.jbi.JBIException { + + if ( installContext == null ) { + throw new JBIException("Null Installation Context received in " + + "Component Bootstrap initialization"); + } + // save the installation context reference passed by the jbi framework. + this.mInstallationContext = installContext; + registerExtensionMBean(); // create and register extension mbean + doInit(); // do any other extra initialization required specific to the component installation. + // initialize logger + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component Installer initialized"); + } + /** + * default implementation just logs the method call. extended classes should override this. + * @see javax.jbi.component.Bootstrap${symbol_pound}onInstall() + */ + public void onInstall() throws javax.jbi.JBIException { + //TODO: do required initializaton and resource creation + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component installed."); + } + /** + * default implementation just logs the method call. + * @see javax.jbi.component.Bootstrap${symbol_pound}onUninstall() + */ + public void onUninstall() throws javax.jbi.JBIException { + //TODO: do clean up the resource and other stuff. + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component uninstalled"); + } + /** + * default noop implementation of the cleanup. + * @see javax.jbi.component.Bootstrap${symbol_pound}cleanUp() + */ + public final void cleanUp() throws javax.jbi.JBIException { + + unregisterExtensionMBean(); // unregister extension mbean and remove it + doCleanUp(); // do any other extra cleanup specific to the component installation. + this.getLogger().fine( this.mInstallationContext.getComponentName() + + " Component Installer Cleaned up"); + } + + /** + * create jmx object name for the extension mbean. Extended classes should + * return the component specific installer extension mbean name here. + */ + protected ObjectName createExtensionMBeanName() { + return null; + } + /** + * default implementation that does not have extension mbean return null. + * @see javax.jbi.component.Bootstrap${symbol_pound}getExtensionMBeanName() + */ + public final javax.management.ObjectName getExtensionMBeanName() { + if ( this.mExtensionMBeanName == null ) { + this.mExtensionMBeanName = createExtensionMBeanName(); + } + return this.mExtensionMBeanName; + } + /** + * create mbean implementation for the extension mbean as a StandardMBean. Extended + * classes should return the installer extension mbean implementation as the + * standard mbean. + */ + protected StandardMBean createExtensionMBean() { + return null; + } + /** + * returns the installation extension mbean implementation. + * @return StandardMBean for the extension mbean implementation. + */ + protected final StandardMBean getExtensionMBean() { + if ( this.mExtensionMBeanImpl == null ) { + this.mExtensionMBeanImpl = this.createExtensionMBean(); + } + return this.mExtensionMBeanImpl; + } + /** + * Chance to extended classes to do the component installation specific init. + * Installation context will be initialized before calling this method. So, + * initialize other things if required in this method. + * @throws javax.jbi.JBIException on error + * @see com.sun.jbi.sample.component.common.ComponentInstaller${symbol_pound}init( + * javax.jbi.component.InstallationContext) + */ + protected void doInit() throws JBIException { + this.getLogger().info(this.getInstallationContext().getComponentName() + + " : Component Installer initialized"); + } + /** + * Chance to extended classes to do the component installation specific cleanup. + * ExtensionMbean will be unregistered before calling this method. + * @throws javax.jbi.JBIException on error + * @see com.sun.jbi.sample.component.common.ComponentInstaller${symbol_pound}cleanUp( + * javax.jbi.component.InstallationContext) + */ + protected void doCleanUp() throws JBIException { + this.getLogger().fine(this.getInstallationContext().getComponentName() + + " : Component Installer doCleanUp"); + } + /** + * if there is an extension mbean supported by the component, then register + * it with the mbean server. + */ + protected void registerExtensionMBean() throws JBIException { + // creatre the installation extension mbean's object name + ObjectName mbeanName = this.getExtensionMBeanName(); + // create the extension mbean implemenation if the object name is created. + StandardMBean mbeanImpl = this.getExtensionMBean(); + + if ( mbeanName == null || mbeanImpl == null ) { + this.getLogger().fine(this.getComponentName() + + " Does not have Installation Extension MBean implemenation "); + return; + } + // register with mbean only if object name and implementation are non null + try { + MBeanServer mbServer = this.getInstallationContext().getContext().getMBeanServer(); + mbServer.registerMBean(mbeanImpl, mbeanName); + } catch (Exception e) { + throw new JBIException("Failed to register Installation Extension MBean for " + + this.getComponentName(), e); + } + } + /** + * remove the registered extension mbean from the mbean server. + */ + protected void unregisterExtensionMBean() { + ObjectName mbeanName = this.getExtensionMBeanName(); + if ( mbeanName == null ) { + return; + } + try { + MBeanServer mbServer = this.getInstallationContext().getContext().getMBeanServer(); + mbServer.unregisterMBean(mbeanName); + } catch (Exception e) { + this.getLogger().log(Level.WARNING, + "Failed to unregister Installation extension MBean for " + this.getComponentName(), e); + } + } + /** + * This method is called by the JBI runtime to allow a component to upgrade + * it's workspace and any existing Service Units to match the new version of + * the component. The JBI runtime copies the existing workspace root to the + * new workspace root prior to calling this method, so that the component + * can examine the contents of the workspace root to determine the version + * of the component from which the upgrade is being made. All updates to the + * workspace root are done in-place; in the event of a failure, the JBI + * runtime reverts back to the original workspace root, the original install + * root, and the original Service Unit roots for the component. + * + * Note1: The component must ensure that it never holds open references + * to any files in the workspace root or any of the Service Unit roots upon + * returning from this method. Failure to do so will cause problems when + * the runtime attempts to complete the upgrade processing. + * + * Note2: The installation context that is normally initialized + * by the runtime by calling ${symbol_pound}init method of the javax.jbi.Bootstrap interface + * before install and uninstall will not be called before calling this + * upgrade method. So, installation context can not be used in this method's + * implementation. + * + * Note3: Since there won't be any installation context available, the logger + * that returned from the ${symbol_pound}getLogger method is a default logger created using + * the package name of this class or extended class if the method is overridden + * in the extended class. + * + * @param workspaceRoot the workspace root for the new version of the + * component that will replace the currently installed version. This is + * populated with the contents of the original workspace root and the + * component must update it to match the new version of the component. + * @param serviceUnitRoots a list of directory paths to all of the Service + * Units currently deployed to the component. The component must update all + * of these to match the new version of the component. + * @exception JBIException when there is an error requiring that the upgrade + * be terminated. + */ + public void upgrade(String workspaceRoot, List serviceUnitRoots) + throws javax.jbi.JBIException + { + //TODO: override this method in the extended class to handle the + // workspace root and service unit roots upgrade according to the + // component's requirement. + this.getLogger().fine("Default upgrade implementation. " + + "TODO: Implement workspace root and service unit roots upgrade."); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/ComponentRuntime.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/ComponentRuntime.java new file mode 100644 index 000000000..5c32ce274 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/ComponentRuntime.java @@ -0,0 +1,174 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ComponentRuntime.java + */ +package net.openesb.component.${artifactId}.common; + +import java.util.logging.Logger; +import javax.jbi.component.Component; +import javax.jbi.component.ComponentContext; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.component.ServiceUnitManager; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.servicedesc.ServiceEndpoint; +import org.w3c.dom.Document; +import org.w3c.dom.DocumentFragment; + +/** + * This class implements javax.jbi.component.Component interface which is + * responsible for creating the Component Lifecycle implementation and the + * ServiceUnitManager implementation for the jbi component. + * + * This class makes sure that non null component lifecycle implementation is + * returns by this class or any classes extended from this class which is + * required as a component contract. It also provides default implementation of + * all methods of the Component interface which the extended classes can + * override to add more functionality. + * + * @see javax.jbi.component.Component + * @author chikkala + */ +public class ComponentRuntime implements Component { + /** Component LifeCycle implementation */ + private ComponentLifeCycle mLifeCycle; + /** ServiceUnitManager implementation */ + private ServiceUnitManager mSUManager; + /** default logger*/ + private Logger mDefLogger; + + /** Creates a new instance of ComponentImpl */ + public ComponentRuntime() { + this.mLifeCycle = null; + this.mSUManager = null; + } + /** + * returns the ComponentContext. Any component runtime class extended from + * this class can override this method to return their own reference to the + * ComponentContext. + * @return ComponentContext component context. + */ + public ComponentContext getComponentContext() { + ComponentContext ctx = null; + if ( this.mLifeCycle != null && this.mLifeCycle instanceof BasicComponentLifeCycle ) { + ctx = ((BasicComponentLifeCycle) this.mLifeCycle).getComponentContext(); + } + return ctx; + } + /** + * Returns logger initialized from the component context or a default logger. + * @return Logger + */ + public Logger getLogger() { + Logger logger = null; + if ( this.mLifeCycle != null && this.mLifeCycle instanceof BasicComponentLifeCycle ) { + logger = ((BasicComponentLifeCycle) this.mLifeCycle).getLogger(); + } + // init default logger if required + if ( logger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (logger != null) ? logger : this.mDefLogger; + } + /** + * return the ComponentLifeCycle implementation. if returned null, the + * ComponentLifeCycleImpl will be used as the component lifecycle + * Extended classes can override this method and do their own ComponentLifecyle + * specific creation. + */ + protected ComponentLifeCycle createComponentLifeCycle() { + return new BasicComponentLifeCycle(this); + } + /** + * Get the life cycle control interface for this component. + * + * @return the life cycle control interface for this component + * @see javax.jbi.Component${symbol_pound}getLifeCycle() + */ + public final ComponentLifeCycle getLifeCycle() { + if ( this.mLifeCycle == null ) { + this.mLifeCycle = createComponentLifeCycle(); + if ( this.mLifeCycle == null ) { + this.getLogger().fine("Creating basic component lifecycle implemenation"); + // use the default ComponentLifeCycle Impl if a component + // specific implementation return null in createComponentLifeCycle. + this.mLifeCycle = new BasicComponentLifeCycle(this); + } + } + return this.mLifeCycle; + } + /** + * if this component supports service unit deployment, then return the + * service unit manager, else return null. + * Extended classes can override this method and do their own ServiceUnitManager + * specific creation. + */ + protected ServiceUnitManager createServiceUnitManager() { + return null; + } + /** + * Get the Service Unit manager for this component. + * + * @return the ServiceUnitManager for this component, or + * null if there is none. + * @see javax.jbi.Component${symbol_pound}getServiceUnitManager() + */ + public final ServiceUnitManager getServiceUnitManager() { + if ( this.mSUManager == null ) { + this.mSUManager = createServiceUnitManager(); + } + return this.mSUManager; + } + /** + * Retrieves a DOM representation containing metadata which describes the + * service provided by this component, through the given endpoint. + * + * Default implementation does not support service description. + * + * @see javax.jbi.Component${symbol_pound}getServiceDescription(javax.jbi.servicedesc.ServiceEndpoint) + */ + public Document getServiceDescription(ServiceEndpoint serviceEndpoint) { + return null; + } + /** + * This method is called by JBI to check if this component, in the role of + * provider of the service indicated by the given exchange, can actually + * perform the operation desired. + * + * Default implementation has no policy and allows all exchanges with consumer. + * + * @see javax.jbi.Component${symbol_pound}isExchangeWithProviderOkay( + * javax.jbi.servicedesc.ServiceEndpoint, javax.jbi.messaging.MessageExchange) + */ + public boolean isExchangeWithConsumerOkay( + ServiceEndpoint serviceEndpoint, MessageExchange messageExchange) { + return true; + } + /** + * This method is called by JBI to check if this component, in the role of + * consumer of the service indicated by the given exchange, can actually + * interact with the provider properly. The provider is described by the + * given endpoint and the service description supplied by that endpoint. + * + * Default implementation has no policy and allows all exchanges with provider. + * + * @see javax.jbi.Component${symbol_pound}isExchangeWithProviderOkay( + * javax.jbi.servicedesc.ServiceEndpoint, javax.jbi.messaging.MessageExchange) + */ + public boolean isExchangeWithProviderOkay( + ServiceEndpoint serviceEndpoint, MessageExchange messageExchange) { + return true; + } + /** + * Resolve the given endpoint reference. + * + * Default implementation does not have any XML dialect. So can not resolve the + * endpoint from the document fragment. + * + * @see javax.jbi.Component${symbol_pound}resolveEndpointReference(org.w3c.dom.DocumentFragment) + */ + public ServiceEndpoint resolveEndpointReference(DocumentFragment documentFragment) { + return null; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java new file mode 100644 index 000000000..51c85bc6e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java @@ -0,0 +1,180 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * DefaultMessageExchangeReceiver.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import javax.jbi.JBIException; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; + +/** + * This class implements MessageExchangeReceiver interface. This is a default implementation that + * demonstrates the multi-threaded environment to receive and process message exchanges from the + * delivery channel. It uses a main thread to receive message exchanges from the delivery channel + * and then processes the received message exchanges in a individual threads from the thread pool. + * The controller methods of MessageExchangeReceiver controls the main thread and the thread pool + * execution. + * + * @author chikkala + */ +public class DefaultMessageExchangeReceiver implements MessageExchangeReceiver { + + /** delivery channel accept time out */ + private final static long DC_ACCEPT_TIME_OUT = 3000; // milliseconds + /** receiver thread wait time before polling for messages after woke up **/ + private final static long RECEIVER_WAIT_TIME = 2000; // milliseconds + /** receiver thread wait time before force shutdown */ + private final static long RECEIVER_SHUTDOWN_WAIT_TIME = 10; // seconds + /** handler threads wait time before forced shutdown */ + private final static long HANDLERS_SHUTDOWN_WAIT_TIME = 30; // seconds + /** handler thread pool size */ + private final static int HANDLER_THREAD_POOL_SIZE = 5; + /** receiver thread accept message exchange condition */ + private Boolean mCanAccept = false; + /** receiver thread termination condition */ + private Boolean mContinue = true; + /** receiver thread executor service */ + private ExecutorService mReceiverThreadMgr; + /** handler thread executor service */ + private ExecutorService mHandlerThreadPool; + + /** no default constructor for extended classes */ + public DefaultMessageExchangeReceiver() { + } + /** + * this method is called from the ComponentLifecyle.init method of the AbstractComponentLifecycle + * to initialize the message exchange receiving resources such as threads and thread pools + * throws JBIException on error + */ + public final void initReceiver() throws JBIException { + + this.mHandlerThreadPool = Executors.newFixedThreadPool(HANDLER_THREAD_POOL_SIZE); + this.mReceiverThreadMgr = Executors.newSingleThreadExecutor(); + + this.mReceiverThreadMgr.execute(new Runnable() { + public void run() { + Thread t = Thread.currentThread(); + while ( mContinue ) { + if (mCanAccept) { + receiveAndProcessMessageExchange(); + } else { + try { + t.sleep(RECEIVER_WAIT_TIME); + } catch (InterruptedException interruptException) { + // someone must have interrupted this thread + // do nothing + RuntimeHelper.logDebug("Interrupted the MessageReceiverThread in Sleep"); + } + } + } + } + }); + } + /** + * this method is called from the ComponentLifecyle.shutdown method of the AbstractComponentLifecycle + * to cleanup the message exchange receiving resources such as threads and thread pools. + * throws JBIException on error + */ + public final void shutdownReceiver() throws JBIException { + + synchronized ( mContinue ) { + mContinue = false; + } + boolean terminated = false; + try { + this.mReceiverThreadMgr.shutdown(); + terminated = this.mReceiverThreadMgr.awaitTermination( + RECEIVER_SHUTDOWN_WAIT_TIME, TimeUnit.SECONDS); + } catch (InterruptedException ex) { + RuntimeHelper.logDebug(ex); + } finally { + if ( !terminated ) { + RuntimeHelper.logDebug("Message Receiver not shutdown. Forcing shutdown"); + this.mReceiverThreadMgr.shutdownNow(); + } + } + shutdownHandlers(); + } + /** + * shutdown all the working threads from the thread pool. + */ + private final void shutdownHandlers() throws JBIException { + + boolean terminated = false; + try { + this.mHandlerThreadPool.shutdown(); + terminated = this.mHandlerThreadPool.awaitTermination( + HANDLERS_SHUTDOWN_WAIT_TIME, TimeUnit.SECONDS); + } catch (InterruptedException ex) { + RuntimeHelper.logDebug(ex); + } finally { + if ( !terminated ) { + RuntimeHelper.logDebug("Handler threads not shutdown. Forcing shutdown"); + this.mHandlerThreadPool.shutdownNow(); + } + } + } + /** + * this method is called from the ComponentLifecyle.start method of the AbstractComponentLifecycle + * to start receiving the message exchanges from the delivery channel and process them. + * throws JBIException on error + */ + public final void startProcessing() throws JBIException { + + synchronized ( this.mCanAccept ) { + this.mCanAccept = true; + } + } + /** + * this method is called from the ComponentLifecyle.stop method of the AbstractComponentLifecycle + * to stop receiving the message exchanges from the delivery channel. + * throws JBIException on error + */ + public final void stopProcessing() throws JBIException { + + synchronized ( this.mCanAccept ) { + this.mCanAccept = false; + } + } + + protected MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeHelper.getMessageExchangeSupport(); + } + + private void receiveAndProcessMessageExchange() { + try { + DeliveryChannel channel = RuntimeHelper.getDeliveryChannel(); + if ( channel == null ) { + RuntimeHelper.logDebug("DeliveryChannel Not Opened for receiving messages"); + return; + } + final MessageExchange msgExchange = channel.accept(DC_ACCEPT_TIME_OUT); + if ( msgExchange == null ) { + // delivery channel timeout occurred. do nothing. + // RuntimeHelper.logDebug("DeliveryChannel returned null message exchange from accept"); + return; + } + final ExchangeStatus status = msgExchange.getStatus(); + // process message exchange in a separate thread + this.mHandlerThreadPool.execute(new Runnable() { + public void run() { + getMessageExchangeSupport().fireMessageExchangeReceived(status, msgExchange); + } + }); + + } catch (MessagingException ex) { + RuntimeHelper.logWarning(ex); + ex.printStackTrace(); + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java new file mode 100644 index 000000000..fed6c987d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java @@ -0,0 +1,31 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * MessageExchangeHandler.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; + +/** + * This interface is a Handler to perform message exchanges when the component + * receives the MessageExchange object from the delivery channel. + * Implementation of this interface should implement the processing of + * the active, error, done status of the MessageExchange object according to + * the MEP for which the MessageExchange object is created. + * + * @author chikkala + */ +public interface MessageExchangeHandler { + /** + * this method will be invoked to process the MessageExchange + * object. + * @param msgExchange MessageExchange object to process. + */ + void processMessageExchange(ExchangeStatus status, MessageExchange msgExchange); + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeListener.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeListener.java new file mode 100644 index 000000000..c27c1f221 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeListener.java @@ -0,0 +1,36 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * MessageExchangeListener.java + */ + +package net.openesb.component.${artifactId}.common; + +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; + +/** + * This interface defines the notification mechanism with which the message exchange object received + * from the delivery channel is processed by the interesting parties. A particular service endpoint + * implementation would first register the implementation of this interface with MessageExchangeSupport + * to get the notification of a received message exchange on a particular service endpoint and the + * implementation of the interface would process the message exchange when notified. + * + * When the com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver receives the message exchange + * object, it asks the MessageExchangeSupport to notify the MessageExchangeLister that is registered for the + * received message exchange object to process the message exchange object. + * @see com.sun.jbi.sample.component.common.MessageExchangeSupport + * @see com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @author chikkala + */ +public interface MessageExchangeListener { + /** + * MessageExchangeSupport will call this method to notify the lister implementation that a + * message exchange is received from the delivery channel. + * @param me MessageExchange Object + */ + void messageExchangeReceived(ExchangeStatus status, MessageExchange me); +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java new file mode 100644 index 000000000..607146abd --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java @@ -0,0 +1,47 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * MessageExchangeReceiver.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import javax.jbi.JBIException; + +/** + * This interface provides the methods can controls the receiving and processing of the message + * exchange objects from the delivery channel during the component lifecycle operations. + * The implementation of this interface can use multi-threaded environment to receive and process + * message exchanges from the delivery channel during the component lifecycle. + * @see com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver + * @author chikkala + */ +public interface MessageExchangeReceiver { + /** + * this method is called from the ComponentLifecyle.init method of the AbstractComponentLifecycle + * to initialize the message exchange receiving resources such as threads and thread pools + * throws JBIException on error + */ + void initReceiver() throws JBIException; + /** + * this method is called from the ComponentLifecyle.start method of the AbstractComponentLifecycle + * to start receiving the message exchanges from the delivery channel and process them. + * throws JBIException on error + */ + void startProcessing() throws JBIException; + /** + * this method is called from the ComponentLifecyle.stop method of the AbstractComponentLifecycle + * to stop receiving the message exchanges from the delivery channel. + * throws JBIException on error + */ + void stopProcessing() throws JBIException; + /** + * this method is called from the ComponentLifecyle.shutdown method of the AbstractComponentLifecycle + * to cleanup the message exchange receiving resources such as threads and thread pools. + * throws JBIException on error + */ + void shutdownReceiver() throws JBIException; + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java new file mode 100644 index 000000000..bddf9a8b1 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java @@ -0,0 +1,170 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * MessageExchangeSupport.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessageExchange.Role; +import javax.xml.namespace.QName; + +/** + * This class supports the registering and unregistering MessageExchangeListeners and the + * MessageExchangeHandlers that can be used to process the received message exchange from a + * delivery channel. A global reference to this class will be created in RuntimeContext object to + * provide access to this class from any where in the component runtime. + * + * A ProviderEndpoint or ConsumerEndpoint interested in a MessageExchange received from a delivery + * channel for a particular service endpoint will register the MessageExchangeListener with this + * class. The DefaultMessageExchangeReceiver when received a message exchange object from the delivery + * channel uses MessageExchangeSupport.processMessageExchange method to notify the registered listener. + * + * The MessageExchangeListener implementation ( ProviderEndpoint or ConsumerEndpoint ) while processing + * received message ( messageExchangeReceived()) will create and register the message exchange handlers + * to process the message exchange. + * + * @see RuntimeContext${symbol_pound}getMessageExchangeSupport + * @see RuntimeHelper${symbol_pound}getMessageExchangeSupport + * @see DefaultMessageExchangeReceiver${symbol_pound}receiveAndProcessMessageExchange + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @author chikkala + */ +public class MessageExchangeSupport { + /** listener map to notify a message exchange received event */ + private Map mListeners; + /** handlers that can process the message exchange */ + private Map mHandlers; + /** Creates a new instance of MessageExchangeSupport */ + public MessageExchangeSupport() { + this.mListeners = Collections.synchronizedMap(new HashMap()); + this.mHandlers = Collections.synchronizedMap(new HashMap()); + } + /** + * generates key that will be used to store the MessageExchangeListener objects. + * @param serviceName QName of the service + * @param endpointName endpoint name of the service. + */ + public String createListenerKey(Role role, QName interfaceName, QName serviceName, String endpointName) { + + StringBuffer strBuff = new StringBuffer(); + strBuff.append(interfaceName).append("+"); + strBuff.append(serviceName).append("+"); + strBuff.append(endpointName).append("+"); + String roleType = null; + if ( Role.CONSUMER.equals(role) ) { + roleType = "CONSUMER"; + } else if ( Role.PROVIDER.equals(role) ) { + roleType = "PROVIDER"; + } + strBuff.append(roleType); + return strBuff.toString(); + } + /** + * adds message exchange listener who are interested in receiving the notification when the + * message exchange is received from delivery channel. The listener can be registered with the + * following combination of the parameters: (role,interfaceName,serviceName, endpointName), + * (role,interfaceName,null, null), (role, null,serviceName, endpointName), (role, null,serviceName, null) + * + * @param role role of the message exchange listener PROVIDER or CONSUMER - can not be null. + * @param interfaceName QName of the interface ( protType ) - can be null if the serviceName is not null + * @param serviceName QName of the service - can be null if interfaceName is not null. + * @param endpointName endpoint name of the service. - can be null if the serviceName is not null. + * @param listener MessageExchangeListener object + */ + public synchronized void addMessageExchangeListener(Role role, QName interfaceName, QName serviceName, String endpointName, MessageExchangeListener listener) { + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + this.mListeners.put(key, listener); + } + /** + * removes any message exchange listener registered for the service endpoint specified by the serviceName and + * endpoint name. + * @param serviceName QName of the service + * @param endpointName endpoint name of the service. + */ + public synchronized void removeMessageExchangeListener(Role role, QName interfaceName, QName serviceName, String endpointName) { + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + MessageExchangeListener listener = this.mListeners.remove(key); + if ( listener == null ) { + RuntimeHelper.getLogger().fine("No message exchange listener removed with key " + key); + } + } + /** + * finds the MessageExchangeListner registers for the endpoint for which the message exchange is + * received and call the method on the listener + */ + public boolean fireMessageExchangeReceived(ExchangeStatus status, MessageExchange me) { + boolean notified = false; + Role role = me.getRole(); + QName interfaceName = me.getInterfaceName(); + QName serviceName = me.getEndpoint().getServiceName(); + String endpointName = me.getEndpoint().getEndpointName(); + // lookup with complete service description ( role + interface + service + endpoint ) + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + MessageExchangeListener listener = this.mListeners.get(key); + + if ( listener == null ) { // lookup with role+interface name + key = createListenerKey(role, interfaceName, null, null); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { // lookup with role + serviceName + endpointName + key = createListenerKey(role, null, serviceName, endpointName); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { // lookup with with role + serviceName + key = createListenerKey(role, null, serviceName, null); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { + RuntimeHelper.getLogger().fine("Could not find listener for message exchange" + me); + notified = false; + } else { + listener.messageExchangeReceived(status,me); + notified = true; + } + return notified; + } + /** + * registers the MessageExchangeHandler implementation against the message exchange id. + * @param me MessageExchange for which the handler need to be assigned + * @param handler MessageExchangeHandler implementation that will be registers. + */ + public synchronized void addMessageExchangeHandler(MessageExchange me, MessageExchangeHandler handler) { + this.mHandlers.put(me.getExchangeId(), handler); + } + /** + * removes the MessageExchangeHandler for the particular message exchange object + */ + public synchronized void removeMessageExchangeHandler(MessageExchange me) { + MessageExchangeHandler handler = this.mHandlers.remove(me.getExchangeId()); + if ( handler == null ) { + RuntimeHelper.getLogger().fine("No MessageExchangeHandler found for removing " + me.getExchangeId()); + } + } + /** + * looks up the registered message exchange handler for the message exchange object + * @param me MessageExchangeHandler. + */ + public synchronized MessageExchangeHandler findMessageExchangeHandler(MessageExchange me) { + return this.mHandlers.get(me.getExchangeId()); + } + /** + * looks up the registered message exchange handler for the message exchange object with Id + * @param exchangeId message exchange object's id + */ + public synchronized MessageExchangeHandler findMessageExchangeHandler(String exchangeId) { + return this.mHandlers.get(exchangeId); + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeContext.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeContext.java new file mode 100644 index 000000000..be75c7b7d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeContext.java @@ -0,0 +1,176 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * RuntimeContext.java + * + */ + +package net.openesb.component.${artifactId}.common; + +import java.util.logging.Logger; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; + +/** + * This class is global context for all the component runtime to store and + * retrieve the information that should be available anywhere in the component runtime. + * + * Each instance variable of this class will be initialized at various points of the + * component runtime using setter methods on this class. + * + * The two important objects that will be initialized and available from this context are + * ComponentContext and the opened DeliveryChannel objects both of which will be set from the + * implementation {@link BasicComponentLifeCycle}. + * + * Note that the ComponentContext from this global context will not be available until + * the jbi framework calls the init method of the ComponentLifeCycle of the component and + * then intern the implementation of the init method sets the context. + * + * @see BasicComponentLifeCycle${symbol_pound}initGlobalContext + * @see BasicComponentLifeCycle${symbol_pound}openDeliveryChannel + * @see BasicComponentLifeCycle${symbol_pound}closeDeliveryChannel + * @author chikkala + */ +public final class RuntimeContext { + /** RuntimeContext singleton instance */ + private static RuntimeContext sRuntimeContext; + /** default logger*/ + private Logger mDefLogger; + /** Logger object. */ + private Logger mLogger; + /** Holds value of property ComponentContext. */ + private ComponentContext mComponentContext; + /** Holds value of property DeliveryChannel. */ + private DeliveryChannel mDeliveryChannel; + /** MessageExchange processing support **/ + private MessageExchangeSupport mMESupport; + + /** outside code can not instantiate RuntimeContext */ + private RuntimeContext() { + } + /** + * @return RuntimeContext instance. + */ + public static RuntimeContext getInstance() { + if ( sRuntimeContext == null ) { + synchronized (RuntimeContext.class) { + if ( sRuntimeContext == null ) { + sRuntimeContext = new RuntimeContext(); + } + } + } + return sRuntimeContext; + } + /** + * Getter for to obtaining ComponentContext from any where in the component runtime. + * @return ComponentContext. + */ + public ComponentContext getComponentContext() { + return this.mComponentContext; + } + /** + * Sets the Component context reference in Runtime context for global access + * any class in the component runtime. + * com.sun.jbi.sample.component.common.AbstractComponentLifeCycle${symbol_pound}initContext + * method implementation should call this method to set the global context. + * see com.sun.jbi.sample.component.common.DefaultComponentLifeCycle${symbol_pound}initContext + * for details. + * @param componentContext New value of property ComponentContext. + * @see BasicComponentLifeCycle${symbol_pound}initGlobalContext + */ + public void setComponentContext(ComponentContext componentContext) { + if ( this.mComponentContext != null ) { + (new IllegalStateException("Component Context already " + + "initialized in RuntimeContext")).printStackTrace(); + } + this.mComponentContext = componentContext; + } + /** + * Getter for obtaining opened delivery channel from any where in the component runtime. + * @return DeliveryChannel. + */ + public DeliveryChannel getDeliveryChannel() { + return this.mDeliveryChannel; + } + /** + * Sets the opened delivery channel reference in Runtime context for global access + * any class in the component runtime. + * com.sun.jbi.sample.component.common.AbstractComponentLifeCycle${symbol_pound}initContext + * method implementation should call this method to set the global context. + * see com.sun.jbi.sample.component.common.DefaultComponentLifeCycle${symbol_pound}initContext + * for details. + * + * @param componentContext New value of property ComponentContext. + */ + public void setDeliveryChannel(DeliveryChannel deliveryChannel) { + if ( deliveryChannel != null && this.mDeliveryChannel != null ) { + (new IllegalStateException("Delivery Channel already " + + "initialized in RuntimeContext")).printStackTrace(); + } + this.mDeliveryChannel = deliveryChannel; + } + /** + * Sets the logger. + * + * @param name name for the Logger. + * @param resourceBundle resource bundle for the logger. can be null. + */ + public void setLogger(String name, String resourceBundle) { + + if (this.mComponentContext != null) { + // get the logger from component context if the component context is not null + try { + this.mLogger = this.mComponentContext.getLogger(name, resourceBundle); + } catch (Exception ex) { + ex.printStackTrace(); + } + } else { + this.mDefLogger = Logger.getLogger(name, resourceBundle); + } + } + /** + * Returns the logger. + * + * @return Logger + */ + public Logger getLogger() { + + // try init logger + if (this.mLogger == null && this.mComponentContext != null ) { + try { + this.mLogger = + this.mComponentContext.getLogger(this.getClass().getName(), null); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + // init default logger if required + if ( this.mLogger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (this.mLogger != null) ? this.mLogger : this.mDefLogger; + } + /** + * Returns the Component Name if the ComponentContext is set. else null + * @return component name + */ + public String getComponentName() { + String componentName = null; + if (this.mComponentContext != null) { + componentName = this.mComponentContext.getComponentName(); + } + return componentName; + } + /** + * Global MessageExchangeSupport reference. Various classes in the common + * component runtime would use this method to obtain the MessageExchangeSupport + * for processing message exchange objects received from delivery channel. + */ + public MessageExchangeSupport getMessageExchangeSupport() { + if ( this.mMESupport == null ) { + this.mMESupport = new MessageExchangeSupport(); + } + return this.mMESupport; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeHelper.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeHelper.java new file mode 100644 index 000000000..f12c2b2f4 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/RuntimeHelper.java @@ -0,0 +1,360 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * RuntimeHelper.java + */ + +package net.openesb.component.${artifactId}.common; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stream.StreamResult; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * This is a helper class that have bunch of methods for xml processing. + * @author chikkala + */ +public class RuntimeHelper { + + public static Logger getLogger() { + return RuntimeContext.getInstance().getLogger(); + } + + public static void logWarning(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.WARNING, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().warning(logObj.toString()); + } + } + + public static void logError(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.SEVERE, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().severe(logObj.toString()); + } + } + + public static void logDebug(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.FINER, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().finer(logObj.toString()); + } + } + + public static String getComponentName() { + return RuntimeContext.getInstance().getComponentName(); + } + public static ComponentContext getComponentContext() { + return RuntimeContext.getInstance().getComponentContext(); + } + public static DeliveryChannel getDeliveryChannel() { + return RuntimeContext.getInstance().getDeliveryChannel(); + } + + public static MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeContext.getInstance().getMessageExchangeSupport(); + } + + /** + * return the DOM Document + * @param xmlReader Reader + * @return dom document + * @throws Exception on parser exception or any other exception + */ + public static Document buildDOMDocument(Reader xmlReader) throws Exception { + InputSource xmlSource = new InputSource(xmlReader); + return buildDOMDocument(xmlSource); + } + /** + * return the DOM Document + * @param xmlReader Reader + * @return dom document + * @throws Exception on parser exception or any other exception + */ + public static Document buildDOMDocument(InputSource xmlSource) throws Exception { + Document xmlDoc = null; + DocumentBuilderFactory docBuilderFactory = + DocumentBuilderFactory.newInstance(); + docBuilderFactory.setValidating(false); + docBuilderFactory.setNamespaceAware(true); + DocumentBuilder docBuilder = + docBuilderFactory.newDocumentBuilder(); + docBuilder.setErrorHandler( new DefaultHandler() { + public void fatalError(SAXParseException e) + throws SAXException { + throw new SAXException(e.getMessage()); + } + }); + + docBuilder.setEntityResolver(new EntityResolver() { + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException, IOException { + StringReader reader = + new StringReader(""); // NOI18N + InputSource source = new InputSource(reader); + source.setPublicId(publicId); + source.setSystemId(systemId); + return source; + } + }); + + xmlDoc = docBuilder.parse(xmlSource); + + return xmlDoc; + } + /** + * reads xml text from DOMSource to StringBuffer + */ + public static StringBuffer readFromDOMSource(DOMSource domSource) { + + StringWriter writer = new StringWriter(); + + TransformerFactory tFactory = TransformerFactory.newInstance(); + Transformer trans = null; + try { + trans = tFactory.newTransformer(); + trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, + "yes"); + trans.setOutputProperty(OutputKeys.INDENT, "yes"); + StreamResult result = new StreamResult(writer); + trans.transform(domSource, result); + } catch (TransformerConfigurationException ex) { + ex.printStackTrace(); + } catch (TransformerException ex) { + ex.printStackTrace(); + } + + return writer.getBuffer(); + } + /** + * reads the xml text from InputSource into a StringBuffer + */ + public static StringBuffer readFromInputSource(InputSource inSource) { + + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + InputStream inStream = inSource.getByteStream(); + Reader reader = inSource.getCharacterStream(); + if ( reader == null ) { + reader = new InputStreamReader(inStream); + } + BufferedReader buff = new BufferedReader(reader); + try { + + for ( String line = null; (line = buff.readLine()) != null ; ) { + out.println(line); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + + return writer.getBuffer(); + } + /** + * reads xml from from DOM, SAX or Stream Source into a string buffer + */ + public static StringBuffer readFromSource(Source source) { + if ( source instanceof DOMSource ) { + return readFromDOMSource((DOMSource)source); + } else { + InputSource inSource = SAXSource.sourceToInputSource(source); + if ( inSource != null ) { + return readFromInputSource(inSource); + } else { + return null; + } + } + } + /** + * creates a DOMSource from the xml text read from the reader. + */ + public static DOMSource createDOMSource(Reader xmlReader) { + Document doc = null; + try { + doc = buildDOMDocument(xmlReader); + } catch (Exception ex) { + ex.printStackTrace(); + } + return new DOMSource(doc); + } + /** + * creates a DOMSource from any source. If the source itself is DOMSource, + * the source is returned as it is as DOMSource. + */ + public static DOMSource sourceToDOMSource(Source source) { + if ( source instanceof DOMSource) { + return (DOMSource) source; + } + InputSource xmlSource = SAXSource.sourceToInputSource(source); + Document doc = null; + try { + doc = buildDOMDocument(xmlSource); + } catch (Exception ex) { + ex.printStackTrace(); + } + return new DOMSource(doc); + } + /** + * converts the ex stracktrace to string. + */ + public static StringBuffer getExceptionStackTrace(Exception ex) { + StringWriter strWriter = new StringWriter(); + if ( ex != null ) { + PrintWriter out = new PrintWriter(strWriter); + ex.printStackTrace(out); + } + return strWriter.getBuffer(); + } + /** + * may be used to set the exception as fault content. + */ + public static String getExceptionAsXmlText(Exception ex) { + String message = replaceXmlEscapeCharsToEntityRefereces(ex.getMessage()); + String stackTrace = replaceXmlEscapeCharsToEntityRefereces( + getExceptionStackTrace(ex).toString()); + String exXmlText = + "" + + "" + message + "" + + "" + stackTrace + "" + + "" ; + return exXmlText; + } + + /** + * may be used to set the exception as fault content. + */ + public static String getExceptionAsText(Exception ex) { + String message = replaceXmlEscapeCharsToEntityRefereces(ex.getMessage()); + String stackTrace = replaceXmlEscapeCharsToEntityRefereces( + getExceptionStackTrace(ex).toString()); + StringBuffer buff = new StringBuffer(); + buff.append(message); + buff.append(System.getProperty("line.separator", "${symbol_escape}n")); + buff.append(stackTrace); + return buff.toString(); + } + + + /** + * For attribute values which denote a QName, i.e. include a namespace prefix, + * resolve the value into a QName. + * If a namespace can not be resolved, it is set to empty - it does not + * result in an exception + * @param attrValue the string value of the attribute + * @param element the element the attribute belongs to + */ + public static QName resolveAttrQName(String attrValue, Element element) { + int aColonLoc = attrValue.indexOf(":"); + String aLocalName = attrValue; + String aPrefix = null; + String aNS = null; + if (aColonLoc > -1) { + aPrefix = attrValue.substring(0, aColonLoc); + aLocalName = attrValue.substring(aColonLoc + 1); + + // Traverse up the hierarchy until a namespace definition is found + // or the top of the document is reached. + Node currNode = element; + while ((aNS == null || aNS.equals("")) && currNode != null) { + if (currNode.getNodeType() == Node.ELEMENT_NODE) { + aNS = ((Element) currNode).getAttribute("xmlns:" + aPrefix); + } + currNode = currNode.getParentNode(); + } + } + + QName qName = new QName(aNS, aLocalName, aPrefix); + + return qName; + } + + /** + * replaces the xml entity references with the xml escape chars + * @param xmlString Text with the xml escape chars + * @param Text with the xml entity references + */ + public static String replaceXmlEscapeCharsToEntityRefereces(String xmlString) { + if ( xmlString == null ) { + return xmlString; + } + + // just convert < , > and & only + StringBuffer sbuff = new StringBuffer(2 * xmlString.length()); + for ( int i = 0; i < xmlString.length(); ++i ) { + switch ( xmlString.charAt(i) ) { + case '&': sbuff.append("&"); + break; + case '<': sbuff.append("<"); + break; + case '>': sbuff.append(">"); + break; + default: sbuff.append( xmlString.charAt(i) ); + } + } + return sbuff.toString(); + } + + /** + * return Element node from a document node or non document. Use to extract + * the message root element. + * @root node from which the Element node will be extracted. + * @return Element node. + */ + public static Element getElement(Node root) { + Element msgEl = null; + if ( root instanceof Document) { + msgEl = ((Document)root).getDocumentElement(); + } else if (root instanceof Element) { + msgEl = (Element)root; + } else { + NodeList nodeList = root.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if ( node instanceof Element ) { + msgEl = (Element) node; + break; + } + } + } + return msgEl; + } + + public static Element getElement(DOMSource domSource) { + return getElement(domSource.getNode()); + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java new file mode 100644 index 000000000..fd0fc4f79 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java @@ -0,0 +1,312 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractServiceUnitManager.java + * + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.component.ServiceUnitManager; +import javax.jbi.management.DeploymentException; + +/** + * This is an abstract class that implements {@link javax.jbi.component.ServiceUnitManager} to provide a + * service unit deployment support for the component. The implementation supported by this service + * unit manager and related classes in this package provides WSDL1.1 based service unit deployment + * in the component. + * + * @see javax.jbi.component.ServiceUnitManager + * @see ServiceUnit + * + * @author chikkala + */ +public abstract class AbstractServiceUnitManager implements ServiceUnitManager { + + /** Map of ServiceUnit Name to the ServiceUnit Object for all the service units + * deployed in the component */ + private Map mSUMap; + + /** Creates a new instance of AbstractSUManager */ + protected AbstractServiceUnitManager() { + this.mSUMap = Collections.synchronizedMap(new HashMap()); + } + /** returns the component name + * @return component name. + */ + protected abstract String getComponentName(); + /** + * @return Logger + */ + protected abstract Logger getLogger(); + /** + * returns the creation of the ServiceUnit implementation specific to the service unit deployment + * for the component. + * @param suName service unit name + * @param suRootPath service unit root path + * @param concrete implementation of the ServiceUnit class. + */ + protected abstract ServiceUnit createServiceUnit(String suName, String suRootPath) + throws DeploymentException; + /** + * returns the service unit object deployed by the specified name. or null if not deployed. + * @param suName service unit name to look for + * @param ServiceUnit object for the suName. or null if not present. + */ + private ServiceUnit getServiceUnit(String suName) { + return this.mSUMap.get(suName); + } + /** + * lookup for the deployed service unit. If not there, throws a deployment exception. + * @param suName service unit name + * @return ServiceUnit object + * @throws DeploymentException if the service unit is not present. + */ + private ServiceUnit findServiceUnit(String suName) throws DeploymentException { + ServiceUnit serviceUnit = getServiceUnit(suName); + if ( serviceUnit == null ) { + throw new DeploymentException("Service unit " + suName + " does not exist"); + } + return serviceUnit; + } + /** + * add the service unit object to the list of deployed service units. if there is already a + * service unit present with the name, throws a deployment exception. + * @param su service unit to add + * @return ServiceUnit object that is added. + * @throws DeploymentException if the service unit already present. + */ + private ServiceUnit addServiceUnit(ServiceUnit su) throws DeploymentException { + String suName = su.getName(); + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU != null ) { + throw new DeploymentException("Service unit " + suName + "already exists"); + } + this.mSUMap.put(suName, su); + return su; + } + /** + * removes service unit object from the list of deployed service units. if there is no + * service unit present with the name, throws a deployment exception. + * @param su service unit to add + * @return ServiceUnit object that is being removed. + * @throws DeploymentException if the service unit already present. + */ + private ServiceUnit removeServiceUnit(ServiceUnit su) throws DeploymentException { + String suName = su.getName(); + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU == null ) { + throw new DeploymentException("Service unit " + suName + " does not exist"); + } + return this.mSUMap.remove(suName); + } + /** + * creates the concrete service unit implementation and calls the load method on it to initialize + * the created service unit. + * @param suName service unit name to create + * @param suRootPath service unit root path. + * @return ServiceUnit that is created and loaded. + */ + private ServiceUnit loadServiceUnit(String suName, String suRootPath) throws DeploymentException { + ServiceUnit serviceUnit = createServiceUnit(suName, suRootPath); + serviceUnit.doLoad(); + return serviceUnit; + } + /** + * deploys a service unit. it creates and loads the service unit object for the suName and then call + * doDeploy on the service unit and adds it to the deployed service unit list + * @return result as jbi management xml + * @throws DeploymentException if there is an error deploying. + */ + private synchronized String deployServiceUnit(String suName, String suRootPath) throws DeploymentException { + String result = suName; + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU != null ) { + throw new DeploymentException("Service unit " + suName + "already exists"); + } + ServiceUnit serviceUnit = loadServiceUnit(suName, suRootPath); + serviceUnit.doDeploy(); + addServiceUnit(serviceUnit); + return result; + } + /** + * Deploy a Service Unit to the component. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}deploy(String, String); + */ + public final String deploy(String suName, String suRootPath) throws DeploymentException { + this.getLogger().fine("Deploying service unit " + suName + " with suRootPath " + suRootPath); + String compName = this.getComponentName(); + boolean isSuccess = true; + String mainMsg = "Successfully deployed service unit " + suName; + Exception errEx = null; + try { + deployServiceUnit(suName, suRootPath); + } catch (Exception ex) { + isSuccess = false; + errEx = ex; + mainMsg = "Failed to deploy service unit " + suName ; + this.getLogger().log(Level.FINE, mainMsg, ex); + } + return createComponentTaskResultXML(compName, "deployTask", isSuccess, mainMsg, errEx); + } + + /** + * undeploys the service unit. it looks up the existing deployed service unit and call doUndeploy + * on it and then removes from the deployed service unit list. + */ + private synchronized String undeployServiceUnit(String suName, String suRootPath) throws DeploymentException { + String result = suName; + ServiceUnit serviceUnit = findServiceUnit(suName); + serviceUnit.doUndeploy(); + removeServiceUnit(serviceUnit); + return result; + } + /** + * Undeploy a service unit from the component. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}undeploy(String, String); + */ + public final String undeploy(String suName, String suRootPath) throws DeploymentException { + this.getLogger().fine("Undeploying service unit " + suName + " with suRootPath " + suRootPath); + String compName = this.getComponentName(); + boolean isSuccess = true; + String mainMsg = "Successfully undeployed service unit " + suName; + Exception errEx = null; + try { + undeployServiceUnit(suName, suRootPath); + } catch (Exception ex) { + isSuccess = false; + errEx = ex; + mainMsg = "Failed to undeploy service unit " + suName ; + this.getLogger().log(Level.FINE, mainMsg, errEx); + } + return createComponentTaskResultXML(compName, "undeployTask", isSuccess, mainMsg, errEx); + } + /** + * Initialize the given deployed service unit. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}init(String, String); */ + public final void init(String suName, String suRootPath) + throws DeploymentException { + this.getLogger().fine("Initializing service unit " + suName + " with suRootPath " + suRootPath); + String result = suName; + ServiceUnit serviceUnit = getServiceUnit(suName); + if ( serviceUnit == null ) { // if the service unit not exists, create and add + serviceUnit = loadServiceUnit(suName, suRootPath); // create and load service unit + addServiceUnit(serviceUnit); // add service unit to existing service units + } + serviceUnit.doInit(); // Do Service unit initialization tasks + this.getLogger().fine("Service unit initialized:" + suName); + } + /** + * Shut down the deployment. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}shutdown(String); + */ + public final void shutDown(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doShutdown(); // Do Service unit shutdown tasks + this.getLogger().fine("Service unit shut down:" + suName); + } + /** + * Start the deployed service unit. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}start(String); + */ + public final void start(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doStart(); // Do service unit start tasks. + this.getLogger().fine("Service unit started:" + suName ); + } + /** + * Stop the deployed service unit. + * @see javax.jbi.component.ServiceUnitManager${symbol_pound}stop(String); + */ + public final void stop(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doStop(); // do service unit stop tasks + this.getLogger().fine("Service unit stopped: " + suName + " stopped."); + } + + /** + * helper method to create result message as jbi management message xml. + * @param componentName name of the component for this xml. + * @param taskId task id + * @param isSuccess true to format a success result, false to format a failed result. + * @param mainMsg main result message + * @param errEx Exception, null if there is no exception in failure message. + * @return XML string. + */ + protected static String createComponentTaskResultXML( + String componentName, String taskId, boolean isSuccess, String mainMsg, Exception errEx ) { + + String exMsgXml = getComponentTaskResultExceptionXML(errEx); + String mainMsgXmlEsc = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces(mainMsg); + String taskResult = isSuccess ? "SUCCESS" : "FAILED"; + String msgType = isSuccess ? "INFO" : "ERROR"; + + String xmlResult = + "" + + " " + componentName + "" + + " " + + " " + + " " + taskId + "" + + " " + taskResult + "" + + " " + msgType + "" + + " " + + " " + + " SU_MGR_MSG_ID" + + " " + mainMsgXmlEsc + "" + + " " + + " " + + exMsgXml + + " " + + " " + + ""; + + return xmlResult; + } + /** + * converts the exception to the jbi management message xml chunk. + */ + private static String getComponentTaskResultExceptionXML(Exception errEx) { + StringBuffer exMsgBuff = new StringBuffer(); + if ( errEx == null ) { + return exMsgBuff.toString(); // empty string. + } + + List exList = new ArrayList(); + int exLevel = 0; + for ( Throwable cause = errEx ; cause != null ; cause = cause.getCause() ) { + String causeMsg = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces( + cause.getMessage()); + StringWriter stBuff = new StringWriter(); + PrintWriter stOut = new PrintWriter(stBuff); + StackTraceElement[] stList = cause.getStackTrace(); + for (StackTraceElement stEl : stList) { + stOut.println(stEl.toString()); + } + stOut.close(); + String causeStackTrace = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces( + stBuff.getBuffer().toString()); + + exMsgBuff.append(""); + exMsgBuff.append(" " + exLevel + ""); + exMsgBuff.append(" " + "SU_MGR_EXP_ID"); + exMsgBuff.append(" " + causeMsg + ""); + exMsgBuff.append(" "); + exMsgBuff.append(" " + causeStackTrace + ""); + exMsgBuff.append(""); + ++exLevel; + } + + return exMsgBuff.toString(); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java new file mode 100644 index 000000000..e9537ca9e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java @@ -0,0 +1,208 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ConsumerEndpoint.java + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import javax.jbi.JBIException; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.InOnly; +import javax.jbi.messaging.InOut; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.messaging.MessageExchangeFactory; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +/** + * This class extends from Endpoint class and implements lifecycle methods functionality required for the + * endpoint for a service consumer. {@link ServiceUnit${symbol_pound}createConsumerEndpoint} creates the object of this + * type to implement the service consumer functionality. + * + * @see ServiceUnit${symbol_pound}createConsumerEndpoint + * @author chikkala + */ + +public class ConsumerEndpoint extends Endpoint { + /** + * This constructor initializes the endpoint with CONSUMER role and makes sure that the service + * description passed to it is of consumer description. + */ + protected ConsumerEndpoint(SUDescriptor.Consumes consumes, Definition wsdlDef, ServiceUnit su) { + super(Role.CONSUMER, consumes, wsdlDef, su); + } + /** + * constructor that does not need service unit information. useful for creating the endpoint for + * static services provided by the component. + */ + protected ConsumerEndpoint(SUDescriptor.Consumes consumes, Definition wsdlDef) { + this(consumes, wsdlDef, null); + } + public final void init() throws JBIException { + getLogger().fine("ConsumerEndpoint: init called"); + doInit(); //1. initialize the endpiont resources + addMessageExchangeListener(); //2. register message exchange linster. + } + public final void activate() throws JBIException { + getLogger().fine("ConsumerEndpoint: activate called"); + //1. do common ativation tasks. + doActivate(); //2. do any other activation related tasks. + } + + public final void deactivate() throws JBIException { + getLogger().fine("ConsumerEndpoint: deactivate called"); + //1. do common deactivation tasks. + doDeactivate(); //2. do any other deactivation related tasks. + } + + public final void clean() throws JBIException { + getLogger().fine("ConsumerEndpoint: clean called"); + removeMessageExchangeListener(); //1. remove message exchange listener + doClean(); //2. clean up any other resources. + } + + protected void doInit() throws JBIException { + //NOOP + } + protected void doActivate() throws JBIException { + //NOOP + } + protected void doDeactivate() throws JBIException { + //NOOP + } + protected void doClean() throws JBIException { + //NOOP + } + + /** + * helper method to find the active ServiceEndpiont for the service described with the + * serviceDescriptor. This method looks for the Active ServiceEndpoint using interface or + * service name or service name and the endpoint name. + */ + public ServiceEndpoint findServiceEndpoint() { + + QName serviceType = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + + ServiceEndpoint [] refs = null; + ServiceEndpoint serviceEndpoint = null; + ComponentContext compContext = this.getComponentContext(); + + if ( compContext == null ) { + this.getLogger().info("Null Component context. Can not find ServiceEndpoint"); + return null; + } + // lookup ServiceEndpiont with concrete service(serice qname + endpoint name). + if ( serviceName != null && endpointName != null ) { + this.getLogger().info("Looking for ServiceEndpoint with:" + + " ServiceName: " + serviceName + " EndpointName: " + endpointName); + serviceEndpoint = compContext.getEndpoint(serviceName, endpointName); + } + // else lookup ServiceEndpiont with Service Name + if ( serviceEndpoint == null && serviceName != null && endpointName == null) { + this.getLogger().info("Looking for ServiceEndpoint with Service name: " + serviceName); + refs = compContext.getEndpointsForService(serviceName); + if ( refs != null && refs.length > 0 ) { + serviceEndpoint = refs[0]; + } + } + // else lookup ServiceEndpont with serviceType + if ( serviceEndpoint == null && serviceType != null && + serviceName == null && endpointName == null) { + this.getLogger().info("Looking for ServiceEndpoint with Service type: " + serviceType); + refs = compContext.getEndpoints(serviceType); + if ( refs != null && refs.length > 0 ) { + serviceEndpoint = refs[0]; + } + } + + return serviceEndpoint; + } + + /** + * this method creates a InOutMessageExchange Object and sets the required + * data on the MessageExchange object including the create and set the Normalized + * message object to hold the input message on the MessageExchange object. + */ + public InOut createInOutMessageExchange(QName operation) + throws MessagingException, JBIException { + + ServiceEndpoint serviceEndpoint = null; + // find a ServiceEndpoint activated by the Service Providers for this service + serviceEndpoint = findServiceEndpoint(); + + if ( serviceEndpoint == null ) { + // if not found a activated ServiceEndpoint for this service, throw exception. + throw new JBIException("Can not find an Active ServiceEndpoint for ${symbol_escape}n" + this.getService()); + } else { + this.setServiceEndpoint(serviceEndpoint); + } + + InOut inOutME = null; + DeliveryChannel channel = this.getDeliveryChannel(); + // create message exchange factory for the endpiont + MessageExchangeFactory factory = channel.createExchangeFactory(serviceEndpoint); + // create INOUT Message Exchange + inOutME = factory.createInOutExchange(); + // set operation + inOutME.setOperation(operation); + // set interface if that is not set + if ( inOutME.getInterfaceName() == null ) { + inOutME.setInterfaceName(this.getService().getInterface()); + } + // create IN Nomralized Message + NormalizedMessage inMsg = inOutME.createMessage(); + // set IN Normalized message on message exchange + inOutME.setInMessage(inMsg); + + return inOutME; + } + + /** + * this method creates a InOnlyMessageExchange Object and sets the required + * data on the MessageExchange object including the create and set the Normalized + * message object to hold the input message on the MessageExchange object. + */ + public InOnly createInOnlyMessageExchange(QName operation) + throws MessagingException, JBIException { + + ServiceEndpoint serviceEndpoint = null; + // find a ServiceEndpoint activated by the Service Providers for this service + serviceEndpoint = findServiceEndpoint(); + + if ( serviceEndpoint == null ) { + // if not found a activated ServiceEndpoint for this service, throw exception. + throw new JBIException("Can not find an Active ServiceEndpoint for ${symbol_escape}n" + this.getService()); + } else { + this.setServiceEndpoint(serviceEndpoint); + } + + InOnly inOnlyME = null; + DeliveryChannel channel = this.getDeliveryChannel(); + // create message exchange factory for the endpiont + MessageExchangeFactory factory = channel.createExchangeFactory(serviceEndpoint); + // create INOUT Message Exchange + inOnlyME = factory.createInOnlyExchange(); + // set operation + inOnlyME.setOperation(operation); + // set interface if that is not set + if ( inOnlyME.getInterfaceName() == null ) { + inOnlyME.setInterfaceName(this.getService().getInterface()); + } + // create IN Nomralized Message + NormalizedMessage inMsg = inOnlyME.createMessage(); + // set IN Normalized message on message exchange + inOnlyME.setInMessage(inMsg); + + return inOnlyME; + } + + +} \ No newline at end of file diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/Endpoint.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/Endpoint.java new file mode 100644 index 000000000..3aac0f8e2 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/Endpoint.java @@ -0,0 +1,289 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * Endpoint.java + * + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.MessageExchangeHandler; +import net.openesb.component.${artifactId}.common.MessageExchangeListener; +import net.openesb.component.${artifactId}.common.MessageExchangeSupport; +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.xml.namespace.QName; + +/** + * This is an abstract class that represents the Endpoint defined for service provisioning or + * consumption in a jbi component. It stores the required service description ( wsdl definition, + * role, service unit to which it belongs etc) and defines the lifecycle operations {@link ${symbol_pound}init}, + * {@link ${symbol_pound}activate}, {@link ${symbol_pound}deactivate}, {@link ${symbol_pound}clean} to control a service endpoint that + * provides or consumes the service. + *

+ * Extended classes implement the abstract methods defined in this class to implement the endpoint + * functionality by providing the functionality to process the deployment artifacts specific to this + * endpoint, configure the endpoint to send/receive messages to/from delivery channel and process them + * according to the specific service implementation. + * + * @author chikkala + */ +public abstract class Endpoint { + /** Role of this endpoint. CONSUMER or PROVIDER */ + private Role mRole; + /** Service description from the SU descriptor for which this endpoint is configured */ + private SUDescriptor.Service mService; + /** WSDL definition corresponding to this endpoint */ + private Definition mWsdlDef; + /** service endpoint corresponding to this endpoint */ + private ServiceEndpoint mServiceEndpoint; + /** service unit from which this endpoint is created */ + private ServiceUnit mSU; // can be null + /** private constructor to force extended classes to use the parameterized constructor */ + private Endpoint() { + } + /** Creates a new instance of Endpoint + * @param role CONSUMER or PRVODER role. + * @param service service description from the su descriptor + * @param wsdl wsdl definition corresponding to this endpoint + * @param su service unit object which created this endpoint. + */ + protected Endpoint(Role role, SUDescriptor.Service service, Definition wsdl, ServiceUnit su) { + this.mService = service; + this.mRole = role; + this.mWsdlDef = wsdl; + this.mSU = su; + } + /** Creates a new instance of Endpoint without service unit. may be useful for static endpoints that + * are not part of the deployment + * @param role CONSUMER or PRVODER role. + * @param service service info from the su descriptor + * @param wsdl wsdl definition corresponding to this endpoint + */ + protected Endpoint(Role role, SUDescriptor.Service service, Definition wsdl) { + this(role, service, wsdl, null); + } + /** + * should be called to initialize any resources related to this endpoint object + * throws JBIException + */ + public abstract void init() throws JBIException; + /** + * activates the endpoint to send/receive messages + * throws JBIException + */ + public abstract void activate() throws JBIException; + /** + * deactivates the endpoint + * throws JBIException + */ + public abstract void deactivate() throws JBIException; + /** + * clean endpoint + * throws JBIException + */ + public abstract void clean() throws JBIException; + + public final Role getRole() { + return this.mRole; + } + public final boolean isProvider() { + return (Role.PROVIDER.equals(this.getRole())); + } + public final boolean isConsumer() { + return (Role.CONSUMER.equals(this.getRole())); + } + public final Definition getWSDL() { + return this.mWsdlDef; + } + public final SUDescriptor.Service getService() { + return this.mService; + } + public final ServiceEndpoint getServiceEndpoint() { + return this.mServiceEndpoint; + } + protected final void setServiceEndpoint(ServiceEndpoint svcEP) { + this.mServiceEndpoint = svcEP; + } + public final ServiceUnit getServiceUnit() { + return this.mSU; + } + /** + * generates an ID that would uniquely identify this endpoint implementation. Use as a key to map + * any information to store that is related to this endpoint. + */ + public final String getID() { + StringBuffer strBuff = new StringBuffer(); + strBuff.append(this.mService.getInterface()).append("+"); + strBuff.append(this.mService.getServiceName()).append("+"); + strBuff.append(this.mService.getEndpointName()).append("+"); + String roleType = null; + if ( Role.CONSUMER.equals(this.mRole) ) { + roleType = "CONSUMER"; + } else if ( Role.PROVIDER.equals(this.mRole) ) { + roleType = "PROVIDER"; + } + strBuff.append(roleType); + return strBuff.toString(); + } + + @Override + public String toString() { + return "Endpoint : " + "${symbol_escape}n" + this.mService; + } + /** + * checks if this endpoint is configured for the binding component or service engine. + */ + public boolean isFor${artifactId}() { + boolean isFor${artifactId} = false; + if ( this.mSU != null ) { + try { + isFor${artifactId} = this.mSU.getSUDescriptor().isFor${artifactId}(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + return isFor${artifactId}; + } + + public QName getOperationQName(String opName) { + return new QName(this.getService().getInterface().getNamespaceURI(), opName); + } + + public Operation getWSDLOperation(QName opQName) { + String opName = null; + if ( opQName != null ) { + opName = opQName.getLocalPart(); + } + Operation operation = WSDLProcessor.findOperation(this.getWSDL(), + this.getService().getInterface(), opName); + return operation; + } + + public Binding getWSDLBinding() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + if ( serviceName != null ) { + return WSDLProcessor.findServiceBinding(this.getWSDL(), serviceName, endpointName); + } else { + return WSDLProcessor.findInterfaceBinding(this.getWSDL(), interfaceName, null); + } + } + /** @return logger */ + public Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** @return ComponentContext */ + public ComponentContext getComponentContext() { + return RuntimeHelper.getComponentContext(); + } + /** @return DeliveryChannel */ + public DeliveryChannel getDeliveryChannel() { + return RuntimeHelper.getDeliveryChannel(); + } + /** + * helper function to get the MessageExchangeSupport object + */ + public MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeHelper.getMessageExchangeSupport(); + } + + public MessageExchangeHandler createMessageExchangeHandler() { + return null; + } + /** + * creates the message exchange listener. Extended classes should return + * MessageExchangeListener implementation. + * @return MessageExchangeListener or null. + * + */ + protected MessageExchangeListener createMessageExchangeListener() { + return null; + } + /** + * Creates and adds message exchange listener to receive message exchange received notification. + */ + protected void addMessageExchangeListener() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + MessageExchangeListener meListener = createMessageExchangeListener(); + MessageExchangeSupport meListenerSupport = getMessageExchangeSupport(); + if ( meListenerSupport != null && meListener != null ) { + meListenerSupport.addMessageExchangeListener( + this.getRole(), interfaceName, serviceName, endpointName, meListener); + if ( serviceName != null ) { + meListenerSupport.addMessageExchangeListener( + this.getRole(), null, serviceName, endpointName, meListener); + } + } + } + /** + * Removes message exchange listener from the MessageExchangeSupport. + */ + protected void removeMessageExchangeListener() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + MessageExchangeSupport meListenerSupport = getMessageExchangeSupport(); + if ( meListenerSupport != null ) { + meListenerSupport.removeMessageExchangeListener( + this.getRole(), interfaceName, serviceName, endpointName); + if ( serviceName != null ) { + meListenerSupport.removeMessageExchangeListener( + this.getRole(), null, serviceName, endpointName); + } + } + } + + public final boolean processMessageExchangeWithHandler(ExchangeStatus status, MessageExchange me) { + + //1. lookup handler + //2. if not there create one and register + //3. call process message exchange on it + //4. check status. if that is the end, remove the handler + + MessageExchangeSupport support = this.getMessageExchangeSupport(); + if ( support == null ) { + getLogger().fine("No MessageExchangeSupport present"); + return false; + } + MessageExchangeHandler handler = support.findMessageExchangeHandler(me); + if ( handler == null ) { + handler = this.createMessageExchangeHandler(); + if ( handler == null ) { + getLogger().fine("MessageExchangeHandler not supported"); + return false; + } + support.addMessageExchangeHandler(me, handler); + } + + handler.processMessageExchange(status, me); + + getLogger().fine("XXX MX Handler processed ME with STATUS: " + status); + + if (!ExchangeStatus.ACTIVE.equals(status) ) { + // DONE or ERROR means done with the me. + getLogger().fine("End of ME processing. STATUS: " + status + + ". Removing the MX Handler ..."); + support.removeMessageExchangeHandler(me); + } + + return true; + } + +} + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java new file mode 100644 index 000000000..4bd932fc1 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java @@ -0,0 +1,107 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ProviderEndpoint.java + * + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Service; +import javax.jbi.JBIException; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Definition; + +/** + * This class extends from Endpoint class and implements lifecycle methods functionality required for the + * endpoint for a service provider. {@link ServiceUnit${symbol_pound}createProviderEndpoint} creates the object of this + * type to implement the service provider functionality. It makes sure that this class or the extended + * classes will activate or deactivate the ServiceEndpoint corresponding to the service + * provided by the endpoint is performed during the activate and deactivate method calls as part of the + * endpoint lifecycle. + * + * @see ServiceUnit${symbol_pound}createProviderEndpoint + * @author chikkala + */ + +public class ProviderEndpoint extends Endpoint { + /** + * This constructor initializes the endpoint with PROVIDER role and makes sure that the service + * description passed to it is of provider description. + */ + protected ProviderEndpoint(SUDescriptor.Provides provides, Definition wsdlDef, ServiceUnit su) { + super(Role.PROVIDER, provides, wsdlDef, su); + } + /** + * constructor that does not need service unit information. useful for creating the endpoint for + * static services provided by the component. + */ + protected ProviderEndpoint(SUDescriptor.Provides provides, Definition wsdlDef) { + this(provides, wsdlDef, null); + } + /** + * initializes the endpoint and creates and registers the MessageExchangeListener with + * MessageExchangeSupport. + */ + public final void init() throws JBIException { + getLogger().fine("ProviderEndpiont: init called"); + doInit(); //1. initialize the endpiont resources + addMessageExchangeListener(); //2. register message exchange linster. + } + /** + * calls activatesServiceEndpoint for the Provider. + */ + public final void activate() throws JBIException { + getLogger().fine("ProviderEndpiont: activate called"); + activateServiceEndpoint(); //1. activate service endpoint in NMR + doActivate(); //2. do any other activation related tasks. + } + /** + * calls deactivateServiceEndpoint for the Provider. + */ + public final void deactivate() throws JBIException { + getLogger().fine("ProviderEndpiont: deactivate called"); + deactivateServiceEndpoint(); //1. deactivates the service endpoint in NMR + doDeactivate(); //2. do any other deactivation related tasks. + } + /** + * removes the message exchange listener. cleans up other resources + */ + public final void clean() throws JBIException { + getLogger().fine("ProviderEndpiont: clean called"); + removeMessageExchangeListener(); //1. remove message exchange listener + doClean(); //2. clean up any other resources. + } + /** + * Activates the ServiceEndpoint with NMR + */ + private void activateServiceEndpoint() throws JBIException { + Service service = this.getService(); + ServiceEndpoint svcEP = this.getComponentContext().activateEndpoint( + service.getServiceName(), service.getEndpointName()); + this.setServiceEndpoint(svcEP); + } + /** + * Deactivates ServiceEndpoint in NMR + */ + private void deactivateServiceEndpoint() throws JBIException { + this.getComponentContext().deactivateEndpoint(this.getServiceEndpoint()); + this.setServiceEndpoint(null); + } + + protected void doInit() throws JBIException { + //NOOP + } + protected void doActivate() throws JBIException { + //NOOP + } + protected void doDeactivate() throws JBIException { + //NOOP + } + protected void doClean() throws JBIException { + //NOOP + } + +} \ No newline at end of file diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java new file mode 100644 index 000000000..3710afa62 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java @@ -0,0 +1,364 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * SUDescriptor.java + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import javax.jbi.management.DeploymentException; +import javax.xml.namespace.QName; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * This interface represent the service unit descriptor (jbi.xml) model. This will be used in + * ServiceUnit implementation to find the services provided and consumed by this service unit. + * {@link SUDescriptorFactory${symbol_pound}getSUDescriptor} method reads the jbi.xml in the service unit to + * to the implementation of this interface. + * + * @see SUDescriptorFactory + * @see Consumes + * @see Provides + * @see ServiceUnit + * + * @author chikkala + */ +public interface SUDescriptor { + + Collection getProvidedServices(); + + Collection getConsumedServices(); + + boolean isFor${artifactId}(); + + /** + * base interface that models the service information described in the service unit descriptor for + * consumed services and provided services. + */ + public interface Service { + /** + * Getter for property interfaceQName. + * @return Value of property interfaceQName. + */ + QName getInterface(); + /** + * Getter for property serviceName. + * @return Value of property serviceName. + */ + QName getServiceName(); + /** + * Getter for property endpointName. + * @return Value of property endpointName. + */ + String getEndpointName(); + } + /** + * marker interface that represents the provided services in the service unit + */ + public interface Provides extends Service { + } + /** + * this interface represents the consumed service information in the su descriptor. + */ + public interface Consumes extends Service { + + public final static String STANDARD_LINK = "standard"; + public final static String SOFT_LINK = "soft"; + public final static String HARD_LINK = "hard"; + /** + * Getter for property linkType. + * @return Value of property linkType. + */ + String getLinkType(); + } + /** + * This is a factory class that can build the Service Unit Descriptor model from the jbi.xml + */ + public static class SUDescriptorFactory { + + protected final static String JBI_TAG_NAME = "services"; + protected final static String SERVICES_TAG_NAME = "services"; + protected final static String BC_TAG_NAME = "binding-component"; + protected final static String PROVIDES_TAG_NAME = "provides"; + protected final static String CONSUMES_TAG_NAME = "consumes"; + protected final static String INTERFACE_TAG_NAME = "interface-name"; + protected final static String SERVICE_TAG_NAME = "service-name"; + protected final static String ENDPOINT_TAG_NAME = "endpoint-name"; + protected final static String LINK_TYPE_TAG_NAME = "link-type"; + /** + * method that builds the Service unit descriptor model from the jbi.xml + */ + public static SUDescriptor getSUDescriptor(String jbiXmlPath) throws Exception { + FileReader reader = null; + try { + reader = new FileReader(jbiXmlPath); + SUDescriptor suDesc = getSUDescriptor(reader); + return suDesc; + } finally { + if ( reader != null ) { + try { + reader.close(); + } catch (IOException ex) { + // ignore + } + } + } + } + /** + * method that builds the Service unit descriptor model from the jbi.xml + */ + public static SUDescriptor getSUDescriptor(Reader reader) throws Exception { + SUDescriptor suDescriptor = null; + Document suDescDoc = RuntimeHelper.buildDOMDocument(reader); + Element jbiEl = suDescDoc.getDocumentElement(); + if (JBI_TAG_NAME.equals(jbiEl.getTagName())) { + throw new DeploymentException("Invalid service unit descriptor : no jbi root element"); + } + + NodeList servicesNL = jbiEl.getElementsByTagName(SERVICES_TAG_NAME); + if (servicesNL != null && servicesNL.getLength() == 1) { + Element servicesEl = (Element) servicesNL.item(0); + suDescriptor = SUDescriptorImpl.createSUDescriptor(servicesEl); + } else { + throw new DeploymentException("Invalid service unit descriptor : invalid services element"); + } + + return suDescriptor; + } + + } + /** + * This class implements SUDescriptor + */ + public static class SUDescriptorImpl implements SUDescriptor { + + private List mConsumedList; + private List mProvidedList; + private boolean mIsFor${artifactId}; + + protected SUDescriptorImpl(boolean isFor${artifactId}) { + this.mIsFor${artifactId} = isFor${artifactId}; + this.mConsumedList = new ArrayList(); + this.mProvidedList = new ArrayList(); + } + + protected void addProvidedService(Provides provides) { + this.mProvidedList.add(provides); + } + + protected void addConsumedService(Consumes consumes) { + this.mConsumedList.add(consumes); + } + + public Collection getProvidedServices() { + // return unmodifiable collection + return Collections.unmodifiableCollection(this.mProvidedList); + } + + public Collection getConsumedServices() { + // return unmodifiable collection + return Collections.unmodifiableCollection(this.mConsumedList); + } + + public boolean isFor${artifactId}() { + return this.mIsFor${artifactId}; + } + + protected static SUDescriptor createSUDescriptor(Element servicesEl) throws Exception { + boolean isForBC = false; + String bcTagString = servicesEl.getAttribute(SUDescriptorFactory.BC_TAG_NAME); + isForBC = Boolean.valueOf(bcTagString).booleanValue(); + SUDescriptorImpl suDesc = new SUDescriptorImpl(isForBC); + // add consumes + NodeList consumesNL = servicesEl.getElementsByTagName(SUDescriptorFactory.CONSUMES_TAG_NAME); + for ( int i=0; i < consumesNL.getLength(); ++i) { + Element consumesEl = (Element) consumesNL.item(i); + Consumes consumes = ConsumedService.createConsumedService(consumesEl); + suDesc.addConsumedService(consumes); + } + // add provides + NodeList providesNL = servicesEl.getElementsByTagName(SUDescriptorFactory.PROVIDES_TAG_NAME); + for ( int i=0; i < providesNL.getLength(); ++i) { + Element providesEl = (Element) providesNL.item(i); + Provides provides = ProvidedService.createProvidedService(providesEl); + suDesc.addProvidedService(provides); + } + + return suDesc; + } + } + /** + * Base class that implements the Service interface + */ + public static abstract class AbstractService implements Service { + + private QName mInterface; + private QName mServiceName; + private String mEndpointName; + + private AbstractService() { + } + /** + * Getter for property interfaceQName. + * @return Value of property interfaceQName. + */ + public QName getInterface() { + return this.mInterface; + } + + /** + * Setter for property interfaceQName. + * @param interfaceQName New value of property interfaceQName. + */ + protected void setInterface(QName interfaceQName) { + this.mInterface = interfaceQName; + } + + /** + * Getter for property serviceName. + * @return Value of property serviceName. + */ + public QName getServiceName() { + return this.mServiceName; + } + + /** + * Setter for property serviceName. + * @param serviceName New value of property serviceName. + */ + protected void setServiceName(QName serviceName) { + this.mServiceName = serviceName; + } + + /** + * Getter for property endpointName. + * @return Value of property endpointName. + */ + public String getEndpointName() { + return this.mEndpointName; + } + + /** + * Setter for property endpointName. + * @param endpointName New value of property endpointName. + */ + protected void setEndpointName(String endpointName) { + this.mEndpointName = endpointName; + } + + } + /** + * This class implements the Provides interface + */ + public static class ProvidedService + extends AbstractService + implements Provides { + protected ProvidedService(QName interfaceQName, QName serviceName, String endpointName) { + this.setInterface(interfaceQName); + this.setServiceName(serviceName); + this.setEndpointName(endpointName); + } + + @Override + public String toString() { + return "Provides :" + + "${symbol_escape}n${symbol_escape}t interface-name= " + getInterface() + + "${symbol_escape}n${symbol_escape}t service-name= " + getServiceName() + + "${symbol_escape}n${symbol_escape}t endpont-name= " + getEndpointName(); + } + + protected static Provides createProvidedService(Element providesEl) throws Exception { + + String ifName = providesEl.getAttribute(SUDescriptorFactory.INTERFACE_TAG_NAME); + String serviceName = providesEl.getAttribute(SUDescriptorFactory.SERVICE_TAG_NAME); + String endpointName = providesEl.getAttribute(SUDescriptorFactory.ENDPOINT_TAG_NAME); + if ( ifName == null || serviceName == null || endpointName == null ) { + throw new Exception("Invalid provides element: missing " + SUDescriptorFactory.INTERFACE_TAG_NAME + + " or " + SUDescriptorFactory.SERVICE_TAG_NAME + " or " + SUDescriptorFactory.ENDPOINT_TAG_NAME ); + } + QName ifQName = RuntimeHelper.resolveAttrQName(ifName, providesEl); + QName serviceQName = RuntimeHelper.resolveAttrQName(serviceName, providesEl); + + return new ProvidedService(ifQName, serviceQName, endpointName); + } + } + /** + * This class implements the Consumes interface. + */ + public static class ConsumedService + extends AbstractService + implements Consumes { + private String mLinkType; + protected ConsumedService(QName interfaceQName, + QName serviceName, String endpointName, String linkType) { + this.setInterface(interfaceQName); + this.setServiceName(serviceName); + this.setEndpointName(endpointName); + this.mLinkType = linkType; + } + + /** + * Getter for property linkType. + * @return Value of property linkType. + */ + public String getLinkType() { + return this.mLinkType; + } + + @Override + public String toString() { + return "Cosumes :" + + "${symbol_escape}n${symbol_escape}t interface-name= " + getInterface() + + "${symbol_escape}n${symbol_escape}t service-name= " + getServiceName() + + "${symbol_escape}n${symbol_escape}t endpont-name= " + getEndpointName() + + "${symbol_escape}n${symbol_escape}t link-type= " + getLinkType(); + } + + protected static Consumes createConsumedService(Element consumesEl) throws Exception { + + String ifName = consumesEl.getAttribute(SUDescriptorFactory.INTERFACE_TAG_NAME); + String serviceName = consumesEl.getAttribute(SUDescriptorFactory.SERVICE_TAG_NAME); + String endpointName = consumesEl.getAttribute(SUDescriptorFactory.ENDPOINT_TAG_NAME); + String linkType = consumesEl.getAttribute(SUDescriptorFactory.LINK_TYPE_TAG_NAME); + if ( linkType == null || linkType.trim().length() == 0 ) { + linkType = STANDARD_LINK; + } + + if ( ifName == null ) { + throw new Exception("Invalid consumes element: missing " + + SUDescriptorFactory.INTERFACE_TAG_NAME ); + } + if ( serviceName == null || endpointName == null ) { + throw new Exception("Invalid consumes element: missing " + + SUDescriptorFactory.SERVICE_TAG_NAME + " or " + + SUDescriptorFactory.ENDPOINT_TAG_NAME ); + } + + QName ifQName = RuntimeHelper.resolveAttrQName(ifName, consumesEl); + QName serviceQName = null; + if ( serviceName != null ) { + serviceQName = RuntimeHelper.resolveAttrQName(serviceName, consumesEl); + } + if ( serviceQName != null && endpointName != null && linkType != null ) { + if (!(STANDARD_LINK.equals(linkType) || + SOFT_LINK.equals(linkType) || HARD_LINK.equals(linkType)) ) { + throw new Exception("Invalid consumes attribute value" + + SUDescriptorFactory.LINK_TYPE_TAG_NAME + "=" + linkType); + } + } + return new ConsumedService(ifQName, serviceQName, endpointName, linkType); + } + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java new file mode 100644 index 000000000..1794d9333 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java @@ -0,0 +1,464 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ServiceUnit.java + * + */ + +package net.openesb.component.${artifactId}.common.deployment; + +import net.openesb.component.${artifactId}.common.RuntimeHelper; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Consumes; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Provides; +import net.openesb.component.${artifactId}.common.deployment.SUDescriptor.Service; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.management.DeploymentException; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; + +/** + * This is an abstract class that implements the service unit functionality in the component which + * processes the service unit artifacts and implement the actual service unit lifecycle functionality. + * The AbstractServiceUnitManager and its extended classes that implement the ServiceUnitManager + * functionality creates and maintains the reference to the concrete implementation of this class to + * invoke the functionality implemented by this class and its concrete implementation during the + * execution of the ServiceUnitMangers lifecycle methods by the jbi runtime. + *

+ * The main lifecycle methods of this class that will be called by the ServiceUnitManger implementation + * during the service unit deployment lifecycle are {@link ${symbol_pound}doload}, {@link ${symbol_pound}doDeploy}, {@link ${symbol_pound}doUndeploy}, + * {@link ${symbol_pound}doInit}, {@link ${symbol_pound}doStart}, {@link ${symbol_pound}doStop} and {@link ${symbol_pound}doShutdown} + *

+ * Service unit processing supported by this implementation is based on wsdl 1.1 deployments where the + * services provided and consumed in this service unit are described using wsdl 1.1 definitions. + *

+ * The main service unit artifacts that will be processed during deployment lifecycle of the service + * unit are 1.Service unit descriptor(jbi.xml) that describes the services provided and consumed by + * this service unit. 2.WSDL 1.1 document that describes the service definition 3.Component specific + * configurations related to services provided and consumed by this service unit. + *

+ * When the service unit is for Binding Component, the component specific configurations are read + * from the WSDL1.1 extensions defined in the WSDL document corresponding to the service provider + * or consumer deployed with this service unit. + *

+ * When the service unit is for Service Engine, the component specific configurations are read + * from the deployment artifacts such as xslt files and mapping files in the service unit zip file + * along with the WSDL document corresponding to the service provider or consumer deployed with this + * service unit. + * + * @see SUDescriptor + * @see Endpoint + * @see ProviderEndpoint + * @see ConsumerEndpoint + * @see WSDLProcessor + * @author chikkala + */ +public abstract class ServiceUnit { + /** Service Unit Name */ + private String mSUName; + /** Service Unit Root path passed by jbi runtime */ + private String mSURootPath; + /** service unit descriptor model unmarshalled from service unit jbi.xml */ + private SUDescriptor mSUDescriptor; + /** Map of Endpoint Key to ProviderEndpoint configurations in this service unit */ + private Map mProviderEndpointMap; + /** Map of Endpoint Key to ConsumerEndpoint configurations in this service unit */ + private Map mConsumerEndpointMap; + /** Map of Service Key to the WSDL Definition in this service unit */ + private Map mWSDLMap; + /** WSDLProcessor configured for this service unit to process wsdls in the service unit */ + private WSDLProcessor mWSDLProcessor; + /** + * + * @param suName + * @param suRootPath + */ + protected ServiceUnit(String suName, String suRootPath) { + this.mSUName = suName; + this.mSURootPath = suRootPath; + this.mSUDescriptor = null; + this.mWSDLMap = new HashMap(); + this.mProviderEndpointMap = new HashMap(); + this.mConsumerEndpointMap = new HashMap(); + } + /** returns service unit name + * @return service unit name + */ + public String getName() { + return this.mSUName; + } + /** returns service unit root path where the su artifacts are unzipped by the jbi runtime + * @return path to the service unit root directory. + */ + public String getSURootPath() { + return this.mSURootPath; + } + protected SUDescriptor createSUDescriptor() throws Exception { + File jbiXmlFile = new File(this.getSURootPath(), "META-INF/jbi.xml"); + String jbiXmlPath = jbiXmlFile.getAbsolutePath(); + return SUDescriptor.SUDescriptorFactory.getSUDescriptor(jbiXmlPath); + } + /** return the Service unit descriptor model that was read from the jbi.xml + * @return SUDescriptor + */ + public SUDescriptor getSUDescriptor() throws Exception { + if ( this.mSUDescriptor == null ) { + this.mSUDescriptor = createSUDescriptor(); + } + return this.mSUDescriptor; + } + public ProviderEndpoint getProviderEndpoint(String providerID) { + return this.mProviderEndpointMap.get(providerID); + } + public Collection getProviderEndpoints() { + return Collections.unmodifiableCollection(this.mProviderEndpointMap.values()); + } + public ConsumerEndpoint getConsumerEndpoint(String cosumerID) { + return this.mConsumerEndpointMap.get(cosumerID); + } + + public Collection getConsumerEndpoints() { + return Collections.unmodifiableCollection(this.mConsumerEndpointMap.values()); + } + /** + * @return Logger + */ + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** + * extended classes implement this method to create the su specific WSDLProcessor. for examples, + * a su supporting binding component may have wsdl extensions that it want to registry for reading + * the configurations from the wsdl file. + * @return WSDLProcessor + * @see com.sun.jbi.sample.component.common.wsdl.WSDLProcessor + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + */ + protected WSDLProcessor createWSDLProcessor() { + return new WSDLProcessor(this.getSURootPath()); + } + /** + * return the WSDLProcessor reference by creates if it is not yet created. + * @return WSDLProcessor. + */ + public final WSDLProcessor getWSDLProcessor() { + if ( this.mWSDLProcessor == null ) { + this.mWSDLProcessor = createWSDLProcessor(); + } + return this.mWSDLProcessor; + } + /** + * loads the service unit artifacts into the SU model. AbstractServiceUnitManager implementation + * calls this method during the during deploy and init lifecycle methods when the service unit + * object is newly created. + */ + public void doLoad() throws DeploymentException { + try { + SUDescriptor suDesc = getSUDescriptor(); // load jbi.xml + loadServiceDefinitions(); // check if the wsdls are valid for corresponding services. + loadOtherArtifacts(); // additional validations specific to component deployment features. + loadEndpoints(); // create endpoints + } catch ( DeploymentException jbiEx) { + throw jbiEx; + } catch (Exception ex) { + throw new DeploymentException(ex); + } + } + /** extended classes implement this method to perform the su specific deployment related tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doDeploy() throws DeploymentException { + // NOOP. doLoad has done it all. + this.getLogger().fine("ServiceUnit.doDeploy"); + } + /** extended classes implement this method to perform the su specific undeployment related tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doUndeploy() throws DeploymentException { + //NOOP + this.getLogger().fine("ServiceUnit.doUndeploy"); + } + /** extended classes implement this method to perform the su specific initialization tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doInit() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doInit"); + this.doInitEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on start in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doStart() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doStart"); + this.doActivateEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on stop in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doStop() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doStop"); + this.doDeactivateEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on shutdown in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doShutdown() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doShutdown"); + this.doCleanEndpoints(); + } + /** + * create the ProviderEndpoint that implement the service provider implementation specific to this su. + * @return ProviderEndpoint or null if the SU does not support the service provider access + */ + protected ProviderEndpoint createProviderEndpoint(Provides provides, Definition wsdlDef) { + return null; + } + /** + * create the ProviderEndpoint that implement the service consumer implementation specific to this su. + * @return ConsumerEndpoint or null if the SU does not support the service consumer access + */ + protected ConsumerEndpoint createConsumerEndpoint(Consumes consumes, Definition wsdlDef) { + return null; + } + /** + * generates the key based on the service to store the wsdl definitions . + */ + protected String getServiceKey(Service service) { + StringBuffer strBuff = new StringBuffer(); + strBuff.append(service.getInterface()).append("+"); + strBuff.append(service.getServiceName()).append("+"); + strBuff.append(service.getEndpointName()); + return strBuff.toString(); + } + /** + * looks up the wsdl definition loaded for this service. + */ + protected Definition findWSDLFor(Service service) throws WSDLException { + Definition wsdlDef = null; + String key = this.getServiceKey(service); + wsdlDef = this.mWSDLMap.get(key); + return wsdlDef; + } + + protected Definition findWSDL(List wsdlList, Service service, boolean ignoreEndpointLookup) { + Definition foundDef = null; + for ( Definition def : wsdlList ) { + if ( WSDLProcessor.isWSDLFor(def, service.getInterface(), service.getServiceName(), + ((ignoreEndpointLookup) ? null : service.getEndpointName()) ) ) { + foundDef = def; + break; + } + } + return foundDef; + } + /** + * loads the WSDL definitions corresponds to the service providers and consumers defined in the + * service unit descriptor. + */ + protected void loadServiceDefinitions() throws Exception { + + this.mWSDLMap = new HashMap(); + + WSDLProcessor wsdlProcessor = getWSDLProcessor(); + List wsdlList = wsdlProcessor.readWSDLs(this.getSURootPath()); + this.getLogger().fine("Number of wsdl definitions in service unit " + wsdlList.size()); + + List services = new ArrayList(); + services.addAll(this.getSUDescriptor().getProvidedServices()); + services.addAll(this.getSUDescriptor().getConsumedServices()); + + boolean isForBinding = this.getSUDescriptor().isFor${artifactId}(); + this.getLogger().fine("Is this service unit for Binding? " + isForBinding); + + for ( Service service : services ) { + this.getLogger().fine("Looking up WSDL for service " + service); + boolean ignoreEndpointLookup = false; + boolean providerAtEngine = false; + if ( !isForBinding && service instanceof Provides ) { + ignoreEndpointLookup = true; + providerAtEngine = true; + } + Definition def = findWSDL(wsdlList, service, ignoreEndpointLookup); + if ( def == null ) { + throw new Exception("WSDL Definition not found for " + service); + } + this.mWSDLMap.put(getServiceKey(service), def); + if ( providerAtEngine ) { + // provider at engine. so add engine binding and endpoint to the wsdl + wsdlProcessor.createServiceEngineBinding(def, + service.getInterface(), service.getServiceName(), service.getEndpointName()); + } + } + } + /** extended classes implement this method to perform the su specific artifacts validation in + * this method implementation. + * @throws DeploymentException on error. + */ + protected void loadOtherArtifacts() throws DeploymentException { + // nothing to validate further. + this.getLogger().fine("ServiceUnit.loadOtherArtifacts"); + } + /** + * creates ProviderEndpoint and ConsumerEndpoint objects corresponding to the service providers + * and consumers described in the su descriptor ( jbi.xml ) + */ + protected void loadEndpoints() throws Exception { + + this.mProviderEndpointMap = new HashMap(); + this.mConsumerEndpointMap = new HashMap(); + + Collection providesList = this.getSUDescriptor().getProvidedServices(); + for ( Provides provides : providesList ) { + Definition wsdlDef = findWSDLFor(provides); + if ( wsdlDef == null ) { + throw new DeploymentException("WSDL Definitions not found for " + provides); + } + ProviderEndpoint provider = createProviderEndpoint(provides, wsdlDef); + this.mProviderEndpointMap.put(provider.getID(), provider); + } + + Collection consumesList = this.getSUDescriptor().getConsumedServices(); + for ( Consumes consumes : consumesList ) { + Definition wsdlDef = findWSDLFor(consumes); + if ( wsdlDef == null ) { + throw new DeploymentException("WSDL Definitions not found for " + consumes); + } + ConsumerEndpoint consumer = createConsumerEndpoint(consumes, wsdlDef); + this.mConsumerEndpointMap.put(consumer.getID(), consumer); + } + } + /** + * initializes the Endpoint objects created corresponding to the consumer and providers defined + * in the su descriptor + */ + protected void doInitEndpoints() throws DeploymentException { + // init endpoints. if any initialization fails, rollback the already inited endpoints + List initedEndpoints = new ArrayList(); + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getProviderEndpoints()); + allEndpoints.addAll(this.getConsumerEndpoints()); + + for ( Endpoint endpoint : allEndpoints ) { + try { + endpoint.init(); + initedEndpoints.add(endpoint); + } catch ( Exception initEx) { + doCleanEndpoints(initedEndpoints); + throw new DeploymentException(initEx); + } + } + + } + /** + * invokes activates method of all provider and consumer endpoint object in this su. if there is + * and error activating any one the endpoints, it deactivates the already activated ones and throws + * the error + */ + protected void doActivateEndpoints() throws DeploymentException { + // activate providers first and then consumers + List activatedEndpoints = new ArrayList(); + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getProviderEndpoints()); + allEndpoints.addAll(this.getConsumerEndpoints()); + + for ( Endpoint endpoint : allEndpoints ) { + try { + endpoint.activate(); + activatedEndpoints.add(endpoint); + } catch ( Exception actEx) { + doDeactivateEndpoints(activatedEndpoints); + throw new DeploymentException(actEx); + } + } + } + /** + * invokes deactivate method on the list of Endpoint objects passed to this method + */ + protected void doDeactivateEndpoints(List endpoints) { + for ( Endpoint endpoint : endpoints ) { + try { + endpoint.deactivate(); + } catch(Exception ex) { + // ignore the exception and log it. + this.getLogger().log(Level.FINE, ex.getMessage(), ex); + } + } + } + /** + * invokes deactivate method on the all consumer and provider endpoint objects + */ + protected void doDeactivateEndpoints() { + // deactivate consumers first and then the providers + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getConsumerEndpoints()); + allEndpoints.addAll(this.getProviderEndpoints()); + doDeactivateEndpoints(allEndpoints); + } + /** + * invokes clean method on the list of endpoint objects + */ + protected void doCleanEndpoints(List endpoints) { + for ( Endpoint endpoint : endpoints ) { + try { + endpoint.clean(); + } catch(Exception ex) { + // ignore the exception and log it. + this.getLogger().log(Level.FINE, ex.getMessage(), ex); + } + } + } + /** + * invokes clean method on the all consumer and provider endpoint objects in this su. + */ + protected void doCleanEndpoints() { + + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getConsumerEndpoints()); + allEndpoints.addAll(this.getProviderEndpoints()); + doCleanEndpoints(allEndpoints); + } + /** + * prints the service unit description + */ + protected final String printDetails() { + + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + + out.println("ServiceUnit Name : " + this.getName()); + out.println("ServiceUnit Root : " + this.getSURootPath()); + + SUDescriptor suDesc = null; + try { + suDesc = this.getSUDescriptor(); + for ( SUDescriptor.Consumes consumer : suDesc.getConsumedServices()) { + out.println(consumer); + } + for ( SUDescriptor.Provides provides : suDesc.getProvidedServices()) { + out.println(provides); + } + } catch (Exception ex) { + ex.printStackTrace(out); + } + return writer.getBuffer().toString(); + } + + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java new file mode 100644 index 000000000..67bbf5a45 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java @@ -0,0 +1,44 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractExtensibilityElement.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import javax.wsdl.extensions.ExtensibilityElement; +import javax.xml.namespace.QName; + +/** + * This is an abstract class which can be extended to create jwsdl (wsdl4j's) extension elements model to + * read/write the wsdl extension elements in wsdl 1.1 xml. + * + * @author chikkala + */ +public abstract class AbstractExtensibilityElement implements ExtensibilityElement, java.io.Serializable { + public static final long serialVersionUID = 1; + private QName mElementType; + private Boolean mRequired; + + /** Creates a new instance of AbstractExtensibilityElement */ + protected AbstractExtensibilityElement() { + } + + public void setElementType(QName elementType) { + this.mElementType = elementType; + } + + public QName getElementType() { + return this.mElementType; + } + + public void setRequired(Boolean required) { + this.mRequired = required; + } + + public Boolean getRequired() { + return this.mRequired; + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java new file mode 100644 index 000000000..0882bd65f --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java @@ -0,0 +1,45 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractExtensionRegistry.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.util.List; +import javax.wsdl.extensions.ExtensionRegistry; + +/** + * This is the abstract class used to add the wsdl extension serializers and deserializers to the + * wsdl extension registry configured to read/write wsdl extensions into a know java model. + * @see AbstractExtensionSerializer + * @see WSDLProcessor + * @author chikkala + */ +public abstract class AbstractExtensionRegistry extends ExtensionRegistry { + + /** Creates a new instance of AbstractSerializer + * it calls the createSerializers method to get the list of + * serializers and then call registerSerializer on each AbstractExtensionSerializer + * to register them with this registry. + * @see AbstractExtensionSerializer${symbol_pound}registerSerializer + */ + protected AbstractExtensionRegistry() { + super(); + List list = createSerializers(); + for (AbstractExtensionSerializer ser : list ) { + ser.registerSerializer(this); + } + // register ServiceEngine Binding serializers + AbstractExtensionSerializer seBindingSer = new SEBindingExt.SEBindingExtSerializer(); + seBindingSer.registerSerializer(this); + } + /** + * create wsdl extension serializers for each extension element to register with the extension + * registry. + * @return List of AbstractExtensionSerializer objects for serializing/deserializing the wsdl extensions. + * @see AbstractExtensionSerializer + */ + protected abstract List createSerializers(); +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java new file mode 100644 index 000000000..4ac1b37d6 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java @@ -0,0 +1,123 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractExtensionSerializer.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.io.PrintWriter; +import java.io.Serializable; +import java.util.Set; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionDeserializer; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.extensions.ExtensionSerializer; +import javax.xml.namespace.QName; +import org.w3c.dom.Attr; +import org.w3c.dom.Element; + +/** + * This class is an abstract class that should be extended to implements extension serializer and + * deserializer. This class implements the code required for registering the serializer and deserializer + * implemented by this class. THe AbstractExtensionRegistry class calls the ${symbol_pound}registerSerializer method + * to register the concrete implementation of this class with extension registry. + * @see AbstractExtensionRegistry + * @author chikkala + */ +public abstract class AbstractExtensionSerializer + implements ExtensionSerializer, ExtensionDeserializer, Serializable { + + public static final long serialVersionUID = 1; + + private Class mParentType; + private Class mExtensionType; + private QName mElementType; + + /** Creates a new instance of AbstractSerializer */ + public AbstractExtensionSerializer(Class parentType, QName elementType, Class extensionType) { + this.mParentType = parentType; + this.mElementType = elementType; + this.mExtensionType = extensionType; + } + + public Class getParentType() { + return this.mParentType; + } + public QName getElementType() { + return this.mElementType; + } + public Class getExtensionType() { + return this.mExtensionType; + } + + public void registerSerializer(ExtensionRegistry extReg) { + extReg.registerSerializer(this.mParentType, this.mElementType, this); + extReg.registerDeserializer(this.mParentType, this.mElementType, this); + extReg.mapExtensionTypes(this.mParentType, this.mElementType, this.mExtensionType); + } + + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg ) throws WSDLException { + // DO NOTHING. Binding component runtime does not need to serialize the wsdl extensions. + } + + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + return null; + } + + public static String getAttribute(Element el, String attrName) { + String attrValue = null; + Attr attr = el.getAttributeNode(attrName); + if ( attr != null ) { + attrValue = attr.getValue(); + } + return attrValue; + } + + protected String getNamespacePrefix(Definition def, String namespaceURI, String defPrefix) { + String prefix = null; + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + Set keySet = def.getNamespaces().keySet(); + String newPrefix = "ns"; + if ( defPrefix != null && defPrefix.trim().length() > 0 ){ + newPrefix = defPrefix; + } + prefix = newPrefix; + for ( int i=0; i < Integer.MAX_VALUE; ++i) { + if (!keySet.contains(prefix)) { + break; + } else { + prefix = newPrefix + i; + } + } + } + return prefix; + } + /** + * @return the name with the prefix defined for the namespaceURI in the wsdl definition. + * @throws WSDLException if the prefix not found in the wsdl definition. note that the + * default prefix is an empty string. + */ + protected String getQualifiedName(Definition def, + String namespaceURI, String localName) throws WSDLException { + String prefix = null; + if (namespaceURI != null && !namespaceURI.equals("")) { + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + throw new WSDLException(WSDLException.OTHER_ERROR, + "Can not find prefix in WSDL Definition for " + namespaceURI); + } + } + if ( prefix != null && !prefix.equals("")) { + return prefix + ":" + localName; + } else { + return localName; + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java new file mode 100644 index 000000000..b10800550 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java @@ -0,0 +1,229 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * AbstractNormalizer.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.util.ArrayList; +import java.util.List; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Part; +import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.dom.DOMSource; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * This is an abstract class that implements most of the functionality to normalize the binding protocol + * specific concrete message to jbi wrapper and and denormalize jbi wrapper to the concrete binding + * protocol specific message. + *

+ * The extended classes specific to particular binding protocol will be used when a jbi binding + * component is sending and receiving messages from the external service providers and consumers using + * a particular binding protocol known to this class. Extended implementation of this class should make + * use of the helper methods in this class in normalizing and denormalizing the messages. + * @see JMXBindingNormalizer + * @author chikkala + */ +public abstract class AbstractNormalizer { + + public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/"; + /** wsdl definition to use when normalizing and denormalizing */ + private Definition mWSDL; + /** Binding definition to use when normalizing and denormalizing */ + private Binding mBinding; + + private AbstractNormalizer() {} + /** Creates a new instance of JMXBCNormalizer */ + public AbstractNormalizer(Definition wsdl, Binding binding) { + this.mWSDL = wsdl; + this.mBinding = binding; + } + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete mssage of a particular binding protocol. + */ + public abstract void normalizeInput(Operation operation, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete message of a particular binding protocol. + */ + public abstract void normalizeOutput(Operation operation, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete message of a particular binding protocol. + */ + public abstract void normalizeFault(Operation operation, String faultName, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * denormalize the normalized message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be de-normalized. + * @param normMsg NormalizedMessage which should be used to create de-normalized message. + */ + public abstract DOMSource denormalizeInput(Operation operation, NormalizedMessage normMsg) + throws MessagingException; + /** + * denormalize the normalized message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be denormalized. + * @param normMsg NormalizedMessage which should be used to create denormalized message. + */ + public abstract DOMSource denormalizeOutput(Operation operation, NormalizedMessage normMsg) + throws MessagingException; + + /** + * denormalized the normalized fault message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be denormalized. + * @param normMsg NormalizedMessage which should be used to create denormalized message. + */ + public abstract DOMSource denormalizeFault(Operation operation, String faultName, NormalizedMessage normMsg) + throws MessagingException; + /** + * @return the wsdl definition to use in normalizing and denormalizing the message + */ + protected Definition getWSDL() { + return this.mWSDL; + } + /** + * @return the wsdl binding definition to use in normalizing and denormalizing the message + */ + protected Binding getBinding() { + return this.mBinding; + } + /** + * create and add message parts to the jbiWrapper according to the abstract message model. This + * method assumes that the each element in the msgParts list passed to it is mapped to the part + * of the abstract wsdl message and uses the type or element attribute of the abstract message to + * determine whether the element is actual part element or a wrapped part type. + * Use this method in normalizing the concrete protocol specific message to jbi wrapper message. + * @param jbiWrapper object that holds the jbi wrapper information. + * @param wsdlMsg abstract message from the wsdl definition + * @param msgParts actual message parts from the concrete message + */ + protected void addMessagePartsToJBIWrapper(WSDL11JBIWrapper jbiWrapper, Message wsdlMsg, List msgParts) throws MessagingException { + List wsdlParts = wsdlMsg.getOrderedParts(null); + for ( int i=0; i < wsdlParts.size(); ++i ) { + Part wsdlPart = (Part) wsdlParts.get(i); + if ( i >= msgParts.size() ) { + throw new MessagingException("missing message content for part " + wsdlPart.getName()); + } + Element msgPart = msgParts.get(i); + if ( wsdlPart.getElementName() != null ) { + jbiWrapper.appendPart(msgPart); + } else { + // it is type. + // check the element name is same as part + if ( !wsdlPart.getName().equals(msgPart.getLocalName()) ) { + throw new MessagingException("mismatched message content for part " + wsdlPart.getName()); + } + if ( !wsdlMsg.getQName().getNamespaceURI().equals(msgPart.getNamespaceURI()) ) { + throw new MessagingException("mismatched message content namespace for part " + wsdlPart.getName()); + } + // check the content is text or element. + List partContent = getChildElements(msgPart); + if ( partContent.size() > 0 ) { + // add content as part elements + jbiWrapper.appendPart(partContent); + } else { + // add the content as text + jbiWrapper.appendPart(msgPart.getTextContent()); + } + } + } + } + /** + * extracts the message parts from the jbiWrapper according to the abstract wsdl message + * definition passed to it. Use this method in denormalizing the jbi wrapper message into the + * binding protocol specific concrete message. + * @param jbiWrapper jbi wrapper object that contains message parts and the message type information. + * @param wsdlMsg abstract wsdl message definition to use in constructing the part elements. + */ + protected List getMessagePartsFromJBIWrapper(WSDL11JBIWrapper jbiWrapper, Message wsdlMsg) + throws MessagingException, ParserConfigurationException { + + List msgParts = new ArrayList(); + int jbiPartCount = jbiWrapper.getPartCount(); + List wsdlParts = wsdlMsg.getOrderedParts(null); + QName msgType = jbiWrapper.getType(); + if (!wsdlMsg.getQName().getNamespaceURI().equals(msgType.getNamespaceURI())) { + throw new MessagingException("Namespace mismatch between jbi wrapper message type and wsdl message"); + } + Document newDoc = jbiWrapper.getDocumentBuilder().newDocument(); + for ( int i=0; i < wsdlParts.size(); ++i ) { + Part wsdlPart = (Part) wsdlParts.get(i); + if ( i >= jbiPartCount ) { + throw new MessagingException("missing message content for part " + wsdlPart.getName()); + } + if ( wsdlPart.getElementName() != null ) { + msgParts.add(jbiWrapper.getPartAsElement(i)); + } else { + // it is type. create a new element for a typed part + // check the element name is same as part + String prefix = msgType.getPrefix(); + String nsURI = msgType.getNamespaceURI(); + String localName = wsdlPart.getName(); + Element partEl = newDoc.createElementNS(nsURI, prefix + ":" + localName); + partEl.setAttributeNS(XMLNS_NS, "xmlns:"+prefix, nsURI); + NodeList partContent = jbiWrapper.getPart(i); + appendChildren(partEl, partContent, newDoc, true); + msgParts.add(partEl); + } + } + return msgParts; + } + /** + * utility method that can append the nodeList passed to it to the element children. + * @param el element node to which the nodeList should be appended + * @param doc the document object that should be used to import the nodeList + * @param importNode true if the nodeList should be imported while appending the nodeList to the + * element children. false if no import is necessary. + */ + protected void appendChildren(Element el, NodeList nodeList, Document doc, boolean importNode) { + + for ( int pIdx = 0; pIdx < nodeList.getLength(); ++pIdx) { + Node node = nodeList.item(pIdx); + if ( importNode ) { + node = doc.importNode(node, true); + } + el.appendChild(node); + } + } + /** + * @param el element from which to extract the child elements + * @return List list of child Element nodes. + */ + protected List getChildElements(Element el) { + List list = new ArrayList(); + NodeList nodeList = el.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if (!(node instanceof Element) ){ + continue; + } + list.add((Element)node); + } + return list; + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java new file mode 100644 index 000000000..de59e0360 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java @@ -0,0 +1,99 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * SEBindingExt.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.io.PrintWriter; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation classes implement wsdl 1.1 extension model for the + * jbi service engine binding that is defined in jsr 208(sec. 5.5.6.1). to read/write concrete binding + * element in the wsdl definition for the service endpoint binding provided by the service engine. + * The wsdl definition with this binding information can be used in providing the service provider + * metadata returned by the service engine in Component.getServiceDescription. + *

+ * AbstractExtensionRegistry by default include this extension serializers in the + * registry to read/write this service engine binding type in the wsdl definition. + *

+ * During a service unit deployment/initialization in the service engine, the deployed wsdl definition + * is loaded and modified to provide this binding for the service provided by the engine. + * + * @see WSDLProcessor${symbol_pound}createServiceEngineBinding + * @see AbstractExtensionRegistry + * @see com.sun.jbi.sample.component.common.deployment.ServiceUnit${symbol_pound}loadServiceDefinitions + * @author chikkala + */ +public interface SEBindingExt extends ExtensibilityElement, java.io.Serializable { + + public static final String NS_URI = "http://java.sun.com/xml/ns/jbi/binding/service+engine"; + public static final String NS_DEF_PREFIX = "jbise"; + /** Element names. */ + public static final String EL_BINDING_EXT = "binding"; + /**Qualified element names.*/ + public static final QName QN_BINDING_EXT = new QName(NS_URI, EL_BINDING_EXT); + + public static class SEBindingExtImpl extends AbstractExtensibilityElement implements SEBindingExt { + + public SEBindingExtImpl() { + setElementType(QN_BINDING_EXT); + } + @Override + public String toString() { + StringBuffer buff = new StringBuffer(); + buff.append("<"+NS_DEF_PREFIX+":"+EL_BINDING_EXT); + buff.append("/>"); + return buff.toString(); + } + /** + * creates and adds the jbi service engine binding extensibility element to the wsdl definition + * under specified binding definition. + */ + public static SEBindingExtImpl addExtensibilityElement(Definition wsdlDef, Binding binding) { + SEBindingExtImpl bindingExt = new SEBindingExt.SEBindingExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, binding, bindingExt, SEBindingExt.NS_DEF_PREFIX); + return bindingExt; + } + } + /** + * serializer and descrializer implementation for the binding extension element. + */ + public static class SEBindingExtSerializer extends AbstractExtensionSerializer { + + public SEBindingExtSerializer() { + super(Binding.class, QN_BINDING_EXT, SEBindingExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + SEBindingExt extObj = (SEBindingExt)extReg.createExtension(parentType, elementType); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg ) throws WSDLException { + + String elName = getQualifiedName(def, NS_URI, EL_BINDING_EXT); + + SEBindingExt extObj = (SEBindingExt)extension; + + StringBuffer buff = new StringBuffer(); + buff.append("<" + elName ); + buff.append("/>"); + pw.println(buff.toString()); + } + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java new file mode 100644 index 000000000..92606104d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java @@ -0,0 +1,471 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * WSDL11JBIWrapper.java + * + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.dom.DOMSource; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +/** + * This class wraps the wsdl11 messages to the jbi wrapper message suitable for + * processing in the wsdl2.0 model of the normalized message in jbi as defined in jsr208 like + * + * + * + * + * + * + * + * + * + * + * @author chikkala + */ +public class WSDL11JBIWrapper { + + public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/"; + public static final String WRAPPER_NAMESPACE = "http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper"; + public static final String DEF_NS_PREFIX = "jbiwrp"; + public static final String DEF_MESSAGE_NS_PREFIX = "msgns"; + public static final String JBI_MESSAGE_EL = "message"; + public static final String JBI_PART_EL = "part"; + public static final String VERSION_ATTR = "version"; + public static final String VERSION_ATTR_VALUE = "1.0"; + public static final String TYPE_ATTR = "type"; + public static final String NAME_ATTR = "name"; + + private static DocumentBuilder sDocBuilder = null; + /** qname of message attribute from wsdl:input, wsdl:output or wsdl:fault */ + private QName mType; + /** optional name attribute from wsdl:input, wsdl:output or wsdl:fault */ + private String mName; + /** each parts contents as node list */ + List mPartConentList = new ArrayList(); + + /** Creates a new instance of WSDL11JBIWrapper */ + public WSDL11JBIWrapper() { + } + /** creates the namespace aware document builder. extended classes can override this method + * to return the doc builder created else where. + */ + protected DocumentBuilder createDocumentBuilder() throws ParserConfigurationException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + return factory.newDocumentBuilder(); + } + /** return the document builder + * @return DocumentBuilder + */ + public final DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { + if ( WSDL11JBIWrapper.sDocBuilder == null ) { + WSDL11JBIWrapper.sDocBuilder = createDocumentBuilder(); + } + return WSDL11JBIWrapper.sDocBuilder; + } + /** + * @return type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + */ + public QName getType() { + return this.mType; + } + /** + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + */ + public void setType(QName type) { + this.mType = type; + } + /** @return name attribute from wsdl:input, wsdl:output or wsdl:fault. or null if not set. */ + public String getName() { + return this.mName; + } + /** + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault. can be null. + */ + public void setName(String name) { + this.mName = name; + } + /** + * appends part content as node list + */ + public void appendPart(NodeList partContent) { + this.mPartConentList.add(partContent); + } + /** + * append part content from the List of nodes + */ + public void appendPart(List partContent) { + this.mPartConentList.add(new NodeListImpl(partContent)); + } + /** + * append part content as element + */ + public void appendPart(Element partContent) { + this.mPartConentList.add(new NodeListImpl(partContent)); + } + /** + * append part content from DOMSource + */ + public void appendPart(DOMSource partContent) { + Element partConentEl = getElement(partContent.getNode()); + this.mPartConentList.add(new NodeListImpl(partConentEl)); + } + /** + * append part content as text node. + */ + public void appendPart(String partContent) { + Text textContent = null; + try { + textContent = this.getDocumentBuilder().newDocument().createTextNode(partContent); + } catch (ParserConfigurationException ex) { + ex.printStackTrace(); + } + if ( textContent != null ) { + this.mPartConentList.add(new NodeListImpl(textContent)); + } + } + /** + * append list of part contents each is a NodeList to the parts + */ + public void appendParts(List partContentList) { + this.mPartConentList.addAll(partContentList); + } + /** + * returned the ordered list of part contents. + */ + public List getParts() { + return Collections.unmodifiableList(this.mPartConentList); + } + /** + * return the number of parts + */ + public int getPartCount() { + return this.mPartConentList.size(); + } + /** + * return the part content at a particular index as NodeList. + */ + public NodeList getPart(int idx) { + return this.mPartConentList.get(idx); + } + /** + * return part context at a particular index as text + */ + public String getPartAsText(int idx) { + NodeList partNodes = getPart(idx); + Document doc; + try { + doc = this.getDocumentBuilder().newDocument(); + Element el = doc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_PART_EL); + for ( int i=0; i < partNodes.getLength(); ++i) { + el.appendChild(partNodes.item(i)); + } + return el.getTextContent(); + } catch (ParserConfigurationException ex) { + return null; + } + } + /** + * return part context at a particular index as Element + */ + public Element getPartAsElement(int idx) { + Element contentEl = null; + NodeList partNodes = getPart(idx); + for ( int i=0; i < partNodes.getLength(); ++i) { + Node node = partNodes.item(i); + if ( node instanceof Element) { + contentEl = (Element)node; + break; + } + } + return contentEl; + } + /** + * creates Document from this wrapper object. Before calling this method, + * the type, name (optional) and parts contents should be set. + * @return Document containing the wsdl 11 wrapper xml + */ + public Document toDocument() throws ParserConfigurationException { + + Document wrapperDoc = getDocumentBuilder().newDocument(); + Element jbiMessage = wrapperDoc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_MESSAGE_EL); + jbiMessage.setAttribute(VERSION_ATTR, VERSION_ATTR_VALUE); + wrapperDoc.appendChild(jbiMessage); + + QName type = this.getType(); + if ( type == null ) { + type = new QName("", "", DEF_MESSAGE_NS_PREFIX); + } + // set the jbiMessage attributes + String prefix = type.getPrefix(); + if (prefix == null || prefix.length() == 0) { + prefix = DEF_MESSAGE_NS_PREFIX; + } + jbiMessage.setAttribute(TYPE_ATTR, prefix + ":" + type.getLocalPart()); + jbiMessage.setAttributeNS( XMLNS_NS, "xmlns:" + prefix, type.getNamespaceURI()); + + String name = this.getName(); + if (name != null && name.trim().length() > 0 ) { + jbiMessage.setAttribute(NAME_ATTR, name); + } + + List partContentList = this.getParts(); + for ( NodeList nodeList : partContentList ) { + // set jbi part message + Element jbiPart = wrapperDoc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_PART_EL); + jbiMessage.appendChild(jbiPart); + for ( int i =0; i < nodeList.getLength(); ++i ) { + Node importedMsgNode = wrapperDoc.importNode(nodeList.item(i), true); + jbiPart.appendChild(importedMsgNode); + } + } + + return wrapperDoc; + + } + /** + * creates DOMSource from this wrapper object. Before calling this method, + * the type, name (optional) and parts contents should be set. + * @return DOMSource containing the wsdl 11 wrapper xml + */ + public DOMSource toDOMSource() throws ParserConfigurationException { + DOMSource wrappedSource = new DOMSource(); + wrappedSource.setNode(toDocument()); + return wrappedSource; + } + /** + * return Element node from a document node or non document. Use to extract + * the message root element. + * @root node from which the Element node will be extracted. + * @return Element node. + */ + public static Element getElement(Node root) { + Element msgEl = null; + if ( root instanceof Document) { + msgEl = ((Document)root).getDocumentElement(); + } else if (root instanceof Element) { + msgEl = (Element)root; + } else { + NodeList nodeList = root.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if ( node instanceof Element ) { + msgEl = (Element) node; + break; + } + } + } + return msgEl; + } + /** + * creates wrapper object from the DOMSource that has wsdl 11 wrapper xml. + * @param wrappedMsg wsdl 11 wrapper xml as DOMSource + * @return WSDL11JBIWrapper representing the wrapper xml. + */ + public static WSDL11JBIWrapper sourceToWrapper(DOMSource wrappedMsg) { + Element jbiMessage = getElement(wrappedMsg.getNode()); + if ( jbiMessage == null ) { + return null; + } + String nsURI = jbiMessage.getNamespaceURI(); + String tagName = jbiMessage.getLocalName(); + if (!WRAPPER_NAMESPACE.equals(nsURI) || !JBI_MESSAGE_EL.equals(tagName)) { + return null; + } + String name = jbiMessage.getAttribute(NAME_ATTR); + String typeQN = jbiMessage.getAttribute(TYPE_ATTR); + String typePrefix = ""; + String typeName = ""; + if ( typeQN != null && typeQN.trim().length() > 0 ) { + int idx = typeQN.indexOf(':'); + if ( idx >= 0 ) { + typePrefix = typeQN.substring(0, idx); + if ( typeQN.length() > idx ) { + typeName = typeQN.substring(idx+1); + } + } else { + typePrefix = ""; + typeName = typeQN; + } + } + String typeURI = jbiMessage.getAttribute("xmlns:" + typePrefix); + QName typeQName = new QName(typeURI, typeName, typePrefix); + + WSDL11JBIWrapper wrapper = new WSDL11JBIWrapper(); + wrapper.setName(name); + wrapper.setType(typeQName); + NodeList jbiPartList = jbiMessage.getElementsByTagNameNS(WRAPPER_NAMESPACE, JBI_PART_EL); + for ( int i=0; i < jbiPartList.getLength(); ++i) { + Node jbiPart = jbiPartList.item(i); + wrapper.appendPart(jbiPart.getChildNodes()); + } + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object and sets the type and name of the object + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name ) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = new WSDL11JBIWrapper(); + wrapper.setName(name); + wrapper.setType(type); + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object. useful when the message has one part and the + * part content has multiple child element. + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @param partContent part content as node list + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name, NodeList partContent) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name); + wrapper.appendPart(partContent); + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object. useful when the message has one part and the + * part content is a single element + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @param partContent part content as node list + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name, Element msgEl) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name, new WSDL11JBIWrapper.NodeListImpl(msgEl)); + return wrapper; + } + + public static WSDL11JBIWrapper createWrapper(QName type, String name, DOMSource inputSource) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name); + Node msgNode = getElement(inputSource.getNode()); + NodeList nodeList = new WSDL11JBIWrapper.NodeListImpl(msgNode); + wrapper.appendPart(nodeList); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations input element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createInputWrapper(Operation operation) throws ParserConfigurationException { + QName type = null; + String name = null; + + Input input = operation.getInput(); + if ( input == null ) { + return null; + } + name = input.getName(); + Message wsdlMsg = input.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations output element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createOutputWrapper(Operation operation) throws ParserConfigurationException { + QName type = null; + String name = null; + + Output output = operation.getOutput(); + if ( output == null) { + return null; + } + name = output.getName(); + Message wsdlMsg = output.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations output element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @param faultName fault name, can be null to look for the fault with no name. + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createFaultWrapper(Operation operation, String faultName) throws ParserConfigurationException { + QName type = null; + String name = null; + @SuppressWarnings("unchecked") + Map faultMap = operation.getFaults(); + Fault fault = faultMap.get(faultName); + + if ( fault == null ) { + return null; + } + name = fault.getName(); + Message wsdlMsg = fault.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * NodeList implementation. + */ + public static class NodeListImpl extends ArrayList implements NodeList { + + public NodeListImpl() { + super(); + } + + public NodeListImpl(Node aNode) { + super(); + if (aNode != null) { + this.add(aNode); + } + } + + public NodeListImpl(List nodes) { + if (nodes != null) { + this.addAll(nodes); + } + } + + public int getLength() { + return this.size(); + } + + public Node item(int idx) { + return this.get(idx); + } + + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java new file mode 100644 index 000000000..b5a1bb331 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java @@ -0,0 +1,419 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * WSDLProcessor.java + */ + +package net.openesb.component.${artifactId}.common.wsdl; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ElementExtensible; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.wsdl.xml.WSDLWriter; +import javax.xml.namespace.QName; + +/** + * This class is used to configure jwsdl(wsdl4j) to read and process wsdl documents with wsdl extensions. + * It provides set of helper methods to read and process the wsdl definitions from files with .wsdl + * extension from a specified directory. + *

+ * A Binding Component that is processing the wsdl extensions for its deployment configuration would + * extend this class and provide the required ExtensionRegistry that will have the extension serializers + * and deserializers configured to read/write the extensions from/to the java model. + *

+ * A Service Engine that is processing the wsdl during deployment can directly use this class + * to process the wsdl as the default implementation returned by this class configures the wsdl extension + * registry to read/write the service engine binding extensions. + * + * @see AbstractExtensionRegistry + * @see SEBindingExt + * @author chikkala + */ +public class WSDLProcessor { + + private String mXmlCatalogPath = "xml-catalog.xml"; + private String mWsdlDirPath = ""; + private WSDLReader mReader; + + /** Creates a new instance of WSDLProcessor + */ + public WSDLProcessor(String wsdlDir) { + this(wsdlDir, null); + } + /** Creates a new instance of WSDLProcessor + */ + public WSDLProcessor(String wsdlDir, String xmlCatPath) { + if ( wsdlDir != null ) { + this.mWsdlDirPath = wsdlDir; + } + if ( xmlCatPath != null ) { + this.mXmlCatalogPath = xmlCatPath; + } + } + /** @return directory path from which this class reads the wsdl files with .wsdl as file extension. */ + public String getWSDLDirectory() { + return this.mWsdlDirPath; + } + /** path to the xml catalog file in the service unit which can be used for Catalog-based entity + * and URI resolution. + */ + public String getXmlCatelogPath() { + return this.mXmlCatalogPath; + } + /** wsdl extension registry required for processing the wsdl extensions in the wsdl definition to + * java model. Binding component that is processing the wsdl extensions for its deployment + * configuration would provide the required ExtensionRegistry that will have the extension serializers + * and deserializers configured to read/write the extensions from/to the java model. + * @return ExtensionSerializer + * @see AbstractExtensionSerializer + */ + protected ExtensionRegistry getExtensionRegistry() { + return new AbstractExtensionRegistry() { + protected List createSerializers() { + return new ArrayList(); + } + }; + } + /** + * @return the WSDLReader configured with extension registry to process the wsdl extensions. + */ + public final WSDLReader getWSDLReader() throws WSDLException { + if ( this.mReader == null ) { + WSDLFactory factory = WSDLFactory.newInstance(); + this.mReader = factory.newWSDLReader(); + // reader.setFeature("javax.wsdl.verbose", true); + // reader.setFeature("javax.wsdl.importDocuments", true); + this.mReader.setExtensionRegistry(getExtensionRegistry()); + } + return this.mReader; + } + /** + * reads the wsdl file and returns the wsdl definition jwsdl model. + * @param wsldFilePath relative path to wsdl file from the the root wsdl directory returns from + * ${symbol_pound}getWSDLDirectory in the service unit or or absolute path . + * @return Definition + */ + public Definition readWSDL(String wsdlFilePath) throws WSDLException { + File wsdlFile = new File(wsdlFilePath); + if ( !wsdlFile.isAbsolute() ) { + wsdlFile = new File(this.mWsdlDirPath, wsdlFilePath); + } + return getWSDLReader().readWSDL(wsdlFile.getAbsolutePath()); + } + /** + * reads the files with .wsdl file extension in a directory. If the directory should + * be searched recursively, it searches this directory, all child directories of this + * directory and then to their child directories recursively. + * @param dir directory file to search for .wsdl files + * @param rec if set to true, it recursively searches the directory. if set to false, only + * this directory is searched. + * @return List of Files with .wsdl extension. + */ + public List listWSDLFiles(File dir, final boolean rec) throws IOException { + if ( dir == null || !dir.isDirectory()) { + throw new IOException(dir + " is not a directory for looking up wsdl files"); + } + List wsdlList = new ArrayList(); + File[] files = dir.listFiles(new FileFilter() { + public boolean accept(File pathname) { + if ( rec && pathname.isDirectory()) { + return true; + } else { + String name = pathname.getName(); + int idx = name.lastIndexOf('.'); + if ( idx < 0 ) { + return false; + } + String ext = name.substring(idx); + return ".wsdl".equalsIgnoreCase(ext); + } + } + }); + for ( File file : files ) { + if ( rec && file.isDirectory()) { + List wsdlFiles = listWSDLFiles(file, rec); + wsdlList.addAll(wsdlFiles); + } else { + wsdlList.add(file); + } + } + return wsdlList; + } + /** + * reads the files with .wsdl file extension in a directory fromDir and return the list of + * wsdl definitions corresponding to them. + * @param fromDir path to the directory relative to the root wsdl directory returns from + * ${symbol_pound}getWSDLDirectory or the absolute path to the directory. + */ + public List readWSDLs(String fromDir) throws WSDLException { + if ( fromDir == null ) { fromDir = ""; } + File wsdlDir = new File(fromDir); + if (!wsdlDir.isAbsolute()) { + wsdlDir = new File(this.mWsdlDirPath, fromDir); + } + + List wsdlFiles = new ArrayList(); + try { + wsdlFiles = listWSDLFiles(wsdlDir, true); + } catch (IOException ioEx) { + throw new WSDLException("WSDLFileReadError", ioEx.getMessage(),ioEx); + } + + List wsdlPaths = new ArrayList(); + for ( File wsdlFile : wsdlFiles) { + wsdlPaths.add(wsdlFile.getAbsolutePath()); + } + Collections.sort(wsdlPaths); + + List wsdlList = new ArrayList(); + for ( String wsdlPath : wsdlPaths ) { + Definition wsdlDef = readWSDL(wsdlPath); + wsdlList.add(wsdlDef); + } + return wsdlList; + } + /** + * finds PortType using port type ( interface ) qname. + */ + public static PortType findInterface(Definition wsdlDef, QName interfaceName) { + return wsdlDef.getPortType(interfaceName); + } + /** finds the Service using service qname */ + public static Service findService(Definition wsdlDef, QName serviceName) { + return wsdlDef.getService(serviceName); + } + /** finds the wsdl port using service qname and endpoint name */ + public static Port findServiceEndpoint(Definition wsdlDef, QName serviceName, String endpointName) { + Service service = null; + Port port = null; + service = findService(wsdlDef, serviceName); + if ( service != null ) { + port = service.getPort(endpointName); + } + return port; + } + /** + * finds the binding definition to which the service with serviceName and endpointName was bound. + */ + public static Binding findServiceBinding(Definition wsdlDef, QName serviceName, String endpointName) { + Binding binding = null; + Port port = findServiceEndpoint(wsdlDef, serviceName, endpointName); + if ( port != null ) { + binding = port.getBinding(); + } + return binding; + } + /** + * finds the binding definition using the interface(portType) qname with a + */ + public static Binding findInterfaceBinding(Definition wsdlDef, + QName interfaceQName, QName extQName) { + Map bindingMap = wsdlDef.getBindings(); + @SuppressWarnings("unchecked") + Collection bindings = bindingMap.values(); + for ( Binding binding : bindings ) { + if ( binding.getPortType().getQName().equals(interfaceQName)) { + return binding; + } + } + return null; + } + + /** + * find the wsdl4j operation corresponds to the interface+operation. + * @param wsdlDef wsdl definition + * @param portTypeQName portType QName + * @param opName operation name. if null, first operation in the portType + * is returned. + * @return Operation corresponding to the portType+opName + */ + public static Operation findOperation(Definition wsdlDef, + QName portTypeQName, String opName) { + Operation operation = null; + PortType portType = wsdlDef.getPortType(portTypeQName); + if ( portType != null ) { + if ( opName != null ) { + operation = portType.getOperation(opName, null, null); + } else { + @SuppressWarnings("unchecked") + List list = portType.getOperations(); + if ( list != null && list.size() > 0 ) { + operation = list.get(0); + } + } + } + return operation; + } + /** + * verifies whether the wsdl definition contains the specified service descriptions or not. Used + * to locate the wsdl definition for the services describes in service unit deployment + * descriptor(jbi.xm). + * @param interfaceName portType qname to find in the definition. can be null if you are trying to + * find only service endpoint description. + * @param serviceName qname for the service to find in this wsdl. can be null if + * you are trying to find only portType (abstract service) description. + * @param endpointName port name to find in the service definition. null if only + * service with any port should be looked up. + * + * @return true if the wsdl definition contains the specified service description. + */ + public static boolean isWSDLFor(Definition wsdlDef, + QName interfaceName, QName serviceName, String endpointName) { + PortType portType = null; + Service service = null; + Port port = null; + if ( interfaceName != null ) { + portType = findInterface(wsdlDef, interfaceName); + } + + if ( serviceName != null ) { + service = findService(wsdlDef, serviceName); + } + + if ( endpointName != null && service != null ) { + port = service.getPort(endpointName); + } + + boolean isWSDL = true; + + if ( (interfaceName != null && portType == null) || + ( serviceName != null && service == null ) || + ( endpointName != null && (service == null || port == null)) ) { + isWSDL = false; + } + + return isWSDL; + } + /** + * creates a binding definition that contains a service engine binding elements in the specified + * wsdl definition for a portType. It will try to find/create the binding element with interface + * local name with a "_JBISEBinding" suffix and add service engine binding element to it if it + * is not present. + * @param wsdl wsdl definition + * @param interfaceName portType qname to which the binding is created. + * @return a Binding contains service engine binding that is created for the portType. + */ + public Binding createServiceEngineBinding(Definition wsdl, QName interfaceName) { + QName bindingQName = new QName(wsdl.getQName().getNamespaceURI(), + interfaceName.getLocalPart() + "_JBISEBinding"); + Binding binding = wsdl.getBinding(bindingQName); + if ( binding == null ) { + binding = wsdl.createBinding(); + binding.setQName(bindingQName); + binding.setPortType(wsdl.getPortType(interfaceName)); + binding.setUndefined(false); + + ExtensibilityElement bindingExt = + SEBindingExt.SEBindingExtImpl.addExtensibilityElement(wsdl, binding); + + wsdl.addBinding(binding); + } + return binding; + } + /** + * creates port and binding elements that provide the the service engine binding for a service. + * @param wsdl wsdl definition + * @param interfaceName portType qname to which the binding is created. + * @param serviceName service under which the port definition bound to the service engine binding + * should be created. + * @param endpointName port name. + * @return a Binding contains service engine binding that is created for the portType. + */ + public Binding createServiceEngineBinding(Definition wsdl, QName interfaceName, QName serviceName, String endpointName ) { + Binding binding = null; + Service service = findService(wsdl, serviceName); + if ( service == null ) { + return null; + } + Port port = service.getPort(endpointName); + if ( port != null ) { + binding = port.getBinding(); + } else { + // create port + port = wsdl.createPort(); + port.setName(endpointName); + binding = createServiceEngineBinding(wsdl, interfaceName); + port.setBinding(binding); + service.addPort(port); + } + return binding; + } + /** prints the wsdl to text from the wsdl definition */ + public static void printWSDL(PrintWriter out, Definition def) { + try { + WSDLFactory factory = WSDLFactory.newInstance(); + WSDLWriter wsdlWriter = factory.newWSDLWriter(); + wsdlWriter.writeWSDL(def, out); + } catch (WSDLException ex) { + ex.printStackTrace(out); + } + } + /** prints the wsdl to text from the wsdl definition */ + public static String printWSDLToString(Definition def) { + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + printWSDL(out, def); + out.close(); + return writer.getBuffer().toString(); + } + /** returns an existing namespace prefix or create one if not exists for the corresponding namespaceURI */ + public static String getNamespacePrefix(Definition def, String namespaceURI, String defPrefix) { + String prefix = null; + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + Set keySet = def.getNamespaces().keySet(); + String newPrefix = "ns"; + if ( defPrefix != null && defPrefix.trim().length() > 0 ){ + newPrefix = defPrefix; + } + prefix = newPrefix; + for ( int i=0; i < Integer.MAX_VALUE; ++i) { + if (!keySet.contains(prefix)) { + break; + } else { + prefix = newPrefix + i; + } + } + } + return prefix; + } + + /** + * creates and adds the jbi service engine binding extensibility element to the wsdl definition + * under specified binding definition. + */ + public static void addExtensibilityElement(Definition wsdlDef, + ElementExtensible extensibleEl, ExtensibilityElement extEl, String defPrefix) { + QName elementType = extEl.getElementType(); + String namespaceURI = elementType.getNamespaceURI(); + String prefix = wsdlDef.getPrefix(namespaceURI); + if ( prefix == null ) { + // no namespace prefix defined. create one. + prefix = WSDLProcessor.getNamespacePrefix(wsdlDef, namespaceURI, defPrefix); + wsdlDef.addNamespace(prefix, namespaceURI); + } + extensibleEl.addExtensibilityElement(extEl); + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/BindingExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/BindingExt.java new file mode 100644 index 000000000..f61d31f64 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/BindingExt.java @@ -0,0 +1,101 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * BindingExt.java + */ +package net.openesb.component.${artifactId}.wsdlext; + +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * extension element. The inner classes BindingExtImpl implements the interface + * and the BindingExtSerializer provides the serializer and deserializer + * implementation. The implementation and serializer classes will be registered + * with the ExtensionRegistry to process the binding extension element in the + * wsdl definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface BindingExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + //TODO: define get/set methods for properties for BindingExt if the extension element has attributes. + + /** + * This class is an implementation of BindingExt interface that provides + * java model for binding extensibility element. + */ + public static class BindingExtImpl extends AbstractExtensibilityElement implements BindingExt { + + public BindingExtImpl() { + setElementType(QN_BINDING_EXT); + } + + /** + * creates and adds the binding extensibility element to the wsdl + * definition + */ + public static BindingExtImpl addExtensibilityElement(Definition wsdlDef, Binding binding) { + BindingExtImpl bindingExt = new BindingExt.BindingExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, binding, bindingExt, NS_DEF_PREFIX); + return bindingExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * binding extensibility element. + */ + public static class BindingExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public BindingExtSerializer() { + super(Binding.class, QN_BINDING_EXT, BindingExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + BindingExt extObj = (BindingExt) extReg.createExtension(parentType, elementType); + //TODO: set any attributes from the el to extension object + // String myAttr = el.getAttribute(ATTR_MY_ATTR); + // extObj.setMyAttr(myAttr); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + BindingExt extObj = (BindingExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_BINDING_EXT); + buff.append("<" + elName); + + //TODO: append any attributes from extension obj to the element + // String myAttr = extObj.getMyAttr(); + // if ( myAttr != null && myAttr.trim().length() > 0 ) { + // buff.append(" myAttr=${symbol_escape}"" + myAttr + "${symbol_escape}""); + // } + // + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/ExtConstants.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/ExtConstants.java new file mode 100644 index 000000000..2a7b8d153 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/ExtConstants.java @@ -0,0 +1,52 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ExtConstants.java + * + */ +package net.openesb.component.${artifactId}.wsdlext; + +import javax.xml.namespace.QName; + +/** + * This interface defines the constants for the namespace, elements, attributes + * and qnames corresponding to the wsdl extensions that this component + * processes. These constants will be used in the wsdl extension model used to + * process a particular wsdl extensions. + * + * @see WSDLExtensionRegistry + * @see PortExt + * @see BindingExt + * @author chikkala + */ +public interface ExtConstants { + + public static final String NS_URI_WSDL = "http://schemas.xmlsoap.org/wsdl/"; + public static final String NS_URI_XMLNS = "http://www.w3.org/2000/xmlns/"; + /** + * wsdl extension namespace processed by this wsdl extension model + */ + public static final String NS_URI = "http://java.sun.com/jbi/wsdl-extensions/sample/jmx-bc/"; + public static final String NS_DEF_PREFIX = "jmxbc"; + // wsdl extension element names. + public static final String EL_BINDING_EXT = "binding"; + public static final String EL_OPERATION_EXT = "operation"; + public static final String EL_INPUT_EXT = "input"; + public static final String EL_OUTPUT_EXT = "output"; + public static final String EL_FAULT_EXT = "fault"; + public static final String EL_PORT_EXT = "address"; + // Qualified wsdl extension element names. + public static final QName QN_BINDING_EXT = new QName(NS_URI, EL_BINDING_EXT); + public static final QName QN_OPERATION_EXT = new QName(NS_URI, EL_OPERATION_EXT); + public static final QName QN_INPUT_EXT = new QName(NS_URI, EL_INPUT_EXT); + public static final QName QN_OUTPUT_EXT = new QName(NS_URI, EL_OUTPUT_EXT); + public static final QName QN_FAULT_EXT = new QName(NS_URI, EL_FAULT_EXT); + public static final QName QN_PORT_EXT = new QName(NS_URI, EL_PORT_EXT); + // wsdl extension elements attribute names. + public static final String ATTR_ACTION = "action"; + public static final String ATTR_SERVICE_URL = "serviceURL"; + public static final String ATTR_USERNAME = "username"; + public static final String ATTR_PASSWORD = "password"; + public static final String ATTR_MBEAN = "mbean"; +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/FaultExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/FaultExt.java new file mode 100644 index 000000000..051573122 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/FaultExt.java @@ -0,0 +1,101 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * FaultExt.java + */ +package net.openesb.component.${artifactId}.wsdlext; + +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.BindingFault; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * operation fault extension element. The inner classes FaultExtImpl implements + * the interface and the FaultExtSerializer provides the serializer and + * deserializer implementation. The implemenation and serializer classes will be + * registered with the ExtensionRegistry to process the binding operation fault + * extension element in the wsdl definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface FaultExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + + //TODO: define getter methods for properties for FaultExt if the extension element has attributes. + /** + * This class is an implementation of FaultExt interface that provides java + * model for binding operation fault extensibility element. + */ + public static class FaultExtImpl extends AbstractExtensibilityElement implements FaultExt { + + public FaultExtImpl() { + setElementType(QN_FAULT_EXT); + } + + /** + * creates and adds the binding operation fault extensibility element to + * the wsdl definition + */ + public static FaultExtImpl addExtensibilityElement(Definition wsdlDef, BindingFault fault) { + FaultExtImpl faultExt = new FaultExt.FaultExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, fault, faultExt, NS_DEF_PREFIX); + return faultExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * binding operation fault extensibility element. + */ + public static class FaultExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public FaultExtSerializer() { + super(BindingFault.class, QN_FAULT_EXT, FaultExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + FaultExt extObj = (FaultExt) extReg.createExtension(parentType, elementType); + //TODO: set any attributes from the el to extension object + // String myAttr = el.getAttribute(ATTR_MY_ATTR); + // extObj.setMyAttr(myAttr); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + FaultExt extObj = (FaultExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_FAULT_EXT); + buff.append("<" + elName); + + //TODO: append any attributes from extension obj to the element + // String myAttr = extObj.getMyAttr(); + // if ( myAttr != null && myAttr.trim().length() > 0 ) { + // buff.append(" myAttr=${symbol_escape}"" + myAttr + "${symbol_escape}""); + // } + // + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/InputExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/InputExt.java new file mode 100644 index 000000000..bb4f45078 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/InputExt.java @@ -0,0 +1,101 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * InputExt.java + */ +package net.openesb.component.${artifactId}.wsdlext; + +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.BindingInput; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * operation input extension element. The inner classes InputExtImpl implements + * the interface and the InputExtSerializer provides the serislizer and + * deserializer implementation. The implementation and serializer classes will + * be registered with the ExtensionRegistry to process the binding operation + * input extension element in the wsdl definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface InputExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + + //TODO: define get/set methods for properties for InputExt if the extension element has attributes. + /** + * This class is an implementation of InputExt interface that provides java + * model for binding operation input extensibility element. + */ + public static class InputExtImpl extends AbstractExtensibilityElement implements InputExt { + + public InputExtImpl() { + setElementType(QN_INPUT_EXT); + } + + /** + * creates and adds the binding operation fault extensibility element to + * the wsdl definition + */ + public static InputExtImpl addExtensibilityElement(Definition wsdlDef, BindingInput input) { + InputExtImpl inputExt = new InputExt.InputExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, input, inputExt, NS_DEF_PREFIX); + return inputExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * binding operation input extensibility element. + */ + public static class InputExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public InputExtSerializer() { + super(BindingInput.class, QN_INPUT_EXT, InputExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + InputExt extObj = (InputExt) extReg.createExtension(parentType, elementType); + //TODO: set any attributes from the el to extension object + // String myAttr = el.getAttribute(ATTR_MY_ATTR); + // extObj.setMyAttr(myAttr); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + InputExt extObj = (InputExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_INPUT_EXT); + buff.append("<" + elName); + + //TODO: append any attributes from extension obj to the element + // String myAttr = extObj.getMyAttr(); + // if ( myAttr != null && myAttr.trim().length() > 0 ) { + // buff.append(" myAttr=${symbol_escape}"" + myAttr + "${symbol_escape}""); + // } + // + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/OperationExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/OperationExt.java new file mode 100644 index 000000000..c7fd384a4 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/OperationExt.java @@ -0,0 +1,121 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * OperationExt.java + */ +package net.openesb.component.${artifactId}.wsdlext; + +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * operation extension element. The inner classes OperationImpl implements the + * interface and the OperationExtSerializer provides the serilizer and + * deserializer implementation. The implementation and serializer classes will + * be registered with the ExtensionRegistry to process the binding operation + * extension element in the wsdl definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface OperationExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + + /** + * Getter for property action. + * + * @return Value of property action. + */ + public String getAction(); + + /** + * Setter for property action. + * + * @param action New value of property action. + */ + public void setAction(String action); + + /** + * This class is an implementation of OperationExt interface that provides + * java model for binding operation extensibility element. + */ + public static class OperationExtImpl extends AbstractExtensibilityElement implements OperationExt { + + private String mAction; + + public OperationExtImpl() { + setElementType(QN_OPERATION_EXT); + } + + public String getAction() { + return this.mAction; + } + + public void setAction(String action) { + this.mAction = action; + } + + /** + * creates and adds the binding operation fault extensibility element to + * the wsdl definition + */ + public static OperationExtImpl addExtensibilityElement(Definition wsdlDef, BindingOperation operation) { + OperationExtImpl operationExt = new OperationExt.OperationExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, operation, operationExt, NS_DEF_PREFIX); + return operationExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * binding operation extensibility element. + */ + public static class OperationExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public OperationExtSerializer() { + super(BindingOperation.class, QN_OPERATION_EXT, OperationExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + OperationExt extObj = (OperationExt) extReg.createExtension(parentType, elementType); + String action = el.getAttribute(ATTR_ACTION); + extObj.setAction(action); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + OperationExt extObj = (OperationExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_OPERATION_EXT); + buff.append("<" + elName); + + String action = extObj.getAction(); + if (action != null && action.trim().length() > 0) { + buff.append(" " + ATTR_ACTION + "=${symbol_escape}"" + action + "${symbol_escape}""); + } + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/OutputExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/OutputExt.java new file mode 100644 index 000000000..7c88fc9de --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/OutputExt.java @@ -0,0 +1,101 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * OutputExt.java + */ +package net.openesb.component.${artifactId}.wsdlext; + +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.BindingOutput; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * operation output extension element. The inner classes OutputExtImpl + * implements the interface and the OutputExtSerializer provides the serilizer + * and deserializer implementation. The implementation and serializer classes + * will be registered with the ExtensionRegistry to process the binding + * operation output extension element in the wsdl definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface OutputExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + + //TODO: define get/set methods for properties for OutputExt if the extension element has attributes. + /** + * This class is an implementation of OutputExt interface that provides java + * model for binding operation output extensibility element. + */ + public static class OutputExtImpl extends AbstractExtensibilityElement implements OutputExt { + + public OutputExtImpl() { + setElementType(QN_OUTPUT_EXT); + } + + /** + * creates and adds the binding operation fault extensibility element to + * the wsdl definition + */ + public static OutputExtImpl addExtensibilityElement(Definition wsdlDef, BindingOutput output) { + OutputExtImpl OutputExt = new OutputExt.OutputExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, output, OutputExt, NS_DEF_PREFIX); + return OutputExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * binding operation output extensibility element. + */ + public static class OutputExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public OutputExtSerializer() { + super(BindingOutput.class, QN_OUTPUT_EXT, OutputExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + OutputExt extObj = (OutputExt) extReg.createExtension(parentType, elementType); + //TODO: set any attributes from the el to extension object + // String myAttr = el.getAttribute(ATTR_MY_ATTR); + // extObj.setMyAttr(myAttr); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + OutputExt extObj = (OutputExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_OUTPUT_EXT); + buff.append("<" + elName); + + //TODO: append any attributes from extension obj to the element + // String myAttr = extObj.getMyAttr(); + // if ( myAttr != null && myAttr.trim().length() > 0 ) { + // buff.append(" myAttr=${symbol_escape}"" + myAttr + "${symbol_escape}""); + // } + // + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/PortExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/PortExt.java new file mode 100644 index 000000000..ca5ce4b09 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/PortExt.java @@ -0,0 +1,217 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * PortExt.java + */ +package net.openesb.component.${artifactId}.wsdlext; + +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.${artifactId}.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for port + * extension element. The inner classes PortExtImpl implements the interface and + * the PortExtSerializer provides the serializer and deserializer implemenation. + * The implementation and serializer classes will be registered with the + * ExtensionRegistry to process the port extension element in the wsdl + * definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface PortExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + + /** + * Getter for property serviceURL. + * + * @return Value of property serviceURL. + */ + public String getServiceURL(); + + /** + * Setter for property serviceURL. + * + * @param serviceURL New value of property serviceURL. + */ + public void setServiceURL(String serviceURL); + + /** + * Getter for property username. + * + * @return Value of property username. + */ + public String getUsername(); + + /** + * Setter for property username. + * + * @param username New value of property username. + */ + public void setUsername(String username); + + /** + * Getter for property password. + * + * @return Value of property password. + */ + public String getPassword(); + + /** + * Setter for property password. + * + * @param password New value of property password. + */ + public void setPassword(String password); + + /** + * Getter for property name. + * + * @return Value of property name. + */ + public String getMBean(); + + /** + * Setter for property mbean. + * + * @param name New value of property mbean. + */ + public void setMBean(String mbean); + + /** + * This class is an implementation of PortExt interface that provides java + * model for port extensibility element. + */ + public static class PortExtImpl + extends AbstractExtensibilityElement implements PortExt { + + private String mServiceURL; + private String mUsername; + private String mPassword; + private String mMBean; + + public PortExtImpl() { + setElementType(QN_PORT_EXT); + } + + public String getServiceURL() { + return this.mServiceURL; + } + + public void setServiceURL(String serviceURL) { + this.mServiceURL = serviceURL; + } + + public String getUsername() { + return this.mUsername; + } + + public void setUsername(String username) { + this.mUsername = username; + } + + public String getPassword() { + return this.mPassword; + } + + public void setPassword(String password) { + this.mPassword = password; + } + + public String getMBean() { + return this.mMBean; + } + + public void setMBean(String mbean) { + this.mMBean = mbean; + } + + /** + * creates and adds the port extensibility element to the wsdl + * definition + */ + public static PortExtImpl addExtensibilityElement(Definition wsdlDef, Port port) { + PortExtImpl portExt = new PortExt.PortExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, port, portExt, NS_DEF_PREFIX); + return portExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * port extensibility element. + */ + public static class PortExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public PortExtSerializer() { + super(Port.class, QN_PORT_EXT, PortExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + PortExt extObj = (PortExt) extReg.createExtension(parentType, elementType); + + String serviceURL = el.getAttribute(ATTR_SERVICE_URL); + extObj.setServiceURL(serviceURL); + + String mbean = el.getAttribute(ATTR_MBEAN); + extObj.setMBean(mbean); + + String username = el.getAttribute(ATTR_USERNAME); + extObj.setUsername(username); + + String password = el.getAttribute(ATTR_PASSWORD); + extObj.setPassword(password); + + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + PortExt extObj = (PortExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_PORT_EXT); + buff.append("<" + elName); + + String serviceURL = extObj.getServiceURL(); + if (serviceURL != null && serviceURL.trim().length() > 0) { + buff.append(" " + ATTR_SERVICE_URL + "=${symbol_escape}"" + serviceURL + "${symbol_escape}""); + } + + String mbean = extObj.getMBean(); + if (mbean != null && mbean.trim().length() > 0) { + buff.append(" " + ATTR_MBEAN + "=${symbol_escape}"" + mbean + "${symbol_escape}""); + } + + String username = extObj.getUsername(); + if (username != null && username.trim().length() > 0) { + buff.append(" " + ATTR_USERNAME + "=${symbol_escape}"" + username + "${symbol_escape}""); + } + + String password = extObj.getUsername(); + if (password != null && password.trim().length() > 0) { + buff.append(" " + ATTR_PASSWORD + "=${symbol_escape}"" + password + "${symbol_escape}""); + } + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtHelper.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtHelper.java new file mode 100644 index 000000000..c73d4e3f6 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtHelper.java @@ -0,0 +1,223 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * WSDLExtHelper.java + */ +package net.openesb.component.${artifactId}.wsdlext; + +import java.util.List; +import javax.wsdl.Binding; +import javax.wsdl.BindingFault; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.xml.namespace.QName; + +/** + * This class is a helper class for processing the wsdl extensions. It has + * methods that help locate the extension elements and return the java models + * corresponds to the extension elements. + * + * @author chikkala + */ +public final class WSDLExtHelper { + + /** + * creates the java object for the port extension element. + * + * @param def wsdl definition + * @param serviceName QName of the service + * @param endpointName name of the port under which to lookup for the port + * extension. + * @return java object for the port extension element + */ + public static PortExt getPortExt(Definition def, QName serviceName, String endpointName) { + PortExt portExt = null; + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + @SuppressWarnings("unchecked") + List extElList = port.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof PortExt) { + portExt = (PortExt) extEl; + break; + } + } + return portExt; + } + + /** + * creates the java object for the binding extension element. + * + * @param def wsdl definition + * @param binding binding under which to lookup for the binding extension. + * @return java object for the port extension element + */ + public static BindingExt getBindingExt(Definition def, Binding binding) { + BindingExt bindingExt = null; + @SuppressWarnings("unchecked") + List extElList = binding.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof BindingExt) { + bindingExt = (BindingExt) extEl; + break; + } + } + return bindingExt; + } + + /** + * creates the java object for the binding extension element. + * + * @param def wsdl definition + * @param serviceName QName of the service + * @param endpointName name of the port that references the binding. + * @return java object for the port extension element + */ + public static BindingExt getBindingExt(Definition def, QName serviceName, String endpointName) { + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + Binding binding = port.getBinding(); + return getBindingExt(def, binding); + } + + /** + * @return OperationExt java object corresponding to the operation extension + * element under binding + */ + public static OperationExt getOperationExt(Definition def, Binding binding, String operation) { + OperationExt operationExt = null; + BindingOperation bindingOp = binding.getBindingOperation(operation, null, null); + if (bindingOp != null) { + @SuppressWarnings("unchecked") + List extElList = bindingOp.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof OperationExt) { + operationExt = (OperationExt) extEl; + break; + } + } + } + return operationExt; + } + + /** + * @return OperationExt java object corresponding to the operation extension + * element under binding + */ + public static OperationExt getOperationExt(Definition def, QName serviceName, String endpointName, String operation) { + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + Binding binding = port.getBinding(); + return getOperationExt(def, binding, operation); + } + + /** + * @return InputExt java object corresponding to input extension element of + * the the binding operation under binding + */ + public static InputExt getInputExt(Definition def, Binding binding, + String operation, String input) { + InputExt inputExt = null; + BindingOperation bindingOp = binding.getBindingOperation(operation, input, null); + if (bindingOp != null) { + BindingInput bindingInput = bindingOp.getBindingInput(); + @SuppressWarnings("unchecked") + List extElList = bindingInput.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof InputExt) { + inputExt = (InputExt) extEl; + break; + } + } + } + return inputExt; + } + + /** + * @return InputExt java object corresponding to input extension element of + * the the binding operation under binding + */ + public static InputExt getInputExt(Definition def, + QName serviceName, String endpointName, String operation, String input) { + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + Binding binding = port.getBinding(); + return getInputExt(def, binding, operation, input); + } + + /** + * @return OutputExt java object corresponding to output extension element + * of the the binding operation under binding + */ + public static OutputExt getOutputExt(Definition def, Binding binding, + String operation, String output) { + OutputExt outputExt = null; + BindingOperation bindingOp = binding.getBindingOperation(operation, null, output); + if (bindingOp != null) { + BindingOutput bindingOutput = bindingOp.getBindingOutput(); + @SuppressWarnings("unchecked") + List extElList = bindingOutput.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof OutputExt) { + outputExt = (OutputExt) extEl; + break; + } + } + } + return outputExt; + } + + /** + * @return OutputExt java object corresponding to output extension element + * of the the binding operation under binding + */ + public static OutputExt getOutputExt(Definition def, + QName serviceName, String endpointName, String operation, String output) { + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + Binding binding = port.getBinding(); + return getOutputExt(def, binding, operation, output); + } + + /** + * @return FaultExt java object corresponding to fault extension element of + * the the binding operation under binding + */ + public static FaultExt getFaultExt(Definition def, Binding binding, + String operation, String faultName) { + FaultExt faultExt = null; + BindingOperation bindingOp = binding.getBindingOperation(operation, null, null); + if (bindingOp != null) { + BindingFault bindingFault = bindingOp.getBindingFault(faultName); + if (bindingFault != null) { + @SuppressWarnings("unchecked") + List extElList = bindingFault.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof FaultExt) { + faultExt = (FaultExt) extEl; + break; + } + } + } + } + return faultExt; + } + + /** + * @return FaultExt java object corresponding to fault extension element of + * the the binding operation under binding + */ + public static FaultExt getFaultExt(Definition def, + QName serviceName, String endpointName, String operation, String faultName) { + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + Binding binding = port.getBinding(); + return getFaultExt(def, binding, operation, faultName); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtension.xsd b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtension.xsd new file mode 100644 index 000000000..1311a03c9 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtension.xsd @@ -0,0 +1,98 @@ + + + + + + + + + "binding" defines a protocol based binding details. + + + + + + + + + + + + + + "operation" defines the protocol based binding operation details. + + + + + + + + + + + + + + + "input" defines the protocol based binding input details. + + + + + + + + + + + + + + "output" defines the protocol based binding output details. + + + + + + + + + + + + + + "fault" defines the protocol based binding fault details. + + + + + + + + + + + + + + "address" indicates protocol based binding port details. + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtensionRegistry.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtensionRegistry.java new file mode 100644 index 000000000..36154acfb --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/src/java/net/openesb/component/cname/wsdlext/WSDLExtensionRegistry.java @@ -0,0 +1,46 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * WSDLExtensionRegistry.java + */ +package net.openesb.component.${artifactId}.wsdlext; + +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensionRegistry; +import net.openesb.component.${artifactId}.common.wsdl.AbstractExtensionSerializer; +import java.util.ArrayList; +import java.util.List; + +/** + * This class extends + * AbstractExtensionRegistry to create the serializers and deserializers + * for processing wsdl extensions. + * + * @see AbstractExtensionRegistry + * @author chikkala + */ +public class WSDLExtensionRegistry extends AbstractExtensionRegistry { + + /** + * Creates a new instance of JMXBindingExtensionRegistry + */ + public WSDLExtensionRegistry() { + super(); + } + + /** + * creates serializers and deserializers for all the extension elements + */ + protected List createSerializers() { + List list = new ArrayList(); + + list.add(new BindingExt.BindingExtSerializer()); + list.add(new OperationExt.OperationExtSerializer()); + list.add(new InputExt.InputExtSerializer()); + list.add(new OutputExt.OutputExtSerializer()); + list.add(new FaultExt.FaultExtSerializer()); + list.add(new PortExt.PortExtSerializer()); + + return list; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/bindingtest/BindingComponentTest.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/bindingtest/BindingComponentTest.java new file mode 100644 index 000000000..defb6afd4 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/bindingtest/BindingComponentTest.java @@ -0,0 +1,55 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * ${artifactId}Test.java + */ +package bindingtest; +import net.openesb.component.${artifactId}.test.JBIComponentTestClient; +import net.openesb.component.${artifactId}.test.JMXBindingTestClient; +import java.util.Properties; + import junit.framework.TestCase; + +/** + * The test method in this testcase uses the JMXBindingTestClient to send the + * input document to the echo service provided by service engine via the binding + * component by sending the input to the binding using jmx interface. The output + * received from the service invocation will be placed in test results directory + * under the same package as this test case. + * @see com.sun.jbi.sample.component.test.JMXBindingTestClinet + * + * @author chikkala + */ +public class BindingComponentTest + extends TestCase +{ + + public BindingComponentTest(String testName) { + super(testName); + } + + public void test1() throws Exception { + String testPropertiesPath = "test1.properties"; + JBIComponentTestClient testClient = new JMXBindingTestClient(); + Properties testProps = testClient.loadTestProperties(this.getClass(), testPropertiesPath); + testClient.testService(testProps); + } + + public void test2() throws Exception { + String testPropertiesPath = "test2.properties"; + JBIComponentTestClient testClient = new JMXBindingTestClient(); + Properties testProps = testClient.loadTestProperties(this.getClass(), testPropertiesPath); + testClient.testService(testProps); + } + + public static void main(String[] args) { + try { + BindingComponentTest compTest = new BindingComponentTest("BindingComponentTest"); + compTest.test1(); + compTest.test2(); + } catch(Exception ex) { + ex.printStackTrace(); + } + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/bindingtest/test1.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/bindingtest/test1.properties new file mode 100644 index 000000000..02707a88a --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/bindingtest/test1.properties @@ -0,0 +1,16 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} Sample ResourceBundle properties file + +${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} test properties for testing the binding component +input.file=test1Input.xml +${symbol_pound}exptected.file=Expected.xml +output.file=test1Output.xml + +consumer.jmx.bc.ep.operation=sayHello +consumer.jmx.bc.ep.address.mbean=com.sun.jbi.sample.jmxbc:jmxbc-ep-address=BindingComponent/greetings +consumer.jmx.bc.ep.address.serviceURL=service:jmx:rmi:///jndi/rmi://localhost:8686/jmxrmi +consumer.jmx.bc.ep.address.username=admin +consumer.jmx.bc.ep.address.password=this really long string is used to identify a password that has been stored in the Keyring + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/bindingtest/test1Input.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/bindingtest/test1Input.xml new file mode 100644 index 000000000..ac1004c3e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/bindingtest/test1Input.xml @@ -0,0 +1,12 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + Srinivasan + Chikkala + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/bindingtest/test2.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/bindingtest/test2.properties new file mode 100644 index 000000000..4921dee72 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/bindingtest/test2.properties @@ -0,0 +1,15 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} Sample ResourceBundle properties file + +${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} test properties for testing the binding component +input.file=test2Input.xml +${symbol_pound}exptected.file=Expected.xml +output.file=test2Output.xml + +consumer.jmx.bc.ep.operation=sayGoodbye +consumer.jmx.bc.ep.address.mbean=com.sun.jbi.sample.jmxbc:jmxbc-ep-address=BindingComponent/greetings +consumer.jmx.bc.ep.address.serviceURL=service:jmx:rmi:///jndi/rmi://localhost:8686/jmxrmi +consumer.jmx.bc.ep.address.username=admin +consumer.jmx.bc.ep.address.password=this really long string is used to identify a password that has been stored in the Keyring diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/bindingtest/test2Input.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/bindingtest/test2Input.xml new file mode 100644 index 000000000..31058414d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/bindingtest/test2Input.xml @@ -0,0 +1,12 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + Srinivasan + Chikkala + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java new file mode 100644 index 000000000..919ad6829 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java @@ -0,0 +1,298 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JBIComponentTestClient.java + */ + +package net.openesb.component.${artifactId}.test; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Properties; + +/** + * This class implements the base framework for the testing the JBI components. + * Testing the JBI component involves may require deploying a service to the + * component(s) to enable the service provided by the test component and then + * invoking the service provided by the test component. If the test component is + * a binding component, then a service provider component such as sample service + * engine is required to test the component end to end. If the test component is a + * service engine, then the service on the test component can be invoked via + * soap/http binding component. + * + * This class provides the utilites to read the test properties, read the input + * message from the file and save the output to the file. The testService + * method implemented here can be executed as the test for the component. The + * testService method calls the invokeService method with the input document and + * expects a output document or error that will be saved to the output file. + * The method invokeService should be implemented by the extended test classes to + * inplement a suitable service consumer implemenation for the test compoent. + * See JMXBindingTestClient.java or SOAPBidningTestClient.java for more details + * on how to implement a partucular test service consumer. + * + * @author chikkala + */ +public abstract class JBIComponentTestClient { + + public static final String TEST_PROPS_FILE_PROP = "test.properties.file"; + public static final String TEST_RESULTS_DIR_PROP = "test.results.dir"; + public static final String TEST_SRC_DIR_PROP = "test.src.dir"; + + public static final String TEST_PACKAGE_PROP = "test.package.name"; + + public static final String INPUT_FILE_PROP = "input.file"; + public static final String EXPECTED_FILE_PROP = "expected.file"; + public static final String OUTPUT_FILE_PROP = "output.file"; + + public static final String DEF_TEST_PROP_FILE = "test.properties"; + public static final String DEF_INPUT_FILE = "Input.xml"; + public static final String DEF_OUTPUT_FILE = "Output.xml"; + public static final String DEF_TEST_RESULTS_DIR = "test-results"; + + public JBIComponentTestClient() { + } + /** + * returns the absolute resource path w.r.t. the packagePath if the resource name + * is relative else return the resourceName as it is. + * @param package name ( dot separated ) + * @param resourcName dot separated name or a absolute resource path + * @return abosolute resource path with path separator + */ + public static String resolveResourcePath(String packageName, String resourceName) { + String resourcePath = resourceName; + if ( !resourceName.startsWith("/")) { + // it is relative resource file. resolve it w.r.t. testPackage + String pkgDir = packageName.trim().replace('.', '/'); + if ( pkgDir.length() != 0 ) { + pkgDir += "/"; + } + resourcePath = "/" + pkgDir + resourceName; + } + return resourcePath; + } + /** + * loads the resource file as properties. + * @param testPackage package name where this test belongs + * @param testPropPath resource path relative to testPackage or absolute resource path + */ + public Properties loadTestProperties(String testPackage, String testPropPath) throws IOException { + String propsResourcePath = resolveResourcePath(testPackage, testPropPath); + + InputStream testPropIS = null; + try { + testPropIS = this.getClass().getResourceAsStream(propsResourcePath); + Properties testProps = new Properties(); + testProps.load(testPropIS); + testProps.setProperty(TEST_PACKAGE_PROP, testPackage); + return testProps; + } finally { + if ( testPropIS != null ) { + try { + testPropIS.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + } + /** + * load default test properties file in the testClass package. + * @param testClass Class where to look for the default test properties + * @param testPropPath resource path relative to testPackage or absolute resource path + * @return Properties test properties + */ + public Properties loadTestProperties(Class testClass, String testPropPath) throws IOException { + return loadTestProperties(testClass.getPackage().getName(), testPropPath ); + } + /** + * load default test properties file in the testClass package. + * @param testClass Class where to look for the default test properties + * @return Properties test properties + */ + public Properties loadTestProperties(Class testClass) throws IOException { + return loadTestProperties(testClass.getPackage().getName(), DEF_TEST_PROP_FILE ); + } + /** + * loads the resource file to string bugger + * @param inputFile resource file path + */ + public StringBuffer loadResourceFile(String resourcePath) throws FileNotFoundException, IOException { + + InputStream inputIS = null; + InputStreamReader inputReader = null; + BufferedReader reader = null; + StringWriter strWriter = null; + PrintWriter writer = null; + try { + inputIS = this.getClass().getResourceAsStream(resourcePath); + inputReader = new InputStreamReader(inputIS); + reader = new BufferedReader(inputReader); + strWriter = new StringWriter(); + writer = new PrintWriter(strWriter); + for ( String line = null; (line = reader.readLine()) != null ; ) { + writer.println(line); + } + writer.close(); + strWriter.close(); + return strWriter.getBuffer(); + } finally { + if ( inputIS != null ) { + try { + inputIS.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + } + + /** + * reads data from the reader and saves to file + * @param reader reader from which to read the data and save to file + * @param outputFilePath absolute file path + */ + public void saveOutputToFile(Reader reader, String outputFilePath) throws IOException { + + BufferedReader buff = null; + FileWriter fileWriter = null; + PrintWriter writer = null; + try { + buff = new BufferedReader(reader); + fileWriter = new FileWriter(outputFilePath); + writer = new PrintWriter(fileWriter); + for ( String line = null; (line = buff.readLine()) != null ; ) { + writer.println(line); + } + } finally { + if ( writer != null ) { + writer.close(); + } + if ( fileWriter != null ) { + fileWriter.close(); + } + } + } + + /** + * resource path. + */ + public String getInputFileResourcePath(Properties testProps) { + + String testPkg = testProps.getProperty(TEST_PACKAGE_PROP, ""); + String inputFile = testProps.getProperty(INPUT_FILE_PROP, DEF_INPUT_FILE); + String resourcePath = resolveResourcePath(testPkg, inputFile); + return resourcePath; + } + /** + * return resource path + */ + public String getExpectedFileResourcePath(Properties testProps) { + + String testPkg = testProps.getProperty(TEST_PACKAGE_PROP, ""); + String resourcePath = null; + String expFile = testProps.getProperty(EXPECTED_FILE_PROP, null); + if ( expFile != null ) { + resourcePath = resolveResourcePath(testPkg, expFile); + } + return resourcePath; + } + /** + * return the absolute path to the output file + */ + public String getOutputFilePath(Properties testProps) { + + String defPackage = this.getClass().getPackage().getName(); + String testPackage = testProps.getProperty(TEST_PACKAGE_PROP, defPackage); + String testPackageDir = testPackage.replace('.','/'); + String outputFile = testProps.getProperty(OUTPUT_FILE_PROP, DEF_OUTPUT_FILE); + + String userHomeDir = System.getProperty("user.home", ""); + String userDir = System.getProperty("user.dir", userHomeDir); + String defResultsDir = userDir + "/" + DEF_TEST_RESULTS_DIR; + String sysResultDir = System.getProperty(TEST_RESULTS_DIR_PROP, defResultsDir); + String resultDir = testProps.getProperty(TEST_RESULTS_DIR_PROP, sysResultDir); + + File outputDir = new File(resultDir, testPackageDir); + // System.out.println("Creating the test results output dir " + outputDir); + outputDir.mkdirs(); + return (new File(outputDir, outputFile)).getAbsolutePath(); + } + + /** + * This is the method where the actual service invocation code based on the + * type of client will be implemented. testService method calls this method + * after preparing the test input and then processes the output returned by + * this method to complte the test. + * @param inputDoc + * @param testProps + * @throws java.lang.Exception + * @return + */ + public abstract StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception; + + /** + * abstract method implemented by the extended classes to compare the output + * document with the expected output to determine the test is a failure or + * success. + * @param outputDoc + * @param expectedDoc + * @param testProps + * @throws java.lang.Exception + */ + public abstract void compareWithExpectedOutput(StringBuffer outputDoc, + StringBuffer expectedDoc, Properties testProps) throws Exception; + + /** + * This is the main test method that a test case will call to test the + * service. The standard steps that required to invoke the service and + * process the output will be done in this method. Each test case creates + * the test Properties required for that test and executes this method for + * testing the service by passing the test properties to it. This method + * prepares the input and executes the invokeService method to invoke a + * service with the prepared input. It then processes the return value from + * the invokeService to complete the test. + * + * @param testProps + * @throws java.lang.Exception + */ + public void testService(Properties testProps) throws Exception { + + String inFilePath = getInputFileResourcePath(testProps); + String outFilePath = getOutputFilePath(testProps); + String expFilePath = getExpectedFileResourcePath(testProps); + File outDir = (new File(outFilePath)).getParentFile(); + outDir.mkdirs(); + + StringBuffer outputDoc = new StringBuffer(); + + try { + StringBuffer inputDoc = loadResourceFile(inFilePath); + outputDoc = invokeService(inputDoc, testProps); + if ( expFilePath != null ) { + StringBuffer expOutputDoc = loadResourceFile(expFilePath); + compareWithExpectedOutput(inputDoc, expOutputDoc, testProps); + } + } catch (Exception ex) { + StringWriter out = new StringWriter(); + ex.printStackTrace(new PrintWriter(out)); + outputDoc.append(out.getBuffer()); + throw ex; + } finally { + if ( outputDoc != null ) { + System.out.println(outputDoc); + this.saveOutputToFile(new StringReader(outputDoc.toString()), outFilePath); + } + } + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java new file mode 100644 index 000000000..7cc8c103e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java @@ -0,0 +1,136 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * JMXBindingTestClient.java + */ + +package net.openesb.component.${artifactId}.test; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanException; +import javax.management.MBeanServerConnection; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.management.ReflectionException; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; + +/** + * This class extends the JBIComponentTestClient and implements the invokeService + * method to test the proxy service consumer implementation by a binding component + * that can communicate with the external service consumers using JMX interface. + * @author chikkala + */ +public class JMXBindingTestClient extends JBIComponentTestClient { + + public static final String CONSUMER_EP_INBOUND_OPERATION_PROP = "consumer.jmx.bc.ep.operation"; + public static final String CONSUMER_EP_ADDRESS_MBEAN_PROP = "consumer.jmx.bc.ep.address.mbean"; + public static final String CONSUMER_EP_ADDRESS_URL_PROP = "consumer.jmx.bc.ep.address.serviceURL"; + public static final String CONSUMER_EP_ADDRESS_USERNAME_PROP = "consumer.jmx.bc.ep.address.username"; + public static final String CONSUMER_EP_ADDRESS_PASSWORD_PROP = "consumer.jmx.bc.ep.address.password"; + + public static final String PROVIDER_EP_INBOUND_OPERATION_PROP = "provider.jmx.bc.ep.operation"; + public static final String PROVIDER_EP_ADDRESS_MBEAN_PROP = "provider.jmx.bc.ep.address.mbean"; + public static final String PROVIDER_EP_ADDRESS_URL_PROP = "provider.jmx.bc.ep.address.serviceURL"; + public static final String PROVIDER_EP_ADDRESS_USERNAME_PROP = "provider.jmx.bc.ep.address.username"; + public static final String PROVIDER_EP_ADDRESS_PASSWORD_PROP = "provider.jmx.bc.ep.address.password"; + + + /** + * Creates a new instance of JMXBindingTestClient + */ + public JMXBindingTestClient() { + super(); + } + /** + * creates jmx connection to send the input message to the binding component. + */ + public static MBeanServerConnection getJMXConnection(Properties testProps) + throws MalformedURLException, IOException { + + String jmxUrl = testProps.getProperty(CONSUMER_EP_ADDRESS_URL_PROP); + String username = testProps.getProperty(CONSUMER_EP_ADDRESS_USERNAME_PROP); + String password = testProps.getProperty(CONSUMER_EP_ADDRESS_PASSWORD_PROP); + + Map env = new HashMap(); + if ( username != null ) { + String [] credentials = new String [] {username, password}; + env.put("jmx.remote.credentials", credentials); + env.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, JMXBindingTestClient.class.getClassLoader()); + } + JMXServiceURL serviceURL = new JMXServiceURL(jmxUrl); + JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, env); + MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection(); + return mbeanServerConnection; + } + /** + * constructs the jmx mbean objectname + */ + public static ObjectName createJMXEndpointMBeanObjectName(String endpointAddressMBean) throws MalformedObjectNameException { + // String objectName = JMX_DOMAIN + ":" + JMX_ENDPOINT_ADDRESS_KEY + "=" + endpointAddressMBean; + return new ObjectName(endpointAddressMBean); + } + /** + * invokes a jmx mbean to send message. + */ + public static StringBuffer invokeSendMessage(MBeanServerConnection jmxConn, ObjectName epAddressName, + String operation, StringBuffer inputDoc) + throws MalformedObjectNameException, InstanceNotFoundException, + MBeanException, ReflectionException, IOException { + StringBuffer outDoc = null; + + Object result = null; + String mbeanOperation = "sendMessage"; + + Object[] params = new Object[2]; + params[0] = operation; + params[1] = inputDoc; + + String[] signature = new String[2]; + signature[0] = "java.lang.String"; + signature[1] = "java.lang.StringBuffer"; + + result = jmxConn.invoke(epAddressName, mbeanOperation, params, signature); + if ( result != null ) { + outDoc = (StringBuffer)result; + } + + return outDoc; + } + /** + * invokes the service via jmx interface. + */ + public StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception { + + ObjectName epAddressName = new ObjectName(testProps.getProperty(CONSUMER_EP_ADDRESS_MBEAN_PROP)); + String operation = testProps.getProperty(CONSUMER_EP_INBOUND_OPERATION_PROP); + + MBeanServerConnection jmxConn = getJMXConnection(testProps); + StringBuffer outputDoc = null; + try { + outputDoc = invokeSendMessage(jmxConn, epAddressName, operation, inputDoc); + } catch (MBeanException ex) { + Exception targetEx = ex.getTargetException(); + if ( targetEx != null ) { + throw targetEx; + } else { + throw ex; + } + } + return outputDoc; + } + /** no expected output comparison implemented */ + public void compareWithExpectedOutput(StringBuffer inputDoc, + StringBuffer expectedDoc, + Properties testProps) throws Exception { + // throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java new file mode 100644 index 000000000..28f534612 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java @@ -0,0 +1,159 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * SOAPBindingTestClient.java + */ + +package net.openesb.component.${artifactId}.test; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Properties; +import javax.xml.soap.MessageFactory; +import javax.xml.soap.MimeHeaders; +import javax.xml.soap.SOAPConnection; +import javax.xml.soap.SOAPConnectionFactory; +import javax.xml.soap.SOAPException; +import javax.xml.soap.SOAPFault; +import javax.xml.soap.SOAPMessage; +import javax.xml.soap.SOAPPart; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +/** + * This class extends the JBIComponentTestClient and implements the invokeService + * method to test the Service Engine via SOAP Binding by invoking the service using + * SOAP Client that sends the message to the service provider via soaphttp binding. + * + * @author chikkala + */ +public class SOAPBindingTestClient extends JBIComponentTestClient { + + private static final String ADDRESS_PROP = "soap.binding.inbound.endpoint.address.location"; + private static final String SOAP_ACTION_PROP = "soap.binding.soapaction"; + private static final String FAIL_ON_SOAP_FAULT_PROP = "fail.on.soap.fault"; + + private static MessageFactory messageFactory; + private static SOAPConnectionFactory soapConnFactory; + private static SOAPConnection connection; + + public SOAPBindingTestClient() throws SOAPException { + init(); + } + /** initializes SOAP client */ + private synchronized void init() throws SOAPException { + if ( messageFactory == null ) { + messageFactory = MessageFactory.newInstance(); + } + if ( soapConnFactory == null ) { + soapConnFactory = SOAPConnectionFactory.newInstance(); + } + if ( connection == null ) { + connection = soapConnFactory.createConnection(); + } + } + + /** + * read in a soap message from the given input file + */ + private static SOAPMessage loadMessage(Reader inReader) throws SOAPException, IOException { + //Create and populate the message from a file + SOAPMessage message = messageFactory.createMessage(); + SOAPPart soapPart = message.getSOAPPart(); + StreamSource preppedMsgSrc = new StreamSource(inReader); + soapPart.setContent(preppedMsgSrc); + message.saveChanges(); + return message; + } + /** saves the SOAP message as xml text to a writer */ + private static void saveMessage(SOAPMessage response, Writer outWriter) + throws TransformerConfigurationException, SOAPException, TransformerException { + + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + transformerFactory.setAttribute("indent-number", new Integer(2)); + Transformer transformer = transformerFactory.newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + + SOAPPart replySOAPPart = response.getSOAPPart(); + Source sourceContent = replySOAPPart.getContent(); + StreamResult result = new StreamResult(outWriter); + try { + transformer.transform(sourceContent, result); + } catch (TransformerException ex) { + ex.printStackTrace(); + } + } + /** + * Send a soap message + * @param destination URL to send to + * @param message message to send + * @param expectedHttpStatus expected http status code or null if success is expected + * @return reply soap message + */ + private static SOAPMessage sendMessage(String destination, SOAPMessage message, String soapAction) throws SOAPException { + + // Add soapAction if not null + if (soapAction != null) { + MimeHeaders hd = message.getMimeHeaders(); + hd.setHeader("SOAPAction", soapAction); + } + // Send the message and get a reply + SOAPMessage reply = null; + reply = connection.call(message, destination); + return reply; + } + /** check the xml text in the StringBuffer passed contains SOAP Fault. */ + public boolean isSOAPFault(StringBuffer msgBuff) { + SOAPFault soapFault = null; + try { + SOAPMessage inMsg = loadMessage(new StringReader(msgBuff.toString())); + soapFault = inMsg.getSOAPBody().getFault(); + } catch (Exception ex) { + // any exception, means either no fault elem or invalid xml + } + return (soapFault != null); + } + /** + * invokes the service ny sending the input message and return the output + * message returned by the service. + */ + public StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception { + + String soapAction = testProps.getProperty(SOAP_ACTION_PROP); + String destination = testProps.getProperty(ADDRESS_PROP); + SOAPMessage inMsg = loadMessage(new StringReader(inputDoc.toString())); + SOAPMessage outMsg = sendMessage(destination, inMsg, soapAction); + StringWriter out = new StringWriter(); + saveMessage(outMsg, out); + StringBuffer outDoc = out.getBuffer(); + Boolean failOnSoapFault = Boolean.valueOf(testProps.getProperty(FAIL_ON_SOAP_FAULT_PROP, "false")); + if ( failOnSoapFault ) { + if (isSOAPFault(outDoc)) { + StringBuffer errBuff = new StringBuffer("${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} SOAP FAULT ${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound}${symbol_pound} ${symbol_escape}n"); + errBuff.append(outDoc); + throw new Exception(errBuff.toString()); + } + } + return outDoc; + } + /** comparing the received output document with the expected document. throw + * exception if the docs are not same. throwing the exception in this method + * fails the test. + */ + public void compareWithExpectedOutput(StringBuffer outputDoc, + StringBuffer expectedDoc, + Properties testProps) throws Exception { + // throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/build.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/build.properties new file mode 100644 index 000000000..945269943 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/build.properties @@ -0,0 +1,22 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} Build properties for the service assembly builds +${symbol_pound} user.properties.file=../../user.properties +src.dir=src +${symbol_pound} This directory is removed when the project is cleaned: +build.dir=build +service.assembly.name=testSA + +${symbol_pound}no.deps=true set the no.deps property if there are no SUs to build +${symbol_pound} for each testSU define the properties here. +${symbol_pound} dependent BC SU projects dependency +${symbol_pound} service unit name +service.unit.name.testSUBC=testSUBC +${symbol_pound} service unit project directory +project.testSUBC=testSUBC + +${symbol_pound} service unit name +service.unit.name.testSUSE=testSUSE +${symbol_pound} service unit project directory +project.testSUSE=testSUSE diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/build.xml new file mode 100644 index 000000000..02f75e641 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/build.xml @@ -0,0 +1,140 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.assembly.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/src/META-INF/jbi.xml new file mode 100644 index 000000000..3ced1c59e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/src/META-INF/jbi.xml @@ -0,0 +1,44 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + ${artifactId}_TestSA + This is a test Service Assembly to test Binding + + + + + ${artifactId}_TestSUBC + This service unit enables inbound endpoint in the JMXBinding for a service in service engine + + + testSUBC.zip + ${artifactId} + + + + + ${artifactId}_TestSUSE + This service unit enables greetings service provider in the service engine + + + testSUSE.zip + ServiceEngine + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUBC/build.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUBC/build.properties new file mode 100644 index 000000000..caaefb87b --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUBC/build.properties @@ -0,0 +1,10 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} Build properties for the service unit builds +src.dir=src +${symbol_pound} This directory is removed when the project is cleaned: +${symbol_pound}build.dir=../../../build/test/testSU/build +build.dir=build +service.unit.name=testSUBC + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUBC/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUBC/build.xml new file mode 100644 index 000000000..777fb3cf9 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUBC/build.xml @@ -0,0 +1,74 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUBC/src/Greetings.wsdl b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUBC/src/Greetings.wsdl new file mode 100644 index 000000000..cf1d4ccc3 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUBC/src/Greetings.wsdl @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml new file mode 100644 index 000000000..112a9decb --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUBC/src/META-INF/jbi.xml @@ -0,0 +1,17 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/build.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/build.properties new file mode 100644 index 000000000..1bfd81c69 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/build.properties @@ -0,0 +1,10 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} Build properties for the service unit builds +src.dir=src +${symbol_pound} This directory is removed when the project is cleaned: +${symbol_pound}build.dir=../../../build/test/testSU/build +build.dir=build +service.unit.name=testSUSE + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/build.xml new file mode 100644 index 000000000..846415d3a --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/build.xml @@ -0,0 +1,74 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/Greetings.wsdl b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/Greetings.wsdl new file mode 100644 index 000000000..9c6322558 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/Greetings.wsdl @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml new file mode 100644 index 000000000..e1edc9a96 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/META-INF/jbi.xml @@ -0,0 +1,17 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/goodbye.xsl b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/goodbye.xsl new file mode 100644 index 000000000..c60e39b73 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/goodbye.xsl @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + Goodbye ! Have a great time. + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/hello.xsl b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/hello.xsl new file mode 100644 index 000000000..994b66f98 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/hello.xsl @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + Hello ! + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/xsltmap.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/xsltmap.properties new file mode 100644 index 000000000..44baf5452 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/classes/archetype-resources/test/testSA/testSUSE/src/xsltmap.properties @@ -0,0 +1,31 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +${symbol_pound} properties will be used to find the xslt file that will be used for invoking a +${symbol_pound} service operation. +${symbol_pound} The "xsltmap.properties" file should contain two types of properties +${symbol_pound} 1. for namespace prefix to namespaceURI map that starts with "xmlns." prefix like +${symbol_pound} "xmlns.tns-prefix=http://www.sun.com/jbi/examples/sample-service/echo" +${symbol_pound} 2. a service description to xslt file properties with syntax like +${symbol_pound} "{tns-prefix}service-name=xslt_file_name" and +${symbol_pound} "{tns-prefix}service-name.{tns-prefix}operation-name=xslt_file_name" and +${symbol_pound} "{tns-prefix}service-name.{tns-prefix}interface-name.operation-name=xslt_file_name" . +${symbol_pound} the service description property is a "." delimited tokens that represents +${symbol_pound} a serive or interface qname and a operation name. To locate xslt file either with +${symbol_pound} service qname or service qname and operaton or serivice qname and interface qname +${symbol_pound} and operation, all the three properties specified above should be there for each xslt file. +${symbol_pound} + +xmlns.greet1=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greet2=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greettypes=http://www.sun.com/jbi/examples/sample-service/greetings/types +${symbol_pound} just service level default settings +{greet2}greetService=hello.xsl +${symbol_pound} service and operation +{greet2}greetService.{greet1}sayHello=hello.xsl +${symbol_pound} service, interface, operation +{greet2}greetService.{greet1}greetings.sayHello=hello.xsl +${symbol_pound} service and operation +{greet2}greetService.{greet1}sayGoodbye=goodbye.xsl +${symbol_pound} service, interface, operation +{greet2}greetService.{greet1}greetings.sayGoodbye=goodbye.xsl diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/archetype.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/archetype.properties new file mode 100644 index 000000000..cdd05f905 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/archetype.properties @@ -0,0 +1,6 @@ +#Tue Jul 30 12:43:25 IST 2013 +package=it.pkg +version=0.1-SNAPSHOT +groupId=archetype.it +artifactId=BindingComponent-archetype +glassfishLocation=C:\\GlassFishESBv22\\glassfish \ No newline at end of file diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/goal.txt b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/goal.txt new file mode 100644 index 000000000..e69de29bb diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/build.log b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/build.log new file mode 100644 index 000000000..e69de29bb diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/build.xml new file mode 100644 index 000000000..8fc9afb3b --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/build.xml @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project BindingComponent-archetype. + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/m2nbbuild-impl.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/m2nbbuild-impl.xml new file mode 100644 index 000000000..5c4fb1097 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/m2nbbuild-impl.xml @@ -0,0 +1,127 @@ + + + + + This project compile, package and test the JBI Components when invoked from Maven2. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/m2nbbuild.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/m2nbbuild.properties new file mode 100644 index 000000000..5bab5aa6b --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/m2nbbuild.properties @@ -0,0 +1,45 @@ +# build properties file to set/override the properties of the netbeans project +# build properties when the netbeans build is called from the maven build lifecycle. +# Netbeans project when build from the IDE, uses a build.properties from the user.dir +# of the Netbeans IDE to resolve some of the properties used in the project such as +# the libraries classpath. +# When invoking the Netbeans project build from maven, this build.properties file +# is not available. So, you can add the properties defined in ide build properties +# that this project uses here. +# + +# default local repository settings. If the repository location is different +# -D command line option should override this (e.g. mvn -Dmaven.repo.local=/my/m2/repository +maven.repo.local=${user.home}/.m2/repository +# begin jbi admin settings +# set the below properties if you want to override the properties from nbproject/project.properties +# that sets the application server admin settings. +# +# jbi.as.home=C:/Sun/glassfish-v2-b58g +# jbi.host=localhost +# jbi.port=4848 +# jbi.username=admin +# jbi.password=adminadmin +# end jbi admin settings +# + +# classpath settings +junit.ant.task.classpath=${maven.repo.local}/ant/ant-junit/1.6.5/ant-junit-1.6.5.jar +junit.runtime.classpath=${maven.repo.local}/junit/junit/3.8.2/junit-3.8.2.jar +libs.junit.classpath=${junit.runtime.classpath}:${junit.ant.task.classpath} +libs.jbi-cdk-ant-tasks.classpath=${maven.repo.local}/open-esb/jbi-cdk/jbi-cdk-ant-tasks/0.1-SNAPSHOT/jbi-cdk-ant-tasks-0.1-SNAPSHOT.jar + +libs.jbi.classpath=${maven.repo.local}/open-esb/jbi/1.0/jbi-1.0.jar +libs.wsdl4j.162.classpath=${maven.repo.local}/wsdl4j/wsdl4j/1.6.2/wsdl4j-1.6.2.jar +# libs.jaxws21.classpath=${jbi.as.home}/lib/javaee.jar:${jbi.as.home}/lib/webservices-rt.jar +libs.jaxws21.classpath=\ +${maven.repo.local}/javax/activation/activation/1.1/activation-1.1.jar:\ +${maven.repo.local}/javax/xml/soap/saaj-api/1.3/saaj-api-1.3.jar:\ +${maven.repo.local}/javax/xml/ws/jaxws-api/2.1/jaxws-api-2.1.jar:\ +${maven.repo.local}/com/sun/xml/messaging/saaj/saaj-impl/1.3/saaj-impl-1.3.jar:\ +${maven.repo.local}/com/sun/xml/ws/jaxws-rt/2.1.2/jaxws-rt-2.1.2.jar + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/m2nbbuild.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/m2nbbuild.xml new file mode 100644 index 000000000..6557242cf --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/m2nbbuild.xml @@ -0,0 +1,34 @@ + + + + + + This project compile, package and test the JBI Components when invoked from Maven2. + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/build-impl.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/build-impl.xml new file mode 100644 index 000000000..7458ae806 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/build-impl.xml @@ -0,0 +1,554 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Inside: postArchTypeGen - Post task is getting executed! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Inside: postArchTypeGen - Post task executed successfully! + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/genfiles.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/genfiles.properties new file mode 100644 index 000000000..d36e5a48b --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=f37ab647 +build.xml.script.CRC32=9068f2c7 +build.xml.stylesheet.CRC32=8add101f@1.0 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=f37ab647 +nbproject/build-impl.xml.script.CRC32=d15987fd +nbproject/build-impl.xml.stylesheet.CRC32=4ed53ee0@1.0 diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/jbi_admin.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/jbi_admin.xml new file mode 100644 index 000000000..623507a02 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/jbi_admin.xml @@ -0,0 +1,501 @@ + + + + + +This ant script contains the jbi ant tasks and the targets and properties using +which the jbi admin commands can be performed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Usage : ant -f <fullpath>/jbi_admin.xml [options] [target] + options: -D<property>=<value> + Specify a property/value pairs as options that are valid for the target. + target : ant target name in jbi_admin.xml + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/jbiadmin-impl.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/jbiadmin-impl.xml new file mode 100644 index 000000000..cde39fb8b --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/jbiadmin-impl.xml @@ -0,0 +1,336 @@ + + + Install, uninstall, reinstall, start, stop, shutdown jbi components. + + + + + + + + + + + + + + Must set jbi.host + Must set jbi.port + Must set jbi.username + Must set jbi.password + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/private/private.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/private/private.properties new file mode 100644 index 000000000..f4fdfea51 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/private/private.properties @@ -0,0 +1,3 @@ +javac.debug=true +javadoc.preview=true +user.properties.file=D:\\softwares\\openesb_logicoy_last_working57\\.netbeans\\openesb\\build.properties diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/project.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/project.properties new file mode 100644 index 000000000..f3c08640d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/project.properties @@ -0,0 +1,90 @@ +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.predist.dir=${build.dir}/predist +build.predist.jar=${build.predist.dir}/component.jar +build.predist.lib.dir=${build.predist.dir}/lib +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.dir=${build.dir}/test +build.test.results.dir=${build.dir}/test/results +conf.dir=src/conf +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/BindingComponent-archetype.zip +dist.javadoc.dir=${dist.dir}/javadoc +jar.compress=false +javac.classpath=\ + ${libs.jbi.classpath}:\ + ${jbi.component.sharedlibs.classpath}:\ + ${jbi.component.lib.classpath} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.6 +javac.target=1.6 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.jaxws21.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +jbi.ant.tasks.classpath=\ + ${jbi.as.home}/lib/sun-appserv-ant.jar:\ + ${jbi.as.home}/jbi/lib/jbi-ant-tasks.jar +#jbi.as.home=D:\\softwares\\openesb_logicoy_last_working53\\glassfish +jbi.as.home=C:\GlassFishESBv22\glassfish +#jbi.as.instance.id=[D:\\softwares\\openesb_logicoy_last_working53\\glassfish]deployer:Sun:AppServer::localhost:4848 +jbi.as.instance.id=[C:\GlassFishESBv22\glassfish]deployer:Sun:AppServer::localhost:4848 +jbi.component.bootstrap.class=BindingComponent-archetype.JMXBindingInstaller +jbi.component.class=BindingComponent-archetype.JMXBindingRuntime +jbi.component.description=Description of binding component : BindingComponent-archetype +jbi.component.lib.classpath=\ + ${libs.wsdl4j.162.classpath} +jbi.component.name=BindingComponent-archetype +jbi.component.sharedlibs.classpath= +jbi.component.type=binding-component +jbi.host=localhost +jbi.install.params.file=install-params.properties +jbi.install.with.params=false +jbi.password=this really long string is used to identify a password that has been stored in the Keyring +jbi.port=4848 +jbi.soap.binding.name=sun-http-binding +jbi.username=admin +meta.inf.dir=${conf.dir}/META-INF +platform.active=default_platform +project.jbi.deploy.plugin=./deploy-plugin +project.testSA=test/testSA +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +src.dir=src/java +test-sys-prop.test.results.dir=${build.test.results.dir} +test-sys-prop.test.src.dir=test-sys-prop.test.src.dir +test.src.dir=test/java +testSA.enabled=true +testSA.name=BindingComponent-archetype_TestSA diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/project.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/project.xml new file mode 100644 index 000000000..4430c8228 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/nbproject/project.xml @@ -0,0 +1,17 @@ + + + org.netbeans.modules.jbi.apisupport.project.jbicomponent + + + BindingComponent-archetype + binding-component + 1.6.5 + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/pom.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/pom.xml new file mode 100644 index 000000000..1b370ee15 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/pom.xml @@ -0,0 +1,268 @@ + + + + 4.0.0 + archetype.it + BindingComponent-archetype + jar + 0.1-SNAPSHOT + JBI Component[BindingComponent-archetype] + Maven project for JBI Component that contains the + maven and netbeans build setup and component code to build and test the JBI Component. + http://open-esb.org + + build + src/java + test/java + build/classes + build/test/classes + package + + + org.apache.maven.plugins + maven-compiler-plugin + + true + 1.5 + 1.5 + + + **/*.java + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + + **/*.* + + + + + maven-surefire-plugin + 2.1.3 + true + + + true + + **/bindingtest/*.java + **/enginetest/*.java + + + + + + maven-antrun-plugin + 1.2 + + + m2nbbuild-compile + compile + run + + + + + + + + m2nbbuild-compile-test + test-compile + run + + + + + + + + m2nbbuild-package + package + run + + + + + + + + m2nbbuild-utest + test + run + + + + + + + + m2nbbuild-itest + integration-test + run + + + + + + + + m2nbbuild-clean + clean + run + + + + + + + default-cli + + run + + + + !!!!!!!!!!!!!!!!!!!!!! Moving Files and organizing package !!!!!!!!!!!!!!!!!!!!!!!! + + + + + + + + + + ant + ant-nodeps + 1.6.5 + + + ant + ant-junit + 1.6.5 + test + + + junit + junit + 3.8.2 + test + + + + + + + + + maven2-repo1 + Maven2 Central Repository + http://repo1.maven.org/maven2 + + + download-java-net-maven2-repository + download.java.net Maven 2.x repository + http://download.java.net/maven/2/ + + + maven-repository.dev.java.net-repository + https://maven-repository.dev.java.net/nonav/repository/ + legacy + + + ws-zones + ws.zones maven repository + http://ws.zones.apache.org/repository2/ + + + apache.org + Maven Snapshots + http://people.apache.org/repo/m2-snapshot-repository + + false + + + + + + + + + apache.org + Maven Plugin Snapshots + http://people.apache.org/repo/m2-snapshot-repository + + false + + + + + + + + ant + ant-nodeps + 1.6.5 + + + ant + ant-junit + 1.6.5 + test + + + junit + junit + 3.8.2 + test + + + org.apache.maven + maven-ant-tasks + 2.0.7 + + + open-esb.jbi-cdk + jbi-cdk-ant-tasks + 1.0-SNAPSHOT + + + open-esb + jbi + 1.0 + + + wsdl4j + wsdl4j + 1.6.2 + + + com.sun.xml.ws + jaxws-rt + 2.1.2 + test + + + + + ${maven.repo.local} + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/conf/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/conf/META-INF/jbi.xml new file mode 100644 index 000000000..33ec52082 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/conf/META-INF/jbi.xml @@ -0,0 +1,42 @@ + + + + + + + BindingComponent-archetype + Description of binding component : BindingComponent-archetype + + + net.openesb.component.BindingComponent-archetype.JMXBindingRuntime + + + component.jar + + lib/wsdl4j-1.6.2.jar + + + net.openesb.component.BindingComponent-archetype.JMXBindingInstaller + + + component.jar + + lib/wsdl4j-1.6.2.jar + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingComponentLifeCycle.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingComponentLifeCycle.java new file mode 100644 index 000000000..86407044a --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingComponentLifeCycle.java @@ -0,0 +1,49 @@ +/* + * JMXBindingComponent-archetypeLifeCycle.java + */ +package net.openesb.component.BindingComponent-archetype; + +import net.openesb.component.BindingComponent-archetype.common.BasicComponentLifeCycle; +import net.openesb.component.BindingComponent-archetype.common.DefaultMessageExchangeReceiver; +import net.openesb.component.BindingComponent-archetype.common.MessageExchangeReceiver; +import net.openesb.component.BindingComponent-archetype.common.RuntimeContext; +import javax.jbi.JBIException; +import javax.jbi.component.Component; + +/** + * This class extends the basic ComponentLifeCycle implementation to provide + * component specific implementation of the ComponentLifeCycle. + * + * @see javax.jbi.ComponentLifeCycle + * @see com.sun.jbi.sample.component.common.BasicComponentLifeCycle + * @author chikkala + */ +public class JMXBindingComponentLifeCycle extends BasicComponentLifeCycle { + + /** + * constructor for the ComponentLifecycle implementation. + */ + public JMXBindingComponentLifeCycle(Component compRuntime) { + super(compRuntime); + } + + /** + * creates DefaultMessageExchangeReceiver to handles receiving and + * processing the message exchanges from the delivery channel. + */ + @Override + protected MessageExchangeReceiver createMessageExchangeReceiver() { + return new DefaultMessageExchangeReceiver(); + } + + /** + * chance to extended classes to do the component specific init + * + * @throws javax.jbi.JBIException + */ + @Override + protected void doInit() throws JBIException { + // NOOP + RuntimeContext.getInstance().setLogger(this.getClass().getName(), null); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingConsumerEndpoint.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingConsumerEndpoint.java new file mode 100644 index 000000000..ecd37c66d --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingConsumerEndpoint.java @@ -0,0 +1,150 @@ +/* + * JMXBindingConsumerEndpoint.java + */ +package net.openesb.component.BindingComponent-archetype; + +import net.openesb.component.BindingComponent-archetype.wsdlext.PortExt; +import net.openesb.component.BindingComponent-archetype.wsdlext.WSDLExtHelper; +import net.openesb.component.BindingComponent-archetype.common.RuntimeHelper; +import net.openesb.component.BindingComponent-archetype.common.deployment.ConsumerEndpoint; +import net.openesb.component.BindingComponent-archetype.common.deployment.SUDescriptor; +import net.openesb.component.BindingComponent-archetype.common.deployment.ServiceUnit; +import javax.jbi.JBIException; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanRegistrationException; +import javax.management.ObjectName; +import javax.management.StandardMBean; +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +/** + * This class extends ConsumerEndpoint to implement the component specific + * consumer endpoint configuration. It uses JMXBindingConsumerProxy to receive + * messages from external service consumers and initiate the InOut message + * exchange. This implementation shows how a synchronous send/receive from the + * delivery channel will be used in InOut message exchange in a service + * invocation by the external consumers. + * + * @author chikkala + */ +public class JMXBindingConsumerEndpoint extends ConsumerEndpoint { + + private ObjectName mJMXEndpointMBeanName; + private JMXEndpointMBean mJMXEndpointMBean; + + /** + * Creates a new instance of XSLTProviderEndpoint + */ + public JMXBindingConsumerEndpoint(SUDescriptor.Consumes consumes, Definition wsdlDef, ServiceUnit su) { + super(consumes, wsdlDef, su); + } + + @Override + protected void doInit() throws JBIException { + RuntimeHelper.getLogger().fine("JMXBindingEndpoint(Consumer): init called"); + this.initJMXEndpoint(); + } + + @Override + protected void doActivate() throws JBIException { + RuntimeHelper.getLogger().fine("JMXBindingEndpoint(Consumer): activate called"); + this.activateJMXEndpoint(); + } + + @Override + protected void doDeactivate() throws JBIException { + RuntimeHelper.getLogger().fine("JMXBindingEndpoint(Consumer): deactivate called"); + this.deactivateJMXEndpoint(); + } + + @Override + protected void doClean() throws JBIException { + RuntimeHelper.getLogger().fine("JMXBindingEndpoint(Consumer): clean called"); + this.cleanJMXEndpoint(); + } + + /** + * creates the JMXEndpointMBean implementation. + */ + protected JMXEndpointMBean createJMXEndpointMBean() { + // JMX EndpointMBean implementation that initiates in-out message exchange. + return new JMXBindingConsumerProxy(this); + } + + /** + * get the mbean object name from the endpoint address of the jmx wsdl + * extension element + */ + protected ObjectName createJMXEndpointMBeanName() throws JBIException { + ObjectName mbeanObjectName = null; + try { + mbeanObjectName = new ObjectName(findMBeanNameFromWSDL()); + } catch (Exception ex) { + throw new JBIException(ex); + } + return mbeanObjectName; + } + + public final ObjectName getJMXEndpointMBeanName() { + return this.mJMXEndpointMBeanName; + } + + public final JMXEndpointMBean getJMXEndpointMBean() { + return this.mJMXEndpointMBean; + } + + protected final void initJMXEndpoint() throws JBIException { + // create jmx mbean resources + this.mJMXEndpointMBeanName = createJMXEndpointMBeanName(); + this.mJMXEndpointMBean = createJMXEndpointMBean(); + } + + protected final void activateJMXEndpoint() throws JBIException { + // open jmx connectivity to external consumers by registering the + // external endpoint mbean implementation. + try { + StandardMBean mbean = new StandardMBean(this.mJMXEndpointMBean, JMXEndpointMBean.class); + this.getComponentContext().getMBeanServer().registerMBean(mbean, this.mJMXEndpointMBeanName); + } catch (Exception ex) { + throw new JBIException(ex); + } + } + + protected final void deactivateJMXEndpoint() throws JBIException { + // close the jmx connectivity to external consumers by unregistering + // the external endpoint mbean. + try { + this.getComponentContext().getMBeanServer().unregisterMBean(this.mJMXEndpointMBeanName); + } catch (InstanceNotFoundException ex) { + ex.printStackTrace(); + } catch (MBeanRegistrationException ex) { + ex.printStackTrace(); + } + } + + protected final void cleanJMXEndpoint() throws JBIException { + // release jmx mbean resources + this.mJMXEndpointMBean = null; + this.mJMXEndpointMBeanName = null; + } + + /** + * get the mbean object name from the endpoint address of the jmx wsdl + * extension element + */ + protected String findMBeanNameFromWSDL() { + String mbeanName = null; + try { + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + Definition def = this.getWSDL(); + PortExt address = WSDLExtHelper.getPortExt(def, serviceName, endpointName); + if (address != null) { + mbeanName = address.getMBean(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + return mbeanName; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingConsumerProxy.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingConsumerProxy.java new file mode 100644 index 000000000..296ad7430 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingConsumerProxy.java @@ -0,0 +1,234 @@ +/* + * JMXBindingConsumerProxy.java + */ +package net.openesb.component.BindingComponent-archetype; + +import net.openesb.component.BindingComponent-archetype.common.RuntimeHelper; +import net.openesb.component.BindingComponent-archetype.common.deployment.ConsumerEndpoint; +import java.io.StringReader; +import javax.jbi.JBIException; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.Fault; +import javax.jbi.messaging.InOnly; +import javax.jbi.messaging.InOut; +import javax.jbi.messaging.NormalizedMessage; +import javax.wsdl.Operation; +import javax.wsdl.OperationType; +import javax.xml.namespace.QName; +import javax.xml.transform.Source; + +/** + * This class acts as a proxy to the external service consumer that can receive + * messages from the external consumer using JMX interface and then initiate the + * InOut message exchange to invoke a service provided by the component in the + * jbi environment. + * + * this code shows how a synchronous send/receive messages from the delivery + * channel can be used in InOut message exchange to complete a service + * invocation. + * + * @author chikkala + */ +public class JMXBindingConsumerProxy implements JMXEndpointMBean { + + /** + * Synchronous send timeout + */ + private static final long SEND_SYNC_TIMEOUT = 60000; + private ConsumerEndpoint mEndpoint; + private JMXBindingNormalizer mNormalizer; + + /** + * Creates a new instance of JMXEndpointMBeanImpl + */ + public JMXBindingConsumerProxy(ConsumerEndpoint endpoint) { + this.mEndpoint = endpoint; + this.mNormalizer = new JMXBindingNormalizer(endpoint.getWSDL(), endpoint.getWSDLBinding()); + } + + public StringBuffer sendMessage(String operation, StringBuffer inputDoc) throws Exception { + // when receive input from external service consumer, + // 1. normalized the message, 2. send in-out message exchange. 3. denormalize out message. + Source inMsgSource = RuntimeHelper.createDOMSource(new StringReader(inputDoc.toString())); + QName operationQName = this.mEndpoint.getOperationQName(operation); + Source out = initiateMessageExchange(operationQName, inMsgSource); + StringBuffer outBuff = null; + if (out != null) { + // read the denormalized out message to string buffer. + outBuff = RuntimeHelper.readFromSource(out); + } + // return the out message content to the external service consumer. + return outBuff; + } + + public Source initiateMessageExchange(QName operation, Source inSource) throws JBIException { + // 1. Decide what type of message exchange needed for this operation. + Source outSource = null; + try { + Operation wsdlOp = this.mEndpoint.getWSDLOperation(operation); + if (OperationType.REQUEST_RESPONSE.equals(wsdlOp.getStyle())) { + outSource = doInOutMessageExchange(operation, inSource); + } else if (OperationType.ONE_WAY.equals(wsdlOp.getStyle())) { + doInOnlyMessageExchange(operation, inSource); + } else { + throw new JBIException("Unsupported MEP " + wsdlOp.getStyle() + + "for operation " + operation); + } + return outSource; + } catch (Exception ex) { + throw new JBIException(ex); + } + } + + /** + * invokes the service provider with in-only message exchange sent to + * delivery channel by the consumer + * + * @param operation operation name on a service + * @param inSource input xml document for the InOut operation + * @throws java.lang.Exception if any error occurs in invoking the operation + * on the service. + * @return output xml document as a Source object received from InOut + * operation of the service invoked. + */ + private void doInOnlyMessageExchange(QName operation, Source inSource) + throws Exception { + // 2. normalized the message. + // 3. locate service endpoint + // 4. create message exchange according to the Opeations MEP + + // get the component context and the delivery channel for preparing to send message + ComponentContext compContext = this.mEndpoint.getComponentContext(); + DeliveryChannel channel = this.mEndpoint.getDeliveryChannel(); + // create INOUT Message Exchange + InOnly inOnlyME = this.mEndpoint.createInOnlyMessageExchange(operation); + // set the content of the IN normalized message ( Normalize the message ) + NormalizedMessage inMsg = inOnlyME.getInMessage(); + Operation wsdlOperation = this.mEndpoint.getWSDLOperation(inOnlyME.getOperation()); + this.mNormalizer.normalizeInput(wsdlOperation, inMsg, RuntimeHelper.sourceToDOMSource(inSource)); + // send the message exchange and wait for response + boolean isSent = channel.sendSync(inOnlyME, SEND_SYNC_TIMEOUT); + if (!isSent) { + throw new Exception("JMXBinding:Timeout occured in sending the message to provider"); + } + // check if you got a done message or error ( done or error are only allowed in in-only) + // process the Message Exchange to check for done or error message and + // complete InOut message exchange with provider + //TODO: put this below code in processInOnlyMessageExchangeOnConsumer() + ExchangeStatus status = inOnlyME.getStatus(); + this.mEndpoint.getLogger().fine("Consumer:InOnly:Processing Message Exchange with status " + status); + if (ExchangeStatus.DONE.equals(status)) { + this.mEndpoint.getLogger().fine("Consumer: Completed the INONLY MessageExchange"); + return; + } else if (ExchangeStatus.ERROR.equals(status)) { + // error can occur any time. so just return the error back to client. + Exception serverSideEx = inOnlyME.getError(); + StringBuffer exMsgBuff = RuntimeHelper.getExceptionStackTrace(serverSideEx); + throw new Exception("Consumer:INONLY Message Exchange status ERROR.\n" + exMsgBuff); + } else { + // any other status is error. + throw new Exception("Consumer:INONLY Message Exchange error. status: " + status); + } + } + + /** + * invokes service provider with in-out message exchange sent to delivery + * channel by the consumer + * + * @param operation operation name on a service + * @param inSource input xml document for the InOut operation + * @throws java.lang.Exception if any error occurs in invoking the operation + * on the service. + * @return output xml document as a Source object received from InOut + * operation of the service invoked. + */ + private Source doInOutMessageExchange(QName operation, Source inSource) + throws Exception { + // 2. normalized the message. + // 3. locate service endpoint + // 4. create message exchange according to the Opeations MEP + + // get the component context and the delivery channel for preparing to send message + ComponentContext compContext = this.mEndpoint.getComponentContext(); + DeliveryChannel channel = this.mEndpoint.getDeliveryChannel(); + // create INOUT Message Exchange + InOut inOutME = this.mEndpoint.createInOutMessageExchange(operation); + // set the content of the IN normalized message ( Normalize the message ) + NormalizedMessage inMsg = inOutME.getInMessage(); + Operation wsdlOperation = this.mEndpoint.getWSDLOperation(inOutME.getOperation()); + this.mNormalizer.normalizeInput(wsdlOperation, inMsg, RuntimeHelper.sourceToDOMSource(inSource)); + // send the message exchange and wait for response + boolean isSent = channel.sendSync(inOutME, SEND_SYNC_TIMEOUT); + if (!isSent) { + throw new Exception("JMXBinding:Timeout occured in sending the message to provider"); + } + // check if you got a out message or fault or error + // process the Message Exchange to get the output message and + // complete InOut message exchange with provider + NormalizedMessage outMsg = processInOutMessageExchangeOnConsumer(inOutME); + Source outSource = this.mNormalizer.denormalizeOutput(wsdlOperation, outMsg); + return outSource; + } + + /** + * takes the InOut message exchange received from sendSync call and + * processes it further to complete InOut message exchange with provider and + * returns the out message or throws exception in case of error or faults. + */ + private NormalizedMessage processInOutMessageExchangeOnConsumer(InOut inoutExchange) + throws Exception { + // InOut MessageExchange processing on consumer side + // 1. ACTIVE status receives a fault or out message, + // send the done status to complete message exchange + // return the fault/out message to external consumer + // 2. can not receive DONE status + // 3. when received ERROR status, return the error to consumer. + + // process the message exchange based on its state. + ExchangeStatus status = inoutExchange.getStatus(); + this.mEndpoint.getLogger().fine("Consumer:Processing Message Exchange with status " + status); + + if (ExchangeStatus.ACTIVE.equals(status)) { + + Fault fault = inoutExchange.getFault(); + NormalizedMessage outMsg = inoutExchange.getOutMessage(); + + // send done to complete message exchange. + DeliveryChannel channel = this.mEndpoint.getDeliveryChannel(); + inoutExchange.setStatus(ExchangeStatus.DONE); + channel.send(inoutExchange); + this.mEndpoint.getLogger().fine("Consumer: Completed the INOUT MessageExchange"); + + // process fault or out message + if (fault != null) { + // throw an exception if there is a fault message. + Source faultContent = fault.getContent(); + StringBuffer faultContentBuff = null; + if (faultContent != null) { + faultContentBuff = RuntimeHelper.readFromSource(faultContent); + } + throw new Exception("Consumer:INOUT message exchange Fault \n" + + faultContentBuff); + } + + // return the outMessage for processing + if (outMsg != null) { + return outMsg; + } else { + throw new Exception("Consumer: Null Out message in INOUT message exchange. "); + } + } else if (ExchangeStatus.DONE.equals(status)) { + // can not get DONE on Consumer side in INOUT message exchange. + throw new Exception("Consumer: Illegal status DONE on INOUT message exchange"); + } else if (ExchangeStatus.ERROR.equals(status)) { + // error can occur any time. so just return the error back to client. + Exception serverSideEx = inoutExchange.getError(); + StringBuffer exMsgBuff = RuntimeHelper.getExceptionStackTrace(serverSideEx); + throw new Exception("Consumer:INOUT Message Exchange status ERROR.\n" + exMsgBuff); + } else { + throw new Exception("Consumer:INOUT Message Exchange error. status: " + status); + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingInstaller.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingInstaller.java new file mode 100644 index 000000000..eaeae9ae1 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingInstaller.java @@ -0,0 +1,31 @@ + /* + * JMXBindingInstaller.java + */ +package net.openesb.component.BindingComponent-archetype; + +import net.openesb.component.BindingComponent-archetype.common.ComponentInstaller; + +/** + * This class extends the ComponentInstaller that implements the + * javax.jbi.component.Bootstrap for a component installation contract. + * + * If the default implemenation of the javax.jbi.component.Bootstrap in + * com.sun.jbi.sample.component.common.ComponentInstaller is not sufficient for + * this components install, uninstall and upgrade requirements, override the + * default implementation here to add component specific installation and + * upgrade tasks such as initializing configuration mbean and creating resources + * specific to component or upgrade workspace and service units during upgrading + * the component. + * + * @see javax.jbi.Bootstrap + * @see com.sun.jbi.sample.component.common.ComponentInstaller + * @author chikkala + */ +public class JMXBindingInstaller extends ComponentInstaller { + + /** + * Constructor to create the ComponentInstaller. + */ + public JMXBindingInstaller() { + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingNormalizer.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingNormalizer.java new file mode 100644 index 000000000..a0886f7d4 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingNormalizer.java @@ -0,0 +1,239 @@ +/* + * JMXBindingNormalizer.java + */ +package net.openesb.component.BindingComponent-archetype; + +import net.openesb.component.BindingComponent-archetype.common.wsdl.AbstractNormalizer; +import net.openesb.component.BindingComponent-archetype.common.wsdl.WSDL11JBIWrapper; +import net.openesb.component.BindingComponent-archetype.common.RuntimeHelper; +import java.util.List; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.dom.DOMSource; +import org.w3c.dom.DOMException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * This class is a concrete implementation of the AbstractNormalizer to + * implement normalize jmx binding specific concrete messages to jbi wrapper + * messages and denormalize the jbi wrapper messages to jmx binding specific + * messages. The jmx binding concrete message has "message" as the root element + * that contains the part elements as its children. for example + * + * + * + * + * This is the sample code that demonstrate how to normalize and denormalize + * messages to/from jbi wrapper from/to concrete messages specific to a binding + * protocol + * + * @author chikkala + */ +public class JMXBindingNormalizer extends AbstractNormalizer { + + public static final String JMXBC_MSG_NS = "http://java.sun.com/jbi/sample/jmx-bc/envelope/"; + public static final String DEF_NS_PREFIX = "jmxbc"; + public static final String MESSAGE_EL = "message"; + + /** + * Creates a new instance of JMXBCNormalizer + */ + public JMXBindingNormalizer(Definition wsdl, Binding binding) { + super(wsdl, binding); + } + + /** + * normalizes the jmx binding protocol specific concrete message to jbi + * normalized message + */ + public void normalizeInput(Operation operation, NormalizedMessage normMsg, + DOMSource msgSource) throws MessagingException { + try { + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.createInputWrapper(operation); + Input input = operation.getInput(); + Message wsdlMsg = input.getMessage(); + //TODO: get the binding input extension here if needed. + Element jmxMessage = RuntimeHelper.getElement(msgSource); + + if (!JMXBC_MSG_NS.equals(jmxMessage.getNamespaceURI()) + || !MESSAGE_EL.equals(jmxMessage.getLocalName())) { + throw new MessagingException("invalid root element for jmxbc envelope"); + } + List jmxMsgParts = getChildElements(jmxMessage); + + addMessagePartsToJBIWrapper(jbiWrapper, wsdlMsg, jmxMsgParts); + + DOMSource wrappedSource = jbiWrapper.toDOMSource(); + normMsg.setContent(wrappedSource); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } + + /** + * normalizes the jmx binding protocol specific concrete message to jbi + * normalized message + */ + public void normalizeOutput(Operation operation, NormalizedMessage normMsg, + DOMSource msgSource) throws MessagingException { + try { + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.createInputWrapper(operation); + Output output = operation.getOutput(); + Message wsdlMsg = output.getMessage(); + //TODO: get the binding output extension here if needed. + Element jmxMessage = RuntimeHelper.getElement(msgSource); + + if (!JMXBC_MSG_NS.equals(jmxMessage.getNamespaceURI()) + || !MESSAGE_EL.equals(jmxMessage.getLocalName())) { + throw new MessagingException("invalid root element for jmxbc envelope"); + } + List jmxMsgParts = getChildElements(jmxMessage); + + addMessagePartsToJBIWrapper(jbiWrapper, wsdlMsg, jmxMsgParts); + + DOMSource wrappedSource = jbiWrapper.toDOMSource(); + normMsg.setContent(wrappedSource); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } + + /** + * normalizes the jmx binding protocol specific concrete message to jbi + * normalized message + */ + public void normalizeFault(Operation operation, String faultName, NormalizedMessage normMsg, + DOMSource msgSource) throws MessagingException { + try { + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.createInputWrapper(operation); + Fault wsdlFault = operation.getFault(faultName); + Message wsdlMsg = wsdlFault.getMessage(); + //TODO: get the binding fault extension here if needed. + Element jmxMessage = RuntimeHelper.getElement(msgSource); + + if (!JMXBC_MSG_NS.equals(jmxMessage.getNamespaceURI()) + || !MESSAGE_EL.equals(jmxMessage.getLocalName())) { + throw new MessagingException("invalid root element for jmxbc envelope"); + } + List jmxMsgParts = getChildElements(jmxMessage); + + addMessagePartsToJBIWrapper(jbiWrapper, wsdlMsg, jmxMsgParts); + + DOMSource wrappedSource = jbiWrapper.toDOMSource(); + normMsg.setContent(wrappedSource); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } + + /** + * denormalizes the jbi message to the jmx binding protocol specific + * concrete message. + */ + public DOMSource denormalizeInput(Operation operation, NormalizedMessage normMsg) + throws MessagingException { + try { + + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.sourceToWrapper( + RuntimeHelper.sourceToDOMSource(normMsg.getContent())); + Input input = operation.getInput(); + Message wsdlMsg = input.getMessage(); + //TODO: get the binding input extension here if needed. + + Document jmxMsgDoc = jbiWrapper.getDocumentBuilder().newDocument(); + Element jmxMessage = jmxMsgDoc.createElementNS(JMXBC_MSG_NS, DEF_NS_PREFIX + ":" + MESSAGE_EL); + jmxMessage.setAttributeNS(XMLNS_NS, "xmlns:" + DEF_NS_PREFIX, JMXBC_MSG_NS); + jmxMsgDoc.appendChild(jmxMessage); + + List jmxMsgParts = getMessagePartsFromJBIWrapper(jbiWrapper, wsdlMsg); + for (int i = 0; i < jmxMsgParts.size(); ++i) { + jmxMessage.appendChild(jmxMsgDoc.importNode(jmxMsgParts.get(i), true)); + } + + DOMSource unwrappedSource = new DOMSource(jmxMsgDoc); + return unwrappedSource; + } catch (DOMException ex) { + throw new MessagingException(ex); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } + + /** + * denormalizes the jbi message to the jmx binding protocol specific + * concrete message. + */ + public DOMSource denormalizeOutput(Operation operation, NormalizedMessage normMsg) + throws MessagingException { + try { + + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.sourceToWrapper( + RuntimeHelper.sourceToDOMSource(normMsg.getContent())); + Output output = operation.getOutput(); + Message wsdlMsg = output.getMessage(); + //TODO: get the binding output extension here if needed. + + Document jmxMsgDoc = jbiWrapper.getDocumentBuilder().newDocument(); + Element jmxMessage = jmxMsgDoc.createElementNS(JMXBC_MSG_NS, DEF_NS_PREFIX + ":" + MESSAGE_EL); + jmxMessage.setAttributeNS(XMLNS_NS, "xmlns:" + DEF_NS_PREFIX, JMXBC_MSG_NS); + + List jmxMsgParts = getMessagePartsFromJBIWrapper(jbiWrapper, wsdlMsg); + + for (int i = 0; i < jmxMsgParts.size(); ++i) { + jmxMessage.appendChild(jmxMsgDoc.importNode(jmxMsgParts.get(i), true)); + } + jmxMsgDoc.appendChild(jmxMessage); + DOMSource unwrappedSource = new DOMSource(jmxMsgDoc); + return unwrappedSource; + } catch (DOMException ex) { + throw new MessagingException(ex); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } + + /** + * denormalizes the jbi message to the jmx binding protocol specific + * concrete message. + */ + public DOMSource denormalizeFault(Operation operation, String faultName, NormalizedMessage normMsg) + throws MessagingException { + try { + WSDL11JBIWrapper jbiWrapper = WSDL11JBIWrapper.sourceToWrapper( + RuntimeHelper.sourceToDOMSource(normMsg.getContent())); + Fault wsdlFault = operation.getFault(faultName); + Message wsdlMsg = wsdlFault.getMessage(); + //TODO: get the binding fault extension here if needed. + + Document jmxMsgDoc = jbiWrapper.getDocumentBuilder().newDocument(); + Element jmxMessage = jmxMsgDoc.createElementNS(JMXBC_MSG_NS, DEF_NS_PREFIX + ":" + MESSAGE_EL); + jmxMessage.setAttributeNS(XMLNS_NS, "xmlns:" + DEF_NS_PREFIX, JMXBC_MSG_NS); + + List jmxMsgParts = getMessagePartsFromJBIWrapper(jbiWrapper, wsdlMsg); + + for (int i = 0; i < jmxMsgParts.size(); ++i) { + jmxMessage.appendChild(jmxMsgDoc.importNode(jmxMsgParts.get(i), true)); + } + jmxMsgDoc.appendChild(jmxMessage); + DOMSource unwrappedSource = new DOMSource(jmxMsgDoc); + return unwrappedSource; + } catch (DOMException ex) { + throw new MessagingException(ex); + } catch (ParserConfigurationException ex) { + throw new MessagingException(ex); + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingProviderEndpoint.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingProviderEndpoint.java new file mode 100644 index 000000000..b0cb8f988 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingProviderEndpoint.java @@ -0,0 +1,84 @@ +/* + * JMXBindingProviderEndpoint.java + * + */ +package net.openesb.component.BindingComponent-archetype; + +import net.openesb.component.BindingComponent-archetype.wsdlext.PortExt; +import net.openesb.component.BindingComponent-archetype.wsdlext.WSDLExtHelper; +import net.openesb.component.BindingComponent-archetype.common.MessageExchangeHandler; +import net.openesb.component.BindingComponent-archetype.common.RuntimeHelper; +import net.openesb.component.BindingComponent-archetype.common.MessageExchangeListener; +import net.openesb.component.BindingComponent-archetype.common.deployment.ProviderEndpoint; +import net.openesb.component.BindingComponent-archetype.common.deployment.SUDescriptor; +import net.openesb.component.BindingComponent-archetype.common.deployment.ServiceUnit; +import java.util.logging.Level; +import javax.jbi.JBIException; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +/** + * This class extends the ProviderEndpoint to implement component specific + * endpoint configuration. It implements the MessageExchangeListener to receive + * message exchange notifications from the MessageExchangeSupport fired by + * MessageExchangeReceiver and process it using a message exchange handler to + * show how an asynchronous processing of message exchange can be done. + * + * This endpoint uses the JMXBindingProviderProxy as a message exchange handler + * that can invoke the external provider to send a message and receive the + * response in a InOut message exchange. + * + * @author chikkala + */ +public class JMXBindingProviderEndpoint extends ProviderEndpoint implements MessageExchangeListener { + + JMXBindingProviderProxy mProviderProxy; + + /** + * Creates a new instance of XSLTProviderEndpoint + */ + public JMXBindingProviderEndpoint(SUDescriptor.Provides provides, Definition wsdlDef, ServiceUnit su) { + super(provides, wsdlDef, su); + } + + @Override + public void doInit() throws JBIException { + RuntimeHelper.getLogger().info("JMXBindingProviderEndpoint:doInit called"); + this.mProviderProxy = new JMXBindingProviderProxy(this); + } + + @Override + public MessageExchangeHandler createMessageExchangeHandler() { + return this.mProviderProxy; + } + + @Override + protected MessageExchangeListener createMessageExchangeListener() { + return this; + } + + public void messageExchangeReceived(ExchangeStatus status, MessageExchange me) { + try { + RuntimeHelper.getLogger().fine("MXListener.MessageExchangeReceived: with Status: " + status); + processMessageExchangeWithHandler(status, me); + // processMessageExchange(me); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public PortExt getJMXProviderInfo() { + PortExt portExt = null; + try { + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + Definition def = this.getWSDL(); + portExt = WSDLExtHelper.getPortExt(def, serviceName, endpointName); + } catch (Exception ex) { + getLogger().log(Level.FINE, ex.getMessage(), ex); + } + return portExt; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingProviderProxy.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingProviderProxy.java new file mode 100644 index 000000000..b92d41878 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingProviderProxy.java @@ -0,0 +1,232 @@ +/* + * JMXBindingProviderProxy.java + * + */ +package net.openesb.component.BindingComponent-archetype; + +import net.openesb.component.BindingComponent-archetype.wsdlext.PortExt; +import net.openesb.component.BindingComponent-archetype.common.AbstractMessageExchangeHandler; +import net.openesb.component.BindingComponent-archetype.common.RuntimeHelper; +import java.io.IOException; +import java.io.StringReader; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.Fault; +import javax.jbi.messaging.InOut; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; +import javax.wsdl.Operation; +import javax.xml.namespace.QName; +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMSource; + +/** + * This is a provider side implementation of the message exchange handler on a + * binding component which acts as a service provider proxy for the external + * provider. During the message exchange processing of the InOut message + * exchange, this handler acting as a proxy to the external provider invokes the + * service operation on the external provider and does required normalization + * and denormalization in processing out and in messages received from or send + * to the external service provider. + * + * @author chikkala + */ +public class JMXBindingProviderProxy extends AbstractMessageExchangeHandler { + + private JMXBindingProviderEndpoint mEndpoint; + private String mServiceURL; + private String mUsername; + private String mPassword; + private String mMBeanName; + private JMXBindingNormalizer mNormalizer; + + /** + * Creates a new instance of ProviderSEMXHandler + */ + public JMXBindingProviderProxy(JMXBindingProviderEndpoint endpoint) { + + this.mEndpoint = endpoint; + + PortExt jmxInfo = this.mEndpoint.getJMXProviderInfo(); + this.mServiceURL = jmxInfo.getServiceURL(); + this.mUsername = jmxInfo.getUsername(); + this.mPassword = jmxInfo.getPassword(); + this.mMBeanName = jmxInfo.getMBean(); + + this.mNormalizer = new JMXBindingNormalizer(endpoint.getWSDL(), endpoint.getWSDLBinding()); + } + + protected Logger getLogger() { + return this.mEndpoint.getLogger(); + } + + protected DeliveryChannel getDeliveryChannel() { + return this.mEndpoint.getDeliveryChannel(); + } + + protected void validateMessageExchange() throws MessagingException { + MessageExchange msgExchange = this.getMessageExchange(); + + if (this.getMessageExchange() == null) { + throw new MessagingException("MessageExchange Object is null in MessageExchageHandler"); + } + + if (MessageExchange.Role.CONSUMER.equals(msgExchange.getRole())) { + throw new MessagingException("Provider Message Exchange Handler can not have MessageExchange with CONSUMER Role"); + } + + if (!(msgExchange instanceof InOut)) { + throw new MessagingException("InOut Message Exchange Handler MessageExchange object should be instanceof javax.jbi.messaging.InOut "); + } + } + + protected void processError(Exception ex) { + MessageExchange msgExchange = this.getMessageExchange(); + Exception errEx = msgExchange.getError(); // get the error and print + RuntimeHelper.getLogger().info( + "InOut Message Exchange Provider received Error: " + errEx.getMessage()); + msgExchange.getError().printStackTrace(); + } + + protected void processDone() { + MessageExchange msgExchange = this.getMessageExchange(); + RuntimeHelper.getLogger().info("InOut Message Exchange Provider received DONE :" + + " END of service invocation"); + } + + protected void processFault(Fault fault) { + MessageExchange msgExchange = this.getMessageExchange(); + RuntimeHelper.logError("InOut Message Exchange Provider Handler can not receive Fault on Provider side"); + } + + protected void processMessage() { + try { + processInMessageOnProvider((InOut) this.getMessageExchange()); + } catch (JBIException ex) { + ex.printStackTrace(); + } + } + + protected void processInMessageOnProvider(InOut inOutExchange) throws JBIException { + RuntimeHelper.getLogger().fine("Processing In Message on Provider side " + inOutExchange); + // receive IN message. + NormalizedMessage inMsg = inOutExchange.getInMessage(); + NormalizedMessage outMsg = null; + Fault fault = null; + DOMSource inContent = null; + DOMSource outContent = null; + Source faultContent = null; + String faultAsText = null; + + QName opName = inOutExchange.getOperation(); + QName svcName = inOutExchange.getEndpoint().getServiceName(); + Operation wsdlOperation = this.mEndpoint.getWSDLOperation(opName); + + // process in message + // invoke the service operation + try { + inContent = this.mNormalizer.denormalizeInput(wsdlOperation, inMsg); + StringBuffer outputDoc = invokeOperation(opName.getLocalPart(), + RuntimeHelper.readFromDOMSource(inContent)); + outContent = RuntimeHelper.createDOMSource(new StringReader(outputDoc.toString())); + } catch (Exception ex) { + // exception invoking the operation. so, set exception text as fault content. + ex.printStackTrace(); + faultAsText = RuntimeHelper.getExceptionAsText(ex); + String faultText = RuntimeHelper.getExceptionAsXmlText(ex); + faultContent = RuntimeHelper.createDOMSource(new StringReader(faultText)); + } + // set out or fault message + if (outContent != null) { + // set the out message content. + outMsg = inOutExchange.createMessage(); + inOutExchange.setOutMessage(outMsg); + this.mNormalizer.normalizeOutput(wsdlOperation, outMsg, outContent); + // outMsg.setContent(outContent); + } else if (faultContent != null) { + fault = inOutExchange.createFault(); + inOutExchange.setFault(fault); + fault.setContent(faultContent); // may need to normalize the content. + } + // send out or fault message. + this.send(); + } + + protected StringBuffer invokeOperation(String operation, StringBuffer inputDoc) throws MessagingException { + try { + StringBuffer outputDoc = invokeSendMessage(this.mServiceURL, this.mUsername, this.mPassword, + this.mMBeanName, operation, inputDoc); + return outputDoc; + } catch (Exception ex) { + ex.printStackTrace(); + throw new MessagingException(ex); + } + } + + /** + * invokes a jmx mbean to send message. + */ + protected StringBuffer invokeSendMessage(String serviceURL, String username, String password, + String mbeanName, String operation, StringBuffer inputDoc) + throws MessagingException { + + JMXConnector jmxConnector = null; + MBeanServerConnection jmxConn = null; + JMXServiceURL jmxURL = null; + ObjectName epAddressName = null; + + Map env = new HashMap(); + if (username != null) { + String[] credentials = new String[]{username, password}; + env.put("jmx.remote.credentials", credentials); + env.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, this.getClass().getClassLoader()); + } + + StringBuffer outDoc = null; + + Object result = null; + String mbeanOperation = "sendMessage"; + + Object[] params = new Object[2]; + params[0] = operation; + params[1] = inputDoc; + + String[] signature = new String[2]; + signature[0] = "java.lang.String"; + signature[1] = "java.lang.StringBuffer"; + + try { + jmxURL = new JMXServiceURL(serviceURL); + epAddressName = new ObjectName(mbeanName); + + jmxConnector = JMXConnectorFactory.connect(jmxURL, env); + jmxConn = jmxConnector.getMBeanServerConnection(); + + result = jmxConn.invoke(epAddressName, mbeanOperation, params, signature); + if (result != null) { + outDoc = (StringBuffer) result; + } + } catch (Exception ex) { + throw new MessagingException(ex); + } finally { + if (jmxConnector != null) { + try { + jmxConnector.close(); + } catch (IOException ex) { + RuntimeHelper.logDebug(ex); + // ingore + } + } + } + return outDoc; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingRuntime.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingRuntime.java new file mode 100644 index 000000000..e2ccb783f --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingRuntime.java @@ -0,0 +1,54 @@ +/* + * JMXBindingRuntime.java + */ +package net.openesb.component.BindingComponent-archetype; + +import net.openesb.component.BindingComponent-archetype.common.ComponentRuntime; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.component.ServiceUnitManager; + +/** + * This class extends the ComponentRuntime that implements + * javax.jbi.component.Component interface required for the component contract + * at runtime. + * + * This class provides the component specific ComponentLifeCycle implementation + * as well as the component specific ServiceUnitManager implementation. + * + * Add any additional component runtime specific functionality here. + * + * @see javax.jbi.component.Component + * @see com.sun.jbi.sample.component.common.ComponentRuntime + * @see com.sun.jbi.sample.component.common.BasicComponentLifecycle + * @see + * com.sun.jbi.sample.component.common.deployment.AbstractServiceUnitManager + * @author chikkala + */ +public class JMXBindingRuntime extends ComponentRuntime { + + /** + * Creates a new instance of MyBindingRuntime + */ + public JMXBindingRuntime() { + super(); + } + + /** + * overriding the parent's createComponentLifeCycle to create MyBinding + * specific component lifecycle implementation. + */ + @Override + protected ComponentLifeCycle createComponentLifeCycle() { + return new JMXBindingComponentLifeCycle(this); + } + + /** + * if this component supports service unit deployment, then return the + * service unit manager, else return null. Extended classes can override + * this method and do their own ServiceUnitManager specific creation. + */ + @Override + protected ServiceUnitManager createServiceUnitManager() { + return new JMXBindingSUManager(this); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingSUManager.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingSUManager.java new file mode 100644 index 000000000..e2b4a5ce7 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingSUManager.java @@ -0,0 +1,48 @@ +/* + * JMXBindingSUManager.java + * + */ +package net.openesb.component.BindingComponent-archetype; + +import net.openesb.component.BindingComponent-archetype.common.RuntimeHelper; +import net.openesb.component.BindingComponent-archetype.common.deployment.AbstractServiceUnitManager; +import net.openesb.component.BindingComponent-archetype.common.deployment.ServiceUnit; +import java.util.logging.Logger; +import javax.jbi.management.DeploymentException; + +/** + * This class extends the AbstractServiceUnitManager to implement component + * specific service unit manager by creating the component specific ServiceUnit + * implementation. + * + * @see + * com.sun.jbi.sample.component.common.deployment.AbstractServiceUnitManager + * @see com.sun.jbi.sample.component.common.deployment.ServiceUnit + * + * @author chikkala + */ +public class JMXBindingSUManager extends AbstractServiceUnitManager { + + private JMXBindingRuntime mRuntime; + + /** + * Creates a new instance of JMXBindingSUManager + */ + public JMXBindingSUManager(JMXBindingRuntime compRuntime) { + super(); + this.mRuntime = compRuntime; + } + + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + + protected String getComponentName() { + return RuntimeHelper.getComponentName(); + } + + //TODO implement ProviderSEServiceUnit + protected ServiceUnit createServiceUnit(String suName, String suRootPath) throws DeploymentException { + return new JMXBindingServiceUnit(suName, suRootPath); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingServiceUnit.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingServiceUnit.java new file mode 100644 index 000000000..2ffef6ef7 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingServiceUnit.java @@ -0,0 +1,52 @@ +/* + * JMXBindingServiceUnit.java + * + */ +package net.openesb.component.BindingComponent-archetype; + +import net.openesb.component.BindingComponent-archetype.common.deployment.ConsumerEndpoint; +import net.openesb.component.BindingComponent-archetype.common.deployment.ProviderEndpoint; +import net.openesb.component.BindingComponent-archetype.common.deployment.SUDescriptor.Consumes; +import net.openesb.component.BindingComponent-archetype.common.deployment.SUDescriptor.Provides; +import net.openesb.component.BindingComponent-archetype.common.deployment.ServiceUnit; +import net.openesb.component.BindingComponent-archetype.common.wsdl.WSDLProcessor; +import javax.jbi.management.DeploymentException; +import javax.wsdl.Definition; + +/** + * This class extends the ServiceUnit to implement the component specific + * service unit processing. It creates the component specific ProviderEndpoint + * and ConsumerEndpoint implementation to configure the service provider and + * consumer endpoints on this component deployed in the service unit. + * + * @author chikkala + */ +public class JMXBindingServiceUnit extends ServiceUnit { + + /** + * Creates a new instance of ProviderSEServiceUnit + */ + public JMXBindingServiceUnit(String suName, String suRootPath) { + super(suName, suRootPath); + } + + @Override + protected WSDLProcessor createWSDLProcessor() { + return new JMXBindingWSDLProcessor(this.getSURootPath()); + } + + @Override + protected ConsumerEndpoint createConsumerEndpoint(Consumes consumes, Definition wsdlDef) { + return new JMXBindingConsumerEndpoint(consumes, wsdlDef, this); + } + + @Override + protected ProviderEndpoint createProviderEndpoint(Provides provides, Definition wsdlDef) { + return new JMXBindingProviderEndpoint(provides, wsdlDef, this); + } + + @Override + protected void loadOtherArtifacts() throws DeploymentException { + //TODO: load any component specific service unit artifacts + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingWSDLProcessor.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingWSDLProcessor.java new file mode 100644 index 000000000..c8ee05b68 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXBindingWSDLProcessor.java @@ -0,0 +1,40 @@ +/* + * JMXBindingWSDLProcessor.java + * + */ +package net.openesb.component.BindingComponent-archetype; + +import net.openesb.component.BindingComponent-archetype.wsdlext.WSDLExtensionRegistry; +import net.openesb.component.BindingComponent-archetype.common.wsdl.WSDLProcessor; +import javax.wsdl.extensions.ExtensionRegistry; + +/** + * This class extends form the WSDLProcessor to configure the wsdl processor use + * the wsdl extension registry configured to process the binding specific + * extension elements in the wsdl documents. + * + * WSDLExtensionRegistry that is created here has the wsdl extension model + * required to process the extension elements specific to the binding used by + * this binding component. + * + * @author chikkala + */ +public class JMXBindingWSDLProcessor extends WSDLProcessor { + + private WSDLExtensionRegistry mExtRegistry; + + /** + * Creates a new instance of JMXBindingWSDLProcessor + */ + public JMXBindingWSDLProcessor(String wsdlDir) { + super(wsdlDir); + } + + @Override + protected ExtensionRegistry getExtensionRegistry() { + if (this.mExtRegistry == null) { + this.mExtRegistry = new WSDLExtensionRegistry(); + } + return this.mExtRegistry; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXEndpointMBean.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXEndpointMBean.java new file mode 100644 index 000000000..cdd79fc8f --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/JMXEndpointMBean.java @@ -0,0 +1,38 @@ +/* + * JMXEndpointMBean.java + */ +package net.openesb.component.BindingComponent-archetype; + +/** + * The sample BC implemented as a jmx binding component exposes this interface + * as a external connectivity (endpoint address) to the external service + * consumers that can exchange messages over jmx protocol to invoke services + * provided inside jbi environment. + * + * A jmx client can send a message by invoking this method using jmx management + * interface. When this mbean method is executed in the BC as a result of mbean + * call from the jmx client, the BC acts as a proxy service consumer inside the + * jbi environment and starts a message exchange with the service provider. + * + * If the operation being executed is a InOut operation, the BC should return + * the Out or Fault message from the InOut message exchange as a return value to + * complete invocation of the service by the external consumer. + * + * @author chikkala + */ +public interface JMXEndpointMBean { + + /** + * This method will be called by a jmx client as a service consumer to send + * message to the echo service provider to invoke the service for a InOut + * message exchange. + * + * @param operation operation name on a service + * @param inputDoc input xml document for the InOut operation + * @return output xml document in a StringBuffer received from InOut + * operation of the service invoked. or null if the operation is InOnly. + * @throws java.lang.Exception if any error occurs in invoking the operation + * on the service. + */ + StringBuffer sendMessage(String operation, StringBuffer inputDoc) throws Exception; +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java new file mode 100644 index 000000000..053197e96 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/AbstractMessageExchangeHandler.java @@ -0,0 +1,138 @@ +/* + * AbstractMessageExchangeHandler.java + * + */ + +package net.openesb.component.BindingComponent-archetype.common; + +import java.io.StringReader; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.Fault; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; +import javax.xml.namespace.QName; + +/** + * This class is an abstract implementation of the MessageExchangeHandler which + * provides the base implementation of the ME processing and provides hooks to + * extended classes to implement component specific processing. + * + * @author chikkala + */ +public abstract class AbstractMessageExchangeHandler implements MessageExchangeHandler { + + public static String IN_MESSAGE = "in"; + public static String OUT_MESSAGE = "out"; + + private MessageExchange mMessageExchange; + private ExchangeStatus mStatus; + /** Creates a new instance of AbstractMessageExchangeHandler */ + protected AbstractMessageExchangeHandler() { + this.mMessageExchange = null; + } + + protected abstract Logger getLogger(); + protected abstract DeliveryChannel getDeliveryChannel(); + protected abstract void validateMessageExchange() throws MessagingException; + protected abstract void processError(Exception ex); + protected abstract void processDone(); + protected abstract void processMessage(); + protected abstract void processFault(Fault fault); + + public final MessageExchange getMessageExchange() { + return this.mMessageExchange; + } + + public final void setMessageExchange(MessageExchange msgExchange) { + this.mMessageExchange = msgExchange; + } + + public final ExchangeStatus getMessageExchangeStatus() { + if ( this.mStatus != null ) { + return this.mStatus; + } else if ( this.mMessageExchange != null ) { + return this.mMessageExchange.getStatus(); + } else { + return null; + } + } + + public final void setMessageExchangeStatus(ExchangeStatus status) { + this.mStatus = status; + } + + protected void send() throws MessagingException { + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected boolean sendSync(long timeout) throws MessagingException { + return this.getDeliveryChannel().sendSync(this.mMessageExchange, timeout); + } + + protected void sendDone() throws MessagingException { + this.mMessageExchange.setStatus(ExchangeStatus.DONE); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void sendError(Exception ex) throws MessagingException { + this.mMessageExchange.setError(ex); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void sendFault(Exception ex, QName type, String name) throws MessagingException { + Fault fault = this.mMessageExchange.createFault(); + if ( ex != null ) { + String xmlText = RuntimeHelper.getExceptionAsXmlText(ex); + fault.setContent(RuntimeHelper.createDOMSource(new StringReader(xmlText))); + } + this.mMessageExchange.setFault(fault); + this.getDeliveryChannel().send(this.mMessageExchange); + } + + protected void processActive() { + Fault fault = this.getMessageExchange().getFault(); + if ( fault != null ) { + processFault(fault); + } else { + processMessage(); + } + } + /** + * implementation of the MessageExchangeHandler#processMessageExchange method. + */ + public void processMessageExchange(ExchangeStatus status, MessageExchange msgEx) { + + getLogger().fine("MessageExchangeHandler.processMessageExchange:status: " + status ); + + this.setMessageExchangeStatus(status); + this.setMessageExchange(msgEx); + + try { + validateMessageExchange(); + } catch (MessagingException ex) { + getLogger().log(Level.FINE, "Invalid message exchange for processing ", ex); + if ( this.getMessageExchange() != null ) { + try { + sendError(ex); + } catch (MessagingException errEx) { + getLogger().log(Level.FINE, "Can not send invalid message exchange error", errEx); + } + } + return; + } + + MessageExchange msgExchange = this.getMessageExchange(); + + if (ExchangeStatus.ACTIVE.equals(status) ) { + processActive(); + } else if (ExchangeStatus.DONE.equals(status) ) { + processDone(); + } else if (ExchangeStatus.ERROR.equals(status) ) { + processError(msgExchange.getError()); + } + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java new file mode 100644 index 000000000..4f2ed2aa2 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/BasicComponentLifeCycle.java @@ -0,0 +1,395 @@ +/* + * AbstractComponentLifeCycle.java + */ + +package net.openesb.component.BindingComponent-archetype.common; + +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.component.Component; +import javax.jbi.component.ComponentContext; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.MessagingException; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.StandardMBean; + +/** + * This class implements the javax.jbi.component.ComponentLifeCycle. This is an + * abstract class that keeps the reference to the component context and the lifecycle + * extension mbeans. It implements the lifecycle method and provide the extended methods + * for each lifecycle methods to implement component specific functionality. + *

+ * It makes sure that the mininum initialization required for the component + * lifecycle is implemented by this class or the classes extending this class. + *

+ * Another important functionality implemented in this class is that it initializes the global + * RuntimeContext for the component with the ComponentContext passed by the JBI runtime and the + * opened delivery channel to make them available globally to any class in the component implementation + * that may need it during component lifecycle + *

+ * Service engine or a binding component lifecycle implementation can directly extend + * this class for their required functionality and override some of the methods to provide + * their own implementation. + * + * @see javax.jbi.ComponentLifeCycle + * @author chikkala + */ +public class BasicComponentLifeCycle implements ComponentLifeCycle { + /** reference to the component runtime */ + private Component mCompRuntime; + /** component context */ + private ComponentContext mComponentContext; + /** Extension Mbean Name*/ + private ObjectName mExtensionMBeanName; + /** Extension Mbean Implementation*/ + private StandardMBean mExtensionMBeanImpl; + /** a message receiver that accepts messages from delivery channel */ + private MessageExchangeReceiver mMsgExchReceiver; + + /** + * constructor for the ComponentLifecycle implementation. + * @param compRuntime + */ + protected BasicComponentLifeCycle(Component compRuntime) { + this.mCompRuntime = compRuntime; + } + /** + * @return Component + */ + public final Component getComponentRuntime() { + return this.mCompRuntime; + } + /** + * @return ComponentContext component context. + */ + public final ComponentContext getComponentContext() { + return mComponentContext; + } + /** + * @return component name + */ + protected String getComponentName() { + return (this.mComponentContext != null) ? + this.mComponentContext.getComponentName() : null; + } + /////////////////////////////////////////////////////////////////////////// + // ComponentLifeCycle interface implemenation + /////////////////////////////////////////////////////////////////////////// + + /** + * Initializes the component lifecycle. This method makes sure that the + * component context passed by the jbi runtime is saved in the lifecycle + * object before calling the other component initialization methods to + * completely initialize the component. + * @param context Component context + * @see javax.jbi.component.ComponentLifeCycle#init(javax.jbi.component.ComponentContext) + * @throws javax.jbi.JBIException on error + */ + public final void init(ComponentContext context) throws JBIException { + + if ( context == null ) { + throw new JBIException("Null Component Context received in " + + "Component Lifecycle init "); + } + this.mComponentContext = context; // 0. save the component context passed by jbi framework. + // initialize the content + initGlobalContext(); // 1. Initialize component runtime context. + registerExtensionMBean(); // 2. Create and register extension mbean. + openDeliveryChannel(); // 3. Open delivery channel. + initMessageExchangeReceiver(); // 4. Create message exchange receiver. + doInit(); // 5. Do any component specific initialization such + // as static service providers and consumers initialization. + + this.getLogger().fine("Component " + this.getComponentName() + " initialized"); + } + + /** + * Starts the component. Extended classes can override/implement the methods called + * in this method to provide component specify start functionality. + * + * @see javax.jbi.component.ComponentLifeCycle#start() + * @throws javax.jbi.JBIException on error + */ + public final void start() throws JBIException { + + doStart(); // 1. do any other component specific start tasks such as + // activating any static service providers and consumers. + startMessageExchangeProcessing(); // 2. begin accepting and processing message exchanges. + + this.getLogger().fine("Component " + this.getComponentName() + " started"); + } + + /** + * Stop the component.Extended classes can override/implement the methods called + * in this method to provide component specify stop functionality. + * @throws javax.jbi.JBIException + * @see javax.jbi.component.ComponentLifeCycle#stop() + */ + public final void stop() throws JBIException { + + stopMessageExchangeProcessing(); // 1. stop accepting and processing message exchanges. + doStop(); // 2. do any other component specific stop tasks such as + // deactivating any static service providers and consumers. + this.getLogger().fine("Component " + this.getComponentName() + " stopped."); + } + + /** + * Shut down the component. Extended classes can override/implement the methods called + * in this method to provide component specify shut down functionality. + * @throws javax.jbi.JBIException + * @see javax.jbi.component.ComponentLifeCycle#shutDown() + */ + public final void shutDown() throws JBIException { + // clean up all resources. + shutdownMessageExchangeReceiver(); // 1. remove the message receiver. + closeDeliveryChannel(); // 2. close delivery channel + unregisterExtensionMBean(); // 3. unregister and remove extension mbean if exists. + doShutDown(); // 4. do any other component specific clean up tasks such + // as clean any static service providers and consumer resource. + this.getLogger().fine("Component " + this.getComponentName() + " shut down"); + } + /** + * create jmx object name for the extension mbean. default implementation does + * not required to have the extension mbean. + * @return ObjectName of the extension mbean + */ + protected ObjectName createExtensionMBeanName() { + return null; + } + /** + * gets the reference to the extension mbean name. + * @see javax.jbi.component.ComponentLifeCycle#getExtensionMBeanName() + * @return ObjectName of the extension mbean objectname or null if component + * does not support extension mbean + */ + public final ObjectName getExtensionMBeanName() { + if ( this.mExtensionMBeanName == null ) { + this.mExtensionMBeanName = this.createExtensionMBeanName(); + } + return this.mExtensionMBeanName; + } + /** + * create mbean implementation for the extension mbean as a StandardMBean. default + * implementation does not require the extension mbean + * @return the ExtensionMBean implementation as StandardMBean + */ + protected StandardMBean createExtensionMBean() { + return null; + } + /** + * gets the reference to the extension mbean. + * @return extension mbean implementation or null if component does not support. + */ + protected final StandardMBean getExtensionMBean() { + if ( this.mExtensionMBeanImpl == null ) { + this.mExtensionMBeanImpl = this.createExtensionMBean(); + } + return this.mExtensionMBeanImpl; + } + /** + * if there is an extension mbean supported by the component, then register + * it with the mbean server. + * @throws JBIException on error registering mbean + */ + protected final void registerExtensionMBean() throws JBIException { + // creatre the extension mbean's object name + ObjectName mbeanName = this.getExtensionMBeanName(); + // create the extension mbean implemenation. + StandardMBean mbeanImpl = this.getExtensionMBean(); + + if ( mbeanName == null || mbeanImpl == null ) { + this.getLogger().fine(this.getComponentName() + + " Does not have Extension MBean implemenation "); + return; + } + // register with mbean only if object name and implementation are non null + try { + MBeanServer mbServer = RuntimeHelper.getComponentContext().getMBeanServer(); + mbServer.registerMBean(mbeanImpl, mbeanName); + } catch (Exception e) { + throw new JBIException("Failed to register Extension MBean for " + + this.getComponentName(), e); + } + } + /** + * remove the registered extension mbean from the mbean server if any. + */ + protected final void unregisterExtensionMBean() { + ObjectName mbeanName = this.getExtensionMBeanName(); + if ( mbeanName == null ) { + return; + } + try { + MBeanServer mbServer = RuntimeHelper.getComponentContext().getMBeanServer(); + mbServer.unregisterMBean(mbeanName); + } catch (Exception e) { + this.getLogger().log(Level.WARNING, + "Failed to unregister Extension MBean from MBeanServer for " + this.getComponentName(), e); + } + } + /** + * creates MessageExchangeReceiver implementation that handles receiving and processing + * the message exchanges from the delivery channel. Component should implement + * this method to provide the MessageReceiver. + * + * Component may return null indicating that they don't need the message receiver + * that can receive and process message exchanges from delivery channel. For example, + * components that have only service consumers which send a synchronous messages to + * providers don't need this. + * + * @throws java.lang.Exception + * @return MessageExchangeReceiver implementation. null if the component does not support it. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle#createMessageExchangeReceiver + */ + protected MessageExchangeReceiver createMessageExchangeReceiver() { + return null; + } + /** + * returns the message exchange receiver implementation reference + * @return MessageExchangeReceiver interface + */ + protected final MessageExchangeReceiver getMessageExchangeReceiver() { + if ( this.mMsgExchReceiver == null ) { + this.mMsgExchReceiver = createMessageExchangeReceiver(); + } + return this.mMsgExchReceiver; + } + /** + * creates a message receiver object as part of the component initialization. + * @throws javax.jbi.JBIException + */ + protected void initMessageExchangeReceiver() throws JBIException { + // create and initialize the MessageExchangeReceiver + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.initReceiver(); + } + } + /** + * allows the component to accept the message exchange objects from the + * delivery channel and process it as part of the component startup process. + * @throws javax.jbi.JBIException + */ + protected void startMessageExchangeProcessing() throws JBIException { + // start message processing + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.startProcessing(); + } + } + /** + * stops the component from accepting the message exchange objects from the + * delivery channel as part of the component stop process + * @throws javax.jbi.JBIException + */ + protected void stopMessageExchangeProcessing() throws JBIException { + // stop message processing + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.stopProcessing(); + } + } + /** + * removes the message receiver as part of the component shutdown process + * @throws javax.jbi.JBIException + */ + protected void shutdownMessageExchangeReceiver() throws JBIException { + // clean up message processing. + MessageExchangeReceiver mxReceiver = getMessageExchangeReceiver(); + if ( mxReceiver != null ) { + mxReceiver.shutdownReceiver(); + } + } + /** + * Returns logger initialized from the component context or a default logger. + * @return Logger + */ + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** + * initializes the RuntimeContext during component init lifecycle phase. This + * includes setting the ComponentContext and loggers etc. extended classes must + * save the component context in the RuntimeContext in this methods implementation. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle#initGlobalContext + */ + protected void initGlobalContext() { + RuntimeContext.getInstance().setComponentContext(this.getComponentContext()); + RuntimeContext.getInstance().setLogger(this.getClass().getName(), null); + } + /** opens the delivery channel to accept or send message exchange objects + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle#openDeliveryChannel + */ + protected void openDeliveryChannel() { + try { + DeliveryChannel channel = this.getComponentContext().getDeliveryChannel(); + RuntimeContext.getInstance().setDeliveryChannel(channel); + } catch (MessagingException ex) { + ex.printStackTrace(); + } + } + /** closes the delivery channel as part of the component shutdown process. + * @see com.sun.jbi.sample.component.common.DefaultComponentLifecycle#closeDeliveryChannel + */ + protected void closeDeliveryChannel() { + // closes delivery channel and remove the reference. + try { + DeliveryChannel channel = RuntimeHelper.getDeliveryChannel(); + if ( channel != null ) { + channel.close(); + } + } catch (MessagingException ex) { + ex.printStackTrace(); + } finally { + RuntimeContext.getInstance().setDeliveryChannel(null); + } + } + /** + * chance to extended classes to do any extra component specific init tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * initialized here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle#init method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle#init + */ + protected void doInit() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific start tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * activated here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle#start method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle#start + */ + protected void doStart() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific stop tasks. If the component + * supports static service providers or consumers without deployment support, they can be + * deactivated here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle#stop method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle#stop + */ + protected void doStop() throws JBIException { + //NOOP + } + /** + * chance to extended classes to do any extra component specific shutdown tasks.If the component + * supports static service providers or consumers without deployment support, they can be + * cleaned up here in the class extended from this class in implementing such a component. + * This method is invoked in the implementation of ComponentLifeCycle#shutdown method by this class. + * @throws javax.jbi.JBIException + * @see com.sun.jbi.sample.component.common.AbstractComponentLifecycle#shutdown + */ + protected void doShutDown() throws JBIException { + //NOOP + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/ComponentInstaller.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/ComponentInstaller.java new file mode 100644 index 000000000..5fdee0912 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/ComponentInstaller.java @@ -0,0 +1,272 @@ + /* + * ComponentInstaller.java + */ +package net.openesb.component.BindingComponent-archetype.common; + +import java.util.List; +import java.util.logging.Level; +import javax.jbi.component.Bootstrap; +import javax.jbi.component.InstallationContext; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.StandardMBean; + +/** + * This class implements the javax.jbi.component.Bootstrap. This class implements + * the minimum required functionality for component installation contract + * of the jbi component in the jbi environment. It also takes care of maintaining + * the installation context reference and installation specific logger creation and + * installation extension mbean registration and unregistration during initialization + * and cleanup. Extended classes only need to supply the mbean name and its implementation + * object for the installation extensions. + * + * It makes sure that the installation context and the loggers are available to + * the classes extended from this class to add more installation specific functionality. + * + * Service engine or a binding component installation implementation can directly use + * this class or extend this class to add more functionality to their installation + * process. + * + * @see javax.jbi.Bootstrap + * @author chikkala + */ +public class ComponentInstaller implements Bootstrap { + /** default logger*/ + private Logger mDefLogger; + /** bootstrap logger */ + private Logger mBTLogger ; + /** Installation Context . */ + private InstallationContext mInstallationContext; + /** Extension Mbean Name*/ + private ObjectName mExtensionMBeanName; + /** Extension Mbean Implementation*/ + private StandardMBean mExtensionMBeanImpl; + + /** Constructor to create the ComponentInstaller. */ + public ComponentInstaller() { + } + /** + * @return InstallationContext of the component. + */ + public final InstallationContext getInstallationContext() { + return this.mInstallationContext; + } + protected String getComponentName() { + return (this.mInstallationContext != null) ? + this.mInstallationContext.getComponentName() : null; + } + /** + * @return logger initialized from the installation context or a default + * logger. + */ + protected Logger getLogger() { + // try init bootstrap logger + if (this.mBTLogger == null && this.mInstallationContext != null ) { + try { + this.mBTLogger = + this.mInstallationContext.getContext().getLogger(this.getClass().getName(), null); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + // init default logger if required + if ( this.mBTLogger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (this.mBTLogger != null) ? this.mBTLogger : this.mDefLogger; + } + /** + * Initializes the installation environment for a component. + * @see javax.jbi.component.Bootstrap#init(javax.jbi.component.InstallationContext) + */ + public final void init(InstallationContext installContext) throws javax.jbi.JBIException { + + if ( installContext == null ) { + throw new JBIException("Null Installation Context received in " + + "Component Bootstrap initialization"); + } + // save the installation context reference passed by the jbi framework. + this.mInstallationContext = installContext; + registerExtensionMBean(); // create and register extension mbean + doInit(); // do any other extra initialization required specific to the component installation. + // initialize logger + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component Installer initialized"); + } + /** + * default implementation just logs the method call. extended classes should override this. + * @see javax.jbi.component.Bootstrap#onInstall() + */ + public void onInstall() throws javax.jbi.JBIException { + //TODO: do required initializaton and resource creation + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component installed."); + } + /** + * default implementation just logs the method call. + * @see javax.jbi.component.Bootstrap#onUninstall() + */ + public void onUninstall() throws javax.jbi.JBIException { + //TODO: do clean up the resource and other stuff. + this.getLogger().fine(this.mInstallationContext.getComponentName() + + " : Component uninstalled"); + } + /** + * default noop implementation of the cleanup. + * @see javax.jbi.component.Bootstrap#cleanUp() + */ + public final void cleanUp() throws javax.jbi.JBIException { + + unregisterExtensionMBean(); // unregister extension mbean and remove it + doCleanUp(); // do any other extra cleanup specific to the component installation. + this.getLogger().fine( this.mInstallationContext.getComponentName() + + " Component Installer Cleaned up"); + } + + /** + * create jmx object name for the extension mbean. Extended classes should + * return the component specific installer extension mbean name here. + */ + protected ObjectName createExtensionMBeanName() { + return null; + } + /** + * default implementation that does not have extension mbean return null. + * @see javax.jbi.component.Bootstrap#getExtensionMBeanName() + */ + public final javax.management.ObjectName getExtensionMBeanName() { + if ( this.mExtensionMBeanName == null ) { + this.mExtensionMBeanName = createExtensionMBeanName(); + } + return this.mExtensionMBeanName; + } + /** + * create mbean implementation for the extension mbean as a StandardMBean. Extended + * classes should return the installer extension mbean implementation as the + * standard mbean. + */ + protected StandardMBean createExtensionMBean() { + return null; + } + /** + * returns the installation extension mbean implementation. + * @return StandardMBean for the extension mbean implementation. + */ + protected final StandardMBean getExtensionMBean() { + if ( this.mExtensionMBeanImpl == null ) { + this.mExtensionMBeanImpl = this.createExtensionMBean(); + } + return this.mExtensionMBeanImpl; + } + /** + * Chance to extended classes to do the component installation specific init. + * Installation context will be initialized before calling this method. So, + * initialize other things if required in this method. + * @throws javax.jbi.JBIException on error + * @see com.sun.jbi.sample.component.common.ComponentInstaller#init( + * javax.jbi.component.InstallationContext) + */ + protected void doInit() throws JBIException { + this.getLogger().info(this.getInstallationContext().getComponentName() + + " : Component Installer initialized"); + } + /** + * Chance to extended classes to do the component installation specific cleanup. + * ExtensionMbean will be unregistered before calling this method. + * @throws javax.jbi.JBIException on error + * @see com.sun.jbi.sample.component.common.ComponentInstaller#cleanUp( + * javax.jbi.component.InstallationContext) + */ + protected void doCleanUp() throws JBIException { + this.getLogger().fine(this.getInstallationContext().getComponentName() + + " : Component Installer doCleanUp"); + } + /** + * if there is an extension mbean supported by the component, then register + * it with the mbean server. + */ + protected void registerExtensionMBean() throws JBIException { + // creatre the installation extension mbean's object name + ObjectName mbeanName = this.getExtensionMBeanName(); + // create the extension mbean implemenation if the object name is created. + StandardMBean mbeanImpl = this.getExtensionMBean(); + + if ( mbeanName == null || mbeanImpl == null ) { + this.getLogger().fine(this.getComponentName() + + " Does not have Installation Extension MBean implemenation "); + return; + } + // register with mbean only if object name and implementation are non null + try { + MBeanServer mbServer = this.getInstallationContext().getContext().getMBeanServer(); + mbServer.registerMBean(mbeanImpl, mbeanName); + } catch (Exception e) { + throw new JBIException("Failed to register Installation Extension MBean for " + + this.getComponentName(), e); + } + } + /** + * remove the registered extension mbean from the mbean server. + */ + protected void unregisterExtensionMBean() { + ObjectName mbeanName = this.getExtensionMBeanName(); + if ( mbeanName == null ) { + return; + } + try { + MBeanServer mbServer = this.getInstallationContext().getContext().getMBeanServer(); + mbServer.unregisterMBean(mbeanName); + } catch (Exception e) { + this.getLogger().log(Level.WARNING, + "Failed to unregister Installation extension MBean for " + this.getComponentName(), e); + } + } + /** + * This method is called by the JBI runtime to allow a component to upgrade + * it's workspace and any existing Service Units to match the new version of + * the component. The JBI runtime copies the existing workspace root to the + * new workspace root prior to calling this method, so that the component + * can examine the contents of the workspace root to determine the version + * of the component from which the upgrade is being made. All updates to the + * workspace root are done in-place; in the event of a failure, the JBI + * runtime reverts back to the original workspace root, the original install + * root, and the original Service Unit roots for the component. + * + * Note1: The component must ensure that it never holds open references + * to any files in the workspace root or any of the Service Unit roots upon + * returning from this method. Failure to do so will cause problems when + * the runtime attempts to complete the upgrade processing. + * + * Note2: The installation context that is normally initialized + * by the runtime by calling #init method of the javax.jbi.Bootstrap interface + * before install and uninstall will not be called before calling this + * upgrade method. So, installation context can not be used in this method's + * implementation. + * + * Note3: Since there won't be any installation context available, the logger + * that returned from the #getLogger method is a default logger created using + * the package name of this class or extended class if the method is overridden + * in the extended class. + * + * @param workspaceRoot the workspace root for the new version of the + * component that will replace the currently installed version. This is + * populated with the contents of the original workspace root and the + * component must update it to match the new version of the component. + * @param serviceUnitRoots a list of directory paths to all of the Service + * Units currently deployed to the component. The component must update all + * of these to match the new version of the component. + * @exception JBIException when there is an error requiring that the upgrade + * be terminated. + */ + public void upgrade(String workspaceRoot, List serviceUnitRoots) + throws javax.jbi.JBIException + { + //TODO: override this method in the extended class to handle the + // workspace root and service unit roots upgrade according to the + // component's requirement. + this.getLogger().fine("Default upgrade implementation. " + + "TODO: Implement workspace root and service unit roots upgrade."); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/ComponentRuntime.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/ComponentRuntime.java new file mode 100644 index 000000000..28c4424e1 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/ComponentRuntime.java @@ -0,0 +1,171 @@ +/* + * ComponentRuntime.java + */ +package net.openesb.component.BindingComponent-archetype.common; + +import java.util.logging.Logger; +import javax.jbi.component.Component; +import javax.jbi.component.ComponentContext; +import javax.jbi.component.ComponentLifeCycle; +import javax.jbi.component.ServiceUnitManager; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.servicedesc.ServiceEndpoint; +import org.w3c.dom.Document; +import org.w3c.dom.DocumentFragment; + +/** + * This class implements javax.jbi.component.Component interface which is + * responsible for creating the Component Lifecycle implementation and the + * ServiceUnitManager implementation for the jbi component. + * + * This class makes sure that non null component lifecycle implementation is + * returns by this class or any classes extended from this class which is + * required as a component contract. It also provides default implementation of + * all methods of the Component interface which the extended classes can + * override to add more functionality. + * + * @see javax.jbi.component.Component + * @author chikkala + */ +public class ComponentRuntime implements Component { + /** Component LifeCycle implementation */ + private ComponentLifeCycle mLifeCycle; + /** ServiceUnitManager implementation */ + private ServiceUnitManager mSUManager; + /** default logger*/ + private Logger mDefLogger; + + /** Creates a new instance of ComponentImpl */ + public ComponentRuntime() { + this.mLifeCycle = null; + this.mSUManager = null; + } + /** + * returns the ComponentContext. Any component runtime class extended from + * this class can override this method to return their own reference to the + * ComponentContext. + * @return ComponentContext component context. + */ + public ComponentContext getComponentContext() { + ComponentContext ctx = null; + if ( this.mLifeCycle != null && this.mLifeCycle instanceof BasicComponentLifeCycle ) { + ctx = ((BasicComponentLifeCycle) this.mLifeCycle).getComponentContext(); + } + return ctx; + } + /** + * Returns logger initialized from the component context or a default logger. + * @return Logger + */ + public Logger getLogger() { + Logger logger = null; + if ( this.mLifeCycle != null && this.mLifeCycle instanceof BasicComponentLifeCycle ) { + logger = ((BasicComponentLifeCycle) this.mLifeCycle).getLogger(); + } + // init default logger if required + if ( logger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (logger != null) ? logger : this.mDefLogger; + } + /** + * return the ComponentLifeCycle implementation. if returned null, the + * ComponentLifeCycleImpl will be used as the component lifecycle + * Extended classes can override this method and do their own ComponentLifecyle + * specific creation. + */ + protected ComponentLifeCycle createComponentLifeCycle() { + return new BasicComponentLifeCycle(this); + } + /** + * Get the life cycle control interface for this component. + * + * @return the life cycle control interface for this component + * @see javax.jbi.Component#getLifeCycle() + */ + public final ComponentLifeCycle getLifeCycle() { + if ( this.mLifeCycle == null ) { + this.mLifeCycle = createComponentLifeCycle(); + if ( this.mLifeCycle == null ) { + this.getLogger().fine("Creating basic component lifecycle implemenation"); + // use the default ComponentLifeCycle Impl if a component + // specific implementation return null in createComponentLifeCycle. + this.mLifeCycle = new BasicComponentLifeCycle(this); + } + } + return this.mLifeCycle; + } + /** + * if this component supports service unit deployment, then return the + * service unit manager, else return null. + * Extended classes can override this method and do their own ServiceUnitManager + * specific creation. + */ + protected ServiceUnitManager createServiceUnitManager() { + return null; + } + /** + * Get the Service Unit manager for this component. + * + * @return the ServiceUnitManager for this component, or + * null if there is none. + * @see javax.jbi.Component#getServiceUnitManager() + */ + public final ServiceUnitManager getServiceUnitManager() { + if ( this.mSUManager == null ) { + this.mSUManager = createServiceUnitManager(); + } + return this.mSUManager; + } + /** + * Retrieves a DOM representation containing metadata which describes the + * service provided by this component, through the given endpoint. + * + * Default implementation does not support service description. + * + * @see javax.jbi.Component#getServiceDescription(javax.jbi.servicedesc.ServiceEndpoint) + */ + public Document getServiceDescription(ServiceEndpoint serviceEndpoint) { + return null; + } + /** + * This method is called by JBI to check if this component, in the role of + * provider of the service indicated by the given exchange, can actually + * perform the operation desired. + * + * Default implementation has no policy and allows all exchanges with consumer. + * + * @see javax.jbi.Component#isExchangeWithProviderOkay( + * javax.jbi.servicedesc.ServiceEndpoint, javax.jbi.messaging.MessageExchange) + */ + public boolean isExchangeWithConsumerOkay( + ServiceEndpoint serviceEndpoint, MessageExchange messageExchange) { + return true; + } + /** + * This method is called by JBI to check if this component, in the role of + * consumer of the service indicated by the given exchange, can actually + * interact with the provider properly. The provider is described by the + * given endpoint and the service description supplied by that endpoint. + * + * Default implementation has no policy and allows all exchanges with provider. + * + * @see javax.jbi.Component#isExchangeWithProviderOkay( + * javax.jbi.servicedesc.ServiceEndpoint, javax.jbi.messaging.MessageExchange) + */ + public boolean isExchangeWithProviderOkay( + ServiceEndpoint serviceEndpoint, MessageExchange messageExchange) { + return true; + } + /** + * Resolve the given endpoint reference. + * + * Default implementation does not have any XML dialect. So can not resolve the + * endpoint from the document fragment. + * + * @see javax.jbi.Component#resolveEndpointReference(org.w3c.dom.DocumentFragment) + */ + public ServiceEndpoint resolveEndpointReference(DocumentFragment documentFragment) { + return null; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java new file mode 100644 index 000000000..9df6d606c --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/DefaultMessageExchangeReceiver.java @@ -0,0 +1,177 @@ +/* + * DefaultMessageExchangeReceiver.java + * + */ + +package net.openesb.component.BindingComponent-archetype.common; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import javax.jbi.JBIException; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessagingException; + +/** + * This class implements MessageExchangeReceiver interface. This is a default implementation that + * demonstrates the multi-threaded environment to receive and process message exchanges from the + * delivery channel. It uses a main thread to receive message exchanges from the delivery channel + * and then processes the received message exchanges in a individual threads from the thread pool. + * The controller methods of MessageExchangeReceiver controls the main thread and the thread pool + * execution. + * + * @author chikkala + */ +public class DefaultMessageExchangeReceiver implements MessageExchangeReceiver { + + /** delivery channel accept time out */ + private final static long DC_ACCEPT_TIME_OUT = 3000; // milliseconds + /** receiver thread wait time before polling for messages after woke up **/ + private final static long RECEIVER_WAIT_TIME = 2000; // milliseconds + /** receiver thread wait time before force shutdown */ + private final static long RECEIVER_SHUTDOWN_WAIT_TIME = 10; // seconds + /** handler threads wait time before forced shutdown */ + private final static long HANDLERS_SHUTDOWN_WAIT_TIME = 30; // seconds + /** handler thread pool size */ + private final static int HANDLER_THREAD_POOL_SIZE = 5; + /** receiver thread accept message exchange condition */ + private Boolean mCanAccept = false; + /** receiver thread termination condition */ + private Boolean mContinue = true; + /** receiver thread executor service */ + private ExecutorService mReceiverThreadMgr; + /** handler thread executor service */ + private ExecutorService mHandlerThreadPool; + + /** no default constructor for extended classes */ + public DefaultMessageExchangeReceiver() { + } + /** + * this method is called from the ComponentLifecyle.init method of the AbstractComponentLifecycle + * to initialize the message exchange receiving resources such as threads and thread pools + * throws JBIException on error + */ + public final void initReceiver() throws JBIException { + + this.mHandlerThreadPool = Executors.newFixedThreadPool(HANDLER_THREAD_POOL_SIZE); + this.mReceiverThreadMgr = Executors.newSingleThreadExecutor(); + + this.mReceiverThreadMgr.execute(new Runnable() { + public void run() { + Thread t = Thread.currentThread(); + while ( mContinue ) { + if (mCanAccept) { + receiveAndProcessMessageExchange(); + } else { + try { + t.sleep(RECEIVER_WAIT_TIME); + } catch (InterruptedException interruptException) { + // someone must have interrupted this thread + // do nothing + RuntimeHelper.logDebug("Interrupted the MessageReceiverThread in Sleep"); + } + } + } + } + }); + } + /** + * this method is called from the ComponentLifecyle.shutdown method of the AbstractComponentLifecycle + * to cleanup the message exchange receiving resources such as threads and thread pools. + * throws JBIException on error + */ + public final void shutdownReceiver() throws JBIException { + + synchronized ( mContinue ) { + mContinue = false; + } + boolean terminated = false; + try { + this.mReceiverThreadMgr.shutdown(); + terminated = this.mReceiverThreadMgr.awaitTermination( + RECEIVER_SHUTDOWN_WAIT_TIME, TimeUnit.SECONDS); + } catch (InterruptedException ex) { + RuntimeHelper.logDebug(ex); + } finally { + if ( !terminated ) { + RuntimeHelper.logDebug("Message Receiver not shutdown. Forcing shutdown"); + this.mReceiverThreadMgr.shutdownNow(); + } + } + shutdownHandlers(); + } + /** + * shutdown all the working threads from the thread pool. + */ + private final void shutdownHandlers() throws JBIException { + + boolean terminated = false; + try { + this.mHandlerThreadPool.shutdown(); + terminated = this.mHandlerThreadPool.awaitTermination( + HANDLERS_SHUTDOWN_WAIT_TIME, TimeUnit.SECONDS); + } catch (InterruptedException ex) { + RuntimeHelper.logDebug(ex); + } finally { + if ( !terminated ) { + RuntimeHelper.logDebug("Handler threads not shutdown. Forcing shutdown"); + this.mHandlerThreadPool.shutdownNow(); + } + } + } + /** + * this method is called from the ComponentLifecyle.start method of the AbstractComponentLifecycle + * to start receiving the message exchanges from the delivery channel and process them. + * throws JBIException on error + */ + public final void startProcessing() throws JBIException { + + synchronized ( this.mCanAccept ) { + this.mCanAccept = true; + } + } + /** + * this method is called from the ComponentLifecyle.stop method of the AbstractComponentLifecycle + * to stop receiving the message exchanges from the delivery channel. + * throws JBIException on error + */ + public final void stopProcessing() throws JBIException { + + synchronized ( this.mCanAccept ) { + this.mCanAccept = false; + } + } + + protected MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeHelper.getMessageExchangeSupport(); + } + + private void receiveAndProcessMessageExchange() { + try { + DeliveryChannel channel = RuntimeHelper.getDeliveryChannel(); + if ( channel == null ) { + RuntimeHelper.logDebug("DeliveryChannel Not Opened for receiving messages"); + return; + } + final MessageExchange msgExchange = channel.accept(DC_ACCEPT_TIME_OUT); + if ( msgExchange == null ) { + // delivery channel timeout occurred. do nothing. + // RuntimeHelper.logDebug("DeliveryChannel returned null message exchange from accept"); + return; + } + final ExchangeStatus status = msgExchange.getStatus(); + // process message exchange in a separate thread + this.mHandlerThreadPool.execute(new Runnable() { + public void run() { + getMessageExchangeSupport().fireMessageExchangeReceived(status, msgExchange); + } + }); + + } catch (MessagingException ex) { + RuntimeHelper.logWarning(ex); + ex.printStackTrace(); + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java new file mode 100644 index 000000000..94e18aa6a --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/MessageExchangeHandler.java @@ -0,0 +1,28 @@ +/* + * MessageExchangeHandler.java + * + */ + +package net.openesb.component.BindingComponent-archetype.common; + +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; + +/** + * This interface is a Handler to perform message exchanges when the component + * receives the MessageExchange object from the delivery channel. + * Implementation of this interface should implement the processing of + * the active, error, done status of the MessageExchange object according to + * the MEP for which the MessageExchange object is created. + * + * @author chikkala + */ +public interface MessageExchangeHandler { + /** + * this method will be invoked to process the MessageExchange + * object. + * @param msgExchange MessageExchange object to process. + */ + void processMessageExchange(ExchangeStatus status, MessageExchange msgExchange); + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/MessageExchangeListener.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/MessageExchangeListener.java new file mode 100644 index 000000000..cba79ca65 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/MessageExchangeListener.java @@ -0,0 +1,33 @@ +/* + * MessageExchangeListener.java + */ + +package net.openesb.component.BindingComponent-archetype.common; + +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; + +/** + * This interface defines the notification mechanism with which the message exchange object received + * from the delivery channel is processed by the interesting parties. A particular service endpoint + * implementation would first register the implementation of this interface with MessageExchangeSupport + * to get the notification of a received message exchange on a particular service endpoint and the + * implementation of the interface would process the message exchange when notified. + * + * When the com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver receives the message exchange + * object, it asks the MessageExchangeSupport to notify the MessageExchangeLister that is registered for the + * received message exchange object to process the message exchange object. + * @see com.sun.jbi.sample.component.common.MessageExchangeSupport + * @see com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @author chikkala + */ +public interface MessageExchangeListener { + /** + * MessageExchangeSupport will call this method to notify the lister implementation that a + * message exchange is received from the delivery channel. + * @param me MessageExchange Object + */ + void messageExchangeReceived(ExchangeStatus status, MessageExchange me); +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java new file mode 100644 index 000000000..2c5d42bf6 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/MessageExchangeReceiver.java @@ -0,0 +1,44 @@ +/* + * MessageExchangeReceiver.java + * + */ + +package net.openesb.component.BindingComponent-archetype.common; + +import javax.jbi.JBIException; + +/** + * This interface provides the methods can controls the receiving and processing of the message + * exchange objects from the delivery channel during the component lifecycle operations. + * The implementation of this interface can use multi-threaded environment to receive and process + * message exchanges from the delivery channel during the component lifecycle. + * @see com.sun.jbi.sample.component.common.DefaultMessageExchangeReceiver + * @author chikkala + */ +public interface MessageExchangeReceiver { + /** + * this method is called from the ComponentLifecyle.init method of the AbstractComponentLifecycle + * to initialize the message exchange receiving resources such as threads and thread pools + * throws JBIException on error + */ + void initReceiver() throws JBIException; + /** + * this method is called from the ComponentLifecyle.start method of the AbstractComponentLifecycle + * to start receiving the message exchanges from the delivery channel and process them. + * throws JBIException on error + */ + void startProcessing() throws JBIException; + /** + * this method is called from the ComponentLifecyle.stop method of the AbstractComponentLifecycle + * to stop receiving the message exchanges from the delivery channel. + * throws JBIException on error + */ + void stopProcessing() throws JBIException; + /** + * this method is called from the ComponentLifecyle.shutdown method of the AbstractComponentLifecycle + * to cleanup the message exchange receiving resources such as threads and thread pools. + * throws JBIException on error + */ + void shutdownReceiver() throws JBIException; + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java new file mode 100644 index 000000000..25fc453b7 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/MessageExchangeSupport.java @@ -0,0 +1,167 @@ +/* + * MessageExchangeSupport.java + * + */ + +package net.openesb.component.BindingComponent-archetype.common; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessageExchange.Role; +import javax.xml.namespace.QName; + +/** + * This class supports the registering and unregistering MessageExchangeListeners and the + * MessageExchangeHandlers that can be used to process the received message exchange from a + * delivery channel. A global reference to this class will be created in RuntimeContext object to + * provide access to this class from any where in the component runtime. + * + * A ProviderEndpoint or ConsumerEndpoint interested in a MessageExchange received from a delivery + * channel for a particular service endpoint will register the MessageExchangeListener with this + * class. The DefaultMessageExchangeReceiver when received a message exchange object from the delivery + * channel uses MessageExchangeSupport.processMessageExchange method to notify the registered listener. + * + * The MessageExchangeListener implementation ( ProviderEndpoint or ConsumerEndpoint ) while processing + * received message ( messageExchangeReceived()) will create and register the message exchange handlers + * to process the message exchange. + * + * @see RuntimeContext#getMessageExchangeSupport + * @see RuntimeHelper#getMessageExchangeSupport + * @see DefaultMessageExchangeReceiver#receiveAndProcessMessageExchange + * @see com.sun.jbi.sample.component.common.deployment.ProviderEndpoint + * @author chikkala + */ +public class MessageExchangeSupport { + /** listener map to notify a message exchange received event */ + private Map mListeners; + /** handlers that can process the message exchange */ + private Map mHandlers; + /** Creates a new instance of MessageExchangeSupport */ + public MessageExchangeSupport() { + this.mListeners = Collections.synchronizedMap(new HashMap()); + this.mHandlers = Collections.synchronizedMap(new HashMap()); + } + /** + * generates key that will be used to store the MessageExchangeListener objects. + * @param serviceName QName of the service + * @param endpointName endpoint name of the service. + */ + public String createListenerKey(Role role, QName interfaceName, QName serviceName, String endpointName) { + + StringBuffer strBuff = new StringBuffer(); + strBuff.append(interfaceName).append("+"); + strBuff.append(serviceName).append("+"); + strBuff.append(endpointName).append("+"); + String roleType = null; + if ( Role.CONSUMER.equals(role) ) { + roleType = "CONSUMER"; + } else if ( Role.PROVIDER.equals(role) ) { + roleType = "PROVIDER"; + } + strBuff.append(roleType); + return strBuff.toString(); + } + /** + * adds message exchange listener who are interested in receiving the notification when the + * message exchange is received from delivery channel. The listener can be registered with the + * following combination of the parameters: (role,interfaceName,serviceName, endpointName), + * (role,interfaceName,null, null), (role, null,serviceName, endpointName), (role, null,serviceName, null) + * + * @param role role of the message exchange listener PROVIDER or CONSUMER - can not be null. + * @param interfaceName QName of the interface ( protType ) - can be null if the serviceName is not null + * @param serviceName QName of the service - can be null if interfaceName is not null. + * @param endpointName endpoint name of the service. - can be null if the serviceName is not null. + * @param listener MessageExchangeListener object + */ + public synchronized void addMessageExchangeListener(Role role, QName interfaceName, QName serviceName, String endpointName, MessageExchangeListener listener) { + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + this.mListeners.put(key, listener); + } + /** + * removes any message exchange listener registered for the service endpoint specified by the serviceName and + * endpoint name. + * @param serviceName QName of the service + * @param endpointName endpoint name of the service. + */ + public synchronized void removeMessageExchangeListener(Role role, QName interfaceName, QName serviceName, String endpointName) { + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + MessageExchangeListener listener = this.mListeners.remove(key); + if ( listener == null ) { + RuntimeHelper.getLogger().fine("No message exchange listener removed with key " + key); + } + } + /** + * finds the MessageExchangeListner registers for the endpoint for which the message exchange is + * received and call the method on the listener + */ + public boolean fireMessageExchangeReceived(ExchangeStatus status, MessageExchange me) { + boolean notified = false; + Role role = me.getRole(); + QName interfaceName = me.getInterfaceName(); + QName serviceName = me.getEndpoint().getServiceName(); + String endpointName = me.getEndpoint().getEndpointName(); + // lookup with complete service description ( role + interface + service + endpoint ) + String key = createListenerKey(role, interfaceName, serviceName, endpointName); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + MessageExchangeListener listener = this.mListeners.get(key); + + if ( listener == null ) { // lookup with role+interface name + key = createListenerKey(role, interfaceName, null, null); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { // lookup with role + serviceName + endpointName + key = createListenerKey(role, null, serviceName, endpointName); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { // lookup with with role + serviceName + key = createListenerKey(role, null, serviceName, null); + RuntimeHelper.getLogger().fine("looking up for mx listener with key " + key); + listener = this.mListeners.get(key); + } + if ( listener == null ) { + RuntimeHelper.getLogger().fine("Could not find listener for message exchange" + me); + notified = false; + } else { + listener.messageExchangeReceived(status,me); + notified = true; + } + return notified; + } + /** + * registers the MessageExchangeHandler implementation against the message exchange id. + * @param me MessageExchange for which the handler need to be assigned + * @param handler MessageExchangeHandler implementation that will be registers. + */ + public synchronized void addMessageExchangeHandler(MessageExchange me, MessageExchangeHandler handler) { + this.mHandlers.put(me.getExchangeId(), handler); + } + /** + * removes the MessageExchangeHandler for the particular message exchange object + */ + public synchronized void removeMessageExchangeHandler(MessageExchange me) { + MessageExchangeHandler handler = this.mHandlers.remove(me.getExchangeId()); + if ( handler == null ) { + RuntimeHelper.getLogger().fine("No MessageExchangeHandler found for removing " + me.getExchangeId()); + } + } + /** + * looks up the registered message exchange handler for the message exchange object + * @param me MessageExchangeHandler. + */ + public synchronized MessageExchangeHandler findMessageExchangeHandler(MessageExchange me) { + return this.mHandlers.get(me.getExchangeId()); + } + /** + * looks up the registered message exchange handler for the message exchange object with Id + * @param exchangeId message exchange object's id + */ + public synchronized MessageExchangeHandler findMessageExchangeHandler(String exchangeId) { + return this.mHandlers.get(exchangeId); + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/RuntimeContext.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/RuntimeContext.java new file mode 100644 index 000000000..814925367 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/RuntimeContext.java @@ -0,0 +1,173 @@ +/* + * RuntimeContext.java + * + */ + +package net.openesb.component.BindingComponent-archetype.common; + +import java.util.logging.Logger; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; + +/** + * This class is global context for all the component runtime to store and + * retrieve the information that should be available anywhere in the component runtime. + * + * Each instance variable of this class will be initialized at various points of the + * component runtime using setter methods on this class. + * + * The two important objects that will be initialized and available from this context are + * ComponentContext and the opened DeliveryChannel objects both of which will be set from the + * implementation {@link BasicComponentLifeCycle}. + * + * Note that the ComponentContext from this global context will not be available until + * the jbi framework calls the init method of the ComponentLifeCycle of the component and + * then intern the implementation of the init method sets the context. + * + * @see BasicComponentLifeCycle#initGlobalContext + * @see BasicComponentLifeCycle#openDeliveryChannel + * @see BasicComponentLifeCycle#closeDeliveryChannel + * @author chikkala + */ +public final class RuntimeContext { + /** RuntimeContext singleton instance */ + private static RuntimeContext sRuntimeContext; + /** default logger*/ + private Logger mDefLogger; + /** Logger object. */ + private Logger mLogger; + /** Holds value of property ComponentContext. */ + private ComponentContext mComponentContext; + /** Holds value of property DeliveryChannel. */ + private DeliveryChannel mDeliveryChannel; + /** MessageExchange processing support **/ + private MessageExchangeSupport mMESupport; + + /** outside code can not instantiate RuntimeContext */ + private RuntimeContext() { + } + /** + * @return RuntimeContext instance. + */ + public static RuntimeContext getInstance() { + if ( sRuntimeContext == null ) { + synchronized (RuntimeContext.class) { + if ( sRuntimeContext == null ) { + sRuntimeContext = new RuntimeContext(); + } + } + } + return sRuntimeContext; + } + /** + * Getter for to obtaining ComponentContext from any where in the component runtime. + * @return ComponentContext. + */ + public ComponentContext getComponentContext() { + return this.mComponentContext; + } + /** + * Sets the Component context reference in Runtime context for global access + * any class in the component runtime. + * com.sun.jbi.sample.component.common.AbstractComponentLifeCycle#initContext + * method implementation should call this method to set the global context. + * see com.sun.jbi.sample.component.common.DefaultComponentLifeCycle#initContext + * for details. + * @param componentContext New value of property ComponentContext. + * @see BasicComponentLifeCycle#initGlobalContext + */ + public void setComponentContext(ComponentContext componentContext) { + if ( this.mComponentContext != null ) { + (new IllegalStateException("Component Context already " + + "initialized in RuntimeContext")).printStackTrace(); + } + this.mComponentContext = componentContext; + } + /** + * Getter for obtaining opened delivery channel from any where in the component runtime. + * @return DeliveryChannel. + */ + public DeliveryChannel getDeliveryChannel() { + return this.mDeliveryChannel; + } + /** + * Sets the opened delivery channel reference in Runtime context for global access + * any class in the component runtime. + * com.sun.jbi.sample.component.common.AbstractComponentLifeCycle#initContext + * method implementation should call this method to set the global context. + * see com.sun.jbi.sample.component.common.DefaultComponentLifeCycle#initContext + * for details. + * + * @param componentContext New value of property ComponentContext. + */ + public void setDeliveryChannel(DeliveryChannel deliveryChannel) { + if ( deliveryChannel != null && this.mDeliveryChannel != null ) { + (new IllegalStateException("Delivery Channel already " + + "initialized in RuntimeContext")).printStackTrace(); + } + this.mDeliveryChannel = deliveryChannel; + } + /** + * Sets the logger. + * + * @param name name for the Logger. + * @param resourceBundle resource bundle for the logger. can be null. + */ + public void setLogger(String name, String resourceBundle) { + + if (this.mComponentContext != null) { + // get the logger from component context if the component context is not null + try { + this.mLogger = this.mComponentContext.getLogger(name, resourceBundle); + } catch (Exception ex) { + ex.printStackTrace(); + } + } else { + this.mDefLogger = Logger.getLogger(name, resourceBundle); + } + } + /** + * Returns the logger. + * + * @return Logger + */ + public Logger getLogger() { + + // try init logger + if (this.mLogger == null && this.mComponentContext != null ) { + try { + this.mLogger = + this.mComponentContext.getLogger(this.getClass().getName(), null); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + // init default logger if required + if ( this.mLogger == null && this.mDefLogger == null) { + this.mDefLogger = Logger.getLogger(this.getClass().getName(), null); + } + return (this.mLogger != null) ? this.mLogger : this.mDefLogger; + } + /** + * Returns the Component Name if the ComponentContext is set. else null + * @return component name + */ + public String getComponentName() { + String componentName = null; + if (this.mComponentContext != null) { + componentName = this.mComponentContext.getComponentName(); + } + return componentName; + } + /** + * Global MessageExchangeSupport reference. Various classes in the common + * component runtime would use this method to obtain the MessageExchangeSupport + * for processing message exchange objects received from delivery channel. + */ + public MessageExchangeSupport getMessageExchangeSupport() { + if ( this.mMESupport == null ) { + this.mMESupport = new MessageExchangeSupport(); + } + return this.mMESupport; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/RuntimeHelper.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/RuntimeHelper.java new file mode 100644 index 000000000..4f0ed8617 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/RuntimeHelper.java @@ -0,0 +1,357 @@ +/* + * RuntimeHelper.java + */ + +package net.openesb.component.BindingComponent-archetype.common; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stream.StreamResult; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * This is a helper class that have bunch of methods for xml processing. + * @author chikkala + */ +public class RuntimeHelper { + + public static Logger getLogger() { + return RuntimeContext.getInstance().getLogger(); + } + + public static void logWarning(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.WARNING, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().warning(logObj.toString()); + } + } + + public static void logError(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.SEVERE, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().severe(logObj.toString()); + } + } + + public static void logDebug(Object logObj) { + if ( logObj instanceof Throwable) { + getLogger().log(Level.FINER, ((Throwable)logObj).getMessage(), (Throwable)logObj); + } else { + getLogger().finer(logObj.toString()); + } + } + + public static String getComponentName() { + return RuntimeContext.getInstance().getComponentName(); + } + public static ComponentContext getComponentContext() { + return RuntimeContext.getInstance().getComponentContext(); + } + public static DeliveryChannel getDeliveryChannel() { + return RuntimeContext.getInstance().getDeliveryChannel(); + } + + public static MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeContext.getInstance().getMessageExchangeSupport(); + } + + /** + * return the DOM Document + * @param xmlReader Reader + * @return dom document + * @throws Exception on parser exception or any other exception + */ + public static Document buildDOMDocument(Reader xmlReader) throws Exception { + InputSource xmlSource = new InputSource(xmlReader); + return buildDOMDocument(xmlSource); + } + /** + * return the DOM Document + * @param xmlReader Reader + * @return dom document + * @throws Exception on parser exception or any other exception + */ + public static Document buildDOMDocument(InputSource xmlSource) throws Exception { + Document xmlDoc = null; + DocumentBuilderFactory docBuilderFactory = + DocumentBuilderFactory.newInstance(); + docBuilderFactory.setValidating(false); + docBuilderFactory.setNamespaceAware(true); + DocumentBuilder docBuilder = + docBuilderFactory.newDocumentBuilder(); + docBuilder.setErrorHandler( new DefaultHandler() { + public void fatalError(SAXParseException e) + throws SAXException { + throw new SAXException(e.getMessage()); + } + }); + + docBuilder.setEntityResolver(new EntityResolver() { + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException, IOException { + StringReader reader = + new StringReader(""); // NOI18N + InputSource source = new InputSource(reader); + source.setPublicId(publicId); + source.setSystemId(systemId); + return source; + } + }); + + xmlDoc = docBuilder.parse(xmlSource); + + return xmlDoc; + } + /** + * reads xml text from DOMSource to StringBuffer + */ + public static StringBuffer readFromDOMSource(DOMSource domSource) { + + StringWriter writer = new StringWriter(); + + TransformerFactory tFactory = TransformerFactory.newInstance(); + Transformer trans = null; + try { + trans = tFactory.newTransformer(); + trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, + "yes"); + trans.setOutputProperty(OutputKeys.INDENT, "yes"); + StreamResult result = new StreamResult(writer); + trans.transform(domSource, result); + } catch (TransformerConfigurationException ex) { + ex.printStackTrace(); + } catch (TransformerException ex) { + ex.printStackTrace(); + } + + return writer.getBuffer(); + } + /** + * reads the xml text from InputSource into a StringBuffer + */ + public static StringBuffer readFromInputSource(InputSource inSource) { + + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + InputStream inStream = inSource.getByteStream(); + Reader reader = inSource.getCharacterStream(); + if ( reader == null ) { + reader = new InputStreamReader(inStream); + } + BufferedReader buff = new BufferedReader(reader); + try { + + for ( String line = null; (line = buff.readLine()) != null ; ) { + out.println(line); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + + return writer.getBuffer(); + } + /** + * reads xml from from DOM, SAX or Stream Source into a string buffer + */ + public static StringBuffer readFromSource(Source source) { + if ( source instanceof DOMSource ) { + return readFromDOMSource((DOMSource)source); + } else { + InputSource inSource = SAXSource.sourceToInputSource(source); + if ( inSource != null ) { + return readFromInputSource(inSource); + } else { + return null; + } + } + } + /** + * creates a DOMSource from the xml text read from the reader. + */ + public static DOMSource createDOMSource(Reader xmlReader) { + Document doc = null; + try { + doc = buildDOMDocument(xmlReader); + } catch (Exception ex) { + ex.printStackTrace(); + } + return new DOMSource(doc); + } + /** + * creates a DOMSource from any source. If the source itself is DOMSource, + * the source is returned as it is as DOMSource. + */ + public static DOMSource sourceToDOMSource(Source source) { + if ( source instanceof DOMSource) { + return (DOMSource) source; + } + InputSource xmlSource = SAXSource.sourceToInputSource(source); + Document doc = null; + try { + doc = buildDOMDocument(xmlSource); + } catch (Exception ex) { + ex.printStackTrace(); + } + return new DOMSource(doc); + } + /** + * converts the ex stracktrace to string. + */ + public static StringBuffer getExceptionStackTrace(Exception ex) { + StringWriter strWriter = new StringWriter(); + if ( ex != null ) { + PrintWriter out = new PrintWriter(strWriter); + ex.printStackTrace(out); + } + return strWriter.getBuffer(); + } + /** + * may be used to set the exception as fault content. + */ + public static String getExceptionAsXmlText(Exception ex) { + String message = replaceXmlEscapeCharsToEntityRefereces(ex.getMessage()); + String stackTrace = replaceXmlEscapeCharsToEntityRefereces( + getExceptionStackTrace(ex).toString()); + String exXmlText = + "" + + "" + message + "" + + "" + stackTrace + "" + + "" ; + return exXmlText; + } + + /** + * may be used to set the exception as fault content. + */ + public static String getExceptionAsText(Exception ex) { + String message = replaceXmlEscapeCharsToEntityRefereces(ex.getMessage()); + String stackTrace = replaceXmlEscapeCharsToEntityRefereces( + getExceptionStackTrace(ex).toString()); + StringBuffer buff = new StringBuffer(); + buff.append(message); + buff.append(System.getProperty("line.separator", "\n")); + buff.append(stackTrace); + return buff.toString(); + } + + + /** + * For attribute values which denote a QName, i.e. include a namespace prefix, + * resolve the value into a QName. + * If a namespace can not be resolved, it is set to empty - it does not + * result in an exception + * @param attrValue the string value of the attribute + * @param element the element the attribute belongs to + */ + public static QName resolveAttrQName(String attrValue, Element element) { + int aColonLoc = attrValue.indexOf(":"); + String aLocalName = attrValue; + String aPrefix = null; + String aNS = null; + if (aColonLoc > -1) { + aPrefix = attrValue.substring(0, aColonLoc); + aLocalName = attrValue.substring(aColonLoc + 1); + + // Traverse up the hierarchy until a namespace definition is found + // or the top of the document is reached. + Node currNode = element; + while ((aNS == null || aNS.equals("")) && currNode != null) { + if (currNode.getNodeType() == Node.ELEMENT_NODE) { + aNS = ((Element) currNode).getAttribute("xmlns:" + aPrefix); + } + currNode = currNode.getParentNode(); + } + } + + QName qName = new QName(aNS, aLocalName, aPrefix); + + return qName; + } + + /** + * replaces the xml entity references with the xml escape chars + * @param xmlString Text with the xml escape chars + * @param Text with the xml entity references + */ + public static String replaceXmlEscapeCharsToEntityRefereces(String xmlString) { + if ( xmlString == null ) { + return xmlString; + } + + // just convert < , > and & only + StringBuffer sbuff = new StringBuffer(2 * xmlString.length()); + for ( int i = 0; i < xmlString.length(); ++i ) { + switch ( xmlString.charAt(i) ) { + case '&': sbuff.append("&"); + break; + case '<': sbuff.append("<"); + break; + case '>': sbuff.append(">"); + break; + default: sbuff.append( xmlString.charAt(i) ); + } + } + return sbuff.toString(); + } + + /** + * return Element node from a document node or non document. Use to extract + * the message root element. + * @root node from which the Element node will be extracted. + * @return Element node. + */ + public static Element getElement(Node root) { + Element msgEl = null; + if ( root instanceof Document) { + msgEl = ((Document)root).getDocumentElement(); + } else if (root instanceof Element) { + msgEl = (Element)root; + } else { + NodeList nodeList = root.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if ( node instanceof Element ) { + msgEl = (Element) node; + break; + } + } + } + return msgEl; + } + + public static Element getElement(DOMSource domSource) { + return getElement(domSource.getNode()); + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java new file mode 100644 index 000000000..1ac6d629c --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/AbstractServiceUnitManager.java @@ -0,0 +1,309 @@ +/* + * AbstractServiceUnitManager.java + * + */ + +package net.openesb.component.BindingComponent-archetype.common.deployment; + +import net.openesb.component.BindingComponent-archetype.common.RuntimeHelper; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.component.ServiceUnitManager; +import javax.jbi.management.DeploymentException; + +/** + * This is an abstract class that implements {@link javax.jbi.component.ServiceUnitManager} to provide a + * service unit deployment support for the component. The implementation supported by this service + * unit manager and related classes in this package provides WSDL1.1 based service unit deployment + * in the component. + * + * @see javax.jbi.component.ServiceUnitManager + * @see ServiceUnit + * + * @author chikkala + */ +public abstract class AbstractServiceUnitManager implements ServiceUnitManager { + + /** Map of ServiceUnit Name to the ServiceUnit Object for all the service units + * deployed in the component */ + private Map mSUMap; + + /** Creates a new instance of AbstractSUManager */ + protected AbstractServiceUnitManager() { + this.mSUMap = Collections.synchronizedMap(new HashMap()); + } + /** returns the component name + * @return component name. + */ + protected abstract String getComponentName(); + /** + * @return Logger + */ + protected abstract Logger getLogger(); + /** + * returns the creation of the ServiceUnit implementation specific to the service unit deployment + * for the component. + * @param suName service unit name + * @param suRootPath service unit root path + * @param concrete implementation of the ServiceUnit class. + */ + protected abstract ServiceUnit createServiceUnit(String suName, String suRootPath) + throws DeploymentException; + /** + * returns the service unit object deployed by the specified name. or null if not deployed. + * @param suName service unit name to look for + * @param ServiceUnit object for the suName. or null if not present. + */ + private ServiceUnit getServiceUnit(String suName) { + return this.mSUMap.get(suName); + } + /** + * lookup for the deployed service unit. If not there, throws a deployment exception. + * @param suName service unit name + * @return ServiceUnit object + * @throws DeploymentException if the service unit is not present. + */ + private ServiceUnit findServiceUnit(String suName) throws DeploymentException { + ServiceUnit serviceUnit = getServiceUnit(suName); + if ( serviceUnit == null ) { + throw new DeploymentException("Service unit " + suName + " does not exist"); + } + return serviceUnit; + } + /** + * add the service unit object to the list of deployed service units. if there is already a + * service unit present with the name, throws a deployment exception. + * @param su service unit to add + * @return ServiceUnit object that is added. + * @throws DeploymentException if the service unit already present. + */ + private ServiceUnit addServiceUnit(ServiceUnit su) throws DeploymentException { + String suName = su.getName(); + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU != null ) { + throw new DeploymentException("Service unit " + suName + "already exists"); + } + this.mSUMap.put(suName, su); + return su; + } + /** + * removes service unit object from the list of deployed service units. if there is no + * service unit present with the name, throws a deployment exception. + * @param su service unit to add + * @return ServiceUnit object that is being removed. + * @throws DeploymentException if the service unit already present. + */ + private ServiceUnit removeServiceUnit(ServiceUnit su) throws DeploymentException { + String suName = su.getName(); + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU == null ) { + throw new DeploymentException("Service unit " + suName + " does not exist"); + } + return this.mSUMap.remove(suName); + } + /** + * creates the concrete service unit implementation and calls the load method on it to initialize + * the created service unit. + * @param suName service unit name to create + * @param suRootPath service unit root path. + * @return ServiceUnit that is created and loaded. + */ + private ServiceUnit loadServiceUnit(String suName, String suRootPath) throws DeploymentException { + ServiceUnit serviceUnit = createServiceUnit(suName, suRootPath); + serviceUnit.doLoad(); + return serviceUnit; + } + /** + * deploys a service unit. it creates and loads the service unit object for the suName and then call + * doDeploy on the service unit and adds it to the deployed service unit list + * @return result as jbi management xml + * @throws DeploymentException if there is an error deploying. + */ + private synchronized String deployServiceUnit(String suName, String suRootPath) throws DeploymentException { + String result = suName; + ServiceUnit oldSU = getServiceUnit(suName); + if ( oldSU != null ) { + throw new DeploymentException("Service unit " + suName + "already exists"); + } + ServiceUnit serviceUnit = loadServiceUnit(suName, suRootPath); + serviceUnit.doDeploy(); + addServiceUnit(serviceUnit); + return result; + } + /** + * Deploy a Service Unit to the component. + * @see javax.jbi.component.ServiceUnitManager#deploy(String, String); + */ + public final String deploy(String suName, String suRootPath) throws DeploymentException { + this.getLogger().fine("Deploying service unit " + suName + " with suRootPath " + suRootPath); + String compName = this.getComponentName(); + boolean isSuccess = true; + String mainMsg = "Successfully deployed service unit " + suName; + Exception errEx = null; + try { + deployServiceUnit(suName, suRootPath); + } catch (Exception ex) { + isSuccess = false; + errEx = ex; + mainMsg = "Failed to deploy service unit " + suName ; + this.getLogger().log(Level.FINE, mainMsg, ex); + } + return createComponentTaskResultXML(compName, "deployTask", isSuccess, mainMsg, errEx); + } + + /** + * undeploys the service unit. it looks up the existing deployed service unit and call doUndeploy + * on it and then removes from the deployed service unit list. + */ + private synchronized String undeployServiceUnit(String suName, String suRootPath) throws DeploymentException { + String result = suName; + ServiceUnit serviceUnit = findServiceUnit(suName); + serviceUnit.doUndeploy(); + removeServiceUnit(serviceUnit); + return result; + } + /** + * Undeploy a service unit from the component. + * @see javax.jbi.component.ServiceUnitManager#undeploy(String, String); + */ + public final String undeploy(String suName, String suRootPath) throws DeploymentException { + this.getLogger().fine("Undeploying service unit " + suName + " with suRootPath " + suRootPath); + String compName = this.getComponentName(); + boolean isSuccess = true; + String mainMsg = "Successfully undeployed service unit " + suName; + Exception errEx = null; + try { + undeployServiceUnit(suName, suRootPath); + } catch (Exception ex) { + isSuccess = false; + errEx = ex; + mainMsg = "Failed to undeploy service unit " + suName ; + this.getLogger().log(Level.FINE, mainMsg, errEx); + } + return createComponentTaskResultXML(compName, "undeployTask", isSuccess, mainMsg, errEx); + } + /** + * Initialize the given deployed service unit. + * @see javax.jbi.component.ServiceUnitManager#init(String, String); */ + public final void init(String suName, String suRootPath) + throws DeploymentException { + this.getLogger().fine("Initializing service unit " + suName + " with suRootPath " + suRootPath); + String result = suName; + ServiceUnit serviceUnit = getServiceUnit(suName); + if ( serviceUnit == null ) { // if the service unit not exists, create and add + serviceUnit = loadServiceUnit(suName, suRootPath); // create and load service unit + addServiceUnit(serviceUnit); // add service unit to existing service units + } + serviceUnit.doInit(); // Do Service unit initialization tasks + this.getLogger().fine("Service unit initialized:" + suName); + } + /** + * Shut down the deployment. + * @see javax.jbi.component.ServiceUnitManager#shutdown(String); + */ + public final void shutDown(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doShutdown(); // Do Service unit shutdown tasks + this.getLogger().fine("Service unit shut down:" + suName); + } + /** + * Start the deployed service unit. + * @see javax.jbi.component.ServiceUnitManager#start(String); + */ + public final void start(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doStart(); // Do service unit start tasks. + this.getLogger().fine("Service unit started:" + suName ); + } + /** + * Stop the deployed service unit. + * @see javax.jbi.component.ServiceUnitManager#stop(String); + */ + public final void stop(String suName) throws DeploymentException { + ServiceUnit serviceUnit = findServiceUnit(suName); // find service unit + serviceUnit.doStop(); // do service unit stop tasks + this.getLogger().fine("Service unit stopped: " + suName + " stopped."); + } + + /** + * helper method to create result message as jbi management message xml. + * @param componentName name of the component for this xml. + * @param taskId task id + * @param isSuccess true to format a success result, false to format a failed result. + * @param mainMsg main result message + * @param errEx Exception, null if there is no exception in failure message. + * @return XML string. + */ + protected static String createComponentTaskResultXML( + String componentName, String taskId, boolean isSuccess, String mainMsg, Exception errEx ) { + + String exMsgXml = getComponentTaskResultExceptionXML(errEx); + String mainMsgXmlEsc = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces(mainMsg); + String taskResult = isSuccess ? "SUCCESS" : "FAILED"; + String msgType = isSuccess ? "INFO" : "ERROR"; + + String xmlResult = + "" + + " " + componentName + "" + + " " + + " " + + " " + taskId + "" + + " " + taskResult + "" + + " " + msgType + "" + + " " + + " " + + " SU_MGR_MSG_ID" + + " " + mainMsgXmlEsc + "" + + " " + + " " + + exMsgXml + + " " + + " " + + ""; + + return xmlResult; + } + /** + * converts the exception to the jbi management message xml chunk. + */ + private static String getComponentTaskResultExceptionXML(Exception errEx) { + StringBuffer exMsgBuff = new StringBuffer(); + if ( errEx == null ) { + return exMsgBuff.toString(); // empty string. + } + + List exList = new ArrayList(); + int exLevel = 0; + for ( Throwable cause = errEx ; cause != null ; cause = cause.getCause() ) { + String causeMsg = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces( + cause.getMessage()); + StringWriter stBuff = new StringWriter(); + PrintWriter stOut = new PrintWriter(stBuff); + StackTraceElement[] stList = cause.getStackTrace(); + for (StackTraceElement stEl : stList) { + stOut.println(stEl.toString()); + } + stOut.close(); + String causeStackTrace = RuntimeHelper.replaceXmlEscapeCharsToEntityRefereces( + stBuff.getBuffer().toString()); + + exMsgBuff.append(""); + exMsgBuff.append(" " + exLevel + ""); + exMsgBuff.append(" " + "SU_MGR_EXP_ID"); + exMsgBuff.append(" " + causeMsg + ""); + exMsgBuff.append(" "); + exMsgBuff.append(" " + causeStackTrace + ""); + exMsgBuff.append(""); + ++exLevel; + } + + return exMsgBuff.toString(); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java new file mode 100644 index 000000000..24ddf56df --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/ConsumerEndpoint.java @@ -0,0 +1,205 @@ +/* + * ConsumerEndpoint.java + */ + +package net.openesb.component.BindingComponent-archetype.common.deployment; + +import javax.jbi.JBIException; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.InOnly; +import javax.jbi.messaging.InOut; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.messaging.MessageExchangeFactory; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +/** + * This class extends from Endpoint class and implements lifecycle methods functionality required for the + * endpoint for a service consumer. {@link ServiceUnit#createConsumerEndpoint} creates the object of this + * type to implement the service consumer functionality. + * + * @see ServiceUnit#createConsumerEndpoint + * @author chikkala + */ + +public class ConsumerEndpoint extends Endpoint { + /** + * This constructor initializes the endpoint with CONSUMER role and makes sure that the service + * description passed to it is of consumer description. + */ + protected ConsumerEndpoint(SUDescriptor.Consumes consumes, Definition wsdlDef, ServiceUnit su) { + super(Role.CONSUMER, consumes, wsdlDef, su); + } + /** + * constructor that does not need service unit information. useful for creating the endpoint for + * static services provided by the component. + */ + protected ConsumerEndpoint(SUDescriptor.Consumes consumes, Definition wsdlDef) { + this(consumes, wsdlDef, null); + } + public final void init() throws JBIException { + getLogger().fine("ConsumerEndpoint: init called"); + doInit(); //1. initialize the endpiont resources + addMessageExchangeListener(); //2. register message exchange linster. + } + public final void activate() throws JBIException { + getLogger().fine("ConsumerEndpoint: activate called"); + //1. do common ativation tasks. + doActivate(); //2. do any other activation related tasks. + } + + public final void deactivate() throws JBIException { + getLogger().fine("ConsumerEndpoint: deactivate called"); + //1. do common deactivation tasks. + doDeactivate(); //2. do any other deactivation related tasks. + } + + public final void clean() throws JBIException { + getLogger().fine("ConsumerEndpoint: clean called"); + removeMessageExchangeListener(); //1. remove message exchange listener + doClean(); //2. clean up any other resources. + } + + protected void doInit() throws JBIException { + //NOOP + } + protected void doActivate() throws JBIException { + //NOOP + } + protected void doDeactivate() throws JBIException { + //NOOP + } + protected void doClean() throws JBIException { + //NOOP + } + + /** + * helper method to find the active ServiceEndpiont for the service described with the + * serviceDescriptor. This method looks for the Active ServiceEndpoint using interface or + * service name or service name and the endpoint name. + */ + public ServiceEndpoint findServiceEndpoint() { + + QName serviceType = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + + ServiceEndpoint [] refs = null; + ServiceEndpoint serviceEndpoint = null; + ComponentContext compContext = this.getComponentContext(); + + if ( compContext == null ) { + this.getLogger().info("Null Component context. Can not find ServiceEndpoint"); + return null; + } + // lookup ServiceEndpiont with concrete service(serice qname + endpoint name). + if ( serviceName != null && endpointName != null ) { + this.getLogger().info("Looking for ServiceEndpoint with:" + + " ServiceName: " + serviceName + " EndpointName: " + endpointName); + serviceEndpoint = compContext.getEndpoint(serviceName, endpointName); + } + // else lookup ServiceEndpiont with Service Name + if ( serviceEndpoint == null && serviceName != null && endpointName == null) { + this.getLogger().info("Looking for ServiceEndpoint with Service name: " + serviceName); + refs = compContext.getEndpointsForService(serviceName); + if ( refs != null && refs.length > 0 ) { + serviceEndpoint = refs[0]; + } + } + // else lookup ServiceEndpont with serviceType + if ( serviceEndpoint == null && serviceType != null && + serviceName == null && endpointName == null) { + this.getLogger().info("Looking for ServiceEndpoint with Service type: " + serviceType); + refs = compContext.getEndpoints(serviceType); + if ( refs != null && refs.length > 0 ) { + serviceEndpoint = refs[0]; + } + } + + return serviceEndpoint; + } + + /** + * this method creates a InOutMessageExchange Object and sets the required + * data on the MessageExchange object including the create and set the Normalized + * message object to hold the input message on the MessageExchange object. + */ + public InOut createInOutMessageExchange(QName operation) + throws MessagingException, JBIException { + + ServiceEndpoint serviceEndpoint = null; + // find a ServiceEndpoint activated by the Service Providers for this service + serviceEndpoint = findServiceEndpoint(); + + if ( serviceEndpoint == null ) { + // if not found a activated ServiceEndpoint for this service, throw exception. + throw new JBIException("Can not find an Active ServiceEndpoint for \n" + this.getService()); + } else { + this.setServiceEndpoint(serviceEndpoint); + } + + InOut inOutME = null; + DeliveryChannel channel = this.getDeliveryChannel(); + // create message exchange factory for the endpiont + MessageExchangeFactory factory = channel.createExchangeFactory(serviceEndpoint); + // create INOUT Message Exchange + inOutME = factory.createInOutExchange(); + // set operation + inOutME.setOperation(operation); + // set interface if that is not set + if ( inOutME.getInterfaceName() == null ) { + inOutME.setInterfaceName(this.getService().getInterface()); + } + // create IN Nomralized Message + NormalizedMessage inMsg = inOutME.createMessage(); + // set IN Normalized message on message exchange + inOutME.setInMessage(inMsg); + + return inOutME; + } + + /** + * this method creates a InOnlyMessageExchange Object and sets the required + * data on the MessageExchange object including the create and set the Normalized + * message object to hold the input message on the MessageExchange object. + */ + public InOnly createInOnlyMessageExchange(QName operation) + throws MessagingException, JBIException { + + ServiceEndpoint serviceEndpoint = null; + // find a ServiceEndpoint activated by the Service Providers for this service + serviceEndpoint = findServiceEndpoint(); + + if ( serviceEndpoint == null ) { + // if not found a activated ServiceEndpoint for this service, throw exception. + throw new JBIException("Can not find an Active ServiceEndpoint for \n" + this.getService()); + } else { + this.setServiceEndpoint(serviceEndpoint); + } + + InOnly inOnlyME = null; + DeliveryChannel channel = this.getDeliveryChannel(); + // create message exchange factory for the endpiont + MessageExchangeFactory factory = channel.createExchangeFactory(serviceEndpoint); + // create INOUT Message Exchange + inOnlyME = factory.createInOnlyExchange(); + // set operation + inOnlyME.setOperation(operation); + // set interface if that is not set + if ( inOnlyME.getInterfaceName() == null ) { + inOnlyME.setInterfaceName(this.getService().getInterface()); + } + // create IN Nomralized Message + NormalizedMessage inMsg = inOnlyME.createMessage(); + // set IN Normalized message on message exchange + inOnlyME.setInMessage(inMsg); + + return inOnlyME; + } + + +} \ No newline at end of file diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/Endpoint.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/Endpoint.java new file mode 100644 index 000000000..1806dbf43 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/Endpoint.java @@ -0,0 +1,286 @@ +/* + * Endpoint.java + * + */ + +package net.openesb.component.BindingComponent-archetype.common.deployment; + +import net.openesb.component.BindingComponent-archetype.common.MessageExchangeHandler; +import net.openesb.component.BindingComponent-archetype.common.MessageExchangeListener; +import net.openesb.component.BindingComponent-archetype.common.MessageExchangeSupport; +import net.openesb.component.BindingComponent-archetype.common.RuntimeHelper; +import net.openesb.component.BindingComponent-archetype.common.wsdl.WSDLProcessor; +import java.util.logging.Logger; +import javax.jbi.JBIException; +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.xml.namespace.QName; + +/** + * This is an abstract class that represents the Endpoint defined for service provisioning or + * consumption in a jbi component. It stores the required service description ( wsdl definition, + * role, service unit to which it belongs etc) and defines the lifecycle operations {@link #init}, + * {@link #activate}, {@link #deactivate}, {@link #clean} to control a service endpoint that + * provides or consumes the service. + *

+ * Extended classes implement the abstract methods defined in this class to implement the endpoint + * functionality by providing the functionality to process the deployment artifacts specific to this + * endpoint, configure the endpoint to send/receive messages to/from delivery channel and process them + * according to the specific service implementation. + * + * @author chikkala + */ +public abstract class Endpoint { + /** Role of this endpoint. CONSUMER or PROVIDER */ + private Role mRole; + /** Service description from the SU descriptor for which this endpoint is configured */ + private SUDescriptor.Service mService; + /** WSDL definition corresponding to this endpoint */ + private Definition mWsdlDef; + /** service endpoint corresponding to this endpoint */ + private ServiceEndpoint mServiceEndpoint; + /** service unit from which this endpoint is created */ + private ServiceUnit mSU; // can be null + /** private constructor to force extended classes to use the parameterized constructor */ + private Endpoint() { + } + /** Creates a new instance of Endpoint + * @param role CONSUMER or PRVODER role. + * @param service service description from the su descriptor + * @param wsdl wsdl definition corresponding to this endpoint + * @param su service unit object which created this endpoint. + */ + protected Endpoint(Role role, SUDescriptor.Service service, Definition wsdl, ServiceUnit su) { + this.mService = service; + this.mRole = role; + this.mWsdlDef = wsdl; + this.mSU = su; + } + /** Creates a new instance of Endpoint without service unit. may be useful for static endpoints that + * are not part of the deployment + * @param role CONSUMER or PRVODER role. + * @param service service info from the su descriptor + * @param wsdl wsdl definition corresponding to this endpoint + */ + protected Endpoint(Role role, SUDescriptor.Service service, Definition wsdl) { + this(role, service, wsdl, null); + } + /** + * should be called to initialize any resources related to this endpoint object + * throws JBIException + */ + public abstract void init() throws JBIException; + /** + * activates the endpoint to send/receive messages + * throws JBIException + */ + public abstract void activate() throws JBIException; + /** + * deactivates the endpoint + * throws JBIException + */ + public abstract void deactivate() throws JBIException; + /** + * clean endpoint + * throws JBIException + */ + public abstract void clean() throws JBIException; + + public final Role getRole() { + return this.mRole; + } + public final boolean isProvider() { + return (Role.PROVIDER.equals(this.getRole())); + } + public final boolean isConsumer() { + return (Role.CONSUMER.equals(this.getRole())); + } + public final Definition getWSDL() { + return this.mWsdlDef; + } + public final SUDescriptor.Service getService() { + return this.mService; + } + public final ServiceEndpoint getServiceEndpoint() { + return this.mServiceEndpoint; + } + protected final void setServiceEndpoint(ServiceEndpoint svcEP) { + this.mServiceEndpoint = svcEP; + } + public final ServiceUnit getServiceUnit() { + return this.mSU; + } + /** + * generates an ID that would uniquely identify this endpoint implementation. Use as a key to map + * any information to store that is related to this endpoint. + */ + public final String getID() { + StringBuffer strBuff = new StringBuffer(); + strBuff.append(this.mService.getInterface()).append("+"); + strBuff.append(this.mService.getServiceName()).append("+"); + strBuff.append(this.mService.getEndpointName()).append("+"); + String roleType = null; + if ( Role.CONSUMER.equals(this.mRole) ) { + roleType = "CONSUMER"; + } else if ( Role.PROVIDER.equals(this.mRole) ) { + roleType = "PROVIDER"; + } + strBuff.append(roleType); + return strBuff.toString(); + } + + @Override + public String toString() { + return "Endpoint : " + "\n" + this.mService; + } + /** + * checks if this endpoint is configured for the binding component or service engine. + */ + public boolean isForBindingComponent-archetype() { + boolean isForBindingComponent-archetype = false; + if ( this.mSU != null ) { + try { + isForBindingComponent-archetype = this.mSU.getSUDescriptor().isForBindingComponent-archetype(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + return isForBindingComponent-archetype; + } + + public QName getOperationQName(String opName) { + return new QName(this.getService().getInterface().getNamespaceURI(), opName); + } + + public Operation getWSDLOperation(QName opQName) { + String opName = null; + if ( opQName != null ) { + opName = opQName.getLocalPart(); + } + Operation operation = WSDLProcessor.findOperation(this.getWSDL(), + this.getService().getInterface(), opName); + return operation; + } + + public Binding getWSDLBinding() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + if ( serviceName != null ) { + return WSDLProcessor.findServiceBinding(this.getWSDL(), serviceName, endpointName); + } else { + return WSDLProcessor.findInterfaceBinding(this.getWSDL(), interfaceName, null); + } + } + /** @return logger */ + public Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** @return ComponentContext */ + public ComponentContext getComponentContext() { + return RuntimeHelper.getComponentContext(); + } + /** @return DeliveryChannel */ + public DeliveryChannel getDeliveryChannel() { + return RuntimeHelper.getDeliveryChannel(); + } + /** + * helper function to get the MessageExchangeSupport object + */ + public MessageExchangeSupport getMessageExchangeSupport() { + return RuntimeHelper.getMessageExchangeSupport(); + } + + public MessageExchangeHandler createMessageExchangeHandler() { + return null; + } + /** + * creates the message exchange listener. Extended classes should return + * MessageExchangeListener implementation. + * @return MessageExchangeListener or null. + * + */ + protected MessageExchangeListener createMessageExchangeListener() { + return null; + } + /** + * Creates and adds message exchange listener to receive message exchange received notification. + */ + protected void addMessageExchangeListener() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + MessageExchangeListener meListener = createMessageExchangeListener(); + MessageExchangeSupport meListenerSupport = getMessageExchangeSupport(); + if ( meListenerSupport != null && meListener != null ) { + meListenerSupport.addMessageExchangeListener( + this.getRole(), interfaceName, serviceName, endpointName, meListener); + if ( serviceName != null ) { + meListenerSupport.addMessageExchangeListener( + this.getRole(), null, serviceName, endpointName, meListener); + } + } + } + /** + * Removes message exchange listener from the MessageExchangeSupport. + */ + protected void removeMessageExchangeListener() { + QName interfaceName = this.getService().getInterface(); + QName serviceName = this.getService().getServiceName(); + String endpointName = this.getService().getEndpointName(); + MessageExchangeSupport meListenerSupport = getMessageExchangeSupport(); + if ( meListenerSupport != null ) { + meListenerSupport.removeMessageExchangeListener( + this.getRole(), interfaceName, serviceName, endpointName); + if ( serviceName != null ) { + meListenerSupport.removeMessageExchangeListener( + this.getRole(), null, serviceName, endpointName); + } + } + } + + public final boolean processMessageExchangeWithHandler(ExchangeStatus status, MessageExchange me) { + + //1. lookup handler + //2. if not there create one and register + //3. call process message exchange on it + //4. check status. if that is the end, remove the handler + + MessageExchangeSupport support = this.getMessageExchangeSupport(); + if ( support == null ) { + getLogger().fine("No MessageExchangeSupport present"); + return false; + } + MessageExchangeHandler handler = support.findMessageExchangeHandler(me); + if ( handler == null ) { + handler = this.createMessageExchangeHandler(); + if ( handler == null ) { + getLogger().fine("MessageExchangeHandler not supported"); + return false; + } + support.addMessageExchangeHandler(me, handler); + } + + handler.processMessageExchange(status, me); + + getLogger().fine("XXX MX Handler processed ME with STATUS: " + status); + + if (!ExchangeStatus.ACTIVE.equals(status) ) { + // DONE or ERROR means done with the me. + getLogger().fine("End of ME processing. STATUS: " + status + + ". Removing the MX Handler ..."); + support.removeMessageExchangeHandler(me); + } + + return true; + } + +} + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java new file mode 100644 index 000000000..fa47fd306 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/ProviderEndpoint.java @@ -0,0 +1,104 @@ +/* + * ProviderEndpoint.java + * + */ + +package net.openesb.component.BindingComponent-archetype.common.deployment; + +import net.openesb.component.BindingComponent-archetype.common.deployment.SUDescriptor.Service; +import javax.jbi.JBIException; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.wsdl.Definition; + +/** + * This class extends from Endpoint class and implements lifecycle methods functionality required for the + * endpoint for a service provider. {@link ServiceUnit#createProviderEndpoint} creates the object of this + * type to implement the service provider functionality. It makes sure that this class or the extended + * classes will activate or deactivate the ServiceEndpoint corresponding to the service + * provided by the endpoint is performed during the activate and deactivate method calls as part of the + * endpoint lifecycle. + * + * @see ServiceUnit#createProviderEndpoint + * @author chikkala + */ + +public class ProviderEndpoint extends Endpoint { + /** + * This constructor initializes the endpoint with PROVIDER role and makes sure that the service + * description passed to it is of provider description. + */ + protected ProviderEndpoint(SUDescriptor.Provides provides, Definition wsdlDef, ServiceUnit su) { + super(Role.PROVIDER, provides, wsdlDef, su); + } + /** + * constructor that does not need service unit information. useful for creating the endpoint for + * static services provided by the component. + */ + protected ProviderEndpoint(SUDescriptor.Provides provides, Definition wsdlDef) { + this(provides, wsdlDef, null); + } + /** + * initializes the endpoint and creates and registers the MessageExchangeListener with + * MessageExchangeSupport. + */ + public final void init() throws JBIException { + getLogger().fine("ProviderEndpiont: init called"); + doInit(); //1. initialize the endpiont resources + addMessageExchangeListener(); //2. register message exchange linster. + } + /** + * calls activatesServiceEndpoint for the Provider. + */ + public final void activate() throws JBIException { + getLogger().fine("ProviderEndpiont: activate called"); + activateServiceEndpoint(); //1. activate service endpoint in NMR + doActivate(); //2. do any other activation related tasks. + } + /** + * calls deactivateServiceEndpoint for the Provider. + */ + public final void deactivate() throws JBIException { + getLogger().fine("ProviderEndpiont: deactivate called"); + deactivateServiceEndpoint(); //1. deactivates the service endpoint in NMR + doDeactivate(); //2. do any other deactivation related tasks. + } + /** + * removes the message exchange listener. cleans up other resources + */ + public final void clean() throws JBIException { + getLogger().fine("ProviderEndpiont: clean called"); + removeMessageExchangeListener(); //1. remove message exchange listener + doClean(); //2. clean up any other resources. + } + /** + * Activates the ServiceEndpoint with NMR + */ + private void activateServiceEndpoint() throws JBIException { + Service service = this.getService(); + ServiceEndpoint svcEP = this.getComponentContext().activateEndpoint( + service.getServiceName(), service.getEndpointName()); + this.setServiceEndpoint(svcEP); + } + /** + * Deactivates ServiceEndpoint in NMR + */ + private void deactivateServiceEndpoint() throws JBIException { + this.getComponentContext().deactivateEndpoint(this.getServiceEndpoint()); + this.setServiceEndpoint(null); + } + + protected void doInit() throws JBIException { + //NOOP + } + protected void doActivate() throws JBIException { + //NOOP + } + protected void doDeactivate() throws JBIException { + //NOOP + } + protected void doClean() throws JBIException { + //NOOP + } + +} \ No newline at end of file diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java new file mode 100644 index 000000000..070382b01 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/SUDescriptor.java @@ -0,0 +1,361 @@ +/* + * SUDescriptor.java + */ + +package net.openesb.component.BindingComponent-archetype.common.deployment; + +import net.openesb.component.BindingComponent-archetype.common.RuntimeHelper; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import javax.jbi.management.DeploymentException; +import javax.xml.namespace.QName; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * This interface represent the service unit descriptor (jbi.xml) model. This will be used in + * ServiceUnit implementation to find the services provided and consumed by this service unit. + * {@link SUDescriptorFactory#getSUDescriptor} method reads the jbi.xml in the service unit to + * to the implementation of this interface. + * + * @see SUDescriptorFactory + * @see Consumes + * @see Provides + * @see ServiceUnit + * + * @author chikkala + */ +public interface SUDescriptor { + + Collection getProvidedServices(); + + Collection getConsumedServices(); + + boolean isForBindingComponent-archetype(); + + /** + * base interface that models the service information described in the service unit descriptor for + * consumed services and provided services. + */ + public interface Service { + /** + * Getter for property interfaceQName. + * @return Value of property interfaceQName. + */ + QName getInterface(); + /** + * Getter for property serviceName. + * @return Value of property serviceName. + */ + QName getServiceName(); + /** + * Getter for property endpointName. + * @return Value of property endpointName. + */ + String getEndpointName(); + } + /** + * marker interface that represents the provided services in the service unit + */ + public interface Provides extends Service { + } + /** + * this interface represents the consumed service information in the su descriptor. + */ + public interface Consumes extends Service { + + public final static String STANDARD_LINK = "standard"; + public final static String SOFT_LINK = "soft"; + public final static String HARD_LINK = "hard"; + /** + * Getter for property linkType. + * @return Value of property linkType. + */ + String getLinkType(); + } + /** + * This is a factory class that can build the Service Unit Descriptor model from the jbi.xml + */ + public static class SUDescriptorFactory { + + protected final static String JBI_TAG_NAME = "services"; + protected final static String SERVICES_TAG_NAME = "services"; + protected final static String BC_TAG_NAME = "binding-component"; + protected final static String PROVIDES_TAG_NAME = "provides"; + protected final static String CONSUMES_TAG_NAME = "consumes"; + protected final static String INTERFACE_TAG_NAME = "interface-name"; + protected final static String SERVICE_TAG_NAME = "service-name"; + protected final static String ENDPOINT_TAG_NAME = "endpoint-name"; + protected final static String LINK_TYPE_TAG_NAME = "link-type"; + /** + * method that builds the Service unit descriptor model from the jbi.xml + */ + public static SUDescriptor getSUDescriptor(String jbiXmlPath) throws Exception { + FileReader reader = null; + try { + reader = new FileReader(jbiXmlPath); + SUDescriptor suDesc = getSUDescriptor(reader); + return suDesc; + } finally { + if ( reader != null ) { + try { + reader.close(); + } catch (IOException ex) { + // ignore + } + } + } + } + /** + * method that builds the Service unit descriptor model from the jbi.xml + */ + public static SUDescriptor getSUDescriptor(Reader reader) throws Exception { + SUDescriptor suDescriptor = null; + Document suDescDoc = RuntimeHelper.buildDOMDocument(reader); + Element jbiEl = suDescDoc.getDocumentElement(); + if (JBI_TAG_NAME.equals(jbiEl.getTagName())) { + throw new DeploymentException("Invalid service unit descriptor : no jbi root element"); + } + + NodeList servicesNL = jbiEl.getElementsByTagName(SERVICES_TAG_NAME); + if (servicesNL != null && servicesNL.getLength() == 1) { + Element servicesEl = (Element) servicesNL.item(0); + suDescriptor = SUDescriptorImpl.createSUDescriptor(servicesEl); + } else { + throw new DeploymentException("Invalid service unit descriptor : invalid services element"); + } + + return suDescriptor; + } + + } + /** + * This class implements SUDescriptor + */ + public static class SUDescriptorImpl implements SUDescriptor { + + private List mConsumedList; + private List mProvidedList; + private boolean mIsForBindingComponent-archetype; + + protected SUDescriptorImpl(boolean isForBindingComponent-archetype) { + this.mIsForBindingComponent-archetype = isForBindingComponent-archetype; + this.mConsumedList = new ArrayList(); + this.mProvidedList = new ArrayList(); + } + + protected void addProvidedService(Provides provides) { + this.mProvidedList.add(provides); + } + + protected void addConsumedService(Consumes consumes) { + this.mConsumedList.add(consumes); + } + + public Collection getProvidedServices() { + // return unmodifiable collection + return Collections.unmodifiableCollection(this.mProvidedList); + } + + public Collection getConsumedServices() { + // return unmodifiable collection + return Collections.unmodifiableCollection(this.mConsumedList); + } + + public boolean isForBindingComponent-archetype() { + return this.mIsForBindingComponent-archetype; + } + + protected static SUDescriptor createSUDescriptor(Element servicesEl) throws Exception { + boolean isForBC = false; + String bcTagString = servicesEl.getAttribute(SUDescriptorFactory.BC_TAG_NAME); + isForBC = Boolean.valueOf(bcTagString).booleanValue(); + SUDescriptorImpl suDesc = new SUDescriptorImpl(isForBC); + // add consumes + NodeList consumesNL = servicesEl.getElementsByTagName(SUDescriptorFactory.CONSUMES_TAG_NAME); + for ( int i=0; i < consumesNL.getLength(); ++i) { + Element consumesEl = (Element) consumesNL.item(i); + Consumes consumes = ConsumedService.createConsumedService(consumesEl); + suDesc.addConsumedService(consumes); + } + // add provides + NodeList providesNL = servicesEl.getElementsByTagName(SUDescriptorFactory.PROVIDES_TAG_NAME); + for ( int i=0; i < providesNL.getLength(); ++i) { + Element providesEl = (Element) providesNL.item(i); + Provides provides = ProvidedService.createProvidedService(providesEl); + suDesc.addProvidedService(provides); + } + + return suDesc; + } + } + /** + * Base class that implements the Service interface + */ + public static abstract class AbstractService implements Service { + + private QName mInterface; + private QName mServiceName; + private String mEndpointName; + + private AbstractService() { + } + /** + * Getter for property interfaceQName. + * @return Value of property interfaceQName. + */ + public QName getInterface() { + return this.mInterface; + } + + /** + * Setter for property interfaceQName. + * @param interfaceQName New value of property interfaceQName. + */ + protected void setInterface(QName interfaceQName) { + this.mInterface = interfaceQName; + } + + /** + * Getter for property serviceName. + * @return Value of property serviceName. + */ + public QName getServiceName() { + return this.mServiceName; + } + + /** + * Setter for property serviceName. + * @param serviceName New value of property serviceName. + */ + protected void setServiceName(QName serviceName) { + this.mServiceName = serviceName; + } + + /** + * Getter for property endpointName. + * @return Value of property endpointName. + */ + public String getEndpointName() { + return this.mEndpointName; + } + + /** + * Setter for property endpointName. + * @param endpointName New value of property endpointName. + */ + protected void setEndpointName(String endpointName) { + this.mEndpointName = endpointName; + } + + } + /** + * This class implements the Provides interface + */ + public static class ProvidedService + extends AbstractService + implements Provides { + protected ProvidedService(QName interfaceQName, QName serviceName, String endpointName) { + this.setInterface(interfaceQName); + this.setServiceName(serviceName); + this.setEndpointName(endpointName); + } + + @Override + public String toString() { + return "Provides :" + + "\n\t interface-name= " + getInterface() + + "\n\t service-name= " + getServiceName() + + "\n\t endpont-name= " + getEndpointName(); + } + + protected static Provides createProvidedService(Element providesEl) throws Exception { + + String ifName = providesEl.getAttribute(SUDescriptorFactory.INTERFACE_TAG_NAME); + String serviceName = providesEl.getAttribute(SUDescriptorFactory.SERVICE_TAG_NAME); + String endpointName = providesEl.getAttribute(SUDescriptorFactory.ENDPOINT_TAG_NAME); + if ( ifName == null || serviceName == null || endpointName == null ) { + throw new Exception("Invalid provides element: missing " + SUDescriptorFactory.INTERFACE_TAG_NAME + + " or " + SUDescriptorFactory.SERVICE_TAG_NAME + " or " + SUDescriptorFactory.ENDPOINT_TAG_NAME ); + } + QName ifQName = RuntimeHelper.resolveAttrQName(ifName, providesEl); + QName serviceQName = RuntimeHelper.resolveAttrQName(serviceName, providesEl); + + return new ProvidedService(ifQName, serviceQName, endpointName); + } + } + /** + * This class implements the Consumes interface. + */ + public static class ConsumedService + extends AbstractService + implements Consumes { + private String mLinkType; + protected ConsumedService(QName interfaceQName, + QName serviceName, String endpointName, String linkType) { + this.setInterface(interfaceQName); + this.setServiceName(serviceName); + this.setEndpointName(endpointName); + this.mLinkType = linkType; + } + + /** + * Getter for property linkType. + * @return Value of property linkType. + */ + public String getLinkType() { + return this.mLinkType; + } + + @Override + public String toString() { + return "Cosumes :" + + "\n\t interface-name= " + getInterface() + + "\n\t service-name= " + getServiceName() + + "\n\t endpont-name= " + getEndpointName() + + "\n\t link-type= " + getLinkType(); + } + + protected static Consumes createConsumedService(Element consumesEl) throws Exception { + + String ifName = consumesEl.getAttribute(SUDescriptorFactory.INTERFACE_TAG_NAME); + String serviceName = consumesEl.getAttribute(SUDescriptorFactory.SERVICE_TAG_NAME); + String endpointName = consumesEl.getAttribute(SUDescriptorFactory.ENDPOINT_TAG_NAME); + String linkType = consumesEl.getAttribute(SUDescriptorFactory.LINK_TYPE_TAG_NAME); + if ( linkType == null || linkType.trim().length() == 0 ) { + linkType = STANDARD_LINK; + } + + if ( ifName == null ) { + throw new Exception("Invalid consumes element: missing " + + SUDescriptorFactory.INTERFACE_TAG_NAME ); + } + if ( serviceName == null || endpointName == null ) { + throw new Exception("Invalid consumes element: missing " + + SUDescriptorFactory.SERVICE_TAG_NAME + " or " + + SUDescriptorFactory.ENDPOINT_TAG_NAME ); + } + + QName ifQName = RuntimeHelper.resolveAttrQName(ifName, consumesEl); + QName serviceQName = null; + if ( serviceName != null ) { + serviceQName = RuntimeHelper.resolveAttrQName(serviceName, consumesEl); + } + if ( serviceQName != null && endpointName != null && linkType != null ) { + if (!(STANDARD_LINK.equals(linkType) || + SOFT_LINK.equals(linkType) || HARD_LINK.equals(linkType)) ) { + throw new Exception("Invalid consumes attribute value" + + SUDescriptorFactory.LINK_TYPE_TAG_NAME + "=" + linkType); + } + } + return new ConsumedService(ifQName, serviceQName, endpointName, linkType); + } + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java new file mode 100644 index 000000000..a51cae714 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/deployment/ServiceUnit.java @@ -0,0 +1,461 @@ +/* + * ServiceUnit.java + * + */ + +package net.openesb.component.BindingComponent-archetype.common.deployment; + +import net.openesb.component.BindingComponent-archetype.common.RuntimeHelper; +import net.openesb.component.BindingComponent-archetype.common.deployment.SUDescriptor.Consumes; +import net.openesb.component.BindingComponent-archetype.common.deployment.SUDescriptor.Provides; +import net.openesb.component.BindingComponent-archetype.common.deployment.SUDescriptor.Service; +import net.openesb.component.BindingComponent-archetype.common.wsdl.WSDLProcessor; +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.jbi.management.DeploymentException; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; + +/** + * This is an abstract class that implements the service unit functionality in the component which + * processes the service unit artifacts and implement the actual service unit lifecycle functionality. + * The AbstractServiceUnitManager and its extended classes that implement the ServiceUnitManager + * functionality creates and maintains the reference to the concrete implementation of this class to + * invoke the functionality implemented by this class and its concrete implementation during the + * execution of the ServiceUnitMangers lifecycle methods by the jbi runtime. + *

+ * The main lifecycle methods of this class that will be called by the ServiceUnitManger implementation + * during the service unit deployment lifecycle are {@link #doload}, {@link #doDeploy}, {@link #doUndeploy}, + * {@link #doInit}, {@link #doStart}, {@link #doStop} and {@link #doShutdown} + *

+ * Service unit processing supported by this implementation is based on wsdl 1.1 deployments where the + * services provided and consumed in this service unit are described using wsdl 1.1 definitions. + *

+ * The main service unit artifacts that will be processed during deployment lifecycle of the service + * unit are 1.Service unit descriptor(jbi.xml) that describes the services provided and consumed by + * this service unit. 2.WSDL 1.1 document that describes the service definition 3.Component specific + * configurations related to services provided and consumed by this service unit. + *

+ * When the service unit is for Binding Component, the component specific configurations are read + * from the WSDL1.1 extensions defined in the WSDL document corresponding to the service provider + * or consumer deployed with this service unit. + *

+ * When the service unit is for Service Engine, the component specific configurations are read + * from the deployment artifacts such as xslt files and mapping files in the service unit zip file + * along with the WSDL document corresponding to the service provider or consumer deployed with this + * service unit. + * + * @see SUDescriptor + * @see Endpoint + * @see ProviderEndpoint + * @see ConsumerEndpoint + * @see WSDLProcessor + * @author chikkala + */ +public abstract class ServiceUnit { + /** Service Unit Name */ + private String mSUName; + /** Service Unit Root path passed by jbi runtime */ + private String mSURootPath; + /** service unit descriptor model unmarshalled from service unit jbi.xml */ + private SUDescriptor mSUDescriptor; + /** Map of Endpoint Key to ProviderEndpoint configurations in this service unit */ + private Map mProviderEndpointMap; + /** Map of Endpoint Key to ConsumerEndpoint configurations in this service unit */ + private Map mConsumerEndpointMap; + /** Map of Service Key to the WSDL Definition in this service unit */ + private Map mWSDLMap; + /** WSDLProcessor configured for this service unit to process wsdls in the service unit */ + private WSDLProcessor mWSDLProcessor; + /** + * + * @param suName + * @param suRootPath + */ + protected ServiceUnit(String suName, String suRootPath) { + this.mSUName = suName; + this.mSURootPath = suRootPath; + this.mSUDescriptor = null; + this.mWSDLMap = new HashMap(); + this.mProviderEndpointMap = new HashMap(); + this.mConsumerEndpointMap = new HashMap(); + } + /** returns service unit name + * @return service unit name + */ + public String getName() { + return this.mSUName; + } + /** returns service unit root path where the su artifacts are unzipped by the jbi runtime + * @return path to the service unit root directory. + */ + public String getSURootPath() { + return this.mSURootPath; + } + protected SUDescriptor createSUDescriptor() throws Exception { + File jbiXmlFile = new File(this.getSURootPath(), "META-INF/jbi.xml"); + String jbiXmlPath = jbiXmlFile.getAbsolutePath(); + return SUDescriptor.SUDescriptorFactory.getSUDescriptor(jbiXmlPath); + } + /** return the Service unit descriptor model that was read from the jbi.xml + * @return SUDescriptor + */ + public SUDescriptor getSUDescriptor() throws Exception { + if ( this.mSUDescriptor == null ) { + this.mSUDescriptor = createSUDescriptor(); + } + return this.mSUDescriptor; + } + public ProviderEndpoint getProviderEndpoint(String providerID) { + return this.mProviderEndpointMap.get(providerID); + } + public Collection getProviderEndpoints() { + return Collections.unmodifiableCollection(this.mProviderEndpointMap.values()); + } + public ConsumerEndpoint getConsumerEndpoint(String cosumerID) { + return this.mConsumerEndpointMap.get(cosumerID); + } + + public Collection getConsumerEndpoints() { + return Collections.unmodifiableCollection(this.mConsumerEndpointMap.values()); + } + /** + * @return Logger + */ + protected Logger getLogger() { + return RuntimeHelper.getLogger(); + } + /** + * extended classes implement this method to create the su specific WSDLProcessor. for examples, + * a su supporting binding component may have wsdl extensions that it want to registry for reading + * the configurations from the wsdl file. + * @return WSDLProcessor + * @see com.sun.jbi.sample.component.common.wsdl.WSDLProcessor + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + */ + protected WSDLProcessor createWSDLProcessor() { + return new WSDLProcessor(this.getSURootPath()); + } + /** + * return the WSDLProcessor reference by creates if it is not yet created. + * @return WSDLProcessor. + */ + public final WSDLProcessor getWSDLProcessor() { + if ( this.mWSDLProcessor == null ) { + this.mWSDLProcessor = createWSDLProcessor(); + } + return this.mWSDLProcessor; + } + /** + * loads the service unit artifacts into the SU model. AbstractServiceUnitManager implementation + * calls this method during the during deploy and init lifecycle methods when the service unit + * object is newly created. + */ + public void doLoad() throws DeploymentException { + try { + SUDescriptor suDesc = getSUDescriptor(); // load jbi.xml + loadServiceDefinitions(); // check if the wsdls are valid for corresponding services. + loadOtherArtifacts(); // additional validations specific to component deployment features. + loadEndpoints(); // create endpoints + } catch ( DeploymentException jbiEx) { + throw jbiEx; + } catch (Exception ex) { + throw new DeploymentException(ex); + } + } + /** extended classes implement this method to perform the su specific deployment related tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doDeploy() throws DeploymentException { + // NOOP. doLoad has done it all. + this.getLogger().fine("ServiceUnit.doDeploy"); + } + /** extended classes implement this method to perform the su specific undeployment related tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doUndeploy() throws DeploymentException { + //NOOP + this.getLogger().fine("ServiceUnit.doUndeploy"); + } + /** extended classes implement this method to perform the su specific initialization tasks in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doInit() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doInit"); + this.doInitEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on start in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doStart() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doStart"); + this.doActivateEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on stop in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doStop() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doStop"); + this.doDeactivateEndpoints(); + } + /** extended classes implement this method to perform the su specific tasks on shutdown in + * this method implementation. + * @throws DeploymentException on error. + */ + public void doShutdown() throws DeploymentException { + this.getLogger().fine("ServiceUnit.doShutdown"); + this.doCleanEndpoints(); + } + /** + * create the ProviderEndpoint that implement the service provider implementation specific to this su. + * @return ProviderEndpoint or null if the SU does not support the service provider access + */ + protected ProviderEndpoint createProviderEndpoint(Provides provides, Definition wsdlDef) { + return null; + } + /** + * create the ProviderEndpoint that implement the service consumer implementation specific to this su. + * @return ConsumerEndpoint or null if the SU does not support the service consumer access + */ + protected ConsumerEndpoint createConsumerEndpoint(Consumes consumes, Definition wsdlDef) { + return null; + } + /** + * generates the key based on the service to store the wsdl definitions . + */ + protected String getServiceKey(Service service) { + StringBuffer strBuff = new StringBuffer(); + strBuff.append(service.getInterface()).append("+"); + strBuff.append(service.getServiceName()).append("+"); + strBuff.append(service.getEndpointName()); + return strBuff.toString(); + } + /** + * looks up the wsdl definition loaded for this service. + */ + protected Definition findWSDLFor(Service service) throws WSDLException { + Definition wsdlDef = null; + String key = this.getServiceKey(service); + wsdlDef = this.mWSDLMap.get(key); + return wsdlDef; + } + + protected Definition findWSDL(List wsdlList, Service service, boolean ignoreEndpointLookup) { + Definition foundDef = null; + for ( Definition def : wsdlList ) { + if ( WSDLProcessor.isWSDLFor(def, service.getInterface(), service.getServiceName(), + ((ignoreEndpointLookup) ? null : service.getEndpointName()) ) ) { + foundDef = def; + break; + } + } + return foundDef; + } + /** + * loads the WSDL definitions corresponds to the service providers and consumers defined in the + * service unit descriptor. + */ + protected void loadServiceDefinitions() throws Exception { + + this.mWSDLMap = new HashMap(); + + WSDLProcessor wsdlProcessor = getWSDLProcessor(); + List wsdlList = wsdlProcessor.readWSDLs(this.getSURootPath()); + this.getLogger().fine("Number of wsdl definitions in service unit " + wsdlList.size()); + + List services = new ArrayList(); + services.addAll(this.getSUDescriptor().getProvidedServices()); + services.addAll(this.getSUDescriptor().getConsumedServices()); + + boolean isForBinding = this.getSUDescriptor().isForBindingComponent-archetype(); + this.getLogger().fine("Is this service unit for Binding? " + isForBinding); + + for ( Service service : services ) { + this.getLogger().fine("Looking up WSDL for service " + service); + boolean ignoreEndpointLookup = false; + boolean providerAtEngine = false; + if ( !isForBinding && service instanceof Provides ) { + ignoreEndpointLookup = true; + providerAtEngine = true; + } + Definition def = findWSDL(wsdlList, service, ignoreEndpointLookup); + if ( def == null ) { + throw new Exception("WSDL Definition not found for " + service); + } + this.mWSDLMap.put(getServiceKey(service), def); + if ( providerAtEngine ) { + // provider at engine. so add engine binding and endpoint to the wsdl + wsdlProcessor.createServiceEngineBinding(def, + service.getInterface(), service.getServiceName(), service.getEndpointName()); + } + } + } + /** extended classes implement this method to perform the su specific artifacts validation in + * this method implementation. + * @throws DeploymentException on error. + */ + protected void loadOtherArtifacts() throws DeploymentException { + // nothing to validate further. + this.getLogger().fine("ServiceUnit.loadOtherArtifacts"); + } + /** + * creates ProviderEndpoint and ConsumerEndpoint objects corresponding to the service providers + * and consumers described in the su descriptor ( jbi.xml ) + */ + protected void loadEndpoints() throws Exception { + + this.mProviderEndpointMap = new HashMap(); + this.mConsumerEndpointMap = new HashMap(); + + Collection providesList = this.getSUDescriptor().getProvidedServices(); + for ( Provides provides : providesList ) { + Definition wsdlDef = findWSDLFor(provides); + if ( wsdlDef == null ) { + throw new DeploymentException("WSDL Definitions not found for " + provides); + } + ProviderEndpoint provider = createProviderEndpoint(provides, wsdlDef); + this.mProviderEndpointMap.put(provider.getID(), provider); + } + + Collection consumesList = this.getSUDescriptor().getConsumedServices(); + for ( Consumes consumes : consumesList ) { + Definition wsdlDef = findWSDLFor(consumes); + if ( wsdlDef == null ) { + throw new DeploymentException("WSDL Definitions not found for " + consumes); + } + ConsumerEndpoint consumer = createConsumerEndpoint(consumes, wsdlDef); + this.mConsumerEndpointMap.put(consumer.getID(), consumer); + } + } + /** + * initializes the Endpoint objects created corresponding to the consumer and providers defined + * in the su descriptor + */ + protected void doInitEndpoints() throws DeploymentException { + // init endpoints. if any initialization fails, rollback the already inited endpoints + List initedEndpoints = new ArrayList(); + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getProviderEndpoints()); + allEndpoints.addAll(this.getConsumerEndpoints()); + + for ( Endpoint endpoint : allEndpoints ) { + try { + endpoint.init(); + initedEndpoints.add(endpoint); + } catch ( Exception initEx) { + doCleanEndpoints(initedEndpoints); + throw new DeploymentException(initEx); + } + } + + } + /** + * invokes activates method of all provider and consumer endpoint object in this su. if there is + * and error activating any one the endpoints, it deactivates the already activated ones and throws + * the error + */ + protected void doActivateEndpoints() throws DeploymentException { + // activate providers first and then consumers + List activatedEndpoints = new ArrayList(); + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getProviderEndpoints()); + allEndpoints.addAll(this.getConsumerEndpoints()); + + for ( Endpoint endpoint : allEndpoints ) { + try { + endpoint.activate(); + activatedEndpoints.add(endpoint); + } catch ( Exception actEx) { + doDeactivateEndpoints(activatedEndpoints); + throw new DeploymentException(actEx); + } + } + } + /** + * invokes deactivate method on the list of Endpoint objects passed to this method + */ + protected void doDeactivateEndpoints(List endpoints) { + for ( Endpoint endpoint : endpoints ) { + try { + endpoint.deactivate(); + } catch(Exception ex) { + // ignore the exception and log it. + this.getLogger().log(Level.FINE, ex.getMessage(), ex); + } + } + } + /** + * invokes deactivate method on the all consumer and provider endpoint objects + */ + protected void doDeactivateEndpoints() { + // deactivate consumers first and then the providers + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getConsumerEndpoints()); + allEndpoints.addAll(this.getProviderEndpoints()); + doDeactivateEndpoints(allEndpoints); + } + /** + * invokes clean method on the list of endpoint objects + */ + protected void doCleanEndpoints(List endpoints) { + for ( Endpoint endpoint : endpoints ) { + try { + endpoint.clean(); + } catch(Exception ex) { + // ignore the exception and log it. + this.getLogger().log(Level.FINE, ex.getMessage(), ex); + } + } + } + /** + * invokes clean method on the all consumer and provider endpoint objects in this su. + */ + protected void doCleanEndpoints() { + + List allEndpoints = new ArrayList(); + allEndpoints.addAll(this.getConsumerEndpoints()); + allEndpoints.addAll(this.getProviderEndpoints()); + doCleanEndpoints(allEndpoints); + } + /** + * prints the service unit description + */ + protected final String printDetails() { + + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + + out.println("ServiceUnit Name : " + this.getName()); + out.println("ServiceUnit Root : " + this.getSURootPath()); + + SUDescriptor suDesc = null; + try { + suDesc = this.getSUDescriptor(); + for ( SUDescriptor.Consumes consumer : suDesc.getConsumedServices()) { + out.println(consumer); + } + for ( SUDescriptor.Provides provides : suDesc.getProvidedServices()) { + out.println(provides); + } + } catch (Exception ex) { + ex.printStackTrace(out); + } + return writer.getBuffer().toString(); + } + + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java new file mode 100644 index 000000000..e1c293183 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensibilityElement.java @@ -0,0 +1,41 @@ +/* + * AbstractExtensibilityElement.java + */ + +package net.openesb.component.BindingComponent-archetype.common.wsdl; + +import javax.wsdl.extensions.ExtensibilityElement; +import javax.xml.namespace.QName; + +/** + * This is an abstract class which can be extended to create jwsdl (wsdl4j's) extension elements model to + * read/write the wsdl extension elements in wsdl 1.1 xml. + * + * @author chikkala + */ +public abstract class AbstractExtensibilityElement implements ExtensibilityElement, java.io.Serializable { + public static final long serialVersionUID = 1; + private QName mElementType; + private Boolean mRequired; + + /** Creates a new instance of AbstractExtensibilityElement */ + protected AbstractExtensibilityElement() { + } + + public void setElementType(QName elementType) { + this.mElementType = elementType; + } + + public QName getElementType() { + return this.mElementType; + } + + public void setRequired(Boolean required) { + this.mRequired = required; + } + + public Boolean getRequired() { + return this.mRequired; + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java new file mode 100644 index 000000000..8cb120d92 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionRegistry.java @@ -0,0 +1,42 @@ +/* + * AbstractExtensionRegistry.java + */ + +package net.openesb.component.BindingComponent-archetype.common.wsdl; + +import java.util.List; +import javax.wsdl.extensions.ExtensionRegistry; + +/** + * This is the abstract class used to add the wsdl extension serializers and deserializers to the + * wsdl extension registry configured to read/write wsdl extensions into a know java model. + * @see AbstractExtensionSerializer + * @see WSDLProcessor + * @author chikkala + */ +public abstract class AbstractExtensionRegistry extends ExtensionRegistry { + + /** Creates a new instance of AbstractSerializer + * it calls the createSerializers method to get the list of + * serializers and then call registerSerializer on each AbstractExtensionSerializer + * to register them with this registry. + * @see AbstractExtensionSerializer#registerSerializer + */ + protected AbstractExtensionRegistry() { + super(); + List list = createSerializers(); + for (AbstractExtensionSerializer ser : list ) { + ser.registerSerializer(this); + } + // register ServiceEngine Binding serializers + AbstractExtensionSerializer seBindingSer = new SEBindingExt.SEBindingExtSerializer(); + seBindingSer.registerSerializer(this); + } + /** + * create wsdl extension serializers for each extension element to register with the extension + * registry. + * @return List of AbstractExtensionSerializer objects for serializing/deserializing the wsdl extensions. + * @see AbstractExtensionSerializer + */ + protected abstract List createSerializers(); +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java new file mode 100644 index 000000000..1c531d1c4 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractExtensionSerializer.java @@ -0,0 +1,120 @@ +/* + * AbstractExtensionSerializer.java + */ + +package net.openesb.component.BindingComponent-archetype.common.wsdl; + +import java.io.PrintWriter; +import java.io.Serializable; +import java.util.Set; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionDeserializer; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.extensions.ExtensionSerializer; +import javax.xml.namespace.QName; +import org.w3c.dom.Attr; +import org.w3c.dom.Element; + +/** + * This class is an abstract class that should be extended to implements extension serializer and + * deserializer. This class implements the code required for registering the serializer and deserializer + * implemented by this class. THe AbstractExtensionRegistry class calls the #registerSerializer method + * to register the concrete implementation of this class with extension registry. + * @see AbstractExtensionRegistry + * @author chikkala + */ +public abstract class AbstractExtensionSerializer + implements ExtensionSerializer, ExtensionDeserializer, Serializable { + + public static final long serialVersionUID = 1; + + private Class mParentType; + private Class mExtensionType; + private QName mElementType; + + /** Creates a new instance of AbstractSerializer */ + public AbstractExtensionSerializer(Class parentType, QName elementType, Class extensionType) { + this.mParentType = parentType; + this.mElementType = elementType; + this.mExtensionType = extensionType; + } + + public Class getParentType() { + return this.mParentType; + } + public QName getElementType() { + return this.mElementType; + } + public Class getExtensionType() { + return this.mExtensionType; + } + + public void registerSerializer(ExtensionRegistry extReg) { + extReg.registerSerializer(this.mParentType, this.mElementType, this); + extReg.registerDeserializer(this.mParentType, this.mElementType, this); + extReg.mapExtensionTypes(this.mParentType, this.mElementType, this.mExtensionType); + } + + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg ) throws WSDLException { + // DO NOTHING. Binding component runtime does not need to serialize the wsdl extensions. + } + + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + return null; + } + + public static String getAttribute(Element el, String attrName) { + String attrValue = null; + Attr attr = el.getAttributeNode(attrName); + if ( attr != null ) { + attrValue = attr.getValue(); + } + return attrValue; + } + + protected String getNamespacePrefix(Definition def, String namespaceURI, String defPrefix) { + String prefix = null; + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + Set keySet = def.getNamespaces().keySet(); + String newPrefix = "ns"; + if ( defPrefix != null && defPrefix.trim().length() > 0 ){ + newPrefix = defPrefix; + } + prefix = newPrefix; + for ( int i=0; i < Integer.MAX_VALUE; ++i) { + if (!keySet.contains(prefix)) { + break; + } else { + prefix = newPrefix + i; + } + } + } + return prefix; + } + /** + * @return the name with the prefix defined for the namespaceURI in the wsdl definition. + * @throws WSDLException if the prefix not found in the wsdl definition. note that the + * default prefix is an empty string. + */ + protected String getQualifiedName(Definition def, + String namespaceURI, String localName) throws WSDLException { + String prefix = null; + if (namespaceURI != null && !namespaceURI.equals("")) { + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + throw new WSDLException(WSDLException.OTHER_ERROR, + "Can not find prefix in WSDL Definition for " + namespaceURI); + } + } + if ( prefix != null && !prefix.equals("")) { + return prefix + ":" + localName; + } else { + return localName; + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java new file mode 100644 index 000000000..f8c48f0a1 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/AbstractNormalizer.java @@ -0,0 +1,226 @@ +/* + * AbstractNormalizer.java + */ + +package net.openesb.component.BindingComponent-archetype.common.wsdl; + +import java.util.ArrayList; +import java.util.List; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Part; +import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.dom.DOMSource; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * This is an abstract class that implements most of the functionality to normalize the binding protocol + * specific concrete message to jbi wrapper and and denormalize jbi wrapper to the concrete binding + * protocol specific message. + *

+ * The extended classes specific to particular binding protocol will be used when a jbi binding + * component is sending and receiving messages from the external service providers and consumers using + * a particular binding protocol known to this class. Extended implementation of this class should make + * use of the helper methods in this class in normalizing and denormalizing the messages. + * @see JMXBindingNormalizer + * @author chikkala + */ +public abstract class AbstractNormalizer { + + public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/"; + /** wsdl definition to use when normalizing and denormalizing */ + private Definition mWSDL; + /** Binding definition to use when normalizing and denormalizing */ + private Binding mBinding; + + private AbstractNormalizer() {} + /** Creates a new instance of JMXBCNormalizer */ + public AbstractNormalizer(Definition wsdl, Binding binding) { + this.mWSDL = wsdl; + this.mBinding = binding; + } + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete mssage of a particular binding protocol. + */ + public abstract void normalizeInput(Operation operation, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete message of a particular binding protocol. + */ + public abstract void normalizeOutput(Operation operation, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * normalize the binding protocol specific concrete message to jbi wrapper. + * @param operation wsdl operation for which a concrete message should be normalized. + * @param normMsg NoramalizedMessage which will be configurate with normalized data from + * the concrete message + * @param msgSource concrete message of a particular binding protocol. + */ + public abstract void normalizeFault(Operation operation, String faultName, NormalizedMessage normMsg, DOMSource msgSource) + throws MessagingException; + /** + * denormalize the normalized message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be de-normalized. + * @param normMsg NormalizedMessage which should be used to create de-normalized message. + */ + public abstract DOMSource denormalizeInput(Operation operation, NormalizedMessage normMsg) + throws MessagingException; + /** + * denormalize the normalized message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be denormalized. + * @param normMsg NormalizedMessage which should be used to create denormalized message. + */ + public abstract DOMSource denormalizeOutput(Operation operation, NormalizedMessage normMsg) + throws MessagingException; + + /** + * denormalized the normalized fault message into a concrete message for a particular binding protocol + * @param operation wsdl operation for which a concrete message should be denormalized. + * @param normMsg NormalizedMessage which should be used to create denormalized message. + */ + public abstract DOMSource denormalizeFault(Operation operation, String faultName, NormalizedMessage normMsg) + throws MessagingException; + /** + * @return the wsdl definition to use in normalizing and denormalizing the message + */ + protected Definition getWSDL() { + return this.mWSDL; + } + /** + * @return the wsdl binding definition to use in normalizing and denormalizing the message + */ + protected Binding getBinding() { + return this.mBinding; + } + /** + * create and add message parts to the jbiWrapper according to the abstract message model. This + * method assumes that the each element in the msgParts list passed to it is mapped to the part + * of the abstract wsdl message and uses the type or element attribute of the abstract message to + * determine whether the element is actual part element or a wrapped part type. + * Use this method in normalizing the concrete protocol specific message to jbi wrapper message. + * @param jbiWrapper object that holds the jbi wrapper information. + * @param wsdlMsg abstract message from the wsdl definition + * @param msgParts actual message parts from the concrete message + */ + protected void addMessagePartsToJBIWrapper(WSDL11JBIWrapper jbiWrapper, Message wsdlMsg, List msgParts) throws MessagingException { + List wsdlParts = wsdlMsg.getOrderedParts(null); + for ( int i=0; i < wsdlParts.size(); ++i ) { + Part wsdlPart = (Part) wsdlParts.get(i); + if ( i >= msgParts.size() ) { + throw new MessagingException("missing message content for part " + wsdlPart.getName()); + } + Element msgPart = msgParts.get(i); + if ( wsdlPart.getElementName() != null ) { + jbiWrapper.appendPart(msgPart); + } else { + // it is type. + // check the element name is same as part + if ( !wsdlPart.getName().equals(msgPart.getLocalName()) ) { + throw new MessagingException("mismatched message content for part " + wsdlPart.getName()); + } + if ( !wsdlMsg.getQName().getNamespaceURI().equals(msgPart.getNamespaceURI()) ) { + throw new MessagingException("mismatched message content namespace for part " + wsdlPart.getName()); + } + // check the content is text or element. + List partContent = getChildElements(msgPart); + if ( partContent.size() > 0 ) { + // add content as part elements + jbiWrapper.appendPart(partContent); + } else { + // add the content as text + jbiWrapper.appendPart(msgPart.getTextContent()); + } + } + } + } + /** + * extracts the message parts from the jbiWrapper according to the abstract wsdl message + * definition passed to it. Use this method in denormalizing the jbi wrapper message into the + * binding protocol specific concrete message. + * @param jbiWrapper jbi wrapper object that contains message parts and the message type information. + * @param wsdlMsg abstract wsdl message definition to use in constructing the part elements. + */ + protected List getMessagePartsFromJBIWrapper(WSDL11JBIWrapper jbiWrapper, Message wsdlMsg) + throws MessagingException, ParserConfigurationException { + + List msgParts = new ArrayList(); + int jbiPartCount = jbiWrapper.getPartCount(); + List wsdlParts = wsdlMsg.getOrderedParts(null); + QName msgType = jbiWrapper.getType(); + if (!wsdlMsg.getQName().getNamespaceURI().equals(msgType.getNamespaceURI())) { + throw new MessagingException("Namespace mismatch between jbi wrapper message type and wsdl message"); + } + Document newDoc = jbiWrapper.getDocumentBuilder().newDocument(); + for ( int i=0; i < wsdlParts.size(); ++i ) { + Part wsdlPart = (Part) wsdlParts.get(i); + if ( i >= jbiPartCount ) { + throw new MessagingException("missing message content for part " + wsdlPart.getName()); + } + if ( wsdlPart.getElementName() != null ) { + msgParts.add(jbiWrapper.getPartAsElement(i)); + } else { + // it is type. create a new element for a typed part + // check the element name is same as part + String prefix = msgType.getPrefix(); + String nsURI = msgType.getNamespaceURI(); + String localName = wsdlPart.getName(); + Element partEl = newDoc.createElementNS(nsURI, prefix + ":" + localName); + partEl.setAttributeNS(XMLNS_NS, "xmlns:"+prefix, nsURI); + NodeList partContent = jbiWrapper.getPart(i); + appendChildren(partEl, partContent, newDoc, true); + msgParts.add(partEl); + } + } + return msgParts; + } + /** + * utility method that can append the nodeList passed to it to the element children. + * @param el element node to which the nodeList should be appended + * @param doc the document object that should be used to import the nodeList + * @param importNode true if the nodeList should be imported while appending the nodeList to the + * element children. false if no import is necessary. + */ + protected void appendChildren(Element el, NodeList nodeList, Document doc, boolean importNode) { + + for ( int pIdx = 0; pIdx < nodeList.getLength(); ++pIdx) { + Node node = nodeList.item(pIdx); + if ( importNode ) { + node = doc.importNode(node, true); + } + el.appendChild(node); + } + } + /** + * @param el element from which to extract the child elements + * @return List list of child Element nodes. + */ + protected List getChildElements(Element el) { + List list = new ArrayList(); + NodeList nodeList = el.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if (!(node instanceof Element) ){ + continue; + } + list.add((Element)node); + } + return list; + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java new file mode 100644 index 000000000..7455a5707 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/SEBindingExt.java @@ -0,0 +1,96 @@ +/* + * SEBindingExt.java + */ + +package net.openesb.component.BindingComponent-archetype.common.wsdl; + +import java.io.PrintWriter; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation classes implement wsdl 1.1 extension model for the + * jbi service engine binding that is defined in jsr 208(sec. 5.5.6.1). to read/write concrete binding + * element in the wsdl definition for the service endpoint binding provided by the service engine. + * The wsdl definition with this binding information can be used in providing the service provider + * metadata returned by the service engine in Component.getServiceDescription. + *

+ * AbstractExtensionRegistry by default include this extension serializers in the + * registry to read/write this service engine binding type in the wsdl definition. + *

+ * During a service unit deployment/initialization in the service engine, the deployed wsdl definition + * is loaded and modified to provide this binding for the service provided by the engine. + * + * @see WSDLProcessor#createServiceEngineBinding + * @see AbstractExtensionRegistry + * @see com.sun.jbi.sample.component.common.deployment.ServiceUnit#loadServiceDefinitions + * @author chikkala + */ +public interface SEBindingExt extends ExtensibilityElement, java.io.Serializable { + + public static final String NS_URI = "http://java.sun.com/xml/ns/jbi/binding/service+engine"; + public static final String NS_DEF_PREFIX = "jbise"; + /** Element names. */ + public static final String EL_BINDING_EXT = "binding"; + /**Qualified element names.*/ + public static final QName QN_BINDING_EXT = new QName(NS_URI, EL_BINDING_EXT); + + public static class SEBindingExtImpl extends AbstractExtensibilityElement implements SEBindingExt { + + public SEBindingExtImpl() { + setElementType(QN_BINDING_EXT); + } + @Override + public String toString() { + StringBuffer buff = new StringBuffer(); + buff.append("<"+NS_DEF_PREFIX+":"+EL_BINDING_EXT); + buff.append("/>"); + return buff.toString(); + } + /** + * creates and adds the jbi service engine binding extensibility element to the wsdl definition + * under specified binding definition. + */ + public static SEBindingExtImpl addExtensibilityElement(Definition wsdlDef, Binding binding) { + SEBindingExtImpl bindingExt = new SEBindingExt.SEBindingExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, binding, bindingExt, SEBindingExt.NS_DEF_PREFIX); + return bindingExt; + } + } + /** + * serializer and descrializer implementation for the binding extension element. + */ + public static class SEBindingExtSerializer extends AbstractExtensionSerializer { + + public SEBindingExtSerializer() { + super(Binding.class, QN_BINDING_EXT, SEBindingExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + SEBindingExt extObj = (SEBindingExt)extReg.createExtension(parentType, elementType); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg ) throws WSDLException { + + String elName = getQualifiedName(def, NS_URI, EL_BINDING_EXT); + + SEBindingExt extObj = (SEBindingExt)extension; + + StringBuffer buff = new StringBuffer(); + buff.append("<" + elName ); + buff.append("/>"); + pw.println(buff.toString()); + } + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java new file mode 100644 index 000000000..8ef35eb17 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/WSDL11JBIWrapper.java @@ -0,0 +1,468 @@ +/* + * WSDL11JBIWrapper.java + * + */ + +package net.openesb.component.BindingComponent-archetype.common.wsdl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.dom.DOMSource; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +/** + * This class wraps the wsdl11 messages to the jbi wrapper message suitable for + * processing in the wsdl2.0 model of the normalized message in jbi as defined in jsr208 like + * + * + * + * + * + * + * + * + * + * + * @author chikkala + */ +public class WSDL11JBIWrapper { + + public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/"; + public static final String WRAPPER_NAMESPACE = "http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper"; + public static final String DEF_NS_PREFIX = "jbiwrp"; + public static final String DEF_MESSAGE_NS_PREFIX = "msgns"; + public static final String JBI_MESSAGE_EL = "message"; + public static final String JBI_PART_EL = "part"; + public static final String VERSION_ATTR = "version"; + public static final String VERSION_ATTR_VALUE = "1.0"; + public static final String TYPE_ATTR = "type"; + public static final String NAME_ATTR = "name"; + + private static DocumentBuilder sDocBuilder = null; + /** qname of message attribute from wsdl:input, wsdl:output or wsdl:fault */ + private QName mType; + /** optional name attribute from wsdl:input, wsdl:output or wsdl:fault */ + private String mName; + /** each parts contents as node list */ + List mPartConentList = new ArrayList(); + + /** Creates a new instance of WSDL11JBIWrapper */ + public WSDL11JBIWrapper() { + } + /** creates the namespace aware document builder. extended classes can override this method + * to return the doc builder created else where. + */ + protected DocumentBuilder createDocumentBuilder() throws ParserConfigurationException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + return factory.newDocumentBuilder(); + } + /** return the document builder + * @return DocumentBuilder + */ + public final DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { + if ( WSDL11JBIWrapper.sDocBuilder == null ) { + WSDL11JBIWrapper.sDocBuilder = createDocumentBuilder(); + } + return WSDL11JBIWrapper.sDocBuilder; + } + /** + * @return type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + */ + public QName getType() { + return this.mType; + } + /** + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + */ + public void setType(QName type) { + this.mType = type; + } + /** @return name attribute from wsdl:input, wsdl:output or wsdl:fault. or null if not set. */ + public String getName() { + return this.mName; + } + /** + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault. can be null. + */ + public void setName(String name) { + this.mName = name; + } + /** + * appends part content as node list + */ + public void appendPart(NodeList partContent) { + this.mPartConentList.add(partContent); + } + /** + * append part content from the List of nodes + */ + public void appendPart(List partContent) { + this.mPartConentList.add(new NodeListImpl(partContent)); + } + /** + * append part content as element + */ + public void appendPart(Element partContent) { + this.mPartConentList.add(new NodeListImpl(partContent)); + } + /** + * append part content from DOMSource + */ + public void appendPart(DOMSource partContent) { + Element partConentEl = getElement(partContent.getNode()); + this.mPartConentList.add(new NodeListImpl(partConentEl)); + } + /** + * append part content as text node. + */ + public void appendPart(String partContent) { + Text textContent = null; + try { + textContent = this.getDocumentBuilder().newDocument().createTextNode(partContent); + } catch (ParserConfigurationException ex) { + ex.printStackTrace(); + } + if ( textContent != null ) { + this.mPartConentList.add(new NodeListImpl(textContent)); + } + } + /** + * append list of part contents each is a NodeList to the parts + */ + public void appendParts(List partContentList) { + this.mPartConentList.addAll(partContentList); + } + /** + * returned the ordered list of part contents. + */ + public List getParts() { + return Collections.unmodifiableList(this.mPartConentList); + } + /** + * return the number of parts + */ + public int getPartCount() { + return this.mPartConentList.size(); + } + /** + * return the part content at a particular index as NodeList. + */ + public NodeList getPart(int idx) { + return this.mPartConentList.get(idx); + } + /** + * return part context at a particular index as text + */ + public String getPartAsText(int idx) { + NodeList partNodes = getPart(idx); + Document doc; + try { + doc = this.getDocumentBuilder().newDocument(); + Element el = doc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_PART_EL); + for ( int i=0; i < partNodes.getLength(); ++i) { + el.appendChild(partNodes.item(i)); + } + return el.getTextContent(); + } catch (ParserConfigurationException ex) { + return null; + } + } + /** + * return part context at a particular index as Element + */ + public Element getPartAsElement(int idx) { + Element contentEl = null; + NodeList partNodes = getPart(idx); + for ( int i=0; i < partNodes.getLength(); ++i) { + Node node = partNodes.item(i); + if ( node instanceof Element) { + contentEl = (Element)node; + break; + } + } + return contentEl; + } + /** + * creates Document from this wrapper object. Before calling this method, + * the type, name (optional) and parts contents should be set. + * @return Document containing the wsdl 11 wrapper xml + */ + public Document toDocument() throws ParserConfigurationException { + + Document wrapperDoc = getDocumentBuilder().newDocument(); + Element jbiMessage = wrapperDoc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_MESSAGE_EL); + jbiMessage.setAttribute(VERSION_ATTR, VERSION_ATTR_VALUE); + wrapperDoc.appendChild(jbiMessage); + + QName type = this.getType(); + if ( type == null ) { + type = new QName("", "", DEF_MESSAGE_NS_PREFIX); + } + // set the jbiMessage attributes + String prefix = type.getPrefix(); + if (prefix == null || prefix.length() == 0) { + prefix = DEF_MESSAGE_NS_PREFIX; + } + jbiMessage.setAttribute(TYPE_ATTR, prefix + ":" + type.getLocalPart()); + jbiMessage.setAttributeNS( XMLNS_NS, "xmlns:" + prefix, type.getNamespaceURI()); + + String name = this.getName(); + if (name != null && name.trim().length() > 0 ) { + jbiMessage.setAttribute(NAME_ATTR, name); + } + + List partContentList = this.getParts(); + for ( NodeList nodeList : partContentList ) { + // set jbi part message + Element jbiPart = wrapperDoc.createElementNS(WRAPPER_NAMESPACE, DEF_NS_PREFIX + ":" + JBI_PART_EL); + jbiMessage.appendChild(jbiPart); + for ( int i =0; i < nodeList.getLength(); ++i ) { + Node importedMsgNode = wrapperDoc.importNode(nodeList.item(i), true); + jbiPart.appendChild(importedMsgNode); + } + } + + return wrapperDoc; + + } + /** + * creates DOMSource from this wrapper object. Before calling this method, + * the type, name (optional) and parts contents should be set. + * @return DOMSource containing the wsdl 11 wrapper xml + */ + public DOMSource toDOMSource() throws ParserConfigurationException { + DOMSource wrappedSource = new DOMSource(); + wrappedSource.setNode(toDocument()); + return wrappedSource; + } + /** + * return Element node from a document node or non document. Use to extract + * the message root element. + * @root node from which the Element node will be extracted. + * @return Element node. + */ + public static Element getElement(Node root) { + Element msgEl = null; + if ( root instanceof Document) { + msgEl = ((Document)root).getDocumentElement(); + } else if (root instanceof Element) { + msgEl = (Element)root; + } else { + NodeList nodeList = root.getChildNodes(); + for ( int i=0; i < nodeList.getLength(); ++i) { + Node node = nodeList.item(i); + if ( node instanceof Element ) { + msgEl = (Element) node; + break; + } + } + } + return msgEl; + } + /** + * creates wrapper object from the DOMSource that has wsdl 11 wrapper xml. + * @param wrappedMsg wsdl 11 wrapper xml as DOMSource + * @return WSDL11JBIWrapper representing the wrapper xml. + */ + public static WSDL11JBIWrapper sourceToWrapper(DOMSource wrappedMsg) { + Element jbiMessage = getElement(wrappedMsg.getNode()); + if ( jbiMessage == null ) { + return null; + } + String nsURI = jbiMessage.getNamespaceURI(); + String tagName = jbiMessage.getLocalName(); + if (!WRAPPER_NAMESPACE.equals(nsURI) || !JBI_MESSAGE_EL.equals(tagName)) { + return null; + } + String name = jbiMessage.getAttribute(NAME_ATTR); + String typeQN = jbiMessage.getAttribute(TYPE_ATTR); + String typePrefix = ""; + String typeName = ""; + if ( typeQN != null && typeQN.trim().length() > 0 ) { + int idx = typeQN.indexOf(':'); + if ( idx >= 0 ) { + typePrefix = typeQN.substring(0, idx); + if ( typeQN.length() > idx ) { + typeName = typeQN.substring(idx+1); + } + } else { + typePrefix = ""; + typeName = typeQN; + } + } + String typeURI = jbiMessage.getAttribute("xmlns:" + typePrefix); + QName typeQName = new QName(typeURI, typeName, typePrefix); + + WSDL11JBIWrapper wrapper = new WSDL11JBIWrapper(); + wrapper.setName(name); + wrapper.setType(typeQName); + NodeList jbiPartList = jbiMessage.getElementsByTagNameNS(WRAPPER_NAMESPACE, JBI_PART_EL); + for ( int i=0; i < jbiPartList.getLength(); ++i) { + Node jbiPart = jbiPartList.item(i); + wrapper.appendPart(jbiPart.getChildNodes()); + } + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object and sets the type and name of the object + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name ) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = new WSDL11JBIWrapper(); + wrapper.setName(name); + wrapper.setType(type); + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object. useful when the message has one part and the + * part content has multiple child element. + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @param partContent part content as node list + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name, NodeList partContent) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name); + wrapper.appendPart(partContent); + return wrapper; + } + /** + * creates the WSDL11JBIWrapper object. useful when the message has one part and the + * part content is a single element + * @param type qname of message attribute from wsdl:input, wsdl:output or wsdl:fault + * @param name optional name attribute from wsdl:input, wsdl:output or wsdl:fault + * @param partContent part content as node list + * @return the jbi message wrapper object + */ + public static WSDL11JBIWrapper createWrapper(QName type, String name, Element msgEl) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name, new WSDL11JBIWrapper.NodeListImpl(msgEl)); + return wrapper; + } + + public static WSDL11JBIWrapper createWrapper(QName type, String name, DOMSource inputSource) throws ParserConfigurationException { + WSDL11JBIWrapper wrapper = createWrapper(type, name); + Node msgNode = getElement(inputSource.getNode()); + NodeList nodeList = new WSDL11JBIWrapper.NodeListImpl(msgNode); + wrapper.appendPart(nodeList); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations input element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createInputWrapper(Operation operation) throws ParserConfigurationException { + QName type = null; + String name = null; + + Input input = operation.getInput(); + if ( input == null ) { + return null; + } + name = input.getName(); + Message wsdlMsg = input.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations output element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createOutputWrapper(Operation operation) throws ParserConfigurationException { + QName type = null; + String name = null; + + Output output = operation.getOutput(); + if ( output == null) { + return null; + } + name = output.getName(); + Message wsdlMsg = output.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * creates the wrapped message using the wsdl4j operations output element for type and name. + * @param msg DOMSource for the unwrapped message + * @param operation wsdl4j operation object representing the operation of the PortType + * @param faultName fault name, can be null to look for the fault with no name. + * @return DOMSource wrapped message as DOMSource + */ + public static WSDL11JBIWrapper createFaultWrapper(Operation operation, String faultName) throws ParserConfigurationException { + QName type = null; + String name = null; + @SuppressWarnings("unchecked") + Map faultMap = operation.getFaults(); + Fault fault = faultMap.get(faultName); + + if ( fault == null ) { + return null; + } + name = fault.getName(); + Message wsdlMsg = fault.getMessage(); + type = wsdlMsg.getQName(); + + WSDL11JBIWrapper wrapper = createWrapper(type, name); + return wrapper; + } + /** + * NodeList implementation. + */ + public static class NodeListImpl extends ArrayList implements NodeList { + + public NodeListImpl() { + super(); + } + + public NodeListImpl(Node aNode) { + super(); + if (aNode != null) { + this.add(aNode); + } + } + + public NodeListImpl(List nodes) { + if (nodes != null) { + this.addAll(nodes); + } + } + + public int getLength() { + return this.size(); + } + + public Node item(int idx) { + return this.get(idx); + } + + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java new file mode 100644 index 000000000..494234431 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/common/wsdl/WSDLProcessor.java @@ -0,0 +1,416 @@ +/* + * WSDLProcessor.java + */ + +package net.openesb.component.BindingComponent-archetype.common.wsdl; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ElementExtensible; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.wsdl.xml.WSDLWriter; +import javax.xml.namespace.QName; + +/** + * This class is used to configure jwsdl(wsdl4j) to read and process wsdl documents with wsdl extensions. + * It provides set of helper methods to read and process the wsdl definitions from files with .wsdl + * extension from a specified directory. + *

+ * A Binding Component that is processing the wsdl extensions for its deployment configuration would + * extend this class and provide the required ExtensionRegistry that will have the extension serializers + * and deserializers configured to read/write the extensions from/to the java model. + *

+ * A Service Engine that is processing the wsdl during deployment can directly use this class + * to process the wsdl as the default implementation returned by this class configures the wsdl extension + * registry to read/write the service engine binding extensions. + * + * @see AbstractExtensionRegistry + * @see SEBindingExt + * @author chikkala + */ +public class WSDLProcessor { + + private String mXmlCatalogPath = "xml-catalog.xml"; + private String mWsdlDirPath = ""; + private WSDLReader mReader; + + /** Creates a new instance of WSDLProcessor + */ + public WSDLProcessor(String wsdlDir) { + this(wsdlDir, null); + } + /** Creates a new instance of WSDLProcessor + */ + public WSDLProcessor(String wsdlDir, String xmlCatPath) { + if ( wsdlDir != null ) { + this.mWsdlDirPath = wsdlDir; + } + if ( xmlCatPath != null ) { + this.mXmlCatalogPath = xmlCatPath; + } + } + /** @return directory path from which this class reads the wsdl files with .wsdl as file extension. */ + public String getWSDLDirectory() { + return this.mWsdlDirPath; + } + /** path to the xml catalog file in the service unit which can be used for Catalog-based entity + * and URI resolution. + */ + public String getXmlCatelogPath() { + return this.mXmlCatalogPath; + } + /** wsdl extension registry required for processing the wsdl extensions in the wsdl definition to + * java model. Binding component that is processing the wsdl extensions for its deployment + * configuration would provide the required ExtensionRegistry that will have the extension serializers + * and deserializers configured to read/write the extensions from/to the java model. + * @return ExtensionSerializer + * @see AbstractExtensionSerializer + */ + protected ExtensionRegistry getExtensionRegistry() { + return new AbstractExtensionRegistry() { + protected List createSerializers() { + return new ArrayList(); + } + }; + } + /** + * @return the WSDLReader configured with extension registry to process the wsdl extensions. + */ + public final WSDLReader getWSDLReader() throws WSDLException { + if ( this.mReader == null ) { + WSDLFactory factory = WSDLFactory.newInstance(); + this.mReader = factory.newWSDLReader(); + // reader.setFeature("javax.wsdl.verbose", true); + // reader.setFeature("javax.wsdl.importDocuments", true); + this.mReader.setExtensionRegistry(getExtensionRegistry()); + } + return this.mReader; + } + /** + * reads the wsdl file and returns the wsdl definition jwsdl model. + * @param wsldFilePath relative path to wsdl file from the the root wsdl directory returns from + * #getWSDLDirectory in the service unit or or absolute path . + * @return Definition + */ + public Definition readWSDL(String wsdlFilePath) throws WSDLException { + File wsdlFile = new File(wsdlFilePath); + if ( !wsdlFile.isAbsolute() ) { + wsdlFile = new File(this.mWsdlDirPath, wsdlFilePath); + } + return getWSDLReader().readWSDL(wsdlFile.getAbsolutePath()); + } + /** + * reads the files with .wsdl file extension in a directory. If the directory should + * be searched recursively, it searches this directory, all child directories of this + * directory and then to their child directories recursively. + * @param dir directory file to search for .wsdl files + * @param rec if set to true, it recursively searches the directory. if set to false, only + * this directory is searched. + * @return List of Files with .wsdl extension. + */ + public List listWSDLFiles(File dir, final boolean rec) throws IOException { + if ( dir == null || !dir.isDirectory()) { + throw new IOException(dir + " is not a directory for looking up wsdl files"); + } + List wsdlList = new ArrayList(); + File[] files = dir.listFiles(new FileFilter() { + public boolean accept(File pathname) { + if ( rec && pathname.isDirectory()) { + return true; + } else { + String name = pathname.getName(); + int idx = name.lastIndexOf('.'); + if ( idx < 0 ) { + return false; + } + String ext = name.substring(idx); + return ".wsdl".equalsIgnoreCase(ext); + } + } + }); + for ( File file : files ) { + if ( rec && file.isDirectory()) { + List wsdlFiles = listWSDLFiles(file, rec); + wsdlList.addAll(wsdlFiles); + } else { + wsdlList.add(file); + } + } + return wsdlList; + } + /** + * reads the files with .wsdl file extension in a directory fromDir and return the list of + * wsdl definitions corresponding to them. + * @param fromDir path to the directory relative to the root wsdl directory returns from + * #getWSDLDirectory or the absolute path to the directory. + */ + public List readWSDLs(String fromDir) throws WSDLException { + if ( fromDir == null ) { fromDir = ""; } + File wsdlDir = new File(fromDir); + if (!wsdlDir.isAbsolute()) { + wsdlDir = new File(this.mWsdlDirPath, fromDir); + } + + List wsdlFiles = new ArrayList(); + try { + wsdlFiles = listWSDLFiles(wsdlDir, true); + } catch (IOException ioEx) { + throw new WSDLException("WSDLFileReadError", ioEx.getMessage(),ioEx); + } + + List wsdlPaths = new ArrayList(); + for ( File wsdlFile : wsdlFiles) { + wsdlPaths.add(wsdlFile.getAbsolutePath()); + } + Collections.sort(wsdlPaths); + + List wsdlList = new ArrayList(); + for ( String wsdlPath : wsdlPaths ) { + Definition wsdlDef = readWSDL(wsdlPath); + wsdlList.add(wsdlDef); + } + return wsdlList; + } + /** + * finds PortType using port type ( interface ) qname. + */ + public static PortType findInterface(Definition wsdlDef, QName interfaceName) { + return wsdlDef.getPortType(interfaceName); + } + /** finds the Service using service qname */ + public static Service findService(Definition wsdlDef, QName serviceName) { + return wsdlDef.getService(serviceName); + } + /** finds the wsdl port using service qname and endpoint name */ + public static Port findServiceEndpoint(Definition wsdlDef, QName serviceName, String endpointName) { + Service service = null; + Port port = null; + service = findService(wsdlDef, serviceName); + if ( service != null ) { + port = service.getPort(endpointName); + } + return port; + } + /** + * finds the binding definition to which the service with serviceName and endpointName was bound. + */ + public static Binding findServiceBinding(Definition wsdlDef, QName serviceName, String endpointName) { + Binding binding = null; + Port port = findServiceEndpoint(wsdlDef, serviceName, endpointName); + if ( port != null ) { + binding = port.getBinding(); + } + return binding; + } + /** + * finds the binding definition using the interface(portType) qname with a + */ + public static Binding findInterfaceBinding(Definition wsdlDef, + QName interfaceQName, QName extQName) { + Map bindingMap = wsdlDef.getBindings(); + @SuppressWarnings("unchecked") + Collection bindings = bindingMap.values(); + for ( Binding binding : bindings ) { + if ( binding.getPortType().getQName().equals(interfaceQName)) { + return binding; + } + } + return null; + } + + /** + * find the wsdl4j operation corresponds to the interface+operation. + * @param wsdlDef wsdl definition + * @param portTypeQName portType QName + * @param opName operation name. if null, first operation in the portType + * is returned. + * @return Operation corresponding to the portType+opName + */ + public static Operation findOperation(Definition wsdlDef, + QName portTypeQName, String opName) { + Operation operation = null; + PortType portType = wsdlDef.getPortType(portTypeQName); + if ( portType != null ) { + if ( opName != null ) { + operation = portType.getOperation(opName, null, null); + } else { + @SuppressWarnings("unchecked") + List list = portType.getOperations(); + if ( list != null && list.size() > 0 ) { + operation = list.get(0); + } + } + } + return operation; + } + /** + * verifies whether the wsdl definition contains the specified service descriptions or not. Used + * to locate the wsdl definition for the services describes in service unit deployment + * descriptor(jbi.xm). + * @param interfaceName portType qname to find in the definition. can be null if you are trying to + * find only service endpoint description. + * @param serviceName qname for the service to find in this wsdl. can be null if + * you are trying to find only portType (abstract service) description. + * @param endpointName port name to find in the service definition. null if only + * service with any port should be looked up. + * + * @return true if the wsdl definition contains the specified service description. + */ + public static boolean isWSDLFor(Definition wsdlDef, + QName interfaceName, QName serviceName, String endpointName) { + PortType portType = null; + Service service = null; + Port port = null; + if ( interfaceName != null ) { + portType = findInterface(wsdlDef, interfaceName); + } + + if ( serviceName != null ) { + service = findService(wsdlDef, serviceName); + } + + if ( endpointName != null && service != null ) { + port = service.getPort(endpointName); + } + + boolean isWSDL = true; + + if ( (interfaceName != null && portType == null) || + ( serviceName != null && service == null ) || + ( endpointName != null && (service == null || port == null)) ) { + isWSDL = false; + } + + return isWSDL; + } + /** + * creates a binding definition that contains a service engine binding elements in the specified + * wsdl definition for a portType. It will try to find/create the binding element with interface + * local name with a "_JBISEBinding" suffix and add service engine binding element to it if it + * is not present. + * @param wsdl wsdl definition + * @param interfaceName portType qname to which the binding is created. + * @return a Binding contains service engine binding that is created for the portType. + */ + public Binding createServiceEngineBinding(Definition wsdl, QName interfaceName) { + QName bindingQName = new QName(wsdl.getQName().getNamespaceURI(), + interfaceName.getLocalPart() + "_JBISEBinding"); + Binding binding = wsdl.getBinding(bindingQName); + if ( binding == null ) { + binding = wsdl.createBinding(); + binding.setQName(bindingQName); + binding.setPortType(wsdl.getPortType(interfaceName)); + binding.setUndefined(false); + + ExtensibilityElement bindingExt = + SEBindingExt.SEBindingExtImpl.addExtensibilityElement(wsdl, binding); + + wsdl.addBinding(binding); + } + return binding; + } + /** + * creates port and binding elements that provide the the service engine binding for a service. + * @param wsdl wsdl definition + * @param interfaceName portType qname to which the binding is created. + * @param serviceName service under which the port definition bound to the service engine binding + * should be created. + * @param endpointName port name. + * @return a Binding contains service engine binding that is created for the portType. + */ + public Binding createServiceEngineBinding(Definition wsdl, QName interfaceName, QName serviceName, String endpointName ) { + Binding binding = null; + Service service = findService(wsdl, serviceName); + if ( service == null ) { + return null; + } + Port port = service.getPort(endpointName); + if ( port != null ) { + binding = port.getBinding(); + } else { + // create port + port = wsdl.createPort(); + port.setName(endpointName); + binding = createServiceEngineBinding(wsdl, interfaceName); + port.setBinding(binding); + service.addPort(port); + } + return binding; + } + /** prints the wsdl to text from the wsdl definition */ + public static void printWSDL(PrintWriter out, Definition def) { + try { + WSDLFactory factory = WSDLFactory.newInstance(); + WSDLWriter wsdlWriter = factory.newWSDLWriter(); + wsdlWriter.writeWSDL(def, out); + } catch (WSDLException ex) { + ex.printStackTrace(out); + } + } + /** prints the wsdl to text from the wsdl definition */ + public static String printWSDLToString(Definition def) { + StringWriter writer = new StringWriter(); + PrintWriter out = new PrintWriter(writer); + printWSDL(out, def); + out.close(); + return writer.getBuffer().toString(); + } + /** returns an existing namespace prefix or create one if not exists for the corresponding namespaceURI */ + public static String getNamespacePrefix(Definition def, String namespaceURI, String defPrefix) { + String prefix = null; + prefix = def.getPrefix(namespaceURI); + if ( prefix == null ) { + Set keySet = def.getNamespaces().keySet(); + String newPrefix = "ns"; + if ( defPrefix != null && defPrefix.trim().length() > 0 ){ + newPrefix = defPrefix; + } + prefix = newPrefix; + for ( int i=0; i < Integer.MAX_VALUE; ++i) { + if (!keySet.contains(prefix)) { + break; + } else { + prefix = newPrefix + i; + } + } + } + return prefix; + } + + /** + * creates and adds the jbi service engine binding extensibility element to the wsdl definition + * under specified binding definition. + */ + public static void addExtensibilityElement(Definition wsdlDef, + ElementExtensible extensibleEl, ExtensibilityElement extEl, String defPrefix) { + QName elementType = extEl.getElementType(); + String namespaceURI = elementType.getNamespaceURI(); + String prefix = wsdlDef.getPrefix(namespaceURI); + if ( prefix == null ) { + // no namespace prefix defined. create one. + prefix = WSDLProcessor.getNamespacePrefix(wsdlDef, namespaceURI, defPrefix); + wsdlDef.addNamespace(prefix, namespaceURI); + } + extensibleEl.addExtensibilityElement(extEl); + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/BindingExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/BindingExt.java new file mode 100644 index 000000000..a2c60c2ae --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/BindingExt.java @@ -0,0 +1,98 @@ +/* + * BindingExt.java + */ +package net.openesb.component.BindingComponent-archetype.wsdlext; + +import net.openesb.component.BindingComponent-archetype.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.BindingComponent-archetype.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.BindingComponent-archetype.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * extension element. The inner classes BindingExtImpl implements the interface + * and the BindingExtSerializer provides the serializer and deserializer + * implementation. The implementation and serializer classes will be registered + * with the ExtensionRegistry to process the binding extension element in the + * wsdl definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface BindingExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + //TODO: define get/set methods for properties for BindingExt if the extension element has attributes. + + /** + * This class is an implementation of BindingExt interface that provides + * java model for binding extensibility element. + */ + public static class BindingExtImpl extends AbstractExtensibilityElement implements BindingExt { + + public BindingExtImpl() { + setElementType(QN_BINDING_EXT); + } + + /** + * creates and adds the binding extensibility element to the wsdl + * definition + */ + public static BindingExtImpl addExtensibilityElement(Definition wsdlDef, Binding binding) { + BindingExtImpl bindingExt = new BindingExt.BindingExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, binding, bindingExt, NS_DEF_PREFIX); + return bindingExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * binding extensibility element. + */ + public static class BindingExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public BindingExtSerializer() { + super(Binding.class, QN_BINDING_EXT, BindingExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + BindingExt extObj = (BindingExt) extReg.createExtension(parentType, elementType); + //TODO: set any attributes from the el to extension object + // String myAttr = el.getAttribute(ATTR_MY_ATTR); + // extObj.setMyAttr(myAttr); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + BindingExt extObj = (BindingExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_BINDING_EXT); + buff.append("<" + elName); + + //TODO: append any attributes from extension obj to the element + // String myAttr = extObj.getMyAttr(); + // if ( myAttr != null && myAttr.trim().length() > 0 ) { + // buff.append(" myAttr=\"" + myAttr + "\""); + // } + // + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/ExtConstants.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/ExtConstants.java new file mode 100644 index 000000000..2ac3598e7 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/ExtConstants.java @@ -0,0 +1,49 @@ +/* + * ExtConstants.java + * + */ +package net.openesb.component.BindingComponent-archetype.wsdlext; + +import javax.xml.namespace.QName; + +/** + * This interface defines the constants for the namespace, elements, attributes + * and qnames corresponding to the wsdl extensions that this component + * processes. These constants will be used in the wsdl extension model used to + * process a particular wsdl extensions. + * + * @see WSDLExtensionRegistry + * @see PortExt + * @see BindingExt + * @author chikkala + */ +public interface ExtConstants { + + public static final String NS_URI_WSDL = "http://schemas.xmlsoap.org/wsdl/"; + public static final String NS_URI_XMLNS = "http://www.w3.org/2000/xmlns/"; + /** + * wsdl extension namespace processed by this wsdl extension model + */ + public static final String NS_URI = "http://java.sun.com/jbi/wsdl-extensions/sample/jmx-bc/"; + public static final String NS_DEF_PREFIX = "jmxbc"; + // wsdl extension element names. + public static final String EL_BINDING_EXT = "binding"; + public static final String EL_OPERATION_EXT = "operation"; + public static final String EL_INPUT_EXT = "input"; + public static final String EL_OUTPUT_EXT = "output"; + public static final String EL_FAULT_EXT = "fault"; + public static final String EL_PORT_EXT = "address"; + // Qualified wsdl extension element names. + public static final QName QN_BINDING_EXT = new QName(NS_URI, EL_BINDING_EXT); + public static final QName QN_OPERATION_EXT = new QName(NS_URI, EL_OPERATION_EXT); + public static final QName QN_INPUT_EXT = new QName(NS_URI, EL_INPUT_EXT); + public static final QName QN_OUTPUT_EXT = new QName(NS_URI, EL_OUTPUT_EXT); + public static final QName QN_FAULT_EXT = new QName(NS_URI, EL_FAULT_EXT); + public static final QName QN_PORT_EXT = new QName(NS_URI, EL_PORT_EXT); + // wsdl extension elements attribute names. + public static final String ATTR_ACTION = "action"; + public static final String ATTR_SERVICE_URL = "serviceURL"; + public static final String ATTR_USERNAME = "username"; + public static final String ATTR_PASSWORD = "password"; + public static final String ATTR_MBEAN = "mbean"; +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/FaultExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/FaultExt.java new file mode 100644 index 000000000..5ad2b4d8b --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/FaultExt.java @@ -0,0 +1,98 @@ +/* + * FaultExt.java + */ +package net.openesb.component.BindingComponent-archetype.wsdlext; + +import net.openesb.component.BindingComponent-archetype.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.BindingComponent-archetype.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.BindingComponent-archetype.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.BindingFault; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * operation fault extension element. The inner classes FaultExtImpl implements + * the interface and the FaultExtSerializer provides the serializer and + * deserializer implementation. The implemenation and serializer classes will be + * registered with the ExtensionRegistry to process the binding operation fault + * extension element in the wsdl definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface FaultExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + + //TODO: define getter methods for properties for FaultExt if the extension element has attributes. + /** + * This class is an implementation of FaultExt interface that provides java + * model for binding operation fault extensibility element. + */ + public static class FaultExtImpl extends AbstractExtensibilityElement implements FaultExt { + + public FaultExtImpl() { + setElementType(QN_FAULT_EXT); + } + + /** + * creates and adds the binding operation fault extensibility element to + * the wsdl definition + */ + public static FaultExtImpl addExtensibilityElement(Definition wsdlDef, BindingFault fault) { + FaultExtImpl faultExt = new FaultExt.FaultExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, fault, faultExt, NS_DEF_PREFIX); + return faultExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * binding operation fault extensibility element. + */ + public static class FaultExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public FaultExtSerializer() { + super(BindingFault.class, QN_FAULT_EXT, FaultExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + FaultExt extObj = (FaultExt) extReg.createExtension(parentType, elementType); + //TODO: set any attributes from the el to extension object + // String myAttr = el.getAttribute(ATTR_MY_ATTR); + // extObj.setMyAttr(myAttr); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + FaultExt extObj = (FaultExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_FAULT_EXT); + buff.append("<" + elName); + + //TODO: append any attributes from extension obj to the element + // String myAttr = extObj.getMyAttr(); + // if ( myAttr != null && myAttr.trim().length() > 0 ) { + // buff.append(" myAttr=\"" + myAttr + "\""); + // } + // + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/InputExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/InputExt.java new file mode 100644 index 000000000..0a8c15af8 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/InputExt.java @@ -0,0 +1,98 @@ +/* + * InputExt.java + */ +package net.openesb.component.BindingComponent-archetype.wsdlext; + +import net.openesb.component.BindingComponent-archetype.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.BindingComponent-archetype.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.BindingComponent-archetype.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.BindingInput; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * operation input extension element. The inner classes InputExtImpl implements + * the interface and the InputExtSerializer provides the serislizer and + * deserializer implementation. The implementation and serializer classes will + * be registered with the ExtensionRegistry to process the binding operation + * input extension element in the wsdl definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface InputExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + + //TODO: define get/set methods for properties for InputExt if the extension element has attributes. + /** + * This class is an implementation of InputExt interface that provides java + * model for binding operation input extensibility element. + */ + public static class InputExtImpl extends AbstractExtensibilityElement implements InputExt { + + public InputExtImpl() { + setElementType(QN_INPUT_EXT); + } + + /** + * creates and adds the binding operation fault extensibility element to + * the wsdl definition + */ + public static InputExtImpl addExtensibilityElement(Definition wsdlDef, BindingInput input) { + InputExtImpl inputExt = new InputExt.InputExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, input, inputExt, NS_DEF_PREFIX); + return inputExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * binding operation input extensibility element. + */ + public static class InputExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public InputExtSerializer() { + super(BindingInput.class, QN_INPUT_EXT, InputExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + InputExt extObj = (InputExt) extReg.createExtension(parentType, elementType); + //TODO: set any attributes from the el to extension object + // String myAttr = el.getAttribute(ATTR_MY_ATTR); + // extObj.setMyAttr(myAttr); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + InputExt extObj = (InputExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_INPUT_EXT); + buff.append("<" + elName); + + //TODO: append any attributes from extension obj to the element + // String myAttr = extObj.getMyAttr(); + // if ( myAttr != null && myAttr.trim().length() > 0 ) { + // buff.append(" myAttr=\"" + myAttr + "\""); + // } + // + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/OperationExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/OperationExt.java new file mode 100644 index 000000000..354f70fcb --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/OperationExt.java @@ -0,0 +1,118 @@ +/* + * OperationExt.java + */ +package net.openesb.component.BindingComponent-archetype.wsdlext; + +import net.openesb.component.BindingComponent-archetype.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.BindingComponent-archetype.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.BindingComponent-archetype.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * operation extension element. The inner classes OperationImpl implements the + * interface and the OperationExtSerializer provides the serilizer and + * deserializer implementation. The implementation and serializer classes will + * be registered with the ExtensionRegistry to process the binding operation + * extension element in the wsdl definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface OperationExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + + /** + * Getter for property action. + * + * @return Value of property action. + */ + public String getAction(); + + /** + * Setter for property action. + * + * @param action New value of property action. + */ + public void setAction(String action); + + /** + * This class is an implementation of OperationExt interface that provides + * java model for binding operation extensibility element. + */ + public static class OperationExtImpl extends AbstractExtensibilityElement implements OperationExt { + + private String mAction; + + public OperationExtImpl() { + setElementType(QN_OPERATION_EXT); + } + + public String getAction() { + return this.mAction; + } + + public void setAction(String action) { + this.mAction = action; + } + + /** + * creates and adds the binding operation fault extensibility element to + * the wsdl definition + */ + public static OperationExtImpl addExtensibilityElement(Definition wsdlDef, BindingOperation operation) { + OperationExtImpl operationExt = new OperationExt.OperationExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, operation, operationExt, NS_DEF_PREFIX); + return operationExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * binding operation extensibility element. + */ + public static class OperationExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public OperationExtSerializer() { + super(BindingOperation.class, QN_OPERATION_EXT, OperationExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + OperationExt extObj = (OperationExt) extReg.createExtension(parentType, elementType); + String action = el.getAttribute(ATTR_ACTION); + extObj.setAction(action); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + OperationExt extObj = (OperationExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_OPERATION_EXT); + buff.append("<" + elName); + + String action = extObj.getAction(); + if (action != null && action.trim().length() > 0) { + buff.append(" " + ATTR_ACTION + "=\"" + action + "\""); + } + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/OutputExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/OutputExt.java new file mode 100644 index 000000000..4a7ddc5f5 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/OutputExt.java @@ -0,0 +1,98 @@ +/* + * OutputExt.java + */ +package net.openesb.component.BindingComponent-archetype.wsdlext; + +import net.openesb.component.BindingComponent-archetype.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.BindingComponent-archetype.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.BindingComponent-archetype.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.BindingOutput; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for binding + * operation output extension element. The inner classes OutputExtImpl + * implements the interface and the OutputExtSerializer provides the serilizer + * and deserializer implementation. The implementation and serializer classes + * will be registered with the ExtensionRegistry to process the binding + * operation output extension element in the wsdl definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface OutputExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + + //TODO: define get/set methods for properties for OutputExt if the extension element has attributes. + /** + * This class is an implementation of OutputExt interface that provides java + * model for binding operation output extensibility element. + */ + public static class OutputExtImpl extends AbstractExtensibilityElement implements OutputExt { + + public OutputExtImpl() { + setElementType(QN_OUTPUT_EXT); + } + + /** + * creates and adds the binding operation fault extensibility element to + * the wsdl definition + */ + public static OutputExtImpl addExtensibilityElement(Definition wsdlDef, BindingOutput output) { + OutputExtImpl OutputExt = new OutputExt.OutputExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, output, OutputExt, NS_DEF_PREFIX); + return OutputExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * binding operation output extensibility element. + */ + public static class OutputExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public OutputExtSerializer() { + super(BindingOutput.class, QN_OUTPUT_EXT, OutputExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + OutputExt extObj = (OutputExt) extReg.createExtension(parentType, elementType); + //TODO: set any attributes from the el to extension object + // String myAttr = el.getAttribute(ATTR_MY_ATTR); + // extObj.setMyAttr(myAttr); + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + OutputExt extObj = (OutputExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_OUTPUT_EXT); + buff.append("<" + elName); + + //TODO: append any attributes from extension obj to the element + // String myAttr = extObj.getMyAttr(); + // if ( myAttr != null && myAttr.trim().length() > 0 ) { + // buff.append(" myAttr=\"" + myAttr + "\""); + // } + // + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/PortExt.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/PortExt.java new file mode 100644 index 000000000..16736a13e --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/PortExt.java @@ -0,0 +1,214 @@ +/* + * PortExt.java + */ +package net.openesb.component.BindingComponent-archetype.wsdlext; + +import net.openesb.component.BindingComponent-archetype.common.wsdl.AbstractExtensibilityElement; +import net.openesb.component.BindingComponent-archetype.common.wsdl.AbstractExtensionSerializer; +import net.openesb.component.BindingComponent-archetype.common.wsdl.WSDLProcessor; +import java.io.PrintWriter; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; +import org.w3c.dom.Element; + +/** + * This interface and its implementation represents the java model for port + * extension element. The inner classes PortExtImpl implements the interface and + * the PortExtSerializer provides the serializer and deserializer implemenation. + * The implementation and serializer classes will be registered with the + * ExtensionRegistry to process the port extension element in the wsdl + * definition. + * + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensibilityElement + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionSerializer + * @see com.sun.jbi.sample.component.common.wsdl.AbstractExtensionRegistry + * @author chikkala + */ +public interface PortExt extends ExtConstants, ExtensibilityElement, java.io.Serializable { + + /** + * Getter for property serviceURL. + * + * @return Value of property serviceURL. + */ + public String getServiceURL(); + + /** + * Setter for property serviceURL. + * + * @param serviceURL New value of property serviceURL. + */ + public void setServiceURL(String serviceURL); + + /** + * Getter for property username. + * + * @return Value of property username. + */ + public String getUsername(); + + /** + * Setter for property username. + * + * @param username New value of property username. + */ + public void setUsername(String username); + + /** + * Getter for property password. + * + * @return Value of property password. + */ + public String getPassword(); + + /** + * Setter for property password. + * + * @param password New value of property password. + */ + public void setPassword(String password); + + /** + * Getter for property name. + * + * @return Value of property name. + */ + public String getMBean(); + + /** + * Setter for property mbean. + * + * @param name New value of property mbean. + */ + public void setMBean(String mbean); + + /** + * This class is an implementation of PortExt interface that provides java + * model for port extensibility element. + */ + public static class PortExtImpl + extends AbstractExtensibilityElement implements PortExt { + + private String mServiceURL; + private String mUsername; + private String mPassword; + private String mMBean; + + public PortExtImpl() { + setElementType(QN_PORT_EXT); + } + + public String getServiceURL() { + return this.mServiceURL; + } + + public void setServiceURL(String serviceURL) { + this.mServiceURL = serviceURL; + } + + public String getUsername() { + return this.mUsername; + } + + public void setUsername(String username) { + this.mUsername = username; + } + + public String getPassword() { + return this.mPassword; + } + + public void setPassword(String password) { + this.mPassword = password; + } + + public String getMBean() { + return this.mMBean; + } + + public void setMBean(String mbean) { + this.mMBean = mbean; + } + + /** + * creates and adds the port extensibility element to the wsdl + * definition + */ + public static PortExtImpl addExtensibilityElement(Definition wsdlDef, Port port) { + PortExtImpl portExt = new PortExt.PortExtImpl(); + WSDLProcessor.addExtensibilityElement(wsdlDef, port, portExt, NS_DEF_PREFIX); + return portExt; + } + } + + /** + * This class provides the serializer and deserializer implementation for + * port extensibility element. + */ + public static class PortExtSerializer extends AbstractExtensionSerializer implements ExtConstants { + + public PortExtSerializer() { + super(Port.class, QN_PORT_EXT, PortExtImpl.class); + } + + @Override + public ExtensibilityElement unmarshall(Class parentType, QName elementType, Element el, + Definition def, ExtensionRegistry extReg) throws WSDLException { + + PortExt extObj = (PortExt) extReg.createExtension(parentType, elementType); + + String serviceURL = el.getAttribute(ATTR_SERVICE_URL); + extObj.setServiceURL(serviceURL); + + String mbean = el.getAttribute(ATTR_MBEAN); + extObj.setMBean(mbean); + + String username = el.getAttribute(ATTR_USERNAME); + extObj.setUsername(username); + + String password = el.getAttribute(ATTR_PASSWORD); + extObj.setPassword(password); + + return extObj; + } + + @Override + public void marshall(Class parentType, QName elementType, ExtensibilityElement extension, + PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { + + PortExt extObj = (PortExt) extension; + StringBuffer buff = new StringBuffer(); + + String elName = getQualifiedName(def, NS_URI, EL_PORT_EXT); + buff.append("<" + elName); + + String serviceURL = extObj.getServiceURL(); + if (serviceURL != null && serviceURL.trim().length() > 0) { + buff.append(" " + ATTR_SERVICE_URL + "=\"" + serviceURL + "\""); + } + + String mbean = extObj.getMBean(); + if (mbean != null && mbean.trim().length() > 0) { + buff.append(" " + ATTR_MBEAN + "=\"" + mbean + "\""); + } + + String username = extObj.getUsername(); + if (username != null && username.trim().length() > 0) { + buff.append(" " + ATTR_USERNAME + "=\"" + username + "\""); + } + + String password = extObj.getUsername(); + if (password != null && password.trim().length() > 0) { + buff.append(" " + ATTR_PASSWORD + "=\"" + password + "\""); + } + + buff.append("/>"); + pw.println(buff.toString()); + + } + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/WSDLExtHelper.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/WSDLExtHelper.java new file mode 100644 index 000000000..a4adafe4f --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/WSDLExtHelper.java @@ -0,0 +1,220 @@ +/* + * WSDLExtHelper.java + */ +package net.openesb.component.BindingComponent-archetype.wsdlext; + +import java.util.List; +import javax.wsdl.Binding; +import javax.wsdl.BindingFault; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.xml.namespace.QName; + +/** + * This class is a helper class for processing the wsdl extensions. It has + * methods that help locate the extension elements and return the java models + * corresponds to the extension elements. + * + * @author chikkala + */ +public final class WSDLExtHelper { + + /** + * creates the java object for the port extension element. + * + * @param def wsdl definition + * @param serviceName QName of the service + * @param endpointName name of the port under which to lookup for the port + * extension. + * @return java object for the port extension element + */ + public static PortExt getPortExt(Definition def, QName serviceName, String endpointName) { + PortExt portExt = null; + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + @SuppressWarnings("unchecked") + List extElList = port.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof PortExt) { + portExt = (PortExt) extEl; + break; + } + } + return portExt; + } + + /** + * creates the java object for the binding extension element. + * + * @param def wsdl definition + * @param binding binding under which to lookup for the binding extension. + * @return java object for the port extension element + */ + public static BindingExt getBindingExt(Definition def, Binding binding) { + BindingExt bindingExt = null; + @SuppressWarnings("unchecked") + List extElList = binding.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof BindingExt) { + bindingExt = (BindingExt) extEl; + break; + } + } + return bindingExt; + } + + /** + * creates the java object for the binding extension element. + * + * @param def wsdl definition + * @param serviceName QName of the service + * @param endpointName name of the port that references the binding. + * @return java object for the port extension element + */ + public static BindingExt getBindingExt(Definition def, QName serviceName, String endpointName) { + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + Binding binding = port.getBinding(); + return getBindingExt(def, binding); + } + + /** + * @return OperationExt java object corresponding to the operation extension + * element under binding + */ + public static OperationExt getOperationExt(Definition def, Binding binding, String operation) { + OperationExt operationExt = null; + BindingOperation bindingOp = binding.getBindingOperation(operation, null, null); + if (bindingOp != null) { + @SuppressWarnings("unchecked") + List extElList = bindingOp.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof OperationExt) { + operationExt = (OperationExt) extEl; + break; + } + } + } + return operationExt; + } + + /** + * @return OperationExt java object corresponding to the operation extension + * element under binding + */ + public static OperationExt getOperationExt(Definition def, QName serviceName, String endpointName, String operation) { + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + Binding binding = port.getBinding(); + return getOperationExt(def, binding, operation); + } + + /** + * @return InputExt java object corresponding to input extension element of + * the the binding operation under binding + */ + public static InputExt getInputExt(Definition def, Binding binding, + String operation, String input) { + InputExt inputExt = null; + BindingOperation bindingOp = binding.getBindingOperation(operation, input, null); + if (bindingOp != null) { + BindingInput bindingInput = bindingOp.getBindingInput(); + @SuppressWarnings("unchecked") + List extElList = bindingInput.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof InputExt) { + inputExt = (InputExt) extEl; + break; + } + } + } + return inputExt; + } + + /** + * @return InputExt java object corresponding to input extension element of + * the the binding operation under binding + */ + public static InputExt getInputExt(Definition def, + QName serviceName, String endpointName, String operation, String input) { + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + Binding binding = port.getBinding(); + return getInputExt(def, binding, operation, input); + } + + /** + * @return OutputExt java object corresponding to output extension element + * of the the binding operation under binding + */ + public static OutputExt getOutputExt(Definition def, Binding binding, + String operation, String output) { + OutputExt outputExt = null; + BindingOperation bindingOp = binding.getBindingOperation(operation, null, output); + if (bindingOp != null) { + BindingOutput bindingOutput = bindingOp.getBindingOutput(); + @SuppressWarnings("unchecked") + List extElList = bindingOutput.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof OutputExt) { + outputExt = (OutputExt) extEl; + break; + } + } + } + return outputExt; + } + + /** + * @return OutputExt java object corresponding to output extension element + * of the the binding operation under binding + */ + public static OutputExt getOutputExt(Definition def, + QName serviceName, String endpointName, String operation, String output) { + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + Binding binding = port.getBinding(); + return getOutputExt(def, binding, operation, output); + } + + /** + * @return FaultExt java object corresponding to fault extension element of + * the the binding operation under binding + */ + public static FaultExt getFaultExt(Definition def, Binding binding, + String operation, String faultName) { + FaultExt faultExt = null; + BindingOperation bindingOp = binding.getBindingOperation(operation, null, null); + if (bindingOp != null) { + BindingFault bindingFault = bindingOp.getBindingFault(faultName); + if (bindingFault != null) { + @SuppressWarnings("unchecked") + List extElList = bindingFault.getExtensibilityElements(); + for (ExtensibilityElement extEl : extElList) { + if (extEl instanceof FaultExt) { + faultExt = (FaultExt) extEl; + break; + } + } + } + } + return faultExt; + } + + /** + * @return FaultExt java object corresponding to fault extension element of + * the the binding operation under binding + */ + public static FaultExt getFaultExt(Definition def, + QName serviceName, String endpointName, String operation, String faultName) { + Service wsdlService = def.getService(serviceName); + Port port = wsdlService.getPort(endpointName); + Binding binding = port.getBinding(); + return getFaultExt(def, binding, operation, faultName); + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/WSDLExtension.xsd b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/WSDLExtension.xsd new file mode 100644 index 000000000..1311a03c9 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/WSDLExtension.xsd @@ -0,0 +1,98 @@ + + + + + + + + + "binding" defines a protocol based binding details. + + + + + + + + + + + + + + "operation" defines the protocol based binding operation details. + + + + + + + + + + + + + + + "input" defines the protocol based binding input details. + + + + + + + + + + + + + + "output" defines the protocol based binding output details. + + + + + + + + + + + + + + "fault" defines the protocol based binding fault details. + + + + + + + + + + + + + + "address" indicates protocol based binding port details. + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/WSDLExtensionRegistry.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/WSDLExtensionRegistry.java new file mode 100644 index 000000000..3405bdd3c --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/src/java/net/openesb/component/cname/wsdlext/WSDLExtensionRegistry.java @@ -0,0 +1,43 @@ +/* + * WSDLExtensionRegistry.java + */ +package net.openesb.component.BindingComponent-archetype.wsdlext; + +import net.openesb.component.BindingComponent-archetype.common.wsdl.AbstractExtensionRegistry; +import net.openesb.component.BindingComponent-archetype.common.wsdl.AbstractExtensionSerializer; +import java.util.ArrayList; +import java.util.List; + +/** + * This class extends + * AbstractExtensionRegistry to create the serializers and deserializers + * for processing wsdl extensions. + * + * @see AbstractExtensionRegistry + * @author chikkala + */ +public class WSDLExtensionRegistry extends AbstractExtensionRegistry { + + /** + * Creates a new instance of JMXBindingExtensionRegistry + */ + public WSDLExtensionRegistry() { + super(); + } + + /** + * creates serializers and deserializers for all the extension elements + */ + protected List createSerializers() { + List list = new ArrayList(); + + list.add(new BindingExt.BindingExtSerializer()); + list.add(new OperationExt.OperationExtSerializer()); + list.add(new InputExt.InputExtSerializer()); + list.add(new OutputExt.OutputExtSerializer()); + list.add(new FaultExt.FaultExtSerializer()); + list.add(new PortExt.PortExtSerializer()); + + return list; + } +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/bindingtest/BindingComponentTest.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/bindingtest/BindingComponentTest.java new file mode 100644 index 000000000..d61cd6a06 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/bindingtest/BindingComponentTest.java @@ -0,0 +1,52 @@ +/* + * BindingComponent-archetypeTest.java + */ +package bindingtest; +import net.openesb.component.BindingComponent-archetype.test.JBIComponentTestClient; +import net.openesb.component.BindingComponent-archetype.test.JMXBindingTestClient; +import java.util.Properties; + import junit.framework.TestCase; + +/** + * The test method in this testcase uses the JMXBindingTestClient to send the + * input document to the echo service provided by service engine via the binding + * component by sending the input to the binding using jmx interface. The output + * received from the service invocation will be placed in test results directory + * under the same package as this test case. + * @see com.sun.jbi.sample.component.test.JMXBindingTestClinet + * + * @author chikkala + */ +public class BindingComponentTest + extends TestCase +{ + + public BindingComponentTest(String testName) { + super(testName); + } + + public void test1() throws Exception { + String testPropertiesPath = "test1.properties"; + JBIComponentTestClient testClient = new JMXBindingTestClient(); + Properties testProps = testClient.loadTestProperties(this.getClass(), testPropertiesPath); + testClient.testService(testProps); + } + + public void test2() throws Exception { + String testPropertiesPath = "test2.properties"; + JBIComponentTestClient testClient = new JMXBindingTestClient(); + Properties testProps = testClient.loadTestProperties(this.getClass(), testPropertiesPath); + testClient.testService(testProps); + } + + public static void main(String[] args) { + try { + BindingComponentTest compTest = new BindingComponentTest("BindingComponentTest"); + compTest.test1(); + compTest.test2(); + } catch(Exception ex) { + ex.printStackTrace(); + } + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/bindingtest/test1.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/bindingtest/test1.properties new file mode 100644 index 000000000..f883e1000 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/bindingtest/test1.properties @@ -0,0 +1,13 @@ +# Sample ResourceBundle properties file + +#### test properties for testing the binding component +input.file=test1Input.xml +#exptected.file=Expected.xml +output.file=test1Output.xml + +consumer.jmx.bc.ep.operation=sayHello +consumer.jmx.bc.ep.address.mbean=com.sun.jbi.sample.jmxbc:jmxbc-ep-address=BindingComponent/greetings +consumer.jmx.bc.ep.address.serviceURL=service:jmx:rmi:///jndi/rmi://localhost:8686/jmxrmi +consumer.jmx.bc.ep.address.username=admin +consumer.jmx.bc.ep.address.password=this really long string is used to identify a password that has been stored in the Keyring + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/bindingtest/test1Input.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/bindingtest/test1Input.xml new file mode 100644 index 000000000..cc869a4d2 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/bindingtest/test1Input.xml @@ -0,0 +1,9 @@ + + + + Srinivasan + Chikkala + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/bindingtest/test2.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/bindingtest/test2.properties new file mode 100644 index 000000000..446c4b1ec --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/bindingtest/test2.properties @@ -0,0 +1,12 @@ +# Sample ResourceBundle properties file + +#### test properties for testing the binding component +input.file=test2Input.xml +#exptected.file=Expected.xml +output.file=test2Output.xml + +consumer.jmx.bc.ep.operation=sayGoodbye +consumer.jmx.bc.ep.address.mbean=com.sun.jbi.sample.jmxbc:jmxbc-ep-address=BindingComponent/greetings +consumer.jmx.bc.ep.address.serviceURL=service:jmx:rmi:///jndi/rmi://localhost:8686/jmxrmi +consumer.jmx.bc.ep.address.username=admin +consumer.jmx.bc.ep.address.password=this really long string is used to identify a password that has been stored in the Keyring diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/bindingtest/test2Input.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/bindingtest/test2Input.xml new file mode 100644 index 000000000..a4f7ed4d2 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/bindingtest/test2Input.xml @@ -0,0 +1,9 @@ + + + + Srinivasan + Chikkala + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java new file mode 100644 index 000000000..1875cc924 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/net/openesb/component/cname/test/JBIComponentTestClient.java @@ -0,0 +1,295 @@ +/* + * JBIComponentTestClient.java + */ + +package net.openesb.component.BindingComponent-archetype.test; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Properties; + +/** + * This class implements the base framework for the testing the JBI components. + * Testing the JBI component involves may require deploying a service to the + * component(s) to enable the service provided by the test component and then + * invoking the service provided by the test component. If the test component is + * a binding component, then a service provider component such as sample service + * engine is required to test the component end to end. If the test component is a + * service engine, then the service on the test component can be invoked via + * soap/http binding component. + * + * This class provides the utilites to read the test properties, read the input + * message from the file and save the output to the file. The testService + * method implemented here can be executed as the test for the component. The + * testService method calls the invokeService method with the input document and + * expects a output document or error that will be saved to the output file. + * The method invokeService should be implemented by the extended test classes to + * inplement a suitable service consumer implemenation for the test compoent. + * See JMXBindingTestClient.java or SOAPBidningTestClient.java for more details + * on how to implement a partucular test service consumer. + * + * @author chikkala + */ +public abstract class JBIComponentTestClient { + + public static final String TEST_PROPS_FILE_PROP = "test.properties.file"; + public static final String TEST_RESULTS_DIR_PROP = "test.results.dir"; + public static final String TEST_SRC_DIR_PROP = "test.src.dir"; + + public static final String TEST_PACKAGE_PROP = "test.package.name"; + + public static final String INPUT_FILE_PROP = "input.file"; + public static final String EXPECTED_FILE_PROP = "expected.file"; + public static final String OUTPUT_FILE_PROP = "output.file"; + + public static final String DEF_TEST_PROP_FILE = "test.properties"; + public static final String DEF_INPUT_FILE = "Input.xml"; + public static final String DEF_OUTPUT_FILE = "Output.xml"; + public static final String DEF_TEST_RESULTS_DIR = "test-results"; + + public JBIComponentTestClient() { + } + /** + * returns the absolute resource path w.r.t. the packagePath if the resource name + * is relative else return the resourceName as it is. + * @param package name ( dot separated ) + * @param resourcName dot separated name or a absolute resource path + * @return abosolute resource path with path separator + */ + public static String resolveResourcePath(String packageName, String resourceName) { + String resourcePath = resourceName; + if ( !resourceName.startsWith("/")) { + // it is relative resource file. resolve it w.r.t. testPackage + String pkgDir = packageName.trim().replace('.', '/'); + if ( pkgDir.length() != 0 ) { + pkgDir += "/"; + } + resourcePath = "/" + pkgDir + resourceName; + } + return resourcePath; + } + /** + * loads the resource file as properties. + * @param testPackage package name where this test belongs + * @param testPropPath resource path relative to testPackage or absolute resource path + */ + public Properties loadTestProperties(String testPackage, String testPropPath) throws IOException { + String propsResourcePath = resolveResourcePath(testPackage, testPropPath); + + InputStream testPropIS = null; + try { + testPropIS = this.getClass().getResourceAsStream(propsResourcePath); + Properties testProps = new Properties(); + testProps.load(testPropIS); + testProps.setProperty(TEST_PACKAGE_PROP, testPackage); + return testProps; + } finally { + if ( testPropIS != null ) { + try { + testPropIS.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + } + /** + * load default test properties file in the testClass package. + * @param testClass Class where to look for the default test properties + * @param testPropPath resource path relative to testPackage or absolute resource path + * @return Properties test properties + */ + public Properties loadTestProperties(Class testClass, String testPropPath) throws IOException { + return loadTestProperties(testClass.getPackage().getName(), testPropPath ); + } + /** + * load default test properties file in the testClass package. + * @param testClass Class where to look for the default test properties + * @return Properties test properties + */ + public Properties loadTestProperties(Class testClass) throws IOException { + return loadTestProperties(testClass.getPackage().getName(), DEF_TEST_PROP_FILE ); + } + /** + * loads the resource file to string bugger + * @param inputFile resource file path + */ + public StringBuffer loadResourceFile(String resourcePath) throws FileNotFoundException, IOException { + + InputStream inputIS = null; + InputStreamReader inputReader = null; + BufferedReader reader = null; + StringWriter strWriter = null; + PrintWriter writer = null; + try { + inputIS = this.getClass().getResourceAsStream(resourcePath); + inputReader = new InputStreamReader(inputIS); + reader = new BufferedReader(inputReader); + strWriter = new StringWriter(); + writer = new PrintWriter(strWriter); + for ( String line = null; (line = reader.readLine()) != null ; ) { + writer.println(line); + } + writer.close(); + strWriter.close(); + return strWriter.getBuffer(); + } finally { + if ( inputIS != null ) { + try { + inputIS.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + } + + /** + * reads data from the reader and saves to file + * @param reader reader from which to read the data and save to file + * @param outputFilePath absolute file path + */ + public void saveOutputToFile(Reader reader, String outputFilePath) throws IOException { + + BufferedReader buff = null; + FileWriter fileWriter = null; + PrintWriter writer = null; + try { + buff = new BufferedReader(reader); + fileWriter = new FileWriter(outputFilePath); + writer = new PrintWriter(fileWriter); + for ( String line = null; (line = buff.readLine()) != null ; ) { + writer.println(line); + } + } finally { + if ( writer != null ) { + writer.close(); + } + if ( fileWriter != null ) { + fileWriter.close(); + } + } + } + + /** + * resource path. + */ + public String getInputFileResourcePath(Properties testProps) { + + String testPkg = testProps.getProperty(TEST_PACKAGE_PROP, ""); + String inputFile = testProps.getProperty(INPUT_FILE_PROP, DEF_INPUT_FILE); + String resourcePath = resolveResourcePath(testPkg, inputFile); + return resourcePath; + } + /** + * return resource path + */ + public String getExpectedFileResourcePath(Properties testProps) { + + String testPkg = testProps.getProperty(TEST_PACKAGE_PROP, ""); + String resourcePath = null; + String expFile = testProps.getProperty(EXPECTED_FILE_PROP, null); + if ( expFile != null ) { + resourcePath = resolveResourcePath(testPkg, expFile); + } + return resourcePath; + } + /** + * return the absolute path to the output file + */ + public String getOutputFilePath(Properties testProps) { + + String defPackage = this.getClass().getPackage().getName(); + String testPackage = testProps.getProperty(TEST_PACKAGE_PROP, defPackage); + String testPackageDir = testPackage.replace('.','/'); + String outputFile = testProps.getProperty(OUTPUT_FILE_PROP, DEF_OUTPUT_FILE); + + String userHomeDir = System.getProperty("user.home", ""); + String userDir = System.getProperty("user.dir", userHomeDir); + String defResultsDir = userDir + "/" + DEF_TEST_RESULTS_DIR; + String sysResultDir = System.getProperty(TEST_RESULTS_DIR_PROP, defResultsDir); + String resultDir = testProps.getProperty(TEST_RESULTS_DIR_PROP, sysResultDir); + + File outputDir = new File(resultDir, testPackageDir); + // System.out.println("Creating the test results output dir " + outputDir); + outputDir.mkdirs(); + return (new File(outputDir, outputFile)).getAbsolutePath(); + } + + /** + * This is the method where the actual service invocation code based on the + * type of client will be implemented. testService method calls this method + * after preparing the test input and then processes the output returned by + * this method to complte the test. + * @param inputDoc + * @param testProps + * @throws java.lang.Exception + * @return + */ + public abstract StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception; + + /** + * abstract method implemented by the extended classes to compare the output + * document with the expected output to determine the test is a failure or + * success. + * @param outputDoc + * @param expectedDoc + * @param testProps + * @throws java.lang.Exception + */ + public abstract void compareWithExpectedOutput(StringBuffer outputDoc, + StringBuffer expectedDoc, Properties testProps) throws Exception; + + /** + * This is the main test method that a test case will call to test the + * service. The standard steps that required to invoke the service and + * process the output will be done in this method. Each test case creates + * the test Properties required for that test and executes this method for + * testing the service by passing the test properties to it. This method + * prepares the input and executes the invokeService method to invoke a + * service with the prepared input. It then processes the return value from + * the invokeService to complete the test. + * + * @param testProps + * @throws java.lang.Exception + */ + public void testService(Properties testProps) throws Exception { + + String inFilePath = getInputFileResourcePath(testProps); + String outFilePath = getOutputFilePath(testProps); + String expFilePath = getExpectedFileResourcePath(testProps); + File outDir = (new File(outFilePath)).getParentFile(); + outDir.mkdirs(); + + StringBuffer outputDoc = new StringBuffer(); + + try { + StringBuffer inputDoc = loadResourceFile(inFilePath); + outputDoc = invokeService(inputDoc, testProps); + if ( expFilePath != null ) { + StringBuffer expOutputDoc = loadResourceFile(expFilePath); + compareWithExpectedOutput(inputDoc, expOutputDoc, testProps); + } + } catch (Exception ex) { + StringWriter out = new StringWriter(); + ex.printStackTrace(new PrintWriter(out)); + outputDoc.append(out.getBuffer()); + throw ex; + } finally { + if ( outputDoc != null ) { + System.out.println(outputDoc); + this.saveOutputToFile(new StringReader(outputDoc.toString()), outFilePath); + } + } + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java new file mode 100644 index 000000000..784c90970 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/net/openesb/component/cname/test/JMXBindingTestClient.java @@ -0,0 +1,133 @@ +/* + * JMXBindingTestClient.java + */ + +package net.openesb.component.BindingComponent-archetype.test; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanException; +import javax.management.MBeanServerConnection; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.management.ReflectionException; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; + +/** + * This class extends the JBIComponentTestClient and implements the invokeService + * method to test the proxy service consumer implementation by a binding component + * that can communicate with the external service consumers using JMX interface. + * @author chikkala + */ +public class JMXBindingTestClient extends JBIComponentTestClient { + + public static final String CONSUMER_EP_INBOUND_OPERATION_PROP = "consumer.jmx.bc.ep.operation"; + public static final String CONSUMER_EP_ADDRESS_MBEAN_PROP = "consumer.jmx.bc.ep.address.mbean"; + public static final String CONSUMER_EP_ADDRESS_URL_PROP = "consumer.jmx.bc.ep.address.serviceURL"; + public static final String CONSUMER_EP_ADDRESS_USERNAME_PROP = "consumer.jmx.bc.ep.address.username"; + public static final String CONSUMER_EP_ADDRESS_PASSWORD_PROP = "consumer.jmx.bc.ep.address.password"; + + public static final String PROVIDER_EP_INBOUND_OPERATION_PROP = "provider.jmx.bc.ep.operation"; + public static final String PROVIDER_EP_ADDRESS_MBEAN_PROP = "provider.jmx.bc.ep.address.mbean"; + public static final String PROVIDER_EP_ADDRESS_URL_PROP = "provider.jmx.bc.ep.address.serviceURL"; + public static final String PROVIDER_EP_ADDRESS_USERNAME_PROP = "provider.jmx.bc.ep.address.username"; + public static final String PROVIDER_EP_ADDRESS_PASSWORD_PROP = "provider.jmx.bc.ep.address.password"; + + + /** + * Creates a new instance of JMXBindingTestClient + */ + public JMXBindingTestClient() { + super(); + } + /** + * creates jmx connection to send the input message to the binding component. + */ + public static MBeanServerConnection getJMXConnection(Properties testProps) + throws MalformedURLException, IOException { + + String jmxUrl = testProps.getProperty(CONSUMER_EP_ADDRESS_URL_PROP); + String username = testProps.getProperty(CONSUMER_EP_ADDRESS_USERNAME_PROP); + String password = testProps.getProperty(CONSUMER_EP_ADDRESS_PASSWORD_PROP); + + Map env = new HashMap(); + if ( username != null ) { + String [] credentials = new String [] {username, password}; + env.put("jmx.remote.credentials", credentials); + env.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, JMXBindingTestClient.class.getClassLoader()); + } + JMXServiceURL serviceURL = new JMXServiceURL(jmxUrl); + JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, env); + MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection(); + return mbeanServerConnection; + } + /** + * constructs the jmx mbean objectname + */ + public static ObjectName createJMXEndpointMBeanObjectName(String endpointAddressMBean) throws MalformedObjectNameException { + // String objectName = JMX_DOMAIN + ":" + JMX_ENDPOINT_ADDRESS_KEY + "=" + endpointAddressMBean; + return new ObjectName(endpointAddressMBean); + } + /** + * invokes a jmx mbean to send message. + */ + public static StringBuffer invokeSendMessage(MBeanServerConnection jmxConn, ObjectName epAddressName, + String operation, StringBuffer inputDoc) + throws MalformedObjectNameException, InstanceNotFoundException, + MBeanException, ReflectionException, IOException { + StringBuffer outDoc = null; + + Object result = null; + String mbeanOperation = "sendMessage"; + + Object[] params = new Object[2]; + params[0] = operation; + params[1] = inputDoc; + + String[] signature = new String[2]; + signature[0] = "java.lang.String"; + signature[1] = "java.lang.StringBuffer"; + + result = jmxConn.invoke(epAddressName, mbeanOperation, params, signature); + if ( result != null ) { + outDoc = (StringBuffer)result; + } + + return outDoc; + } + /** + * invokes the service via jmx interface. + */ + public StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception { + + ObjectName epAddressName = new ObjectName(testProps.getProperty(CONSUMER_EP_ADDRESS_MBEAN_PROP)); + String operation = testProps.getProperty(CONSUMER_EP_INBOUND_OPERATION_PROP); + + MBeanServerConnection jmxConn = getJMXConnection(testProps); + StringBuffer outputDoc = null; + try { + outputDoc = invokeSendMessage(jmxConn, epAddressName, operation, inputDoc); + } catch (MBeanException ex) { + Exception targetEx = ex.getTargetException(); + if ( targetEx != null ) { + throw targetEx; + } else { + throw ex; + } + } + return outputDoc; + } + /** no expected output comparison implemented */ + public void compareWithExpectedOutput(StringBuffer inputDoc, + StringBuffer expectedDoc, + Properties testProps) throws Exception { + // throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java new file mode 100644 index 000000000..e33be0bed --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/java/net/openesb/component/cname/test/SOAPBindingTestClient.java @@ -0,0 +1,156 @@ +/* + * SOAPBindingTestClient.java + */ + +package net.openesb.component.BindingComponent-archetype.test; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Properties; +import javax.xml.soap.MessageFactory; +import javax.xml.soap.MimeHeaders; +import javax.xml.soap.SOAPConnection; +import javax.xml.soap.SOAPConnectionFactory; +import javax.xml.soap.SOAPException; +import javax.xml.soap.SOAPFault; +import javax.xml.soap.SOAPMessage; +import javax.xml.soap.SOAPPart; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +/** + * This class extends the JBIComponentTestClient and implements the invokeService + * method to test the Service Engine via SOAP Binding by invoking the service using + * SOAP Client that sends the message to the service provider via soaphttp binding. + * + * @author chikkala + */ +public class SOAPBindingTestClient extends JBIComponentTestClient { + + private static final String ADDRESS_PROP = "soap.binding.inbound.endpoint.address.location"; + private static final String SOAP_ACTION_PROP = "soap.binding.soapaction"; + private static final String FAIL_ON_SOAP_FAULT_PROP = "fail.on.soap.fault"; + + private static MessageFactory messageFactory; + private static SOAPConnectionFactory soapConnFactory; + private static SOAPConnection connection; + + public SOAPBindingTestClient() throws SOAPException { + init(); + } + /** initializes SOAP client */ + private synchronized void init() throws SOAPException { + if ( messageFactory == null ) { + messageFactory = MessageFactory.newInstance(); + } + if ( soapConnFactory == null ) { + soapConnFactory = SOAPConnectionFactory.newInstance(); + } + if ( connection == null ) { + connection = soapConnFactory.createConnection(); + } + } + + /** + * read in a soap message from the given input file + */ + private static SOAPMessage loadMessage(Reader inReader) throws SOAPException, IOException { + //Create and populate the message from a file + SOAPMessage message = messageFactory.createMessage(); + SOAPPart soapPart = message.getSOAPPart(); + StreamSource preppedMsgSrc = new StreamSource(inReader); + soapPart.setContent(preppedMsgSrc); + message.saveChanges(); + return message; + } + /** saves the SOAP message as xml text to a writer */ + private static void saveMessage(SOAPMessage response, Writer outWriter) + throws TransformerConfigurationException, SOAPException, TransformerException { + + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + transformerFactory.setAttribute("indent-number", new Integer(2)); + Transformer transformer = transformerFactory.newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + + SOAPPart replySOAPPart = response.getSOAPPart(); + Source sourceContent = replySOAPPart.getContent(); + StreamResult result = new StreamResult(outWriter); + try { + transformer.transform(sourceContent, result); + } catch (TransformerException ex) { + ex.printStackTrace(); + } + } + /** + * Send a soap message + * @param destination URL to send to + * @param message message to send + * @param expectedHttpStatus expected http status code or null if success is expected + * @return reply soap message + */ + private static SOAPMessage sendMessage(String destination, SOAPMessage message, String soapAction) throws SOAPException { + + // Add soapAction if not null + if (soapAction != null) { + MimeHeaders hd = message.getMimeHeaders(); + hd.setHeader("SOAPAction", soapAction); + } + // Send the message and get a reply + SOAPMessage reply = null; + reply = connection.call(message, destination); + return reply; + } + /** check the xml text in the StringBuffer passed contains SOAP Fault. */ + public boolean isSOAPFault(StringBuffer msgBuff) { + SOAPFault soapFault = null; + try { + SOAPMessage inMsg = loadMessage(new StringReader(msgBuff.toString())); + soapFault = inMsg.getSOAPBody().getFault(); + } catch (Exception ex) { + // any exception, means either no fault elem or invalid xml + } + return (soapFault != null); + } + /** + * invokes the service ny sending the input message and return the output + * message returned by the service. + */ + public StringBuffer invokeService(StringBuffer inputDoc, Properties testProps) throws Exception { + + String soapAction = testProps.getProperty(SOAP_ACTION_PROP); + String destination = testProps.getProperty(ADDRESS_PROP); + SOAPMessage inMsg = loadMessage(new StringReader(inputDoc.toString())); + SOAPMessage outMsg = sendMessage(destination, inMsg, soapAction); + StringWriter out = new StringWriter(); + saveMessage(outMsg, out); + StringBuffer outDoc = out.getBuffer(); + Boolean failOnSoapFault = Boolean.valueOf(testProps.getProperty(FAIL_ON_SOAP_FAULT_PROP, "false")); + if ( failOnSoapFault ) { + if (isSOAPFault(outDoc)) { + StringBuffer errBuff = new StringBuffer("########## SOAP FAULT ############ \n"); + errBuff.append(outDoc); + throw new Exception(errBuff.toString()); + } + } + return outDoc; + } + /** comparing the received output document with the expected document. throw + * exception if the docs are not same. throwing the exception in this method + * fails the test. + */ + public void compareWithExpectedOutput(StringBuffer outputDoc, + StringBuffer expectedDoc, + Properties testProps) throws Exception { + // throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/build.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/build.properties new file mode 100644 index 000000000..8770a8330 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/build.properties @@ -0,0 +1,19 @@ +# Build properties for the service assembly builds +# user.properties.file=../../user.properties +src.dir=src +# This directory is removed when the project is cleaned: +build.dir=build +service.assembly.name=testSA + +#no.deps=true set the no.deps property if there are no SUs to build +# for each testSU define the properties here. +# dependent BC SU projects dependency +# service unit name +service.unit.name.testSUBC=testSUBC +# service unit project directory +project.testSUBC=testSUBC + +# service unit name +service.unit.name.testSUSE=testSUSE +# service unit project directory +project.testSUSE=testSUSE diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/build.xml new file mode 100644 index 000000000..12d519c6a --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/build.xml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.assembly.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/src/META-INF/jbi.xml new file mode 100644 index 000000000..3e03318dc --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/src/META-INF/jbi.xml @@ -0,0 +1,41 @@ + + + + + BindingComponent-archetype_TestSA + This is a test Service Assembly to test Binding + + + + + BindingComponent-archetype_TestSUBC + This service unit enables inbound endpoint in the JMXBinding for a service in service engine + + + testSUBC.zip + BindingComponent-archetype + + + + + BindingComponent-archetype_TestSUSE + This service unit enables greetings service provider in the service engine + + + testSUSE.zip + ServiceEngine + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUBC/build.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUBC/build.properties new file mode 100644 index 000000000..cf9b455e9 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUBC/build.properties @@ -0,0 +1,7 @@ +# Build properties for the service unit builds +src.dir=src +# This directory is removed when the project is cleaned: +#build.dir=../../../build/test/testSU/build +build.dir=build +service.unit.name=testSUBC + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUBC/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUBC/build.xml new file mode 100644 index 000000000..4c4b3d9a1 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUBC/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUBC/src/Greetings.wsdl b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUBC/src/Greetings.wsdl new file mode 100644 index 000000000..cf1d4ccc3 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUBC/src/Greetings.wsdl @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUBC/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUBC/src/META-INF/jbi.xml new file mode 100644 index 000000000..e3e5435c1 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUBC/src/META-INF/jbi.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/build.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/build.properties new file mode 100644 index 000000000..387359c01 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/build.properties @@ -0,0 +1,7 @@ +# Build properties for the service unit builds +src.dir=src +# This directory is removed when the project is cleaned: +#build.dir=../../../build/test/testSU/build +build.dir=build +service.unit.name=testSUSE + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/build.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/build.xml new file mode 100644 index 000000000..38fc64f50 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set service.unit.name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/src/Greetings.wsdl b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/src/Greetings.wsdl new file mode 100644 index 000000000..9c6322558 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/src/Greetings.wsdl @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/src/META-INF/jbi.xml b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/src/META-INF/jbi.xml new file mode 100644 index 000000000..62253668a --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/src/META-INF/jbi.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/src/goodbye.xsl b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/src/goodbye.xsl new file mode 100644 index 000000000..c60e39b73 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/src/goodbye.xsl @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + Goodbye ! Have a great time. + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/src/hello.xsl b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/src/hello.xsl new file mode 100644 index 000000000..994b66f98 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/src/hello.xsl @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + Hello ! + + + + + diff --git a/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/src/xsltmap.properties b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/src/xsltmap.properties new file mode 100644 index 000000000..06e4b6631 --- /dev/null +++ b/maven-archtype-v2/maven-archtype-binding-component-v2/target/test-classes/projects/basic/project/BindingComponent-archetype/test/testSA/testSUSE/src/xsltmap.properties @@ -0,0 +1,28 @@ +# properties will be used to find the xslt file that will be used for invoking a +# service operation. +# The "xsltmap.properties" file should contain two types of properties +# 1. for namespace prefix to namespaceURI map that starts with "xmlns." prefix like +# "xmlns.tns-prefix=http://www.sun.com/jbi/examples/sample-service/echo" +# 2. a service description to xslt file properties with syntax like +# "{tns-prefix}service-name=xslt_file_name" and +# "{tns-prefix}service-name.{tns-prefix}operation-name=xslt_file_name" and +# "{tns-prefix}service-name.{tns-prefix}interface-name.operation-name=xslt_file_name" . +# the service description property is a "." delimited tokens that represents +# a serive or interface qname and a operation name. To locate xslt file either with +# service qname or service qname and operaton or serivice qname and interface qname +# and operation, all the three properties specified above should be there for each xslt file. +# + +xmlns.greet1=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greet2=http://www.sun.com/jbi/examples/sample-service/greetings/ +xmlns.greettypes=http://www.sun.com/jbi/examples/sample-service/greetings/types +# just service level default settings +{greet2}greetService=hello.xsl +# service and operation +{greet2}greetService.{greet1}sayHello=hello.xsl +# service, interface, operation +{greet2}greetService.{greet1}greetings.sayHello=hello.xsl +# service and operation +{greet2}greetService.{greet1}sayGoodbye=goodbye.xsl +# service, interface, operation +{greet2}greetService.{greet1}greetings.sayGoodbye=goodbye.xsl