Search in sources :

Example 1 with VersionConversionFilter

use of com.datatorrent.stram.client.WebServicesVersionConversion.VersionConversionFilter in project apex-core by apache.

the class WebServicesVersionConversionTest method testVersioning.

@Test
public void testVersioning() throws Exception {
    WebServicesClient wsClient = new WebServicesClient();
    Client client = wsClient.getClient();
    WebResource ws = client.resource("http://localhost:" + port).path("/new_path");
    WebServicesVersionConversion.Converter versionConverter = new WebServicesVersionConversion.Converter() {

        @Override
        public String convertCommandPath(String path) {
            if (path.equals("/new_path")) {
                return "/old_path";
            }
            return path;
        }

        @Override
        public String convertResponse(String path, String response) {
            if (path.equals("/new_path")) {
                try {
                    JSONObject json = new JSONObject(response);
                    json.put("new_key", json.get("old_key"));
                    json.remove("old_key");
                    return json.toString();
                } catch (JSONException ex) {
                    throw new RuntimeException(ex);
                }
            }
            return response;
        }
    };
    VersionConversionFilter versionConversionFilter = new VersionConversionFilter(versionConverter);
    client.addFilter(versionConversionFilter);
    JSONObject result = new JSONObject(ws.get(String.class));
    Assert.assertEquals(result.getString("url"), "/old_path");
    Assert.assertEquals(result.getString("new_key"), "value");
    Assert.assertEquals(result.getString("other_key"), "other_value");
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) JSONException(org.codehaus.jettison.json.JSONException) WebServicesClient(com.datatorrent.stram.util.WebServicesClient) WebServicesClient(com.datatorrent.stram.util.WebServicesClient) Client(com.sun.jersey.api.client.Client) VersionConversionFilter(com.datatorrent.stram.client.WebServicesVersionConversion.VersionConversionFilter) Test(org.junit.Test)

Example 2 with VersionConversionFilter

use of com.datatorrent.stram.client.WebServicesVersionConversion.VersionConversionFilter in project apex-core by apache.

the class StramAgent method getStramWebURIBuilder.

private UriBuilder getStramWebURIBuilder(WebServicesClient webServicesClient, String appid) throws IncompatibleVersionException {
    webServicesClient.getClient().setFollowRedirects(true);
    webServicesClient.clearFilters();
    StramWebServicesInfo info = getWebServicesInfo(appid);
    UriBuilder ub = null;
    if (info != null) {
        // ws = wsClient.resource("http://" + info.appMasterTrackingUrl).path(WebServices.PATH).path(info.version).path("stram");
        // the filter should convert to the right version
        String url;
        if (!info.appMasterTrackingUrl.startsWith("http://") && !info.appMasterTrackingUrl.startsWith("https://")) {
            url = "http://" + info.appMasterTrackingUrl;
        } else {
            url = info.appMasterTrackingUrl;
        }
        ub = UriBuilder.fromUri(url).path(WebServices.PATH).path(WebServices.VERSION).path("stram");
        WebServicesVersionConversion.Converter versionConverter = WebServicesVersionConversion.getConverter(info.version);
        if (versionConverter != null) {
            VersionConversionFilter versionConversionFilter = new VersionConversionFilter(versionConverter);
            webServicesClient.addFilter(versionConversionFilter);
        }
        if (info.securityInfo != null) {
            webServicesClient.addFilter(info.securityInfo.secClientFilter);
        }
    }
    return ub;
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) VersionConversionFilter(com.datatorrent.stram.client.WebServicesVersionConversion.VersionConversionFilter)

Aggregations

VersionConversionFilter (com.datatorrent.stram.client.WebServicesVersionConversion.VersionConversionFilter)2 WebServicesClient (com.datatorrent.stram.util.WebServicesClient)1 Client (com.sun.jersey.api.client.Client)1 WebResource (com.sun.jersey.api.client.WebResource)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 JSONException (org.codehaus.jettison.json.JSONException)1 JSONObject (org.codehaus.jettison.json.JSONObject)1 Test (org.junit.Test)1