Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to access Jira Payload in JAVA (java.util.Arrays$ArrayList)

Here is my Flow information. Trying to GET one issue from JIRA and want to setup that issueID to another project. Here i want to use Custom Transformer and setup all objects using JAVA coding.

<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>

I am trying to access JIRA payload object but it's throwing me Error as Type Cast Exception.

@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

I am getting following Errors.

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)
********************************************************************************

I tried to follow this Documentation URL but couldn't able to figure it out. http://mulesoft.github.io/jira-connector/java/com/atlassian/jira/rpc/soap/beans/RemoteIssue.html

I want to Access this Payload and want to update some details from payload object here. I can access payload using MEL expression #[payload[0]] and it automatically coverts it to com.atlassian.jira.rpc.soap.beans.RemoteIssue but using Java code i am not able to type cast it.

Can you please help me to cast this object correctly so i can access the Payload here ?

Thanks.

like image 429
dev Avatar asked Apr 16 '15 00:04

dev


1 Answers

There's a bug in your component.

This Arrays.asList(message.getPayload()) wraps the message payload into a list. But the message payload is already a List<RemoteIssues> so this wrapping is unnecessary.

If you look at the source code of the JIRA connector, you'll see that MuleSoft prefers late casting of the RemoteIssue. I suggest you do the same:

for (Object o : ((List) message.getPayload())) {
  RemoteIssue ri = (RemoteIssue) o;
  ...
}
like image 52
David Dossot Avatar answered Sep 19 '22 00:09

David Dossot