无法访问JAVA中的Jira Payload(java.util.Arrays $ ArrayList)

时间:2015-04-16 00:32:18

标签: mule jira mule-component

这是我的Flow信息。试图从JIRA获取一个问题,并希望将该问题ID设置为另一个项目。在这里,我想使用Custom Transformer并使用JAVA编码设置所有对象。

<jira:config name="Jira" connectionUser="XXXXXXX" connectionPassword="XXXXX" connectionAddress="http://XXXXXXX/rpc/soap/jirasoapservice-v2" doc:name="Jira">
        <jira:connection-pooling-profile initialisationPolicy="INITIALISE_ONE" exhaustedAction="WHEN_EXHAUSTED_GROW"/>
        <reconnect count="3"/>
    </jira:config>

    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>


  <flow name="jira-pocFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/input" doc:name="HTTP"/>
        <jira:get-issues-from-jql-search config-ref="Jira" jqlSearch="id=MRT-75" maxNumResults="100" doc:name="Jira"/>
        <set-variable variableName="payload" value="#[payload[0]]" doc:name="Variable"/>
        <component class="JIRATransformer" doc:name="Java"/>
        <jira:create-issue-using-object config-ref="Jira"    doc:name="Jira"   >
            <jira:issue ref="#[message.payload]"/>
        </jira:create-issue-using-object>
        <logger level="INFO" doc:name="Logger"/>
    </flow>

我正在尝试访问JIRA有效负载对象,但是它会将Error作为类型转换异常。

@Override
public Object transformMessage(MuleMessage message, String outputEncoding) 
        throws org.mule.api.transformer.TransformerException { 

      ArrayList<com.atlassian.jira.rpc.soap.beans.RemoteIssue> list = new ArrayList(Arrays.asList(message.getPayload()));

    for(RemoteIssue q : (List<RemoteIssue>) list){
        System.out.println("Print AssigneeInfo:->"+q.getAssignee());
    }


 }

enter image description here

我遇到了错误。

ERROR 2015-04-15 19:58:59,526 [[jira-poc].HTTP_Listener_Configuration.worker.01] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : Component that caused exception is: DefaultJavaComponent{jira-pocFlow.component.887693985}. Message payload is of type: Arrays$ArrayList
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. java.util.Arrays$ArrayList cannot be cast to com.atlassian.jira.rpc.soap.beans.RemoteIssue (java.lang.ClassCastException)
  JIRATransformer:29 (null)
2. Component that caused exception is: DefaultJavaComponent{jira-pocFlow.component.887693985}. Message payload is of type: Arrays$ArrayList (org.mule.component.ComponentException)
  org.mule.component.DefaultComponentLifecycleAdapter:348 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to com.atlassian.jira.rpc.soap.beans.RemoteIssue
    at JIRATransformer.transformMessage(JIRATransformer.java:29)
    at org.mule.transformer.AbstractMessageTransformer.transform(AbstractMessageTransformer.java:141)
    at org.mule.transformer.AbstractMessageTransformer.transform(AbstractMessageTransformer.java:69)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

我尝试关注此文档网址,但无法弄明白。 http://mulesoft.github.io/jira-connector/java/com/atlassian/jira/rpc/soap/beans/RemoteIssue.html

我想访问此有效负载,并希望在此处更新有效负载对象的一些详细信息。我可以使用MEL表达式[[payload [0]]访问有效负载,它会自动将其转换为com.atlassian.jira.rpc.soap.beans.RemoteIssue但使用Java代码我无法输入强制转换它。

你能帮我正确地投射这个物体,这样我可以在这里访问有效载荷吗?

感谢。

1 个答案:

答案 0 :(得分:1)

您的component中存在错误。

Arrays.asList(message.getPayload())将消息有效内容包装到列表中。但是消息有效负载已经是List<RemoteIssues>,所以这种包装是不必要的。

如果您查看source code of the JIRA connector,您会发现MuleSoft更喜欢延迟投射RemoteIssue。我建议你这样做:

for (Object o : ((List) message.getPayload())) {
  RemoteIssue ri = (RemoteIssue) o;
  ...
}