使用Java和Axis 1.4的部分错误问题 [英] Problem with partial errors using Java and Axis 1.4

查看:135
本文介绍了使用Java和Axis 1.4的部分错误问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java并使用Axis 1.4生成的类访问BingAds API v9。 

I am using Java and accessing the BingAds API v9 with Axis 1.4 generated classes. 

我的问题是当我尝试添加关键字并收到错误时,无法反序列化响应。我认为这是因为响应中的id设置为null,并且在生成的java代码中,id声明为long [],即
数组中的元素不能为null。

My problem is that when I try to add keywords and I receive an error, the response cannot be deserialized. I think it is because the id in the response is set to null and in the generated java code the ids are declared as a long[], i.e the elements in the array cannot be null.

以下是SOAP请求和响应的示例:

Here is a sample SOAP request and response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Header>
    <ns1:DeveloperToken soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xsi:type="xsd:string" xmlns:ns1="https://bingads.microsoft.com/CampaignManagement/v9">*******
    </ns1:DeveloperToken>
    <ns2:AuthenticationToken soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xsi:type="xsd:string" xmlns:ns2="https://bingads.microsoft.com/CampaignManagement/v9">********
    </ns2:AuthenticationToken>
    <ns3:CustomerAccountId soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xsi:type="xsd:string" xmlns:ns3="https://bingads.microsoft.com/CampaignManagement/v9">2735886
    </ns3:CustomerAccountId>
    <ns4:CustomerId soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xsi:type="xsd:string" xmlns:ns4="https://bingads.microsoft.com/CampaignManagement/v9">17038669
    </ns4:CustomerId>
  </soapenv:Header>
  <soapenv:Body>
    <AddKeywords xmlns="">
      <ns5:AddKeywordsRequest xmlns:ns5="https://bingads.microsoft.com/CampaignManagement/v9">
        <AdGroupId xsi:type="xsd:long">941230074
        </AdGroupId>
        <Keywords soapenc:arrayType="ns5:Keyword[2]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
          <ns5:Keyword xsi:type="ns5:Keyword">
            <Bid xsi:type="ns5:Bid">
              <Amount xsi:type="xsd:double">3.0
              </Amount>
            </Bid>
            <DestinationUrl xsi:type="xsd:string">http://www.adtraction.com/t/t?a=545466444445&amp;as=50941721&amp;t=2&amp;tk=1&amp;epi=(7!{AdId}!{OrderItemId}!{MatchType})&amp;url=http://fyndiq.se/product/333093-halsband-oppningsbar-kula-med-klocka/
            </DestinationUrl>
            <EditorialStatus xsi:type="ns5:KeywordEditorialStatus" xsi:nil="true"/>
            <ForwardCompatibilityMap xsi:type="ns6:KeyValuePairOfstringstring" xsi:nil="true" xmlns:ns6="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
            <Id xsi:type="xsd:long" xsi:nil="true"/>
            <MatchType xsi:type="ns5:MatchType">Broad
            </MatchType>
            <Param1 xsi:type="xsd:string">149
            </Param1>
            <Param2 xsi:type="xsd:string">150
            </Param2>
            <Param3 xsi:type="xsd:string" xsi:nil="true"/>
            <Status xsi:type="ns5:KeywordStatus" xsi:nil="true"/>
            <Text xsi:type="xsd:string">+halsband +&#xF6;ppningsbar +kula +klocka
            </Text>
          </ns5:Keyword>
          <ns5:Keyword xsi:type="ns5:Keyword">
            <Bid xsi:type="ns5:Bid">
              <Amount xsi:type="xsd:double">1.5
              </Amount>
            </Bid>
            <DestinationUrl xsi:type="xsd:string">http://www.adtraction.com/t/t?a=545466444445&amp;as=50941721&amp;t=2&amp;tk=1&amp;epi=(7!{AdId}!{OrderItemId}!{MatchType})&amp;url=http://fyndiq.se/product/333093-halsband-oppningsbar-kula-med-klocka/
            </DestinationUrl>
            <EditorialStatus xsi:type="ns5:KeywordEditorialStatus" xsi:nil="true"/>
            <ForwardCompatibilityMap xsi:type="ns7:KeyValuePairOfstringstring" xsi:nil="true" xmlns:ns7="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
            <Id xsi:type="xsd:long" xsi:nil="true"/>
            <MatchType xsi:type="ns5:MatchType">Broad
            </MatchType>
            <Param1 xsi:type="xsd:string">149
            </Param1>
            <Param2 xsi:type="xsd:string">150
            </Param2>
            <Param3 xsi:type="xsd:string" xsi:nil="true"/>
            <Status xsi:type="ns5:KeywordStatus" xsi:nil="true"/>
            <Text xsi:type="xsd:string">+halsband +&#xF6;ppningsbar +kula
            </Text>
          </ns5:Keyword>
        </Keywords>
      </ns5:AddKeywordsRequest>
    </AddKeywords>
  </soapenv:Body>
