JMeter JSON Assertion: Path must not end with a '.' or '..' - json

I'm trying to replicate the JMeter script described here: https://www.blazemeter.com/blog/selenium-vs-jmeter-which-one-should-you-choose-and-when -- specifically under the "Front End: Testing Custom Communication Channels".
The author talks about setting up JSON assertions to verify response data, which is where I'm stuck. I'll post my code at the end, but what I've done is setup a HTTP request to POST to https:\reqres.in\api\users, sending the JSON payload shown in the article:
{
"name": "new_user",
"job": "user_role"
}
I then have the HTTP Header Manager setup with the header "Content-Type" set to "application/JSON". Finally, there's a JSON response assertion I tried to setup to replicate the author's description. I checked the box for "Match as regular expression" and set the expected value as [0-9]+. (I'm guessing this is where I went horribly wrong.)
The script's view results tree listener shows that the script did get a response:
{"name":"new_user","job":"user_role","id":"86","createdAt":"2020-11-16T23:41:04.645Z"}
But the script failed because the assertion failed with this message:
Assertion error: false
Assertion failure: true Assertion failure
message: Path must not end with a '.' or '..'
Here's my full script:
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.1 r1853635">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="TestPlan.user_define_classpath"></stringProp>
</TestPlan>
<hashTree>
<Arguments guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments">
<elementProp name="host" elementType="Argument">
<stringProp name="Argument.name">host</stringProp>
<stringProp name="Argument.value">wsf.cdyne.com</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<stringProp name="Argument.desc">Host of Webservice</stringProp>
</elementProp>
</collectionProp>
</Arguments>
<hashTree/>
<ConfigTestElement guiclass="HttpDefaultsGui" testclass="ConfigTestElement" testname="HTTP Request Defaults" enabled="true">
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="HTTPSampler.domain">${host}</stringProp>
<stringProp name="HTTPSampler.port"></stringProp>
<stringProp name="HTTPSampler.protocol"></stringProp>
<stringProp name="HTTPSampler.contentEncoding"></stringProp>
<stringProp name="HTTPSampler.path"></stringProp>
<stringProp name="HTTPSampler.concurrentPool">4</stringProp>
<stringProp name="HTTPSampler.connect_timeout"></stringProp>
<stringProp name="HTTPSampler.response_timeout"></stringProp>
</ConfigTestElement>
<hashTree/>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Number of Users" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">2</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">5</stringProp>
<stringProp name="ThreadGroup.ramp_time">5</stringProp>
<longProp name="ThreadGroup.start_time">1375525852000</longProp>
<longProp name="ThreadGroup.end_time">1375525852000</longProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
</ThreadGroup>
<hashTree>
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Rest Request" enabled="true">
<boolProp name="HTTPSampler.postBodyRaw">true</boolProp>
<elementProp name="HTTPsampler.Arguments" elementType="Arguments">
<collectionProp name="Arguments.arguments">
<elementProp name="" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">false</boolProp>
<stringProp name="Argument.value">{
"name": "new_user",
"job": "user_role"
}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</elementProp>
<stringProp name="HTTPSampler.domain">reqres.in</stringProp>
<stringProp name="HTTPSampler.port"></stringProp>
<stringProp name="HTTPSampler.protocol">https</stringProp>
<stringProp name="HTTPSampler.contentEncoding"></stringProp>
<stringProp name="HTTPSampler.path">\api\users</stringProp>
<stringProp name="HTTPSampler.method">POST</stringProp>
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
<stringProp name="HTTPSampler.embedded_url_re"></stringProp>
<stringProp name="HTTPSampler.connect_timeout"></stringProp>
<stringProp name="HTTPSampler.response_timeout"></stringProp>
</HTTPSamplerProxy>
<hashTree>
<HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP Header Manager" enabled="true">
<collectionProp name="HeaderManager.headers">
<elementProp name="" elementType="Header">
<stringProp name="Header.name">Content-Type</stringProp>
<stringProp name="Header.value">application/JSON</stringProp>
</elementProp>
</collectionProp>
</HeaderManager>
<hashTree/>
<JSONPathAssertion guiclass="JSONPathAssertionGui" testclass="JSONPathAssertion" testname="JSON Assertion on id" enabled="true">
<stringProp name="JSON_PATH">$.</stringProp>
<stringProp name="EXPECTED_VALUE">[0-9]+</stringProp>
<boolProp name="JSONVALIDATION">true</boolProp>
<boolProp name="EXPECT_NULL">false</boolProp>
<boolProp name="INVERT">false</boolProp>
<boolProp name="ISREGEX">true</boolProp>
</JSONPathAssertion>
<hashTree/>
<JSONPathAssertion guiclass="JSONPathAssertionGui" testclass="JSONPathAssertion" testname="JSON Assertion on createdAt" enabled="false">
<stringProp name="JSON_PATH">$.</stringProp>
<stringProp name="EXPECTED_VALUE">[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}Z</stringProp>
<boolProp name="JSONVALIDATION">true</boolProp>
<boolProp name="EXPECT_NULL">false</boolProp>
<boolProp name="INVERT">false</boolProp>
<boolProp name="ISREGEX">true</boolProp>
</JSONPathAssertion>
<hashTree/>
</hashTree>
</hashTree>
<ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>false</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>false</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>true</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>true</responseDataOnError>
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<hostname>true</hostname>
<threadCounts>true</threadCounts>
<sampleCount>true</sampleCount>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
<ResultCollector guiclass="StatGraphVisualizer" testclass="ResultCollector" testname="Aggregate Graph" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>false</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>false</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>true</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>true</responseDataOnError>
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<hostname>true</hostname>
<threadCounts>true</threadCounts>
<sampleCount>true</sampleCount>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
</hashTree>
</hashTree>
</jmeterTestPlan>

There are several problems with your script:
You need to use forward slashes in your request path like /api/users
More information: HTML Uniform Resource Locators
Correct mime type for JSON is application/json, for HTTP Headers the names are case-insensitive but the values MAY be case sensitive
More information: HTTP Headers Specification
You need to provide a Json Path expression which will match the value you're trying to assert, to wit $.id instead of $.
More information: API Testing With JMeter and the JSON Extractor

You forgot the key name as createdAt in JSON path expressions
$.createdAt
and id
$.id
You can't have JSON expression as $.

Related

Reading a .txt file in WSO2 Integration Studio

Is it possible to read a .txt file which has "|" as seperator using smooks? The file is similar to a normal csv file, only the extension is .txt. For csv we make use of "csv-reader", what can I use for reading a .txt file? Or is there any way to convert the .txt file into .csv in WSO2 Integration Studio?
This is the content of my file:
SYS_CD|PRO_CD|LOC_CD|AVA_QTY|RESQTY|PRO_QTY
POS|15|90|00|0|067656400
This is how I am calling the Smooks in my Proxy.
<smooks config-key="Smooks-config-file">
<input type="text"/>
<output type="xml"/>
</smooks>
This is my smooks-config-file
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="Smooks-config-file" xmlns="http://ws.apache.org/ns/synapse">
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.5.xsd">
<csv:reader fields="SYS_CD,PRO_CD,LOC_CD,AVA_QTY,RESQTY,PRO_QTY" separator="|" skipLines="1"/>
</smooks-resource-list>
</localEntry>
You can use the Smooks Mediator for this. You can simply read the file and use the property separator="|" to split the records by "|" and parse it to an XML.
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.5.xsd">
<csv:reader fields="name,age,$ignore$,address" separator="|" skipLines="1"/>
</smooks-resource-list>
Following is a VFS working sample.
Consumer Proxy
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="Consumer" startOnLoad="true" transports="vfs" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<log description="Log student file records" level="full"/>
<smooks config-key="smooks">
<input type="text"/>
<output type="xml"/>
</smooks>
<log description="Log student file records After===========" level="full"/>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
<parameter name="transport.PollInterval">3</parameter>
<parameter name="transport.vfs.ContentType">text/plain</parameter>
<parameter name="transport.vfs.FileURI">file:///home/ycr/workspace/wso2/file/in</parameter>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.vfs.MoveAfterFailure">file:///home/ycr/workspace/wso2/file/out</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
<parameter name="transport.vfs.FileNamePattern">.*\.txt</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///home/ycr/workspace/wso2/file/out</parameter>
</proxy>
Smooks Config
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="smooks" xmlns="http://ws.apache.org/ns/synapse">
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.5.xsd">
<csv:reader fields="SYS_CD,PRO_CD,LOC_CD,AVA_QTY,RESQTY,PRO_QTY" separator="|" skipLines="1"/>
</smooks-resource-list>
</localEntry>
Output
[2022-09-20 08:24:24,200] INFO {LogMediator} - {proxy:Consumer} To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:1FE89F7256E5FF52E91663676664208, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><text xmlns="http://ws.apache.org/commons/ns/payload">SYS_CD|PRO_CD|LOC_CD|AVA_QTY|RESQTY|PRO_QTY
POS|15|90|00|0|067656400
</text></soapenv:Body></soapenv:Envelope>
[2022-09-20 08:24:24,204] INFO {LogMediator} - {proxy:Consumer} To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:1FE89F7256E5FF52E91663676664208, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><csv-set><csv-record number="1"><SYS_CD>POS</SYS_CD><PRO_CD>15</PRO_CD><LOC_CD>90</LOC_CD><AVA_QTY>00</AVA_QTY><RESQTY>0</RESQTY><PRO_QTY>067656400</PRO_QTY></csv-record></csv-set></soapenv:Body></soapenv:Envelope>

Does JMeter 5 works with JUnit 5?

I'm having trouble while trying to run JUnit 5 test suite using jmeter-maven-plugin version 3. The setup and tear down phases of the test suite are not invoked at all. However, the methods annotated with #Test are called.
My setup is this:
First project (contains the JUnit test case)
Dummy test suite (BasiTest.java):
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
#TestInstance(Lifecycle.PER_CLASS)
public class BasicTest {
public BasicTest() {
}
#Test
public void passingTest() {
System.out.println("I'm a simple test that passes!");
}
#BeforeAll
public void setUp() {
System.out.println("setUp");
}
#AfterAll
public void tearDown() {
System.out.println("tearDown");
}
}
And the pom.xml file contains:
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Second project (should run the jar generated by the first project via jmeter-maven-plugin)
The pom.xml file:
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>configuration</id>
<goals>
<goal>configure</goal>
</goals>
</execution>
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<configuration>
<overrideRootLogLevel>debug</overrideRootLogLevel>
<jmeterExtensions>
<artifact>org.junit.jupiter:junit-jupiter:5.6.2</artifact>
</jmeterExtensions>
<junitLibraries>
<artifact>com.dummy.group.id:junit4sample:0.0.1-SNAPSHOT-tests</artifact>
</junitLibraries>
</configuration>
</plugin>
</plugins>
</build>
And the JMeter test scenario (JMX file) is:
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.2.1">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="TestPlan.user_define_classpath"></stringProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">1</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">10</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</stringProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
<boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
</ThreadGroup>
<hashTree>
<JUnitSampler guiclass="JUnitTestSamplerGui" testclass="JUnitSampler" testname="JUnit Request" enabled="true">
<stringProp name="junitSampler.classname">com.dummy.group.id.BasicTest</stringProp>
<stringProp name="junitsampler.constructorstring"></stringProp>
<stringProp name="junitsampler.method">passingTest</stringProp>
<stringProp name="junitsampler.pkg.filter"></stringProp>
<stringProp name="junitsampler.success">Test successful</stringProp>
<stringProp name="junitsampler.success.code">1000</stringProp>
<stringProp name="junitsampler.failure">Test failed</stringProp>
<stringProp name="junitsampler.failure.code">0001</stringProp>
<stringProp name="junitsampler.error">An unexpected error occurred</stringProp>
<stringProp name="junitsampler.error.code">9999</stringProp>
<stringProp name="junitsampler.exec.setup">false</stringProp>
<stringProp name="junitsampler.append.error">false</stringProp>
<stringProp name="junitsampler.append.exception">false</stringProp>
<boolProp name="junitsampler.junit4">true</boolProp>
</JUnitSampler>
<hashTree>
<ResultCollector guiclass="SummaryReport" testclass="ResultCollector" testname="Summary Report" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>true</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<sentBytes>true</sentBytes>
<url>true</url>
<threadCounts>true</threadCounts>
<idleTime>true</idleTime>
<connectTime>true</connectTime>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
</hashTree>
</hashTree>
</hashTree>
</hashTree>
</jmeterTestPlan>
I have to mention that the jar file containing the JUnit test cases (first project) is loaded by the junit plugin, the method annotated with #Test is running (I'm able to see the output in the console) but the setup and tear down phases are completely ignored.
Do you have any idea why?
Thanks a lot!
JMeter calls setUp and tearDown functions automatically
You need to call functions annotated with #BeforeClass and #AfterClass explicitly from separate JUnit Request samplers, the same applies to #BeforeAll and #AfterAll
I don't think JUnit 5 is officially supported, consider downgrading to JUnit 4, otherwise you will be left alone with your problems
More information: How to Use JUnit With JMeter

insert into database with anypoint studio

I would like to save the flow coming from this json file: https://gist.githubusercontent.com/Rajeun/3dbbe8ca240d479dbabe/raw/aba5d0ec9345b886426ab767376b7c9cb60c251f/person.json in a database using anypoint studio.
For this i'm using a http connector where i mentioned the link of the json file. and then i used a json-to-object transformer and a database connector.
In my db i have a table with id, token, tel "int" and email is a varchar
-(I tested the connection and its working well).
when i run my code:
ERROR 2015-03-20 13:14:05,522 [main] org.mule.module.launcher.application.DefaultMuleApplication: null
java.lang.NullPointerException
at org.mule.module.db.internal.config.domain.query.QueryTemplateBeanDefinitionParser.parseParameterizedQuery(QueryTemplateBeanDefinitionParser.java:136) ~[mule-module-db-3.6.1.jar:3.6.1]
at org.mule.module.db.internal.config.domain.query.QueryTemplateBeanDefinitionParser.doParse(QueryTemplateBeanDefinitionParser.java:62) ~[mule-module-db-3.6.1.jar:3.6.1]
at org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser.parseInternal(AbstractMuleBeanDefinitionParser.java:295) ~[mule-module-spring-config-3.6.1.jar:3.6.1]
at org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:59) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.mule.config.spring.MuleHierarchicalBeanDefinitionParserDelegate.parseCustomElement(MuleHierarchicalBeanDefinitionParserDelegate.java:98) ~[mule-module-spring-config-3.6.1.jar:3.6.1]
at org.mule.config.spring.MuleHierarchicalBeanDefinitionParserDelegate.parseCustomElement(MuleHierarchicalBeanDefinitionParserDelegate.java:140) ~[mule-module-spring-config-3.6.1.jar:3.6.1]
******************************************************************************
Config:
<mule xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="www.gist.githubusercontent.com" port="80" doc:name="HTTP Listener Configuration"/>
<db:mysql-config name="MySQL_Configuration" host="localhost" port="3306" user="root" database="mulesoft" doc:name="MySQL Configuration"/>
<db:template-query name="Template_Query" doc:name="Template Query">
<db:parameterized-query/>
</db:template-query>
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="Rajeun/3dbbe8ca240d479dbabe/raw/aba5d0ec9345b886426ab767376b7c9cb60c251f/person.json" doc:name="HTTP"/>
<json:json-to-object-transformer returnClass="myclass" doc:name="JSON to Object"/>
<response>
<logger message="c bon" level="INFO" doc:name="Logger"/>
</response>
<response>
<db:insert config-ref="MySQL_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[INSERT INTO push(id, token, tel, email) VALUES (2,2,3,#[payload['userImage']])]]></db:parameterized-query>
</db:insert>
</response>
</flow>
</mule>
Remove the empty template query:
<db:template-query name="Template_Query" doc:name="Template Query">
<db:parameterized-query />
</db:template-query>
Also, does 'myclass' exist? if not try just using a map:
<json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/>
Also It looks like you want to retrieve that JSON file from the specified URL. For that you want the http:request not http:listener. http:listener is used as a message source waiting for requests to your app.
You should use the http:request to request the file and trigger it using a polling message source:
<http:request-config name="HTTP_Request_Configuration" host="www.gist.githubusercontent.com" port="80" doc:name="HTTP Request Configuration"/>
<flow name="testFlow">
<poll>
<http:request config-ref="HTTP_Request_Configuration" path="Rajeun/3dbbe8ca240d479dbabe/raw/aba5d0ec9345b886426ab767376b7c9cb60c251f/person.json" method="GET" doc:name="HTTP"/>
</poll>
</flow>
See: http://www.mulesoft.org/documentation/display/current/HTTP+Request+Connector
And: http://www.mulesoft.org/documentation/display/current/Poll+Reference

