Search in sources :

Example 1 with PolicyTestBackEndApiResponse

use of io.apiman.test.policies.PolicyTestBackEndApiResponse in project apiman-plugins by apiman.

the class ProduceJsonBackEndApi method invoke.

@Override
public PolicyTestBackEndApiResponse invoke(ApiRequest apiRequest, byte[] requestBody) {
    try {
        String responseBody = "{\"name\":\"apiman\"}";
        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 2 with PolicyTestBackEndApiResponse

use of io.apiman.test.policies.PolicyTestBackEndApiResponse 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 3 with PolicyTestBackEndApiResponse

use of io.apiman.test.policies.PolicyTestBackEndApiResponse 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 4 with PolicyTestBackEndApiResponse

use of io.apiman.test.policies.PolicyTestBackEndApiResponse 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 5 with PolicyTestBackEndApiResponse

use of io.apiman.test.policies.PolicyTestBackEndApiResponse 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)6 PolicyTestBackEndApiResponse (io.apiman.test.policies.PolicyTestBackEndApiResponse)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4