IBM BPM, V8.0.1, All platforms > Programming IBM BPM > Developing using the web service API > Samples

Building a Java client

You can use the WID web service generate client to generate a Java Client that can invoke the web API.


Preventing WID errors

WID 7 seems to have a problem with the WSDL format. The WSDL file contains documentation tags such as <a:since ...> that can prevent the Java Client generation.

You can use a grep tool to remove these lines by executing the following command:

grep -v a:since originalWSDL.wsdl > newWSDL.wsdl


Testing the web service interface from the generated code

To test the JAX-WS generated code, you can use the following code sample.

WebAPIService webAPIService = new WebAPIService();
WebAPI webAPI = webAPIService.getWebAPISoap();
BindingProvider bp = (BindingProvider) webAPI;
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "tw_admin");
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "tw_admin");
webAPI.testConnection();
System.out.println("Connection worked!");


Adding a SOAP header

You must use a SOAP header when you send a request to IBM BPM. To achieve this, you can use the following code sample.
Map <QName, List<String>> headersMap = new HashMap<QName, List<String>>();
QName myQName = new QName("http://webapi.lombardisoftware.com", "myHeader");
String mySoapHeader =
  "<p:ClientInfo xmlns:p='http://webapi.lombardisoftware.com'>" +
  "<p:TimeZone>CST</p:TimeZone>" +
  "<p:Locale>EN</p:Locale>" +
  "<p:AcceptsTimeZone>false</p:AcceptsTimeZone>" +
  "</p:ClientInfo>";

List<String> mySOAPHeaders = new ArrayList<String>();
mySOAPHeaders.add(mySoapHeader);
headersMap.put(myQName, mySOAPHeaders);

BindingProvider bp = (BindingProvider) webAPI;
bp.getRequestContext().put("jaxws.binding.soap.headers.outbound", headersMap);


Redirecting the SOAP request to a TCP/IP monitor

You can use JAX-WS for testing purposes and redirect the SOAP request through a TCP/IP Monitor with the following code sample. In this sample, the TCP/IP monitor is listening on port 9089 and redirecting to the target port.
BindingProvider bp = (BindingProvider) webAPI;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://win7-x64:9089/webapi/services/WebAPIService");

This example illustrates a search.

WebAPIService webAPIService = new WebAPIService();
WebAPI webAPI = webAPIService.getWebAPISoap();

Map <QName, List<String>> headersMap = new HashMap<QName, List<String>>();
QName myQName = new QName("http://webapi.lombardisoftware.com", "myHeader");
String mySoapHeader =
  "<p:ClientInfo xmlns:p='http://webapi.lombardisoftware.com'>" +
  "<p:TimeZone>CST</p:TimeZone>" +
  "<p:Locale>EN</p:Locale>" +
  "<p:AcceptsTimeZone>false</p:AcceptsTimeZone>" +
  "</p:ClientInfo>";

List<String> mySOAPHeaders = new ArrayList<String>();
mySOAPHeaders.add(mySoapHeader);
headersMap.put(myQName, mySOAPHeaders);

BindingProvider bp = (BindingProvider) webAPI;

bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "kolban");
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");
bp.getRequestContext().put("jaxws.binding.soap.headers.outbound", headersMap);
ObjectFactory objectFactory = new ObjectFactory();

Search search = objectFactory.createSearch();
search.setOrganizedByType("Task");

SearchColumn searchColumn = objectFactory.createSearchColumn();
searchColumn.setType("Task");
searchColumn.setName("Subject");
ArrayOfSearchColumn arrayOfSearchColumn =
objectFactory.createArrayOfSearchColumn();
arrayOfSearchColumn.getSearchColumn().add(searchColumn);

searchColumn = objectFactory.createSearchColumn();
searchColumn.setType("Task");
searchColumn.setName("Id");
arrayOfSearchColumn.getSearchColumn().add(searchColumn);
search.setColumns(arrayOfSearchColumn);

SearchCondition searchCondition = new SearchCondition();
searchColumn = objectFactory.createSearchColumn();
searchColumn.setName("Status");
searchColumn.setType("Task");
searchCondition.setColumn(searchColumn);

searchCondition.setOperator("EQUALS");
searchCondition.setValue(objectFactory.createSearchConditionValue(TaskStatus.NEW
_OR_RECEIVED));
ArrayOfSearchCondition arrayOfSearchCondition =
objectFactory.createArrayOfSearchCondition();
arrayOfSearchCondition.getSearchCondition().add(searchCondition);

search.setConditions(objectFactory.createSearchConditions(arrayOfSearchCondition));
SearchResults searchResults = webAPI.executeSearch(search, null, null);

Samples