Angular 2 Issue with http.get Request to Restful Webservice
When I try jsontest.com, I receive the value properly.
getCurrentTime()
{
//return this.http.get('http://date.jsontest.com')
return this.http.get('http://localhost:8080/webserviceangular2/services/updateUserRecords/')
.map(res=>res.json());
}
Another Component.ts Page
import {Component} from 'angular2/core';
import {FormExample} from "./angular-typescript-form.component";
import {Jsonp, URLSearchParams} from 'angular2/http';
@Component({
selector: 'my-app',
template: `<angular-typescript-form>loading...</angular-typescript-form> <br>
<p>{{postData}}</p>
<button (click)="OnTestGet()">Test_get_request</button>
<p>{{getData |json}}</p>
`,
directives: [FormExample],
providers: [FormExample,JSONP_PROVIDERS]
})
export class FormComponent {
constructor(private httpservice: FormExample){}
getData: string;
OnTestPost(){
this.httpservice.postJSON()
}
OnTestGet()
{
this.httpservice.getCurrentTime()
.subscribe(
data=>console.log(this.getData=data),
error=>console.log(JSON.stringify(error)),
()=> console.log("finished"));
}
}
Java Code Snippet
@Path("/updateManager")
public class UpdateManager {
@GET
@Produces("text/plain")
@Consumes("text/plain")
//@Produces("application/json")
//@Consumes("application/json")
@Path("/updateUserRecords/")
public Response updateUserRecords(){
try {
dbConnection = getDBConnection();
System.out.println("connected is created "+dbConnection);
myStatement = dbConnection.prepareStatement("select * from account");
System.out.println(myStatement);
rs = myStatement.executeQuery();
while (rs.next()) {
data=rs.getString(3);
}
ResponseBuilder rb=Response.status(200);
rb.cacheControl(cc);
rb.entity(data);
response=rb.build();
}catch (Exception e) {
System.out.println(e);
}
return response;
}
I am able to retrieve payload value in Java Restful Webservice but encountering errors on the client-side. Can anyone assist me?