I need help with communication between a JHipster scaffolded Angular frontend plus Springboot backend. I would like to use the backend's API in sort of doing a request to a Kafka Webflux method, which will continuously fire events to the consumer of the API.
Therefore I wrote this piece of code into a new mqconnect.service.ts
class.
Injectable({
providedIn: 'root',
})
export class MqconnectService {
url: string = KAFKA_CONSUME_MSG; // contains part of URL : /api/someurl/
constructor() { this; }
getMessagesStream(): Observable<StandardMessage> {
return new Observable<StandardMessage>(observer => {
const url = this.url;
const eventSource = new EventSource(url, {withCredentials: true});
eventSource.onmessage = event => {
// eslint-disable-next-line no-console
console.debug('received event: ', event);
const json = JSON.parse(event.data);
observer.next(
new StandardMessage(
json['Id'],
// OMITTED
)
);
};
eventSource.onerror = error => {
if (eventSource.readyState === 0) {
// eslint-disable-next-line no-console
console.log('The stream has been closed by the server.');
eventSource.close();
observer.complete();
} else {
observer.error('EventSource error: ' + `${String(error)}`);
}
};
});
}
}
When I read the logs from Firefox's Developer Console, I will receive always a 401. The Bearer token is not being sent, when doing the request. I wondered, if it has something to do with some interceptor stuff, so I tried to 'get' the token from the Angular Framework.
EDIT: removed useless interceptor.
This will not solve my problem. What's the right way, because IMHO it's a DI Framework and it makes absolutely no sense to create a dangling http.client to make a GET request to the Spring backend.