/*
* Copyright (c) 2002, 2003, 2004 Active Endpoints, Inc.
*
* This program is licensed under the terms of the GNU General Public License
* Version 2 (the "License") as published by the Free Software Foundation, and
* the ActiveBPEL Licensing Policies (the "Policies"). A copy of the License
* and the Policies were distributed with this program.
*
* The License is available at:
* http://www.gnu.org/copyleft/gpl.html
*
* The Policies are available at:
* http://www.activebpel.org/licensing/index.html
*
* Unless required by applicable law or agreed to in writing, this program is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License and the Policies for
* specific language governing the use of this program.
*/
package org.activebpel.demo.client;
import org.activebpel.demo.Constants;
import org.activebpel.demo.loanProcessFault;
import org.activebpel.demo.util.RuntimeParams;
import java.math.BigInteger;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.AxisFault;
import javax.xml.rpc.ParameterMode;
/**
* A loan approval client that calls a BPEL Web Service directly.
*
* @author Jim Menard, jimm@activebpel.org
*
* @Revised by Dr. Haiping Xu
*/
public class BPELTestClient {
private RuntimeParams rp;
private String firstName, lastName;
private BigInteger amount;
/**
* Create a test client and run it, printing out the JUnit-like results.
*/
public static void main(String[] args) {
try {
BPELTestClient client = new BPELTestClient();
String result = client.run();
System.out.println("Congratulations! Dr. " + client.firstName + " " + client.lastName +
"! The answer to your loan request of $" + client.amount + " is \"" + result + "\".");
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* Constructor. Reads runtime parameters from the config file.
*/
public BPELTestClient() throws Exception {
rp = new RuntimeParams();
}
/**
* Creates a SOAP RPC call, calls the BPEL process Web service, and returns
* the result returned from the server. If an AxisFault is caught and it
* contains the magic fault string, we return that string instead of
* re-throwing the fault.
*
* @return the string returned by the BPEL process or
* Constants.MAGIC_FAULT_STRING
if an AxisFault
* containing that string is received
*/
public String run() throws Exception {
// Call BPEL process Web service using RPC
Call call = createCall();
String result = null;
try {
firstName = rp.getText("/rundata/client/firstName");
lastName = rp.getText("/rundata/client/name");
amount = new BigInteger(rp.getText("/rundata/client/amount"));
result = (String)call.invoke(new Object[] {firstName, lastName, amount});
}
catch (AxisFault af) {
if (loanProcessFault.hasMagicFaultErrorCode(af))
result = Constants.MAGIC_FAULT_STRING;
else
result = af.toString();
}
catch (Exception e) {
result = "unexpected exception seen: " + e.toString();
}
return result;
}
/**
* Creates and returns an RPC SOAP call. The call's parameter values are taken
* from the config file.
*
* @return an RPC SOAP call
*/
protected Call createCall() throws Exception {
Service service = new Service();
Call call = (Call)service.createCall();
String urlString = rp.getAttr("/rundata/client", "url");
call.setTargetEndpointAddress(new java.net.URL(urlString));
call.setOperationName(rp.getAttr("/rundata/client", "operation"));
call.addParameter("firstName", org.apache.axis.Constants.XSD_STRING,
ParameterMode.IN);
call.addParameter("name", org.apache.axis.Constants.XSD_STRING,
ParameterMode.IN);
call.addParameter("amount", org.apache.axis.Constants.XSD_INTEGER,
ParameterMode.IN);
call.setReturnType(org.apache.axis.Constants.XSD_STRING);
return call;
}
}