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

问题描述

我正在尝试使用可在此链接https://tim-erp.com/ERPX_WEB/awws/ErpX.awws?wsdl上找到的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();
    }

}

package-info看起来像这样

@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,((byte[]) value));
    }

}

我得到错误

javax.xml.bind.UnmarshalException:意外元素(uri:“ http://schemas.xmlsoap.org/soap/envelope/”,本地:“ Fault”)。期望的元素是,

使用Java 11和Spring Boot 2.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;
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...