dblevins 2004/12/22 00:42:40
Modified: modules/openejb-builder/src/java/org/openejb/deployment
ContainerBuilder.java SessionBuilder.java
Added: modules/openejb-builder/src/java/org/openejb/deployment
WSContainerBuilder.java
Log:
Basic soap rpc/encoded deployment and container support along with a general
revamping of the networkservice stacks.
Revision Changes Path
1.2 +41 -13
openejb/modules/openejb-builder/src/java/org/openejb/deployment/ContainerBuilder.java
Index: ContainerBuilder.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/java/org/openejb/deployment/ContainerBuilder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ContainerBuilder.java 10 Nov 2004 01:35:08 -0000 1.1
+++ ContainerBuilder.java 22 Dec 2004 05:42:40 -0000 1.2
@@ -1,18 +1,46 @@
/**
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
*
- * Copyright 2004 The Apache Software Foundation
+ * 1. Redistributions of source code must retain copyright
+ * statements and notices. Redistributions must also contain a
+ * copy of this document.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * 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 name "OpenEJB" must not be used to endorse or promote
+ * products derived from this Software without prior written
+ * permission of The OpenEJB Group. For written permission,
+ * please contact [EMAIL PROTECTED]
+ *
+ * 4. Products derived from this Software may not be called "OpenEJB"
+ * nor may "OpenEJB" appear in their names without prior written
+ * permission of The OpenEJB Group. OpenEJB is a registered
+ * trademark of The OpenEJB Group.
+ *
+ * 5. Due credit should be given to the OpenEJB Project
+ * (http://openejb.org/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
+ * ``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 OPENEJB GROUP 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.
+ *
+ * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
+ *
+ * $Id$
*/
package org.openejb.deployment;
1.8 +7 -1
openejb/modules/openejb-builder/src/java/org/openejb/deployment/SessionBuilder.java
Index: SessionBuilder.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/java/org/openejb/deployment/SessionBuilder.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SessionBuilder.java 20 Dec 2004 20:51:55 -0000 1.7
+++ SessionBuilder.java 22 Dec 2004 05:42:40 -0000 1.8
@@ -148,10 +148,16 @@
OpenejbSessionBeanType openejbSessionBean =
(OpenejbSessionBeanType)
openejbBeans.get(sessionBean.getEjbName().getStringValue());
ObjectName sessionObjectName =
createEJBObjectName(moduleJ2eeContext, sessionBean);
-
+ assert sessionObjectName != null: "StatelesSessionBean object
name is null";
addEJBContainerGBean(earContext, ejbModule, cl,
sessionObjectName, sessionBean, openejbSessionBean, transactionPolicyHelper,
security);
+ addWSContainerGBean(earContext, ejbModule, cl,
sessionObjectName, sessionBean, openejbSessionBean, transactionPolicyHelper,
security);
}
+ }
+
+ private void addWSContainerGBean(EARContext earContext, EJBModule
ejbModule, ClassLoader cl, ObjectName sessionObjectName, SessionBeanType
sessionBean, OpenejbSessionBeanType openejbSessionBean, TransactionPolicyHelper
transactionPolicyHelper, Security security) throws DeploymentException {
+ WSContainerBuilder wsBuilder = new WSContainerBuilder();
+ wsBuilder.addGbean(earContext, ejbModule, cl, sessionObjectName,
sessionBean, openejbSessionBean, transactionPolicyHelper, security);
}
private void addEJBContainerGBean(EARContext earContext, EJBModule
ejbModule, ClassLoader cl, ObjectName sessionObjectName, SessionBeanType
sessionBean, OpenejbSessionBeanType openejbSessionBean, TransactionPolicyHelper
transactionPolicyHelper, Security security) throws DeploymentException {
1.1
openejb/modules/openejb-builder/src/java/org/openejb/deployment/WSContainerBuilder.java
Index: WSContainerBuilder.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 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 name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``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 OPENEJB GROUP 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.
*
* Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: WSContainerBuilder.java,v 1.1 2004/12/22 05:42:40 dblevins Exp $
*/
package org.openejb.deployment;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.util.jar.JarFile;
import javax.management.ObjectName;
import javax.wsdl.*;
import javax.wsdl.extensions.soap.SOAPAddress;
import javax.wsdl.extensions.soap.SOAPBinding;
import javax.wsdl.extensions.soap.SOAPBody;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
import org.apache.geronimo.common.DeploymentException;
import org.apache.geronimo.deployment.util.DeploymentUtil;
import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.j2ee.deployment.EARContext;
import org.apache.geronimo.j2ee.deployment.EJBModule;
import org.apache.geronimo.security.deploy.Security;
import org.apache.geronimo.xbeans.j2ee.SessionBeanType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openejb.dd.webservices.*;
import org.openejb.server.soap.WSContainerGBean;
import org.openejb.xbeans.ejbjar.OpenejbSessionBeanType;
public class WSContainerBuilder {
private static final Log log =
LogFactory.getLog(WSContainerBuilder.class);
/*
* The ultimate goal of this method is to create an XFireService GBean
that wraps the EJBContainer with
* the corresponding sessionObjectname and is capable of being indexed by
its WSDL address location.
*/
public void addGbean(EARContext earContext, EJBModule ejbModule,
ClassLoader cl, ObjectName sessionObjectName, SessionBeanType sessionBean,
OpenejbSessionBeanType openejbSessionBean, TransactionPolicyHelper
transactionPolicyHelper, Security security) throws DeploymentException {
boolean isStateless =
"Stateless".equals(sessionBean.getSessionType().getStringValue());
String serviceEndpointName =
OpenEJBModuleBuilder.getJ2eeStringValue(sessionBean.getServiceEndpoint());
String ejbName = sessionBean.getEjbName().getStringValue().trim();
if (!isStateless || serviceEndpointName == null) {
return;
}
serviceEndpointName = serviceEndpointName.trim();
GBeanData gBean = buildGBeanData(sessionObjectName, ejbName,
serviceEndpointName, ejbModule.getModuleFile());
earContext.addGBean(gBean);
}
public GBeanData buildGBeanData(ObjectName sessionObjectName, String
ejbName, String serviceEndpointName, JarFile jarFile) throws
DeploymentException {
WebServices webservice;
try {
URL webservicesURL = DeploymentUtil.createJarURL(jarFile,
"META-INF/webservices.xml");
webservice =
WebServicesFactory.getInstance().readXML(webservicesURL);
} catch (MalformedURLException e1) {
throw new DeploymentException("Invalid URL to webservices.xml",
e1);
}
WebServiceDescription webServiceDescription = null;
PortComponent portComponent = null;
WebServiceDescription[] webServiceDescriptions =
webservice.getWebServiceDescription();
// Grab the WebServiceDescription and PortComponent for this EJB
search: for (int i = 0; i < webServiceDescriptions.length; i++) {
webServiceDescription = webServiceDescriptions[i];
PortComponent[] portComponents =
webServiceDescription.getPortComponent();
for (int j = 0; j < portComponents.length; j++) {
portComponent = portComponents[j];
ServiceImplBean serviceImplBean =
portComponent.getServiceImplBean();
if (ejbName.equals(serviceImplBean.getEjbLink())) {
break search;
}
}
}
// TODO: Should be flushed out in a pure validation phase
// TODO: Use i18n messages
if (webServiceDescription == null || portComponent == null) {
throw new DeploymentException("There is no matching
port-component for ejb: ejb-name=" + ejbName);
}
// TODO: Should be flushed out in a pure validation phase
// TODO: Use i18n messages
if
(!serviceEndpointName.equals(portComponent.getServiceEndpointInterface().trim()))
{
throw new DeploymentException("The service-endpoint interface of
the port-component does " +
"not match that of the ejb: ejb-name=" + ejbName + ",
\nexpected = " + serviceEndpointName + ", \nfound = " +
portComponent.getServiceEndpointInterface());
}
String wsdlFile = webServiceDescription.getWsdlFile();
URL wsdlURL;
Definition definition;
try {
wsdlURL = DeploymentUtil.createJarURL(jarFile, wsdlFile);
WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
definition = wsdlReader.readWSDL(wsdlURL.toExternalForm());
} catch (MalformedURLException e) {
throw new DeploymentException("Webservices.xml file references a
wsdl file that does not exist: " + wsdlFile, e);
} catch (WSDLException e) {
throw new DeploymentException("Could not parse the WSDL file: " +
wsdlFile, e);
}
if (!isTargetNamespaceImported(definition)){
log.warn("Target namespace declared, but not included in document
namespace declarations: "+wsdlURL);
}
String[] strings = portComponent.getWsdlPort().split(":");
String portName = strings[strings.length - 1];
// Find the port definition with the name
Port port = null;
Map services = definition.getServices();
for (Iterator iterator = services.values().iterator();
iterator.hasNext();) {
Service service = (Service) iterator.next();
port = service.getPort(portName);
if (port != null) {
break;
}
}
URI location = null;
List extensibilityElements = port.getExtensibilityElements();
for (int i = 0; i < extensibilityElements.size(); i++) {
Object element = extensibilityElements.get(i);
if (element instanceof SOAPAddress) {
SOAPAddress address = (SOAPAddress) element;
try {
location = new URI(address.getLocationURI());
break;
} catch (URISyntaxException e) {
throw new DeploymentException("Invalid location URI for
port: port-name=" + port.getName(), e);
}
}
}
String style = null;
extensibilityElements = port.getBinding().getExtensibilityElements();
for (int i = 0; i < extensibilityElements.size(); i++) {
Object element = extensibilityElements.get(i);
if (element instanceof SOAPBinding) {
SOAPBinding soapBinding = (SOAPBinding) element;
style = soapBinding.getStyle();
}
}
if (style == null || !style.matches("rpc|document")){
throw new DeploymentException("Cannot determine the messaging
style of the binding: "+port.getBinding().getQName());
}
String encoding = null;
List bindingOperations = port.getBinding().getBindingOperations();
for (int i = 0; i < bindingOperations.size(); i++) {
BindingOperation bindingOperation = (BindingOperation)
bindingOperations.get(i);
extensibilityElements =
bindingOperation.getBindingInput().getExtensibilityElements();
for (int j = 0; j < extensibilityElements.size(); j++) {
Object element = extensibilityElements.get(j);
if (element instanceof SOAPBody){
SOAPBody body = (SOAPBody) element;
encoding = body.getUse();
break;
}
}
}
if (encoding == null || !encoding.matches("literal|encoded")){
throw new DeploymentException("Cannot determine the encoding of
the binding: "+port.getBinding().getQName());
}
GBeanData gBean = WSContainerGBean.createGBean(ejbName,
sessionObjectName, location, wsdlURL, definition.getTargetNamespace(),
encoding, style);
return gBean;
}
private boolean isTargetNamespaceImported(Definition definition) {
String targetNamespace = definition.getTargetNamespace();
Collection namespaces = definition.getNamespaces().values();
for (Iterator iterator = namespaces.iterator(); iterator.hasNext();) {
String namespace = (String) iterator.next();
if (targetNamespace.equals(namespace)){
return true;
}
}
return false;
}
}