+ /**
+ * @param discoveryUrl
+ * @return
+ */
+ private Response routeHttpPut2DiscoveryService(String resourceUrl) {
+ String discoveryServiceUrl = getDiscoveryServiceUrl();
+ String fullUrl = new StringBuilder(discoveryServiceUrl).append(resourceUrl).toString();
+ CloseableHttpClient httpClient = null;
+ CloseableHttpResponse httpResponse = null;
+ try {
+ HttpPut httpPut = HttpClientUtil.createHttpPut(fullUrl);
+ httpClient = HttpClients.createDefault();
+ httpResponse = httpClient.execute(httpPut);
+ return cloneHttpResponse(httpResponse);
+ } catch (Exception e) {
+ throw new ExtendedInternalServerErrorException(e.getMessage());
+ } finally {
+ HttpClientUtil.closeHttpClient(httpClient, httpResponse);
+ }
+ }
+
+ /**
+ * @param discoveryUrl
+ * @return
+ */
+ private Response routeHttpGet2DiscoveryService(String resourceUrl) {
+ String discoveryServiceUrl = getDiscoveryServiceUrl();
+ String fullUrl = new StringBuilder(discoveryServiceUrl).append(resourceUrl).toString();
+ CloseableHttpClient httpClient = null;
+ CloseableHttpResponse httpResponse = null;
+ try {
+ HttpGet httpGet = HttpClientUtil.createHttpGet(fullUrl);
+ httpClient = HttpClients.createDefault();
+ httpResponse = httpClient.execute(httpGet);
+ return cloneHttpResponse(httpResponse);
+ } catch (Exception e) {
+ throw new ExtendedInternalServerErrorException(e.getMessage());
+ } finally {
+ HttpClientUtil.closeHttpClient(httpClient, httpResponse);
+ }
+ }
+
+ /**
+ * @param microServiceFullInfo
+ * @param registrationUrl
+ * @return
+ */
+ private Response routeRegistration2DiscoveryService(MicroServiceFullInfo microServiceFullInfo) {
+ String registrationUrl = getDiscoveryServiceUrl();
+ CloseableHttpClient httpClient = null;
+ CloseableHttpResponse httpResponse = null;
+ try {
+ HttpPost httpPost = HttpClientUtil.createHttpPost(registrationUrl, microServiceFullInfo);
+ httpClient = HttpClients.createDefault();
+ httpResponse = httpClient.execute(httpPost);
+ return cloneHttpResponse(httpResponse);
+ } catch (Exception e) {
+ throw new ExtendedInternalServerErrorException(e.getMessage());
+ } finally {
+ HttpClientUtil.closeHttpClient(httpClient, httpResponse);
+ }
+ }
+
+ /**
+ * @param httpResponse
+ * @return
+ * @throws IOException
+ */
+ private Response cloneHttpResponse(CloseableHttpResponse httpResponse) throws IOException {
+ String jsonString = EntityUtils.toString(httpResponse.getEntity());
+ Response response = Response.status(httpResponse.getStatusLine().getStatusCode()).entity(jsonString).build();
+ return response;
+ }
+
+ /**
+ * @return
+ */
+ private String getDiscoveryServiceUrl() {
+ DiscoverInfo discoverInfo = ConfigUtil.getInstance().getDiscoverInfo();
+ String registrationUrl = new StringBuilder().append("http://").append(discoverInfo)
+ .append(RouteUtil.MSB_ROUTE_URL).toString();
+ return registrationUrl;