Currently, my goal is to establish a simple API response using AngularJS and the CXF-JAXRS library in an OSGi environment (KARAF). The challenge lies in retrieving the information sent back from the REST service even though the logs indicate a successful connection with a 200 status code.
Note: Due to StackExchange restrictions, I had to remove "http://" from all links initially included in the code/logs.
This fragment showcases the REST method being connected to:
@GET
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
public Response test(){
String testResponse = "Success.";
Response responseString = Response
.status(200)
.entity(testResponse)
.build();
return responseString;
}
Below is the snippet of AngularJS Controller:
app.controller('HttpController', function($scope, $http){
$http({
method: 'GET',
url: 'localhost:8181/cxf/strsoftware/test'
}).then(function successCallback(response){
$scope.testString = response.data;
}, function errorCallback(response){
$scope.testString = response;
});
$scope.validationString = "Controller is functional.";
});
Here you can find the AngularJS Display Code to further visualize the elements.
<div ng-controller="HttpController">
The response is {{ testString }}<br>
{{validationString}}
To troubleshoot any connectivity issues, take a look at this snapshot extracted from the KARAF logs:
2017-01-10 11:42:30,133 | INFO | qtp84694963-897 | LoggingInInterceptor | 107 - org.apache.cxf.cxf-core - 3.2.0.SNAPSHOT | Inbound Message
Headers: {Accept=[application/json, text/plain, /], accept-encoding=[gzip, deflate, sdch, br], Accept-Language=[en-US,en;q=0.8], connection=[keep-alive], Content-Type=[null], Host=[localhost:8181], Origin=[localhost:63343], Referer=[localhost:63343/STRFrontEnd/StartScreen.html?_ijt=qsu1c8a1qskj0def9ho1rml4hv], User-Agent=[Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36]}
Payload: Success.
UPDATE
The Inspect page on Chrome revealed an error message indicating cross-origin request limitations. We are now implementing CORS on the Server-Side to resolve this issue. Stay tuned for updates!