I am trying to search a contact from netsuite. what i basically do is, creating a search criteria with email as parameter and trying to retrieve the result and then map it to object to xml transformer. But I am getting following error as :
Could not call java.util.concurrent.CopyOnWriteArrayList.writeObject() : Cannot marshal the XStream instance in action
The mule flow i am using as follows:
<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"/>
The search component i am using as follows:
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;
}
}
I am using NetSuite Connector (Mule 3.5+) version 7.1.0.201603151241 and running in mule 3.8.0 EE version.
Here is the stack trace i got from mule logs.
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
.
.
.
Could you please help on this!
That conversion exception occurs because the NetSuite Search operation is a processor that implements Pagination. Therefore, the resulting payload is of type ConsumerIterator. The Object to XML transformer cannot directly convert that iterator to XML. You need to extract its contents first in order to manipulate it. One option is to convert the data to a List and then apply the XML transformer. For example:
#[org.apache.commons.collections.IteratorUtils.toList(payload)]
Then your flow would look like this:
<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>
Additionally, I suggest you use DataWeave to build the input data for NetSuite instead of using the Java component to set the search criteria.
<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>
The final flow would look similar to:
Related
i have code
<int:channel id="partnerConfigChannel" />
<int:gateway id="partnerService" service-interface="org.service.PartnerService"
default-request-timeout="5000" default-reply-timeout="5000">
<int:method name="findConfig" request-channel="partnerConfigChannel" />
</int:gateway>
<int-jpa:retrieving-outbound-gateway entity-manager="entityManager"
request-channel="partnerConfigChannel"
jpa-query="select q from QueueConfiguration q where q.partnerId = :partnerId">
<int-jpa:parameter name="partnerId" expression="payload['partnerId']" />
</int-jpa:retrieving-outbound-gateway>
and java interface
public interface PartnerService {
#Payload("partnerId")
List<QueueConfiguration> findConfig();
}
i am calling it
List<QueueConfiguration> qc= partnerService.findConfig();
but i am getting exception
EL1007E:(pos 0): Property or field 'partnerId' cannot be found on null
please tell me how can i pass payload . i tried by passing Message object with a map , string but same error .
please tell me how can i pass payload in such case.
#Payload("partnerId")
At this point, there is no object for the SpEL expression to be evaluated against.
It either needs to be a literal
#Payload("'partnerId'")
Or refer to some other bean.
Further, on your adapter, you are expecting the payload to be a map with key partnerId.
expression="payload['partnerId']"
So this won't work.
If you want to pass a variable, you should do something like this...
public interface PartnerService {
List<QueueConfiguration> findConfig(MyClass param);
Where MyClass has some property 'partnerId'.
or
List<QueueConfiguration> findConfig(String partnerId);
and
expression="payload"
I suggest you do some more reading.
i modified my code
public interface PartnerService {
List<QueueConfiguration> findConfig(#Payload Message msg);
}
and the call it like
Map msgMap=new HashMap();
msgMap.put("partnerId", partnerId);
Message msg=MessageBuilder.withPayload(msgMap).build();
List<QueueConfiguration> qc= partnerService.findConfig(msg);
and it is working fine.
I am using fork-join pattern to achieve parallel processing in Batch.
I have take reference of the following question :
Mule File Inbound Flow : Control Number of threads
Since I do have too many files in my input folder, but i need to achieve parallel processing. Hence, thought of using this pattern. Here is my config flow how it looks.
<quartz:connector name="Quartz1" validateConnections="true" doc:name="Quartz">
<receiver-threading-profile maxThreadsActive="1"/>
</quartz:connector>
<flow name="Mainflow" processingStrategy="synchronous">
<quartz:inbound-endpoint jobName="EventGeneration" repeatInterval="1000" connector-ref="Quartz1" responseTimeout="10000" doc:name="Quartz">
<quartz:event-generator-job/>
</quartz:inbound-endpoint>
<mulerequester:request-collection config-ref="Mule_Requester" resource="file:///FileLocation?connector=FileMRTransformer" count="3" doc:name="Mule Requester"/>
<expression-filter expression="#[payload.size() != 0]" doc:name="Expression"/>
<request-reply doc:name="Request-Reply" timeout="300000">
<processor-chain doc:name="Processor Chain">
<collection-splitter doc:name="Collection Splitter"/>
<vm:outbound-endpoint exchange-pattern="one-way" doc:name="VM" connector-ref="VM" path="Batchinput" />
</processor-chain>
<vm:inbound-endpoint exchange-pattern="one-way" doc:name="VM" connector-ref="VM" path="Batchoutput">
<message-properties-transformer>
<add-message-property key="MULE_CORRELATION_GROUP_SIZE" value="3" />
</message-properties-transformer>
<collection-aggregator />
</vm:inbound-endpoint>
</request-reply>
</flow>
<batch:job name="BatchDemo" max-failed-records="-1">
<batch:input>
<vm:inbound-endpoint exchange-pattern="one-way" path="Batchinput" connector-ref="VM" doc:name="VM"/>
....
required processing.....
.
.
<batch:on-complete>
<vm:outbound-endpoint exchange-pattern="one-way" doc:name="VM" connector-ref="VM" path="Batchoutput"/>
</batch:on-complete>
As soon as the control enter the request-reply scope the following exception is thrown:
ERROR 2016-06-23 10:32:56,190 [scheduler-multithreadint019.1.2_productindexing_hybris_fh_Worker-1] org.mule.exception.CatchMessagingExceptionStrategy:
********************************************************************************
Message : null (java.lang.NullPointerException). Message payload is of type: CopyOnWriteArrayList
Type : org.mule.api.MessagingException
Code : MULE_ERROR--2
Payload : [[B#26589e4d, [B#400e4e6, [B#56b3ba17]
JavaDoc : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html
********************************************************************************
Exception stack is:
1. null (java.lang.NullPointerException)
java.util.concurrent.ConcurrentHashMap:-1 (null)
2. null (java.lang.NullPointerException). Message payload is of type: CopyOnWriteArrayList (org.mule.api.MessagingException)
org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
********************************************************************************
Root Exception stack trace:
java.lang.NullPointerException
at java.util.concurrent.ConcurrentHashMap.hash(Unknown Source)
at java.util.concurrent.ConcurrentHashMap.put(Unknown Source)
at org.mule.routing.requestreply.AbstractAsyncRequestReplyRequester.process(AbstractAsyncRequestReplyRequester.java:85)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
Alternate config tried for request part in Request-Reply processor:
<vm:outbound-endpoint exchange-pattern="one-way" doc:name="VM" connector-ref="VM" path="Batchinput">
<collection-splitter />
</vm:outbound-endpoint>
But it resulted the same exception.
Only when using MuleRequester i am getting this exception. If i use some java snippet to return a collection of File objects i am not getting this exception, and the control is entering as expected into the batch flow. But, i do have a transformer(DataWeave) in my input phase of batch, and my transformer is not able to parse this file object (say java.io.file or java.io.FileInputStream). Hence used MuleRequester so that i can have streaming enabled.
I am not sure what went wrong when using this Mulerequester??
Found an alternative for it, if anyone is interested.
Used a poll component, with Java to return fileNames collection (rather than file Objects). Used the same requestreply pattern. However, this time i am retrieving payload from file in the input phase of batch, using MuleRequester. giving the filename to this MuleRequester as input path.
This way it is running fine.
Background:
We are using Spring.Net 2.0 to manage our transactions with nHibernate 3.3.1. The application follows the the publisher-subscriber pattern. Each subscriber runs in a separate thread and is invoked by RabbitMQ message broker system once the queue, it is bound to, got a message published from some other thread.
Each time the subscriber begins processing it starts a new transaction (using Spring.Net declarative transactions support) in a separate thread. All the subsequent operations invoked by subscriber usually use the same transaction. But there are cases where we need a new transaction e.g. when we need to update the shared data, like oracle sequence. The methods doing such operations are decorated with Transaction aspect and with TransactionPropagation value set as RequiresNew.
Based on spring.Net documentation and source code we assume that for such special scenarios where a method is invoked with TransactionPropagation value as RequiresNew, the outer transaction is suspended until the method is completed. The outer transaction resumes after the completion of the method and follows the execution path of the thread.
Problem:
We are encountering a random scenario where once a subscriber is handed over the message for processing, some times it completes the task with out any problem but some times it throws following exception:
Exception message:
Cannot activate transaction synchronization - already active
Stacktrace: at
Spring.Transaction.Support.TransactionSynchronizationManager.InitSynchronization()
at
Spring.Transaction.Support.AbstractPlatformTransactionManager.DoResumeSynchronization(IList
suspendedSynchronizations) at
Spring.Transaction.Support.AbstractPlatformTransactionManager.Resume(Object
transaction, Object suspendedResources) at
Spring.Transaction.Support.AbstractPlatformTransactionManager.HandleExistingTransaction(ITransactionDefinition
definition, Object transaction, Boolean debugEnabled) at
Spring.Transaction.Support.AbstractPlatformTransactionManager.GetTransaction(ITransactionDefinition
definition) at
Spring.Transaction.Interceptor.TransactionAspectSupport.CreateTransactionIfNecessary(ITransactionAttribute
sourceAttr, String joinpointIdentification) at
Spring.Transaction.Interceptor.TransactionAspectSupport.CreateTransactionIfNecessary(MethodInfo
method, Type targetType) at
Spring.Transaction.Interceptor.TransactionInterceptor.Invoke(IMethodInvocation
invocation) at
Spring.Aop.Framework.AbstractMethodInvocation.Proceed() in
e:\spring.net\spring-net-master\src\Spring\Spring.Aop\Aop\Framework\AbstractMethodInvocation.cs:line
291 at Spring.Aop.Framework.DynamicProxy.AdvisedProxy.Invoke(Object
proxy, Object target, Type targetType, MethodInfo targetMethod,
MethodInfo proxyMethod, Object[] args, IList interceptors) in
e:\spring.net\spring-net-master\src\Spring\Spring.Aop\Aop\Framework\DynamicProxy\AdvisedProxy.cs:line
210
The frequency of this issue increases with number of messages in the message broker queues.
Sample Code/Configuration:
The spring transaction is configured in our spring context file as:
<object id="transactionManager" type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate3">
<property name="DbProvider" ref="DbProvider" />
<property name="SessionFactory" ref="NHibernateSessionFactory" />
<property name="TransactionSynchronization" value="Always" />
</object>
The code is written like:
public class MyMessageHandler
{
ServiceOne MyServiceOne { get; set;}
ServiceTwo MyServiceTwo { get; set;}
[Transaction]
public void Execute()
{
var unprocessedObjects = MyServiceOne.FindUnprocessedObjects();
foreach (var unprocessedObject in unprocessedObjects)
{
MyServiceTwo.UpdateObject(unprocessedObject); //----> This is where exception is being thrown
}
}
}
public class ServiceOne
{
[Transaction]
public List<MyType> FindUnprocessedObjects()
{
return TestRepository.FindUnprocessedObjects();
}
}
public class ServiceTwo
{
[Transaction(TransactionPropagation.RequiresNew)]
public List<MyType> UpdateObject(MyType obj)
{
var myObj = this.GetCurrentSession().Merge(obj);
myObj.Processed = true;
}
}
We are stuck as we could not see a real reason whey above code is running some times without problem but throwing exception randomly. Please help.
Regards
Hi guys i need help here :)
Previously when I tried to pass only one variable, it was working fine. Now as soon as I am trying to pass 2/n-number of parameters by using Spring Integration, getting following 'payload' exceptions, which I am not clear about.
Exception I am getting is as follows:
[2014-10-31 12:12:43,943][WARN ]GatewayProxyFactoryBean$MethodInvocationGateway.doSendAndReceive: failure occurred in gateway sendAndReceive
org.springframework.messaging.converter.MessageConversionException: failed to convert object to Message
at org.springframework.integration.support.converter.SimpleMessageConverter.toMessage(SimpleMessageConverter.java:85)
at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:112)
at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:103)
...
Caused by: org.springframework.messaging.MessagingException: At most one parameter (or expression via method-level #Payload) may be mapped to the payload or Message. Found more than one on method [public abstract java.util.List com.dao.PersonalinfoDao.queryExecute(java.lang.String,java.lang.String)]
at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper.throwExceptionForMultipleMessageOrPayloadParameters(GatewayMethodInboundMessageMapper.java:235)
at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper.access$400(GatewayMethodInboundMessageMapper.java:77)
at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper$DefaultMethodArgsMessageMapper.toMessage(GatewayMethodInboundMessageMapper.java:337)
...
Bellow showing what I am doing for passing 2 parameters:
In my PersonalinfoDao.java file I have this:
public interface PersonalinfoDao {
/** Method to call a SQL query using spring integration mechanism */
public List<PersonalInfo> queryExecute(String firstname, String lastname);
}
In my PersonalinfoService.java file I have this:
public class PersonalinfoService {
#Autowired
private PersonalinfoDao personalinfoDao;
public List<PersonalInfo> dbConnect(String firstname, String lastname) {
List<PersonalInfo> personalinfoList = personalinfoDao.queryExecute(firstname, lastname);
return personalinfoList;
}
}
In Gateway definition file I have the following:
<!-- Mapper Declarations -->
<bean id="personalinfoMapper" class="com.support.PersonalinfoMapper"/>
<!-- Service Inheritance -->
<bean id="personalinfoService" class="com.service.PersonalinfoService"/>
<!-- Channels = For calling DAO interface methods in Spring Integration Mechanism one has to create request & response channels -->
<int:channel id="procedureRequestChannel"/>
<!-- Gateway = DAO Interface Method Mapped to Request & Response Channels -->
<int:gateway id="gateway_personalinfo" default-request-timeout="5000"
default-reply-timeout="5000"
service-interface="com.dao.PersonalinfoDao">
<int:method name="queryExecute" request-channel="procedureRequestChannel" />
</int:gateway>
<!-- Stored Procedure Outbound-Gateway = To call a database stored procedure -->
<int-jdbc:stored-proc-outbound-gateway id="outbound-gateway-storedproc-personalinfo"
request-channel="procedureRequestChannel"
data-source="dataSource"
stored-procedure-name="pkg_personalinfo_spring.proc_personalinfo_spring"
expect-single-result="true"
ignore-column-meta-data="true">
<!-- Parameter Definitions -->
<int-jdbc:sql-parameter-definition name="firstname" direction="IN"/>
<int-jdbc:sql-parameter-definition name="lastname" direction="IN"/>
<int-jdbc:sql-parameter-definition name="get_ResultSet" type="#{T(oracle.jdbc.OracleTypes).CURSOR}" direction="OUT"/>
<!-- Parameter Mappings Before Passing & Receiving -->
<int-jdbc:parameter name="firstname" expression="payload"/>
<int-jdbc:parameter name="lastname" expression="payload"/>
<int-jdbc:returning-resultset name="get_ResultSet" row-mapper="com.support.PersonalinfoMapper"/>
</int-jdbc:stored-proc-outbound-gateway>
I know that i am doing something wrong in this above gateway definition specially when using expression="payload"...because for any given Getway i can use only one payload. But as I am not clear how to do that by using Map/Array/List, can any one plz help me to resolve this?
Thank u so much :)
Probably the simplest way is to use a #Payload annotation:
public interface PersonalinfoDao {
/** Method to call a SQL query using spring integration mechanism */
#Payload("#args")
public List<PersonalInfo> queryExecute(String firstname, String lastname);
}
Or use a payload-expression="#args" in the XML declaration of the <gateway/>'s method.
The framework will then make the payload an Object[] and you can use payload[0], payload[1] etc in your expressions.
I have an issue when using the Binder implementation in MOXy.
Here is the input XML document (input.xml)
<?xml version="1.0" encoding="utf-8"?>
<root>
<unmapped />
</root>
And now, here is the source code used to unmarshal XML into a Binder instance and then update the XML from the corresponding Java object:
JAXBContext context = JAXBContext.newInstance(Input.class);
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document document = builder.parse(new File("input.xml"));
Binder<Node> binder = context.createBinder(Node.class);
Input input = (Input) binder.unmarshal(document);
binder.updateXML(input);
In the end, the very simple Input class file:
#XmlRootElement(name = "root")
public class Input {
#XmlAnyElement
protected Object[] elements;
}
When the updateXML() method is invoked, the following exception is thrown:
java.lang.NullPointerException
at org.eclipse.persistence.internal.jaxb.DomHandlerConverter.convertObjectValueToDataValue(DomHandlerConverter.java:97)
We have been able to confirm this issue and it looks like it will be a very quick fix. You can use the link below to track our progress on this issue.
http://bugs.eclipse.org/391237
UPDATE
A fix has been checked into the EclipseLink 2.5.0 stream, a nightly download can be obtained from the following location:
http://www.eclipse.org/eclipselink/downloads/nightly.php
We have also checked in a fix to the EclipseLink 2.4.2 stream. A nightly download can be obtained from the above location starting October 12, 2012.