如何解决quarkus反应性端点中的“无法执行选项”?

时间:2019-10-15 10:54:16

标签: resteasy quarkus

我正在使用Quarkus 0.24.0和以下扩展程序开发API:[cdi,reactive-pg-client,rest-client,resteasy,resteasy-jackson,security,vertx]

这是我实施的路线之一:

@Path("/users")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class UsersResource {

    @Inject
    KeycloakUsersService keycloakUsersService;

    @GET
    @RolesAllowed({"ADMIN"})
    public CompletionStage<Response> getUsers(@QueryParam("search") String searchQuery) {
        return keycloakUsersService.getUsers(searchQuery)
                .thenApply(Response::ok)
                .thenApply(Response.ResponseBuilder::build)
                 .exceptionally(throwable -> {
                    logger.error("Wut ?" + throwable.getMessage());
                    return Response.status(500).entity("Something wrong happened while retrieving users from Keycloak : " + throwable.getCause()).build();
                });
    }
}

一切都运行顺利,直到我开始使用Angular使用API​​。在进行API调用之前,有一个OPTIONS请求,该请求失败:

 Failed executing OPTIONS /users: org.jboss.resteasy.spi.DefaultOptionsMethodException: RESTEASY003655: No resource method found for options, return OK with Allow header

我尝试在application.properties中添加以下内容,但没有成功:

quarkus.http.cors.origins=http://localhost:4200,http://localhost:8080
quarkus.http.cors.headers=accept, authorization, content-type, x-requested-with
quarkus.http.cors.methods=GET, OPTIONS, POST

如何解决OPTIONS请求?是否可以全局处理OPTIONS请求?

1 个答案:

答案 0 :(得分:0)

这似乎是CORS问题。你尝试过吗?

#include <iostream>

using namespace std;

void reorder(int arr[], int index[], int n)
{
    int temp[n];

    for (int i = 0; i < n; i++)
        temp[index[i]] = arr[i];

    for (int i = 0; i < n; i++) {
        arr[i] = temp[i];
        index[i] = i;
    }
}

int main()
{
    int arr[] = { 3, 2, 1, 5, 6, 4 };
    int arb[] = { 5, 6, 1, 3, 2, 4 };
    int index[] = { 3, 4, 2, 0, 1, 5 };

    int n = sizeof(arr) / sizeof(arr[0]);
    cout << "\nSequence array is: \n";
    for (int i = 0; i < n; i++)
        std::cout << index[i] << ' ';
    cout << "\nOriginal array is: \n";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    printf("\n");

    reorder(arr, index, n);
    reorder(arb, index, n);

    cout << "Reordered array is: \n";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";

    printf("\n");

    printf("\n");

    return 0;
}