When Aegis data binding is added the soap request body is empty - soap

<jaxws:endpoint id="FacService"
address="/FacService" implementor="#facServiceProxyBean"
implementorClass="xxx.yyy.zzz.FacServiceSEI"
wsdlLocation="wsdl/FacService.wsdl" serviceName="fac:FacService"
endpointName="fac:FacServiceSEIPort">
<jaxws:features>
<ref bean="xsltFeature" />
</jaxws:features>
<jaxws:dataBinding>
<bean class="org.apache.cxf.aegis.databinding.AegisDatabinding">
</bean>
</jaxws:dataBinding>
</jaxws:endpoint>
Everything worked fine before adding Aegis data binding in my applicationContentCXF.xml file, But after adding the data binding the soap request body is empty for the request calls its making.
I am using <cxf.version>3.1.11</cxf.version>,<cxf.xjc.version>3.1.0</cxf.xjc.version>,<cxf.aegis.version>3.1.8</cxf.aegis.version>. Hope this version difference is not an issue.
I appreciate any help on this.

Related

How to get original text body in WSO2 mediation in case of HL7?

I've implemented a simple API service in WSO2 EI. The Input endpoint is configured to accept 'application/edi-hl7' essentially to read HL7 message. I perform certain transformations on the message and then need to respond with JSON. So, as part of the response JSON payload I also want to have original HL7 message sent as request payload and that too in original shape (not XML / JSON formatted).
Say my input is,
MSH|^~\&|ULTRA_V3.1|LAV|Web Portal|Web Portal|201810030949||ORU^R01|279857418|P|2.3.1|||AL|AL|AU
PID||3914950|21710425491^^^AUSHIC^MC~111111^^^^UR~5548391^^^^ULTRAREL||KAY^BRUCE^^^||19630604|M|||11 NJUONA AVE^^BAIURE BAY^WSN^2000||^^^^^^0243333323||||||21710425491
PV1||O|CSLI^KINUYMBER|||||214082JL^KOPRA^MARUTI^^KAYBB^DR
ORC|RE||18-15768981-000-0||R
OBR|1||18-15768981-000-0|000^PENDING^ULTRA^LAVLEI||20180914|201810030805|||CSKI||||201810030949||214082JL^KOPRA^MARUTI^^KAYBB^DR||TFT-0^GLU-0^CRP-0^RDA-0^MBA-0^LIP-0^FBE-0||683131368452|LAV^false|201810030949||LAB|I||^^^20180914|
And sample output is,
{"message": "MSH|^~\&|.....", "Otherkeys": "someVal"}
As part of message, I want original message as is and not SOAP body.
P.S. I need to remove \n\r available at the end of each line.
The main question is how can get the original message in original shape in the mediation flow.
Here is a sample API. Hope It helps.
Screenshot of the result
Just put payloadFactory Mediator in appropriate place in your Sequence.
<api xmlns="http://ws.apache.org/ns/synapse" name="Test" context="/Test">
<resource methods="POST" uri-template="/testHL">
<inSequence>
<log level="full"/>
<payloadFactory media-type="json">
<format>{"message": "$1", "Otherkeys": "someVal"}</format>
<args>
<arg evaluator="xml" expression="$body/*[1]"/>
</args>
</payloadFactory>
<respond/>
</inSequence>
</resource>
</api>

Getting Json error while using #variable()# matcher

I have a scenario where particular response data has to be used in the next request.
I used payload("{\"alarmName\":\"#variable('apiVersion')#\"}") But the execution is failing with exception. Below is the exception message.
{"__v":0,"minVal":18,"alarmName":"TempAlarm7","_id":"59d50f49e877251d1eea592d"}
Number of JSON entries not equal for element: '$.', expected '1' but was '4'
Any idea how to resolve it?
Regards
Geeks
This is because your actual Json message has multiple elements (__v, minVal, alarmName and _id). Your control Json message just defines the element alarmName. Citrus Json message validator is using this strict mode by default so it will count and check that all elements are defined in expected control Json message. This is why you get the error.
Two options here. Either add all missing elements in control Json message with #ignore# value or disable strict mode in Json message validator. Second option can be done by overwriting the Json message validator bean:
<bean id="defaultJsonMessageValidator" class="com.consol.citrus.validation.json.JsonTextMessageValidator">
<property name="strict" value="false"/>
</bean>

