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");
}
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;
}
Aggregations