Dear Tammo,

I work with Eclipse, unfortunately I have not worked before with Maven.
I need a java project which can call ODE API deployment service and deploy
the process remotely. I used the "DeploymentWebService.java" +
"ServiceClientUtil.java" + "ODEClient.java"+ "Test.java".

The first Two classes I only copied from Github into my default package.
But the other two I can copy the code below. I also add some jars which the
classes need and obviously have installed Apache ODE inside Tomcat
Application server. I mean I can see the WSDL file of this service by
calling this:  "http://localhost:8080/ode/processes/DeploymentService?wsdl";

The problem is that I am not sure that am I am in the right direction or
not as I always get exception? I am new to all these topics and I am not
sure that should I also include other java classes from github or not?

I do appreciate your kind consideration.

ODEClient.java :

import java.io.BufferedInputStream;
import java.io.IOException;
import javax.xml.stream.XMLStreamException;
import org.apache.axiom.om.*;
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;

import javax.xml.namespace.QName;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.StringBufferInputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.axiom.om.impl.llom.util.AXIOMUtil;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.ode.bpel.pmapi.ScopeInfoDocument;
import org.apache.ode.tools.sendsoap.cline.HttpSoapSender;

public class ODEClient {

    public Boolean checkProcess(String packge) throws AxisFault {
        // Setup and tear down are doing ost of the job here, just checking
in the middle
        ServiceClientUtil client = new ServiceClientUtil();

        OMElement listRoot = client.buildMessage("listProcesses", new
String[]{"filter", "orderKeys"},
                new String[]{packge, ""});
        OMElement result = client.send(listRoot, "
http://localhost:8080/ode/processes/ProcessManagement?wsdl";);
        OMElement child = result.getFirstElement();
        OMElement pid = child.getFirstElement();
        if (pid != null) {
            return true;
        }
        return false;
    }

    public OMElement listAllProcesses() throws AxisFault {
        ServiceClientUtil client = new ServiceClientUtil();
        OMElement listRoot = client.buildMessage("listProcesses", new
String[]{},
                new String[]{});
        OMElement result = client.send(listRoot, "
http://localhost:8080/ode/processes/ProcessManagement?wsdl";);
        return result;
    }
    private OMFactory _factory;
    private ServiceClientUtil _client;
    private ArrayList<QName> _deployed = new ArrayList<QName>();
    private String _package;

    public void undeploy(String pakage) throws Exception {
        // Prepare undeploy message
        _client = new ServiceClientUtil();
        _factory = OMAbstractFactory.getOMFactory();
        OMNamespace depns =
_factory.createOMNamespace(Namespaces.ODE_PMAPI, "deployapi");
        OMElement root = _factory.createOMElement("undeploy", depns);
        OMElement part = _factory.createOMElement("packageName", null);
        part.setText(pakage);
        root.addChild(part);

        // Undeploy
        sendToDeployment(root);
    }

    public String deploy(String packageName, String path) throws
IOException, XMLStreamException {
        String pakage = null;
        try {
            SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
            OMNamespace omn = factory.createOMNamespace("
http://www.apache.org/ode/pmapi";, "tns");
            OMNamespace soapnm = factory.createOMNamespace("
http://schemas.xmlsoap.org/soap/envelope/";, "SOAP-ENV");
            OMElement message = factory.createOMElement("Envelope", soapnm);
            OMElement body = factory.createOMElement("Body", soapnm);
            message.addChild(body);
            OMNamespace depns =
factory.createOMNamespace(Namespaces.ODE_PMAPI, "deployapi");
            OMElement root = factory.createOMElement("deploy", omn);
            body.addChild(root);
            OMElement namePart = factory.createOMElement("name", depns);
            namePart.setText(packageName);
            OMElement zipPart = factory.createOMElement("package", depns);
            OMElement zipElmt = factory.createOMElement("zip", depns);
            System.out.println("zip part :" + zipPart);
            System.out.println("zip element :" + zipElmt);

            // Add the zip to deploy
            File fileName = new File(path);
            InputStream istream = new FileInputStream(fileName);
            System.out.println("stream : " + istream);
            BufferedInputStream is = new BufferedInputStream(istream);
            System.out.println("is :" + is);
            ByteArrayOutputStream outputStream = new
ByteArrayOutputStream();
            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);
            System.out.println("root input :" + message);
            // Deploy
            InputStream instreams = null;
            try {
                instreams = new StringBufferInputStream(message.toString());
            } catch (java.lang.Exception e) {
                System.out.println("file not found " + e.toString());
            }
            String soapresult = HttpSoapSender.doSend(new URL("
http://127.0.0.1:8080/ode/processes/DeploymentService?wsdl";), instreams,
"1", 0, "admin", "axis2", null);
            System.out.println("result :" + soapresult);
            AXIOMUtil axutil = new AXIOMUtil();
            org.apache.axiom.om.OMElement result =
axutil.stringToOM(soapresult);
            _deployed.clear();
            System.out.println(result);
            Iterator iter = result.getChildElements();

            while (iter.hasNext()) {
                OMElement e = (OMElement) iter.next();
                e = e.getFirstElement().getFirstElement().getFirstElement();
                System.out.println("etext : " + e.getText());
                System.out.println("local name : " + e.getLocalName());
                if (e.getLocalName().equals("name")) {
                    pakage = e.getText();
                    System.out.println("package :" + pakage);
                }
                if (e.getLocalName().equals("id")) {
                    _deployed.add(e.getTextAsQName());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pakage;
    }

    private OMElement sendToDeployment(OMElement msg) throws AxisFault {
        return _client.send(msg, "
http://localhost:8080/ode/processes/DeploymentService?wsdl";);
    }

    private OMElement sendToPM(OMElement msg) throws AxisFault {
        return _client.send(msg, "
http://localhost:8080/ode/processes/ProcessManagement?wsdl";);
    }
}

Test.java :

import java.io.IOException;
import javax.xml.stream.XMLStreamException;
public class Test {

/**
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    ODEClient client=new ODEClient();
    client.undeploy("DynPartner");
}

}

On Mon, Feb 2, 2015 at 4:41 PM, Tammo van Lessen <[email protected]>
wrote:

> Hi Marzie,
>
> if that exception occurs, it is very unlikely that it is related to any ODE
> code. I'm afraid you need to resolve any classpath issues first. Have you
> checked if you included the correct version of Axiom (axiom-common-impl or
> axiom-impl)? How do you call the main class? Do you use Maven? Eclipse?
>
> Best,
>   Tammo
>
> On Mon, Feb 2, 2015 at 2:12 PM, Marzie Dehghanipour <
> [email protected]> wrote:
>
> > Dear Tammo,
> >
> > I always get this exception:
> >
> > Exception in thread "main"
> >
> >
> java.lang.NoClassDefFoundError:org/apache/axiom/om/impl/AbstractOMMetaFactory
> >
> >
> > I searched on the web but I could not solve the problem. I imported all
> > necessary jars in my project but it seems that at run time it cannot find
> > them.
> >
> > Best,
> > Marzie
> >
> > On Sun, Feb 1, 2015 at 2:42 PM, Tammo van Lessen <[email protected]>
> > wrote:
> >
> > > Hi Marzie,
> > >
> > > what exception do you get? Without that information is difficult to
> help.
> > >
> > > Best,
> > >   Tammo
> > >
> > > On Sun, Feb 1, 2015 at 8:02 AM, Marzie Dehghanipour <
> > > [email protected]> wrote:
> > >
> > > > Hi,
> > > > Yes I checked it. I also have implemented some codes that use the
> > > > deployment service but it has exception and I worked the whole week
> > but I
> > > > could not solve the problem.
> > > >
> > > > I have basically two classes: deploymentconnection.java
> > > >
> > > > 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);
> > > >     }
> > > >
> > > > }
> > > >
> > > >
> > > > and my main class which uses ServiceClientUtil class for sending the
> > > > message to Axis2 for calling the deploy function. ServiceClientUtil
> is
> > > the
> > > > class which I found it on Github and this is an interface for making
> it
> > > > easier to use the API : main.java
> > > >
> > > >
> > > > import java.io.File;
> > > > import java.io.FileNotFoundException;
> > > > import java.io.IOException;
> > > > import java.util.logging.Level;
> > > > import java.util.logging.Logger;
> > > >
> > > > public class Main {
> > > >     public static void main(String[] args) throws
> > FileNotFoundException {
> > > >         DeploymentConnection con = new DeploymentConnection("
> > > > http://localhost:8080/ode/processes/DeploymentService";);
> > > >         try {
> > > >             con.deploy(new File("C:\\temp\\DynPartner.zip"),
> > > "DynPartner");
> > > >         } catch (IOException ex) {
> > > >
>  //Logger.getLogger(Main.class.getName()).log(Level.SEVERE,
> > > > null,ex);
> > > >         ex.printStackTrace();
> > > >         }}}
> > > >
> > > > I do appreciate if someone can help me. It makes me crazy and I was
> > > working
> > > > the last 2 weeks on it.
> > > >
> > > > On Sun, Feb 1, 2015 at 4:15 AM, Sathwik B P <[email protected]>
> > > wrote:
> > > >
> > > > > Did you check fileupload.jsp
> > > > >
> > > > > On Sat, Jan 31, 2015 at 8:19 PM, Marzie Dehghanipour <
> > > > > [email protected]> wrote:
> > > > >
> > > > > > Dear Sathwik,
> > > > > >
> > > > > > Thanks a lot for your answer. I know already the concept. but I
> > need
> > > > some
> > > > > > implementation sample.
> > > > > >
> > > > > > Thanks
> > > > > >
> > > > > > On Sat, Jan 31, 2015 at 2:29 PM, Sathwik B P <
> [email protected]
> > >
> > > > > wrote:
> > > > > >
> > > > > > > Hi Marzie,
> > > > > > >
> > > > > > > You basically need to read the process artifact (zip file) and
> > > encode
> > > > > it
> > > > > > > with Base64 and use it as the payload contents for deploy
> > operation
> > > > of
> > > > > > > Deployment Service.
> > > > > > >
> > > > > > > Have a look at fileupload.jsp under ODE webapp.
> > > > > > >
> > > > > > > regards,
> > > > > > > sathwik
> > > > > > >
> > > > > > > On Sat, Jan 31, 2015 at 6:42 PM, Marzie Dehghanipour <
> > > > > > > [email protected]> wrote:
> > > > > > >
> > > > > > > > Hi,
> > > > > > > > I am looking for sample implementation of deploying a process
> > on
> > > > > Apache
> > > > > > > ODE
> > > > > > > > engine using deployment service API. I want to use the
> > deployment
> > > > API
> > > > > > > > exposed by ODE. This allows for transferring deployment units
> > > (zip
> > > > > > files
> > > > > > > > containing BPELs, WSDLs, DDs) via SOAP to ODE and starting
> the
> > > > > > > deployment.
> > > > > > > >
> > > > > > > > Any help in this regard would be appreciated.
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > Tammo van Lessen - http://www.taval.de
> > >
> >
>
>
>
> --
> Tammo van Lessen - http://www.taval.de
>

Reply via email to