Hi,

I have a file download Service, this is the code :

public abstract class Updater implements IUpdater
{
        private static final String FILE_ELEMENT_NAME = "file";

        private static final String OM_NAMESPACE_NAME = "update";

        private static final String OM_NAMESPACE = 
"http://updater.webservices.hussoninfo.fr";;

        private String directory;

        private String fileName;

        public void setFileName(final String in_fileName) {
                fileName = in_fileName;
        }

        protected abstract String getRootPath();

        private String getUpdatePath() {
                return getRootPath() + File.separator + directory;
        }

        public OMElement getFile(final OMElement in_e)
        {
                OMFactory factory = OMAbstractFactory.getOMFactory();
                OMNamespace ns = factory.createOMNamespace(OM_NAMESPACE, 
OM_NAMESPACE_NAME);
                OMElement fileElement = 
OMAbstractFactory.getOMFactory().createOMElement(FILE_ELEMENT_NAME, ns);
            DataHandler dataHandler = new DataHandler(new 
FileDataSource(getUpdatePath() + File.separator + fileName));
            OMText textData = factory.createOMText(dataHandler, true);
            fileElement.addChild(textData);
                return fileElement;
        }
}

This is the service.xml (see service DatabaseUptader)

<serviceGroup>
        
        <service name="InitService" 
class="fr.hussoninfo.webservices.lifecycle.InitService">
            <description>Service d'initialisation</description>
            <parameter 
name="ServiceClass">fr.hussoninfo.webservices.lifecycle.InitService</parameter>
            <parameter name="ServiceTCCL">composite</parameter>
            <parameter name="load-on-startup">true</parameter>
        </service>
        
        <service name="DatabaseUpdater">
                <description>Service de mise a jour de base de 
donnees</description>
                <messageReceivers>
                        <messageReceiver 
mep="http://www.w3.org/2004/08/wsdl/in-only"; 
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
                        <messageReceiver 
mep="http://www.w3.org/2004/08/wsdl/in-out"; 
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
                </messageReceivers>
                <parameter name="ServiceClass" 
locked="false">fr.hussoninfo.webservices.updater.IUpdater</parameter>
                <parameter 
name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier</parameter>
                <parameter name="SpringBeanName">databaseUpdater</parameter>
                <parameter name="enableMTOM" locked="false">true</parameter>
        
                <module ref="rampart" /> 

                <operation name="getFile">
                        <messageReceiver 
class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
                        <actionMapping>urn:getFile</actionMapping>
                </operation>

                <wsp:Policy wsu:Id="UTOverTransport"
                        
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
                        
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy";>

                        <wsp:ExactlyOne>
                                <wsp:All>
                                        <sp:TransportBinding
                                                
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
                                                <wsp:Policy>
                                                        <sp:TransportToken>
                                                                <wsp:Policy>
                                                                        
<sp:HttpsToken
                                                                                
RequireClientCertificate="false" />
                                                                </wsp:Policy>
                                                        </sp:TransportToken>
                                                        <sp:AlgorithmSuite>
                                                                <wsp:Policy>
                                                                        
<sp:Basic256 />
                                                                </wsp:Policy>
                                                        </sp:AlgorithmSuite>
                                                        <sp:Layout>
                                                                <wsp:Policy>
                                                                        <sp:Lax 
/>
                                                                </wsp:Policy>
                                                        </sp:Layout>
                                                </wsp:Policy>
                                        </sp:TransportBinding>
                                        <sp:SignedSupportingTokens
                                                
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
                                                <wsp:Policy>
                                                        <sp:UsernameToken
                                                                
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient";
 />
                                                </wsp:Policy>
                                        </sp:SignedSupportingTokens>

                                        <ramp:RampartConfig 
xmlns:ramp="http://ws.apache.org/rampart/policy";>
                                                
<ramp:passwordCallbackClass>fr.hussoninfo.webservices.security.PasswordCallback</ramp:passwordCallbackClass>
                                        </ramp:RampartConfig>
                                        
                                </wsp:All>
                        </wsp:ExactlyOne>
                </wsp:Policy>
        </service>
</serviceGroup>


And here the client : 


public abstract class AbstractUpdaterClient {

        private static final String URN_GET_FILE = "urn:getFile";
        private static final String METHOD_GET_FILE = "getFile";
        private static final String WEBSERVICES_NAMESPACE = 
"http://updater.webservices.hussoninfo.fr";;
        private static final String RAMPART_MODULE_NAME = "rampart";

        private String domaine = null;

        private ConfigurationContext cc = null;

        private Policy policy = null;

