Hi,

I'm attaching an example that uses Ode's ServiceClientUtil class.

(I'm not sure what's wrong with your approach)

alex


On Wed, Apr 22, 2009 at 11:09 AM, buddhika chamith
<[email protected]>wrote:

> Hi all,
>
> Here is the revised attachment of HttpClient code. But I am getting the
> same error. Any help is greatly appreciated.
>
> Regards,
> Chamith
>
>
> On Wed, Apr 22, 2009 at 11:27 PM, buddhika chamith <
> [email protected]> wrote:
>
>> Hi all,
>>
>> A JIRA for the same was raised under ODE-590 by me. Since this has been
>> resolved in ODE-591 it was closed.
>>
>> (
>> https://issues.apache.org/jira/browse/ODE-590?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
>> )
>>
>> Regards,
>> Chamith
>>
>>
>> On Wed, Apr 22, 2009 at 12:49 AM, Alexis Midon <[email protected]> wrote:
>>
>>> fixed by ODE-591.
>>> thanks for the catch
>>>
>>> On Mon, Apr 20, 2009 at 2:19 PM, Alex Boisvert <[email protected]>
>>> wrote:
>>>
>>> > On Mon, Apr 20, 2009 at 12:23 PM, buddhika chamith
>>> > <[email protected]>wrote:
>>> >
>>> > > This code is vulnerable if a carriage return is present after the
>>> <name>
>>> > > tag before <package> tag. AFAIK this happens because of the behaviour
>>> of
>>> > > Axiom. Axiom creates an OMText node for the carriage return. So when
>>> > > getNextOMSibling() is called instead of <package> element OMText is
>>> > > selected. But since the OMText cannot be cast to OMElement a
>>> > > ClassCastException occurs. This can be avoided by obtaining zipart
>>> > OMElement
>>> > > with a call to getChild() or any related method which returns an
>>> > OMElement
>>> > > reference. I can provide a patch for this if necessary.
>>> >
>>> >
>>> > Good catch!  Yes, a patch would be much appreciated.
>>> >
>>> > alex
>>> >
>>>
>>
>>
>
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMText;
import org.apache.axiom.om.util.Base64;
import org.apache.axis2.AxisFault;
import org.apache.ode.axis2.service.ServiceClientUtil;
import org.apache.ode.utils.Namespaces;

public class DeploymentConnection {
    private final String _url;
    private OMFactory _factory;
    private ServiceClientUtil _client;
    private final OMNamespace _pmapi;

    public DeploymentConnection(String url) {
        _url = url;
        _factory = OMAbstractFactory.getOMFactory();
        _client = new ServiceClientUtil();
        _pmapi = _factory.createOMNamespace("http://www.apache.org/ode/pmapi";, "pmapi");
    }

    public void deploy(File archive, String name) throws FileNotFoundException, IOException {
        // Use the factory to create three elements
        OMElement root = _factory.createOMElement("deploy", _pmapi);
        OMElement namePart = _factory.createOMElement("name", null);
        namePart.setText(name);
        OMElement zipPart = _factory.createOMElement("package", null);
        OMElement zipElmt = _factory.createOMElement("zip", null);

        InputStream is = new FileInputStream(archive.getPath());
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream( (int) archive.length());
        byte[] buffer = new byte[4096];
        int len;
        while ((len = is.read(buffer)) >= 0) {
            outputStream.write(buffer, 0, len);
        }

        String base64Enc = Base64.encode(outputStream.toByteArray());
        OMText zipContent = _factory.createOMText(base64Enc, "application/zip", true);
        root.addChild(namePart);
        root.addChild(zipPart);
        zipPart.addChild(zipElmt);
        zipElmt.addChild(zipContent);

        sendToDeployment(root);
    }

    public void undeploy(String packageName) throws IOException {
        // Prepare undeploy message
        OMNamespace pmapi = _factory.createOMNamespace(Namespaces.ODE_PMAPI, "deployapi");
        OMElement root = _factory.createOMElement("undeploy", pmapi);
        OMElement part = _factory.createOMElement("packageName", null);
        part.setText(packageName);
        root.addChild(part);

        if (packageName != null) {
            part.setText(packageName);
            root.addChild(part);
            sendToDeployment(root);
        }
    }

    private OMElement sendToDeployment(OMElement msg) throws AxisFault {
        return _client.send(msg, this._url);
    }

}

Reply via email to