I created a microservice using MSF4J and tested the resources with postman all works fine but when I use it with a Angular 5 client app; the browser sends an additional http OPTIONS request to check CORS I get a "405 Method Not Allowed" Response. Can anybody help on this?
Asked
Active
Viewed 117 times
3 Answers
0
MSF4J doesn't have CORS support. You can add OPTION
to your resource methods if you want to handle CORS requests

Thusitha Thilina Dayaratne
- 5,666
- 4
- 42
- 69
0
I had the same problem and I used a firefox plugin called CORS Everywhere just for development purposes but when it went to production I had to pass the requests through an ESB that has the following property in the insequence
<property name="Access-Control-Allow-Origin" scope="transport" type="STRING" value="*"/>
That fixed the problem. I still don't know if it's possible to enable CORS on the microservice itself

Piaget Hadzizi
- 702
- 8
- 15
0
You'll have to implement an OPTIONS method. Here is an example I used in an old project:
@GET
@Path("device")
@Produces({ "application/json" })
@RequestInterceptor(DeviceBasicAuthInterceptor.class)
public Response deviceGet() throws NotFoundException {
//...
return result;
}
@OPTIONS
@Path("device")
public Response deviceOptions() throws NotFoundException {
String allowedOrigin = null;
try {
allowedOrigin = PropertyFileHandler.getInstance().getPropertyValueFromKey("api.cors.allowed");
} catch (IllegalArgumentException | PropertyException | IOException e) {
LOGGER.error("Could not get allowed origin.", e);
}
Response response = Response.ok().header("Allow", "GET").header("Access-Control-Allow-Origin", allowedOrigin)
.header("Access-Control-Allow-Headers", "authorization, content-type").build();
return response;
}

JWo
- 650
- 1
- 6
- 23