        public AbstractUpdaterClient(final ConfigurationContext in_cc, final 
Policy in_policy, final String in_domaine)
        {
                domaine = in_domaine;
                cc = in_cc;
                policy = in_policy;
        }

        protected abstract String getUpdateService();
        
        private String getEPRString()
        {
                return "http://"; + domaine + "/TCXUpdater/services/" + 
getUpdateService();
        }

        public void retrieveFile(final String in_outputFile) throws IOException
        {
           ServiceClient serviceClient2 = new ServiceClient(cc, null);
                
        EndpointReference targetEPR2 = new EndpointReference(getEPRString());

        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMNamespace omNs = fac.createOMNamespace(WEBSERVICES_NAMESPACE, 
METHOD_GET_FILE);
        
        OMElement method = fac.createOMElement(METHOD_GET_FILE, omNs);

        serviceClient2.engageModule(RAMPART_MODULE_NAME);
        
        Options options2 = serviceClient2.getOptions();
        options2.setTo(targetEPR2);
        options2.setAction(URN_GET_FILE);
        options2.setProperty(RampartMessageData.KEY_RAMPART_POLICY,  policy);
        options2.setProperty(Constants.Configuration.ENABLE_MTOM, 
Constants.VALUE_TRUE);

        MessageContext messageContext = new MessageContext();
        messageContext.setServiceContext(serviceClient2.getServiceContext());
        SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();
        SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
        envelope.getBody().addChild(method);
        serviceClient2.addHeadersToEnvelope(envelope);
        messageContext.setEnvelope(envelope);
        OperationClient operationClient = 
serviceClient2.createClient(ServiceClient.ANON_OUT_IN_OP);
        operationClient.addMessageContext(messageContext);
        operationClient.execute(true);
        MessageContext responseMc = operationClient
                .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);

        DataHandler attachement = responseMc.getAttachment(
                        responseMc.getAttachmentMap().getAllContentIDs()[1]);
        
        InputStream is = new 
BufferedInputStream(attachement.getDataSource().getInputStream());
        OutputStream os = new BufferedOutputStream(new 
FileOutputStream(in_outputFile));
        
        IOUtils.copy(is, os);
        
        os.close();
        is.close();
        
        os = null;
        is = null;
        }
}

MTOM caching is enabled on client side (axis2.xml fragment):

<parameter name="cacheAttachments" locked="false">true</parameter>
<parameter name="attachmentDIR" locked="false">c:/tcx/cache</parameter>
<parameter name="sizeThreshold" locked="false">1024</parameter>

Policy for client side :

<wsp:Policy wsu:Id="UTOverTransport"
        
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
        xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy";>
        <wsp:ExactlyOne>
                <wsp:All>
                        <sp:TransportBinding
                                
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
                                <wsp:Policy>
                                        <sp:TransportToken>
                                                <wsp:Policy>
                                                        <sp:HttpsToken
                                                                
RequireClientCertificate="false" />
                                                </wsp:Policy>
                                        </sp:TransportToken>
                                        <sp:AlgorithmSuite>
                                                <wsp:Policy>
                                                        <sp:Basic256 />
                                                </wsp:Policy>
                                        </sp:AlgorithmSuite>
                                        <sp:Layout>
                                                <wsp:Policy>
                                                        <sp:Lax />
                                                </wsp:Policy>
                                        </sp:Layout>
                                </wsp:Policy>
                        </sp:TransportBinding>
                        <sp:SignedSupportingTokens
                                
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
                                <wsp:Policy>
                                        <sp:UsernameToken
                                                
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient";
 />
                                </wsp:Policy>
                        </sp:SignedSupportingTokens>
                </wsp:All>
        </wsp:ExactlyOne>
</wsp:Policy>

And the method to get the Policy :

StAXOMBuilder builder = new StAXOMBuilder(CONF_POLICY_XML);
policy =  PolicyEngine.getPolicy(builder.getDocumentElement());
        
RampartConfig rc = new RampartConfig();
rc.setUser("user");
rc.setPwCbClass(PasswordCallback.class.getName());
policy.addAssertion(rc);


And now the problem :

It works with file not larger than 10mb, without tuning JVM memory.
When I disengage Rampart module (both client and server), all works fine with 
larger file !! But when Rampart is engaged I get an OutOfMemoryError on the 
client side for file larger than 10mb.

For a file of 74MB, I have to set client JVM Memory to 728MB !!! 

My conf :
Axis2 1.2, Rampart 1.2, Tomcat/5.5, jsdk_1.5_10

Thanks for your response, 


Grégoire Rolland


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to