Camel and CXF: How to get the outbound message?

I have this camel route:
from("cxf:bean:endpointDocs01?loggingFeatureEnabled=true")
.to("direct:CBR")
.transform().method(WebServiceUtils.class,"response()")
.log("Outbound message: ${body}");
endpointDocs01 is defined in the blueprint like this:
<cxf:cxfEndpoint address="/documentos/" id="endpointDocs01"
serviceClass="com.adelco.webservice.ServiceDocs" wsdlURL="wsdl/wsdl03.wsdl">
<cxf:properties>
<entry key="schema-validation-enabled" value="true"/>
</cxf:properties>
</cxf:cxfEndpoint>
This route works with no problems including the schema-validation.
When I send a correct request, I can do "things" (in this case logging) using the last line of the exchange ".log("Outbound message: ${body}". In this case, the log shows this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<outputDocumento xmlns="http://webservice.adelco.com">
<respuesta>0</respuesta>
<mensaje>El mensaje [113282] fue recibido. Fecha recepciĆ³n Wed Apr 12 17:01:11 CLT 2017</mensaje>
</outputDocumento>
</soap:Body>
</soap:Envelope>
But, when I send a incorrect request, the line ".log("Log outbound message: ${body}" does nothing. However I get a response in the client (a Soap:Fault response)
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Unmarshalling Error: cvc-complex-type.2.4.a: Invalid content was found starting with element 'Sociedad'. One of '{"http://webservice.adelco.com":TipoMovimiento}' is expected.</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
Why this soap:Fault response in not logged?
Your route is invoked after unmarshalling. So if unmarshalling fails because of invalid input, the route does not trigger and does not log.
Read this article about CXF architecture.
Phase Interceptors
CXF provides an InterceptorChain implementation called the PhaseInterceptorChain. [...]
Let us take a hypothetical simplified example (NOTE: these phases and interceptors don't necessarily exist in CXF). Let us say we are parsing a SOAP message. We may want to have two phases. First, a dispatch phase which parses the soap headers and determines which service to route the Message to. Second, an unmarshal phase which binds the SOAP body to JAXB objects.
Fault Handling
At any point during processing, an interceptor may throw a Fault, or a derivative of a Fault like the SoapFault. This will cause the chain to stop invoking and unwind it. Unwinding consists of calling handleFault on each interceptor that was invoked in reverse order.
When a Fault occurs the processing is stopped and the interceptor chain unwinded. CXF uses different chains for messages (in & out) and Faults (in & out).
To use custom beans (which must implement PhaseInterceptor interface) as interceptors:
<cxf:cxfEndpoint address="/documentos/" id="endpointDocs01"
serviceClass="com.adelco.webservice.ServiceDocs" wsdlURL="wsdl/wsdl03.wsdl">
<cxf:properties>
<entry key="schema-validation-enabled" value="true"/>
</cxf:properties>
<cxf:inInterceptors>
<ref component-id="inInterceptorBean" />
</cxf:inInterceptors>
<cxf:outInterceptors>
<ref component-id="outInterceptorBean" />
</cxf:outInterceptors>
<cxf:outFaultInterceptors>
<ref component-id="outFaultInterceptorBean" />
</cxf:outFaultInterceptors>
</cxf:cxfEndpoint>
As #Allesandro has said, the chain would unwind on failure.
You could've added an onException clause:
onException(ValidationException.class)
.log("Outbound message: ${body}");
from("cxf:bean:endpointDocs01?loggingFeatureEnabled=true")
.to("direct:CBR")
.transform().method(WebServiceUtils.class,"response()")
.log("Outbound message: ${body}");

OAuth2RestTemplate The access token provided has expired

I was trying to find solution for a very long time and didn't find anything useful.
Now, straight to problem.
I have to use remote OAuth2 authentication server and I have credentials for using it. Authentication is used for REST service calls.
REST service are being called in 15 minutes interval and our application calls more than one URL in one iteration.
For the first time REST API is called, everything is allright, we get access token and it's useful.
After 1 hour, when access token expires and REST API is called again, we get following error:
The access token provided has expired
This error is shown sometimes once, sometimes twice or more.
After another 15 minutes REST API call is errorless again.
I tried to use property retryBadAccessTokens, but with no luck.
We are using spring-security-oauth2-2.0.8.RELEASE with following settings:
<bean id="oipRestTemplate" class="org.springframework.security.oauth2.client.OAuth2RestTemplate" scope="prototype">
<constructor-arg ref="oipClientCredentialsResourceDetail"/>
<property name="accessTokenProvider" ref="tokenProvider"/>
<property name="requestFactory" ref="httpComponentsClientHttpRequestFactory"/>
<property name="retryBadAccessTokens" value="true"/>
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" >
<property name="supportedMediaTypes">
<list>
<bean class="org.springframework.http.MediaType">
<constructor-arg value="application" />
<constructor-arg value="json" />
</bean>
</list>
</property>
</bean>
</list>
</property>
<property name="errorHandler">
<bean class="our.company.app.holders.MyResponseErrorHandler" />
</property>
</bean>
See if they are also giving you a Refresh Token. You use those to generate tokens on behalf of the user.
By the way, if you are calling every 15 minutes, I would just get new tokens every time. You don't want to do that when you are making thousands of calls per minute.... but 15 minutes? Not biggie.
We have a fairly high traffic system, and I'm noting that the failures we get are always right around the moment in time that the token is about to expire.
Is it possible that the client looks at the token, which is about to expire, sends it to the server, and now it is expired, the server rejects it.
If this is the case, we would need some buffer space of at least the time difference between when Oauth2RestTemplate looks at its copy of the token, and the server looks at the token.
I'm thinking of posting a mod to Oauth2RestTemplate itself.
if (accessToken == null || accessToken.isExpired())
ought be
if (accessToken == null || accessToken.isAboutToExpire())
with some config value of how early to declare.

Quartz Generator and exception handling

i have a flow that works as follows:
<flow name="ChatListener">
<quartz:inbound-endpoint jobName="eventTimer"
repeatInterval="${chatListener.pollingInterval}">
<quartz:event-generator-job />
</quartz:inbound-endpoint>
<filter ref="ActiveTrainingFilter" />
<component>
<singleton-object class="com.ChatListener.ChatListener" />
</component>
<not-filter>
<payload-type-filter expectedType="org.mule.transport.NullPayload" />
</not-filter>
<collection-splitter />
<vm:outbound-endpoint path="ChatMsgs"
exchange-pattern="one-way" />
<default-exception-strategy>
<vm:outbound-endpoint path="ErrorMsgs"/>
</default-exception-strategy>
</flow>
Now, what is actually hapenning is that the generator calls the singleton compnent which does some DB retrieval and returns a collection of a java bean class which i later split (the null filter is in case i want to stop the flow).
My problem is - suppose i have an error connecting to the db and the component's oninitialise fails. What would keep the generator from trying to call the component over and over again? (and producing an error every time).
It looks to me as if i've handling something not quite right, So what would be the good to implement it to deal with exceptions?
Any ideas? thanks in advance!
I would try the following:
Declare the quartz endpoint in a global manner,
Use it in the flow.
Create a custom exception strategy and use it in the flow too.
Inject the global quartz endpoint in this custom exception strategy.
In this strategy, if the exception caught is one you deem characteristic to unrecoverable failure, call endpoint.stop().
You would need to go through JMX to restart the endpoint after clearing the error condition.