I was having some problem when trying to send RESTful API from Angular to EJB. Here is my component.ts:
this.opUserAdminWinService.retrievePegRoleList().subscribe(resf => {
console.log(resf);
});
And my service.ts:
serviceAPI = SERVER_API_URL;
mainAPI = '/api/securityactivity/securityactivity';
retrievePegRoleList() {
const url: string = this.serviceAPI + this.mainAPI + '/RetrievePegRoleList';
return this.http.post(url, this.httpOptions);
}
In my Controller.java:
@PostMapping("/RetrievePegRoleList")
public Vector RetrievePegRoleList()
throws JaMClientRemoteException, JaMException {
return getSecurityActivity().RetrievePegRoleList();
}
In my EjbBean class:
public Vector RetrievePegRoleList() throws JaMClientRemoteException, JaMException;
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public Vector RetrievePegRoleList() throws JaMClientRemoteException, JaMException
{
Vector pegRoleList;
try {
String dataSource = JaM.getProperties().ORD_DATA_SOURCE;
RetrievePegRoleListTask retrievePegRoleListTask = new RetrievePegRoleListTask(dataSource);
retrievePegRoleListTask.execute();
pegRoleList = retrievePegRoleListTask.getResult();
} catch (Exception e) {
throw new JaMClientRemoteException(this.ERR_EXCEPTION_JAM, e.toString());
}
return pegRoleList;
}
However, I am getting this error message:
Any ideas why is it so? Thanks!
try this in angular.
export const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
this.http.post(your-url,your-data, httpOptions);
I always send post like this in angular. If it doesn't work. You should examine,is there an interceptor in Server.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.