Destinations: contain the connection details for the remote communication of an application.

Create destination service instance


@RequestMapping(value = "/getProducts")
public String getProducts() {
String DESTINATION_NAME = "northwind_api";
try {
HttpDestination destination =
DestinationAccessor.getDestination(DESTINATION_NAME).asHttp();
HttpClient client = HttpClientAccessor.getHttpClient(destination);
HttpResponse httpResponse = null;
try {
httpResponse = client.execute(new HttpGet());
if (httpResponse.getStatusLine().getStatusCode() == 200) {
BufferedReader reader = new BufferedReader(
new InputStreamReader(httpResponse.getEntity().getContent()));
StringBuilder result = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
result.append(line);
}
reader.close();
return result.toString();
}
} catch (IOException e) {
return "IOException: " + e.getMessage();
}
} catch (DestinationNotFoundException | DestinationAccessException e) {
return e.getMessage();
}
return null;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 39 | |
| 37 | |
| 33 | |
| 31 | |
| 29 | |
| 23 | |
| 21 | |
| 21 | |
| 21 | |
| 20 |