I get an file.xml has some syntax errors whenever i tried setting a header for authentication in wso2 developer studio
<header name="Authentication" scope="default" value="Bearer code"/>
There is an issue in this configuration. ESB synapse can not validate your requirement with given configurations.
<header name="Authentication" scope="default" value="Bearer code"/>
You are going to add SOAP header as you define scope as "default". In WSO2 documentation, you may find sample scenarios for adding a header [1]
<header xmlns:m="http://org.synapse.example" xmlns:sym="http://services.samples/xsd" name="m:header1" scope="default" expression="//sym:symbol"/>
Change your configuration which will be compatible with standards.
[1] https://docs.wso2.com/display/ESB490/Header+Mediator
Related
I'm using WSO2 EI 6.3.0 and WSO2 Developer Studio 3.8.0.
I'm working with an ESB Project and a Proxy Service inside it.
The Proxy service is a simple pass through service;
it receives a request from a webapp and forward it to a
Soap Web Service, gets the response from the WS and gives
it back to the web app.
I realized this configuration following this tutorial:
https://youtu.be/3OsuGhEMQgc
The setup is very simple, everything worked fine until I found
a web service whose endpoint has http basic authentication.
I made it work thanks to this article:
https://medium.com/#Jenananthan/wso2-esb-how-to-invoke-basic-auth-protected-endpoint-service-5bcdd8290cb4
Here follows the xml that describes the proxy service:
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="ProxyWithBasicAuth" startOnLoad="true" trace="disable" transports="https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<endpoint name="endpoint_urn_uuid_xxxxxxxx-yyyy-zzzz-1111-234567892345">
<address trace="disable" uri="https://here.goes.the.uri.of.the.ws.endpoint"/>
</endpoint>
<inSequence>
<property value="this_is_the_username" name="username" scope="default" type="STRING"/>
<property value="this_is_the_password" name="password" scope="default" type="STRING"/>
<property expression="fn:concat($ctx:username,':',$ctx:password)" name="credentials" scope="default" type="STRING"/>
<property expression="fn:concat('Basic ', base64Encode($ctx:credentials))" name="Authorization" scope="transport" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
So, this configuration (xml file) is working, but I wrote all
the section that enables basic auth without using any visual or drag and drop element of the gui.
My questions are:
1) is this the right way to setup basic auth on a proxy service?
2) is there any gui (drag and drop) element that allows to do this setup visually?
Note: I do not need to struggle with basic authentication between
"clients" and the ESB Proxy Service; this question is about basic
authentication between ESB Proxy Service and an "external" web service.
What you have done is correct. To invoke a service secured with Basic Auth, we just have to set the Authorization header to the message. You could use Header Mediator[1] or the Property mediator (as you have already used) to do that. There is no special Mediator (or a GUI element in the Tool) specifically designed for setting the Authorization header.
Btw, you could consider storing passwords in the secure-vault[2] rather than having it in plain text in the Synapse configuration.
[1] https://docs.wso2.com/display/EI640/Header+Mediator
[2] https://docs.wso2.com/display/EI640/Working+with+Passwords+in+the+ESB+profile
I am new to WSO2, Can anyone of you please tell the process of consuming a web service using WSO2 developer studio ? and how i can transform the output to xml format from JSON ?
Thank you,
Sampath.
Firstly WSO2 developer studio is eclipse based IDE, so if you have used eclipse earlier it will be easier for you to understand.
Secondly , it is used to develop WSO2 code, now there are 2 options, either build a CAR file and add it in wso2 esb directly or connect to wso2 esb directly from eclipse and then upload the CAR file.
Lastly , if your output is JSON and you need XML as the response then use property mediator as
<property name="messageType" scope="axis2" type="STRING" value="application/xml"/>
<property name="contentType" scope="axis2" type="STRING" value="application/xml"/>
The link explains on how you can send a message to a service. Also the steps takes you through how it can be done in the WSO2 Developer Studio.
If you want to directly transform JSON to XML without any changes you can use the below two properties,
<property name="messageType" value="text/xml" scope="axis2"/>
<property name="ContentType" value="text/xml" scope="axis2"/>
But if you want to transform from JSON to XML with changes to the final payload you can use payload factory mediator.
I am facing an issue where the receiving application (consumer/listener of an IBM MQ) cannot handle MQHRF2 format and is expecting the raw MQSTR format instead.
When put a plain old XML message into the queue using WSO2 Integrator (v. 6.1.1), the receiving application sees:
RFH € zMQSTR z <mcd><Msd>jms_text</Msd></mcd> X<jms>
<Dst>queue://QUEUE_ALIAS</Dst><Tms>1532002363544</Tms><Dlv>2</Dlv></jms>
ahead of my XML message which starts right after the JMS tag.
How can I force WSO2 to put MQSTR instead of MQRFH2 into the Websphere MQ? I have tried the following property just before sending via my endpoint but it has no effect.
<property name="JMS_IBM_FORMAT" value="MQSTR" scope="transport" type="STRING" action="set"/>
<send>
<endpoint key="conf:/endpoints/MY_ENDPOINT.xml"/>
</send>
The endpoint is merely defined as:
<endpoint name="MY_ENDPOINT" xmlns="http://ws.apache.org/ns/synapse">
<address format="pox" uri="jms://QUEUE_ALIAS"/>
</endpoint>
The RFH2 header is added by MQ. If you don't need it, add targetClient=1 to the location URI, like:
queue:///MYQUEUE?targetClient=1
http://www.mqseries.net/phpBB2/viewtopic.php?=&p=171236
Change the queue definition the application gets from as follows:-
ALTER QLOCAL(q-name) PROPCTL(NONE)
I'm using WSO2 ESB 4.6.0 and my configurations in axis2.xml are default:
<transportReceiver name="local" class="org.wso2.carbon.core.transports.local.CarbonLocalTransportReceiver"/>
<transportSender name="local" class="org.wso2.carbon.core.transports.local.CarbonLocalTransportSender"/>
Calling a proxy in the same JVM, when a fault occurs, the faultSequence can not return a response by the send mediator, and I receive a timeout.
The configuration below not solve my problem:
<faultSequence>
...
<header name="To" action="remove"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<send/>
</faultSequence>
Otherwise, changing the 'local transport' by 'http transport', everything works well.
Any suggestion?
Try using the <respond/> mediator instead of the above to send the response back to client.
I did an upgrade to the ESB 4.9.0 version and I solved my problem. I saw some posts on internet like this and I think that is a bug in the old WSO2 version.
My WSO2 ESB proxy service references an endpoint which is located at different URLs in various environments - DEV, TEST, PROD. According to the WSO2 documentation, I need to store the endpoint definition in the Governance Registry and modify the URL in endpoint XML file in each environment. That might work fine for the organizations with 1 or 2 proxies, but becomes a significant overhead for a 10+ proxies.
Another scenario is when I need to read certain environment-specific properties in my ESB sequence.
Is there a way to define a bunch of properties in the external *.properties file and then read them within the ESB and Registry definitions?
You can access system properties inside ESB sequences/proxy services using the script mediator as follows;
<script language="js">mc.setProperty("file.separator",java.lang.System.getProperty("file.separator"));</script>
<log level="custom">
<property name="file.separator" expression="get-property('file.separator')"/>
</log>
Here "file.separator" property is set as the property in the message context inside the script mediator and it can be used in subsequent mediators.
You also can access properties defined in a file in ESB registry. For example if you have a file in configuration registry (test.xml) with the following content,
<a>Helloo<b>World</b></a>
The text element "World" in <b> can be accessed using property mediator as follows,
<property name="test" expression="get-property('registry','conf:/test.xml')" scope="default" type="OM"/>
<log level="custom">
<property name="test.b" expression="$ctx:test//b"/>
</log>
here is a blog post on how to access registry resources from a classmeditor1. You can access any resources as mentioned in the post and do modifications.
Likewise you can keep the external properties file and read that from the classmeditor and set all properties in synapse message context using class meditaor.