I am trying to connect to a third-party API from quarkus controller . I have a controller using the method of service.
Controller
package com.ncr.invoice;
// all imports over here
@Path("/api")
@RequestScoped
public class InvoiceController {
// all variable and injection
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/invoice")
@Timeout(250)
@PermitAll
public Response getInvoice(AuthTokenRequestModel atrm){
SoupResponseInvoiceDetail srid = null;
try{
srid = service.getInvoice(
atrm.getMcn(),"transactionId", atrm.getInvoiceNumber()
);
LOG.info("try block end");
}
catch(InterruptedException e)
{
LOG.info("Over here");
return Response.status(401).build();
}
return Response.ok(srid).build();
}
return Response.status(401).build();
}
// all getter setter
}
service
@Path("/")
@RegisterRestClient(configKey="invoice-api")
public interface InvoiceService {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/")
public SoupResponseInvoiceDetail getInvoice(@QueryParam("id") String id,@QueryParam("txn_id") String txnId, @QueryParam("invoice") String invoice) throws InterruptedException;
}
How to return the HTTP status code from service to controller?
I need to look into the response body when http status is 500
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…