6

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.

dev
  • 97
  • 2
  • 8

1 Answers1

1

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;
  ...
}
David Dossot
  • 33,403
  • 4
  • 38
  • 72
  • My component has issue with reading RemoteIssue arrays.arraylist of payload. Which is actually returned by JIRA component. I am looking for solution here. Why Java code is throwing class cast exception while reading that object ? – dev Apr 16 '15 at 14:54
  • @dev Reviewed my answer. – David Dossot Apr 16 '15 at 15:43
  • Thanks a lot David !! That worked for me but i wanted to Migrate some issues using JQL Query which returned me Arrays of records and migrate all to another system. While here create issue using Object only support Obejct type which is RemoteIssue type. So what's the best approach if i want to migrate all RemoteIssues to another system ? – dev Apr 16 '15 at 19:38
  • 1
    Just add a `for-each` scope around `jira:create-issue-using-object` so that it will iterate the `List` returned by your custom component. – David Dossot Apr 16 '15 at 22:43