Hi all, I would like if we can reconsider this commit...
I know it's a bug, but at this point I feel it's worth to live with it rather than doing major changes... IMHO a change like this needs to be tested for a while... We need to learn from our past bad experiences of last minute changes... Even at this moment I feel that this will get broken at the AsyncMessageReceiver, since we are spawning a seperate thread... Comments?? ~Thilina On 10/13/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
Author: deepal Date: Fri Oct 13 10:54:31 2006 New Revision: 463755 URL: http://svn.apache.org/viewvc?view=rev&rev=463755 Log: fixing setOperationContext problem Modified: webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLTask.java webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/description/AxisDescription.java webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractInMessageReceiver.java webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractInOutAsyncMessageReceiver.java webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractInOutSyncMessageReceiver.java webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractMessageReceiver.java webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractRobustInMessageReceiver.java Modified: webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLTask.java URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLTask.java?view=diff&rev=463755&r1=463754&r2=463755 ============================================================================== --- webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLTask.java (original) +++ webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLTask.java Fri Oct 13 10:54:31 2006 @@ -26,175 +26,179 @@ public class Java2WSDLTask extends Task implements Java2WSDLConstants { - private String className = null; - private String outputLocation = null; - private String classpathURI = null; - private String targetNamespace = null; - private String targetNamespacePrefix = null; - private String schemaTargetNamespace = null; - private String schemaTargetNamespacePrefix = null; - private String serviceName = null; - private String outputFileName = null; - - /** - * - */ - public Java2WSDLTask() { - super(); - } + private String className = null; + private String outputLocation = null; + private String classpathURI = null; + private String targetNamespace = null; + private String targetNamespacePrefix = null; + private String schemaTargetNamespace = null; + private String schemaTargetNamespacePrefix = null; + private String serviceName = null; + private String outputFileName = null; + private String classPath = null; + + /** + * + */ + public Java2WSDLTask() { + super(); + } - /** - * Fills the option map. This map is passed onto - * the code generation API to generate the code. - */ - private Map fillOptionMap() { - Map optionMap = new HashMap(); - - // Check that critical options exist - if (className == null) { - throw new BuildException( + /** + * Fills the option map. This map is passed onto + * the code generation API to generate the code. + */ + private Map fillOptionMap() { + Map optionMap = new HashMap(); + + // Check that critical options exist + if (className == null) { + throw new BuildException( "You must specify a classname"); - } + } - //////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////// - // Classname - addToOptionMap( optionMap, - Java2WSDLConstants.CLASSNAME_OPTION, - className); - - // Output location - addToOptionMap( optionMap, - Java2WSDLConstants.OUTPUT_LOCATION_OPTION, - outputLocation); - - String[] jars = classpathURI.split(";"); - optionMap.put(Java2WSDLConstants.CLASSPATH_OPTION, new Java2WSDLCommandLineOption(Java2WSDLConstants.CLASSPATH_OPTION, jars)); - - // Target namespace - addToOptionMap( optionMap, - Java2WSDLConstants.TARGET_NAMESPACE_OPTION, - targetNamespace); - - // Target namespace prefix - addToOptionMap( optionMap, - Java2WSDLConstants.TARGET_NAMESPACE_PREFIX_OPTION, - targetNamespacePrefix); - - // Schema target namespace - addToOptionMap( optionMap, - Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_OPTION, - schemaTargetNamespace); - - // Schema target namespace prefix - addToOptionMap( optionMap, - Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_PREFIX_OPTION, - schemaTargetNamespacePrefix); - - // Service name - addToOptionMap( optionMap, - Java2WSDLConstants.SERVICE_NAME_OPTION, - serviceName); - - // Output file name - addToOptionMap( optionMap, - Java2WSDLConstants.OUTPUT_FILENAME_OPTION, - outputFileName); + // Classname + addToOptionMap(optionMap, + Java2WSDLConstants.CLASSNAME_OPTION, + className); + + // Output location + addToOptionMap(optionMap, + Java2WSDLConstants.OUTPUT_LOCATION_OPTION, + outputLocation); + + String[] jars = classpathURI.split(";"); + optionMap.put(Java2WSDLConstants.CLASSPATH_OPTION, new Java2WSDLCommandLineOption(Java2WSDLConstants.CLASSPATH_OPTION, jars)); + + // Target namespace + addToOptionMap(optionMap, + Java2WSDLConstants.TARGET_NAMESPACE_OPTION, + targetNamespace); + + // Target namespace prefix + addToOptionMap(optionMap, + Java2WSDLConstants.TARGET_NAMESPACE_PREFIX_OPTION, + targetNamespacePrefix); + + // Schema target namespace + addToOptionMap(optionMap, + Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_OPTION, + schemaTargetNamespace); + + // Schema target namespace prefix + addToOptionMap(optionMap, + Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_PREFIX_OPTION, + schemaTargetNamespacePrefix); + + // Service name + addToOptionMap(optionMap, + Java2WSDLConstants.SERVICE_NAME_OPTION, + serviceName); + + // Output file name + addToOptionMap(optionMap, + Java2WSDLConstants.OUTPUT_FILENAME_OPTION, + outputFileName); - return optionMap; - } + return optionMap; + } - /** - * Utility method to convert a string into a single item string[] - * @param value - * @return Returns String[]. - */ - private String[] getStringArray(String value) { - String[] values = new String[1]; - values[0] = value; - return values; - } + /** + * Utility method to convert a string into a single item string[] + * + * @param value + * @return Returns String[]. + */ + private String[] getStringArray(String value) { + String[] values = new String[1]; + values[0] = value; + return values; + } - /** - * Function to put arguments in the option map. - * This functions skips adding of options that have a null value. - * - * @param map The option map into which the option is to be added - * @param option The option name - * @param value The value of the option - */ - private void addToOptionMap(Map map, String option, String value) { - if (value != null) { - map.put(option, - new Java2WSDLCommandLineOption(option, getStringArray(value))); - } + /** + * Function to put arguments in the option map. + * This functions skips adding of options that have a null value. + * + * @param map The option map into which the option is to be added + * @param option The option name + * @param value The value of the option + */ + private void addToOptionMap(Map map, String option, String value) { + if (value != null) { + map.put(option, + new Java2WSDLCommandLineOption(option, getStringArray(value))); } + } - public void execute() throws BuildException { - try { - /** - * <comment borrowed from AntCodegenTask> - * - * This needs the ClassLoader we use to load the task have all the dependancies set, hope that - * is ok for now - * - * todo look into this further!!!!! - */ - - - AntClassLoader cl = new AntClassLoader( - null, - getProject(), - null, - false); - - Thread.currentThread().setContextClassLoader(cl); - - if (outputLocation != null) cl.addPathElement(outputLocation); - - Map commandLineOptions = this.fillOptionMap(); - new Java2WSDLCodegenEngine(commandLineOptions).generate(); - - } catch (Throwable e) { - throw new BuildException(e); - } + public void execute() throws BuildException { + try { + /** + * <comment borrowed from AntCodegenTask> + * + * This needs the ClassLoader we use to load the task have all the dependancies set, hope that + * is ok for now + * + * todo look into this further!!!!! + */ + + + AntClassLoader cl = new AntClassLoader( + null, + getProject(), + null, + false); + + Thread.currentThread().setContextClassLoader(cl); - } + if (outputLocation != null) cl.addPathElement(outputLocation); - public void setClassName(String className) { - this.className = className; - } + Map commandLineOptions = this.fillOptionMap(); + new Java2WSDLCodegenEngine(commandLineOptions).generate(); - public void setOutputLocation(String outputLocation) { - this.outputLocation = outputLocation; + } catch (Throwable e) { + throw new BuildException(e); } - public void setClassPathURI(String classpathURI) { - this.classpathURI = classpathURI; - } + } - public void setTargetNamespace(String targetNamespace) { - this.targetNamespace = targetNamespace; - } + public void setClassName(String className) { + this.className = className; + } - public void setTargetNamespacePrefix(String targetNamespacePrefix) { - this.targetNamespacePrefix = targetNamespacePrefix; - } + public void setOutputLocation(String outputLocation) { + this.outputLocation = outputLocation; + } - public void setSchemaTargetNamespace(String schemaTargetNamespace) { - this.schemaTargetNamespace = schemaTargetNamespace; - } + public void setClassPathURI(String classpathURI) { + this.classpathURI = classpathURI; + } - public void setSchemaTargetNamespacePrefix(String schemaTargetNamespacePrefix) { - this.schemaTargetNamespacePrefix = schemaTargetNamespacePrefix; - } + public void setTargetNamespace(String targetNamespace) { + this.targetNamespace = targetNamespace; + } - public void setServiceName(String serviceName) { - this.serviceName = serviceName; - } + public void setTargetNamespacePrefix(String targetNamespacePrefix) { + this.targetNamespacePrefix = targetNamespacePrefix; + } - public void setOutputFileName(String outputFileName) { - this.outputFileName = outputFileName; - } + public void setSchemaTargetNamespace(String schemaTargetNamespace) { + this.schemaTargetNamespace = schemaTargetNamespace; } + + public void setSchemaTargetNamespacePrefix(String schemaTargetNamespacePrefix) { + this.schemaTargetNamespacePrefix = schemaTargetNamespacePrefix; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + public void setOutputFileName(String outputFileName) { + this.outputFileName = outputFileName; + } + + +} Modified: webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/description/AxisDescription.java URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/description/AxisDescription.java?view=diff&rev=463755&r1=463754&r2=463755 ============================================================================== --- webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/description/AxisDescription.java (original) +++ webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/description/AxisDescription.java Fri Oct 13 10:54:31 2006 @@ -86,6 +86,12 @@ } } + public Object getParameterValue(String name) { + Parameter param = getParameter(name); + if (param == null) return null; + return param.getValue(); + } + public ArrayList getParameters() { return parameterInclude.getParameters(); } Modified: webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractInMessageReceiver.java URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractInMessageReceiver.java?view=diff&rev=463755&r1=463754&r2=463755 ============================================================================== --- webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractInMessageReceiver.java (original) +++ webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractInMessageReceiver.java Fri Oct 13 10:54:31 2006 @@ -26,17 +26,15 @@ * This is takes care of the IN-OUT sync MEP in the server side */ public abstract class AbstractInMessageReceiver extends AbstractMessageReceiver { - private static final Log log = LogFactory.getLog(AbstractInMessageReceiver.class); public abstract void invokeBusinessLogic(MessageContext inMessage) throws AxisFault; public final void receive(final MessageContext messageCtx) throws AxisFault { + ThreadContextDescriptor tc = setThreadContext(messageCtx); try { - saveTCCL(messageCtx); invokeBusinessLogic(messageCtx); - } finally { - restoreTCCL(messageCtx); + restoreThreadContext(tc); } } } Modified: webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractInOutAsyncMessageReceiver.java URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractInOutAsyncMessageReceiver.java?view=diff&rev=463755&r1=463754&r2=463755 ============================================================================== --- webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractInOutAsyncMessageReceiver.java (original) +++ webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractInOutAsyncMessageReceiver.java Fri Oct 13 10:54:31 2006 @@ -56,11 +56,11 @@ try { MessageContext newmsgCtx = Utils.createOutMessageContext(messageCtx); newmsgCtx.getOperationContext().addMessageContext(newmsgCtx); + ThreadContextDescriptor tc = setThreadContext(messageCtx); try { - saveTCCL(messageCtx); invokeBusinessLogic(messageCtx, newmsgCtx); } finally { - restoreTCCL(messageCtx); + restoreThreadContext(tc); } callback.handleResult(newmsgCtx); } catch (AxisFault e) { Modified: webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractInOutSyncMessageReceiver.java URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractInOutSyncMessageReceiver.java?view=diff&rev=463755&r1=463754&r2=463755 ============================================================================== --- webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractInOutSyncMessageReceiver.java (original) +++ webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractInOutSyncMessageReceiver.java Fri Oct 13 10:54:31 2006 @@ -34,11 +34,11 @@ MessageContext outMsgContext = Utils.createOutMessageContext(msgContext); outMsgContext.getOperationContext().addMessageContext(outMsgContext); + ThreadContextDescriptor tc = setThreadContext(msgContext); try { - saveTCCL(msgContext); invokeBusinessLogic(msgContext, outMsgContext); } finally { - restoreTCCL(msgContext); + restoreThreadContext(tc); } AxisEngine engine = Modified: webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractMessageReceiver.java URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractMessageReceiver.java?view=diff&rev=463755&r1=463754&r2=463755 ============================================================================== --- webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractMessageReceiver.java (original) +++ webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractMessageReceiver.java Fri Oct 13 10:54:31 2006 @@ -40,49 +40,69 @@ public static final String SCOPE = "scope"; protected String serviceTCCL = null; public static final String SAVED_TCCL = "_SAVED_TCCL_"; - protected boolean init = false; + public static final String SAVED_MC = "_SAVED_MC_"; + + // Place to store previous values + public class ThreadContextDescriptor { + public ClassLoader oldClassLoader; + public MessageContext oldMessageContext; + } + + /** + * A place to store the current MessageContext + */ + protected static ThreadLocal currentMessageContext = new ThreadLocal(); + + protected static MessageContext getCurrentMessageContext() { + return (MessageContext) currentMessageContext.get(); + } + + protected static void setCurrentMessageContext(MessageContext ctx) { + currentMessageContext.set(ctx); + } + + /** + * Several pieces of information need to be available to the service + * implementation class. For one, the ThreadContextClassLoader needs + * to be correct, and for another we need to give the service code + * access to the MessageContext (getCurrentContext()). So we toss these + * things in TLS. + * + * @param msgContext + */ + protected ThreadContextDescriptor + setThreadContext(MessageContext msgContext) { + + ThreadContextDescriptor tc = new ThreadContextDescriptor(); + tc.oldMessageContext = (MessageContext) currentMessageContext.get(); + ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + tc.oldClassLoader = contextClassLoader; - protected void saveTCCL(MessageContext msgContext) { AxisService service = msgContext.getAxisService(); - if (!init) { - init = true; - if (service.getParameter(Constants.SERVICE_TCCL) != null) { - Parameter serviceObjectParam = - service.getParameter(Constants.SERVICE_TCCL); - serviceTCCL = ((String) - serviceObjectParam.getValue()).trim().toLowerCase(); - } - } - if (serviceTCCL != null && service != null && - service.getClassLoader() != null) { - ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + String serviceTCCL = (String) service.getParameterValue( + Constants.SERVICE_TCCL); + if (serviceTCCL != null) { + serviceTCCL = serviceTCCL.trim().toLowerCase(); + + if (serviceTCCL.equals(Constants.TCCL_COMPOSITE)) { - msgContext.setProperty(SAVED_TCCL, contextClassLoader); Thread.currentThread().setContextClassLoader(new MultiParentClassLoader(new URL[]{}, new ClassLoader[]{ msgContext.getAxisService().getClassLoader(), contextClassLoader, })); } else if (serviceTCCL.equals(Constants.TCCL_SERVICE)) { - msgContext.setProperty(SAVED_TCCL, contextClassLoader); Thread.currentThread().setContextClassLoader( msgContext.getAxisService().getClassLoader() ); } } + return tc; } - protected void restoreTCCL(MessageContext msgContext) { - if (serviceTCCL != null) { - ClassLoader oldTCCL = (ClassLoader) msgContext.getProperty(SAVED_TCCL); - if (oldTCCL != null) { - if (serviceTCCL.equals(Constants.TCCL_COMPOSITE)) { - Thread.currentThread().setContextClassLoader(oldTCCL); - } else if (serviceTCCL.equals(Constants.TCCL_SERVICE)) { - Thread.currentThread().setContextClassLoader(oldTCCL); - } - } - } + protected void restoreThreadContext(ThreadContextDescriptor tc) { + Thread.currentThread().setContextClassLoader(tc.oldClassLoader); + currentMessageContext.set(tc.oldMessageContext); } /** Modified: webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractRobustInMessageReceiver.java URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractRobustInMessageReceiver.java?view=diff&rev=463755&r1=463754&r2=463755 ============================================================================== --- webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractRobustInMessageReceiver.java (original) +++ webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/receivers/AbstractRobustInMessageReceiver.java Fri Oct 13 10:54:31 2006 @@ -26,16 +26,15 @@ * This is takes care of the IN-OUT sync MEP in the server side */ public abstract class AbstractRobustInMessageReceiver extends AbstractMessageReceiver { - private static final Log log = LogFactory.getLog(AbstractRobustInMessageReceiver.class); public abstract void invokeBusinessLogic(MessageContext inMessage) throws AxisFault; public final void receive(final MessageContext messageCtx) throws AxisFault { + ThreadContextDescriptor tc = setThreadContext(messageCtx); try { - saveTCCL(messageCtx); invokeBusinessLogic(messageCtx); } finally { - restoreTCCL(messageCtx); + restoreThreadContext(tc); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- http://webservices.apache.org/~thilina/ http://thilinag.blogspot.com/ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
