Consuming a SOAP web service error (No marshaller registered. Check configuration of WebServiceTemplate)

16,197

In this case I cant instanciate a new object in the Controller like i've done:

ProcuraPMPorREClient pm = new ProcuraPMPorREClient();

Instead of this, I need to create a @Autowired object, like this:

@Autowired ProcuraPMPorREClient pm;

After, I only call the same routines:

ProcuraPMPorREResponse response = pm.getPMPorRE(123456); 
System.out.println(response.getProcuraPMPorREResult().getNomePM());

This worked fine.

Share:
16,197
Murilo Góes de Almeida
Author by

Murilo Góes de Almeida

I'm a full stack developer from Brazil, very passionate about new technologies

Updated on June 25, 2022

Comments

  • Murilo Góes de Almeida
    Murilo Góes de Almeida almost 2 years

    I've followed the Getting Started - Consuming a SOAP web service (https://spring.io/guides/gs/consuming-web-service/) to consume a specific web service and everything works well:

    I've made the configuration class:

    @Configuration
    public class PMConfiguration {
        @Bean
        public Jaxb2Marshaller marshaller() {
            Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
            // this package must match the package in the <generatePackage> specified in
            // pom.xml
            marshaller.setContextPath("com.inteligenciaweb.wsdl");
            return marshaller;
        }
    
        @Bean
        public ProcuraPMPorREClient procuraPMPorREClient(Jaxb2Marshaller marshaller) {
            ProcuraPMPorREClient client = new ProcuraPMPorREClient();
            client.setDefaultUri("http://tempuri.org/procuraPMPorRE");
            client.setMarshaller(marshaller);
            client.setUnmarshaller(marshaller);
            return client;
        } 
    

    }

    Client:

    public class ProcuraPMPorREClient extends WebServiceGatewaySupport {
    
        private static final Logger log = LoggerFactory.getLogger(ProcuraPMPorRE.class);
    
    
        public ProcuraPMPorREResponse getPMPorRE(Integer RE) {
    
            ProcuraPMPorRE request = new ProcuraPMPorRE();
            request.setPMRENum(RE);
    
            log.info("Requesting PM for " + RE);
    
            ProcuraPMPorREResponse response = (ProcuraPMPorREResponse) getWebServiceTemplate()
                    .marshalSendAndReceive("http://webservices.externo.policiamilitar.sp.gov.br:8071/router/wsscpm/basic",
                            request,
                            new SoapActionCallback("http://tempuri.org/procuraPMPorRE"));
    
            return response;
        }
    
    }
    

    At the class Application:

    @SpringBootApplication
    public class InteligenciawebApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(InteligenciawebApplication.class, args);
        }
    
        @Bean
        CommandLineRunner lookup(ProcuraPMPorREClient pm) {
            return args -> {
                Integer re = 123456;        
                ProcuraPMPorREResponse response = pm.getPMPorRE(re); 
                System.err.println(response.getProcuraPMPorREResult().getNomeBancoPM());
            };
        }
    }
    

    When I start a application, the weservice calling works fine, so I can see the result at the console. I've tried to use the same logic to call this web service in other class, but isn't working. For instance, I've made a test at the Controller Class:

    @RequestMapping(value = "/soap", method = RequestMethod.GET)
    public String testeSoap() {
        ProcuraPMPorREClient pm = new ProcuraPMPorREClient();
        ProcuraPMPorREResponse response = pm.getPMPorRE(123456); 
        System.out.println(response.getProcuraPMPorREResult().getNomePM());
      return null;
    }
    

    In this case, the webservice doesn't work and the system show this error message: java.lang.IllegalStateException: No marshaller registered. Check configuration of WebServiceTemplate. I don't know why, but the webservice works in a specific place and doesn't work in the other. If someone knows what happen, I apreciate! Thanks!