001: /*
002: * $Id: StartTask.java,v 1.1 2004/12/06 07:53:37 fornp1 Exp $
003: *
004: * Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
005: * Berne University of Applied Sciences
006: * School of Engineering and Information Technology
007: * All rights reserved.
008: */
009: package bexee.ant;
010:
011: import java.rmi.RemoteException;
012:
013: import javax.xml.rpc.ParameterMode;
014: import javax.xml.rpc.ServiceException;
015:
016: import org.apache.axis.client.Call;
017: import org.apache.axis.client.Service;
018: import org.apache.axis.encoding.XMLType;
019: import org.apache.tools.ant.BuildException;
020: import org.apache.tools.ant.Task;
021:
022: /**
023: * Starts a BPEL process on bexee.
024: * <p>
025: * Note that this Task is very primitive and supports only service operations
026: * that take a string parameter as input and return a string. It is only used
027: * for simple demonstration purposes.
028: *
029: * @version $Revision: 1.1 $, $Date: 2004/12/06 07:53:37 $
030: * @author Patric Fornasier
031: * @author Pawel Kowalski
032: */
033: public class StartTask extends Task {
034:
035: private String url;
036:
037: private String operation;
038:
039: private String input;
040:
041: /**
042: * Location of the BPEL process Web Service.
043: *
044: * @param url
045: * a <code>URL</code>
046: */
047: public void setUrl(String url) {
048: this .url = url;
049: }
050:
051: /**
052: * Name of the operation to perform
053: *
054: * @param operation
055: * a <code>String</code>
056: */
057: public void setOperation(String operation) {
058: this .operation = operation;
059: }
060:
061: /**
062: * The input value to pass to the process.
063: *
064: * @param input
065: * a <code>String</code>
066: */
067: public void setInput(String input) {
068: this .input = input;
069: }
070:
071: /**
072: * Starts the process on bexee.
073: */
074: public void execute() throws BuildException {
075:
076: // check if the required parameter have been set
077: if (url == null || operation == null || input == null) {
078: throw new BuildException(
079: "All of url, operation and value required");
080: }
081:
082: Service service = new Service();
083: Call call = null;
084: try {
085: call = (Call) service.createCall();
086: call.setTargetEndpointAddress(url);
087: call.setOperation(operation);
088: call
089: .addParameter("x", XMLType.XSD_STRING,
090: ParameterMode.IN);
091: call.setReturnType(XMLType.XSD_STRING);
092: } catch (ServiceException e) {
093: throw new BuildException("Unable to create call", e);
094: }
095:
096: try {
097: String result = (String) call
098: .invoke(new Object[] { input });
099: log(result);
100: } catch (RemoteException e) {
101: throw new BuildException("Unable to invoke service", e);
102: }
103: }
104: }
|