Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 87643 invoked from network); 22 Jan 2008 19:36:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Jan 2008 19:36:37 -0000 Received: (qmail 98932 invoked by uid 500); 22 Jan 2008 19:36:27 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 98802 invoked by uid 500); 22 Jan 2008 19:36:27 -0000 Mailing-List: contact axis-cvs-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-cvs@ws.apache.org Received: (qmail 98791 invoked by uid 500); 22 Jan 2008 19:36:27 -0000 Delivered-To: apmail-ws-axis2-cvs@ws.apache.org Received: (qmail 98788 invoked by uid 99); 22 Jan 2008 19:36:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Jan 2008 11:36:26 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Jan 2008 19:36:20 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id F1E5F1A983A; Tue, 22 Jan 2008 11:36:10 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r614296 - in /webservices/axis2/branches/java/jaxws21/modules: kernel/src/org/apache/axis2/ metadata/src/org/apache/axis2/jaxws/description/ metadata/src/org/apache/axis2/jaxws/description/builder/ metadata/src/org/apache/axis2/jaxws/descri... Date: Tue, 22 Jan 2008 19:36:07 -0000 To: axis2-cvs@ws.apache.org From: ngallardo@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080122193610.F1E5F1A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ngallardo Date: Tue Jan 22 11:36:04 2008 New Revision: 614296 URL: http://svn.apache.org/viewvc?rev=614296&view=rev Log: AXIS2-3448 Initial enablement for @MTOM annotation. Added: webservices/axis2/branches/java/jaxws21/modules/metadata/test/org/apache/axis2/jaxws/description/feature/ webservices/axis2/branches/java/jaxws21/modules/metadata/test/org/apache/axis2/jaxws/description/feature/MTOMFeatureTests.java Modified: webservices/axis2/branches/java/jaxws21/modules/kernel/src/org/apache/axis2/Constants.java webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/EndpointDescription.java webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/builder/DescriptionBuilderComposite.java webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/builder/converter/ConverterUtils.java webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/builder/converter/JavaClassToDBCConverter.java webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/server/config/MTOMConfigurator.java Modified: webservices/axis2/branches/java/jaxws21/modules/kernel/src/org/apache/axis2/Constants.java URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/jaxws21/modules/kernel/src/org/apache/axis2/Constants.java?rev=614296&r1=614295&r2=614296&view=diff ============================================================================== --- webservices/axis2/branches/java/jaxws21/modules/kernel/src/org/apache/axis2/Constants.java (original) +++ webservices/axis2/branches/java/jaxws21/modules/kernel/src/org/apache/axis2/Constants.java Tue Jan 22 11:36:04 2008 @@ -265,6 +265,7 @@ //Attachment configurations public static final String ENABLE_MTOM = "enableMTOM"; + public static final String MTOM_THRESHOLD = "mtomThreshold"; public static final String CACHE_ATTACHMENTS = "cacheAttachments"; public static final String ATTACHMENT_TEMP_DIR = "attachmentDIR"; public static final String FILE_SIZE_THRESHOLD = "sizeThreshold"; Modified: webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/EndpointDescription.java URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/EndpointDescription.java?rev=614296&r1=614295&r2=614296&view=diff ============================================================================== --- webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/EndpointDescription.java (original) +++ webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/EndpointDescription.java Tue Jan 22 11:36:04 2008 @@ -136,11 +136,27 @@ public abstract QName getServiceQName(); public abstract Service.Mode getServiceMode(); - + + /** + * Signals whether or not MTOM has been turned on for the endpoint + * based on the annotation configuration. + * + * @return a boolean value + */ + public boolean isMTOMEnabled(); + + /** + * If MTOM is enabled, returns the threshold value. + * + * @return -1 if MTOM is not enabled, a positive integer value if + * one was configured. + */ + public int getMTOMThreshold(); + + /** * Return the DescriptionBuilderComposite, if any, used to build this service description. * @return */ public DescriptionBuilderComposite getDescriptionBuilderComposite(); - } Modified: webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/builder/DescriptionBuilderComposite.java URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/builder/DescriptionBuilderComposite.java?rev=614296&r1=614295&r2=614296&view=diff ============================================================================== --- webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/builder/DescriptionBuilderComposite.java (original) +++ webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/builder/DescriptionBuilderComposite.java Tue Jan 22 11:36:04 2008 @@ -31,6 +31,7 @@ import javax.wsdl.Definition; import javax.xml.namespace.QName; +import javax.xml.ws.spi.WebServiceFeatureAnnotation; import java.io.InputStream; import java.lang.annotation.Annotation; @@ -82,7 +83,9 @@ private List webServiceRefAnnotList; private BindingTypeAnnot bindingTypeAnnot; private WebServiceContextAnnot webServiceContextAnnot; - + + private List features; + // Class information private String className; private String[] classModifiers; //public, abstract, final, strictfp... @@ -91,7 +94,7 @@ private boolean isInterface = false; private QName preferredPort; // Port to use if no port QName given. May be null private boolean isMTOMEnabled = false; - + private List methodDescriptions; private List fieldDescriptions; @@ -369,7 +372,15 @@ public WebServiceContextAnnot getWebServiceContextAnnot() { return (WebServiceContextAnnot) webServiceContextAnnot; } - + + public List getWebServiceFeatures() { + return features; + } + + public void setWebServiceFeatures(List list) { + features = list; + } + /** @return Returns the wsdlDefinition */ public Definition getWsdlDefinition() { if (wsdlDefinition != null) { Modified: webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/builder/converter/ConverterUtils.java URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/builder/converter/ConverterUtils.java?rev=614296&r1=614295&r2=614296&view=diff ============================================================================== --- webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/builder/converter/ConverterUtils.java (original) +++ webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/builder/converter/ConverterUtils.java Tue Jan 22 11:36:04 2008 @@ -33,6 +33,8 @@ import javax.jws.soap.SOAPBinding; import javax.xml.bind.annotation.XmlList; import javax.xml.ws.WebServiceRef; +import javax.xml.ws.spi.WebServiceFeatureAnnotation; + import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.GenericArrayType; @@ -41,6 +43,7 @@ import java.lang.reflect.Type; import java.lang.reflect.WildcardType; import java.security.PrivilegedAction; +import java.util.ArrayList; import java.util.List; public class ConverterUtils { @@ -60,6 +63,40 @@ } }); } + + /** + * Helper method to retrieve a list of all annotations that match the following + * conditions: + * + * - Annotations that extend the parameterized type T + * - Annotations that themselves are annotated with type T + * + * @param annotationClass + * @param element + * @return + */ + public static List getAnnotations(final Class annotationClass, final AnnotatedElement element) { + List matches = new ArrayList(); + Annotation[] annotations = null; + + // Get the complete list of annotations from the class that was provided. + annotations = (Annotation[]) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return element.getAnnotations(); + } + }); + + for (Annotation a: annotations) { + // If the annotation matches the parameter type we're looking + // for, add it to the list. + if (a.annotationType().isAnnotationPresent(annotationClass) || + annotationClass.isAssignableFrom(a.annotationType())) { + matches.add(a); + } + } + + return matches; + } /** * This is a helper method to create a HandlerChainAnnot since the Modified: webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/builder/converter/JavaClassToDBCConverter.java URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/builder/converter/JavaClassToDBCConverter.java?rev=614296&r1=614295&r2=614296&view=diff ============================================================================== --- webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/builder/converter/JavaClassToDBCConverter.java (original) +++ webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/builder/converter/JavaClassToDBCConverter.java Tue Jan 22 11:36:04 2008 @@ -18,12 +18,14 @@ */ package org.apache.axis2.jaxws.description.builder.converter; +import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.jws.WebService; import javax.xml.ws.BindingType; @@ -33,6 +35,7 @@ import javax.xml.ws.WebServiceProvider; import javax.xml.ws.WebServiceRef; import javax.xml.ws.WebServiceRefs; +import javax.xml.ws.spi.WebServiceFeatureAnnotation; import org.apache.axis2.jaxws.description.builder.BindingTypeAnnot; import org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite; @@ -54,7 +57,15 @@ private String seiClassName; private List classes; - + + private static final Map annotationProcessors; + + static { + annotationProcessors = new HashMap(); + + + } + public JavaClassToDBCConverter(Class serviceClass) { this.serviceClass = serviceClass; classes = new ArrayList(); @@ -185,6 +196,7 @@ attachWebServiceProviderAnnotation(composite); attachWebServiceRefsAnnotation(composite); attachWebServiceRefAnnotation(composite); + attachWebServiceFeatureAnnotations(composite); } /** @@ -347,6 +359,24 @@ private void attachWebServiceRefAnnotation(DescriptionBuilderComposite composite) { ConverterUtils.attachWebServiceRefAnnotation(composite, serviceClass); + } + + /** + * Finds the list of WebServiceFeatureAnnotation instances, and set them on the composite. + * + * @param composite + */ + private void attachWebServiceFeatureAnnotations(DescriptionBuilderComposite composite) { + List features = ConverterUtils.getAnnotations( + WebServiceFeatureAnnotation.class, serviceClass); + + if (features.size() > 0) { + if (log.isDebugEnabled()) { + log.debug("There were [" + features.size() + "] WebServiceFeature annotations found."); + } + + composite.setWebServiceFeatures(features); + } } private void establishClassHierarchy(Class rootClass) { Modified: webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java?rev=614296&r1=614295&r2=614296&view=diff ============================================================================== --- webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java (original) +++ webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java Tue Jan 22 11:36:04 2008 @@ -47,13 +47,16 @@ import javax.xml.ws.WebServiceProvider; import javax.xml.ws.handler.PortInfo; import javax.xml.ws.soap.AddressingFeature; +import javax.xml.ws.soap.MTOM; import javax.xml.ws.soap.MTOMFeature; import javax.xml.ws.soap.SOAPBinding; import javax.xml.ws.spi.WebServiceFeatureAnnotation; import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants.Configuration; import org.apache.axis2.client.ServiceClient; import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.deployment.DeploymentException; import org.apache.axis2.description.AxisService; import org.apache.axis2.description.OutInAxisOperation; import org.apache.axis2.description.OutOnlyAxisOperation; @@ -97,11 +100,11 @@ */ class EndpointDescriptionImpl implements EndpointDescription, EndpointDescriptionJava, EndpointDescriptionWSDL { - private static final ServerConfigurator RESPECT_BINDING_CONFIGURATOR = + private static final ServerConfigurator RESPECT_BINDING_CONFIGURATOR = new RespectBindingConfigurator(); - private static final ServerConfigurator ADDRESSING_CONFIGURATOR = + private static final ServerConfigurator ADDRESSING_CONFIGURATOR = new AddressingConfigurator(); - private static final ServerConfigurator MTOM_CONFIGURATOR = + private static final ServerConfigurator MTOM_CONFIGURATOR = new MTOMConfigurator(); private ServiceDescriptionImpl parentServiceDescription; @@ -491,6 +494,9 @@ processor.processTypeLevelAnnotation(this, annotation); } } + + // Configure any available WebServiceFeatures on the endpoint. + configureWebServiceFeatures(); } /** @@ -589,14 +595,18 @@ if (composite.isDeprecatedServiceProviderConstruction() || !composite.isServiceProvider()) { +// if (!getServiceDescriptionImpl().isDBCMap()) { Class seiClass = null; if (DescriptionUtils.isEmpty(seiClassName)) { - // This is the client code path; the @WebServce will not have an endpointInterface member - // so just build the EndpointInterfaceDesc based on the class itself. + // TODO: (JLB) This is the client code path; the @WebServce will not have an endpointInterface member + // For now, just build the EndpointInterfaceDesc based on the class itself. + // TODO: The EID ctor doesn't correctly handle anything but an SEI at this + // point; e.g. it doesn't publish the correct methods of just an impl. seiClass = composite.getCorrespondingClass(); } else { - // This is the deprecated server-side introspection code for an impl that references an SEI + // TODO: (JLB) This is the deprecated server-side introspection code for an impl that references an SEI try { + // TODO: Using Class forName() is probably not the best long-term way to get the SEI class from the annotation seiClass = ClassLoaderUtils.forName(seiClassName, false, ClassLoaderUtils.getContextClassLoader(this.axisService != null ? this.axisService.getClassLoader() : null)); // Catch Throwable as ClassLoader can throw an NoClassDefFoundError that @@ -609,14 +619,17 @@ } endpointInterfaceDescription = new EndpointInterfaceDescriptionImpl(seiClass, this); } else { + //TODO: Determine if we need logic here to determine implied SEI or not. This logic + // may be handled by EndpointInterfaceDescription + if (DescriptionUtils.isEmpty(getAnnoWebServiceEndpointInterface())) { - // Build the EndpointInterfaceDesc based on the class itself + //TODO: Build the EndpointInterfaceDesc based on the class itself endpointInterfaceDescription = new EndpointInterfaceDescriptionImpl(composite, true, this); } else { - // Otherwise, build the EID based on the SEI composite + //Otherwise, build the EID based on the SEI composite endpointInterfaceDescription = new EndpointInterfaceDescriptionImpl( getServiceDescriptionImpl().getDBCMap().get(seiClassName), false, @@ -1364,6 +1377,44 @@ return handlerChainAnnotation; } + // =========================================== + // ANNOTATION: MTOM + // =========================================== + + /* + * (non-Javadoc) + * @see org.apache.axis2.jaxws.description.EndpointDescription#isMTOMEnabled() + */ + public boolean isMTOMEnabled() { + if (axisService != null) { + // We should cache this call here so we don't have to make + // it on every pass through. + Parameter enableMTOM = axisService.getParameter(Configuration.ENABLE_MTOM); + if (enableMTOM != null) { + return (Boolean) enableMTOM.getValue(); + } + } + + return false; + } + + /* + * (non-Javadoc) + * @see org.apache.axis2.jaxws.description.EndpointDescription#getMTOMThreshold() + */ + public int getMTOMThreshold() { + if (axisService != null) { + // We should cache this call here so we don't have to make + // it on every pass through. + Parameter mtomThreshold = axisService.getParameter(Configuration.MTOM_THRESHOLD); + if (mtomThreshold != null) { + return (Integer) mtomThreshold.getValue(); + } + } + + return -1; + } + // Get the specified WebServiceFeatureAnnotation public Annotation getAnnoFeature(String id) { return framework.getAnnotation(id); @@ -1383,17 +1434,26 @@ framework.addConfigurator(MTOMFeature.ID, MTOM_CONFIGURATOR); } - //TODO: Need to add support for the DescriptionBuilderComposite? - Annotation[] annotations = composite.getCorrespondingClass().getAnnotations(); - - if (annotations != null) { - for (Annotation annotation : annotations) { - if (annotation.annotationType().isAnnotationPresent(WebServiceFeatureAnnotation.class)) - framework.addAnnotation(annotation); - } - - framework.configure(this); - } + // The feature instances are stored on the composite from either the + // Java class or from something else building the list and setting it there. + List features = composite.getWebServiceFeatures(); + + if (features != null && features.size() > 0) { + // Add each of the annotation instances to the WebServiceFeature framework + Iterator itr = features.iterator(); + while (itr.hasNext()) { + Annotation feature = (Annotation) itr.next(); + framework.addAnnotation(feature); + } + + // Kick off the configuration of the WebServiceFeature instances. + framework.configure(this); + } + else { + if (log.isDebugEnabled()) { + log.debug("No WebServiceFeatureAnnotation instances were found on the composite."); + } + } } private Definition getWSDLDefinition() { @@ -1819,6 +1879,20 @@ return string.toString(); } return string.toString(); + } + + /** + * Get an annotation. This is wrappered to avoid a Java2Security violation. + * @param cls Class that contains annotation + * @param annotation Class of requrested Annotation + * @return annotation or null + */ + private static Annotation getAnnotation(final Class cls, final Class annotation) { + return (Annotation) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return cls.getAnnotation(annotation); + } + }); } } Modified: webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/server/config/MTOMConfigurator.java URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/server/config/MTOMConfigurator.java?rev=614296&r1=614295&r2=614296&view=diff ============================================================================== --- webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/server/config/MTOMConfigurator.java (original) +++ webservices/axis2/branches/java/jaxws21/modules/metadata/src/org/apache/axis2/jaxws/server/config/MTOMConfigurator.java Tue Jan 22 11:36:04 2008 @@ -21,20 +21,25 @@ import javax.xml.ws.soap.MTOM; import javax.xml.ws.soap.MTOMFeature; +import org.apache.axis2.Constants; import org.apache.axis2.description.AxisService; import org.apache.axis2.description.Parameter; import org.apache.axis2.jaxws.ExceptionFactory; import org.apache.axis2.jaxws.description.EndpointDescription; import org.apache.axis2.jaxws.description.EndpointDescriptionJava; import org.apache.axis2.jaxws.feature.ServerConfigurator; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * */ public class MTOMConfigurator implements ServerConfigurator { + private static Log log = LogFactory.getLog(MTOMConfigurator.class); + /* - * (non-Javadoc) + * (non-Javadoc) * @see org.apache.axis2.jaxws.feature.WebServiceFeatureConfigurator#configure(org.apache.axis2.jaxws.description.EndpointDescription) */ public void configure(EndpointDescription endpointDescription) { @@ -43,19 +48,32 @@ AxisService service = endpointDescription.getAxisService(); //Disable MTOM - Parameter enableMTOM = new Parameter("enableMTOM", Boolean.FALSE); - -// TODO NLS enable. + Parameter enableMTOM = new Parameter(Constants.Configuration.ENABLE_MTOM, Boolean.FALSE); + Parameter threshold = new Parameter(Constants.Configuration.MTOM_THRESHOLD, 0); + + //TODO NLS enable. if (mtomAnnoation == null) throw ExceptionFactory.makeWebServiceException("The MTOM annotation was unspecified."); //Enable MTOM. if (mtomAnnoation.enabled()) { - enableMTOM.setValue(Boolean.TRUE); + if (log.isDebugEnabled()) { + log.debug("Enabling MTOM via annotation."); + } + enableMTOM.setValue(Boolean.TRUE); } + + //Set the threshold value. + if (mtomAnnoation.threshold() > 0) { + if (log.isDebugEnabled()) { + log.debug("Setting MTOM threshold to [" + mtomAnnoation.threshold() + "]."); + } + threshold.setValue(mtomAnnoation.threshold()); + } try { - service.addParameter(enableMTOM); + service.addParameter(enableMTOM); + service.addParameter(threshold); } catch (Exception e) { //TODO NLS enable. Added: webservices/axis2/branches/java/jaxws21/modules/metadata/test/org/apache/axis2/jaxws/description/feature/MTOMFeatureTests.java URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/jaxws21/modules/metadata/test/org/apache/axis2/jaxws/description/feature/MTOMFeatureTests.java?rev=614296&view=auto ============================================================================== --- webservices/axis2/branches/java/jaxws21/modules/metadata/test/org/apache/axis2/jaxws/description/feature/MTOMFeatureTests.java (added) +++ webservices/axis2/branches/java/jaxws21/modules/metadata/test/org/apache/axis2/jaxws/description/feature/MTOMFeatureTests.java Tue Jan 22 11:36:04 2008 @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.axis2.jaxws.description.feature; + +import org.apache.axis2.jaxws.description.DescriptionFactory; +import org.apache.axis2.jaxws.description.EndpointDescription; +import org.apache.axis2.jaxws.description.ServiceDescription; + +import javax.jws.WebService; +import javax.xml.namespace.QName; +import javax.xml.ws.soap.MTOM; + +import junit.framework.TestCase; + +public class MTOMFeatureTests extends TestCase { + + private static final String ns = "http://jaxws.axis2.apache.org/metadata/feature/mtom"; + + private static final String defaultServicePortName = "DefaultServicePort"; + private static final String plainServicePortName = "PlainServicePort"; + private static final String disabledServicePortName = "DisabledServicePort"; + private static final String thresholdServicePortName = "ThresholdServicePort"; + private static final String badThresholdServicePortName = "BadThresholdServicePort"; + + public void testNoAnnotation() { + ServiceDescription sd = DescriptionFactory.createServiceDescription(DefaultService.class); + + EndpointDescription ed = sd.getEndpointDescription(new QName(ns, defaultServicePortName)); + assertTrue("The EndpointDescription should not be null.", ed != null); + + boolean mtomEnabled = ed.isMTOMEnabled(); + assertTrue("MTOM should not be enabled by default", mtomEnabled == false); + } + + public void testPlainAnnotation() { + ServiceDescription sd = DescriptionFactory.createServiceDescription(PlainService.class); + + EndpointDescription ed = sd.getEndpointDescription(new QName(ns, plainServicePortName)); + assertTrue("The EndpointDescription should not be null.", ed != null); + + boolean mtomEnabled = ed.isMTOMEnabled(); + assertTrue("@MTOM included, but was not enabled.", mtomEnabled == true); + + int threshold = ed.getMTOMThreshold(); + assertTrue("MTOM threshold should be 0 or less.", threshold <= 0); + } + + public void testDisabled() { + ServiceDescription sd = DescriptionFactory.createServiceDescription(DisabledService.class); + + EndpointDescription ed = sd.getEndpointDescription(new QName(ns, disabledServicePortName)); + assertTrue("The EndpointDescription should not be null.", ed != null); + + boolean mtomEnabled = ed.isMTOMEnabled(); + assertTrue("@MTOM included, and should be disabled.", mtomEnabled == false); + } + + public void testThreshold() { + ServiceDescription sd = DescriptionFactory.createServiceDescription(ThresholdService.class); + + EndpointDescription ed = sd.getEndpointDescription(new QName(ns, thresholdServicePortName)); + assertTrue("The EndpointDescription should not be null.", ed != null); + + int threshold = ed.getMTOMThreshold(); + assertTrue("MTOM threshold should be 2000.", threshold == 20000); + } + + public void testBadThreshold() { + ServiceDescription sd = DescriptionFactory.createServiceDescription(BadThresholdService.class); + + EndpointDescription ed = sd.getEndpointDescription(new QName(ns, badThresholdServicePortName)); + assertTrue("The EndpointDescription should not be null.", ed != null); + + int threshold = ed.getMTOMThreshold(); + assertTrue("MTOM threshold should be [0], but was [" + threshold + "].", threshold == 0); + } + + @WebService(targetNamespace=ns, portName=defaultServicePortName) + class DefaultService { + public double getQuote(String symbol) { + return 101.01; + } + } + + @WebService(targetNamespace=ns, portName=plainServicePortName) + @MTOM + class PlainService { + public double getQuote(String symbol) { + return 101.01; + } + } + + @WebService(targetNamespace=ns, portName=disabledServicePortName) + @MTOM(enabled=false) + class DisabledService { + public double getQuote(String symbol) { + return 101.01; + } + } + + @WebService(targetNamespace=ns, portName=thresholdServicePortName) + @MTOM(threshold=20000) + class ThresholdService { + public double getQuote(String symbol) { + return 101.01; + } + } + + @WebService(targetNamespace=ns, portName=badThresholdServicePortName) + @MTOM(threshold=-1000) + class BadThresholdService { + public double getQuote(String symbol) { + return 101.01; + } + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org For additional commands, e-mail: axis-cvs-help@ws.apache.org