@Test public void testModifyUrl2() { String responseCorrect = "{\"urls\":[\"http: String resourcePath = "/example.com/second/{resourceId}/"; String responseStr = "{\"urls\":[\"http: responseStr = ConsumerGatewayUtil.rewriteUrl(servletUrl, resourcePath, responseStr); assertEquals(responseCorrect, responseStr); }
public static String rewriteUrl(String servletUrl, String pathToResource, String responseStr) { log.debug("Rewrite URLs in the response to point Consumer Gateway."); log.debug("Consumer Gateway URL : \"{}\".", servletUrl); try { String resourcePath = pathToResource.substring(1, pathToResource.length() - 1).replaceAll("/\\{" + Constants.PARAM_RESOURCE_ID + "\\}", ""); log.debug("Resourse URL that's replaced with Consumer Gateway URL : \"http(s): log.debug("New resource URL : \"{}{}\".", servletUrl, resourcePath); return responseStr.replaceAll("http(s|):\\/\\/" + resourcePath, servletUrl + resourcePath); } catch (Exception ex) { log.error("Rewriting the URLs failed!"); log.error(ex.getMessage(), ex); return responseStr; } }
ConsumerGatewayUtil { public static String rewriteUrl(String servletUrl, String pathToResource, String responseStr) { log.debug("Rewrite URLs in the response to point Consumer Gateway."); log.debug("Consumer Gateway URL : \"{}\".", servletUrl); try { String resourcePath = pathToResource.substring(1, pathToResource.length() - 1).replaceAll("/\\{" + Constants.PARAM_RESOURCE_ID + "\\}", ""); log.debug("Resourse URL that's replaced with Consumer Gateway URL : \"http(s): log.debug("New resource URL : \"{}{}\".", servletUrl, resourcePath); return responseStr.replaceAll("http(s|):\\/\\/" + resourcePath, servletUrl + resourcePath); } catch (Exception ex) { log.error("Rewriting the URLs failed!"); log.error(ex.getMessage(), ex); return responseStr; } } }
ConsumerGatewayUtil { public static String rewriteUrl(String servletUrl, String pathToResource, String responseStr) { log.debug("Rewrite URLs in the response to point Consumer Gateway."); log.debug("Consumer Gateway URL : \"{}\".", servletUrl); try { String resourcePath = pathToResource.substring(1, pathToResource.length() - 1).replaceAll("/\\{" + Constants.PARAM_RESOURCE_ID + "\\}", ""); log.debug("Resourse URL that's replaced with Consumer Gateway URL : \"http(s): log.debug("New resource URL : \"{}{}\".", servletUrl, resourcePath); return responseStr.replaceAll("http(s|):\\/\\/" + resourcePath, servletUrl + resourcePath); } catch (Exception ex) { log.error("Rewriting the URLs failed!"); log.error(ex.getMessage(), ex); return responseStr; } } private  ConsumerGatewayUtil(); }
ConsumerGatewayUtil { public static String rewriteUrl(String servletUrl, String pathToResource, String responseStr) { log.debug("Rewrite URLs in the response to point Consumer Gateway."); log.debug("Consumer Gateway URL : \"{}\".", servletUrl); try { String resourcePath = pathToResource.substring(1, pathToResource.length() - 1).replaceAll("/\\{" + Constants.PARAM_RESOURCE_ID + "\\}", ""); log.debug("Resourse URL that's replaced with Consumer Gateway URL : \"http(s): log.debug("New resource URL : \"{}{}\".", servletUrl, resourcePath); return responseStr.replaceAll("http(s|):\\/\\/" + resourcePath, servletUrl + resourcePath); } catch (Exception ex) { log.error("Rewriting the URLs failed!"); log.error(ex.getMessage(), ex); return responseStr; } } private  ConsumerGatewayUtil(); static Map<String, ConsumerEndpoint> extractConsumers(Properties endpoints, Properties gatewayProperties); static void extractEndpoints(String key, Properties endpoints, ConsumerEndpoint endpoint); static ConsumerEndpoint findMatch(String serviceId, Map<String, ConsumerEndpoint> endpoints); static String rewriteUrl(String servletUrl, String pathToResource, String responseStr); static ConsumerEndpoint createUnconfiguredEndpoint(Properties props, String pathToResource); static String removeResponseTag(String message); static boolean checkEncryptionProperties(Properties props, Map<String, ConsumerEndpoint> endpoints,
                                                    Map<String, Encrypter> asymmetricEncrypterCache); }
ConsumerGatewayUtil { public static String rewriteUrl(String servletUrl, String pathToResource, String responseStr) { log.debug("Rewrite URLs in the response to point Consumer Gateway."); log.debug("Consumer Gateway URL : \"{}\".", servletUrl); try { String resourcePath = pathToResource.substring(1, pathToResource.length() - 1).replaceAll("/\\{" + Constants.PARAM_RESOURCE_ID + "\\}", ""); log.debug("Resourse URL that's replaced with Consumer Gateway URL : \"http(s): log.debug("New resource URL : \"{}{}\".", servletUrl, resourcePath); return responseStr.replaceAll("http(s|):\\/\\/" + resourcePath, servletUrl + resourcePath); } catch (Exception ex) { log.error("Rewriting the URLs failed!"); log.error(ex.getMessage(), ex); return responseStr; } } private  ConsumerGatewayUtil(); static Map<String, ConsumerEndpoint> extractConsumers(Properties endpoints, Properties gatewayProperties); static void extractEndpoints(String key, Properties endpoints, ConsumerEndpoint endpoint); static ConsumerEndpoint findMatch(String serviceId, Map<String, ConsumerEndpoint> endpoints); static String rewriteUrl(String servletUrl, String pathToResource, String responseStr); static ConsumerEndpoint createUnconfiguredEndpoint(Properties props, String pathToResource); static String removeResponseTag(String message); static boolean checkEncryptionProperties(Properties props, Map<String, ConsumerEndpoint> endpoints,
                                                    Map<String, Encrypter> asymmetricEncrypterCache);  }