0

I have Jersey Rest service, which works fine from browser, but when I call it with angular http.get I got 405 "Method Not Allowed". Both server and client run in the same tomcat8

I've tried to add CORS headers "Access-Control-Allow-Origin", "Access-Control-Allow-Methods", no luck.

I added custom @WebFilter and found Additional filter Tomcat Websocket Filter in FilterChain which I suppose is responsible for this error. But I have no idea how to configure or get rid of it.

My web.xml is blank.

Service

@GET
    @Path("/findalljson")
    @Produces(MediaType.APPLICATION_JSON)
    public String findAll_JSON(@QueryParam("begin") String sdate, @QueryParam("end") String edate)
{}

Error

e {headers: t, status: 405, statusText: "Method Not Allowed", url: "http://localhost:8080/ConfCallService/api/conference/findaljson", ok: false, …}
error: "<!DOCTYPE html><html><head><title>Apache Tomcat/8.0.24 - Error report</title><style type="text/css">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}</style> </head><body><h1>HTTP Status 405 - Method Not Allowed</h1><div class="line"></div><p><b>type</b> Status report</p><p><b>message</b> <u>Method Not Allowed</u></p><p><b>description</b> <u>The specified HTTP method is not allowed for the requested resource.</u></p><hr class="line"><h3>Apache Tomcat/8.0.24</h3></body></html>"
headers: t {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
message: "Http failure response for http://localhost:8080/ConfCallService/api/conference/findaljson: 405 Method Not Allowed"
name: "HttpErrorResponse"
ok: false
status: 405
statusText: "Method Not Allowed"
url: "http://localhost:8080/ConfCallService/api/conference/findaljson"
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • `method not allowed` looks like the endpoint you are calling doesnt exist. going by what you have posted, your endpoint is `findalljson` but you call `findaljson` – mast3rd3mon Apr 16 '19 at 13:47
  • @ mast3rd3mon Thanks mate, error description was totally awful ( – Mikhail Ivanov Apr 16 '19 at 15:21
  • no problem, this is not off topic however due to a typo, it will probably get closed as a result – mast3rd3mon Apr 16 '19 at 15:22
  • It's most likely a [CORS preflight](https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request) request, which is an OPTIONS request. That's why it's returning a 405, because you have no OPTIONS implemented. You should implement a filter to handle CORS. Take a look at [this post](https://stackoverflow.com/q/28065963/2587435) – Paul Samsotha Apr 16 '19 at 22:25

0 Answers0