1

I tried to make a SOAP call from spring reactive webclient.

the ConfirmPayer10, ConfirmPayer10Response and ObjectFactory classes i generated from wsdl file by the maven-jaxb2-plugin plugin.

for the encoder and decoder config, i get the same from here and here

    ConfirmPayer10 confirmPayer10 = new ConfirmPayer10();
    confirmPayer10.setArg0(confirmPayerRq);
    final JAXBElement<ConfirmPayer10> jAXBElement = new ObjectFactory().createConfirmPayer10(confirmPayer10);

    webClient.post().uri( url )
        .contentType(MediaType.TEXT_XML)
        .body( Mono.just(jAXBElement) , new ParameterizedTypeReference<JAXBElement<ConfirmPayer10>>() {})
        .retrieve()
        .onStatus(
            HttpStatus::isError,
            clientResponse ->
                clientResponse
                    .bodyToMono(String.class)
                    .flatMap(
                        errorResponseBody ->
                            Mono.error(
                                new ResponseStatusException(
                                    clientResponse.statusCode(),
                                    errorResponseBody))))

        .bodyToMono(new ParameterizedTypeReference<JAXBElement<ConfirmPayer10Response>>() {})
        .doOnSuccess( (res) -> {
            System.out.println("success");
            System.out.println("capital : " + res.getValue().getReturn().getRqUID());
        })
        .doOnError(ResponseStatusException.class, error -> {
            System.out.println( "error : "+ error );
        })
        .doOnError(Exception.class, ( Exception error ) -> {
            System.out.println( "error : "+ error );
            error.printStackTrace();
        }).subscribe();

the problem is that i have this error

org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'text/xml' not supported for bodyType=javax.xml.bind.JAXBElement< ConfirmPayer10 >

Aymen Kanzari
  • 1,765
  • 7
  • 41
  • 73
  • if you say "SOAP"...where is the "envelope"? https://medium.com/@EBingolIT/calling-soap-services-with-webclient-springboot-1b5e0df044cc – xerx593 Oct 07 '22 at 15:26
  • But regarding original exception message: try `application/xml` , get rid of `JAXBContext`, just try `XYZ` ...but when fixed (on client side), you need to conform with endpoint (server) – xerx593 Oct 07 '22 at 15:29
  • @xerx593 when i tried the call using web-services it work fine, https://github.com/akanzari/MongoAutoConfig/blob/main/test – Aymen Kanzari Oct 07 '22 at 17:25

0 Answers0