Background
I have two services. Service A is exposed to the outside world and Service B is invoked by Service A. All of these services are dropwizard services. The feature I am trying to implement is to upload a file from frontend which is uploaded to Service A which handles auth. The same request as is should be transferred to Service B. Service B should get the file and save it to disk after compression and thumbnail creation.
I have tested both the services individually using postman and they are able to receive the file as InputStream and the content disposition.
Problem
The problem I am facing is when I want to pass the file in the formData from Service A to Service B.
Here is the code in Service A that sends the form data to Service B.
@POST
@Timed
@Consumes(MediaType.MULTIPART_FORM_DATA)
fun create(
@Auth user: AuthUser,
@FormDataParam("file") file: InputStream,
@FormDataParam("file") fileDetail: FormDataContentDisposition,
@FormDataParam("file") body: FormDataBodyPart,
@PathParam("res_id") articleId: String): Response {
val multiPart = FormDataMultiPart()
multiPart.bodyPart(body)
val target = this.client.target("http://localhost:8082/file/create?res_id=1")
val response = target.request().post(Entity.entity(multiPart, multiPart.mediaType), Response::class.java)
Response.status(response.status).entity(response.entity).build()
}
Here is the code in Service B that receives it.
@POST
@Path("/create")
@Consumes(MediaType.MULTIPART_FORM_DATA)
fun create(
@FormDataParam("file") file: InputStream,
@FormDataParam("file") fileDetail: FormDataContentDisposition,
@QueryParam("res_id") resId: String): Response {
resourceLogger.info("Res id in media create $resId")
upload_file(file, fileDetail)
return Response.status(201).entity(mapOf("success" to true)).build()
}
The request is reaching Service A and is sent to Service B. But Service B is responding with 400. No logs or stack trace. Couldn't figure out what is going wrong. Any help would be appreciated.