user3671807
user3671807

Reputation: 33

Consume SOAP service using Quarkus

My project requirement is to consume a SOAP service and I am trying to use Quarkus for this purpose. What are the quarkus dependecies hwould I use to acheive this? Is there any sample application I can refer to?

In Spring we can use org.springframework.ws.client.core.support.WebServiceGatewaySupport is there anything similiar in Quarkus.

Upvotes: 2

Views: 11062

Answers (3)

olivier dufour
olivier dufour

Reputation: 332

we have a new version on https://github.com/quarkiverse/quarkiverse-cxf that you can used for native. It is in beta and can be reference with maven central.

Upvotes: 3

Marcin Dąbrowski
Marcin Dąbrowski

Reputation: 61

It can be done like @loicmathieu said. In our realization we have Controller :

@Slf4j
@Path("/xxx")
public class EKWReactiveResource {

@Inject
RequestObject2WsdlRequestObjectConverter converter;

@POST
@Path("/xxxx")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_XML)
public Uni<Response<XsdResponseObject>> wyszukajKsiege(RequestObject request) {
    return Uni.createFrom().item(request)
            .onItem()
            .invoke( req -> log.info(req.toString()))
            .map(converter::convert)
            .onItem()
            .apply(ServiceClient::send);
 }

}

ServiceClient :

@Slf4j
public final class ServiceClient {

private final static String ENDPOINT_HTTP = "XXXX";
private final static QName SERVICE_QNAME = new QName("XXXX", "XXXX");
private final static QName SERVICE_QNAME2 = new QName("XXXX", "XXXX");

private static XXXPortType portType;

static {
    try {
        URL endpointUrl = new URL(ENDPOINT_HTTP);
        XXXService service = new XXXService(endpointUrl ,SERVICE_QNAME);
        portType = service.getPort(SERVICE_QNAME2, XXXPortType.class);
    } catch (MalformedURLException e) {
        log.error(e.getMessage(), e);
    }
}

public static Response<XsdResponseObject> send(RequestObject  requestType) {
    return portType.EndpointAsync(requestType);
 }

}

And after this we must define ResponseMessageBodyWriter for AsyncResponseImpl> because for some reason it is unknown. MessageBodyWriter example - you should better write isWriteable method i just dont do this perfectly because this is example only :

@Slf4j
@Provider
@Produces(MediaType.APPLICATION_XML)
public class XXXMessageBodyWriter implements MessageBodyWriter<AsyncResponseImpl<XsdResponseObject>> {
@Override
public boolean isWriteable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
    return AsyncResponseImpl.class.isAssignableFrom(aClass);
}

@Override
public void writeTo(AsyncResponseImpl<XsdResponseObject> asyncResponse, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> multivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException {
    try {
        XsdResponseObject responseObject = asyncResponse.get();
        String marshalled = JAXBUtils.marshallToSOAP(responseObject);
        log.info(String.format("Response : %s",marshalled));
        outputStream.write(marshalled.getBytes());
    } catch (InterruptedException | ExecutionException | JAXBException | ParserConfigurationException | SOAPException e) {
        log.error(e.getMessage(),e);
    }
  }
}

Upvotes: 0

loicmathieu
loicmathieu

Reputation: 5562

There is no SOAP client extension at the moment in Quarkus.

There is some discussion to include a CXF extension here : https://github.com/quarkusio/quarkus/issues/4005, you can join the discussion.

A PR is open (not yet finished) for SOAP WS support via CXF but not for SOAP client: https://github.com/quarkusio/quarkus/pull/5538

If you didn't plan to deploy to GraalVM (Quarkus can be deployed both in standard JVM mode and on GraalVM/SubstrateVM as a native application) you can still use any Java library with Quarkus but you will not have any integration with Quarkus itself. So using the CXF Client should works fine in JVM mode : https://cxf.apache.org/docs/how-do-i-develop-a-client.html

Upvotes: 5

Related Questions