</soapenv:Envelope>


<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <h:TrackingId xmlns:h="https://bingads.microsoft.com/CampaignManagement/v9">34538e38-9202-4611-bc69-f5a717219342
    </h:TrackingId>
  </s:Header>
  <s:Body>
    <AddKeywordsResponse xmlns="https://bingads.microsoft.com/CampaignManagement/v9">
      <KeywordIds xmlns:a="http://schemas.datacontract.org/2004/07/System" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:long i:nil="true"/>
        <a:long i:nil="true"/>
      </KeywordIds>
      <PartialErrors xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <BatchError>
          <Code>1542
          </Code>
          <Details i:nil="true"/>
          <ErrorCode>CampaignServiceKeywordAndMatchTypeCombinationAlreadyExists
          </ErrorCode>
          <Index>0
          </Index>
          <Message>A keyword with the specified match type already exists.
          </Message>
          <Type>BatchError
          </Type>
        </BatchError>
        <BatchError>
          <Code>1542
          </Code>
          <Details i:nil="true"/>
          <ErrorCode>CampaignServiceKeywordAndMatchTypeCombinationAlreadyExists
          </ErrorCode>
          <Index>1
          </Index>
          <Message>A keyword with the specified match type already exists.
          </Message>
          <Type>BatchError
          </Type>
        </BatchError>
      </PartialErrors>
    </AddKeywordsResponse>
  </s:Body>
</s:Envelope>

生成的AddKeywordsResponse类

The generated AddKeywordsResponse class

/**
 * AddKeywordsResponse.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.
 */

package com.microsoft.bingads.v9.campaignmanagement;

public class AddKeywordsResponse  implements java.io.Serializable {
    private long[] keywordIds;

    private com.microsoft.bingads.v9.campaignmanagement.BatchError[] partialErrors;

    public AddKeywordsResponse() {
    }

    public AddKeywordsResponse(
           long[] keywordIds,
           com.microsoft.bingads.v9.campaignmanagement.BatchError[] partialErrors) {
           this.keywordIds = keywordIds;
           this.partialErrors = partialErrors;
    }


    /**
     * Gets the keywordIds value for this AddKeywordsResponse.
     * 
     * @return keywordIds
     */
    public long[] getKeywordIds() {
        return keywordIds;
    }


    /**
     * Sets the keywordIds value for this AddKeywordsResponse.
     * 
     * @param keywordIds
     */
    public void setKeywordIds(long[] keywordIds) {
        this.keywordIds = keywordIds;
    }


    /**
     * Gets the partialErrors value for this AddKeywordsResponse.
     * 
     * @return partialErrors
     */
    public com.microsoft.bingads.v9.campaignmanagement.BatchError[] getPartialErrors() {
        return partialErrors;
    }


    /**
     * Sets the partialErrors value for this AddKeywordsResponse.
     * 
     * @param partialErrors
     */
    public void setPartialErrors(com.microsoft.bingads.v9.campaignmanagement.BatchError[] partialErrors) {
        this.partialErrors = partialErrors;
    }

