Skip to main content

WSO2 ESB calling a REST endpoint which expects a not chunked request

WSO2 ESB provides the following property mediator to remove the "Chunked" encoding type when calling SOAP endpoints. You can use the below configuration to call a SOAP endpoint which expects a non-chunked request (Request with "Content-Length" header).

<property name=”DISABLE_CHUNKING” value=”true” scope=”axis2″/>

Here is a sample proxy service configuration.

<?xml version=”1.0″ encoding=”UTF-8″?>
<proxy xmlns=”http://ws.apache.org/ns/synapse&#8221;
name=”SampleProxy_v1″
transports=”https”
startOnLoad=”true”
trace=”enable”>
<description/>
<target>
<inSequence>
<property name=”DISABLE_CHUNKING” value=”true” scope=”axis2″/>
         <send>
            <endpoint>
               <address uri="http://localhost:9764/services/HelloService" ></address>
            </endpoint>
         </send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</target>
<publishWSDL uri=”http://192.168.66.1:9764/services/HelloService?wsdl”/&gt;
</proxy>


If you need to call a REST endpoint without the "chunked" encoding, sometimes the above property mediator would not work. In that kind of situation, if you need to send "Content-Length" header which means "non-chunked" request, you can use the following 2 properties.

         <property name="FORCE_HTTP_CONTENT_LENGTH" value="true" scope="axis2"></property>
         <property name="COPY_CONTENT_LENGTH_FROM_INCOMING" value="true" scope="axis2"></property>


Here is a sample API definition for WSO2 ESB.

<api xmlns="http://ws.apache.org/ns/synapse" name="SampleAPI" context="test">
   <resource methods="POST" url-mapping="/*">
      <inSequence>
         <log level="custom">
            <property name="msg" value="Executing IN sequence"></property>
         </log>
         <property name="FORCE_HTTP_CONTENT_LENGTH" value="true" scope="axis2"></property>
         <property name="COPY_CONTENT_LENGTH_FROM_INCOMING" value="true" scope="axis2"></property>
         <send>
            <endpoint>
               <address uri="https://www.google.com" format="rest"></address>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <log level="custom">
            <property name="msg" value="Sending response"></property>
         </log>
         <send></send>
      </outSequence>
      <faultSequence>
         <log level="custom">
            <property name="msg" value="Error occurred "></property>
         </log>
         <send></send>
      </faultSequence>
   </resource>
</api>

Comments

  1. Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating mulesoft online training Hyderabad

    ReplyDelete

Post a Comment

Popular posts from this blog

WSO2 ESB creating a response for a "GET" request

When you are creating REST APIs with WSO2 ESB, you may need to send some response message back to the user when something goes wrong. In this kind of scenario, you can create a payload inside the ESB and send it back. For doing this, you can use the below configuration. <api xmlns=" http://ws.apache.org/ ns/synapse " name="LoopBackProxy" context="/loopback">    <resource methods="POST GET">       <inSequence>          <property name="NO_ENTITY_BODY" scope="axis2" action="remove"></property>          <log level="full"></log>          <payloadFactory media-type="xml">             <format>                <m:messageBeforeLoopBack xmlns:m=" http://services...

How to protect your APIs with self contained access token (JWT) using WSO2 API Manager and WSO2 Identity Server

In a typical enterprise information system, there is a high chance that people will use different types of systems built by different vendors to implement certain types of functionalities. The APIs might be hosted in an API Manager developed by vendor A and the user management can be implemented using a different vendor (vendor B). In this type of a situation, one system will not be able to directly contact the other system but they want to use both systems in tandem. Self-contained access tokens are used in these types of situations where applications can get the token from one system and use that in another system to access protected resources. In this scenario, the second system does not need to make a contact to the first system over the network to validate the user information since the token is self-contained and it has relevant details about the user. This will improve the token processing time significantly since it completely removes the network interaction. The below fig...

WSO2 ESB usage of get-property function

What are Properties? WSO2 has a huge set of mediators but property mediator is mostly used mediator for writing any proxy service or API. Property mediator is used to store any value or xml fragment temporarily during life cycle of a thread for any service or API. We can compare “Property” mediator with “Variable” in any other traditional programming languages (Like: C, C++, Java, .Net etc). There are few properties those are used/maintained by ESB itself and on the other hand few properties can be defined by users (programmers). In other words, we can say that properties can be define in below 2 categories: ESB Defined Properties User Defined Properties. These properties can be stored/defined in different scopes, like: Transport Synapse or Default Axis2 Registry System Operation Generally, these properties are read by get-properties() function. This function can be invoked with below 2 variations. get-property(String propertyName) get-property(String scop...