Получение [javax.xml.bind.JAXBException: «com.mta.example» не содержит ObjectFactory.class или jaxb.index] - PullRequest
0 голосов
/ 07 февраля 2019

Я пытаюсь использовать веб-сервис Soap в моем приложении Springboot.Я получаю ошибку [javax.xml.bind.JAXBException: «com.mta.example» не содержит ObjectFactory.class или jaxb.index] в моем коде.Я не уверен, какая конфигурация здесь неправильная.какое должно быть значение contextPath?Это относится к какому-либо пакету или должно соответствовать какому-то элементу из WSDL?Извините, я не слишком знаком с веб-сервисами SOAP.

Spring boot Основной класс, как показано ниже.

package com.mta;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages = {"com.mta"})
public class MTApplication {
public static void main(String[] args) {
    SpringApplication.run(MTApplication.class, args);
    LoginClient logClient = new LoginClient();
    logClient.getLoginDetails();
}
}

Класс конфигурации Soap, как показано ниже

package com.mta;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;

@Configuration
public class SoapConfiguration {

    @Bean
    public Jaxb2Marshaller marshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setContextPath("com.mta.example");
        return marshaller;
    }

    @Bean
    public SoapConnector soapConnector(Jaxb2Marshaller marshaller) {
        SoapConnector client = new SoapConnector();
        client.setDefaultUri("https://test.platform.ws");
        client.setMarshaller(marshaller);
        client.setUnmarshaller(marshaller);
        return client;
    }

}

Класс SoapConnector дляПозвоните в веб-службу

package com.mta;

import org.springframework.ws.client.core.support.WebServiceGatewaySupport;

public class SoapConnector extends WebServiceGatewaySupport {

    public Object callWebService(String url, Object request) {
        // CREDENTIALS and REQUEST SETTINGS...
        return getWebServiceTemplate().marshalSendAndReceive(url, request);
    }
}

Клиентский класс

public class LoginClient extends WebServiceGatewaySupport{
     @Autowired
        SoapConnector soapConnector;
    private static final Logger log = LoggerFactory.getLogger(LoginClient.class);

    public LoginResponse getLoginDetails() {
        LoginRequest request = new LoginRequest();
        request.setUserId("mtatest");
        request.setPassword("test");

        LoginResponse response = (LoginResponse) soapConnector.callWebService("http://www.mta.com/gp/Login", request);
        System.out.println(response.getOpCode());
        return response;

    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...