Not able to access secured back end service through WSO2 EI - wso2

My requirement is to call a secured backend service through WSO2 EI 6,
So i tried to add the Property mediator and header mediator as below, but I am not able to access the secured API.
<header name="Authorization" scope="transport" value="Bearer 1e127891-c430-3312-87ab-a2ba23ef8a4d"/>
The whole API looks like below,
<?xml version="1.0" encoding="UTF-8"?>
<api context="/nexgen" name="ChainApis" publishSwagger="nexgen" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/getProviders">
<inSequence>
<header name="Authorization" scope="transport" value="Bearer 1e127891-c430-3312-87ab-a2ba23ef8a4d"/>
<send>
<endpoint key="LdapTest"/>
</send>
</inSequence>
<outSequence>
<log>
<property name="checklist" value="after call"/>
</log>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
And the Endpoint looks like below.
<endpoint name="LdapTest" xmlns="http://ws.apache.org/ns/synapse">
<http method="get" uri-template="https://******/***/1.0/getLdapUserData?userName=suresh">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
I even tried with the below property mediator too
<property expression="fn:concat('Bearer ', 'db9df6c0-dfd4-3fde-ba0f-b9a524f0c9b0')" name="Authorization" scope="transport" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
the below is the log i get in my log file.
TID: [-1234] [] [2020-02-07 14:35:56,703] INFO {org.apache.synapse.mediators.builtin.LogMediator} -
To: /nexgen/getProviders, MessageID: urn:uuid:c0409753-deb4-4c28-8d1e-23db599b4296,
Direction: request, Envelope:
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body/>
</soapenv:Envelope>
{org.apache.synapse.mediators.builtin.LogMediator}

Related

Datamapper Return Null WSO2

I have an API that will return XML data, I want to use datamapper to map some data and then return it to the client, but the API after using DataMapper keeps returning null.
see below
<?xml version="1.0" encoding="UTF-8"?>
<api context="/AllAdByCRN" name="AllAdByCRN" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope format="soap11" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<GetCustomerWaselNotCancelled xmlns="http://tempuri.org/">
<userName></userName>
<password></password>
<id></id>
<idType></idType>
<sequenceNumber></sequenceNumber>
<laborOffice></laborOffice>
</GetCustomerWaselNotCancelled>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args/>
</payloadFactory>
<header name="Action" scope="default" value=""/>
<call>
<endpoint>
<http format="soap11" method="post" uri-template="">
<timeout>
<duration>17000000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
<property expression="json-eval($.*)" name="responseData" scope="default" type="STRING"/>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<datamapper config="gov:datamapper/NewConfig.dmc" inputSchema="gov:datamapper/NewConfig_inputSchema.json" inputType="JSON" outputSchema="gov:datamapper/NewConfig_outputSchema.json" outputType="XML" xsltStyleSheet="gov:datamapper/NewConfig_xsltStyleSheet.xml"/>
<log level="custom">
<property expression="json-eval($.*)" name="responseData"/>
</log>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
I want to map data only not converting from XML to JSON.
You have to choose XML as input and output :
<datamapper config="gov:datamapper/NewConfig.dmc" inputSchema="gov:datamapper/NewConfig_inputSchema.json" inputType="XML" outputSchema="gov:datamapper/NewConfig_outputSchema.json" outputType="XML" xsltStyleSheet="gov:datamapper/NewConfig_xsltStyleSheet.xml"/>

Message Details are not shown in Apache ActiveMQ 5.16.3 with WSO2 EI 6.5.0

I'm using WSO2 EI 6.5.0 to send message to activemq 5.16.3. I have followed this blog steps to set up WSO2 EI and ActiveMQ.
API Code:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/activemqsapi" name="ActiveMQAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<log level="custom">
<property name="===ActiveMQAPI" value="is called===="/>
</log>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
<send>
<endpoint>
<address uri="jms:/WSO2EIQ?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.DestinationType=queue">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</address>
</endpoint>
</send>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Message Details are shown like below in activeMQ.
Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: org.apache.synapse.message.store.impl.commons.StorableMessage
As per this question i have added property in %ACTIVEMQ_HOME%\bin\win64\wrapper.conf which also not working.
wrapper.java.additional.13=Dorg.apache.activemq.SERIALIZABLE_PACKAGES="*"
Can anyone help me on this?
As per this doc, added below line in windows.bat file which resolved my issue.
org.apache.activemq.SERIALIZABLE_PACKAGES="*"
Now I can able to see newly posted message in active-mq console.

In wso2 esb i can send but i am not able to listen to websocket

In wso2 ESB, I am able to send data to WebSocket but I am not able to receive data.
I tried this with rest api of wso2 esb.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/test" name="test" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="true"/>
<log level="full">
<property name="message" value="********************************************input**********************"/>
</log>
<send>
<endpoint>
<http method="post" uri-template="ws://localhost:8080/websocket/server"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
outsequence:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="outflowDispatchSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="full">
<property name="message" value="************************************************"/>
</log>
</sequence>
with the above API, I am able to send data to the server as shown in below image.
Http request from postman.
But as shown in below image of the console, the response which i am getting is empty as no body present.
If I use proxy service with content-type mentioned as in esb documentation(link) in websocket server i am getting exception
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="dispatchSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property name="OUT_ONLY" value="true"/>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="true"/>
<property name="websocket.accept.contenType" scope="axis2" value="text/plain"/>
<send>
<endpoint>
<address uri="ws://localhost:8080/websocket/server"/>
</endpoint>
</send>
</sequence>
axis2.xml websocket configuration is:
<transportSender name="ws" class="org.wso2.carbon.websocket.transport.WebsocketTransportSender">
<parameter name="ws.outflow.dispatch.sequence" locked="false">outflowDispatchSeq</parameter>
<parameter name="ws.outflow.dispatch.fault.sequence" locked="false">outflowFaultSeq</parameter>
</transportSender>
So how to send and receive the data from websocket

