Wednesday, 11 January 2012

Invoke BPEL Process using JAVA

The Following Code will invoke the Vaccation Request BPEL process come in samples with BPEL Manager installation.

try
{
URL url = new URL("http://host:port/wsdl link of deployed bpel");
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(url);
call.setProperty(Call.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
call.setProperty(Call.SOAPACTION_URI_PROPERTY, SOAP_ACTION);

call.setProperty( Call.OPERATION_STYLE_PROPERTY , STYLE );
call.setOperationName(OPERATION_NAME);
call.addParameter(new QName(PARAMETER_NAMESPACE,"creator"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter(new QName(PARAMETER_NAMESPACE,"fromDate"), XMLType.XSD_DATETIME, ParameterMode.IN);
call.addParameter(new QName(PARAMETER_NAMESPACE,"toDate"), XMLType.XSD_DATETIME, ParameterMode.IN);
call.addParameter(new QName(PARAMETER_NAMESPACE,"reason"), XMLType.XSD_STRING, ParameterMode.IN);
Object[] params = new Object[4];
params[0] = "Anna";
params[1] = new Date();
params[2] = new Date();
params[3] = "No Reason";
/* Invoke the service */
/*************************************/
call.invokeOneWay(params);
System.out.println( "Vacation Request BPEL process initiated" );
}
catch (SOAPFaultException e)
{
System.err.println("Generated fault: ");
System.out.println (" Fault Code = " + e.getFaultCode());
System.out.println (" Fault String = " + e.getFaultString());
}
catch (JAXRPCException e)
{
System.err.println("JAXRPC Exception: " + e.getMessage());
}
catch (ServiceException e)
{
System.err.println("Service Exception: " + e.getMessage());
}
catch(Exception e)
{
e.printStackTrace();
System.err.println("Other Exception: " + e.getMessage());
}

I write this code using apache axis client you need to add apache axis libraries in your project build path.

No comments:

Post a Comment