Search in sources :

Example 11 with HttpClientImpl

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

the class HttpResponseImplTest method testGetHeaderMapNull.

/**
 * ヘッダー情報を取得するテスト。
 * <p>
 * 条件:
 * <ul>
 * <li>定義ファイルをロードし、HttpClientFactoryServiceインスタンスを生成する</li>
 * <li>HttpRequestImpl#createRequest(論理アクション名)を実行し、HttpRequestを生成</li>
 * <li>HttpRequestImpl#executeRequest()を実行し、HttpResponseを生成</li>
 * <li>レスポンスのヘッダーにContent-Type=text/html;charset=Shift_JISが含まれている</li>
 * <li>HttpResponseImpl#getHeader(),getHeaders()を実行</li>
 * </ul>
 * 確認:
 * <ul>
 * <li>HttpResponseImpl#getHeader(),getHeaders()が正しい結果が返されることを確認</li>
 * </ul>
 */
public void testGetHeaderMapNull() {
    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);
        HttpResponseImpl res = (HttpResponseImpl) client.executeRequest(request);
        assertEquals("text/html;charset=Shift_JIS", res.getHeader("Content-Type"));
        assertEquals("text/html;charset=Shift_JIS", res.getHeaders("Content-Type")[0]);
    } catch (Exception e) {
        e.printStackTrace();
        fail("例外発生");
    } finally {
        ServiceManagerFactory.unloadManager("jp/ossc/nimbus/service/http/httpclient/service-clientTest.xml");
    }
}
Also used : HttpRequest(jp.ossc.nimbus.service.http.HttpRequest) Header(jp.ossc.nimbus.beans.dataset.Header) DataSet(jp.ossc.nimbus.beans.dataset.DataSet) HttpClientImpl(jp.ossc.nimbus.service.http.httpclient.HttpClientFactoryService.HttpClientImpl) HttpClientFactory(jp.ossc.nimbus.service.http.HttpClientFactory) ConvertException(jp.ossc.nimbus.util.converter.ConvertException) PropertySchemaDefineException(jp.ossc.nimbus.beans.dataset.PropertySchemaDefineException)

Example 12 with HttpClientImpl

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

the class HttpResponseImplTest method testGetHeaderMap.

/**
 * ヘッダー情報を取得するテスト。
 * <p>
 * 条件:
 * <ul>
 * <li>定義ファイルをロードし、HttpClientFactoryServiceインスタンスを生成する</li>
 * <li>HttpRequestImpl#createRequest(論理アクション名)を実行し、HttpRequestを生成</li>
 * <li>HttpRequestImpl#executeRequest()を実行し、HttpResponseを生成</li>
 * <li>レスポンスのヘッダーにContent-Type=text/html;charset=Shift_JISが含まれている</li>
 * <li>HttpResponseImpl#getHeadermap()を実行してmapを生成</li>
 * <li>HttpResponseImpl#getHeader(),getHeaders()を実行</li>
 * </ul>
 * 確認:
 * <ul>
 * <li>HttpResponseImpl#getHeader(),getHeaders()が正しい結果が返されることを確認</li>
 * </ul>
 */
public void testGetHeaderMap() {
    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);
        HttpResponseImpl res = (HttpResponseImpl) client.executeRequest(request);
        res.getHeaderMap();
        assertEquals("text/html;charset=Shift_JIS", res.getHeader("Content-Type"));
        assertEquals("text/html;charset=Shift_JIS", res.getHeaders("Content-Type")[0]);
    } catch (Exception e) {
        e.printStackTrace();
        fail("例外発生");
    } finally {
        ServiceManagerFactory.unloadManager("jp/ossc/nimbus/service/http/httpclient/service-clientTest.xml");
    }
}
Also used : HttpRequest(jp.ossc.nimbus.service.http.HttpRequest) Header(jp.ossc.nimbus.beans.dataset.Header) DataSet(jp.ossc.nimbus.beans.dataset.DataSet) HttpClientImpl(jp.ossc.nimbus.service.http.httpclient.HttpClientFactoryService.HttpClientImpl) HttpClientFactory(jp.ossc.nimbus.service.http.HttpClientFactory) ConvertException(jp.ossc.nimbus.util.converter.ConvertException) PropertySchemaDefineException(jp.ossc.nimbus.beans.dataset.PropertySchemaDefineException)

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