📄 securitystatelessejbprovider.java
字号:
//org.apache.soap.providers.SecurityStatelessEJBProvider.java
package org.apache.soap.providers;
import java.io.* ;
import java.util.* ;
import javax.servlet.* ;
import javax.servlet.http.* ;
import org.apache.soap.* ;
import org.apache.soap.rpc.* ;
import org.apache.soap.server.* ;
import org.apache.soap.util.* ;
import java.lang.reflect.*;
import javax.rmi.*;
import javax.ejb.*;
import javax.naming.*;
import javax.naming.Context.*;
public class SecurityStatelessEJBProvider implements org.apache.soap.util.Provider {
private DeploymentDescriptor dd ;
private Envelope envelope ;
private Call call ;
private String methodName ;
private String targetObjectURI ;
private HttpServlet servlet ;
private HttpSession session ;
private javax.naming.Context contxt = null;
private EJBObject remoteObjRef = null;
public static java.lang.String CNTXT_PROVIDER_URL = "iiop://localhost:900";
public static java.lang.String CNTXT_FACTORY_NAME
= "com.ibm.ejs.ns.jndi.CNInitialContextFactory";
private Vector methodParameters = null;
private String respEncStyle = null;
/**
* StatelessEJBProvider constructor comment.
*/
public SecurityStatelessEJBProvider() {
super();
}
private void initialize() throws SOAPException {
if(contxt == null) {
java.util.Properties properties = new java.util.Properties();
properties.put(javax.naming.Context.PROVIDER_URL,
CNTXT_PROVIDER_URL);
properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
CNTXT_FACTORY_NAME);
try {
contxt = new javax.naming.InitialContext(properties);
} catch (NamingException ne) {
// ErrorListener?
System.out.println("Naming Exception caught during InitialContext creation @ "
+ CNTXT_PROVIDER_URL);
throw new SOAPException(Constants.FAULT_CODE_SERVER,
"Unable to initialize context" );
}
}
}
private void initialize(String url, String factory) throws SOAPException {
if(contxt == null) {
java.util.Properties properties = new java.util.Properties();
properties.put(javax.naming.Context.PROVIDER_URL, url);
properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
factory);
try {
contxt = new javax.naming.InitialContext(properties);
} catch (NamingException ne) {
// ErrorListener?
System.out.println("Naming Exception caught during InitialContext creation @ "
+ CNTXT_PROVIDER_URL);
throw new SOAPException(Constants.FAULT_CODE_SERVER,
"Unable to initialize context");
}
}
}
private void initialize(String url, String factory, String roleName, String password)
throws SOAPException {
if(contxt == null) {
java.util.Properties properties = new java.util.Properties();
properties.put(javax.naming.Context.PROVIDER_URL, url);
properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
factory);
properties.put(javax.naming.Context.SECURITY_PRINCIPAL, roleName);
properties.put(javax.naming.Context.SECURITY_CREDENTIALS,
password);
try {
contxt = new javax.naming.InitialContext(properties);
} catch (NamingException ne) {
// ErrorListener?
System.out.println("Naming Exception caught during InitialContext creation @ "
+ CNTXT_PROVIDER_URL);
throw new SOAPException(Constants.FAULT_CODE_SERVER,
"Unable to initialize context");
}
}
}
/**
* invoke method comment.
*/
public void invoke(SOAPContext reqContext, SOAPContext resContext)
throws SOAPException {
System.err.println( "=====================================" );
System.err.println("In TemplateProvider.invoke()" );
Parameter ret = null;
Object[] args = null;
Class[] argTypes = null;
respEncStyle = call.getEncodingStyleURI();
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;
}
try {
Method m = MethodUtils.getMethod (remoteObjRef, methodName, argTypes);
Bean result = new Bean (m.getReturnType (),
m.invoke (remoteObjRef, args));
if (result.type != void.class) {
ret = new Parameter (RPCConstants.ELEM_RETURN, result.type,
result.value, null);
}
} catch (InvocationTargetException e) {
System.err.println("Exception Caught upon method invocation attempt: "
+ e.getMessage());
Throwable t = e.getTargetException ();
throw new SOAPException (Constants.FAULT_CODE_SERVER,
t.getMessage(), t);
}
catch (Throwable t) {
System.err.println("Exception Caught upon method invocation attempt: "
+ t.toString());
throw new SOAPException (Constants.FAULT_CODE_SERVER,
t.getMessage(), t);
}
try {
Response resp = new Response( targetObjectURI,
// URI
call.getMethodName(),
// Method
(Parameter) ret,
// ReturnValue
null,
// Params
null,
// Header
respEncStyle,
// encoding
resContext );
// response soapcontext - not supported yet
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,
e.toString() );
}
}
/**
* locate method comment.
*/
public void locate(DeploymentDescriptor dd,
Envelope env,
Call call,
String methodName,
String targetObjectURI,
SOAPContext reqContext)
throws org.apache.soap.SOAPException {
HttpServlet servlet = (HttpServlet)
reqContext.getProperty( Constants.BAG_HTTPSERVLET );
HttpSession session = (HttpSession)
reqContext.getProperty( Constants.BAG_HTTPSESSION );
System.err.println( "=======================================" );
System.err.println( "In TemplateProvider.locate()" );
System.err.println( "URI: " + targetObjectURI );
System.err.println( "DD.ServiceClass: " + dd.getServiceClass() );
System.err.println( "DD.ProviderClass: " + dd.getProviderClass() );
System.err.println( "Call.MethodName: " + call.getMethodName() );
this.dd = dd ;
this.envelope = env ;
this.call = call ;
this.methodName = methodName ;
this.targetObjectURI = targetObjectURI ;
this.servlet = servlet ;
this.session = session ;
Hashtable props = dd.getProps();
String ContxtProviderURL = (String) props.get("ContextProviderURL");
String ContxtFactoryName = (String) props.get("FullContextFactoryName");
String roleName = (String) props.get("RoleName");
String password = (String) props.get("Password");
if ((roleName != null) && (password != null) &&
(ContxtProviderURL != null) && (ContxtFactoryName != null))
initialize(ContxtProviderURL, ContxtFactoryName, roleName, password);
else if ((ContxtProviderURL != null) && (ContxtFactoryName != null))
initialize(ContxtProviderURL, ContxtFactoryName);
else
initialize();
String homeInterfaceName = (String) props.get("FullHomeInterfaceName");
if (homeInterfaceName == null)
throw new SOAPException(Constants.FAULT_CODE_SERVER,
"Error in Deployment Descriptor Property Settings");
// From the Deployment Descriptor get the JNDI lookup name that is inside
// the "java" element...
String jndiName = (String) props.get("JNDIName");
if ( jndiName == null ) jndiName = dd.getProviderClass();
if ((jndiName != null) && (contxt != null)) {
try {
// Use service name to locate EJB home object via the contxt
// EJBHome home = (EJBHome) contxt.lookup(jndiName);
EJBHome home = (EJBHome) PortableRemoteObject.narrow(
contxt.lookup(jndiName), Class.forName(homeInterfaceName));
// call the 'create' method on the EJB home object, and store the
// ref to the EJB object.
Method createMethod =
home.getClass().getMethod("create", new Class[0]);
remoteObjRef = (EJBObject)
createMethod.invoke((Object) home, new Object[0]);
} catch (Exception e) {
System.out.println("Exception caught: " + e.toString());
throw new SOAPException(Constants.FAULT_CODE_SERVER,
"Error in connecting to EJB", e);
}
}
// Once previous steps have been successful, then we take the Call Object
// and extract the method name from it, and any parameters, and store them.
//
methodName = call.getMethodName();
methodParameters = call.getParams();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -