使用Soap Lite和perl的自定义字段在JIRA中创建问题的问题

时间:2011-07-27 21:23:16

标签: perl soap jira soaplite

我正用以下代码敲击肥皂api。我的目标是创建一个包含自定义字段的票证。如果您注释掉自定义字段部分,则此代码可以正常工作。知道发生了什么事吗?

代码

my $soap = SOAP::Lite->service($wsdl);
my $token = $soap->login($_jira_user,$_jira_pass);

my $customFields = [
    {'customFieldId' => $_cf_map{'severity'},'values' => [SOAP::Data->type('string', $severity)]},
    {'customFieldId' => $_cf_map{'outage_start'}, 'values' => [SOAP::Data->type('string', $start)]},
    {'customFieldId' => $_cf_map{'no_auto_close'}, 'values' => [SOAP::Data->type('string', $no_auto_close == 1 ? 'Yes': 'No')]},
    {'customFieldId' => $_cf_map{'nco_serials'}, 'values' => [SOAP::Data->type('string', $serial_string)]},
    {'customFieldId' => $_cf_map{'services'}, 'values' => \@services},
];

my $remoteIssueHash = {
    'project' => SOAP::Data->type('string' => $_projectkey),
    'type' => SOAP::Data->type('string' => $_issuetype),
    'summary' => SOAP::Data->type('string' => $summary),
    'reporter' => SOAP::Data->type('string' => $user),
    'assignee' => SOAP::Data->type('string' => $user),
    'customFieldValues' => $customFields,
};

my $remote_issue = $soap->call('createIssue', $token, $remoteIssueHash);
print Dumper [$remote_issue->faultcode(), $remote_issue->faultstring(), $soap->transport()->status(), $remote_issue->result(), $remote_issue ]
exit();

输出

$VAR1 = [
      'soapenv:Server.userException',
      'org.xml.sax.SAXException: No deserializer for {http://www.w3.org/2001/XMLSchema}anyType',
      '500 Internal Server Error',
      #big soap object
      ]

XML SENT

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:tns2="http://exception.rpc.jira.atlassian.com" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:namesp1="http://soap.rpc.jira.atlassian.com" xmlns:apachesoap="http://xml.apache.org/xml-soap" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns1="http://beans.soap.rpc.jira.atlassian.com" xmlns:impl="http://jira.nyc.hcmny.com:8080/rpc/soap/jirasoapservice-v2" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <soap:Body>
            <namesp1:createIssue>
                  <c-gensym6 xsi:type="xsd:string">Y6DQd1k2BL</c-gensym6>
                  <c-gensym8>
                        <assignee xsi:type="xsd:string">fgulotta</assignee>
                        <customFieldValues soapenc:arrayType="xsd:anyType[5]" xsi:type="soapenc:Array">
                              <item>
                                    <customFieldId xsi:type="xsd:string">customfield_10094</customFieldId>
                                    <values soapenc:arrayType="xsd:string[1]" xsi:type="soapenc:Array">
                                          <item xsi:type="xsd:string">4</item>
                                    </values>
                                    <key xsi:type="xsd:string" />
                              </item>
                              <item>
                                    <customFieldId xsi:type="xsd:string">customfield_10084</customFieldId>
                                    <values soapenc:arrayType="xsd:string[1]" xsi:type="soapenc:Array">
                                          <item xsi:type="xsd:string">29/Jul/11 05:46 PM</item>
                                    </values>
                                    <key xsi:type="xsd:string" />
                              </item>
                              <item>
                                    <customFieldId xsi:type="xsd:string">customfield_10100</customFieldId>
                                    <values soapenc:arrayType="xsd:string[1]" xsi:type="soapenc:Array">
                                          <item xsi:type="xsd:string">Yes</item>
                                    </values>
                                    <key xsi:type="xsd:string" />
                              </item>
                              <item>
                                    <customFieldId xsi:type="xsd:string">customfield_10093</customFieldId>
                                    <values soapenc:arrayType="xsd:string[1]" xsi:type="soapenc:Array">
                                          <item xsi:type="xsd:string" />
                                    </values>
                                    <key xsi:type="xsd:string" />
                              </item>
                              <item>
                                    <customFieldId xsi:type="xsd:string">customfield_10080</customFieldId>
                                    <values soapenc:arrayType="xsd:string[1]" xsi:type="soapenc:Array">
                                          <item xsi:type="xsd:string">intranet</item>
                                    </values>
                                    <key xsi:type="xsd:string" />
                              </item>
                        </customFieldValues>
                        <summary xsi:type="xsd:string">This is a test ticket.</summary>
                        <project xsi:type="xsd:string">MON</project>
                        <type xsi:type="xsd:string">31</type>
                        <reporter xsi:type="xsd:string">fgulotta</reporter>
                  </c-gensym8>
            </namesp1:createIssue>
      </soap:Body>
</soap:Envelope>

XML RECIEVED

<?xml version="1.0" encoding="utf-8"?>
<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:Body>
            <soapenv:Fault>
                  <faultcode>soapenv:Server.userException</faultcode>
                  <faultstring>org.xml.sax.SAXException: No deserializer for {http://www.w3.org/2001/XMLSchema}anyType</faultstring>
                  <detail>
                        <faultData xsi:type="ns1:SAXException" xmlns:ns1="http://sax.xml.org">
                              <exception xsi:type="ns2:Exception" xsi:nil="true" xmlns:ns2="http://lang.java"/>
                              <message xsi:type="xsd:string">No deserializer for {http://www.w3.org/2001/XMLSchema}anyType</message>
                        </faultData>
                        <ns3:hostname xmlns:ns3="http://xml.apache.org/axis/">deputy.811t.hcmny.com</ns3:hostname>
                  </detail>
            </soapenv:Fault>
      </soapenv:Body>
</soapenv:Envelope>

已更新已修复字段名称并将值放入字符串数组但仍有问题。

第二次更新 我找到了一些针对soap服务的java代码并针对它运行了我的测试。然后我用wireshark来嗅探xml。忽略multirefs它是一个非常相似的结构,但我不太确定如何用Soap :: Lite建模它。

<?xml version="1.0" encoding="UTF-8"?>
<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:Body>
            <ns1:createIssue soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://soap.rpc.jira.atlassian.com">
                  <in0 xsi:type="xsd:string">B2P69v5NrS</in0>
                  <in1 href="#id0"/>
            </ns1:createIssue>
            <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:RemoteIssue" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://beans.soap.rpc.jira.atlassian.com">
                  <id xsi:type="xsd:string" xsi:nil="true"/>
                  <affectsVersions xsi:type="ns2:RemoteVersion" xsi:nil="true"/>
                  <assignee xsi:type="xsd:string">fgulotta</assignee>
                  <attachmentNames xsi:type="xsd:string" xsi:nil="true"/>
                  <components xsi:type="ns2:RemoteComponent" xsi:nil="true"/>
                  <created xsi:type="xsd:dateTime" xsi:nil="true"/>
                  <customFieldValues soapenc:arrayType="ns2:RemoteCustomFieldValue[3]" xsi:type="soapenc:Array">
                        <customFieldValues href="#id1"/>
                        <customFieldValues href="#id2"/>
                        <customFieldValues href="#id3"/>
                  </customFieldValues>
                  <description xsi:type="xsd:string" xsi:nil="true"/>
                  <duedate xsi:type="xsd:dateTime" xsi:nil="true"/>
                  <environment xsi:type="xsd:string" xsi:nil="true"/>
                  <fixVersions xsi:type="ns2:RemoteVersion" xsi:nil="true"/>
                  <key xsi:type="xsd:string" xsi:nil="true"/>
                  <priority xsi:type="xsd:string" xsi:nil="true"/>
                  <project xsi:type="xsd:string">MON</project>
                  <reporter xsi:type="xsd:string">fgulotta</reporter>
                  <resolution xsi:type="xsd:string" xsi:nil="true"/>
                  <status xsi:type="xsd:string" xsi:nil="true"/>
                  <summary xsi:type="xsd:string">This is a test ticket.</summary>
                  <type xsi:type="xsd:string">31</type>
                  <updated xsi:type="xsd:dateTime" xsi:nil="true"/>
                  <votes xsi:type="xsd:long" xsi:nil="true"/>
            </multiRef>
            <multiRef id="id2" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:RemoteCustomFieldValue" xmlns:ns3="http://beans.soap.rpc.jira.atlassian.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
                  <customfieldId xsi:type="xsd:string">customfield_10094</customfieldId>
                  <key xsi:type="xsd:string" xsi:nil="true"/>
                  <values soapenc:arrayType="xsd:string[1]" xsi:type="soapenc:Array">
                        <values xsi:type="xsd:string">4</values>
                  </values>
            </multiRef>
            <multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns4:RemoteCustomFieldValue" xmlns:ns4="http://beans.soap.rpc.jira.atlassian.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
                  <customfieldId xsi:type="xsd:string">customfield_10084</customfieldId>
                  <key xsi:type="xsd:string" xsi:nil="true"/>
                  <values soapenc:arrayType="xsd:string[1]" xsi:type="soapenc:Array">
                        <values xsi:type="xsd:string">27/Jul/11 02:21 PM</values>
                  </values>
            </multiRef>
            <multiRef id="id3" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns5:RemoteCustomFieldValue" xmlns:ns5="http://beans.soap.rpc.jira.atlassian.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
                  <customfieldId xsi:type="xsd:string">customfield_10100</customfieldId>
                  <key xsi:type="xsd:string" xsi:nil="true"/>
                  <values soapenc:arrayType="xsd:string[1]" xsi:type="soapenc:Array">
                        <values xsi:type="xsd:string">Yes</values>
                  </values>
            </multiRef>
      </soapenv:Body>
</soapenv:Envelope>

3 个答案:

答案 0 :(得分:2)

我设法使用perl和SOAP :: Lite创建一个问题(需求)。关键是使用数组构建请求并使用SOAP :: Data-&gt; type()定义类型。我无法使用'fixVersions'属性填写修复版本,但我是通过自定义字段'customfield_10040'完成的。您可以使用getItem()调用来检查您的案例中使用的是哪一个。

my $soap = SOAP::Lite->service($URI);
my $token = $soap->login($USERNAME,$PASSWORD);

my $fieldValues = [
   SOAP::Data->type('RemoteCustomFieldValue', {'customfieldId' => 'customfield_10040',
                                               'values' => [
                                                   SOAP::Data->type('string', '10051'),
                                                   SOAP::Data->type('string', '10052')
                                                           ]
                                              }),];
my $affectedValues = [
   SOAP::Data->type('RemoteVersion', {'name' => 'FINS 1.16.1', 
                                        'id' => SOAP::Data->type('string', '10051')}),
   SOAP::Data->type('RemoteVersion', {'name' => 'FINS 1.16.1a',
                                        'id' => SOAP::Data->type('string', '10052')})
                     ];
my $fixedValues = [
                   SOAP::Data->type('RemoteVersion', {'name' => 'FINS 1.16.1', 
                                                        'id' => SOAP::Data->type('string', '10051')})
                  ];
my $customFields    = SOAP::Data->type('RemoteCustomFieldValue', $fieldValues);
my $fixVersion      = SOAP::Data->type('RemoteVersion'  , $fixedValues);
my $affectedVersion = SOAP::Data->type('RemoteVersion'  , $affectedValues);
my $component       = SOAP::Data->type('RemoteComponent', \{'name' => 'CST', 'id' => SOAP::Data->type('string', '10194')});

my $remoteIssueHash = {
    'project'           => SOAP::Data->type('string' => $PROJECT),
    'type'              => SOAP::Data->type('string' => 10),
    'summary'           => SOAP::Data->type('string' => $summary),
    'reporter'          => SOAP::Data->type('string' => $reporter),
    'assignee'          => SOAP::Data->type('string' => $assignee),
    'customFieldValues' => SOAP::Data->type('array'  => $customFields),
    'affectsVersions'   => SOAP::Data->type('array'  => $affectedVersion),
    'components'        => SOAP::Data->type('array'  => $component),
    'fixVersions'       => SOAP::Data->type('array'  => $fixVersion),  ## this doesn't do anything
    'description'       => SOAP::Data->type('string' => $description),
    'environment'       => SOAP::Data->type('string' => 'Some environment'),
};

my $remote_issue = $soap->call('createIssue', $token, $remoteIssueHash);
print Dumper [$remote_issue->faultcode(), $remote_issue->faultstring(), $soap->transport()->status(), $remote_issue->result(), $remote_issue ];
exit();

祝你好运。

丹尼尔

答案 1 :(得分:1)

createIssue采用RemoteIssue对象。 RemoteIssue对象具有名为customFustomFieldValue对象的customFieldValues的数组。到目前为止都很好。 RemoteCustomFieldValue对象有一个名为customfieldId的字段(不是你所拥有的“id”)和一个名为“values”的字符串数组。看起来$ severity不是一个数组?

所有这些都来自RemoteIssue和RemoteCustomFieldValue的Java源代码。根据我的经验,SOAP错误几乎总是无用的。

〜马特

答案 2 :(得分:0)

我已经放弃了尝试理解SOAP::Lite。 2005年,我对该模块的无法预料的做法感到非常不满,并学会了避免使用它。

很多时候,构建DOM的简单LWPXML::LibXML就足够了。

您甚至可以将XML文档硬编码为程序中的字符串,只是插入变量。不漂亮,但在某些情况下足够了。

现在您正面临着一个WSDL文件,您的场景很可能并非无足轻重。 (我不知道。)

我最近才知道优秀的Mark Overmeer的XML::Compile模块套件的存在。你必须在尊重到期时付出尊重。我们必须与SOAP / MTOM / XOM服务集成,因此XML使用二进制附件。关于那个(臃肿的企业)规范,我没有太多线索。使用XML::Compile::SOAP,我们让它在三个小时内完成,大部分时间都浪费在一些琐碎的问题上,这些问题只能通过我们的(愚蠢的)试错方法来解决。如果我们遵循文档,那将是一个小时。

所以我强烈推荐Mark Overmeer的XML::Compile::SOAP。它对我们起了很大作用。