Repository: wso2/micro-integrator
Issue: HTTP Inbound endpoint creates new inbound worker thread pool for each request

**Description:**
HTTP Inboundendpoint creates a new inbound worker thread pool for each request.
The thread pool needs to be initialized once and then the threads should be taken from the pool for every consequent request.

**Affected Product Version:**
MI 1.1.0

**Steps to reproduce:**
1. Deploy the InboundWorkerTest.xml
```
<?xml version="1.0" encoding="UTF-8"?>
<inboundEndpoint xmlns="http://ws.apache.org/ns/synapse"
                 name="InboundWorkerTest"
                 sequence="TestInboundSequence"
                 onError="InboundFault"
                 protocol="http"
                 suspend="false">
   <parameters>
      <parameter name="inbound.http.port">9600</parameter>
      <parameter name="inbound.worker.pool.size.core">2</parameter>
      <parameter name="inbound.worker.pool.size.max">5</parameter>
      <parameter name="inbound.worker.thread.keep.alive.sec">60</parameter>
      <parameter name="inbound.worker.pool.queue.length">1</parameter>
      <parameter name="inbound.thread.group.id">PassThroughinboundworkerthreadgroup</parameter>
      <parameter name="inbound.thread.id">thread_id</parameter>
   </parameters>
</inboundEndpoint>
```
2. Deploy the TestInboundSequence.xml
<?xml version="1.0" encoding="UTF-8"?>
```
<sequence xmlns="http://ws.apache.org/ns/synapse" name="TestInboundSequence">
   <log level="custom">
      <property name="Thread logger" value="********************"/>
   </log>
   <log level="custom">
      <property name="Thread logger Before" value="********************"/>
   </log>
   <script language="js">java.lang.Thread.sleep(60000);</script> 

   <log level="custom">
      <property name="Thread logger After" value="********************"/>
   </log>
   <respond/>
</sequence>
```
3. Invoke the inbound with below curl command
`curl http://localhost:9600/InboundWorkerTest`
It will take around 60s to respond back since we have blocked the inboundworker thread with thread sleep using script mediator.
4. If we send another ten requests within 60s after the first request MI will accept all the request, We cannot accept that behavior since we have configured the inbound worker thread poll as below.
```
<parameter name="inbound.worker.pool.size.core">2</parameter>
<parameter name="inbound.worker.pool.size.max">5</parameter>
<parameter name="inbound.worker.pool.queue.length">1</parameter>
```
Theoretically, it should accept only 6 requests (5 + 1 in queue) within the 60s

Changed files:
components/mediation/inbound-endpoints/org.wso2.micro.integrator.inbound.endpoint/src/main/java/org/wso2/carbon/inbound/endpoint/protocol/http/InboundHttpSourceHandler.java

diff --git a/components/mediation/inbound-endpoints/org.wso2.micro.integrator.inbound.endpoint/src/main/java/org/wso2/carbon/inbound/endpoint/protocol/http/InboundHttpSourceHandler.java b/components/mediation/inbound-endpoints/org.wso2.micro.integrator.inbound.endpoint/src/main/java/org/wso2/carbon/inbound/endpoint/protocol/http/InboundHttpSourceHandler.java
index 8ebf041e5..dc8e90000 100644
--- a/components/mediation/inbound-endpoints/org.wso2.micro.integrator.inbound.endpoint/src/main/java/org/wso2/carbon/inbound/endpoint/protocol/http/InboundHttpSourceHandler.java
+++ b/components/mediation/inbound-endpoints/org.wso2.micro.integrator.inbound.endpoint/src/main/java/org/wso2/carbon/inbound/endpoint/protocol/http/InboundHttpSourceHandler.java
@@ -79,20 +79,21 @@ public class InboundHttpSourceHandler extends SourceHandler {
 
             Pattern dispatchPattern = null;
 
-            WorkerPoolConfiguration workerPoolConfiguration = HTTPEndpointManager.getInstance()
-                    .getWorkerPoolConfiguration(SUPER_TENANT_DOMAIN_NAME, port);
-            if (workerPoolConfiguration != null) {
-                workerPool = sourceConfiguration.getWorkerPool(workerPoolConfiguration.getWorkerPoolCoreSize(),
-                                                               workerPoolConfiguration.getWorkerPoolSizeMax(),
-                                                               workerPoolConfiguration
-                                                                       .getWorkerPoolThreadKeepAliveSec(),
-                                                               workerPoolConfiguration.getWorkerPoolQueuLength(),
-                                                               workerPoolConfiguration.getThreadGroupID(),
-                                                               workerPoolConfiguration.getThreadID());
-            }
-
+            // Need to initialize workerPool only once
             if (workerPool == null) {
-                workerPool = sourceConfiguration.getWorkerPool();
+                WorkerPoolConfiguration workerPoolConfiguration = HTTPEndpointManager.getInstance()
+                        .getWorkerPoolConfiguration(SUPER_TENANT_DOMAIN_NAME, port);
+                if (workerPoolConfiguration != null) {
+                    workerPool = sourceConfiguration.getWorkerPool(workerPoolConfiguration.getWorkerPoolCoreSize(),
+                            workerPoolConfiguration.getWorkerPoolSizeMax(),
+                            workerPoolConfiguration
+                                    .getWorkerPoolThreadKeepAliveSec(),
+                            workerPoolConfiguration.getWorkerPoolQueuLength(),
+                            workerPoolConfiguration.getThreadGroupID(),
+                            workerPoolConfiguration.getThreadID());
+                } else {
+                    workerPool = sourceConfiguration.getWorkerPool();
+                }
             }
 
             Object correlationId = conn.getContext().getAttribute(PassThroughConstants.CORRELATION_ID);
@@ -121,5 +122,4 @@ public class InboundHttpSourceHandler extends SourceHandler {
             sourceConfiguration.getSourceConnections().shutDownConnection(conn, true);
         }
     }
-
 }