Search in sources :

Example 1 with HttpClientImpl

use of jp.ossc.nimbus.service.http.httpclient.HttpClientFactoryService.HttpClientImpl in project nimbus by nimbus-org.

the class HttpClientFactoryServiceTest method testCreateHttpClient.

/**
 * 指定された論理アクション名に該当するHttpClientを生成するテスト。
 * <p>
 * 条件:
 * <ul>
 * <li>次の内容の定義ファイルをロードし、HttpClientFactoryServiceインスタンスを生成する</li>
 * <li>LocalAddress:127.0.0.1</li>
 * <li>Proxy:localhost:8280</li>
 * <li>HttpVersion:1.1</li>
 * <li>ConnectionTimeout:500</li>
 * <li>SoTimeout:1000</li>
 * <li>Linger:500</li>
 * <li>RequestDeflateLength:1000000</li>
 * <li>RequestContentType:application/xml</li>
 * <li>RequestCharacterEncoding:UTF-8</li>
 * <li>RequestHeaders(Accept-Encoding):gzip</li>
 * <li>RequestHeaders(Content-Encoding):gzip</li>
 * <li>RequestStreamConverterServiceName:#DateSetXMLConverter</li>
 * <li>HttpClientParam(ConnectionTimeout):500</li>
 * <li>HttpClientFactoryService#createHttpClient()を実行</li>
 * </ul>
 * 確認:
 * <ul>
 * <li>HttpClienttオブジェクトにに指定した値が設定されていることを確認</li>
 * </ul>
 */
public void testCreateHttpClient() {
    try {
        if (!ServiceManagerFactory.loadManager("jp/ossc/nimbus/service/http/httpclient/service-client1.xml")) {
            System.exit(-1);
        }
        final HttpClientFactory factory = (HttpClientFactory) ServiceManagerFactory.getServiceObject("HttpClientFactory");
        HttpClientImpl client = (HttpClientImpl) factory.createHttpClient();
        assertEquals("localhost", client.client.getHostConfiguration().getProxyHost());
        assertEquals(8280, client.client.getHostConfiguration().getProxyPort());
        assertEquals("127.0.0.1", client.client.getHostConfiguration().getLocalAddress().getHostAddress());
        assertEquals(500, client.client.getHttpConnectionManager().getParams().getConnectionTimeout());
        assertEquals(1000, client.client.getHttpConnectionManager().getParams().getSoTimeout());
        assertEquals(500, client.client.getHttpConnectionManager().getParams().getLinger());
        assertEquals(5000, client.client.getHttpConnectionManager().getParams().getReceiveBufferSize());
        assertEquals(5000, client.client.getHttpConnectionManager().getParams().getSendBufferSize());
    } catch (HttpRequestCreateException e) {
        e.printStackTrace();
        fail("例外発生");
    } finally {
        ServiceManagerFactory.unloadManager("jp/ossc/nimbus/service/http/httpclient/service-client1.xml");
    }
}
Also used : HttpClientImpl(jp.ossc.nimbus.service.http.httpclient.HttpClientFactoryService.HttpClientImpl)

Example 2 with HttpClientImpl

use of jp.ossc.nimbus.service.http.httpclient.HttpClientFactoryService.HttpClientImpl 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");
    }
}
Also used : Header(jp.ossc.nimbus.beans.dataset.Header) HttpClientImpl(jp.ossc.nimbus.service.http.httpclient.HttpClientFactoryService.HttpClientImpl)

Example 3 with HttpClientImpl

use of jp.ossc.nimbus.service.http.httpclient.HttpClientFactoryService.HttpClientImpl in project nimbus by nimbus-org.

the class HttpClientFactoryServiceTest method testExecuteRequestWithoutData.

/**
 * 指定された論理アクション名に該当するリクエストを発行するテスト。
 * <p>
 * 条件:
 * <ul>
 * <li>次の内容の定義ファイルをロードし、HttpClientFactoryServiceインスタンスを生成する</li>
 * <li>RequestContentType:application/xml</li>
 * <li>RequestCharacterEncoding:Shift_JIS</li>
 * <li>RequestStreamConverterServiceName:#DataSetXMLConverter</li>
 * <li>ResponseStreamConverterServiceName:#ResponseStreamConverter</li>
 * <li>Proxy:#localhost:8280</li>
 * <li>次のパラメータ定義と併せて論理アクション名"login"のリクエスト情報を定義<BR>
 * sectionCode=22,account=05961,password=05961</li>
 * <li>HttpClientFactoryService#createHttpClient()を実行し、HttpClientを生成</li>
 * <li>HttpRequestImpl#createRequest(論理アクション名)を実行し、HttpRequestを生成</li>
 * <li>生成したHttpRequestを指定して、HttpClientImpl#executeRequest(request)を実行</li>
 * </ul>
 * 確認:
 * <ul>
 * <li>送信先で指定した次の値がHTTPリクエストに正しく設定されていることを確認</li>
 * <li>レスポンスの内容が正しく設定されていることを確認</li>
 * </ul>
 */
