Search in sources :

Example 16 with ApiResponse

use of io.apiman.gateway.engine.beans.ApiResponse in project apiman-plugins by apiman.

the class JsonpPolicyTest method doNotChangeResponseWhenCallbackParamNameIsNotSavedInContext.

@Test
public void doNotChangeResponseWhenCallbackParamNameIsNotSavedInContext() throws Exception {
    JsonpConfigBean config = new JsonpConfigBean();
    // given
    ApiResponse response = new ApiResponse();
    // when
    IReadWriteStream<ApiResponse> responseDataHandler = jsonpPolicy.getResponseDataHandler(response, sContext, config);
    // then
    assertNull(responseDataHandler);
}
Also used : JsonpConfigBean(io.apiman.plugins.jsonp_policy.beans.JsonpConfigBean) ApiResponse(io.apiman.gateway.engine.beans.ApiResponse) Test(org.junit.Test)

Example 17 with ApiResponse

use of io.apiman.gateway.engine.beans.ApiResponse in project apiman-plugins by apiman.

the class ConsumeJsonBackEndApi method invoke.

@Override
public PolicyTestBackEndApiResponse invoke(ApiRequest apiRequest, byte[] requestBody) {
    String body = new String(requestBody);
    Assert.assertEquals("{\"a\":{\"b\":\"test\"}}", body);
    ApiResponse apiResponse = new ApiResponse();
    return new PolicyTestBackEndApiResponse(apiResponse, null);
}
Also used : PolicyTestBackEndApiResponse(io.apiman.test.policies.PolicyTestBackEndApiResponse) ApiResponse(io.apiman.gateway.engine.beans.ApiResponse) PolicyTestBackEndApiResponse(io.apiman.test.policies.PolicyTestBackEndApiResponse)

Example 18 with ApiResponse

use of io.apiman.gateway.engine.beans.ApiResponse in project apiman-plugins by apiman.

the class ConsumeXmlBackEndApi method invoke.

@Override
public PolicyTestBackEndApiResponse invoke(ApiRequest apiRequest, byte[] requestBody) {
    String body = new String(requestBody);
    Assert.assertEquals("<name>apiman</name>", body);
    ApiResponse apiResponse = new ApiResponse();
    return new PolicyTestBackEndApiResponse(apiResponse, null);
}
Also used : PolicyTestBackEndApiResponse(io.apiman.test.policies.PolicyTestBackEndApiResponse) ApiResponse(io.apiman.gateway.engine.beans.ApiResponse) PolicyTestBackEndApiResponse(io.apiman.test.policies.PolicyTestBackEndApiResponse)

Example 19 with ApiResponse

use of io.apiman.gateway.engine.beans.ApiResponse in project apiman-plugins by apiman.

the class ProduceComplexJsonBackEndApi method invoke.

