Getting error while parsing JSON in Mule - mule-studio

I am making a webservice call from Mule to another system using mule anypoint studio. The call happens fine and I do see a message returned from the external system. Now i am trying to pass an input for that webservice call using JSON string. This value would be logged on the external system which we are making the call to. I am using Datamapper for that and selecting the JSON file in the data mapper configuration. The map is happening without any error but when I am invoking the mule flow(via http connector).
I see this error on console
Unexpected character ('N' (code 78)): was expecting double-quote to
start field name at [Source: java.io.InputStreamReader#687aae57;
line: 1, column: 3] ERROR 2016-08-23 18:42:44,405 [WatchDog_0]
org.jetel.graph.runtime.SingleThreadWatchDog: Error details:
org.jetel.exception.JetelRuntimeException: Component [JSON
READER:JSON_READER0] finished with status ERROR.
org.codehaus.jackson.JsonParseException: Unexpected character ('N' (code 78)): was expecting double-quote to start field name
Root Exception stack trace:
org.codehaus.jackson.JsonParseException: Unexpected character ('N' (code 78)): was expecting double-quote to start field name
at [Source: java.io.InputStreamReader
at [Source: java.io.InputStreamReader#
I thought the problem is with the JSON file but not able to figure out where.. My JSON file looks like
{"receiveMessageFromMule":"Invocation Message from Mule"}
Could anyone help ?

#Angel, according to the error the JSON data received with unquoted field names (doesn't have the double quotes,", for field names). You need to enable jackson mapper to handle the unquoted field names, this can be done by adding the JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES to the ObjectMapper configuration.
You can customize the JSON transformer by injecting the custom ObjectMapper using spring in mule. Below is the code snippet for reference
<spring:bean id="jacksonObjectMapper" class="org.codehaus.jackson.map.ObjectMapper" />
<spring:bean
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<spring:property name="targetObject" ref="jacksonObjectMapper" />
<spring:property name="targetMethod" value="configure" />
<spring:property name="arguments">
<spring:list>
<spring:value>ALLOW_UNQUOTED_FIELD_NAMES</spring:value>
<spring:value>true</spring:value>
</spring:list>
</spring:property>
</spring:bean>
<json:object-to-json-transformer mapper-ref="jacksonObjectMapper" />
Hope this helps

Related

Undeclared namespace prefix "soapenv" error while using web service consumer

I am using web service consumer in Mule4 and after configuration and deployed the application and triggered the target ARIBA SOAP service in logs I see below error:
org.apache.cxf.binding.soap.SoapFault: Error reading XMLStreamReader: Undeclared namespace prefix "soapenv"
at [row,col {unknown-source}]: [1,14]
When i explored the error I see it is an issue at target system end:], please let me know whether it is end system thrown error or any pointers on what would cause this issue
enter link description here
The link you shared seems pretty clear. It is an issue on SAP Ariba side. The solution is also shared in the same page:
The error message is as follows:
<fault xmlns="http://www.bea.com/wli/sb/context">
<errorCode>OSB-380001</errorCode>
<reason>java.lang.RuntimeException: javax.xml.soap.SOAPException: Error parsing
envelope: most likely due to an invalid SOAP message.: Undeclared namespace prefix
"soapenv" at [row,col {unknown-source}]: [1,14] </reason>
For some reason Ariba doesn't seem to be declaring the SOAP XML namespaces in its responses.
If you receive the invalid soap message response error or some other invocation error from Ariba, you must enable the following property in the Ariba sand box.
Application.Messaging.Channels.Util.IncludeNameSpaceDetailsInErrorResponse
You have to follow the instructions to configure Ariba to include the namespaces in responses.

Issues generating Enterprise jar for Salesforce Soap API; issue with generated WSDL XML from Salesforce

I've recently made some databasae changes to custom objects, and I'm trying to generate a new enterprise.jar to reflect these changes. I'm following all documentation located here for the process. I'll also note, with the exception of some new dependencies, I've followed this process before with no errors to generate the enterprise.jar file. So this is a process that has worked for my sandbox in the past, but we haven't had any structural changes to the database in a solid 5 years.
Following along with the steps is simple enough. I generate the XML file from my Salesforce login in my developer sandbox utilizing Enterprise WSDL (we clearly have Enterprise level service, just so that's established). From there, I go to the Maven repository, get force-wsc-48.0.0.jar from there (as per the current API version of my sandbox), and then download a few dependencies like rhino, ST, and antlr-runtime. I get all files together in a temp folder in my C drive and try running command:
java -classpath C:\temp\force-wsc-48.0.0.jar;C:\temp\rhino1_7R4\js.jar;C:\temp\ST-4.3.1.jar;\jdk\jdk1.8.0_251\lib\tools.jar;C:\temp\antlr-runtime-3.5.jar com.sforce.ws.tools.wsdlc C:\temp\enterprise.wsdl C:\temp\enterprise.jar
Here's where the trouble begins. Once I run this, I hit the following error:
Exception in thread "main" com.sforce.ws.wsdl.WsdlParseException: Parse error: Found invalid XML. could not determine namespace bound to element prefix xsd (position: TEXT seen ...ration value="ACTIONCALL_DUPLICATE_INPUT_PARAM">\r\n<xsd:annotation>... #17360:17)
at com.sforce.ws.wsdl.WsdlParser.next(WsdlParser.java:94)
at com.sforce.ws.wsdl.Definitions.read(Definitions.java:111)
at com.sforce.ws.wsdl.WsdlFactory.createFromInputStream(WsdlFactory.java:69)
at com.sforce.ws.wsdl.WsdlFactory.create(WsdlFactory.java:49)
at com.sforce.ws.codegen.Generator.generate(Generator.java:94)
at com.sforce.ws.tools.wsdlc.run(wsdlc.java:115)
at com.sforce.ws.tools.wsdlc.run(wsdlc.java:149)
at com.sforce.ws.tools.wsdlc.main(wsdlc.java:71)
Caused by: com.sforce.ws.ConnectionException: Found invalid XML. could not determine namespace bound to element prefix xsd (position: TEXT seen ...ration value="ACTIONCALL_DUPLICATE_INPUT_PARAM">\r\n<xsd:annotation>... #17360:17)
at com.sforce.ws.parser.XmlInputStream.next(XmlInputStream.java:138)
at com.sforce.ws.wsdl.WsdlParser.next(WsdlParser.java:90)
... 7 more
Caused by: com.sforce.ws.parser.XmlPullParserException: could not determine namespace bound to element prefix xsd (position: TEXT seen ...ration value="ACTIONCALL_DUPLICATE_INPUT_PARAM">\r\n<xsd:annotation>... #17360:17)
at com.sforce.ws.parser.MXParser.parseStartTag(MXParser.java:1826)
at com.sforce.ws.parser.MXParser.nextImpl(MXParser.java:1144)
at com.sforce.ws.parser.MXParser.next(MXParser.java:1111)
at com.sforce.ws.parser.XmlInputStream.next(XmlInputStream.java:136)
... 8 more
A snipped of the XML at error line:
<!--
These are the extension code to provide additional error information
-->
<simpleType name="ExtendedErrorCode">
<restriction base="xsd:string">
<enumeration value="ACTIONCALL_DUPLICATE_INPUT_PARAM">
<xsd:annotation>
<xsd:documentation>
Errors with this extended error code have the following properties: severity, actionCallName, parameterName
</xsd:documentation>
</xsd:annotation>
</enumeration>
<enumeration value="ACTIONCALL_DUPLICATE_OUTPUT_PARAM">
<xsd:annotation>
<xsd:documentation>
Errors with this extended error code have the following properties: severity, actionCallName, parameterName
</xsd:documentation>
</xsd:annotation>
</enumeration>
Parent schema:
<schema elementFormDefault="qualified" targetNamespace="urn:fault.enterprise.soap.sforce.com">
<import namespace="urn:enterprise.soap.sforce.com"/>
I don't know if it's necessary, but I'll note that there's no <xsd:schema...> at all in the XML file. xsd is used before this, but only to define element string types; eg: <element name="sessionId" type="xsd:string" nillable="true"/>
If I remove xsd prefix from everything that causes the error, I'll instead get the same error, but for soap instead of xsd. XML snippet of first instance of that:
<!-- Soap Binding -->
<binding name="SoapBinding" type="tns:Soap">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="login">
<soap:operation soapAction=""/>
<input>
<soap:header use="literal" message="tns:Header" part="LoginScopeHeader"/>
<soap:body parts="parameters" use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
There's no parent schema here.
Again, there is no <soap:schema...> defined in the XML. And if I remove all of the instances of using the soap prefix, I'll land on the following issue.
Exception in thread "main" com.sforce.ws.wsdl.WsdlParseException: targetNamespace not specified in wsdl:definitions
at com.sforce.ws.wsdl.Definitions.read(Definitions.java:115)
at com.sforce.ws.wsdl.WsdlFactory.createFromInputStream(WsdlFactory.java:69)
at com.sforce.ws.wsdl.WsdlFactory.create(WsdlFactory.java:49)
at com.sforce.ws.codegen.Generator.generate(Generator.java:94)
at com.sforce.ws.tools.wsdlc.run(wsdlc.java:115)
at com.sforce.ws.tools.wsdlc.run(wsdlc.java:149)
at com.sforce.ws.tools.wsdlc.main(wsdlc.java:71)
Again, not sure if it matters, but there's no <wsdl:definitions...> in the XML file.
I don't know if this is an issue of Salesforce generating a bad XML file (the issue occurs even in sandboxes I haven't made any database changes for, including production where I have an old but working enterprise.jar), if I don't have the right force-wsc jar file, if I'm not running it through the right version of Java (1.8, if it wasn't clear, but I've tried earlier versions of java and I just get the minor.major 52 error, which means it should be 8, as far as I know).
Any help pinpointing what the issue here is would be greatly appreciated. I'm more than open to suggestions. And if it is just Salesforce giving me a bad XML file, I can open a ticket there. I just want to make sure I'm not doing something wrong before I open a ticket.
After spending more time on this, and after coordinating with a co-worker who works on a different Salesforce project, we've discovered the following
1 Salesforce was absolutely giving a bad WSDL file.
2 The generation of the bad WSDL file only occurred because I was using a Firefox web browser. Using Chrome instead to access the WSDL generation fixed the issue, of all things.
So for any poor soul that comes across this issue in the future, I hope using Chrome fixes it for you as well.

Spring Batch Integration, Email to be sent out in case of JobInstanceAlreadyCompleteException

I would like to put a hook somewhere in the following code/config to be able to spot a JobInstanceAlreadyCompleteException and then email the production support team that this occurred.
I have tried a JobExecutionListener#beforeJob() method in Spring Batch, but the JobInstanceAlreadyCompleteException is occurring before job execution.
I am using this Spring Batch Integration configuration from the documentation:
<int:channel id="inboundFileChannel"/>
<int:channel id="outboundJobRequestChannel"/>
<int:channel id="jobLaunchReplyChannel"/>
<int-file:inbound-channel-adapter id="filePoller"
channel="inboundFileChannel"
directory="file:/tmp/myfiles/"
filename-pattern="*.csv">
<int:poller fixed-rate="1000"/>
</int-file:inbound-channel-adapter>
<int:transformer input-channel="inboundFileChannel"
output-channel="outboundJobRequestChannel">
<bean class="io.spring.sbi.FileMessageToJobRequest">
<property name="job" ref="personJob"/>
<property name="fileParameterName" value="input.file.name"/>
</bean>
</int:transformer>
I want to handle JobInstanceAlreadyCompleteException in case the same CSV file name appears as the job parameter. Do I extend org.springframework.integration.handler.LoggingHandler?
I notice that class is reporting the error:
ERROR org.springframework.integration.handler.LoggingHandler - org.springframework.messaging.MessageHandlingException: org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException: A job instance already exists and is complete for parameters={input.file.name=C:\Users\csv\file2015.csv}. If you want to run this job again, change the parameters.
The ERROR org.springframework.integration.handler.LoggingHandler is done from the default errorChannel which is reached from the <poller> on your <int-file:inbound-channel-adapter>.
So, to handle it manually your just need to specify your own error-channel there a go ahead with email sending:
<int-file:inbound-channel-adapter>
<int:poller fixed-rate="1000" error-channel="sendErrorToEmailChannel"/>
</int-file:inbound-channel-adapter>
<int-mail:outbound-channel-adapter id="sendErrorToEmailChannel"/>
Of course, you will have to do some ErrorMessage transformation before sending ti over e-mail, but that is already details of the target business logic implementation.

How to configure MessageEndpointMapping by namespace in NServiceBus

I am trying to configure my message endpoint mapping in my NServiceBus configuration by sending messages from different namespaces to different endpoints.
As such, I have configured the following in my web.config:
<MessageEndpointMappings>
<add Messages="Company.Messages.Accounts" Endpoint="ServiceInput" />
<add Messages="Company.Messages.Payments" Endpoint="ServiceInput" />
<add Messages="Company.Messages.Cancellations" Endpoint="ServiceInput" />
<add Messages="Company.Messages.Notifications" Endpoint="ServiceInput" />
</MessageEndpointMappings>
However, when my application starts, I receive the following exception:
Spring.Objects.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested PropertyAccessExceptions are:
[Spring.Core.TypeMismatchException: Cannot convert property value of type [System.Collections.Hashtable] to required type [System.Collections.IDictionary] for property 'MessageOwners'., Inner Exception: System.ArgumentException: Problem loading message assembly: Company.Messages.Payments ---> System.IO.FileNotFoundException: Could not load file or assembly 'Company.Messages.Payments' or one of its dependencies. The system cannot find the file specified.
File name: 'Company.Messages.Payments'
What I find interesting is that it seems to have found Company.Messages.Accounts but failed on the second configured line. I thought that maybe it didn't like have them all go to the same endpoint, but changing this configuration to have them go different endpoints didn't change the error message I received.
What am I doing wrong? Is it not possible to segment messages by namespace (all I have seen is by type and by assembly)?
Thanks,
Steve
NSB only supports mapping of assemblies or individual types to endpoints. Namespaces are not supported, I suggest you split you message assembly into separate assemblies for each of your endpoints.
According to this page you can specify a type:
http://docs.particular.net/nservicebus/messaging/message-owner
Specific types can be configured by using their qualified name: "namespace.type, assembly".
As of NServiceBus v3.3 namespaces can be used to filter message mappings
http://docs.particular.net/nservicebus/messaging/message-owner

Where to define <Environment...> elements in JBoss

I try to define environment entries in JBoss 5.1 and added following to the server/default/deploy/jbossweb.sar/context.xml file:
<Environment type="java.lang.String" name="name" value="value" />
Following error occurs on startup:
2010-01-26 14:50:08,383 ERROR
[org.jboss.web.tomcat.service.deployers.JBossContextConfig]
(main) XML error parsing: context.xml
org.jboss.xb.binding.JBossXBException:
Failed to parse source: Resource
cannot appear in this position.
Expected content of Context is
unordered_sequence: attributes?
InstanceListener* Realm? Parameters*
Manager? Loader? Valve* SessionCookie?
Resources? Listener*
Where may I define environment entries in JBoss (but outside of application's EAR)?
This article confirms that (likely) it is not possible to configure environment entries in JBoss. Author suggests to use PropertiesService as alternative.
Property configuration in properties-service.xml works great!