Solr issues with MAMP MySQL Data Import

I am having a problem trying to get Solr to connect with MySQL running on my local MAMP installation to do a data import.
I have setup my data-config.xml file like so:
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:8889/***"
user="root"
password="root"
batchSize="-1"
readOnly="true" />
<document>
<entity name="id" query="SELECT show_id AS 'id', name, description FROM ***;">
<field column="show_id" name="id" />
<field column="name" name="name" />
<field column="description" name="description" />
</entity>
</document>
</dataConfig>
I have also added the following to my solrconfig.xml file:
<lib dir="../../../libexec/contrib/dataimporthandler/lib" regex=".*\.jar" />
<lib dir="../../../libexec/dist/" regex="solr-dataimporthandler-.*\.jar" />
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">db-data-config.xml</str>
</lst>
</requestHandler>
<lib dir="../../../libexec/dist/mysql/" regex="mysql-connector-java-\d.*\.jar" />
I run the following to do a data import:
http://localhost:8983/solr/collection1/dataimport?command=full-import&debug=true&verbose=true
But I get the following:
org.apache.solr.handler.dataimport.DataImportHandlerException: Unable to execute query: SELECT show_id AS 'id', name, description FROM tbl_hbo_shows; Processing Document # 1 at org.apache.solr.handler.dataimport.DataImportHandlerException.wrapAndThrow(DataImportHandlerException.java:71) at org.apache.solr.handler.dataimport.JdbcDataSource$ResultSetIterator.<init>(JdbcDataSource.java:283) at org.apache.solr.handler.dataimport.JdbcDataSource.getData(JdbcDataSource.java:240) at org.apache.solr.handler.dataimport.JdbcDataSource.getData(JdbcDataSource.java:44) at org.apache.solr.handler.dataimport.DebugLogger$2.getData(DebugLogger.java:188) at org.apache.solr.handler.dataimport.SqlEntityProcessor.initQuery(SqlEntityProcessor.java:59) at org.apache.solr.handler.dataimport.SqlEntityProcessor.nextRow(SqlEntityProcessor.java:73) at org.apache.solr.handler.dataimport.EntityProcessorWrapper.nextRow(EntityProcessorWrapper.java:243) at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:476) at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:415) at org.apache.solr.handler.dataimport.DocBuilder.doFullDump(DocBuilder.java:330) at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:232) at org.apache.solr.handler.dataimport.DataImporter.doFullImport(DataImporter.java:416) at org.apache.solr.handler.dataimport.DataImporter.runCmd(DataImporter.java:480) at org.apache.solr.handler.dataimport.DataImportHandler.handleRequestBody(DataImportHandler.java:189) at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:135) at org.apache.solr.core.SolrCore.execute(SolrCore.java:1967) at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:777) at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:418) at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:207) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:455) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255) at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) at org.eclipse.jetty.server.Server.handle(Server.java:368) at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489) at org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53) at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:942) at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1004) at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:640) at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) at org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72) at org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) at java.lang.Thread.run(Thread.java:745) Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. at sun.reflect.GeneratedConstructorAccessor21.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:408) at com.mysql.jdbc.Util.handleNewInstance(Util.java:377) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1036) at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:338) at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2232) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2265) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2064) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:790) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44) at sun.reflect.GeneratedConstructorAccessor18.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:408) at com.mysql.jdbc.Util.handleNewInstance(Util.java:377) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:395) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325) at org.apache.solr.handler.dataimport.JdbcDataSource$1.call(JdbcDataSource.java:153) at org.apache.solr.handler.dataimport.JdbcDataSource$1.call(JdbcDataSource.java:133) at org.apache.solr.handler.dataimport.JdbcDataSource.getConnection(JdbcDataSource.java:402) at org.apache.solr.handler.dataimport.JdbcDataSource.access$200(JdbcDataSource.java:44) at org.apache.solr.handler.dataimport.JdbcDataSource$ResultSetIterator.<init>(JdbcDataSource.java:270) ... 43 more Caused by: java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:213) at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:297) ... 59 more
I am running Solr 4.10.2 with MAMP Pro to handle the MySQL database connection. I have looked at various similar issues online but changes to my connection url etc. do not seem to resolve the issue.
Your help is appreciated.
I fixed it by finally finding out I was getting the error:
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Using point 1 of the answer at:
https://serverfault.com/questions/89955/unable-to-connect-to-mysql-through-jdbc-connector-through-tomcat-or-externally
...solved the problem!

How to returned with custmise response to client using Mule ESB

I am new for the mule esb but i know other ESB patterns
my issue is i have done a sample which will insert a data into DB.its working fine but its not giving any response to client so client is getting nothing from server
my sample code is
<mule xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<jdbc-ee:postgresql-data-source name="PostgreSQL_Data_Source" user="youtilitydba" password="45782dfff1" url="jdbc:postgresql://localhost:5432/sample" transactionIsolation="UNSPECIFIED" doc:name="PostgreSQL Data Source"/>
<jdbc-ee:connector name="Database" dataSource-ref="PostgreSQL_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>
<flow name="insertintoDBFlow1" doc:name="insertintoDBFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" path="httpPost"/>
<logger message="log about input message: #[payload]" level="INFO" doc:name="Logger"/>
<json:json-to-object-transformer doc:name="JSON to Object" returnClass="java.util.Map"></json:json-to-object-transformer>
<jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryKey="INSERT_TOKEN" queryTimeout="-1" connector-ref="Database" doc:name="Database">
<jdbc-ee:query key="INSERT_TOKEN" value="insert into users(FirstName,lastname) values(#[message.payload.name],#[message.payload.id]);"/>
</jdbc-ee:outbound-endpoint>
</flow>
</mule>
and i am calling to this using sample JSON client like this
curl -H "Content-Type: application/json" -d '{"name":"kk","id":"anil"}' http://localhost:8081/httpPost
when i am running this json its giving nothing response but i wish to give response like this {"ResponseJSON":{"Body":{"Datalist":{"Data":"Successfully Rows inserted"}},"Status":"200"}}
how would i format this above format i used http response builder but there is nothing to do like this..
you need to add an Echo component, set the payload to the value you are looking for and add a HTTP Response Builder with status="200" and contentType="application/json".
Add the following lines after </jdbc-ee:outbound-endpoint> and before </flow>
<response>
<http:response-builder status="200" contentType="application/json" doc:name="HTTP Response Builder"/>
</response>
<response>
<set-payload value="{"Body":{"Datalist":{"Data":"Successfully Rows inserted"}},"Status":"200"}}" doc:name="Set Payload"/>
</response>
<echo-component doc:name="Echo"/>
Cheers,
-Marco.