尝试与soap客户端通信时出现意外的元素错误

ffvjumwh  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(242)

我正在尝试使用可在此链接上找到的wsdl客户端https://tim-erp.com/erpx_web/awws/erpx.awws?wsdl
我的java代码如下

public class SoapServicesImpl extends WebServiceGatewaySupport implements SoapServices {

    @Override
    public String doAuth(AuthDto authDto){
        AuthStrct authStrct = new AuthStrct();
        authStrct.setFirmaNaziv(authDto.getNazivFirme());
        authStrct.setGodina(authDto.getGodina());
        authStrct.setPassword(authDto.getPassword());
        authStrct.setUsername(authDto.getUsername());
        return callService(new ObjectFactory().createAuthStrct(authStrct));
    }

    @SuppressWarnings("unchecked")
    public <T> T callService(JAXBElement<?> jaxbRequest) {
        jaxbRequest.getValue();
        JAXBElement<T> jaxbResponse;
        try {
            jaxbResponse = (JAXBElement<T>) getWebServiceTemplate().marshalSendAndReceive(jaxbRequest);
        } catch (WebServiceException e) {
            e.printStackTrace();
            throw e;
        }
        return jaxbResponse.getValue();
    }

}

包裹信息如下

@javax.xml.bind.annotation.XmlSchema(namespace = "urn:ErpX")
package rs.sweetchoice.commonservice.generated;

生成的objectfactory代码段:

//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.0 
// See <a href="https://javaee.github.io/jaxb-v2/">https://javaee.github.io/jaxb-v2/</a> 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2020.09.05 at 01:28:42 PM CEST 
//

package rs.sweetchoice.commonservice.generated;

import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.namespace.QName;

/**
 * This object contains factory methods for each 
 * Java content interface and Java element interface 
 * generated in the rs.sweetchoice.commonservice.generated package. 
 * <p>An ObjectFactory allows you to programatically 
 * construct new instances of the Java representation 
 * for XML content. The Java representation of XML 
 * content can consist of schema derived interfaces 
 * and classes representing the binding of schema 
 * type definitions, element declarations and model 
 * groups.  Factory methods for each of these are 
 * provided in this class.
 * 
 */
@XmlRegistry
public class ObjectFactory {

    private final static QName _WSID_QNAME = new QName("urn:ErpX", "WSID");
    private final static QName _AUTH_QNAME = new QName("urn:ErpX", "authStrct");

    /**
     * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: rs.sweetchoice.commonservice.generated
     * 
     */
    public ObjectFactory() {
    }

    /**
     * Create an instance of {@link AutoCompleteStrct }
     * 
     */
    public AutoCompleteStrct createAutoCompleteStrct() {
        return new AutoCompleteStrct();
    }

    /**
     * Create an instance of {@link KorpaStrct }
     * 
     */
    public KorpaStrct createKorpaStrct() {
        return new KorpaStrct();
    }

    /**
     * Create an instance of {@link CmbStrct }
     * 
     */
    public CmbStrct createCmbStrct() {
        return new CmbStrct();
    }

    /**
     * Create an instance of {@link AuthStrct }
     * 
     */
    @XmlElementDecl(namespace = "urn:ErpX", name = "authStrct")
    public JAXBElement<AuthStrct> createAuthStrct(AuthStrct value) {
        return new JAXBElement<>(_AUTH_QNAME, AuthStrct.class, null, value);
    }

    /**
     * Create an instance of {@link FilterStrct }
     * 
     */
    public FilterStrct createFilterStrct() {
        return new FilterStrct();
    }

    /**
     * Create an instance of {@link ProfakStavStrct }
     * 
     */
    public ProfakStavStrct createProfakStavStrct() {
        return new ProfakStavStrct();
    }

    /**
     * Create an instance of {@link ProfakStrct }
     * 
     */
    public ProfakStrct createProfakStrct() {
        return new ProfakStrct();
    }

    /**
     * Create an instance of {@link RacunStavStrct }
     * 
     */
    public RacunStavStrct createRacunStavStrct() {
        return new RacunStavStrct();
    }

