Custom Error Handler in Wso2 Mediation - mediator

In my In sequence mediatior, I need to process some logic on the input values and based on that i need to decide whether to call the webservice or return a fault. I have defined the sequence as following
<sequence xmlns="http://ws.apache.org/ns/synapse" name="m1">
<class name="com.myclass">
</class>
<makefault version="soap11">
<code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:Client"/>
<reason value="ERROR_MESSAGE"/>
<role>Acc</role>
<detail>Test Details</detail>
</makefault>
<log/>
</sequence>
The problem is by default the webservice is always passing fault information to the webservice. How do i make of the following
1. Incase the there is an custom exception thrown in Mediator, soap fault is thrown back to the webservice client.
2. Incase all the information are correct, the webservice is called properly and client gets the proper response.

You need to define a separate sequence to handle the faults. Then, in your InSequence, you need to set that fault sequence to the "onError" attribute. So your InSequence will look like
<sequence xmlns="http://ws.apache.org/ns/synapse" name="m1" onError="yourFaultSequence">
<class name="com.myclass">
</class>
<log/>
<send/>
</sequence>
Above configuration was added to give an idea. Note the onError attribute.
Following sample will also help.

Related

Validate XML against schematron using SAXON EE edition

I am evaluating SAXON EE edition to validate XML against xsd and schematron.
Can someone help me in resolving the following queries:
While validating xml document against xsd, can we also get xpath of that error node along with errors in plain text. Currently I am getting error only.
Can we validate xml against schematron using Saxon EE version? Any code sample would be a great help.
Thanks.
1. While validating xml document against xsd, can we also get xpath of that error node.
Yes, the error information includes an XPath reference to the invalid node (in most cases: there are some cases such as duplicate IDs where there isn't one specific node in error).
If you generate an XML validity report using SchemaValidator.SetValidityReporting() then the resulting report will include the path information. Here's an example:
<?xml version="1.0" encoding="UTF-8"?>
<validation-report xmlns="http://saxon.sf.net/ns/validation"
system-id="file:/Users/mike/repo2/samples/data/books-invalid.xml">
<error line="3"
column="17"
path="/Q{}BOOKLIST[1]/Q{}BOOKS[1]/#x"
xsd-part="1"
constraint="cvc-complex-type.3">Attribute #x is not allowed on element <BOOKS></error>
<error line="10"
column="17"
path="/Q{}BOOKLIST[1]/Q{}BOOKS[1]/Q{}ITEM[1]/Q{}PRICE[1]"
xsd-part="2"
constraint="cvc-datatype-valid.1">The content "$0.2" of element <PRICE> does not match the required simple type. Cannot convert string to decimal: $0.2</error>
<error line="21"
column="20"
path="/Q{}BOOKLIST[1]/Q{}BOOKS[1]/Q{}ITEM[2]/Q{}PUB-DATE[1]"
xsd-part="2"
constraint="cvc-datatype-valid.1">The content "2002-02-31" of element <PUB-DATE> does not match the required simple type. Invalid date "2002-02-31" (Non-existent date)</error>
<error line="42"
column="22"
path="/Q{}BOOKLIST[1]/Q{}BOOKS[1]/Q{}ITEM[3]/Q{}REPUTATION[1]"
xsd-part="1"
constraint="cvc-complex-type.2.4">In content of element <ITEM>: The content model does not allow element <REPUTATION> to appear immediately after element <WEIGHT>. No further elements are allowed at this point. </error>
<meta-data>
<validator name="SAXON-EE" version="9.8.0.9"/>
<results errors="4" warnings="0"/>
<schema file="books.xsd" xsd-version="1.1"/>
<run at="2018-03-07T15:22:04.847Z"/>
</meta-data>
</validation-report>
You can also get the information if you supply an IInvalidityHandler as a callback to the SchemaValidator, though this requires a bit more digging. Saxon calls your IInvalidityHandler supplying a StaticError object (which is a bit of a misnomer). The StaticError object doesn't have the path information directly available, but it contains a reference to an XPathException object which can be cast to a ValidationException, and ValidationException has a method getPath() which returns this information if available.
2. Can we validate xml against schematron.
Saxon doesn't include a schematron validator per se, though many of the third-party tools that do schematron validation make use of Saxon "under the hood". I'm not up-to-date with the situation on .NET - but essentially there are two kinds of Schematron processor: those that generate XSLT code from the schematron schema (which typically use Saxon both to generate the XSLT and to execute it), and "native" processors. Searching for "schematron on .NET" gives you quite a number of projects, but I have no idea of their current status or quality.

Custom configuration not getting reflected in applicationcontext.xml

I am using custom configuration for my RabbitMQ connectivity. I'm connecting to multiple hosts.
<context:property-placeholder location="classpath:/test_setting.properties" ignore-unresolvable="true"/>
...
<rabbit:connection-factory id="testConnectionFactory"
addresses="${test.addresses}"
username="${test.username}"
password="${test.password}"
virtual-host="${test.virtualhost}"
connection-factory="rhb" />
<bean id="rhb" class="com.rabbitmq.client.ConnectionFactory">
<property name="requestedHeartbeat" value="${test.connection.heartbeat}" />
</bean>
My property file looks like: test_setting.properties
test.queue=testQueue
test.virtualhost=/global_api
test.addresses=host1:5672,
host2:5672
test.username=guest
test.password=guest
test.connection.heartbeat=60
test.consumer.concurrency=1
When i trigger my main class properties not getting replaced inside applicationcontext.xml in Spring. Thereby I am getting connection refused exception.
Please note if I hard code the connection details everything works fine.
ignore-unresolvable="true"
It looks like the file is not being found - change that to false to see the error.
Also, turning on DEBUG logging for org.springframework will provide a great deal of information about property resolution.
test.addresses=host1:5672,
host2:5672
Properties have to be on one line (you can terminate a line with \) for continuation.
test.addresses=host1:5672, \
host2:5672

ANT SCRIPT: http url property value is not loaded and giving error java.net.MalformedURLException: For input string: "${amx.admin.port}"

I am busy with automation of tasks using ant script.
In main properties ( Connection.properties) file I had defined properties values which will be used at runtime in script.
admin.url.protocol=${amx.admin.url.protocol}
amx.admin.hostname=shrijeet
amx.admin.port=8120
amx.admin.url=${amx.admin.url.protocol}://${amx.admin.hostname}:${amx.admin.port}
Later in script another property file (build.properties) is used at runtime where it uses above values as below.
adminURL=http://${amx.admin.hostname}:${amx.admin.port}
Now issue is , whenever script is reading value of "adminURL" property it fails with below error
[AMXAdminTask] 08 Apr 2017 18:15:14 WARN - TIBCO-AMX-CLI-000743: Failed to parse the admin base
url 'http://${amx.admin.hostname}:${amx.admin.port}'. Not a valid url.
[AMXAdminTask] java.net.MalformedURLException: For input string: "${amx.admin.port}".
when I hard code value like adminURL=http://shrijeet:8120 , then script works fine. But I need hostname:port number to be externalised in main connection.properties.
Please suggect is there is any other way to externalize http url type of properties.
I see i have found solution
where i am creating temporary file ,say build-temp.properties and given tokens in property.
Ex
adminURL=adminuRL_temp
And then i am replacing token with values mentioned in Connection.properies file.
In build-temp.properties file:
adminURL=adminurl_temp
username=username_temp
password=password_temp
Target:
<target name="setBuildProperty">
<copy file="${ScriptFilesPath}/StandAloneTibcohost/build-temp.properties" tofile="${ScriptFilesPath}/StandAloneTibcohost/build.properties" overwrite="true"/>
<replace file="${ScriptFilesPath}/StandAloneTibcohost/build.properties" propertyFile="${ScriptFilesPath}/Connection.properties">
<replacefilter token="adminurl_temp" property="adminurl"/>
<replacefilter token="username_temp" property="username"/>
<replacefilter token="password_temp" property="password"/>
</replace>
</target>
This works perfectly and values are now getting updated.

Set the maxParameterCount attribute on the Connector JBoss EAP6

I have a main page with many elements included to another page but with different parameters using jsf 2.2 and it works with seam & jboss 5, but with jboss EAP6 (without seam) it gives me those errors :
java.lang.IllegalStateException: JBWEB002004: More than the maximum number of request parameters (GET plus POST) for a single request (512) were detected. Any parameters beyond this limit have been ignored. To change this limit, set the maxParameterCount attribute on the Connector.
org.apache.tomcat.util.http.Parameters.addParameter(Parameters.java:184)
org.apache.tomcat.util.http.Parameters.processParameters(Parameters.java:360)
org.apache.tomcat.util.http.Parameters.processParameters(Parameters.java:213)
org.apache.catalina.connector.Request.parseParameters(Request.java:2858)
org.apache.catalina.connector.Request.getParameter(Request.java:1279)
org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:349)
com.sun.faces.context.RequestParameterMap.containsKey(RequestParameterMap.java:99)
java.util.Collections$UnmodifiableMap.containsKey(Collections.java:1337)
org.jboss.weld.jsf.WeldPhaseListener.getConversationId(WeldPhaseListener.java:171)
org.jboss.weld.jsf.WeldPhaseListener.activateConversations(WeldPhaseListener.java:99)
org.jboss.weld.jsf.WeldPhaseListener.beforePhase(WeldPhaseListener.java:85)
com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)
com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
Any idea to solve these?
I searched and I have found this :
<system-properties>
<property name="org.apache.tomcat.util.http.Parameters.MAX_COUNT" value="5000"/>
</system-properties>
I found that I have to add that to standalone.xml but when I tried it doesn't start.

