我正在使用 Quarkus 为我的休息微服务实现一个 API 网关。我想将请求转发到另一个(Quarkus)rest-api。我正在尝试使用多格式数据转发 POST 请求。我期望得到 201,但我得到 500 内部服务器错误。RESTEASY 抛出以下错误:
RESTEASY002020: Unhandled asynchronous exception, sending back 500: javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request: javax.ws.rs.ProcessingException: RESTEASY003215: could not find writer for content-type multipart/form-data type: org.acme.rest.client.multipart.MultipartBody
我尝试将我的 Quarkus 版本从 1.4.2 升级到 1.5.2,因为我看到了以下问题: https ://github.com/quarkusio/quarkus/issues/8223
还尝试过 Intellij 无效缓存/重启,重新导入 maven
代码
多部分体:
package org.acme.rest.client.multipart;
import org.jboss.resteasy.annotations.providers.multipart.PartType;
import javax.ws.rs.FormParam;
import javax.ws.rs.core.MediaType;
public class MultipartBody {
@FormParam("sample_id")
@PartType(MediaType.TEXT_PLAIN)
public Long sampleId;
@FormParam("username")
@PartType(MediaType.TEXT_PLAIN)
public String username;
@FormParam("content")
@PartType(MediaType.TEXT_PLAIN)
public String content;
}
界面:
package org.acme.rest.client;
import io.smallrye.mutiny.Uni;
import org.acme.rest.client.multipart.MultipartBody;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import org.jboss.resteasy.annotations.providers.multipart.MultipartForm;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@RegisterRestClient
@Consumes(MediaType.MULTIPART_FORM_DATA)
public interface SocialService {
@POST
Uni<Response> create(@MultipartForm MultipartBody data);
}
资源:
package org.acme.rest.client;
import io.smallrye.mutiny.Uni;
import org.acme.rest.client.multipart.MultipartBody;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.jboss.resteasy.annotations.providers.multipart.MultipartForm;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/comments")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public class SocialResource {
@Inject
@RestClient
SocialService socialService;
@POST
public Uni<Response> create(@MultipartForm MultipartBody data) {
return socialService.create(data);
}
}
测试:
package org.acme.rest.client;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
@QuarkusTest
public class SocialResourceTest {
@Test
public void create(){
given().contentType("multipart/form-data")
.multiPart("sample_id", "1")
.multiPart("username", "testuser")
.multiPart("content", "test message")
.when()
.post("/comments")
.then()
.statusCode(201);
}
}