今回は、biz-StreamのJavaライブラリのAPIを使用するのではなく、biz-Stream Webサービスサーバを使ったPDF生成をScalaによるクライアントから指示する方法を見ていきたいと思います。
前編ではまずbiz-Stream Webサービスサーバへ送るSOAPメッセージの作成について解説します.
実際にサーバへメッセージを送る部分ついては後編で解説する予定です.
biz-Stream Webサービスサーバとは,biz-Streamをアプリに組み込むのではなく,別サーバに設置して動作させるためのものです.SOAPメッセージをサーバに送ることによって生成する内容の指示を行ないます.
一番始めの部分(layoutXml)は,biz-Streamのレイアウト定義を直接ソースコード内に
記述しています.
これは前回と同様,レイアウト定義は通常2種類(ドキュメントレイアウト定義,ページレイアウト定義)の別ファイルで構成されますが,ここではそれらを1つに結合しています.
次にrecordsは上記のXMLレイアウトに流しこむデータを定義しています.
実際のアプリでは,ここは動的にデータ内容を生成するロジックがコーディングされる部分です.
soapMessageでは、Webサービスサーバへ送信するためのSOAPメッセージを構築しています.
指定したファイル名でPDFファイルをWebサービスサーバ上のコンテンツリポジトリへ出力するように指示しています.
次回は,前回も使用しました,dispatchというScala用のライブラリを利用して,サーバにSOAPメッセージを送信したいと思います.
ソースコードは次のようになります。
- 《 Scalaからbiz-Stream Webサービスサーバへデータを送りPDFを生成するソースコード(SOAPメッセージの構築) 》
-
package wssclient object wss_client { val FILE_NAME = "output_test.pdf" val DATASOURCE_NAME = "app-resource" val COL1 = "col1" val COL2 = "col2" val COL3 = "col3" val RESOURCE_NAME = "resource1" def main(args: Array[String]) { val layoutXml = <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:pdf="http://www.brainsellers.com/schema" xmlns:svg="http://www.brainsellers.com/schema" xmlns:bs="http://www.brainsellers.com/schema" xmlns:form="http://www.brainsellers.com/schema"> <bs:datasource-master-set> <bs:application-data-resource-master master-name={DATASOURCE_NAME}/> <bs:application-data-master master-name="app-field"> <bs:application-data-statement master-reference={DATASOURCE_NAME}/> </bs:application-data-master> <bs:datasource-master master-name="app-source" position="inherit"> <bs:application-data-master-reference master-reference="app-field"/> </bs:datasource-master> </bs:datasource-master-set> <fo:layout-master-set> <fo:simple-page-master master-name="A4" page-height="297mm" page-width="210mm"> <fo:region-body> <fo:region-before extent="0"> <fo:region-after extent="0"> <fo:region-start extent="0"> <fo:region-end extent="0"> </fo:region-end> </fo:region-start> </fo:region-after> </fo:region-before> </fo:region-body> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="A4"> <fo:flow flow-name="xsl-region-body"> <bs:block-container> <!-- ページレイアウト定義開始 --> <Layout width="210mm" height="297mm" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:bs="http://www.brainsellers.com/schema" xmlns:svg="http://www.brainsellers.com/schema" xmlns:form="http://www.brainsellers.com/schema" xmlns:pdf="http://www.brainsellers.com/schema"> <flow-area name="flow-area" x="14" y="280" width="180" height="260" master-reference="app-source" no-data-disabled="false"> <flow-table line-height="10" record-type="header" view="page" border-color="0,255,255"> <flow-table-cell cell-width="60" align="horizon" text-align="left" cell-align="bottom" narrow="size"> <Label Width="60" Height="10" Horizon="center" Vertical="center" Vector="horizon" FontSize="12" FontStyle="BOLD" Narrow="horizon">col1</Label> </flow-table-cell> <flow-table-cell cell-width="30" align="horizon" text-align="left" cell-align="bottom" narrow="size"> <Label Width="30" Height="10" Horizon="center" Vertical="center" Vector="horizon" FontSize="12" FontStyle="BOLD" Narrow="horizon">col2</Label> </flow-table-cell> <flow-table-cell cell-width="90" align="horizon" text-align="left" cell-align="bottom" narrow="size"> <Label Width="90" Height="10" Horizon="center" Vertical="center" Vector="horizon" FontSize="12" FontStyle="BOLD" Narrow="horizon">col3</Label> </flow-table-cell> </flow-table> <flow-table record-type="details" view="layout"> <flow-table-cell cell-width="60" border-color="0,255,255" cell-align="top" narrow="size"> <multi-text name={COL1} cell-width="60" font-size="11" margin="start:1;end:1;top:1;bottom:1"/> </flow-table-cell> <flow-table-cell cell-width="30" border-color="0,255,255" cell-align="top" narrow="size"> <multi-text name={COL2} cell-width="30" font-size="11" margin="start:1;end:1;top:1;bottom:1"/> </flow-table-cell> <flow-table-cell cell-width="90" border-color="0,255,255" cell-align="top" narrow="size"> <multi-text name={COL3} cell-width="90" font-size="11" margin="start:1;end:1;top:1;bottom:1"/> </flow-table-cell> </flow-table> </flow-area> </Layout> <!-- ページレイアウト定義完了 --> </bs:block-container> </fo:flow> </fo:page-sequence> </fo:root> val layoutString = layoutXml.toString val records = List( Map(1 -> "data1", 2 -> "data2", 3 -> "data3"), Map(1 -> "data2_1", 2 -> "data2_2", 3 -> "data2_3"), Map(1 -> "data3_1", 2 -> "data3_2", 3 -> "data3_3")) val soapMessage = <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns="http://schemas.brainsellers.com/webservices/bizstream/2006-10" xmlns:ns1="http://schemas.brainsellers.com/webservices/common/2006-10" xmlns:xm="http://www.w3.org/2005/05/xmlmime"> <soap:Header/> <soap:Body> <generateOutputRequest xmlns="http://schemas.brainsellers.com/webservices/bizstream/2006-10" xmlns:common="http://schemas.brainsellers.com/webservices/common/2006-10"> <output> <pdf> <file name={FILE_NAME}/> </pdf> </output> <resource> <resourceData name={RESOURCE_NAME}> <applicationData masterName={DATASOURCE_NAME}> <recordData> <header> <headerColumn value={COL1}/> <headerColumn value={COL2}/> <headerColumn value={COL3}/> </header>{records.map(record => <detail> <detailColumn value={record(1)}/> <detailColumn value={record(2)}/> <detailColumn value={record(3)}/> </detail>)} </recordData> </applicationData> </resourceData> </resource> <layoutData> <layoutDefinition dataReference={RESOURCE_NAME}> {layoutString} </layoutDefinition> </layoutData> </generateOutputRequest> </soap:Body> </soap:Envelope> print(soapMessage) } }