0

My client-side application(Front end) - Angular My server-side application(Back end) - Java JAX-RS (jersy)

I'm getting this error when I call a function from frontend to backend

My angular service code

import { User } from './../model/user';
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';

const headeroption = {
  headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};

@Injectable({
  providedIn: 'root'
})
export class UserService {

  constructor(private http: HttpClient) { }

  url = 'http://localhost:9090/HealthCare2/services/';

  user: Observable<User[]>;

  //Testing
  test() {
    return this.http.get(this.url + 'user/test');
  }

My Java JAX-RS Controller

@Path("/user")
public class UserController {

    UserService userService = new UserService();

    // Test function
    @GET
    @Path("/test")
    @Produces(MediaType.TEXT_HTML)
    public String testing() {

        return "Test Function is working";

    }
}
chamikamac
  • 25
  • 6
  • 2
    The Issue is with your API. You have to allow CORS. This is definetly a duplicate. Check out the related section of your question. – mamichels Apr 16 '20 at 10:26
  • I checked. but couldn't find any solution for a JAX-RS application. If you found something, please inform me. It will be a great help to me. Thanks – chamikamac Apr 16 '20 at 10:29
  • Does this answer your question? [How to enable Cross domain requests on JAX-RS web services?](https://stackoverflow.com/questions/23450494/how-to-enable-cross-domain-requests-on-jax-rs-web-services) – mamichels Apr 16 '20 at 10:30
  • Thank you. I tried this now and "ContainerRequestContext" is not importing to the project – chamikamac Apr 16 '20 at 11:14
  • I added a snapshot of the error. please check it - https://imgur.com/a/RxGunc7 – chamikamac Apr 16 '20 at 11:18

0 Answers0