Java™ Web サービス環境をセットアップした あとで、GenericWebServiceSample.java を Web サービス要求の 作成の基礎として使用できます。
CMBGenericWebServiceService cs =
new CMBGenericWebServiceServiceLocator();
cmbservice = cs.getCMBGenericWebService();
String requestXML = MessageFormat.format(
SampleMessageTemplate.TEMPLATE,
new Object[] { authenticationDataXML, pid });
CMBXMLResponse response = null;
response = cmbservice.processXMLRequest(requestXML, null);
String replyXML = response.getXmlResponseText();
return replyXML;
すべての Web サービス・メッセージ・テンプレートは、SampleMessageTemplate.java ファイルに定義されています。基本操作テンプレートは、以下のとおりです。
if (factory == null) {
factory = DocumentBuilderFactory.newInstance();
}
builder = factory.newDocumentBuilder();
Document document = null;
document= builder.parse(
new InputSource(new StringReader(replyXML)));
以下の例では、永続的 ID を使用して XYZ 保険証書 (およびそのリソース・パーツの URL) を検索するために、XML 応答をラップしています。
public CMDocument retrievePolicyWithResourceURL(
String authenticationDataXML,
String pid) {
String requestXML = MessageFormat.format(
SampleMessageTemplate
.RETRIEVE_ITEM_WITH_RESOURCE_URL_TEMPLATE,
new Object[] { authenticationDataXML, pid });
CMBXMLResponse response = null;
// call the web service with the xml request message
try {
response =
cmbservice.processXMLRequest(requestXML, null);
} catch (RemoteException e) {
e.printStackTrace();
return null;
}
// Get the DOM object representing the xml message
Document document = getDocument(
response.getXmlResponseText());
if (document == null) {
return null;
}
// parse the status of the response from web service
if (parseRequestStatus(document) != true) {
return null;
}
// return the array of PIDs for the resources associated
// with the retrieved document
Element policyElement =
getElement(document, "XYZ_InsPolicy");
if (policyElement == null) {
return null;
}
CMDocument policy = parsePolicy(policyElement);
return policy;
}