public void testExecuteRequestWithoutData() {
    try {
        if (!ServiceManagerFactory.loadManager("jp/ossc/nimbus/service/http/httpclient/service-clientTest2.xml")) {
            System.exit(-1);
        }
        final HttpClientFactory factory = (HttpClientFactory) ServiceManagerFactory.getServiceObject("HttpClientFactory");
        HttpClientImpl client = (HttpClientImpl) factory.createHttpClient();
        HttpRequest request = factory.createRequest("login");
        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;charset=Shift_JIS"));
            }
            sb.append(s);
        }
        br.close();
        // DataSet内容の検証
        assertTrue(sb.toString().endsWith("sectionCode=022&account=059641&password=059641"));
    } 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-clientTest2.xml");
    }
}
Also used : HttpClientImpl(jp.ossc.nimbus.service.http.httpclient.HttpClientFactoryService.HttpClientImpl)

Example 4 with HttpClientImpl

use of jp.ossc.nimbus.service.http.httpclient.HttpClientFactoryService.HttpClientImpl 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");
    }
}
Also used : Header(jp.ossc.nimbus.beans.dataset.Header) HttpClientImpl(jp.ossc.nimbus.service.http.httpclient.HttpClientFactoryService.HttpClientImpl)

Example 5 with HttpClientImpl

use of jp.ossc.nimbus.service.http.httpclient.HttpClientFactoryService.HttpClientImpl in project nimbus by nimbus-org.

the class HttpRequestImplTest method testRequestSetHeader.

/**
 * HttpRequestにヘッダ情報を設定するテスト。
 * <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に対してsetContentType()を実行し、ContentTypeヘッダ情報設定</li>
 * <li>生成したHttpRequestに対してsetHeader(),addHeader()を実行しヘッダ情報設定</li>
 * <li>生成したHttpRequestを指定して、HttpClientImpl#executeRequest(request)を実行</li>
 * </ul>
 * 確認:
 * <ul>
 * <li>setContentType()で設定したヘッダ情報が優先されることを確認</li>
 * <li>ssetHeader(),addHeader()設定したヘッダ情報が反映されることを確認</li>
 * </ul>
 */
public void testRequestSetHeader() {
    try {
        if (!ServiceManagerFactory.loadManager("jp/ossc/nimbus/service/http/httpclient/service-clientTest2.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);
        HttpRequestImpl request = (HttpRequestImpl) factory.createRequest("login");
        // request.setObject(requestDs);
        // ヘッダ情報設定
        request.setContentType("text/html");
        request.addHeader("Accept", "text/html");
        request.addHeader("Accept", "text/html");
        request.setHeader("Accept-Language", "jp");
        // settr,getterの動作確認
        request.setHttpVersion("1.1");
        assertEquals("1.1", request.getHttpVersion());
        request.setDoAuthentication(true);
        assertTrue(request.isDoAuthentication());
        request.setFollowRedirects(false);
        assertFalse(request.isFollowRedirects());
        request.setHttpMethodParam("TEST", "test");
        request.setHttpMethodParam("TEST1", "test1");
        assertEquals("test", request.getHttpMethodParam("TEST"));
        assertEquals("test1", request.getHttpMethodParam("TEST1"));
        assertTrue(request.getHttpMethodParamNameSet().contains("TEST"));
        assertTrue(request.getHttpMethodParamNameSet().contains("TEST1"));
        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("text/html;charset=Shift_JIS"));
            }
            if (s.startsWith("Accept:")) {
                assertTrue(s.endsWith("text/html"));
            }
            if (s.startsWith("Accept-Language:")) {
                assertTrue(s.endsWith("jp"));
            }
            sb.append(s);
        }
        br.close();
        // DataSet内容の検証
        assertTrue(sb.toString().endsWith("sectionCode=022&account=059641&password=059641"));
    } 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-clientTest2.xml");
    }
}
Also used : HttpRequestCreateException(jp.ossc.nimbus.service.http.HttpRequestCreateException) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException) HttpClientImpl(jp.ossc.nimbus.service.http.httpclient.HttpClientFactoryService.HttpClientImpl) HttpClientFactory(jp.ossc.nimbus.service.http.HttpClientFactory)

Aggregations

HttpClientImpl (jp.ossc.nimbus.service.http.httpclient.HttpClientFactoryService.HttpClientImpl)12 Header (jp.ossc.nimbus.beans.dataset.Header)6 HttpClientFactory (jp.ossc.nimbus.service.http.HttpClientFactory)5 PropertySchemaDefineException (jp.ossc.nimbus.beans.dataset.PropertySchemaDefineException)3 HttpRequest (jp.ossc.nimbus.service.http.HttpRequest)3 ConvertException (jp.ossc.nimbus.util.converter.ConvertException)3 BufferedReader (java.io.BufferedReader)2 FileNotFoundException (java.io.FileNotFoundException)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 DataSet (jp.ossc.nimbus.beans.dataset.DataSet)2 HttpRequestCreateException (jp.ossc.nimbus.service.http.HttpRequestCreateException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 jp.ossc.nimbus.service.http (jp.ossc.nimbus.service.http)1 HttpMethodBase (org.apache.commons.httpclient.HttpMethodBase)1