    /**
     * Create an instance of {@link RacunStrct }
     * 
     */
    public RacunStrct createRacunStrct() {
        return new RacunStrct();
    }

    /**
     * Create an instance of {@link UplKomitStrct }
     * 
     */
    public UplKomitStrct createUplKomitStrct() {
        return new UplKomitStrct();
    }

    /**
     * Create an instance of {@link UplListaStavStrct }
     * 
     */
    public UplListaStavStrct createUplListaStavStrct() {
        return new UplListaStavStrct();
    }

    /**
     * Create an instance of {@link UplListaStrct }
     * 
     */
    public UplListaStrct createUplListaStrct() {
        return new UplListaStrct();
    }

    /**
     * Create an instance of {@link WsGetRoba }
     * 
     */
    public WsGetRoba createWsGetRoba() {
        return new WsGetRoba();
    }

    /**
     * Create an instance of {@link WsGetKomit }
     * 
     */
    public WsGetKomit createWsGetKomit() {
        return new WsGetKomit();
    }

    /**
     * Create an instance of {@link WsGetGrpRoba }
     * 
     */
    public WsGetGrpRoba createWsGetGrpRoba() {
        return new WsGetGrpRoba();
    }

    /**
     * Create an instance of {@link WsGetGrpKomit }
     * 
     */
    public WsGetGrpKomit createWsGetGrpKomit() {
        return new WsGetGrpKomit();
    }

    /**
     * Create an instance of {@link WsGetManuf }
     * 
     */
    public WsGetManuf createWsGetManuf() {
        return new WsGetManuf();
    }

    /**
     * Create an instance of {@link WsUplProfak }
     * 
     */
    public WsUplProfak createWsUplProfak() {
        return new WsUplProfak();
    }

    /**
     * Create an instance of {@link WsGetMagacin }
     * 
     */
    public WsGetMagacin createWsGetMagacin() {
        return new WsGetMagacin();
    }

    /**
     * Create an instance of {@link WsGetAkcijskeCene }
     * 
     */
    public WsGetAkcijskeCene createWsGetAkcijskeCene() {
        return new WsGetAkcijskeCene();
    }

    /**
     * Create an instance of {@link WsUplKomit }
     * 
     */
    public WsUplKomit createWsUplKomit() {
        return new WsUplKomit();
    }

    /**
     * Create an instance of {@link WsUplKomitResponse }
     * 
     */
    public WsUplKomitResponse createWsUplKomitResponse() {
        return new WsUplKomitResponse();
    }

    /**
     * Create an instance of {@link WsUplRacun }
     * 
     */
    public WsUplRacun createWsUplRacun() {
        return new WsUplRacun();
    }

    /**
     * Create an instance of {@link JAXBElement }{@code <}{@link byte[]}{@code >}
     * 
     * @param value
     *     Java instance representing xml element's value.
     * @return
     *     the new instance of {@link JAXBElement }{@code <}{@link byte[]}{@code >}
     */
    @XmlElementDecl(namespace = "urn:ErpX", name = "WSID")
    @XmlJavaTypeAdapter(HexBinaryAdapter.class)
    public JAXBElement<byte[]> createWSID(byte[] value) {
        return new JAXBElement<byte[]>(_WSID_QNAME, byte[].class, null, ((byte[]) value));
    }

}

我得到一个错误
javax.xml.bind.unmarshalexception:意外元素(uri:)http://schemas.xmlsoap.org/soap/envelope/,局部:“故障”)。预期元素为<{urn:erpx}wsid><{urn:erpx}authstrct>
使用Java11和SpringBoot2.3.3。
编辑这是我的配置类

@Configuration
public class WsConfig {
    @Bean
    public Jaxb2Marshaller marshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setContextPath("rs.sweetchoice.commonservice.generated");
        return marshaller;
    }
    @Bean
    public SoapServicesImpl soapServicesImpl(Jaxb2Marshaller marshaller) {
        SoapServicesImpl client = new SoapServicesImpl();
        client.setDefaultUri("https://tim-erp.com/ERPX_WEB/awws/ErpX.awws");
        client.setMarshaller(marshaller);
        client.setUnmarshaller(marshaller);
        return client;
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题