检索netsuite搜索结果时出错

时间:2016-08-18 15:24:23

标签: netsuite mule-component

我正在尝试搜索来自netsuite的联系人。我基本上做的是,创建一个搜索条件,使用电子邮件作为参数,并尝试检索结果,然后将其映射到对象到xml转换器。但我得到以下错误:

无法调用java.util.concurrent.CopyOnWriteArrayList.writeObject():无法封送正在运行的XStream实例

我使用的骡子流程如下:

<flow name="contact_searchFlow">
    <http:listener config-ref="HTTP_Request_Configuration" path="/basicContactSearch" doc:name="HTTP"/>
    <logger message="Test1" level="INFO" doc:name="Logger"/>
<component class="netsuitews.ContactBasicSearchComponent" doc:name="Search Contact Basic criteria"/>
    <logger message="Test 2" level="INFO" doc:name="Logger"/>
<netsuite:search config-ref="NetSuite__Request_Level_Authentication" searchRecord="CONTACT_BASIC" fetchSize="5" doc:name="Contact Basic Search"/>
    <logger message="Test3" level="INFO" doc:name="Logger"/>
    <mulexml:object-to-xml-transformer doc:name="Object to XML"/>
    <logger message="Test4" level="INFO" doc:name="Logger"/>     

我正在使用的搜索组件如下:

public class ContactBasicSearchComponent implements Callable {

public Object onCall(MuleEventContext eventContext) throws Exception {
    ContactSearchBasic searchCriteria = new ContactSearchBasic();       

    SearchStringField nameFilter = new SearchStringField();
    nameFilter.setOperator(SearchStringFieldOperator.IS);
    nameFilter.setSearchValue("test_shutterFly@gmail.com");
    searchCriteria.setEmail(nameFilter);

    return searchCriteria;
}
@Override
public Object call() throws Exception {
    // TODO Auto-generated method stub
    return null;
} 

}

我正在使用NetSuite Connector(Mule 3.5+)版本7.1.0.201603151241并在mule 3.8.0 EE版本中运行。

这是我从骡子日志中获得的堆栈跟踪。

2016-08-18 20:41:26,181 [netsuitews].HTTP_Request_Configuration.worker.01] INFO  org.mule.api.processor.LoggerMessageProcessor - Test1

2016-08-18 20:41:26,194 [[netsuitews].HTTP_Request_Configuration.worker.01] INFO  org.mule.api.processor.LoggerMessageProcessor - Test 2

2016-08-18 20:41:37,668 [[netsuitews].HTTP_Request_Configuration.worker.01] INFO  org.mule.api.processor.LoggerMessageProcessor - Test3

2016-08-18 20:41:43,761 [[netsuitews].HTTP_Request_Configuration.worker.01] ERROR org.mule.exception.DefaultMessagingExceptionStrategy - 

********************************************************************************
Message               : Could not call java.util.concurrent.CopyOnWriteArrayList.writeObject() : Cannot marshal the XStream instance in action
-------------------------------
message             : Could not call java.util.concurrent.CopyOnWriteArrayList.writeObject()
cause-exception     : com.thoughtworks.xstream.converters.ConversionException
cause-message       : Cannot marshal the XStream instance in action

(com.thoughtworks.xstream.converters.ConversionException).
Payload               : org.mule.streaming.ConsumerIterator@7dbf934e
Element XML           : <mulexml:object-to-xml-transformer doc:name="Object to XML"></mulexml:object-to-xml-transformer>
Payload Type          : org.mule.streaming.ConsumerIterator

Element               : /contact_searchFlow/processors/5 @ netsuitews:customer_crud.xml:61 (Object to XML)
Root Exception stack trace:
com.thoughtworks.xstream.converters.ConversionException: Cannot marshal the XStream instance in action
at com.thoughtworks.xstream.core.util.SelfStreamingInstanceChecker.marshal(SelfStreamingInstanceChecker.java:59)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:250)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:226)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:189)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:135)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:83)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:250)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:226)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:189)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:135)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:83)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:43)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:88)
at     
.
.
.

你能帮忙解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

发生转换异常是因为NetSuite 搜索操作是实现分页的处理器。因此,生成的有效内容的类型为 ConsumerIterator Object to XML 转换器无法直接将该迭代器转换为XML。您需要首先提取其内容才能操作它。一种选择是将数据转换为List,然后应用XML转换器。例如:

#[org.apache.commons.collections.IteratorUtils.toList(payload)]

然后您的流程将如下所示:

<flow>
    ...
    <netsuite:search config-ref="NetSuite__Request_Level_Authentication" searchRecord="CONTACT_BASIC" fetchSize="5" doc:name="NetSuite"/>
    <set-payload value="#[org.apache.commons.collections.IteratorUtils.toList(payload)]" doc:name="Set Payload"/>
    <mulexml:object-to-xml-transformer doc:name="Object to XML"/>
</flow>

此外,我建议您使用DataWeave为NetSuite构建输入数据,而不是使用Java组件来设置搜索条件。

<dw:transform-message doc:name="Transform Message">
    <dw:set-payload><![CDATA[%dw 1.0
    %output application/java
    ---
    {
        email: {
            operator: "IS",
            searchValue: "test_shutterFly@gmail.com"
        }
    } as :object {
        class : "com.netsuite.webservices.platform.common.ContactSearchBasic"
    }
    ]]></dw:set-payload>
</dw:transform-message>

最终流程看起来类似于:

enter image description here