📄 javaprovider.java
字号:
} /** * Process the current message. Side-effect resEnv to create return value. * * @param msgContext self-explanatory * @param reqEnv the request envelope * @param resEnv the response envelope * @param obj the service object itself */ public abstract void processMessage (MessageContext msgContext, SOAPEnvelope reqEnv, SOAPEnvelope resEnv, Object obj) throws Exception; /** * Invoke the message by obtaining various common fields, looking up * the service object (via getServiceObject), and actually processing * the message (via processMessage). */ public void invoke(MessageContext msgContext) throws AxisFault { if (log.isDebugEnabled()) log.debug("Enter: JavaProvider::invoke (" + this + ")"); /* Find the service we're invoking so we can grab it's options */ /***************************************************************/ String serviceName = msgContext.getTargetService(); Handler service = msgContext.getService(); /* Now get the service (RPC) specific info */ /********************************************/ String clsName = getServiceClassName(service); if ((clsName == null) || clsName.equals("")) { throw new AxisFault("Server.NoClassForService", Messages.getMessage("noOption00", getServiceClassNameOptionName(), serviceName), null, null); } IntHolder scope = new IntHolder(); Object serviceObject = null; try { serviceObject = getServiceObject(msgContext, service, clsName, scope); SOAPEnvelope resEnv = null; // If there IS a response message AND this is a one-way operation, // we delete the response message here. Note that this might // cause confusing results in some cases - i.e. nothing fails, // but your response headers don't go anywhere either. It might // be nice if in the future there was a way to detect an error // when trying to install a response message in a MessageContext // associated with a one-way operation.... OperationDesc operation = msgContext.getOperation(); if (operation != null && OperationType.ONE_WAY.equals(operation.getMep())) { msgContext.setResponseMessage(null); } else { Message resMsg = msgContext.getResponseMessage(); // If we didn't have a response message, make sure we set one up // with the appropriate versions of SOAP and Schema if (resMsg == null) { resEnv = new SOAPEnvelope(msgContext.getSOAPConstants(), msgContext.getSchemaVersion()); resMsg = new Message(resEnv); String encoding = XMLUtils.getEncoding(msgContext); resMsg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, encoding); msgContext.setResponseMessage( resMsg ); } else { resEnv = resMsg.getSOAPEnvelope(); } } Message reqMsg = msgContext.getRequestMessage(); SOAPEnvelope reqEnv = reqMsg.getSOAPEnvelope(); processMessage(msgContext, reqEnv, resEnv, serviceObject); } catch( SAXException exp ) { entLog.debug( Messages.getMessage("toAxisFault00"), exp); Exception real = exp.getException(); if (real == null) { real = exp; } throw AxisFault.makeFault(real); } catch( Exception exp ) { entLog.debug( Messages.getMessage("toAxisFault00"), exp); AxisFault fault = AxisFault.makeFault(exp); //make a note if this was a runtime fault, for better logging if (exp instanceof RuntimeException) { fault.addFaultDetail(Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION, "true"); } throw fault; } finally { // If this is a request scoped service object which implements // ServiceLifecycle, let it know that it's being destroyed now. if (serviceObject != null && scope.value == Scope.REQUEST.getValue() && serviceObject instanceof ServiceLifecycle) { ((ServiceLifecycle)serviceObject).destroy(); } } if (log.isDebugEnabled()) log.debug("Exit: JavaProvider::invoke (" + this + ")"); } private String getAllowedMethods(Handler service) { String val = (String)service.getOption(OPTION_ALLOWEDMETHODS); if (val == null || val.length() == 0) { // Try the old option for backwards-compatibility val = (String)service.getOption("methodName"); } return val; } /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// /////// Default methods for java classes. Override, eg, for /////// ejbeans /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// /** * Default java service object comes from simply instantiating the * class wrapped in jc * */ protected Object makeNewServiceObject(MessageContext msgContext, String clsName) throws Exception { ClassLoader cl = msgContext.getClassLoader(); ClassCache cache = msgContext.getAxisEngine().getClassCache(); JavaClass jc = cache.lookup(clsName, cl); return jc.getJavaClass().newInstance(); } /** * Return the class name of the service */ protected String getServiceClassName(Handler service) { return (String) service.getOption( getServiceClassNameOptionName() ); } /** * Return the option in the configuration that contains the service class * name */ protected String getServiceClassNameOptionName() { return OPTION_CLASSNAME; } /** * Returns the Class info about the service class. */ protected Class getServiceClass(String clsName, SOAPService service, MessageContext msgContext) throws AxisFault { ClassLoader cl = null; Class serviceClass = null; AxisEngine engine = service.getEngine(); // If we have a message context, use that to get classloader // otherwise get the current threads classloader if (msgContext != null) { cl = msgContext.getClassLoader(); } else { cl = Thread.currentThread().getContextClassLoader(); } // If we have an engine, use its class cache if (engine != null) { ClassCache cache = engine.getClassCache(); try { JavaClass jc = cache.lookup(clsName, cl); serviceClass = jc.getJavaClass(); } catch (ClassNotFoundException e) { log.error(Messages.getMessage("exception00"), e); throw new AxisFault(Messages.getMessage("noClassForService00", clsName), e); } } else { // if no engine, we don't have a cache, use Class.forName instead. try { serviceClass = ClassUtils.forName(clsName, true, cl); } catch (ClassNotFoundException e) { log.error(Messages.getMessage("exception00"), e); throw new AxisFault(Messages.getMessage("noClassForService00", clsName), e); } } return serviceClass; } /** * Fill in a service description with the correct impl class * and typemapping set. This uses methods that can be overridden by * other providers (like the EJBProvider) to get the class from the * right place. */ public void initServiceDesc(SOAPService service, MessageContext msgContext) throws AxisFault { // Set up the Implementation class for the service String clsName = getServiceClassName(service); if (clsName == null) { throw new AxisFault(Messages.getMessage("noServiceClass")); } Class cls = getServiceClass(clsName, service, msgContext); JavaServiceDesc serviceDescription = (JavaServiceDesc)service.getServiceDescription(); // And the allowed methods, if necessary if (serviceDescription.getAllowedMethods() == null && service != null) { String allowedMethods = getAllowedMethods(service); if (allowedMethods != null && !"*".equals(allowedMethods)) { ArrayList methodList = new ArrayList(); StringTokenizer tokenizer = new StringTokenizer(allowedMethods, " ,"); while (tokenizer.hasMoreTokens()) { methodList.add(tokenizer.nextToken()); } serviceDescription.setAllowedMethods(methodList); } } serviceDescription.loadServiceDescByIntrospection(cls); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -