SOAPHeaderCreator
Purpose
This class provides interfaces to set SOAP header elements for PPM Web services.
Function
This method is used to add some auditing information through an Audit header.
This method is used to set a preferred language when a caller invokes a Web service operation. For example, if you want to create requests in a language other than the system language, you can specify the preferred locale by using this method.
Limitations
In a single web service operation, there is no support for working with data in multiple languages. To work with data in multiple languages, you must perform multiple, separate Web service transactions, each specifying the desired session language.
The language code you set in the method must be supported (and enabled) in PPM. If the translation of a certain entity does not exist in the specified language, the result of a Get operation will be returned in the Definition Language of the entity.
Java Interface
Add the Audit header for auditing information:
SOAPHeaderCreator.setAuditHeader(stub, "Submitted By: TEST","PPM on " + InetAddress.getLocalHost().getHostAddress(),"createRequest");
|
Parameters |
Description |
|---|---|
|
stub |
Generated by another Web service operation. For example: DemandServiceStub stub = new DemandServiceStub(ctx, serviceURL); |
Add UserLocaleHeader to set the language locale to a specified locale:
SOAPHeaderCreator.setUserLocaleHeader(stub, locale);
|
Parameters |
Description |
|---|---|
|
stub |
Generated by another Web service operation. For example: DemandServiceStub stub = new DemandServiceStub(ctx, serviceURL); |
|
locale |
Language code of the language you want to set the session to, for example, |
Java Example
This is an example for DemandService that demonstrates how to get the MLU functionality from DemandService in a PPM instance that supports MLU.
import examples.dm.DemandServiceClient; import examples.util.SOAPHeaderCreator;
public class DemandServiceMLUClient {
protected ConfigurationContext ctx = null;
public DemandServiceMLUClient() {
String repositoryPath =
System.getProperty("client.repository.dir");
String axis2 = repositoryPath + "/conf/clientaxis2.
xml";
File file = new File(axis2);
if (file.exists()) {
try {
ctx =
ConfigurationContextFactory.createConfigurationContextFromFileS
ystem(repositoryPath, axis2);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* The main program
*
* Parameter: args[0] - service URL. e.g.
* http://server:port/itg/ppmservices/DemandService
* args[1] - language locale e.g. de or en, ko etc.
*
*/
public static void main(String[] args) throws Exception {
// check parameter
if (args.length < 1) {
System.out.println("Usage: java DemandServiceClient
<service URL> <language locale>");
System.exit(1);
}
System.out.println("Starting Demand Service MLU
tests...");
// get server URL
String serviceURL = args[0];
// get preferred language
String locale = null;
if (args.length > 1) locale = args[1];
// Test Create Request
DemandServiceMLUClient dm = new
DemandServiceMLUClient();
String requestId = dm.createRequest(serviceURL);
// Test Get Request
dm.getRequests(serviceURL, locale, requestId);
System.out.println("Demand Service MLU tests
complete.");
}
/**
* This method creates a request and it shows the
instruction on how to
* create the request in a language other than the system
language
* @param serviceURL
* @return
* @throws Exception
*/
private String createRequest(String serviceURL) throws
Exception {
// Get web service
DemandServiceStub stub = new DemandServiceStub(ctx,
serviceURL);
// Add the Audit header for auditing information
SOAPHeaderCreator.setAuditHeader(stub, "Submitted By:
TEST","PPM on " +
InetAddress.getLocalHost().getHostAddress(),"createRequest");
/ *************************************************************** * * Note: If you want to create a request in a language other than the System language, you must specify the preferred locale by uncommenting the following line: SOAPHeaderCreator.setUserLocaleHeader(stub, locale);
Then, make sure to pass the token values in the translated language instead of the System language. This is because when you set the LanguageLocale field in UserLocaleHeader to a specific locale, PPM web service expects the token values in the corresponding language if the translation for that value in the preferred language exists in the system. If the translation doesn't exist in that language, you must pass the values in the System language.
Take the following scenario as an example:
o You set the preferred locale to "de" and you want to set the value for the REQ.DEPARTMENT_NAME token to 'Manufacturing' (English.
o The German translation for 'Manufacturing' exists in the system.
In this scenario, you must specify it as 'Herstellung', which is the German translated value of 'Manufacturing' and so forth for other token values as well. ***********************************************************/
// Add UserLocaleHeader to set the language locale to
the specified locale
// SOAPHeaderCreator.setUserLocaleHeader(stub, locale);
// Construct a request object
Request oRequest = Request.Factory.newInstance();
oRequest.setRequestType("Bug");
SimpleField[] fields = new SimpleField[2];
// Set values for the fields of the request object
// Set field 'Description'
SimpleField field_A = SimpleField.Factory.newInstance();
field_A.setToken("REQ.DESCRIPTION");
field_A.setStringValue1Array(new String[] { "WebService
Test" });
fields[0] = field_A;
// Set field 'Department'
SimpleField field_B = SimpleField.Factory.newInstance();
field_B.setToken("REQ.DEPARTMENT_NAME");
field_B.setStringValue1Array(new String[]{"Finance"});
fields[1] = field_B;
// Add all the fields to request object
oRequest.setSimpleFieldsArray(fields);
}
/**
* This method invokes getRequest operation with language
locale set to specified locale
* @param serviceURL
* @param language
* @param requestId
* @throws Exception
*/
private void getRequests(String serviceURL, String
language, String requestId)
throws Exception {
// Set Identifier
Identifier[] ids = new Identifier[1];
Identifier reqId = Identifier.Factory.newInstance();
reqId.setId(requestId);
reqId.setServerURL(serviceURL);
ids[0] = reqId;
// Get web service
DemandServiceStub stub = new DemandServiceStub(ctx,
serviceURL);
// Add the UserLocaleHeader SOAP header
SOAPHeaderCreator.setUserLocaleHeader(stub, language);
// Construct message to send
GetRequestsDocument inDoc =
GetRequestsDocument.Factory.newInstance();
GetRequestsDocument.GetRequests getRequests =
inDoc.addNewGetRequests();
getRequests.setRequestIdsArray(ids);
// Invoke web service
GetRequestsResponseDocument outDoc =
stub.getRequests(inDoc);
// Process return message
Request[] requests =
outDoc.getGetRequestsResponse().getReturnArray();
System.out.println("getRequests Succeeded");
System.out.println("Returned Request: " +
requests[0].getId());
}
}
Errors and Exceptions
There are no special exceptions for the SOAPHeaderCreator class.

