snichol 2002/08/26 14:16:16
Modified: java/docs changes.html
Added: java/src/org/apache/soap/providers CORBAProvider.java
Log:
Add a CORBA provider, allowing CORBA interfaces to be exposed via
SOAP without writing any code.
Revision Changes Path
1.37 +2 -0 xml-soap/java/docs/changes.html
Index: changes.html
===================================================================
RCS file: /home/cvs/xml-soap/java/docs/changes.html,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- changes.html 4 Aug 2002 02:47:32 -0000 1.36
+++ changes.html 26 Aug 2002 21:16:16 -0000 1.37
@@ -58,6 +58,8 @@
by specifying
<code><isd:option key="SessionRequired"
value="false"/></code>
within the <code>isd:provider</code> element in the deployment
descriptor.</li>
+ <li>Add a CORBA provider, allowing CORBA interfaces to be exposed via
+ SOAP without writing any code.</li>
</ul>
</li>
</ul>
1.1 xml-soap/java/src/org/apache/soap/providers/CORBAProvider.java
Index: CORBAProvider.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2000 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "SOAP" 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 [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 2000, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.soap.providers;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
//import javax.servlet.*;
//import javax.servlet.http.*;
import org.omg.CORBA.ORB;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
import org.apache.soap.server.*;
import org.apache.soap.util.*;
/**
* Allows methods on a CORBA object to be invoked through a
* SOAP call without writing any service code.
*
* @author Scott Nichol ([EMAIL PROTECTED])
*/
public class CORBAProvider implements Provider {
private static final String DEFAULT_ORB_INITIAL_HOST = "localhost";
private static final String DEFAULT_ORB_INITIAL_PORT = "900";
private DeploymentDescriptor dd;
private Envelope envelope;
private Call call;
private String targetObjectURI;
private String interfaceClassName = null;
private Object targetObject = null;
/**
* Locates the target object for the call.
*/
public void locate(DeploymentDescriptor dd, Envelope env, Call call,
String methodName, String targetObjectURI,
SOAPContext reqContext) throws SOAPException {
// Save useful parameters for invoke method
this.dd = dd;
this.envelope = env;
this.call = call;
this.targetObjectURI = targetObjectURI;
// Read deployment descriptor options
Hashtable props = dd.getProps();
String orbInitialHost = (String) props.get("ORBInitialHost");
if (orbInitialHost == null)
orbInitialHost = DEFAULT_ORB_INITIAL_HOST;
String orbInitialPort = (String) props.get("ORBInitialPort");
if (orbInitialPort == null)
orbInitialPort = DEFAULT_ORB_INITIAL_PORT;
String nameId = (String) props.get("NameID");
if (nameId == null)
throw new SOAPException(Constants.FAULT_CODE_SERVER, "NameID must be
specified");
String nameKind = (String) props.get("NameKind");
if (nameKind == null)
throw new SOAPException(Constants.FAULT_CODE_SERVER, "NameKind must be
specified");
interfaceClassName = (String) props.get("InterfaceClassName");
if (interfaceClassName == null)
throw new SOAPException(Constants.FAULT_CODE_SERVER, "InterfaceClassName
must be specified");
String helperClassName = (String) props.get("HelperClassName");
if (helperClassName == null)
throw new SOAPException(Constants.FAULT_CODE_SERVER, "HelperClassName must
be specified");
// Initialize ORB
Properties orbProps = new Properties();
orbProps.put("org.omg.CORBA.ORBInitialHost", orbInitialHost);
orbProps.put("org.omg.CORBA.ORBInitialPort", orbInitialPort);
ORB orb = null;
try {
orb = ORB.init(new String[0], orbProps);
} catch (Exception e) {
throw new SOAPException(Constants.FAULT_CODE_SERVER,
"Error initializing ORB: " + e,
e);
}
// Find the object
NamingContext root = null;
try {
root =
NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
} catch (Exception e) {
throw new SOAPException(Constants.FAULT_CODE_SERVER,
"Error getting name service: " + e,
e);
}
NameComponent nc = new NameComponent(nameId, nameKind);
NameComponent[] ncs = {nc};
org.omg.CORBA.Object corbaObject;
try {
corbaObject = root.resolve(ncs);
} catch (Exception e) {
throw new SOAPException(Constants.FAULT_CODE_SERVER,
"Error resolving '" + nameId + "': " + e,
e);
}
// Narrow the object reference
Method narrowMethod = null;
try {
Class helperClass = Class.forName(helperClassName);
narrowMethod = helperClass.getMethod("narrow", new Class[]
{org.omg.CORBA.Object.class});
} catch (Exception e) {
throw new SOAPException(Constants.FAULT_CODE_SERVER,
"Error getting helper class '" + helperClassName +
"': " + e,
e);
}
try {
targetObject = narrowMethod.invoke(null, new Object[] {corbaObject});
} catch (Exception e) {
throw new SOAPException(Constants.FAULT_CODE_SERVER,
"Error using helper class '" + helperClassName + "
to narrow': " + e,
e);
}
}
/**
* Invokes the service method
*/
public void invoke(SOAPContext reqContext, SOAPContext resContext)
throws SOAPException {
// Get information about the call
String methodName = call.getMethodName();
Vector methodParameters = call.getParams();
String respEncStyle = call.getEncodingStyleURI();
Parameter ret = null;
Object[] args = null;
Class[] argTypes = null;
if (methodParameters != null) {
int parametersCount = methodParameters.size();
args = new Object[parametersCount];
argTypes = new Class[parametersCount];
for (int i = 0; i < parametersCount; i++) {
Parameter param = (Parameter) methodParameters.elementAt(i);
args[i] = param.getValue();
argTypes[i] = param.getType();
if (respEncStyle == null) {
respEncStyle = param.getEncodingStyleURI();
}
}
}
if (respEncStyle == null)
respEncStyle = Constants.NS_URI_SOAP_ENC;
// Find the method an invoke it
try {
Method m = MethodUtils.getMethod(targetObject, methodName, argTypes);
Bean result = new Bean(m.getReturnType(), m.invoke(targetObject, args));
if (result.type != void.class) {
ret = new Parameter(RPCConstants.ELEM_RETURN, result.type,
result.value, null);
}
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
throw new SOAPException(Constants.FAULT_CODE_SERVER, t.getMessage(), t);
} catch (Throwable t) {
throw new SOAPException(Constants.FAULT_CODE_SERVER, t.getMessage(), t);
}
// Create the response
try {
Response resp = new Response(targetObjectURI, methodName, ret, null,
null, respEncStyle, resContext);
Envelope env = resp.buildEnvelope();
StringWriter sw = new StringWriter();
env.marshall(sw, call.getSOAPMappingRegistry(), resContext);
resContext.setRootPart(sw.toString(), Constants.HEADERVAL_CONTENT_TYPE_UTF8);
} catch (Exception e) {
if (e instanceof SOAPException) throw (SOAPException) e;
throw new SOAPException(Constants.FAULT_CODE_SERVER,
"Error creating response: " + e,
e);
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>