Showing posts with label Proxy Services. Show all posts
Showing posts with label Proxy Services. Show all posts

Monday, February 18, 2013

Retrieve values from a xml in config registry with WSO ESB

Configuration given below cane used for this.

<proxy xmlns="http://ws.apache.org/ns/synapse" name="test123" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <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>
      </inSequence>
      <outSequence>
         <send />
      </outSequence>
      <endpoint>
         <address uri="http://localhost:8280/services/Version" />
      </endpoint>
   </target>
   <publishWSDL uri="http://localhost:8280/services/Version?wsdl" />
   <policy key="conf:/repository/axis2/service-groups/test123/services/test123/policies/61afea637b914422e1753dde4e88864cc199fecbb66084e2" />
   <policy key="conf:/repository/axis2/service-groups/test123/services/test123/policies/urn:version" />
</proxy>
                              
Please create a xml file in the config registry with following content.

<a>Hello<b>WSO2</b></a>



You will see the following log

[2013-02-18 23:33:35,690] INFO - LogMediator test.b = WSO2 

Friday, December 7, 2012

Proxy Services with WSO2 ESB - ( From Registry )

Recently , i was looking into proxy services from registry and found a blog post about it. So i decided to share it in my blog

WSO2 ESB proxy from registry

If you are new to WSO2 ESB it is recommended to refer following links

Proxy Services with WSO2 ESB
Proxy Services with WSO2 ESB / Monitoring with TCPMon
WSO2 ESB Proxy Services with Custom URLs

Friday, August 10, 2012

WSO2 ESB : How propagate the exception to the client

This can be done with the makefault mediator.

<makefault>
            <code value="tns:Receiver" xmlns:tns="http://www.w3.org/2003/05/soap-envelope"/>
            <reason expression="get-property('ERROR_MESSAGE')"/>
        </makefault>


Following proxy is an example


<proxy xmlns="http://ws.apache.org/ns/synapse" name="test11" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <makefault version="soap12">
            <code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver" />
            <reason expression="get-property('ERROR_MESSAGE')" />
         </makefault>
         <send />
      </inSequence>
      <outSequence>
         <log level="full" />
         <send />
      </outSequence>
   </target>
</proxy>
                               

Saturday, July 28, 2012

Route to an endpoint based on the time of the day - Using ESB

This can be achieved with the use of Switch Case Mediator. Following proxy service will route to an endpoint based on the time of the day.

<proxy xmlns="http://ws.apache.org/ns/synapse" name="Proxy1" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <switch xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" source="get-property('SYSTEM_DATE', 'HH')">
            <case regex="10">
               <log level="custom">
                  <property name="system-time" expression="get-property('SYSTEM_DATE', 'HH')" />
               </log>
               <send>
                  <endpoint>
                     <address uri="http://localhost:8280/services/Version" format="get" />
                  </endpoint>
               </send>
            </case>
         </switch>
      </inSequence>
      <outSequence>
         <send />
      </outSequence>
      <endpoint>
         <address uri="http://localhost:8280/services/Version" />
      </endpoint>
   </target>
   <publishWSDL uri="http://localhost:8280/services/Version?wsdl" />
</proxy> 

Tuesday, July 17, 2012

How to use the System time inside a proxy service


system time can be used inside a proxy service. Following proxy uses the system time.

<proxy xmlns="http://ws.apache.org/ns/synapse" name="Proxy2" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <log level="custom">
            <property name="system-time" expression="get-property('SYSTEM_DATE', 'HH:MM:SS')" />
         </log>
      </inSequence>
      <outSequence>
         <send />
      </outSequence>
      <endpoint>
         <address uri="http://localhost:8280/services/Version" />
      </endpoint>
   </target>
   <publishWSDL uri="http://localhost:8280/services/Version?wsdl" />
</proxy>
                               

WSO2 ESB Proxy Services with Custom URLs

The URL of a proxy service can be customized.  If you want to get an understanding about proxy services refer this post  (http://achala11.blogspot.com/2012/07/proxy-services-with-wso2-esb.html).


Add the following to the axis2.xml
<handler name="CustomURIBasedDispatcher"
                     class="org.apache.synapse.core.axis2.CustomURIBasedDispatcher"/>

The dispatcher should be inserted in to the In-Flow of the ESB as the first handler(at the Dispatch phase).

Add the following parameter to the proxy service.
 <parameter name="ServiceURI">customurl</parameter>


This is explained in a details manner here

http://wso2.com/products/enterprise-service-bus/
http://wso2.org/library/knowledge-base/2011/01/custom-urls-wso2-esb-proxy-services

Proxy Services with WSO2 ESB

First lets try to figure out 'What is a proxy service?'
"Proxy services define virtual services hosted on the ESB that can accept requests, mediate them, and deliver them to an actual service. Proxy services could perform transport or interface switching and expose different semantics than the actual service, i.e., WSDL, policies, and QoS aspects like WS-RM, WS-Security, etc."[1]


Another important term is 'endpoint'
An endpoint is a specific destination for a message. It may be specified as an Address endpoint, WSDL endpoint, a fail over group, or a load balance group.


OK , Lets create a proxy service (Pass Through Proxy) for version service


Give the proxy name as - 'Pass Through Proxy'
Target URL - http://localhost:8280/services/Version (We will use the endpoint of Version service here )


When publishing the WSDL select "specify source uri
WSDL URL - http://localhost:8280/services/Version?wsdl
If you ar eno using the UI, Please refere the following configuration.



<proxy xmlns="http://ws.apache.org/ns/synapse" name="Proxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <outSequence>
         <send />
      </outSequence>
      <endpoint>
         <address uri="http://localhost:8280/services/Version" />
      </endpoint>
   </target>
   <publishWSDL uri="http://localhost:8280/services/Version?wsdl" />
</proxy>




Press OK, and the proxy is created. From the ESB, you can find the newly created proxy service at (Web Services -> list)






[1] http://wso2.org/project/esb/java/4.0.3/docs/user_guide.html#Proxy
[2] http://wso2.org/project/esb/java/4.0.3/docs/samples/proxy_samples.html

Using Zotero for academic writing