Author: objectiser
Date: 2010-11-22 08:22:37 -0500 (Mon, 22 Nov 2010)
New Revision: 1130
Added:
dwsp/trunk/pom.xml
dwsp/trunk/src/
dwsp/trunk/src/main/
dwsp/trunk/src/main/java/
dwsp/trunk/src/main/java/org/
dwsp/trunk/src/main/java/org/jboss/
dwsp/trunk/src/main/java/org/jboss/soa/
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/EndpointMetaData.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/InvocationAdapter.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/MessageAdapter.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ServiceEndpointReference.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ServiceProvider.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/deployer/
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/deployer/ServiceDeployer.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/deployer/jboss/
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/deployer/jboss/JBossServiceDeployer.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/deployer/jboss/WebMetaDataFactory.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/ServerConfig.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/KernelAwareSPIFactory.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/KernelLocator.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/MBeanServerLocator.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/ObjectNameFactory.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/ServerConfigFactory.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/ServerConfigImpl.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/BaseWebServiceEndpoint.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/DOMWriter.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/DeploymentBuilder.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/JavaUtils.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/SOAPMessageAdapter.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/TemplateWebServiceEndpoint.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WSDLParser.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WSDLReference.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WSInvocationAdapter.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WebServiceDetails.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WebServiceProviderFactory.java
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WebServiceProviderGenerator.java
dwsp/trunk/src/main/resources/
dwsp/trunk/src/test/
dwsp/trunk/src/test/java/
dwsp/trunk/src/test/resources/
Modified:
dwsp/trunk/
Log:
Initial version of Dynamic Web Service Provider lib.
Property changes on: dwsp/trunk
___________________________________________________________________
Name: svn:ignore
+ .settings
target
.classpath
.project
Added: dwsp/trunk/pom.xml
===================================================================
--- dwsp/trunk/pom.xml (rev 0)
+++ dwsp/trunk/pom.xml 2010-11-22 13:22:37 UTC (rev 1130)
@@ -0,0 +1,283 @@
+<?xml version="1.0"?>
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.soa</groupId>
+ <artifactId>dwsp</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0.0-SNAPSHOT</version>
+ <name>SOA::DWSP</name>
+
+ <properties>
+ <junit.version>4.8.1</junit.version>
+ <jboss.version>5.1.0.GA</jboss.version>
+ <jaxws.version>2.1</jaxws.version>
+ <wsdl4j.version>1.6.2</wsdl4j.version>
+ <commons.logging.version>1.1.1</commons.logging.version>
+ <javassist.version>3.11.0.GA</javassist.version>
+ <jboss.metadata.version>1.0.1.GA</jboss.metadata.version>
+ <jboss.microcontainer.version>2.0.6.GA</jboss.microcontainer.version>
+ <jboss.deployers.version>2.0.7.GA</jboss.deployers.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>wsdl4j</groupId>
+ <artifactId>wsdl4j</artifactId>
+ <version>${wsdl4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>${commons.logging.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <version>${javassist.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.xml.ws</groupId>
+ <artifactId>jaxws-api</artifactId>
+ <version>${jaxws.version}</version>
+ </dependency>
+
+ <!-- Dependencies for JBoss specific deployer -->
+ <dependency>
+ <groupId>org.jboss.metadata</groupId>
+ <artifactId>jboss-metadata</artifactId>
+ <version>${jboss.metadata.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-kernel</artifactId>
+ <version>${jboss.microcontainer.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-dependency</artifactId>
+ <version>${jboss.microcontainer.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.deployers</groupId>
+ <artifactId>jboss-deployers-client-spi</artifactId>
+ <version>${jboss.deployers.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.deployers</groupId>
+ <artifactId>jboss-deployers-core-spi</artifactId>
+ <version>${jboss.deployers.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.deployers</groupId>
+ <artifactId>jboss-deployers-structure-spi</artifactId>
+ <version>${jboss.deployers.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.deployers</groupId>
+ <artifactId>jboss-deployers-vfs-spi</artifactId>
+ <version>${jboss.deployers.version}</version>
+ </dependency>
+
+ </dependencies>
+
+
+ <distributionManagement>
+ <repository>
+ <id>jboss-releases-repository</id>
+ <name>JBoss Releases Repository</name>
+
<
url>https://repository.jboss.org/nexus/service/local/staging/deploy/ma...
+ </repository>
+ <snapshotRepository>
+ <id>jboss-snapshots-repository</id>
+ <name>JBoss Snapshots Repository</name>
+
<
url>https://repository.jboss.org/nexus/content/repositories/snapshots/...
+ </snapshotRepository>
+ </distributionManagement>
+
+ <build>
+ <!-- This section defines the default plugin settings inherited by child projects.
-->
+ <pluginManagement>
+ <plugins>
+ <!-- Fixes how test resources of a project can be used in projects dependent
on it -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.2</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <aggregate>true</aggregate>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <!-- Specify the compiler options and settings -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <!--version>2.0.2</version-->
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ <showDeprecation>false</showDeprecation>
+ <showWarnings>false</showWarnings>
+ <optimize>true</optimize>
+ <compilerArgument>-verbose</compilerArgument>
+ </configuration>
+ </plugin>
+ <!-- Produce source jars during the 'verify' phase -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>**/*TestCase.java</include>
+ <include>**/*Test.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.2-beta-5</version>
+ </plugin>
+ </plugins>
+ </build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ </plugin>
+ <!--plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <version>2.3</version>
+ <configuration>
+ <xmlOutput>true</xmlOutput>
+ <xmlOutputDirectory>target/site</xmlOutputDirectory>
+ <onlyAnalyze>org.jboss.soa.bpel.*</onlyAnalyze>
+ </configuration>
+ </plugin-->
+ </plugins>
+ </reporting>
+
+ <repositories>
+
+ <repository>
+ <id>jboss-public-repository-group</id>
+ <name>JBoss Public Repository Group</name>
+ <
url>http://repository.jboss.org/nexus/content/groups/public</url>
+ <releases>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ </snapshots>
+ </repository>
+
+ </repositories>
+
+<!--
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.2</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <aggregate>true</aggregate>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>jboss-packaging-maven-plugin</artifactId>
+ <version>2.1.1</version>
+ <extensions>true</extensions>
+ <configuration>
+ <excludes>
+ <exclude>jboss:jboss-common</exclude>
+ <exclude>jboss:jboss-system</exclude>
+ <exclude>jboss:jboss-jmx</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ <showDeprecation>false</showDeprecation>
+ <showWarnings>false</showWarnings>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>**/*TestCase.java</include>
+ <include>**/*Test.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
+-->
+
+</project>
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/EndpointMetaData.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/EndpointMetaData.java
(rev 0)
+++ dwsp/trunk/src/main/java/org/jboss/soa/dwsp/EndpointMetaData.java 2010-11-22 13:22:37
UTC (rev 1130)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Minimum endpoint meta data that's required to create
+ * endpoints. Anything else is derived by the {@link
org.jboss.soa.bpel.runtime.ws.EndpointManager}
+ * itself.
+ *
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class EndpointMetaData
+{
+ private QName serviceName;
+ private String portName;
+ private String endpointId;
+ private QName processId;
+
+ public EndpointMetaData(QName serviceName, String portName, QName processId, String
endpointId)
+ {
+ this.serviceName = serviceName;
+ this.portName = portName;
+ this.processId = processId;
+ this.endpointId = endpointId;
+ }
+
+ public QName getServiceName()
+ {
+ return serviceName;
+ }
+
+ public String getPortName()
+ {
+ return portName;
+ }
+
+ public QName getProcessId()
+ {
+ return processId;
+ }
+
+ public String getEndpointId()
+ {
+ return endpointId;
+ }
+
+ public void setEndpointId(String endpointId)
+ {
+ this.endpointId = endpointId;
+ }
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/InvocationAdapter.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/InvocationAdapter.java
(rev 0)
+++ dwsp/trunk/src/main/java/org/jboss/soa/dwsp/InvocationAdapter.java 2010-11-22 13:22:37
UTC (rev 1130)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Hides the message translation details when invoking ODE from
+ * an external component (i.e. ESB or WS).
+ *
+ * @see org.jboss.soa.bpel.runtime.engine.BPELEngine#invoke(InvocationAdapter)
+ *
+ * @author Heiko Braun <hbraun(a)redhat.com>
+ */
+public interface InvocationAdapter<T> {
+
+ String getOperationName();
+
+ QName getServiceName();
+
+ String getPortName();
+
+ /**
+ * Callback from the Service towards the adapter when
+ * turning an external message representation into a Service request.
+ *
+ * @param mex
+ * @param odeRequest
+ */
+ void initRequest(javax.wsdl.Operation op, MessageAdapter request);
+
+ /**
+ * Callback from the Engine towards the adapter when
+ * turning an ODE response {@link org.apache.ode.bpel.iapi.Message} into an external
format <T>
+ * @param mex
+ */
+ void createResponse(javax.wsdl.Operation wsdl, MessageAdapter resp);
+
+ void createFault(javax.wsdl.Operation op, QName faultName, MessageAdapter fault);
+
+ /**
+ * Access the invocation result (response)
+ * @return T
+ */
+ T getInvocationResult();
+
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/MessageAdapter.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/MessageAdapter.java
(rev 0)
+++ dwsp/trunk/src/main/java/org/jboss/soa/dwsp/MessageAdapter.java 2010-11-22 13:22:37
UTC (rev 1130)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.dwsp;
+
+public interface MessageAdapter {
+
+ public org.w3c.dom.Element getMessage();
+
+ public void setPart(String name, org.w3c.dom.Element elem);
+
+ public org.w3c.dom.Element getPart(String name);
+
+ public void setHeaderPart(String name, org.w3c.dom.Element elem);
+
+ public java.util.Map<String, org.w3c.dom.Node> getHeaderParts();
+
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ServiceEndpointReference.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ServiceEndpointReference.java
(rev 0)
+++ dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ServiceEndpointReference.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp;
+
+/**
+ * References webservice endpoint deployment properties.
+ *
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class ServiceEndpointReference
+{
+ private String endpointId;
+ private java.net.URL serviceUrl;
+ private String deploymentName;
+ private String archiveLocation;
+
+ public ServiceEndpointReference(String endpointId, java.net.URL location, String
deploymentName,
+ String archiveLocation)
+ {
+ this.endpointId = endpointId;
+ this.serviceUrl = location;
+ this.deploymentName = deploymentName;
+ this.archiveLocation = archiveLocation;
+System.out.println("GPB: SER endpointId="+endpointId+"
location="+location+" deploymentName="+deploymentName+"
arch="+archiveLocation);
+ }
+
+ public String getArchiveLocation()
+ {
+ return archiveLocation;
+ }
+
+ /*
+ public void setArchiveLocation(String archiveLocation)
+ {
+ this.archiveLocation = archiveLocation;
+ }
+ */
+
+ public String getEndpointId()
+ {
+ return endpointId;
+ }
+
+ public java.net.URL getServiceUrl()
+ {
+ return serviceUrl;
+ }
+
+ public String getDeploymentName()
+ {
+ return deploymentName;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ ServiceEndpointReference that = (ServiceEndpointReference) o;
+
+ if (!archiveLocation.equals(that.archiveLocation)) return false;
+ if (!deploymentName.equals(that.deploymentName)) return false;
+ if (!endpointId.equals(that.endpointId)) return false;
+ if (!serviceUrl.equals(that.serviceUrl)) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = endpointId.hashCode();
+ result = 31 * result + serviceUrl.hashCode();
+ result = 31 * result + deploymentName.hashCode();
+ result = 31 * result + archiveLocation.hashCode();
+ return result;
+ }
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ServiceProvider.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ServiceProvider.java
(rev 0)
+++ dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ServiceProvider.java 2010-11-22 13:22:37
UTC (rev 1130)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.dwsp;
+
+public interface ServiceProvider {
+
+ /**
+ * This method initializes the service invoker. This method must
+ * be called before using the invoker.
+ *
+ * @throws Exception Failed to initialize
+ */
+ public void init() throws Exception;
+
+ /**
+ * This method invokes the associated service using the invocation
+ * adapter supplied.
+ *
+ * @param invocationAdapter The invocation adapter
+ * @throws Exception Failed to invoke the service
+ */
+ public void invoke(InvocationAdapter<?> invocationAdapter) throws Exception;
+
+ /**
+ * This method closes the service invoker.
+ *
+ * @throws Exception Failed to close
+ */
+ public void close() throws Exception;
+
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/deployer/ServiceDeployer.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/deployer/ServiceDeployer.java
(rev 0)
+++ dwsp/trunk/src/main/java/org/jboss/soa/dwsp/deployer/ServiceDeployer.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.dwsp.deployer;
+
+import java.net.URL;
+
+import org.jboss.soa.dwsp.EndpointMetaData;
+import org.jboss.soa.dwsp.ServiceEndpointReference;
+
+public interface ServiceDeployer {
+
+ public ServiceEndpointReference deploy(EndpointMetaData metaData, Class<?>
providerImpl, URL serviceUrl,
+ ClassLoader classLoader, java.io.File deployment) throws Exception;
+
+ public void undeploy(ServiceEndpointReference ref) throws Exception;
+
+}
Added:
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/deployer/jboss/JBossServiceDeployer.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/deployer/jboss/JBossServiceDeployer.java
(rev 0)
+++
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/deployer/jboss/JBossServiceDeployer.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,129 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.dwsp.deployer.jboss;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.deployers.structure.spi.ClassLoaderFactory;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.DeploymentUnitFilter;
+import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
+import org.jboss.kernel.Kernel;
+import org.jboss.metadata.web.jboss.JBossWebMetaData;
+import org.jboss.soa.dwsp.EndpointMetaData;
+import org.jboss.soa.dwsp.ServiceEndpointReference;
+import org.jboss.soa.dwsp.deployer.ServiceDeployer;
+import org.jboss.soa.dwsp.server.jboss.KernelLocator;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+public class JBossServiceDeployer implements ServiceDeployer {
+
+ public ServiceEndpointReference deploy(EndpointMetaData metaData, Class<?>
providerImpl, URL serviceUrl,
+ final ClassLoader classLoader, File warArchive) throws Exception {
+ Deployment deployment = createVFSDeployment(warArchive);
+
+ // Classloading
+ ClassLoaderFactory clf = new DelegatingClassLoaderFactory(classLoader);
+
+ // WebMetaData
+ String[] webContext = deriveWebContextFromServiceUrl(serviceUrl);
+
+ WebMetaDataFactory wmdFactory = new WebMetaDataFactory(
+ metaData.getEndpointId(), webContext[0], webContext[1],
providerImpl.getName()
+ );
+
+ MutableAttachments mutableAttachments =
+ (MutableAttachments)deployment.getPredeterminedManagedObjects();
+
+ // Applies to in memory only. Not used with VFS underneath
+ //mutableAttachments.addAttachment(StructureMetaData.class, new
StructureMetaDataImpl());
+ mutableAttachments.addAttachment(ClassLoaderFactory.class, clf);
+ mutableAttachments.addAttachment(JBossWebMetaData.class,
wmdFactory.createWebMetaData(classLoader));
+ mutableAttachments.addAttachment(DeploymentUnitFilter.class, new
RiftsawWSDeploymentUnitFilter());
+
+ getMainDeployer().deploy(deployment);
+
+ ServiceEndpointReference ref = new ServiceEndpointReference(
+ metaData.getEndpointId(), serviceUrl, deployment.getName(),
warArchive.getAbsolutePath()
+ );
+
+ //ref.setArchiveLocation(warArchive.getAbsolutePath());
+
+ return(ref);
+ }
+
+ public void undeploy(ServiceEndpointReference ref) throws Exception {
+ getMainDeployer().undeploy(ref.getDeploymentName());
+ }
+
+ private String[] deriveWebContextFromServiceUrl(URL serviceUrl) {
+ // metadata based on soapAddress
+ String urlPathInfo = serviceUrl.getPath(); // has always leading slash
+ urlPathInfo = urlPathInfo.substring(1, urlPathInfo.length());
+
+ String actualWebContext;
+ String actualUrlPattern;
+ actualWebContext = urlPathInfo;
+ actualUrlPattern = "/*";
+
+ return new String[] {actualWebContext, actualUrlPattern};
+ }
+
+ private Deployment createVFSDeployment(File war) throws IOException {
+ VirtualFile webAppVFS = VFS.getRoot(war.toURI().toURL());
+ return VFSDeploymentFactory.getInstance().createVFSDeployment(webAppVFS);
+ }
+
+ private DeployerClient getMainDeployer() {
+ Kernel mc = KernelLocator.getKernel();
+ ControllerContext context =
mc.getController().getInstalledContext("MainDeployer");
+ DeployerClient mainDeployer = (DeployerClient)context.getTarget();
+ return mainDeployer;
+ }
+
+ public class DelegatingClassLoaderFactory implements ClassLoaderFactory {
+ private ClassLoader delegate;
+
+ public DelegatingClassLoaderFactory(final ClassLoader delegate) {
+ this.delegate = delegate;
+ }
+
+ public ClassLoader createClassLoader(DeploymentUnit unit) throws Exception {
+ return delegate;
+ }
+
+ public void removeClassLoader(DeploymentUnit unit) throws Exception {
+ // cleanup?
+ }
+ }
+
+ public class RiftsawWSDeploymentUnitFilter implements DeploymentUnitFilter {
+ public boolean accepts(DeploymentUnit unit) {
+ // When I am attached, it's always a BPEL deployment
+ return false;
+ }
+ }
+
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/deployer/jboss/WebMetaDataFactory.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/deployer/jboss/WebMetaDataFactory.java
(rev 0)
+++
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/deployer/jboss/WebMetaDataFactory.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.deployer.jboss;
+
+import org.jboss.metadata.web.jboss.JBossServletMetaData;
+import org.jboss.metadata.web.jboss.JBossServletsMetaData;
+import org.jboss.metadata.web.jboss.JBossWebMetaData;
+import org.jboss.metadata.web.spec.ServletMappingMetaData;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Creates an in-memory representation of web meta data.
+ * Based on
http://anonsvn.jboss.org/repos/jbossas/tags/JBoss_5_1_0_GA/webservices/sr...
+ *
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class WebMetaDataFactory
+{
+ private String endpointId;
+ private String servletClassName = null;
+ private String webContext = null;
+ private String urlPattern = null;
+
+ public WebMetaDataFactory(String endpointId, String webContext, String urlPattern,
String servletClassName)
+ {
+ this.endpointId = endpointId;
+ this.servletClassName = servletClassName;
+ this.webContext = webContext;
+ this.urlPattern = urlPattern;
+ }
+
+ public JBossWebMetaData createWebMetaData(ClassLoader loader)
+ {
+ JBossWebMetaData jbwmd = new JBossWebMetaData();
+ createWebAppDescriptor(jbwmd);
+ createJBossWebAppDescriptor(jbwmd);
+ return jbwmd;
+ }
+
+ private void createWebAppDescriptor(JBossWebMetaData jbwmd)
+ {
+ /*
+ <servlet>
+ <servlet-name>
+ <servlet-class>
+ </servlet>
+ */
+ JBossServletsMetaData servlets = jbwmd.getServlets();
+ JBossServletMetaData servlet = new JBossServletMetaData();
+ servlet.setServletName("Endpoint-"+endpointId);
+ servlet.setServletClass(servletClassName);
+ servlets.add(servlet);
+
+
+ /*
+ <servlet-mapping>
+ <servlet-name>
+ <url-pattern>
+ </servlet-mapping>
+ */
+ List<ServletMappingMetaData> servletMappings = jbwmd.getServletMappings();
+ if (servletMappings == null)
+ {
+ servletMappings = new ArrayList<ServletMappingMetaData>();
+ jbwmd.setServletMappings(servletMappings);
+ }
+ ServletMappingMetaData servletMapping = new ServletMappingMetaData();
+ servletMapping.setServletName("Endpoint-"+endpointId);
+ ArrayList<String> urlPatterns = new ArrayList<String>();
+ urlPatterns.add(urlPattern);
+ servletMapping.setUrlPatterns(urlPatterns);
+ servletMappings.add(servletMapping);
+
+ }
+
+ private void createJBossWebAppDescriptor(JBossWebMetaData jbwmd)
+ {
+ /* Create a jboss-web
+ <jboss-web>
+ <security-domain>java:/jaas/cts</security-domain>
+ <context-root>/ws/ejbN/</context-root>
+ <virtual-host>some.domain.com</virtual-host>
+ </jboss-web>
+ */
+
+ jbwmd.setContextRoot(webContext);
+ }
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/ServerConfig.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/ServerConfig.java
(rev 0)
+++ dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/ServerConfig.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.server;
+
+import java.io.File;
+
+/**
+ * Interface to container independent config
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 08-May-2006
+ */
+public interface ServerConfig
+{
+ String getImplementationTitle();
+
+ String getImplementationVersion();
+
+ File getServerTempDir();
+
+ File getServerDataDir();
+
+ String getWebServiceHost();
+
+ int getWebServicePort();
+
+ int getWebServiceSecurePort();
+
+ String getClusterNodeName();
+
+ String getUddiNodeName();
+
+}
\ No newline at end of file
Added:
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/KernelAwareSPIFactory.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/KernelAwareSPIFactory.java
(rev 0)
+++
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/KernelAwareSPIFactory.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.server.jboss;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.kernel.spi.dependency.KernelController;
+
+/**
+ * SPI factory delegating to kernel for bean lookups
+ *
+ * @author richard.opalka(a)jboss.com
+ * @author Heiko.Braun(a)jboss.com
+ */
+public class KernelAwareSPIFactory
+{
+ @SuppressWarnings("unchecked")
+ public <T> T getKernelProvidedSPI(String beanName, Class<T> spiArtifact)
+ {
+ KernelController controller = KernelLocator.getKernel().getController();
+ ControllerContext ctx = controller.getInstalledContext(beanName);
+ return (T)ctx.getTarget();
+ }
+}
\ No newline at end of file
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/KernelLocator.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/KernelLocator.java
(rev 0)
+++ dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/KernelLocator.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.server.jboss;
+
+//$Id$
+
+import org.jboss.kernel.Kernel;
+
+/**
+ * Locate the single instance of the kernel
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 12-May-2006
+ */
+public class KernelLocator
+{
+ private static Kernel kernel;
+
+ public static Kernel getKernel()
+ {
+ return KernelLocator.kernel;
+ }
+
+ public void setKernel(Kernel kernel)
+ {
+ KernelLocator.kernel = kernel;
+ }
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/MBeanServerLocator.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/MBeanServerLocator.java
(rev 0)
+++
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/MBeanServerLocator.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.server.jboss;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import java.util.Iterator;
+
+/**
+ * Locate the single instance of the MBeanServer
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 30-Jul-2007
+ */
+public class MBeanServerLocator
+{
+ private MBeanServer mbeanServer;
+
+ public MBeanServer getMbeanServer()
+ {
+ // In jboss-4.2 the MBeanServer cannot be injected
+ if (mbeanServer == null)
+ {
+ for (Iterator i = MBeanServerFactory.findMBeanServer(null).iterator();
i.hasNext();)
+ {
+ mbeanServer = (MBeanServer)i.next();
+ break;
+ }
+ }
+ return mbeanServer;
+ }
+
+ public void setMbeanServer(MBeanServer mbeanServer)
+ {
+ this.mbeanServer = mbeanServer;
+ }
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/ObjectNameFactory.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/ObjectNameFactory.java
(rev 0)
+++
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/ObjectNameFactory.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.server.jboss;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import java.util.Hashtable;
+
+/**
+ * A simple factory for creating safe object names.
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 08-May-2006
+ */
+public class ObjectNameFactory
+{
+ public static ObjectName create(String name)
+ {
+ try
+ {
+ return new ObjectName(name);
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new Error("Invalid ObjectName: " + name + "; " + e);
+ }
+ }
+
+ public static ObjectName create(String domain, String key, String value)
+ {
+ try
+ {
+ return new ObjectName(domain, key, value);
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new Error("Invalid ObjectName: " + domain + "," + key +
"," + value + "; " + e);
+ }
+ }
+
+ public static ObjectName create(String domain, Hashtable table)
+ {
+ try
+ {
+ return new ObjectName(domain, table);
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new Error("Invalid ObjectName: " + domain + "," + table +
"; " + e);
+ }
+ }
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/ServerConfigFactory.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/ServerConfigFactory.java
(rev 0)
+++
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/ServerConfigFactory.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.server.jboss;
+
+import org.jboss.soa.dwsp.server.ServerConfig;
+
+
+/**
+ * Factory to container independent config
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @author Heiko.Braun(a)jboss.com
+ *
+ * @since 08-May-2006
+ */
+public class ServerConfigFactory
+{
+ /** The default bean name */
+ public static String BEAN_NAME =
"org.jboss.soa.bpel.runtime.util:service=ServerConfig";
+
+ public static ServerConfig getServerConfig()
+ {
+ return new KernelAwareSPIFactory().getKernelProvidedSPI(
+ BEAN_NAME, ServerConfig.class
+ );
+ }
+}
\ No newline at end of file
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/ServerConfigImpl.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/ServerConfigImpl.java
(rev 0)
+++
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/server/jboss/ServerConfigImpl.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,252 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.server.jboss;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.soa.dwsp.server.ServerConfig;
+import org.jboss.util.id.GUID;
+
+import javax.management.AttributeNotFoundException;
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Set;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class ServerConfigImpl implements ServerConfig
+{
+ protected final Log log = LogFactory.getLog(getClass());
+
+ // The MBeanServer
+ private MBeanServer mbeanServer;
+
+ private final static String UNDEFINED_HOSTNAME = "undefined.host";
+
+ // The webservice host name that will be used when updating the wsdl
+ private String webServiceHost = UNDEFINED_HOSTNAME;
+ // The webservice port that will be used when updating the wsdl
+ private int webServicePort;
+ // The webservice port that will be used when updating the wsdl
+ private int webServiceSecurePort;
+
+ private static String nonClusteredServerName=new GUID().toString();
+
+ private String clusterNodeName;
+
+ public ServerConfigImpl()
+ {
+ }
+
+ public MBeanServer getMbeanServer()
+ {
+ return mbeanServer;
+ }
+
+ public void setMbeanServer(MBeanServer mbeanServer)
+ {
+ this.mbeanServer = mbeanServer;
+ }
+
+ public String getImplementationTitle()
+ {
+ return "jbossas-riftsaw";
+ }
+
+ public String getImplementationVersion()
+ {
+ return "5.x";
+ }
+
+ public File getServerTempDir()
+ {
+ try
+ {
+ ObjectName oname =
ObjectNameFactory.create("jboss.system:type=ServerConfig");
+ File dir = (File)getMbeanServer().getAttribute(oname, "ServerTempDir");
+ return dir;
+ }
+ catch (JMException e)
+ {
+ return null;
+ }
+ }
+
+ public File getHomeDir()
+ {
+ try
+ {
+ ObjectName oname =
ObjectNameFactory.create("jboss.system:type=ServerConfig");
+ File dir = (File)getMbeanServer().getAttribute(oname, "HomeDir");
+ return dir;
+ }
+ catch (JMException e)
+ {
+ return null;
+ }
+ }
+
+ public File getServerDataDir()
+ {
+ try
+ {
+ ObjectName oname =
ObjectNameFactory.create("jboss.system:type=ServerConfig");
+ File dir = (File)getMbeanServer().getAttribute(oname, "ServerDataDir");
+ return dir;
+ }
+ catch (JMException e)
+ {
+ return null;
+ }
+ }
+
+ public String getWebServiceHost()
+ {
+ return webServiceHost;
+ }
+
+ public void setWebServiceHost(String host) throws UnknownHostException
+ {
+ if (host == null || host.trim().length() == 0)
+ {
+ log.debug("Using undefined host: " + UNDEFINED_HOSTNAME);
+ host = UNDEFINED_HOSTNAME;
+ }
+ if ("0.0.0.0".equals(host))
+ {
+ InetAddress localHost = InetAddress.getLocalHost();
+ log.debug("Using local host: " + localHost.getHostName());
+ host = localHost.getHostName();
+ }
+ this.webServiceHost = host;
+ }
+
+ public void setWebServicePort(int port)
+ {
+ this.webServicePort = port;
+ }
+
+ public void setWebServiceSecurePort(int port)
+ {
+ this.webServiceSecurePort = port;
+ }
+
+ public int getWebServicePort()
+ {
+ if (webServicePort <= 0)
+ webServicePort = getConnectorPort("HTTP/1.1", false);
+
+ int localPort = webServicePort;
+ if (localPort <= 0)
+ {
+ // Do not initialize webServicePort with the default, the connector port may become
available later
+ log.warn("Unable to calculate 'WebServicePort', using default
'8080'");
+ localPort = 8080;
+ }
+
+ return localPort;
+ }
+
+
+ public int getWebServiceSecurePort()
+ {
+ if (webServiceSecurePort <= 0)
+ webServiceSecurePort = getConnectorPort("HTTP/1.1", true);
+
+ int localPort = webServiceSecurePort;
+ if (localPort <= 0)
+ {
+ // Do not initialize webServiceSecurePort with the default, the connector port may
become available later
+ log.warn("Unable to calculate 'WebServiceSecurePort', using default
'8443'");
+ localPort = 8443;
+ }
+
+ return localPort;
+ }
+
+ private int getConnectorPort(final String protocol, final boolean secure)
+ {
+ int port = -1;
+
+ try
+ {
+ ObjectName connectors = new ObjectName("jboss.web:type=Connector,*");
+
+ Set connectorNames = getMbeanServer().queryNames(connectors, null);
+ for (Object current : connectorNames)
+ {
+ ObjectName currentName = (ObjectName)current;
+
+ try
+ {
+ int connectorPort = (Integer)getMbeanServer().getAttribute(currentName,
"port");
+ boolean connectorSecure = (Boolean)getMbeanServer().getAttribute(currentName,
"secure");
+ String connectorProtocol = (String)getMbeanServer().getAttribute(currentName,
"protocol");
+
+
+ if (protocol.equals(connectorProtocol) && secure == connectorSecure)
+ {
+ if (port > -1)
+ {
+ log.warn("Found multiple connectors for protocol='" +
protocol + "' and secure='" + secure + "', using first port
found '" + port + "'");
+ }
+ else
+ {
+ port = connectorPort;
+ }
+ }
+ }
+ catch (AttributeNotFoundException ignored)
+ {
+ }
+ }
+
+ return port;
+ }
+ catch (JMException e)
+ {
+ return -1;
+ }
+ }
+
+ public String getClusterNodeName() {
+ if (this.clusterNodeName == null || "".equals(this.clusterNodeName.trim()))
{
+ return nonClusteredServerName;
+ }
+ return this.clusterNodeName;
+ }
+
+ public void setClusterNodeName(String clusterNodeName) {
+ this.clusterNodeName = clusterNodeName;
+ }
+
+
+ public String getUddiNodeName() {
+ return this.getWebServiceHost() + "-" + this.getWebServicePort();
+ }
+
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/BaseWebServiceEndpoint.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/BaseWebServiceEndpoint.java
(rev 0)
+++ dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/BaseWebServiceEndpoint.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,226 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.ws;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Operation;
+import javax.wsdl.WSDLException;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+import javax.xml.soap.*;
+import javax.xml.ws.Provider;
+
+/**
+ * Base class for BPEL endpoints that are created through javassist.
+ * Represents a JAX-WS {@link javax.xml.ws.Provider} implementation.
+ *
+ * @see org.jboss.soa.dwsp.ws.WebServiceProviderGenerator
+ *
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class BaseWebServiceEndpoint implements Provider<SOAPMessage>
+{
+ protected final Log log = LogFactory.getLog(getClass());
+
+ private SOAPMessageAdapter soapAdapter;
+ private QName serviceQName;
+ private Definition wsdlDefinition;
+ private WebServiceProviderFactory serviceFactory;
+
+ private boolean isInitialized;
+
+ private void init()
+ {
+ if(!isInitialized)
+ {
+ try
+ {
+ WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
+ this.wsdlDefinition = wsdlReader.readWSDL(getWsdlLocation());
+ this.serviceQName = QName.valueOf(getServiceName());
+ this.soapAdapter = new SOAPMessageAdapter(wsdlDefinition, serviceQName,
getPortName());
+
+ WebServiceDetails details=getClass().getAnnotation(WebServiceDetails.class);
+
+ if (details != null) {
+ try {
+ Class<?> cls=Class.forName(details.factory());
+
+ serviceFactory = (WebServiceProviderFactory)cls.newInstance();
+
+ } catch(ClassNotFoundException cnfe) {
+ throw new RuntimeException("Unable to find Web Service Factory class
'"+
+ details.factory()+"'", cnfe);
+ } catch(Exception ex) {
+ throw new RuntimeException("Failed to instantiate Web Service Factory
class '"+
+ details.factory()+"'", ex);
+ }
+ } else {
+ throw new RuntimeException("Web service details not defined on Web Service
endpoint");
+ }
+ }
+ catch (WSDLException e)
+ {
+ throw new RuntimeException("Failed to parse WSDL", e);
+ }
+ isInitialized = true;
+ }
+ }
+
+ public SOAPMessage invoke(SOAPMessage soapMessage)
+ {
+ log.debug("Invoking endpoint "+getEndpointId());
+ init();
+
+ try
+ {
+ SOAPPart soapPart = soapMessage.getSOAPPart();
+ SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
+ Element messageElement = getMessagePayload(soapEnvelope);
+
+ if(log.isDebugEnabled())
+ log.debug( "ODE inbound message: \n" +DOMWriter.printNode(soapEnvelope,
true) );
+
+ // Create invocation context
+ final String operationName = resolveOperationName(messageElement);
+
+ WSInvocationAdapter invocationContext =
serviceFactory.getInvocationAdapter(operationName,
+ serviceQName, getPortName(), soapAdapter);
+
+ invocationContext.setSOAPMessage(soapMessage);
+
+ // Invoke ODE
+ serviceFactory.getServiceProvider().invoke(invocationContext);
+
+ // Handle response
+ SOAPMessage responseMessage = null;
+
+ if (isResponseExpected(messageElement)) {
+ responseMessage = invocationContext.getInvocationResult();
+
+ if(log.isDebugEnabled())
+ log.debug( "ODE outbound message: \n" +
+ DOMWriter.printNode(responseMessage.getSOAPPart().getEnvelope(), true)
+ );
+ } else if (log.isDebugEnabled()) {
+ log.debug( "ODE no outbound message");
+ }
+
+ if (responseMessage == null) {
+ log.debug("No response, probably due to oneway request");
+
+ // Need to create an empty response to avoid npe in jbossws (RIFTSAW-154)
+ responseMessage = MessageFactory.newInstance().createMessage();
+ }
+
+ return responseMessage;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to invoke BPEL process:
"+e.getMessage(), e);
+ }
+ }
+
+ public String resolveOperationName(Element payload)
+ {
+ if(soapAdapter.isRPC())
+ {
+ return payload.getLocalName();
+ }
+ else
+ {
+ QName elementName = new QName(payload.getNamespaceURI(), payload.getLocalName());
+ Operation op = new WSDLParser(wsdlDefinition).getDocLitOperation(
+ this.serviceQName, getPortName(), elementName
+ );
+
+ return op.getName();
+ }
+ }
+
+ public boolean isResponseExpected(Element payload)
+ {
+ Operation op=null;
+
+ if(soapAdapter.isRPC())
+ {
+ QName elementName = new QName(payload.getNamespaceURI(),
payload.getLocalName());
+ op = new WSDLParser(wsdlDefinition).getRPCOperation(
+ this.serviceQName, getPortName(), elementName
+ );
+ }
+ else
+ {
+ QName elementName = new QName(payload.getNamespaceURI(), payload.getLocalName());
+ op = new WSDLParser(wsdlDefinition).getDocLitOperation(
+ this.serviceQName, getPortName(), elementName
+ );
+ }
+
+ if (op == null) {
+ throw new RuntimeException("Failed to locate operation definition for:
"+payload);
+ }
+
+ return op.getOutput() != null;
+ }
+
+ public static Element getMessagePayload(SOAPEnvelope soapEnvelope)
+ throws SOAPException
+ {
+ SOAPBody body = soapEnvelope.getBody();
+ Element messageElement = null; // first child of type Element
+ NodeList children = body.getChildNodes();
+ for(int i=0; i<children.getLength(); i++)
+ {
+ Node tmp = children.item(i);
+ if(Node.ELEMENT_NODE == tmp.getNodeType())
+ {
+ messageElement = (Element)tmp;
+ break;
+ }
+ }
+ return messageElement;
+ }
+
+ public String getEndpointId() {
+ return(null);
+ }
+
+ public String getServiceName() {
+ return(null);
+ }
+
+ public String getWsdlLocation() {
+ return(null);
+ }
+
+ public String getPortName() {
+ return(null);
+ }
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/DOMWriter.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/DOMWriter.java
(rev 0)
+++ dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/DOMWriter.java 2010-11-22 13:22:37 UTC
(rev 1130)
@@ -0,0 +1,656 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.ws;
+
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (
http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Tomcat", and "Apache
Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache(a)apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <
http://www.apache.org/>.
+ */
+
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Traverse a DOM tree in order to print a document that is parsed.
+ *
+ * @author Andy Clark, IBM
+ * @author Thomas.Diesler(a)jboss.org
+ */
+@SuppressWarnings("unchecked")
+public class DOMWriter
+{
+ // Print writer
+ private PrintWriter out;
+ // True, if canonical output
+ private boolean canonical;
+ // True, if pretty printing should be used
+ private boolean prettyprint;
+ // True, if the XML declaration should be written
+ private boolean writeXMLDeclaration;
+ // True, if whitespace should be ignored
+ private boolean ignoreWhitespace;
+ // Explicit character set encoding
+ private String charsetName;
+ // indent for the pretty printer
+ private int prettyIndent;
+ // True, if the XML declaration has been written
+ private boolean wroteXMLDeclaration;
+ // The node that started the write
+ private Node rootNode;
+ // True if we want namespace completion
+ private boolean completeNamespaces = true;
+ // The current default namespace
+ private String currentDefaultNamespace;
+
+ public DOMWriter(Writer w)
+ {
+ this.out = new PrintWriter(w);
+ }
+
+ public DOMWriter(Writer w, String charsetName)
+ {
+ this.out = new PrintWriter(w);
+ this.charsetName = charsetName;
+ this.writeXMLDeclaration = true;
+ }
+
+ public DOMWriter(OutputStream stream)
+ {
+ try
+ {
+ this.out = new PrintWriter(new OutputStreamWriter(stream, "UTF-8"));
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ // ignore, UTF-8 should be available
+ }
+ }
+
+ public DOMWriter(OutputStream stream, String charsetName)
+ {
+ try
+ {
+ this.out = new PrintWriter(new OutputStreamWriter(stream, charsetName));
+ this.charsetName = charsetName;
+ this.writeXMLDeclaration = true;
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new IllegalArgumentException("Unsupported encoding: " +
charsetName);
+ }
+ }
+
+ /**
+ * Print a node with explicit prettyprinting.
+ * The defaults for all other DOMWriter properties apply.
+ *
+ */
+ public static String printNode(Node node, boolean prettyprint)
+ {
+ StringWriter strw = new StringWriter();
+ new DOMWriter(strw).setPrettyprint(prettyprint).print(node);
+ return strw.toString();
+ }
+
+ public boolean isCanonical()
+ {
+ return canonical;
+ }
+
+ /**
+ * Set wheter entities should appear in their canonical form.
+ * The default is false.
+ */
+ public DOMWriter setCanonical(boolean canonical)
+ {
+ this.canonical = canonical;
+ return this;
+ }
+
+ public boolean isIgnoreWhitespace()
+ {
+ return ignoreWhitespace;
+ }
+
+ /**
+ * Set whether whitespace should be ignored.
+ * The default is false.
+ */
+ public DOMWriter setIgnoreWhitespace(boolean ignoreWhitespace)
+ {
+ this.ignoreWhitespace = ignoreWhitespace;
+ return this;
+ }
+
+ /**
+ * Set wheter subelements should have their namespaces completed.
+ * Setting this to false may lead to invalid XML fragments.
+ * The default is true.
+ */
+ public DOMWriter setCompleteNamespaces(boolean complete)
+ {
+ this.completeNamespaces = complete;
+ return this;
+ }
+
+ public boolean isPrettyprint()
+ {
+ return prettyprint;
+ }
+
+ /**
+ * Set wheter element should be indented.
+ * The default is false.
+ */
+ public DOMWriter setPrettyprint(boolean prettyprint)
+ {
+ this.prettyprint = prettyprint;
+ return this;
+ }
+
+ public boolean isWriteXMLDeclaration()
+ {
+ return writeXMLDeclaration;
+ }
+
+ /**
+ * Set wheter the XML declaration should be written.
+ * The default is false.
+ */
+ public DOMWriter setWriteXMLDeclaration(boolean flag)
+ {
+ this.writeXMLDeclaration = flag;
+ return this;
+ }
+
+ public void print(Node node)
+ {
+ if (prettyprint && ignoreWhitespace)
+ throw new IllegalStateException("Cannot pretty print and ignore
whitespace");
+
+ rootNode = node;
+ printInternal(node, false);
+ }
+
+ private void printInternal(Node node, boolean indentEndMarker)
+ {
+ // is there anything to do?
+ if (node == null)
+ {
+ return;
+ }
+
+ // JBAS-2117 - Don't skip the DOCUMENT_NODE
+ // if (node instanceof Document) node = ((Document)node).getDocumentElement();
+
+ if (wroteXMLDeclaration == false && writeXMLDeclaration == true &&
canonical == false)
+ {
+ out.print("<?xml version='1.0'");
+ if (charsetName != null)
+ out.print(" encoding='" + charsetName + "'");
+
+ out.print("?>");
+ if (prettyprint)
+ out.println();
+
+ wroteXMLDeclaration = true;
+ }
+
+ int type = node.getNodeType();
+ boolean hasChildNodes = node.getChildNodes().getLength() > 0;
+
+ String nodeName = node.getNodeName();
+ switch (type)
+ {
+ // print document
+ case Node.DOCUMENT_NODE:
+ {
+ NodeList children = node.getChildNodes();
+ int len = children.getLength();
+ for (int iChild = 0; iChild < len; iChild++)
+ {
+ printInternal(children.item(iChild), false);
+ }
+ out.flush();
+ break;
+ }
+
+ // print element with attributes
+ case Node.ELEMENT_NODE:
+ {
+ Element element = (Element)node;
+ if (prettyprint)
+ {
+ for (int i = 0; i < prettyIndent; i++)
+ {
+ out.print(' ');
+ }
+ prettyIndent++;
+ }
+
+ out.print('<');
+ out.print(nodeName);
+
+ Map nsMap = new HashMap();
+ String elPrefix = node.getPrefix();
+ String elNamespaceURI = node.getNamespaceURI();
+ if (elPrefix != null)
+ {
+ String nsURI = getNamespaceURI(elPrefix, element, rootNode);
+ nsMap.put(elPrefix, nsURI);
+ }
+
+ Attr attrs[] = sortAttributes(node.getAttributes());
+ for (int i = 0; i < attrs.length; i++)
+ {
+ Attr attr = attrs[i];
+ String atPrefix = attr.getPrefix();
+ String atName = attr.getNodeName();
+ String atValue = normalize(attr.getNodeValue(), canonical);
+
+ if (atName.equals("xmlns"))
+ currentDefaultNamespace = atValue;
+
+ if (atPrefix != null && !atPrefix.equals("xmlns")
&& !atPrefix.equals("xml"))
+ {
+ String nsURI = getNamespaceURI(atPrefix, element, rootNode);
+ nsMap.put(atPrefix, nsURI);
+ // xsi:type='ns1:SubType', xsi:type='xsd:string'
+ if (atName.equals(atPrefix + ":type") &&
atValue.indexOf(":") > 0)
+ {
+ // xsi defined on the envelope
+ if (nsURI == null)
+ nsURI = getNamespaceURI(atPrefix, element, null);
+
+ if
("http://www.w3.org/2001/XMLSchema-instance".equals(nsURI))
+ {
+ String typePrefix = atValue.substring(0,
atValue.indexOf(":"));
+ String typeURI = getNamespaceURI(typePrefix, element, rootNode);
+ nsMap.put(typePrefix, typeURI);
+ }
+ }
+ }
+
+ out.print(" " + atName + "='" + atValue +
"'");
+ }
+
+ // Add namespace declaration for prefixes
+ // that are defined further up the tree
+ if (completeNamespaces)
+ {
+ Iterator itPrefix = nsMap.keySet().iterator();
+ while (itPrefix.hasNext())
+ {
+ String prefix = (String)itPrefix.next();
+ String nsURI = (String)nsMap.get(prefix);
+ if (nsURI == null)
+ {
+ nsURI = getNamespaceURI(prefix, element, null);
+ out.print(" xmlns:" + prefix + "='" + nsURI
+ "'");
+ }
+ }
+ }
+
+ // The SAX ContentHandler will by default not add the namespace declaration
+ // <Hello xmlns='http://somens'>World</Hello>
+ if (elPrefix == null && elNamespaceURI != null)
+ {
+ String defaultNamespace = element.getAttribute("xmlns");
+ if (defaultNamespace.length() == 0 &&
!elNamespaceURI.equals(currentDefaultNamespace))
+ {
+ out.print(" xmlns='" + elNamespaceURI +
"'");
+ currentDefaultNamespace = elNamespaceURI;
+ }
+ }
+
+ if (hasChildNodes)
+ {
+ out.print('>');
+ }
+
+ // Find out if the end marker is indented
+ indentEndMarker = isEndMarkerIndented(node);
+
+ if (indentEndMarker)
+ {
+ out.print('\n');
+ }
+
+ NodeList childNodes = node.getChildNodes();
+ int len = childNodes.getLength();
+ for (int i = 0; i < len; i++)
+ {
+ Node childNode = childNodes.item(i);
+ printInternal(childNode, false);
+ }
+ break;
+ }
+
+ // handle entity reference nodes
+ case Node.ENTITY_REFERENCE_NODE:
+ {
+ if (canonical)
+ {
+ NodeList children = node.getChildNodes();
+ if (children != null)
+ {
+ int len = children.getLength();
+ for (int i = 0; i < len; i++)
+ {
+ printInternal(children.item(i), false);
+ }
+ }
+ }
+ else
+ {
+ out.print('&');
+ out.print(nodeName);
+ out.print(';');
+ }
+ break;
+ }
+
+ // print cdata sections
+ case Node.CDATA_SECTION_NODE:
+ {
+ if (canonical)
+ {
+ out.print(normalize(node.getNodeValue(), canonical));
+ }
+ else
+ {
+ out.print("<![CDATA[");
+ out.print(node.getNodeValue());
+ out.print("]]>");
+ }
+ break;
+ }
+
+ // print text
+ case Node.TEXT_NODE:
+ {
+ String text = normalize(node.getNodeValue(), canonical);
+ if (text.trim().length() > 0)
+ {
+ out.print(text);
+ }
+ else if (prettyprint == false && ignoreWhitespace == false)
+ {
+ out.print(text);
+ }
+ break;
+ }
+
+ // print processing instruction
+ case Node.PROCESSING_INSTRUCTION_NODE:
+ {
+ out.print("<?");
+ out.print(nodeName);
+ String data = node.getNodeValue();
+ if (data != null && data.length() > 0)
+ {
+ out.print(' ');
+ out.print(data);
+ }
+ out.print("?>");
+ break;
+ }
+
+ // print comment
+ case Node.COMMENT_NODE:
+ {
+ for (int i = 0; i < prettyIndent; i++)
+ {
+ out.print(' ');
+ }
+
+ out.print("<!--");
+ String data = node.getNodeValue();
+ if (data != null)
+ {
+ out.print(data);
+ }
+ out.print("-->");
+
+ if (prettyprint)
+ {
+ out.print('\n');
+ }
+
+ break;
+ }
+ }
+
+ if (type == Node.ELEMENT_NODE)
+ {
+ if (prettyprint)
+ prettyIndent--;
+
+ if (hasChildNodes == false)
+ {
+ out.print("/>");
+ }
+ else
+ {
+ if (indentEndMarker)
+ {
+ for (int i = 0; i < prettyIndent; i++)
+ {
+ out.print(' ');
+ }
+ }
+
+ out.print("</");
+ out.print(nodeName);
+ out.print('>');
+ }
+
+ if (prettyIndent > 0)
+ {
+ out.print('\n');
+ }
+ }
+ out.flush();
+ }
+
+ private String getNamespaceURI(String prefix, Element element, Node stopNode)
+ {
+ Node parent = element.getParentNode();
+ String nsURI = element.getAttribute("xmlns:" + prefix);
+ if (nsURI.length() == 0 && element != stopNode && parent instanceof
Element)
+ return getNamespaceURI(prefix, (Element)parent, stopNode);
+
+ return (nsURI.length() > 0 ? nsURI : null);
+ }
+
+ private boolean isEndMarkerIndented(Node node)
+ {
+ if (prettyprint)
+ {
+ NodeList childNodes = node.getChildNodes();
+ int len = childNodes.getLength();
+ for (int i = 0; i < len; i++)
+ {
+ Node children = childNodes.item(i);
+ if (children.getNodeType() == Node.ELEMENT_NODE)
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /** Returns a sorted list of attributes. */
+ private Attr[] sortAttributes(NamedNodeMap attrs)
+ {
+
+ int len = (attrs != null) ? attrs.getLength() : 0;
+ Attr array[] = new Attr[len];
+ for (int i = 0; i < len; i++)
+ {
+ array[i] = (Attr)attrs.item(i);
+ }
+ for (int i = 0; i < len - 1; i++)
+ {
+ String name = array[i].getNodeName();
+ int index = i;
+ for (int j = i + 1; j < len; j++)
+ {
+ String curName = array[j].getNodeName();
+ if (curName.compareTo(name) < 0)
+ {
+ name = curName;
+ index = j;
+ }
+ }
+ if (index != i)
+ {
+ Attr temp = array[i];
+ array[i] = array[index];
+ array[index] = temp;
+ }
+ }
+ return (array);
+ }
+
+ /** Normalizes the given string. */
+ public static String normalize(String s, boolean canonical)
+ {
+ int len = (s != null) ? s.length() : 0;
+ StringBuilder str = new StringBuilder();
+
+ for (int i = 0; i < len; i++)
+ {
+ char ch = s.charAt(i);
+ switch (ch)
+ {
+ case '<':
+ {
+ str.append("<");
+ break;
+ }
+ case '>':
+ {
+ str.append(">");
+ break;
+ }
+ case '&':
+ {
+ str.append("&");
+ break;
+ }
+ case '"':
+ {
+ str.append(""");
+ break;
+ }
+ case '\'':
+ {
+ str.append("'");
+ break;
+ }
+ case '\r':
+ case '\n':
+ {
+ if (canonical)
+ {
+ str.append("&#");
+ str.append(Integer.toString(ch));
+ str.append(';');
+ break;
+ }
+ // else, default append char
+ }
+ default:
+ {
+ str.append(ch);
+ }
+ }
+ }
+ return (str.toString());
+ }
+}
\ No newline at end of file
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/DeploymentBuilder.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/DeploymentBuilder.java
(rev 0)
+++ dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/DeploymentBuilder.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,222 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.ws;
+
+import org.jboss.soa.dwsp.server.ServerConfig;
+
+import java.io.*;
+
+public class DeploymentBuilder
+{
+ private static final String SI = "si";
+
+ private File war;
+ private File webInf;
+ private File wsdlDir;
+ private DeploymentBuilder instance;
+
+ private ServerConfig serverConfig;
+
+ public DeploymentBuilder(ServerConfig serverConfig)
+ {
+ this.serverConfig = serverConfig;
+ }
+
+ public DeploymentBuilder setEndpoint(String endpointId)
+ {
+ File tmpDir = new File(serverConfig.getServerTempDir(), SI);
+
+ tmpDir.mkdir();
+ File fakeWebApp = new File(tmpDir, SI+"-"+endpointId+".war");
+ File fakeWebInf = new File(fakeWebApp, "WEB-INF");
+ fakeWebInf.mkdirs();
+
+ // Workaround
+ // See
https://jira.jboss.org/jira/browse/JBWS-2718
+ File fakeWSDLDir = new File(fakeWebInf, "wsdl");
+ fakeWSDLDir.mkdirs();
+
+ this.war = fakeWebApp;
+ this.webInf = fakeWebInf;
+ this.wsdlDir = fakeWSDLDir;
+
+ return this;
+ }
+
+ public DeploymentBuilder setWSDL(File wsdl, File root)
+ {
+ copy(wsdl, new File(this.wsdlDir, wsdl.getName()));
+
+ // any related artifact as well (brute force, I know)
+ //File parent = wsdl.getParentFile();
+ //assert parent.isDirectory();
+
+ FileFilter filter = new FileFilter()
+ {
+ public boolean accept(File f)
+ {
+ // Deploy all artifacts, as we don't know what might be relevant in a
+ // particular execution context
+ return (true);
+ }
+ };
+
+ for(File f : root.listFiles(filter))
+ {
+ if(f.equals(wsdl)) continue;
+ copy(f, new File(this.wsdlDir, f.getName()));
+ copy(f, new File(this.webInf, f.getName()));
+
+
+/* Causes problems with testcase RIFTSAW-70 on jbossws-native. Ok
+ on jbossws-cxf. So just copying all artifacts to both locations
+ for now.
+
+ if (f.getName().endsWith(".wsdl") ||
+ f.getName().endsWith(".xsd")) {
+ copy(f, new File(this.wsdlDir, f.getName()));
+ } else {
+ copy(f, new File(this.webInf, f.getName()));
+ }
+*/
+ }
+ return this;
+ }
+
+ public DeploymentBuilder setProvider(javax.xml.ws.Provider<?> provider) {
+
+ // Check if jbossws-cxf.xml is present, and if so, updated the provider implementation
class attribute
+ File f=new File(this.webInf, "jbossws-cxf.xml");
+
+ if (f.exists()) {
+ FileInputStream fis=null;
+ FileOutputStream fos=null;
+
+ try {
+ fis=new FileInputStream(f);
+
+ byte[] b=new byte[fis.available()];
+ fis.read(b);
+
+ String str=new String(b);
+
+ fis.close();
+ fis = null;
+
+ if (str.indexOf("@provider@") != -1) {
+ fos=new FileOutputStream(f);
+
+ str = str.replaceAll("@provider@", provider.getClass().getName());
+
+ fos.write(str.getBytes());
+
+ fos.flush();
+ fos.close();
+
+ fos = null;
+ } else {
+ // Report error
+ System.err.println("jbossws-cxf.xml file does not contain @provider@
field");
+ }
+
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to copy files", e);
+ } finally {
+ try {
+ if (fis != null) fis.close();
+ } catch (IOException e) {
+ }
+ try {
+ if (fos != null) fos.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+
+ return this;
+ }
+
+ public File build()
+ {
+ return this.war;
+ }
+
+ public static synchronized void copy(File src, File dest)
+ {
+ InputStream in = null;
+ OutputStream out = null;
+
+ try
+ {
+ if (src.isDirectory())
+ {
+ if (!dest.exists()) {
+ dest.mkdir();
+ }
+
+ String[] children = src.list();
+ for (int i=0; i<children.length; i++) {
+ copy(new File(src, children[i]),
+ new File(dest, children[i]));
+ }
+ } else {
+
+ in = new FileInputStream(src);
+ out = new FileOutputStream(dest);
+
+ // Copy the bits from instream to outstream
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ in.close();
+ out.close();
+ }
+
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Failed to copy files", e);
+ }
+ finally
+ {
+ try
+ {
+ if(in!=null) in.close();
+ }
+ catch (IOException e)
+ {
+ //
+ }
+
+ try
+ {
+ if(out!=null) out.close();
+ }
+ catch (IOException e)
+ {
+ //
+ }
+ }
+ }
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/JavaUtils.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/JavaUtils.java
(rev 0)
+++ dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/JavaUtils.java 2010-11-22 13:22:37 UTC
(rev 1130)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.ws;
+
+import java.io.ByteArrayOutputStream;
+import java.lang.reflect.Method;
+
+import javax.xml.soap.SOAPMessage;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ * @author Jeff Yu <cyu(a)redhat.com>
+ */
+public class JavaUtils
+{
+ protected static final Log log = LogFactory.getLog(JavaUtils.class);
+
+ public static boolean isJBossRepositoryClassLoader(ClassLoader loader)
+ {
+ Class clazz = loader.getClass();
+ while (!clazz.getName().startsWith("java"))
+ {
+ if
("org.jboss.mx.loading.RepositoryClassLoader".equals(clazz.getName()))
+ return true;
+ clazz = clazz.getSuperclass();
+ }
+
+ return false;
+ }
+
+ /**
+ * Clears black lists on a JBoss RepositoryClassLoader. This is somewhat of a hack,
and
+ * could be replaced with an integration module. This is needed when the following
order of
+ * events occur.
+ *
+ * <ol>
+ * <li>loadClass() returns not found</li>
+ * <li>Some call to defineClass()</li>
+ * <ol>
+ *
+ * The CNFE triggers a black list addition, which cause the class never again to be
found.
+ *
+ * @param loader the loader to clear black lists for
+ */
+ public static void clearBlacklists(ClassLoader loader)
+ {
+ if (isJBossRepositoryClassLoader(loader))
+ {
+ for(Method m : loader.getClass().getMethods())
+ {
+ if("clearBlackLists".equalsIgnoreCase(m.getName()))
+ {
+ try
+ {
+ m.invoke(loader);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Convert the SoapMessage object into String.
+ * @param soapMessage
+ * @return
+ */
+ public static String getSoapMessageASString(SOAPMessage soapMessage) {
+ try {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ soapMessage.writeTo(outputStream);
+ byte[] byteArray = outputStream.toByteArray();
+ String soapMsg = new String( byteArray, "UTF-8");
+ return soapMsg;
+ } catch (Exception e) {
+ log.error("Error in converting SOAPMessage into String");
+ }
+ return null;
+ }
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/SOAPMessageAdapter.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/SOAPMessageAdapter.java
(rev 0)
+++ dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/SOAPMessageAdapter.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,832 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.ws;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+//import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;
+import org.jboss.soa.dwsp.MessageAdapter;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import javax.wsdl.*;
+import javax.wsdl.extensions.ElementExtensible;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.http.HTTPBinding;
+import javax.wsdl.extensions.soap.SOAPBinding;
+import javax.wsdl.extensions.soap.SOAPHeader;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.soap.*;
+
+import java.util.*;
+
+/**
+ * Adopts {@link javax.xml.soap.SOAPMessage}'s to ODE's internal
+ * {@link org.apache.ode.bpel.iapi.Message} representation and vice versa.
+ *
+ * @see org.jboss.soa.bpel.runtime.ws.WebServiceClient
+ *
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class SOAPMessageAdapter
+{
+ protected static final Log log = LogFactory.getLog(SOAPMessageAdapter.class);
+
+ private Definition wsdl;
+ private QName serviceName;
+
+ private String portName;
+ private Service serviceDef;
+ private Binding binding;
+
+ private Port port;
+ private boolean isRPC;
+
+ private SOAPBinding soapBinding;
+
+ private SOAPFactory soapFactory;
+
+ public SOAPMessageAdapter(Definition wsdl, QName serviceName, String portName)
+ {
+ this.wsdl = wsdl;
+ this.serviceName = serviceName;
+ this.portName = portName;
+
+ serviceDef = wsdl.getService(serviceName);
+ if (serviceDef == null)
+ throw new RuntimeException("Service not found "+serviceName);
+
+ port = serviceDef.getPort(portName);
+ if (port == null)
+ throw new RuntimeException("Port '"+portName+"' not found on
service: "+serviceName);
+
+ binding = port.getBinding();
+ if (binding == null)
+ throw new RuntimeException("No binding for port "+portName);
+
+ if (!useSOAPBinding(port)) {
+ throw new RuntimeException("No SOAP binding for port"+portName);
+ }
+ soapBinding = (SOAPBinding)getBindingExtension(port);
+
+
+ String style = soapBinding.getStyle();
+ isRPC = style != null && style.equals("rpc");
+
+ try
+ {
+ this.soapFactory = SOAPFactory.newInstance();
+ }
+ catch (SOAPException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * This method creates the SOAP request and returns the SOAPAction field.
+ *
+ * @param soapMessage
+ * @param odeRequestMessage
+ * @param wsdlOperation
+ * @return The SOAP action
+ */
+ public String createSoapRequest(SOAPMessage soapMessage, MessageAdapter
odeRequestMessage, Operation wsdlOperation)
+ {
+ String ret=null;
+
+ BindingOperation bop = binding.getBindingOperation(wsdlOperation.getName(), null,
null);
+ if (bop == null)
+ throw new RuntimeException("Operation "+wsdlOperation.getName()+"not
found on "+serviceName+"/"+portName);
+
+ BindingInput bi = bop.getBindingInput();
+ if (bi == null)
+ throw new RuntimeException("Binding input not found on
"+serviceName+"/"+portName);
+
+ // Headers
+ createSoapHeaders(
+ soapMessage,
+ getSOAPHeaders(bi),
+ wsdlOperation.getInput().getMessage(),
+ odeRequestMessage.getHeaderParts(),
+ odeRequestMessage.getMessage()
+ );
+
+
+ // SOAP Body
+ javax.wsdl.extensions.soap.SOAPBody wsdlSoapBody = getSOAPBody(bi);
+
+ createSoapBody(
+ soapMessage,
+ wsdlSoapBody,
+ wsdlOperation.getInput().getMessage(),
+ odeRequestMessage.getMessage(),
+ wsdlOperation.getName()
+ );
+
+ // Discover SOAPAction
+ for (Object extension : bop.getExtensibilityElements()) {
+ if (extension instanceof javax.wsdl.extensions.soap.SOAPOperation) {
+ javax.wsdl.extensions.soap.SOAPOperation soapop=
+ (javax.wsdl.extensions.soap.SOAPOperation)extension;
+
+ if (soapop.getSoapActionURI() != null) {
+ ret = soapop.getSoapActionURI();
+ break;
+ }
+ }
+ }
+
+ return(ret);
+ }
+
+ public boolean isRPC()
+ {
+ return isRPC;
+ }
+
+ public void createSoapResponse(SOAPMessage soapMessage, MessageAdapter
odeResponseMessage, Operation wsdlOperation)
+ {
+
+ BindingOperation bop =
binding.getBindingOperation(wsdlOperation.getName(),null,null);
+ if (bop == null)
+ throw new RuntimeException("Operation "+wsdlOperation.getName()+"not
found on "+serviceName+"/"+portName);
+
+ BindingOutput bo = bop.getBindingOutput();
+ if (bo == null)
+ throw new RuntimeException("Binding output not found on
"+serviceName+"/"+portName);
+
+ // Headers
+ if (odeResponseMessage.getHeaderParts().size() > 0 || getSOAPHeaders(bo).size()
> 0)
+ createSoapHeaders(
+ soapMessage,
+ getSOAPHeaders(bo),
+ wsdlOperation.getOutput().getMessage(),
+ odeResponseMessage.getHeaderParts(),
+ odeResponseMessage.getMessage()
+ );
+
+
+ // SOAP Body
+ javax.wsdl.extensions.soap.SOAPBody wsdlSOAPBody = getSOAPBody(bo);
+ createSoapBody(
+ soapMessage,
+ wsdlSOAPBody,
+ wsdlOperation.getOutput().getMessage(),
+ odeResponseMessage.getMessage(),
+ wsdlOperation.getName() + "Response"
+ );
+
+ }
+
+ private void createSoapBody(SOAPMessage soapMessage,
+ javax.wsdl.extensions.soap.SOAPBody wsdlSoapBody,
javax.wsdl.Message wsdlMessageDef,
+ Element message, String operationName)
+ {
+ try
+ {
+ SOAPBody soapBody = soapMessage.getSOAPBody();
+
+ SOAPElement partHolder = null;
+ if(isRPC)
+ {
+ partHolder = soapFactory.createElement(new QName(wsdlSoapBody.getNamespaceURI(),
operationName, "odens"));
+ }
+ else
+ {
+ partHolder = soapBody;
+ }
+
+ List<Part> parts = wsdlMessageDef.getOrderedParts(wsdlSoapBody.getParts());
+ for(Part part : parts)
+ {
+ Element srcPartEl = findChildByName(message, new QName(null, part.getName()));
+ if (srcPartEl == null)
+ throw new RuntimeException("Part is missing: " +part.getName());
+
+ SOAPElement partElement = soapFactory.createElement(srcPartEl);
+ if (isRPC)
+ {
+ partHolder.addChildElement(partElement);
+ }
+ else
+ {
+ for (Iterator<SOAPElement> i = partElement.getChildElements();
i.hasNext();) partHolder.addChildElement(i.next());
+ }
+ }
+
+ // late bind
+ if(isRPC)
+ soapBody.addChildElement(partHolder);
+ }
+ catch (SOAPException e)
+ {
+ throw new RuntimeException("Failed to create soap body",e);
+ }
+ }
+
+ private void createSoapHeaders(SOAPMessage soapMessage, List<SOAPHeader>
headers,
+ javax.wsdl.Message wsdlMessageDef,
+ Map<String, Node> headerParts, Element message)
+ {
+ try {
+ javax.xml.soap.SOAPHeader soapHeader = soapMessage.getSOAPHeader();
+ if (soapHeader==null) soapHeader =
soapMessage.getSOAPPart().getEnvelope().addHeader();
+ for (Node headerNode : headerParts.values()) {
+ //like we may have password header with null value.
+ if(headerNode == null){
+ continue;
+ }
+ if (Node.ELEMENT_NODE == headerNode.getNodeType()) {
+ if (getFirstChildWithName(new QName(headerNode.getNamespaceURI(),
headerNode.getLocalName()),soapHeader) == null) {
+ SOAPElement partElement = soapFactory.createElement((Element) headerNode);
+ soapHeader.addChildElement(partElement);
+ }
+ } else {
+ throw new RuntimeException("SOAP header must be a node_element " +
headerNode);
+ }
+ }
+
+ //Add soap header according to binding.
+ for (SOAPHeader header : headers) {
+ Element headerEl = findChildByName(message, new QName(null, header.getPart()));
+ if (headerEl != null) {
+
+ // RIFTSAW-305 - don't think the part name should be added to the SOAP header
+ //SOAPElement soapHeaderEl = soapFactory.createElement(new
QName(header.getMessage().getNamespaceURI(), header.getPart(),"odens"));
+ NodeList list = headerEl.getChildNodes();
+ for(int i=0; i< list.getLength(); i++) {
+ SOAPElement partElement = soapFactory.createElement((Element)list.item(i));
+ soapHeader.addChildElement(partElement);
+ }
+ //soapHeader.addChildElement(soapHeaderEl);
+ }
+ }
+ } catch (SOAPException e) {
+ throw new RuntimeException("Failed to create soap header",e);
+ }
+ }
+
+ public void parseSoapResponse(MessageAdapter odeMessage,
+ SOAPMessage soapMessage, javax.wsdl.Operation
odeOperation) {
+ BindingOperation bop = binding.getBindingOperation(odeOperation.getName(), null,
null);
+ if (bop == null)
+ throw new RuntimeException("Operation "+odeOperation.getName()+"not
found on "+serviceName+"/"+portName);
+
+ BindingOutput bo = bop.getBindingOutput();
+ if (bo == null)
+ throw new RuntimeException("Binding output not found on
"+serviceName+"/"+portName);
+
+ extractSoapBodyParts(odeMessage, soapMessage, getSOAPBody(bo),
odeOperation.getOutput().getMessage(), odeOperation.getName() + "Response");
+ extractSoapHeaderParts(odeMessage, soapMessage, getSOAPHeaders(bo),
odeOperation.getOutput().getMessage());
+ }
+
+ public void parseSoapRequest(MessageAdapter odeMessage,
+ SOAPMessage soapMessage,
+ Operation op)
+ {
+
+ BindingOperation bop = binding.getBindingOperation(op.getName(), null, null);
+
+ if (bop == null)
+ throw new RuntimeException("Binding operation not found
("+serviceName+"/"+portName);
+
+ BindingInput bi = bop.getBindingInput();
+ if (bi == null)
+ throw new RuntimeException("Binding input not
found"+serviceName+"/"+portName);
+
+ extractSoapBodyParts(odeMessage, soapMessage, getSOAPBody(bi),
op.getInput().getMessage(), op.getName());
+ extractSoapHeaderParts(odeMessage, soapMessage, getSOAPHeaders(bi),
op.getInput().getMessage());
+ }
+
+ public void createSoapFault(SOAPMessage soapMessage, Element message, QName faultName,
Operation op)
+ {
+ try
+ {
+ Element detail = buildSoapDetail(message, faultName, op);
+ SOAPFault fault = soapMessage.getSOAPBody().addFault();
+ fault.setFaultCode(faultName);
+ if(detail!=null)
+ fault.addDetail().addChildElement(soapFactory.createElement(detail));
+ }
+ catch (SOAPException e)
+ {
+ throw new RuntimeException("Failed to create fault", e);
+ }
+ }
+
+ private Element buildSoapDetail(Element message, QName faultName, Operation op)
+ {
+ if (faultName.getNamespaceURI() == null)
+ return toFaultDetail(faultName, message);
+ if (op == null) {
+ return toFaultDetail(faultName, message);
+ }
+ Fault f = op.getFault(faultName.getLocalPart());
+ if (f == null)
+ return toFaultDetail(faultName, message);
+
+ // For faults, there will be exactly one part.
+ Part p = (Part)f.getMessage().getParts().values().iterator().next();
+ if (p == null)
+ return toFaultDetail(faultName, message);
+ Element partEl= findChildByName(message,new QName(null,p.getName()));
+ if (partEl == null)
+ return toFaultDetail(faultName, message);
+ Element detail = findChildByName(partEl, p.getElementName());
+ if (detail == null)
+ return toFaultDetail(faultName, message);
+
+ return detail;
+ }
+
+ private Element toFaultDetail(QName fault, Element message) {
+ if (message == null) return null;
+ Element firstPart = getFirstChildElement(message);
+ if (firstPart == null) return null;
+ Element detail = getFirstChildElement(firstPart);
+ if (detail == null) return firstPart;
+ return detail;
+ }
+
+ private void extractSoapHeaderParts(MessageAdapter odeMessage, SOAPMessage soapMessage,
List<SOAPHeader> headerDefs,javax.wsdl.Message wsdlMessageDef)
+ {
+ try {
+ javax.xml.soap.SOAPHeader soapHeader = soapMessage.getSOAPHeader();
+ // Checking that the definitions we have are at least there
+ for (SOAPHeader headerDef : headerDefs)
+ handleSoapHeaderPartDef(odeMessage, soapHeader, headerDef, wsdlMessageDef);
+
+ // Extracting whatever header elements we find in the message, binding and
abstract parts
+ // aren't reliable enough given what people do out there.
+ if (soapHeader != null) {
+ Iterator headersIter = soapHeader.getChildElements();
+ while (headersIter.hasNext()) {
+ Object obj=headersIter.next();
+
+ // Should be SOAPHeaderElement, but CXF also returns javax.xml.soap.Text
+ // objects aswell
+ if (obj instanceof javax.xml.soap.SOAPHeaderElement) {
+ javax.xml.soap.SOAPHeaderElement headerElem =
(javax.xml.soap.SOAPHeaderElement) obj;
+ String partName = findHeaderPartName(headerDefs,
headerElem.getElementQName());
+ Document doc = newDocument();
+
+ // RIFTSAW-74 - slight modification to avoid jbossws exception when
reconstructing the
+ // SOAP message.
+
+ //Element destPart = doc.createElementNS(null, partName);
+ //destPart.appendChild(doc.importNode(headerElem, true));
+ //odeMessage.setHeaderPart(partName, destPart);
+ odeMessage.setHeaderPart(partName, (Element)doc.importNode(headerElem, true));
+ }
+ }
+ }
+ }
+ catch (SOAPException e)
+ {
+ throw new RuntimeException("Failed to extracts header parts",e);
+ }
+ }
+
+ private String findHeaderPartName(List<SOAPHeader> headerDefs, QName elmtName) {
+ for (SOAPHeader headerDef : headerDefs) {
+ javax.wsdl.Message hdrMsg = wsdl.getMessage(headerDef.getMessage());
+ for (Object o : hdrMsg.getParts().values()) {
+ Part p = (Part) o;
+ if (p.getElementName() != null &&
+ p.getElementName().equals(elmtName)) return p.getName();
+ }
+ }
+ return elmtName.getLocalPart();
+ }
+
+ private void handleSoapHeaderPartDef(Object odeMessage, javax.xml.soap.SOAPHeader
header, SOAPHeader headerdef,
+ javax.wsdl.Message msgType) {
+ // Is this header part of the "payload" messsage?
+ boolean payloadMessageHeader = headerdef.getMessage() == null ||
headerdef.getMessage().equals(msgType.getQName());
+ boolean requiredHeader = payloadMessageHeader ||
Boolean.TRUE.equals(headerdef.getRequired());
+
+ if (header == null) {
+ if (requiredHeader)
+ throw new RuntimeException("Soap Header is missing a required field " +
headerdef.getElementType());
+
+ return;
+ }
+
+ javax.wsdl.Message hdrMsg = wsdl.getMessage(headerdef.getMessage());
+ if (hdrMsg == null)
+ return;
+ Part p = hdrMsg.getPart(headerdef.getPart());
+ if (p == null || p.getElementName() == null)
+ return;
+
+ SOAPElement headerEl = getFirstChildWithName(p.getElementName(), header);
+ if (requiredHeader && headerEl == null)
+ throw new RuntimeException("Soap Header is missing a required field "
+ headerdef.getElementType());
+
+ if (headerEl == null) return;
+
+ /* RIFTSAW-127 - this was duplicating the header part in the consolidated (merged)
message stored in the
+ * BPEL process - but this code actually causes two levels of 'part' to be
defined - e.g.
+ * <conversionId><conversationId><details ....
/></conversatioId></conversationId>
+ Document doc = DOMUtils.newDocument();
+ Element destPart = doc.createElementNS(null, p.getName());
+ destPart.appendChild(doc.importNode(headerEl, true));
+ odeMessage.setHeaderPart(p.getName(), destPart);
+ */
+ }
+
+ private void extractSoapBodyParts(
+ MessageAdapter odeMessage,
+ SOAPMessage soapMessage,
+ javax.wsdl.extensions.soap.SOAPBody wsdlSOAPBody,
+ javax.wsdl.Message wsdlMessageDef, String operationName)
+ {
+ try
+ {
+ SOAPBody soapBody = soapMessage.getSOAPBody();
+ List<Part> parts = wsdlMessageDef.getOrderedParts(wsdlSOAPBody.getParts());
+
+ if(isRPC)
+ {
+ // In RPC the body element is the operation name, wrapping parts. Order
doesn't really matter as far as
+ // we're concerned. All we need to do is copy the soap:body children, since
doc-lit rpc looks the same
+ // in ode and soap.
+
+ QName rpcWrapQName = new QName(wsdlSOAPBody.getNamespaceURI(), operationName);
+ SOAPElement partWrapper = getFirstChildWithName(rpcWrapQName, soapBody);
+
+ if (partWrapper == null)
+ throw new RuntimeException("Expected part wrapper
'"+rpcWrapQName+"'missing on
service:"+serviceName+"/"+portName);
+
+ for(Part part : parts)
+ {
+ Element srcPart = getFirstChildWithName(new QName(null, part.getName()),
partWrapper);
+ if (srcPart == null)
+ throw new RuntimeException("Soap body does not contain required part
+"+part.getName());
+
+ odeMessage.setPart(srcPart.getLocalName(), srcPart);
+ }
+ }
+ else
+ {
+ // In doc-literal style, we expect the elements in the body to correspond (in
order)
+ // to the parts defined in the binding.
+ // All the parts should be element-typed, otherwise it is a mess.
+ List<SOAPElement> childElements = new ArrayList<SOAPElement>();
+ final Iterator children = soapBody.getChildElements() ;
+ while(children.hasNext())
+ {
+ final Node node = (Node)children.next() ;
+ if (node instanceof SOAPElement)
+ childElements.add((SOAPElement)node);
+ }
+
+ Iterator<SOAPElement> srcParts = childElements.iterator();
+ for(Part part : parts)
+ {
+ SOAPElement srcPart = srcParts.next();
+ Document doc = newDocument();
+ Element destPart = doc.createElementNS(null, part.getName());
+ destPart.appendChild(doc.importNode(srcPart, true));
+ odeMessage.setPart(part.getName(), destPart);
+ }
+ }
+ }
+ catch (SOAPException e)
+ {
+ throw new RuntimeException("Failed to extract soap body parts", e);
+ }
+ }
+
+ private static SOAPElement getFirstChildWithName(QName name, SOAPElement parent)
+ {
+ SOAPElement match = null;
+ Iterator iterator = parent.getChildElements(name);
+ while(iterator.hasNext())
+ {
+ match= (SOAPElement)iterator.next();
+ }
+ return match;
+ }
+
+ /*private static Element cloneElement(Element source)
+ {
+ // TODO:
https://jira.jboss.org/jira/browse/RIFTSAW-38
+ // For now create a deep copy (performance hit)
+ try
+ {
+ DocumentBuilder builder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document doc = builder.newDocument();
+ return (Element)doc.importNode(source, true);
+ }
+ catch (ParserConfigurationException e)
+ {
+ throw new RuntimeException(e);
+ }
+ } */
+
+ public static <T> T getFirstExtensibilityElement(ElementExtensible parent,
Class<T> cls) {
+ Collection<T> ee = filter(parent.getExtensibilityElements(), cls);
+
+ return ee.isEmpty() ? null : ee.iterator().next();
+
+ }
+
+ public static javax.wsdl.extensions.soap.SOAPBody getSOAPBody(ElementExtensible ee) {
+ return getFirstExtensibilityElement(ee, javax.wsdl.extensions.soap.SOAPBody.class);
+ }
+
+ public static List<SOAPHeader> getSOAPHeaders(ElementExtensible eee) {
+ return filter(new ArrayList<SOAPHeader>(), (Collection<Object>)
eee.getExtensibilityElements(),
+ SOAPHeader.class);
+ }
+
+ public static Fault parseSoapFault(
+ Element odeMessage,
+ SOAPMessage soapMessage,
+ javax.wsdl.Operation operation)
+ {
+ Fault fdef = null;
+ try
+ {
+ SOAPFault flt = soapMessage.getSOAPBody().getFault();
+ Detail detail = flt.getDetail();
+ fdef = inferFault(operation, flt);
+ if(fdef!=null)
+ {
+ Part pdef = (Part)fdef.getMessage().getParts().values().iterator().next();
+ Element partel =
odeMessage.getOwnerDocument().createElementNS(null,pdef.getName());
+ odeMessage.appendChild(partel);
+
+ Element childByName = findChildByName(detail, pdef.getElementName());
+ if (childByName != null)
+ {
+ partel.appendChild(odeMessage.getOwnerDocument().importNode(childByName,
true));
+ }
+ else
+ {
+ partel.appendChild(odeMessage.getOwnerDocument().importNode(detail,true));
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to parse SOAP Fault",e);
+ }
+
+ return fdef;
+ }
+
+ public static Fault parseSoapFault(
+ Element odeMessage,
+ SOAPFault flt,
+ javax.wsdl.Operation operation)
+ {
+ Fault fault=inferFault(operation, flt);
+
+ if(fault!=null)
+ {
+ Detail detail = flt.getDetail();
+ Part pdef = (Part)fault.getMessage().getParts().values().iterator().next();
+ Element partel =
odeMessage.getOwnerDocument().createElementNS(null,pdef.getName());
+ odeMessage.appendChild(partel);
+
+ Element childByName = findChildByName(detail, pdef.getElementName());
+ if (childByName != null)
+ {
+ partel.appendChild(odeMessage.getOwnerDocument().importNode(childByName,
true));
+ }
+ else
+ {
+ partel.appendChild(odeMessage.getOwnerDocument().importNode(detail,true));
+ }
+ }
+
+ return fault;
+ }
+
+ private static Fault inferFault(Operation operation, SOAPFault flt) {
+ if (!flt.hasDetail())
+ return null;
+ // The detail is a dummy <detail> node containing the interesting fault
element
+ Element element = getFirstChildElement(flt.getDetail());
+
+ if (element == null) {
+ return(null);
+ }
+
+ QName elName=new QName(element.getNamespaceURI(), element.getLocalName());
+ return inferFault(operation, elName);
+ }
+
+
+ // Code taken from Apache ODE util module
+
+ private static ThreadLocal<DocumentBuilder> __builders = new ThreadLocal();
+
+ private static DocumentBuilderFactory __documentBuilderFactory ;
+
+ static {
+ initDocumentBuilderFactory();
+ }
+
+ /**
+ * Initialize the document-builder factory.
+ */
+ private static void initDocumentBuilderFactory() {
+ DocumentBuilderFactory f =
javax.xml.parsers.DocumentBuilderFactory.newInstance();//new
DocumentBuilderFactoryImpl();
+ f.setNamespaceAware(true);
+ __documentBuilderFactory = f;
+ }
+
+ private static DocumentBuilder getBuilder() {
+ DocumentBuilder builder = __builders.get();
+ if (builder == null) {
+ synchronized (__documentBuilderFactory) {
+ try {
+ builder = __documentBuilderFactory.newDocumentBuilder();
+ builder.setErrorHandler(new org.xml.sax.ErrorHandler() {
+
+ public void error(SAXParseException arg0)
+ throws SAXException {
+ log.error("Parser error", arg0);
+ }
+
+ public void fatalError(SAXParseException arg0)
+ throws SAXException {
+ log.error("Parser fatal error", arg0);
+ }
+
+ public void warning(SAXParseException arg0)
+ throws SAXException {
+ log.warn("Parser warning", arg0);
+ }
+
+ });
+ } catch (ParserConfigurationException e) {
+ log.error(e);
+ throw new RuntimeException(e);
+ }
+ }
+ __builders.set(builder);
+ }
+ return builder;
+ }
+
+ public static Document newDocument() {
+ DocumentBuilder db = getBuilder();
+ return db.newDocument();
+ }
+
+ /**
+ * Return the first child element of the given element. Null if no children
+ * are found.
+ *
+ * @param elem Element whose child is to be returned
+ *
+ * @return the first child element.
+ */
+ public static Element getFirstChildElement(Element elem) {
+ return (Element) findChildByType(elem, Node.ELEMENT_NODE);
+ }
+
+ public static Element findChildByName(Element parent, QName name) {
+ return findChildByName(parent, name, false);
+ }
+
+ public static Element findChildByName(Element parent, QName name, boolean recurse) {
+ if (parent == null)
+ throw new IllegalArgumentException("null parent");
+ if (name == null)
+ throw new IllegalArgumentException("null name");
+
+ NodeList nl = parent.getChildNodes();
+ for (int i = 0; i < nl.getLength(); ++i) {
+ Node c = nl.item(i);
+ if(c.getNodeType() != Node.ELEMENT_NODE)
+ continue;
+ // For a reason that I can't fathom, when using in-mem DAO we actually get
elements with
+ // no localname.
+ String nodeName = c.getLocalName() != null ? c.getLocalName() :
c.getNodeName();
+ if (new QName(c.getNamespaceURI(),nodeName).equals(name))
+ return (Element) c;
+ }
+
+ if(recurse){
+ NodeList cnl = parent.getChildNodes();
+ for (int i = 0; i < cnl.getLength(); ++i) {
+ Node c = cnl.item(i);
+ if(c.getNodeType() != Node.ELEMENT_NODE)
+ continue;
+ Element result = findChildByName((Element)c, name, recurse);
+ if(result != null)
+ return result;
+ }
+ }
+ return null;
+ }
+
+ public static Node findChildByType(Element elem, int type) {
+ if (elem == null)
+ throw new NullPointerException("elem parameter must not be null!");
+
+ for (Node n = elem.getFirstChild(); n != null; n = n.getNextSibling()) {
+ if (n.getNodeType() == type) {
+ return n;
+ }
+ }
+ return null;
+ }
+
+ public static <C extends Collection<T>, S, T extends S> C filter(C newList,
Iterator<S> iterator, Class<T> t) {
+ while (iterator.hasNext()) {
+ S next = iterator.next();
+ if (t.isAssignableFrom(next.getClass())) {
+ newList.add((T) next);
+ }
+ }
+ return newList;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> Collection<T> filter(Collection src, final Class<T>
aClass) {
+ return filter(new ArrayList<T>(src.size()), src.iterator(), aClass);
+ }
+
+ public static <C extends Collection<T>, S, T extends S> C filter(C dest,
Collection<S> src, Class<T> t) {
+ return filter(dest, src.iterator(), t);
+ }
+
+ @SuppressWarnings("unchecked")
+ public static Fault inferFault(Operation operation, QName elName) {
+ for (Fault f : (Collection<Fault>) operation.getFaults().values()) {
+ if (f.getMessage() == null) continue;
+ Collection<Part> parts = f.getMessage().getParts().values();
+ if (parts.isEmpty()) continue;
+ Part p = parts.iterator().next();
+ if (p.getElementName() == null) continue;
+ if (p.getElementName().equals(elName)) return f;
+ }
+ return null;
+ }
+
+ public static ExtensibilityElement getBindingExtension(Binding binding) {
+ Collection bindings = new ArrayList();
+ filter(bindings, binding.getExtensibilityElements(), HTTPBinding.class);
+ filter(bindings, binding.getExtensibilityElements(), SOAPBinding.class);
+ if (bindings.size() == 0) {
+ return null;
+ } else if (bindings.size() > 1) {
+ // exception if multiple bindings found
+ throw new IllegalArgumentException("Binding
"+binding.getQName()+" has multiple binding elements");
+ } else {
+ // retrieve the single element
+ ExtensibilityElement result = (ExtensibilityElement)
bindings.iterator().next();
+ return result;
+ }
+ }
+
+ public static ExtensibilityElement getBindingExtension(Port port) {
+ Binding binding = port.getBinding();
+ if (binding == null) {
+ throw new IllegalArgumentException("Binding not found: port
"+port.getName()+".");
+ }
+ return getBindingExtension(binding);
+ }
+
+ public static boolean useSOAPBinding(Binding binding) {
+ ExtensibilityElement element = getBindingExtension(binding);
+ return SOAPBinding.class.isAssignableFrom(element.getClass());
+ }
+
+ public static boolean useSOAPBinding(Port port) {
+ return useSOAPBinding(port.getBinding());
+ }
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/TemplateWebServiceEndpoint.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/TemplateWebServiceEndpoint.java
(rev 0)
+++
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/TemplateWebServiceEndpoint.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.ws;
+
+
+import javax.xml.soap.*;
+import javax.xml.ws.Provider;
+
+
+/**
+ * CXF requires the JAX-WS implementation class to directly implement the
+ * Provider<SOAPMessage>, rather than be derived from a superclass that
+ * implements it. Therefore this 'template' web service endpoint class
+ * has been created, which will be loaded by javassist and renamed to
+ * be the specific endpoint implementation. This is necessary as
+ * javassist does not provide a way to set a interface that uses generics.
+ *
+ * @see org.jboss.soa.dwsp.ws.WebServiceProviderGenerator
+ *
+ */
+public class TemplateWebServiceEndpoint extends BaseWebServiceEndpoint implements
Provider<SOAPMessage>
+{
+ // See RIFTSAW-123 for description of issue related to CXF
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WSDLParser.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WSDLParser.java
(rev 0)
+++ dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WSDLParser.java 2010-11-22 13:22:37 UTC
(rev 1130)
@@ -0,0 +1,223 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.ws;
+
+import javax.wsdl.*;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.xml.namespace.QName;
+import java.net.URL;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * WSDL helper class
+ */
+public final class WSDLParser
+{
+
+ private Definition wsdlDefinition;
+ private int dfsDepth = 0;
+
+ public WSDLParser(Definition wsdlDefinition)
+ {
+ this.wsdlDefinition = wsdlDefinition;
+ }
+
+ public void reset()
+ {
+ dfsDepth = 0;
+ }
+
+ public Operation getRPCOperation(QName service, String port, QName payloadName)
+ {
+ reset();
+ Operation result = _getRPCOperation(this.wsdlDefinition, service, port,
payloadName);
+ if (result == null)
+ throw new IllegalArgumentException("Unable to find operation for element
"+payloadName);
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Operation _getRPCOperation(Definition wsdl, QName serviceName, String portName,
QName payloadName)
+ {
+ if(++dfsDepth>50) // easier then retaining references
+ throw new IllegalStateException("Recursive loop detected. DFS depth reached
limit");
+
+ // namespace / java.util.List of imports
+ Collection<List<Import>> imports = wsdl.getImports().values();
+ for(List<Import> importNS : imports)
+ {
+ for(Import wsdlImport : importNS)
+ {
+ Operation result = _getRPCOperation(wsdlImport.getDefinition(), serviceName,
portName, payloadName);
+ if(result!=null)
+ return result;
+ }
+ }
+
+ // resolve the port & operation
+ Service service = wsdl.getService(serviceName);
+ if (service == null)
+ return null; // service might be defined elsewhere
+
+ Port port = service.getPort(portName);
+ if (port == null)
+ throw new IllegalArgumentException("service "+serviceName+" contains
no such port "+portName);
+
+ Binding binding = port.getBinding();
+ PortType portType = binding.getPortType();
+ List<Operation> operations = portType.getOperations();
+ for(Operation op : operations)
+ {
+ if(op.getName().equals(payloadName.getLocalPart()))
+ return op;
+ }
+
+ return null;
+ }
+
+ public Operation getDocLitOperation(QName service, String port, QName payloadName)
+ {
+ reset();
+ Operation result = _getDocLitOperation(this.wsdlDefinition, service, port,
payloadName);
+ if (result == null)
+ throw new IllegalArgumentException("Unable to find operation for element
"+payloadName);
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Operation _getDocLitOperation(Definition wsdl, QName serviceName, String
portName, QName payloadName)
+ {
+ if(++dfsDepth>50) // easier then retaining references
+ throw new IllegalStateException("Recursive loop detected. DFS depth reached
limit");
+
+ // namespace / java.util.List of imports
+ Collection<List<Import>> imports = wsdl.getImports().values();
+ for(List<Import> importNS : imports)
+ {
+ for(Import wsdlImport : importNS)
+ {
+ Operation result = _getDocLitOperation(wsdlImport.getDefinition(), serviceName,
portName, payloadName);
+ if(result!=null)
+ return result;
+ }
+ }
+
+ // resolve the port & operation
+ Service service = wsdl.getService(serviceName);
+ if (service == null)
+ return null; // service might be defined elsewhere
+
+ Port port = service.getPort(portName);
+ if (port == null)
+ throw new IllegalArgumentException("service "+serviceName+" contains
no such port "+portName);
+
+ Binding binding = port.getBinding();
+ PortType portType = binding.getPortType();
+ List<Operation> operations = portType.getOperations();
+ for(Operation op : operations)
+ {
+ Message message = op.getInput().getMessage();
+ Collection<Part> parts = message.getParts().values();
+ for(Part part : parts)
+ {
+ if(part.getElementName().equals(payloadName))
+ return op;
+ }
+ }
+
+ return null;
+ }
+
+ public URL getServiceLocationURL(QName serviceQName, String portName)
+ {
+ reset();
+ return _getServiceLocationURL(this.wsdlDefinition, serviceQName, portName);
+ }
+
+ public URL _getServiceLocationURL(Definition wsdl, QName serviceQName, String
portName)
+ {
+ URL match = null;
+ dfsDepth++;
+
+ if(dfsDepth>50) // easier then retaining references
+ throw new IllegalStateException("Recursive loop detected. DFS depth reached
limit");
+
+ // namespace / java.util.List of imports
+ Map<String, List<Import>> imports = wsdl.getImports();
+ for(String ns : imports.keySet())
+ {
+ List<Import> importNS = imports.get(ns);
+ for(Import wsdlImport : importNS)
+ {
+ URL result = _getServiceLocationURL(wsdlImport.getDefinition(), serviceQName,
portName);
+ if(result!=null)
+ {
+ match = result;
+ break;
+ }
+ }
+
+ if(match!=null) break;
+ }
+
+ if(match!=null) // DFS results
+ return match;
+
+ try
+ {
+ Service service = wsdl.getService(serviceQName);
+ Port port = null;
+ SOAPAddress soapAddress = null;
+
+ // --
+
+ if(service!=null)
+ {
+ port = service.getPort(portName);
+ if(port!=null)
+ {
+ for(Object obj : port.getExtensibilityElements())
+ {
+ if(obj instanceof SOAPAddress)
+ {
+ soapAddress = (SOAPAddress)obj;
+ }
+ }
+
+ }
+ }
+
+ // --
+
+ if(soapAddress!=null)
+ match = new URL(soapAddress.getLocationURI());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to parse " + wsdl, e);
+ }
+
+ return match;
+ }
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WSDLReference.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WSDLReference.java
(rev 0)
+++ dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WSDLReference.java 2010-11-22 13:22:37
UTC (rev 1130)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.ws;
+
+import javax.wsdl.Definition;
+
+import java.net.URI;
+import java.net.URL;
+import java.net.MalformedURLException;
+
+/**
+ * Used to pass along both parsed and raw WSDL references.
+ *
+ * @see org.jboss.soa.bpel.runtime.engine.ode.JAXWSBindingContext
+ * @see org.jboss.soa.bpel.runtime.ws.EndpointManager
+ *
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ * @author Kurt.Stam <kurt.stam(a)jboss.com>
+ *
+ */
+public final class WSDLReference
+{
+ private Definition definition;
+ private URI wsdlURI;
+
+ public WSDLReference(Definition definition, URI wsdlURI)
+ {
+ this.definition = definition;
+ this.wsdlURI = wsdlURI;
+ }
+
+ public Definition getDefinition()
+ {
+ return definition;
+ }
+
+ public URL getWsdlURL()
+ {
+ try
+ {
+ return wsdlURI.toURL();
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WSInvocationAdapter.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WSInvocationAdapter.java
(rev 0)
+++ dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WSInvocationAdapter.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,117 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.ws;
+
+import org.jboss.soa.dwsp.InvocationAdapter;
+import org.jboss.soa.dwsp.MessageAdapter;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+
+/**
+ * @author Heiko Braun <hbraun(a)redhat.com>
+ */
+public final class WSInvocationAdapter implements InvocationAdapter<SOAPMessage>
+{
+ private final String operationName;
+ private final QName serviceName;
+ private final String portName;
+
+ private SOAPMessage soapRequestMessage;
+ private SOAPMessage soapResponseMessage;
+
+ private final SOAPMessageAdapter soapAdapter;
+
+ public WSInvocationAdapter(String operationName,
+ QName serviceName, String portName, SOAPMessageAdapter soapAdapter)
+ {
+ this.operationName = operationName;
+ this.serviceName = serviceName;
+ this.portName = portName;
+ this.soapAdapter = soapAdapter;
+ }
+
+ public String getOperationName()
+ {
+ return operationName;
+ }
+
+ public QName getServiceName()
+ {
+ return serviceName;
+ }
+
+ public String getPortName()
+ {
+ return portName;
+ }
+
+ public void initRequest(javax.wsdl.Operation op, MessageAdapter request)
+ {
+ if(null==soapRequestMessage)
+ throw new IllegalArgumentException("No request SOAPMessage set");
+
+ soapAdapter.parseSoapRequest(request, soapRequestMessage, op);
+ }
+
+ public void createResponse(javax.wsdl.Operation op, MessageAdapter resp)
+ {
+ try
+ {
+ // create SOAPEnvelope
+ soapResponseMessage = MessageFactory.newInstance().createMessage();
+ soapAdapter.createSoapResponse(soapResponseMessage,resp, op);
+ }
+ catch (SOAPException e)
+ {
+ throw new RuntimeException("Failed to create SOAP response", e);
+ }
+ }
+
+ public void createFault(javax.wsdl.Operation op, QName faultName, MessageAdapter
fault)
+ {
+ try
+ {
+ soapResponseMessage = MessageFactory.newInstance().createMessage();
+ soapAdapter.createSoapFault(soapResponseMessage, fault.getMessage(), faultName,
op);
+ }
+ catch (SOAPException e)
+ {
+ throw new RuntimeException("Failed to create SOAP fault", e);
+ }
+ }
+
+ public SOAPMessage getInvocationResult()
+ {
+ if(null==soapResponseMessage)
+ throw new IllegalArgumentException("No response SOAPMessage set");
+
+ return soapResponseMessage;
+ }
+
+ public void setSOAPMessage(SOAPMessage soapMessage)
+ {
+ this.soapRequestMessage = soapMessage;
+ }
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WebServiceDetails.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WebServiceDetails.java
(rev 0)
+++ dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WebServiceDetails.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,25 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.dwsp.ws;
+
+import java.lang.annotation.*;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface WebServiceDetails {
+ String factory();
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WebServiceProviderFactory.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WebServiceProviderFactory.java
(rev 0)
+++
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WebServiceProviderFactory.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.dwsp.ws;
+
+import javax.xml.namespace.QName;
+
+import org.jboss.soa.dwsp.ServiceProvider;
+
+public interface WebServiceProviderFactory {
+
+ public ServiceProvider getServiceProvider();
+
+ public WSInvocationAdapter getInvocationAdapter(String operationName,
+ QName serviceName, String portName, SOAPMessageAdapter soapAdapter);
+
+}
Added: dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WebServiceProviderGenerator.java
===================================================================
--- dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WebServiceProviderGenerator.java
(rev 0)
+++
dwsp/trunk/src/main/java/org/jboss/soa/dwsp/ws/WebServiceProviderGenerator.java 2010-11-22
13:22:37 UTC (rev 1130)
@@ -0,0 +1,211 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.soa.dwsp.ws;
+
+import javassist.*;
+import javassist.bytecode.AnnotationsAttribute;
+import javassist.bytecode.ClassFile;
+import javassist.bytecode.ConstPool;
+import javassist.bytecode.annotation.Annotation;
+import javassist.bytecode.annotation.EnumMemberValue;
+import javassist.bytecode.annotation.StringMemberValue;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * Creates JAX-WS Provider classes using javassist.
+ * These provider classes can then be deployed to JBossWS in memory.<p>
+ * The javassist generated class basically just carries the meta data,
+ * while the actual implementation resides in {@link
org.jboss.soa.dwsp.ws.BaseWebServiceEndpoint}
+ *
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class WebServiceProviderGenerator
+{
+ private final static String PKG_PREFIX =
WebServiceProviderGenerator.class.getPackage().getName()+".generated.";
+
+ public BaseWebServiceEndpoint createProvider(
+ QName service, String port,
+ String endpointId,
+ WSDLReference wsdlRef,
+ ClassLoader loader,
+ java.io.File handlerFile,
+ Class<? extends WebServiceProviderFactory> providerFactory
+ )
+ throws Exception
+ {
+ ClassPool pool = new ClassPool(true);
+ pool.appendClassPath(new LoaderClassPath(loader));
+
+ // Imports
+ pool.importPackage("java.lang");
+ pool.importPackage("javax.xml.ws");
+ pool.importPackage("javax.jws");
+
+ CtClass stringType = pool.get("java.lang.String");
+
+ String implClassName = PKG_PREFIX+"WebServiceEndpoint_"+endpointId;
+ //CtClass impl = pool.makeClass(implClassName);
+
+ // Load an existing class representing the template for a Web Service provider
+ // This was necessary, as javassist does not provide a way to set an implemented
+ // interface that supports generics. Although the super class
(AbstractWebServiceEndpoint)
+ // implements this Provider<SOAPMessage> interface, CXF requires the actual web
service
+ // implementation class to directly define this interface. (RIFTSAW-123)
+ CtClass impl =
pool.get(org.jboss.soa.dwsp.ws.TemplateWebServiceEndpoint.class.getName());
+ impl.setName(implClassName);
+
+ // AbstractWebServiceEndpoint.endpointId property
+ CtField idField = new CtField(stringType, "endpointId", impl);
+ idField.setModifiers(Modifier.PUBLIC);
+ impl.addField(idField, "\""+endpointId+"\"");
+
+ // AbstractWebServiceEndpoint.serviceName property
+ CtField serviceField = new CtField(stringType, "serviceName", impl);
+ serviceField.setModifiers(Modifier.PUBLIC);
+ impl.addField(serviceField,
"\""+service.toString()+"\"");
+
+ // AbstractWebServiceEndpoint.wsdlLocation property
+ CtField wsdlLocationField = new CtField(stringType, "wsdlLocation", impl);
+ wsdlLocationField.setModifiers(Modifier.PUBLIC);
+ impl.addField(wsdlLocationField,
"\""+wsdlRef.getWsdlURL().toExternalForm()+"\"");
+
+ // AbstractWebServiceEndpoint.portName property
+ CtField portNameField = new CtField(stringType, "portName", impl);
+ portNameField.setModifiers(Modifier.PUBLIC);
+ impl.addField(portNameField, "\""+port+"\"");
+
+ // Annotations
+ ClassFile classFile = impl.getClassFile();
+ classFile.setVersionToJava5();
+ ConstPool constantPool = classFile.getConstPool();
+
+ /*
+ @WebServiceProvider(
+ portName="HelloPort",
+ serviceName="HelloService",
+
targetNamespace="http://helloservice.org/wsdl",
+ wsdlLocation="WEB-INF/wsdl/HelloService.wsdl"
+ )
+ @ServiceMode(value=Service.Mode.MESSAGE)
+ */
+ AnnotationsAttribute attr = new
+ AnnotationsAttribute(constantPool, AnnotationsAttribute.visibleTag);
+
+ // --
+ Annotation providerAnnotation = new Annotation(
+ "javax.xml.ws.WebServiceProvider", constantPool);
+
+ providerAnnotation.addMemberValue(
+ "serviceName",
+ new StringMemberValue(service.getLocalPart(), constantPool)
+ );
+ providerAnnotation.addMemberValue(
+ "portName",
+ new StringMemberValue(port, constantPool)
+ );
+ providerAnnotation.addMemberValue(
+ "targetNamespace",
+ new StringMemberValue(service.getNamespaceURI(), constantPool)
+ );
+ providerAnnotation.addMemberValue(
+ "wsdlLocation",
+ new StringMemberValue(wsdlRef.getWsdlURL().toExternalForm(), constantPool)
+ );
+ attr.addAnnotation(providerAnnotation);
+
+ // --
+ Annotation annotation2 = new Annotation("javax.xml.ws.ServiceMode",
+ constantPool);
+ EnumMemberValue enumValue = new EnumMemberValue(constantPool);
+ enumValue.setType("javax.xml.ws.Service$Mode");
+ enumValue.setValue("MESSAGE");
+ annotation2.addMemberValue("value", enumValue);
+
+ attr.addAnnotation(annotation2);
+
+ // Specify the web service providerdetails
+ Annotation detailsAnnotation = new Annotation(
+ org.jboss.soa.dwsp.ws.WebServiceDetails.class.getName(), constantPool);
+
+ detailsAnnotation.addMemberValue("factory",
+ new StringMemberValue(providerFactory.getName(), constantPool));
+
+ attr.addAnnotation(detailsAnnotation);
+
+
+ classFile.addAttribute(attr);
+
+
+ // Check if handler chain should be established
+ if (handlerFile != null) {
+ Annotation handlerChain = new Annotation("javax.jws.HandlerChain",
constantPool);
+
+ handlerChain.addMemberValue("file",
+ new StringMemberValue("/"+handlerFile.getName(), constantPool));
+
+ attr.addAnnotation(handlerChain);
+ }
+
+
+ createStringGetter(impl, stringType, "endpointId",
"getEndpointId");
+ createStringGetter(impl, stringType, "serviceName",
"getServiceName");
+ createStringGetter(impl, stringType, "wsdlLocation",
"getWsdlLocation");
+ createStringGetter(impl, stringType, "portName", "getPortName");
+
+ // ------------
+
+ // freeze
+ impl.stopPruning(false);
+ impl.toClass(loader);
+ JavaUtils.clearBlacklists(loader);
+
+ // test it
+ Class clazz = loader.loadClass(implClassName);
+
+ BaseWebServiceEndpoint obj = (BaseWebServiceEndpoint)clazz.newInstance();
+
+ return obj;
+ }
+
+ private void createStringGetter(CtClass impl, CtClass stringType, String property,
String methodName)
+ throws Exception
+ {
+ CtMethod method = new CtMethod(
+ stringType, methodName,
+ new CtClass[]{},
+ impl
+ );
+
+ // Method body
+ StringBuffer body = new StringBuffer();
+ body.append("{");
+ body.append("return this."+property+";");
+ body.append("}");
+
+ method.setBody(body.toString());
+
+ impl.addMethod(method);
+
+ }
+}