    private java.lang.Object __equalsCalc = null;
    public synchronized boolean equals(java.lang.Object obj) {
        if (!(obj instanceof AddKeywordsResponse)) return false;
        AddKeywordsResponse other = (AddKeywordsResponse) obj;
        if (obj == null) return false;
        if (this == obj) return true;
        if (__equalsCalc != null) {
            return (__equalsCalc == obj);
        }
        __equalsCalc = obj;
        boolean _equals;
        _equals = true && 
            ((this.keywordIds==null && other.getKeywordIds()==null) || 
             (this.keywordIds!=null &&
              java.util.Arrays.equals(this.keywordIds, other.getKeywordIds()))) &&
            ((this.partialErrors==null && other.getPartialErrors()==null) || 
             (this.partialErrors!=null &&
              java.util.Arrays.equals(this.partialErrors, other.getPartialErrors())));
        __equalsCalc = null;
        return _equals;
    }

    private boolean __hashCodeCalc = false;
    public synchronized int hashCode() {
        if (__hashCodeCalc) {
            return 0;
        }
        __hashCodeCalc = true;
        int _hashCode = 1;
        if (getKeywordIds() != null) {
            for (int i=0;
                 i<java.lang.reflect.Array.getLength(getKeywordIds());
                 i++) {
                java.lang.Object obj = java.lang.reflect.Array.get(getKeywordIds(), i);
                if (obj != null &&
                    !obj.getClass().isArray()) {
                    _hashCode += obj.hashCode();
                }
            }
        }
        if (getPartialErrors() != null) {
            for (int i=0;
                 i<java.lang.reflect.Array.getLength(getPartialErrors());
                 i++) {
                java.lang.Object obj = java.lang.reflect.Array.get(getPartialErrors(), i);
                if (obj != null &&
                    !obj.getClass().isArray()) {
                    _hashCode += obj.hashCode();
                }
            }
        }
        __hashCodeCalc = false;
        return _hashCode;
    }

    // Type metadata
    private static org.apache.axis.description.TypeDesc typeDesc =
        new org.apache.axis.description.TypeDesc(AddKeywordsResponse.class, true);

    static {
        typeDesc.setXmlType(new javax.xml.namespace.QName("https://bingads.microsoft.com/CampaignManagement/v9", ">AddKeywordsResponse"));
        org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();
        elemField.setFieldName("keywordIds");
        elemField.setXmlName(new javax.xml.namespace.QName("https://bingads.microsoft.com/CampaignManagement/v9", "KeywordIds"));
        elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "long"));
        elemField.setMinOccurs(0);
        elemField.setNillable(true);
        elemField.setItemQName(new javax.xml.namespace.QName("http://schemas.datacontract.org/2004/07/System", "long"));
        typeDesc.addFieldDesc(elemField);
        elemField = new org.apache.axis.description.ElementDesc();
        elemField.setFieldName("partialErrors");
        elemField.setXmlName(new javax.xml.namespace.QName("https://bingads.microsoft.com/CampaignManagement/v9", "PartialErrors"));
        elemField.setXmlType(new javax.xml.namespace.QName("https://bingads.microsoft.com/CampaignManagement/v9", "BatchError"));
        elemField.setMinOccurs(0);
        elemField.setNillable(true);
        elemField.setItemQName(new javax.xml.namespace.QName("https://bingads.microsoft.com/CampaignManagement/v9", "BatchError"));
        typeDesc.addFieldDesc(elemField);
    }

    /**
     * Return type metadata object
     */
    public static org.apache.axis.description.TypeDesc getTypeDesc() {
        return typeDesc;
    }

    /**
     * Get Custom Serializer
     */
    public static org.apache.axis.encoding.Serializer getSerializer(
           java.lang.String mechType, 
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) {
        return 
          new  org.apache.axis.encoding.ser.BeanSerializer(
            _javaType, _xmlType, typeDesc);
    }

    /**
     * Get Custom Deserializer
     */
    public static org.apache.axis.encoding.Deserializer getDeserializer(
           java.lang.String mechType, 
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) {
        return 
          new  org.apache.axis.encoding.ser.BeanDeserializer(
            _javaType, _xmlType, typeDesc);
    }

}