@Override
public PolicyTestBackEndApiResponse invoke(ApiRequest apiRequest, byte[] requestBody) {
    try {
        String responseBody = "{\r\n" + "  \"property-1\" : \"value-1\",\r\n" + "  \"property-2\" : \"value-2\",\r\n" + "  \"object-1\" : {\r\n" + "    \"p1\" : \"v1\",\r\n" + "    \"p2\" : \"v2\"\r\n" + "  },\r\n" + "  \"array-1\" : [\r\n" + "    10,\r\n" + "    5,\r\n" + "    3,\r\n" + "    12\r\n" + "  ]\r\n" + "}";
        ApiResponse apiResponse = new ApiResponse();
        apiResponse.getHeaders().put("Content-Type", "application/json");
        apiResponse.getHeaders().put("Content-Length", String.valueOf(responseBody.getBytes("UTF-8").length));
        return new PolicyTestBackEndApiResponse(apiResponse, responseBody);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}
Also used : PolicyTestBackEndApiResponse(io.apiman.test.policies.PolicyTestBackEndApiResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ApiResponse(io.apiman.gateway.engine.beans.ApiResponse) PolicyTestBackEndApiResponse(io.apiman.test.policies.PolicyTestBackEndApiResponse)

Example 20 with ApiResponse

use of io.apiman.gateway.engine.beans.ApiResponse in project apiman-plugins by apiman.

the class ProduceEchoXmlResponseBackend method invoke.

/**
 * @see io.apiman.test.policies.IPolicyTestBackEndApi#invoke(io.apiman.gateway.engine.beans.ApiRequest, byte[])
 */
@Override
@SuppressWarnings("nls")
public PolicyTestBackEndApiResponse invoke(ApiRequest request, byte[] requestBody) {
    try {
        String responseBody = "<echoResponse>\r\n" + "  <counter>24</counter>\r\n" + "  <headers>\r\n" + "    <entry>\r\n" + "      <key>Accept</key>\r\n" + "      <value>text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8</value>\r\n" + "    </entry>\r\n" + "    <entry>\r\n" + "      <key>Connection</key>\r\n" + "      <value>keep-alive</value>\r\n" + "    </entry>\r\n" + "    <entry>\r\n" + "      <key>User-Agent</key>\r\n" + "      <value>Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0</value>\r\n" + "    </entry>\r\n" + "    <entry>\r\n" + "      <key>Host</key>\r\n" + "      <value>localhost:8080</value>\r\n" + "    </entry>\r\n" + "    <entry>\r\n" + "      <key>Accept-Language</key>\r\n" + "      <value>null</value>\r\n" + "    </entry>\r\n" + "    <entry>\r\n" + "      <key>Accept-Encoding</key>\r\n" + "      <value>gzip, deflate</value>\r\n" + "    </entry>\r\n" + "  </headers>\r\n" + "  <method>GET</method>\r\n" + "  <resource>/services/echo</resource>\r\n" + "  <uri>/services/echo</uri>\r\n" + "</echoResponse>";
        ApiResponse apiResponse = new ApiResponse();
        apiResponse.getHeaders().put("Content-Type", "application/xml");
        apiResponse.getHeaders().put("Content-Length", String.valueOf(responseBody.getBytes("UTF-8").length));
        return new PolicyTestBackEndApiResponse(apiResponse, responseBody);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}
Also used : PolicyTestBackEndApiResponse(io.apiman.test.policies.PolicyTestBackEndApiResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ApiResponse(io.apiman.gateway.engine.beans.ApiResponse) PolicyTestBackEndApiResponse(io.apiman.test.policies.PolicyTestBackEndApiResponse)

Aggregations

ApiResponse (io.apiman.gateway.engine.beans.ApiResponse)21 IApimanBuffer (io.apiman.gateway.engine.io.IApimanBuffer)7 ApiRequest (io.apiman.gateway.engine.beans.ApiRequest)5 PolicyTestBackEndApiResponse (io.apiman.test.policies.PolicyTestBackEndApiResponse)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 AbstractStream (io.apiman.gateway.engine.io.AbstractStream)4 ISignalWriteStream (io.apiman.gateway.engine.io.ISignalWriteStream)4 Test (org.junit.Test)4 IPolicyContext (io.apiman.gateway.engine.policy.IPolicyContext)3 IOException (java.io.IOException)3 IApiRequestExecutor (io.apiman.gateway.engine.IApiRequestExecutor)2 IEngine (io.apiman.gateway.engine.IEngine)2 IEngineResult (io.apiman.gateway.engine.IEngineResult)2 IAsyncResultHandler (io.apiman.gateway.engine.async.IAsyncResultHandler)2 ComponentNotFoundException (io.apiman.gateway.engine.beans.exceptions.ComponentNotFoundException)2 IBufferFactoryComponent (io.apiman.gateway.engine.components.IBufferFactoryComponent)2 ICacheStoreComponent (io.apiman.gateway.engine.components.ICacheStoreComponent)2 ByteBuffer (io.apiman.gateway.engine.io.ByteBuffer)2 JsonpConfigBean (io.apiman.plugins.jsonp_policy.beans.JsonpConfigBean)2 IApiConnectionResponse (io.apiman.gateway.engine.IApiConnectionResponse)1