Example usage for javax.xml.ws.soap MTOMFeature ID

List of usage examples for javax.xml.ws.soap MTOMFeature ID

Introduction

In this page you can find the example usage for javax.xml.ws.soap MTOMFeature ID.

Prototype

String ID

To view the source code for javax.xml.ws.soap MTOMFeature ID.

Click Source Link

Document

Constant value identifying the MTOMFeature

Usage

From source file:org.apache.axis2.jaxws.client.config.MTOMConfigurator.java

public void configure(MessageContext messageContext, BindingProvider provider) {
    Binding bnd = (Binding) provider.getBinding();
    MTOMFeature mtomFeature = (MTOMFeature) bnd.getFeature(MTOMFeature.ID);
    Message requestMsg = messageContext.getMessage();

    //Disable MTOM.
    requestMsg.setMTOMEnabled(false);/*from   w w w  . ja v a2  s.  c  o  m*/

    if (mtomFeature == null) {
        throw ExceptionFactory.makeWebServiceException(Messages.getMessage("mtomFeatureErr"));
    }

    //Enable MTOM if specified.
    if (mtomFeature.isEnabled()) {
        int threshold = mtomFeature.getThreshold();
        List<String> attachmentIDs = requestMsg.getAttachmentIDs();

        // Enable MTOM
        requestMsg.setMTOMEnabled(true);

        if (threshold <= 0) {
            if (log.isDebugEnabled()) {
                log.debug("Enabling MTOM with no threshold.");
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("MTOM Threshold Value =" + threshold);
            }

            //set MTOM threshold value on message context.
            //Once MTOM threshold is set on message context it will be
            //read by SOAPMessageFormatter.writeTo() while writing the attachment
            //SOAPMessageFormatter will further propogate the threshold value to
            //Axiom.OMOutputFormat. JAXBAttachmentUnmarshaller will then make 
            //decision if the attachment should be inlined or optimized.  
            messageContext.setProperty(Constants.Configuration.MTOM_THRESHOLD, new Integer(threshold));
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("The MTOMFeature was found, but not enabled.");
        }
    }
}

From source file:org.apache.axis2.jaxws.description.impl.EndpointDescriptionImpl.java

public boolean isMTOMEnabled() {
    if (isMTOMEnabledCache != null) {
        return isMTOMEnabledCache.booleanValue();
    }/*from  www. j  av  a  2s  .  c o  m*/

    // isMTOMEnabled is a combination of the @BindingType and the @MTOM setting.
    MTOM mtomAnnotation = (MTOM) getAnnoFeature(MTOMFeature.ID);

    // If the @MTOM annotation is set, it wins
    if (mtomAnnotation != null) {
        isMTOMEnabledCache = Boolean.valueOf(mtomAnnotation.enabled());
        return isMTOMEnabledCache.booleanValue();
    }

    // Else look at the bindingType
    String bindingType = getBindingType();
    isMTOMEnabledCache = Boolean.valueOf(isMTOMBinding(bindingType));
    return isMTOMEnabledCache.booleanValue();
}

From source file:org.apache.axis2.jaxws.server.config.MTOMConfigurator.java

public void configure(EndpointDescription endpointDescription) {
    MTOM mtomAnnoation = (MTOM) ((EndpointDescriptionJava) endpointDescription).getAnnoFeature(MTOMFeature.ID);
    AxisService service = endpointDescription.getAxisService();

    //Disable MTOM
    Parameter enableMTOM = new Parameter(Constants.Configuration.ENABLE_MTOM, Boolean.FALSE);
    Parameter threshold = new Parameter(Constants.Configuration.MTOM_THRESHOLD, 0);

    if (mtomAnnoation == null) {
        throw ExceptionFactory.makeWebServiceException(Messages.getMessage("mtomAnnotationErr"));
    }/*from  w w  w.ja  v a  2  s.  c om*/

    //Enable MTOM.
    if (mtomAnnoation.enabled()) {
        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(threshold);
    } catch (Exception e) {
        throw ExceptionFactory.makeWebServiceException(Messages.getMessage("mtomEnableErr"), e);
    }
}