Axis2 generates wrong WSDL, where is the error?

I've used NetBeans plugin "Axis2 Support" to create webservice from my pojo class.
When I go to create the client from wsdl file I get some errors.
Here is the message:
[ERROR] missing required property "style" of element "operation"
This is an example of element operation that generates the error:
<wsdl:operation name="addObjectPropertyAssertion">
<wsdl:input message="ns:addObjectPropertyAssertionRequest" wsaw:Action="urn:addObjectPropertyAssertion"/>
<wsdl:fault message="ns:EcourbStorageServiceInvalidURIException" name="EcourbStorageServiceInvalidURIException" wsaw:Action="urn:addObjectPropertyAssertionEcourbStorageServiceInvalidURIException"/>
<wsdl:fault message="ns:EcourbStorageServiceInvalidURIReferenceException" name="EcourbStorageServiceInvalidURIReferenceException" wsaw:Action="urn:addObjectPropertyAssertionEcourbStorageServiceInvalidURIReferenceException"/>
</wsdl:operation>
Deploying web service I've just some errors like this (I will correct it after, I don't think is the cause)
[WARN] We don't support method overloading. Ignoring [addRDFTriple]
Using some simple service operation in browser it works.
I found the solution: the problem was methods with void return. Set a return value of any type solves the problem.

Resources