我得到的错误:

java.lang.IllegalArgumentException
	at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
	at org.apache.axis.client.Call.invoke(Call.java:2470)
	at org.apache.axis.client.Call.invoke(Call.java:2366)
	at org.apache.axis.client.Call.invoke(Call.java:1812)
	at com.microsoft.bingads.v9.campaignmanagement.BasicHttpBinding_ICampaignManagementServiceStub.addKeywords(BasicHttpBinding_ICampaignManagementServiceStub.java:5504)
	... 32 more
Caused by: java.lang.IllegalArgumentException
	at org.apache.axis.encoding.ser.BeanPropertyTarget.set(BeanPropertyTarget.java:157)
	at org.apache.axis.encoding.DeserializerImpl.valueComplete(DeserializerImpl.java:249)
	at org.apache.axis.encoding.ser.ArrayDeserializer.valueComplete(ArrayDeserializer.java:583)
	at org.apache.axis.encoding.DeserializerImpl.endElement(DeserializerImpl.java:509)
	at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
	at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:171)
	at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
	at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
	at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
	at org.apache.axis.client.Call.invoke(Call.java:2467)
	... 35 more
Caused by: java.lang.IllegalArgumentException
	at java.lang.reflect.Array.set(Native Method)
	at org.apache.axis.utils.JavaUtils.convert(JavaUtils.java:469)
	at org.apache.axis.encoding.ser.BeanPropertyTarget.set(BeanPropertyTarget.java:98)
	... 44 more

这是wsdl中的问题还是我应该在生成Java代码时向wsdl2java传递更多的标志?

Is this a problem in the wsdl or should I pass some more flags to wsdl2java when generating the Java code?

感谢任何帮助,

Magnus

推荐答案

你好。

Hello.

很棒的问题。是的,这个问题与Axis 1.4 WSDL2Java 发射器有关,它将关键字标识符指定为'long'数组,这是一个原始的非可空数据类型。对于AddAdsResponse
和AddKeywordsResponse,服务将这些标识符定义为可以为空的long数组。应将标识符指定为非原始可空数据类型,例如java.lang.Long。


Great question. Yes this issue has to do with the Axis 1.4 WSDL2Java emitter specifying the keyword identifiers as array of 'long', which is a primitive non-nullable data type. For AddAdsResponse and AddKeywordsResponse, the service defines these identifiers as an array of nullable long. The identifiers should be specified as a non-primitive nullable data type, for example java.lang.Long.

这可以通过在AddAdsResponse.java和AddKeywordsResponse.java中用'java.lang.Long'替换'long'来解决。如果你按照文档中描述的那样完成了WSDL2Java命令b $ b( http: //msdn.microsoft.com/en-US/library/bing-ads-overview-getting-started-java-with-web-services.aspx#proxy ),这两个文件都应在
之内bingads\campaignmanagement,相对于您当前的目录。

This can be resolved by replacing 'long' with 'java.lang.Long' in both AddAdsResponse.java and AddKeywordsResponse.java. If you completed the WSDL2Java command as described in the documentation (http://msdn.microsoft.com/en-US/library/bing-ads-overview-getting-started-java-with-web-services.aspx#proxy), both files should be within bingads\campaignmanagement, relative to your current directory.

我们将更新文档以明确地调用它。这里使用最新的JAR更新Java代码示例下载。

We will update the documentation to call this out explicitly. The Java code sample download is updated here with the latest JARs.

http://code.msdn.microsoft.com / Bing-Ads-API-Version-9-in-3754a3f4

http://code.msdn.microsoft.com/Bing-Ads-API-Version-9-in-3754a3f4

我不知道WSDL2Java标志可以完成相同的操作。如果我遇到任何问题,我一定会提供更新。


I am not aware of a WSDL2Java flag to accomplish the same. If I run across anything I'll be sure to provide an update.

谢谢,

Eric


这篇关于使用Java和Axis 1.4的部分错误问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