use of jp.ossc.nimbus.beans.dataset.Header in project nimbus by nimbus-org.
the class HttpClientFactoryServiceTest method testExecuteRequestWithCompressDataSet.
/**
* 指定された論理アクション名に該当するリクエストを発行するテスト。
* <p>
* 条件:
* <ul>
* <li>次の内容の定義ファイルをロードし、HttpClientFactoryServiceインスタンスを生成する</li>
* <li>RequestContentType:application/xml</li>
* <li>RequestHeaders(Accept-Encoding):gzip</li>
* <li>RequestHeaders(Content-Encoding):gzip(リクエストデータを圧縮)</li>
* <li>RequestStreamConverterServiceName:#DataSetXMLConverter</li>
* <li>ResponseStreamConverterServiceName:#ResponseStreamConverter</li>
* <li>ResponseHeaders:ContentType=application/xml</li>
* <li>Proxy:#localhost:8280</li>
* <li>論理アクション名"login"のリクエスト情報を定義</li>
* <li>HttpClientFactoryService#createHttpClient()を実行し、HttpClientを生成</li>
* <li>HttpRequestImpl#createRequest(論理アクション名)を実行し、HttpRequestを生成</li>
* <li>送信するデータセットを次の内容で生成し、HttpRequest#setObject()でセット<BR>
* スキーマ::name,java.lang.String,,,\n:age,int,,,<BR>
* 値 :name=hoge,age=25 </li>
* <li>生成したHttpRequestを指定して、HttpClientImpl#executeRequest(request)を実行</li>
* </ul>
* 確認:
* <ul>
* <li>送信先で指定した次の値がHTTPリクエストに正しく設定されていることを確認</li>
* </ul>
*/
public void testExecuteRequestWithCompressDataSet() {
try {
if (!ServiceManagerFactory.loadManager("jp/ossc/nimbus/service/http/httpclient/service-clientTestComp.xml")) {
System.exit(-1);
}
final HttpClientFactory factory = (HttpClientFactory) ServiceManagerFactory.getServiceObject("HttpClientFactory");
HttpClientImpl client = (HttpClientImpl) factory.createHttpClient();
DataSet requestDs = new DataSet("Login");
requestDs.setHeaderSchema("UserInfo", ":name,java.lang.String,,,\n" + ":age,int,,,");
Header userInfo = requestDs.getHeader("UserInfo");
userInfo.setProperty("name", "hoge");
userInfo.setProperty("age", 25);
HttpRequest request = factory.createRequest("login");
request.setObject(requestDs);
HttpResponse res = client.executeRequest(request);
// レスポンス内容の確認
assertEquals(200, res.getStatusCode());
assertEquals("testdata", res.getObject());
/*Proxyテスト用プログラム(jp.ossc.nimbus.service.http.proxy.TestHttpProcessService)
* の出力ファイルの内容を確認し、HTTPリクエストデータを検証
*/
BufferedReader br = new BufferedReader(new FileReader("target/temp/jp/ossc/nimbus/service/http/httpclient/help_output.txt"));
String s;
StringBuffer sb = new StringBuffer();
// Requestヘッダの検証
while ((s = br.readLine()) != null) {
if (s.startsWith("Content-Type:")) {
assertTrue(s.endsWith("application/xml"));
}
if (s.startsWith("Content-Encoding:")) {
assertTrue(s.endsWith("gzip"));
}
if (s.startsWith("Accept-Encoding:")) {
assertTrue(s.endsWith("gzip"));
}
sb.append(s);
}
br.close();
// DataSet内容の検証
assertTrue(sb.toString().endsWith("<dataSet name=\"Login\"><schema>" + "<header name=\"UserInfo\">:name,java.lang.String,,,:age,int,,,</header>" + "</schema><header name=\"UserInfo\">" + "<name>hoge</name><age>25</age></header></dataSet>"));
} catch (HttpRequestCreateException e) {
e.printStackTrace();
fail("例外発生");
} catch (FileNotFoundException e) {
e.printStackTrace();
fail("例外発生");
} catch (IOException e) {
e.printStackTrace();
fail("例外発生");
} catch (Exception e) {
e.printStackTrace();
fail("例外発生");
} finally {
ServiceManagerFactory.unloadManager("jp/ossc/nimbus/service/http/httpclient/service-clientTestComp.xml");
}
}
use of jp.ossc.nimbus.beans.dataset.Header in project nimbus by nimbus-org.
the class HttpClientFactoryServiceTest method testExecuteRequestWithDataSet.
/**
* 指定された論理アクション名に該当するリクエストを発行するテスト。
* <p>
* 条件:
* <ul>
* <li>次の内容の定義ファイルをロードし、HttpClientFactoryServiceインスタンスを生成する</li>
* <li>RequestContentType:application/xml</li>
* <li>RequestCharacterEncoding:Shift_JIS</li>
* <li>RequestStreamConverterServiceName:#DataSetXMLConverter</li>
* <li>ResponseStreamConverterServiceName:#ResponseStreamConverter</li>
* <li>ResponseHeaders:ContentType=application/xml</li>
* <li>Proxy:#localhost:8280</li>
* <li>論理アクション名"login"のリクエスト情報を定義</li>
* <li>HttpClientFactoryService#createHttpClient()を実行し、HttpClientを生成</li>
* <li>HttpRequestImpl#createRequest(論理アクション名)を実行し、HttpRequestを生成</li>
* <li>送信するデータセットを次の内容で生成し、HttpRequest#setObject()でセット<BR>
* スキーマ::name,java.lang.String,,,\n:age,int,,,<BR>
* 値 :name=hoge,age=25 </li>
* <li>生成したHttpRequestを指定して、HttpClientImpl#executeRequest(request)を実行</li>
* </ul>
* 確認:
* <ul>
* <li>送信先で指定した次の値がHTTPリクエストに正しく設定されていることを確認</li>
* </ul>
*/
public void testExecuteRequestWithDataSet() {
try {
if (!ServiceManagerFactory.loadManager("jp/ossc/nimbus/service/http/httpclient/service-clientTest.xml")) {
System.exit(-1);
}
final HttpClientFactory factory = (HttpClientFactory) ServiceManagerFactory.getServiceObject("HttpClientFactory");
HttpClientImpl client = (HttpClientImpl) factory.createHttpClient();
DataSet requestDs = new DataSet("Login");
requestDs.setHeaderSchema("UserInfo", ":name,java.lang.String,,,\n" + ":age,int,,,");
Header userInfo = requestDs.getHeader("UserInfo");
userInfo.setProperty("name", "hoge");
userInfo.setProperty("age", 25);
HttpRequest request = factory.createRequest("login");
request.setObject(requestDs);
client.executeRequest(request);
/*Proxyテスト用プログラム(jp.ossc.nimbus.service.http.proxy.TestHttpProcessService)
* の出力ファイルの内容を確認し、HTTPリクエストデータを検証
*/
BufferedReader br = new BufferedReader(new FileReader("target/temp/jp/ossc/nimbus/service/http/httpclient/help_output.txt"));
String s;
StringBuffer sb = new StringBuffer();
// Requestヘッダの検証
while ((s = br.readLine()) != null) {
if (s.startsWith("Content-Type:")) {
assertTrue(s.endsWith("application/xml;charset=Shift_JIS"));
}
sb.append(s);
}
br.close();
// DataSet内容の検証
assertTrue(sb.toString().endsWith("<dataSet name=\"Login\"><schema>" + "<header name=\"UserInfo\">:name,java.lang.String,,,:age,int,,,</header>" + "</schema><header name=\"UserInfo\">" + "<name>hoge</name><age>25</age></header></dataSet>"));
} catch (HttpRequestCreateException e) {
e.printStackTrace();
fail("例外発生");
} catch (FileNotFoundException e) {
e.printStackTrace();
fail("例外発生");
} catch (IOException e) {
e.printStackTrace();
fail("例外発生");
} finally {
ServiceManagerFactory.unloadManager("jp/ossc/nimbus/service/http/httpclient/service-clientTest.xml");
}
}
use of jp.ossc.nimbus.beans.dataset.Header in project nimbus by nimbus-org.
the class DataSetHtmlConverterTest method testConvertToObject.
public void testConvertToObject() {
DataSet inputDataSet = new DataSetHtmlConverterTestDataSet();
DataSetHtmlConverter converter = new DataSetHtmlConverter();
converter.setCharacterEncodingToObject("Windows-31J");
DataSetHtmlConverterTestDataSet dataSet = (DataSetHtmlConverterTestDataSet) converter.convertToObject(createTestData(), inputDataSet);
Header header = dataSet.getHeader();
RecordList recordList = dataSet.getRecordList();
Assert.assertEquals("タイトル", header.get(DataSetHtmlConverterTestDataSet.PROPERTY1));
Assert.assertEquals("テキスト", header.get(DataSetHtmlConverterTestDataSet.PROPERTY2));
for (int i = 0; i < recordList.size(); i++) {
Record record = (Record) recordList.get(i);
Assert.assertEquals("テキスト" + (i + 1) + "-1", record.get(DataSetHtmlConverterTestDataSet.PROPERTY3));
Assert.assertEquals("テキスト" + (i + 1) + "-2", record.get(DataSetHtmlConverterTestDataSet.PROPERTY4));
Assert.assertEquals("テキスト" + (i + 1) + "-3", record.get(DataSetHtmlConverterTestDataSet.PROPERTY5));
}
}
use of jp.ossc.nimbus.beans.dataset.Header in project nimbus by nimbus-org.
the class DataSetJournalEditorService method makeHeadersFormat.
protected StringBuilder makeHeadersFormat(EditorFinder finder, Object key, DataSet dataSet, StringBuilder buf) {
buf.append(HEADERS_HEADER);
final String[] names = dataSet.getHeaderNames();
if (names.length == 0) {
buf.append(NULL_STRING);
return buf;
} else {
buf.append(getLineSeparator());
}
final StringBuilder subBuf = new StringBuilder();
for (int i = 0; i < names.length; i++) {
Header header = dataSet.getHeader(names[i]);
if (!enabledHeaderSet.isEmpty() && !enabledHeaderSet.contains(names[i])) {
continue;
}
makeObjectFormat(finder, null, header, subBuf);
if (i != names.length - 1) {
subBuf.append(getLineSeparator());
}
}
addIndent(subBuf);
return buf.append(subBuf);
}
use of jp.ossc.nimbus.beans.dataset.Header in project nimbus by nimbus-org.
the class HeaderJournalEditorService method processBlock.
protected boolean processBlock(EditorFinder finder, Object key, Object value, StringBuilder buf) {
final Header bean = (Header) value;
boolean isMake = false;
if (isOutputHeaderName()) {
makeHeaderNameFormat(finder, key, bean, buf);
isMake = true;
}
if (isOutputRecordSchema()) {
if (isMake) {
buf.append(getLineSeparator());
}
makeRecordSchemaFormat(finder, key, bean, buf);
isMake = true;
}
if (isOutputProperties()) {
if (isMake) {
buf.append(getLineSeparator());
}
makePropertiesFormat(finder, key, bean, buf);
isMake = true;
}
return isMake;
}
Aggregations