call external web service from WSO2 ESB

I'm in an internel network and I want to create a service (ESB) to call an external get service.
for example my ESB service path: uri/esb/path/param1/param2
my external path: external/path/param1/param2
here my entry
<?xml version="1.0" encoding="UTF-8"?>
<api context="/services/KRI-getIndividualVehicleFuelco2" name="KRI-getIndividualVehicleFuelco2" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<property name="renault_error_format" scope="default" type="STRING" value="json"/>
<log level="custom">
<property name="getIndividualVehicleFuelco2" value="********** begin **********"/>
<property expression="get-property('RequestID')" name="RequestID"/>
</log>
<Delegation.DelegationIn>
<Jboss-Endpoint-Key>KRI-customAddressingTransformation.xml</Jboss-Endpoint-Key>
<Custom-Sequence-Header>KRI-commonsequences-processSpecialHeadersIn</Custom-Sequence-Header>
</Delegation.DelegationIn>
<loopback/>
</inSequence>
<outSequence>
<sequence key="KRI-commonsequences-genericErrorHandling"/>
<Delegation.DelegationOut>
<Jboss-Endpoint-Key>KRI-customAddressingTransformation.xml</Jboss-Endpoint-Key>
<Custom-Sequence-Header>KRI-commonsequences-processSpecialHeadersOut</Custom-Sequence-Header>
</Delegation.DelegationOut>
<log level="custom">
<property name="getIndividualVehicleFuelco2" value="********** end **********"/>
<property expression="get-property('RequestID')" name="RequestID"/>
</log>
</outSequence>
<faultSequence>
<loopback/>
</faultSequence>
</resource>
</api>
I created an endpoint with the base uri of the external service.
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="KIS-fuelco-PPD" xmlns="http://ws.apache.org/ns/synapse">
<address uri="http://kisre701.intra.com/kis/api/v2/individual-vehicle-fuelco2/"/>
</endpoint>
how can I parse parameters and send them to endpoint?

Different behaviors between ESB 4.9.0 and 4.8.1

I have this proxy service in ESB 4.8.1, when I test it with SoapUI 5.2.1. I got this problem:
Does not write the full log in the server console when a timeout rise, but when I change it to custom it works.
Does not return any response to SoapUI (payloadFactory does not work)
When I deploy it in ESB 4.9.0 it works perfectly. Its a bug from the older version? How can I fix it?
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="StockQuoteProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<send>
<endpoint>
<address uri="http://localhost:8089/mockStockQuoteProxySoap11Binding"
format="soap11">
<timeout>
<duration>1000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<errorCodes>101500,101501,101506,101507,101508</errorCodes>
<initialDuration>2000</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>3000</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<errorCodes>101504,101505</errorCodes>
<retriesBeforeSuspension>3</retriesBeforeSuspension>
<retryDelay>1</retryDelay>
</markForSuspension>
</address>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence>
<log level="full">
<property name="FALLO" value="DETALLES DEL ERROR!!"/>
<property name="message" expression="get-property('ERROR_MESSAGE')"/>
<property name="code" expression="get-property('ERROR_CODE')"/>
<property name="detail" expression="get-property('ERROR_DETAIL')"/>
<property name="exception" expression="get-property('ERROR_EXCEPTION')"/>
</log>
<payloadFactory>
<format>
<ns:MyResponse xmlns:ns="http://services.samples">
<ns:Error>Execution Error</ns:Error>
</ns:MyResponse>
</format>
</payloadFactory>
<header name="To" action="remove"/>
<property name="RESPONSE" value="true"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<send/>
</faultSequence>
</target>
<description/>
</proxy>
Thanks in advance.
Try with this fault sequence:
Steps:
Create my response message.
Use the enrich mediator to store the body in property OK.
Create a fault message.
Override the body with the property OK using the enrich mediator.
<payloadFactory>
<format>
<ns:getQuoteResponse xmlns:ns="http://services.samples">
<ns:return xmlns:ax21="http://services.samples/xsd">
<status>ERROR</status>
</ns:return>
</ns:getQuoteResponse>
</format>
</payloadFactory>
<log level="full">
<property name="MESSAGE" value="Mensaje despues del payloadFactory"></property>
</log>
<enrich>
<source clone="true" type="body"></source>
<target action="replace" type="property" property="OK"></target>
</enrich>
<makefault version="soap11">
<code xmlns:soap11Env="schemas.xmlsoap.org/soap/envelope/" value="soap11Env:EdnpointTimeout"/>
<reason value="timeout fault"/>
<role/>
</makefault>
<enrich>
<source type="property" clone="true" property="OK"/>
<target type="body"/>
</enrich>
<log level="full">
<property name="MESSAGE" value="Mensaje despues del enrich"></property>
</log>
<send/>
When I run this proxy this is what I get as the response and the console log. Were you expecting something like this?
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<ns:MyResponse xmlns:ns="http://services.samples">
<ns:Error>Execution Error</ns:Error>
</ns:MyResponse>
</soap:Body>
</soap:Envelope>
INFO - LogMediator To: /services/StockQuoteProxy.StockQuoteProxyHttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:44da8426-00fc-442a-b4e9-1a9a1dd948f2, Direction: request, FALLO = DETALLES DEL ERROR!!, message = Error connecting to the back end, code = 101503, detail = Error connecting to the back end, exception = null, Envelope: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body></soap:Body></soap:Envelope>