Change the Way to Invoke HTTP Requests
authoryoubowu <wu.youbo@zte.com.cn>
Mon, 13 Mar 2017 07:54:30 +0000 (15:54 +0800)
committer6092002067 <wu.youbo@zte.com.cn>
Mon, 13 Mar 2017 07:54:30 +0000 (15:54 +0800)
Change-Id: Ide3962f548e619c4cdeee416b02c1cda2b2d9b9a
Issue-ID: HOLMES-50
Signed-off-by: youbowu <wu.youbo@zte.com.cn>
rulemgt/pom.xml
rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineService.java
rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java
rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleDao.java
rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java
rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java

index 5a82ed2..e4af4c6 100644 (file)
             <version>2.4</version>
             <classifier>jdk15</classifier>
         </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.core</groupId>
+            <artifactId>jersey-server</artifactId>
+            <version>${jersey.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.core</groupId>
+            <artifactId>jersey-client</artifactId>
+            <version>${jersey.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.core</groupId>
+            <artifactId>jersey-common</artifactId>
+            <version>${jersey.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.containers</groupId>
+            <artifactId>jersey-container-servlet-core</artifactId>
+            <version>${jersey.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>19.0</version>
+        </dependency>
+
     </dependencies>
     <build>
         <plugins>
index 21e29b3..ac381d1 100644 (file)
  */\r
 package org.openo.holmes.rulemgt.bolt.enginebolt;\r
 \r
-import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;\r
-\r
 import com.fasterxml.jackson.databind.ObjectMapper;\r
-import java.io.ByteArrayOutputStream;\r
 import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.io.InputStreamReader;\r
-import java.io.Reader;\r
-import java.io.UnsupportedEncodingException;\r
-import java.nio.charset.Charset;\r
+import javax.ws.rs.client.Client;\r
+import javax.ws.rs.client.ClientBuilder;\r
+import javax.ws.rs.client.Entity;\r
+import javax.ws.rs.client.WebTarget;\r
+import javax.ws.rs.core.MediaType;\r
+import javax.ws.rs.core.Response;\r
 import lombok.extern.slf4j.Slf4j;\r
-import org.apache.commons.lang3.StringUtils;\r
-import org.apache.http.ConnectionClosedException;\r
-import org.apache.http.HttpEntity;\r
-import org.apache.http.HttpResponse;\r
-import org.apache.http.client.methods.HttpDelete;\r
-import org.apache.http.client.methods.HttpGet;\r
-import org.apache.http.client.methods.HttpPost;\r
-import org.apache.http.client.methods.HttpPut;\r
-import org.apache.http.client.methods.HttpRequestBase;\r
-import org.apache.http.entity.BufferedHttpEntity;\r
-import org.apache.http.entity.ByteArrayEntity;\r
-import org.apache.http.entity.ContentType;\r
-import org.apache.http.impl.client.CloseableHttpClient;\r
-import org.apache.http.impl.client.HttpClients;\r
-import org.apache.http.protocol.HTTP;\r
-import org.apache.http.util.EntityUtils;\r
+import org.glassfish.jersey.client.ClientConfig;\r
 import org.jvnet.hk2.annotations.Service;\r
-import org.openo.holmes.common.config.MicroServiceConfig;\r
-import org.openo.holmes.common.exception.CorrelationException;\r
-import org.openo.holmes.common.utils.I18nProxy;\r
 import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
 import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
 import org.openo.holmes.rulemgt.constant.RuleMgtConstant;\r
@@ -56,152 +36,31 @@ public class EngineService {
 \r
     String url = "http://10.250.0.3:9102";\r
 \r
-    protected HttpResponse delete(String packageName) throws IOException {\r
-        return deleteRequest(url + RuleMgtConstant.ENGINE_PATH + "/" + packageName);\r
+    protected Response delete(String packageName) throws IOException {\r
+        Client client = createClient();\r
+        WebTarget webTarget = client.target(url + RuleMgtConstant.ENGINE_PATH + "/" + packageName);\r
+        return webTarget.request(MediaType.APPLICATION_JSON).delete();\r
+    }\r
+\r
+    private Client createClient() {\r
+        ClientConfig clientConfig = new ClientConfig();\r
+        return ClientBuilder.newClient(clientConfig);\r
     }\r
 \r
-    protected HttpResponse check(CorrelationCheckRule4Engine correlationCheckRule4Engine)\r
+    protected Response check(CorrelationCheckRule4Engine correlationCheckRule4Engine)\r
             throws IOException {\r
+        Client client = createClient();\r
         ObjectMapper mapper = new ObjectMapper();\r
         String content = mapper.writeValueAsString(correlationCheckRule4Engine);\r
-        String queryUrl = MicroServiceConfig.getMsbServerAddr()\r
-                + "/openoapi/microservices/v1/services/holmes-engine/version/v1";\r
-        HttpGet httpGet = new HttpGet(queryUrl);\r
-        CloseableHttpClient httpClient = HttpClients.createDefault();\r
-        try {\r
-            HttpResponse httpResponse = httpClient.execute(httpGet);\r
-            log.info("response entity:" + EntityUtils.toString(httpResponse.getEntity()));\r
-        } finally {\r
-            httpClient.close();\r
-        }\r
-        return postRequest(url + RuleMgtConstant.ENGINE_PATH, content);\r
+        WebTarget webTarget = client.target(url + RuleMgtConstant.ENGINE_PATH);\r
+        return webTarget.request(MediaType.APPLICATION_JSON).post(Entity.entity(content, MediaType.APPLICATION_JSON));\r
     }\r
 \r
-    protected HttpResponse deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine) throws IOException {\r
+    protected Response deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine) throws IOException {\r
+        Client client = createClient();\r
         ObjectMapper mapper = new ObjectMapper();\r
         String content = mapper.writeValueAsString(correlationDeployRule4Engine);\r
-        return putRequest(url + RuleMgtConstant.ENGINE_PATH, content);\r
-    }\r
-\r
-    private HttpResponse postRequest(String url, String content) throws IOException {\r
-        CloseableHttpClient httpClient = HttpClients.createDefault();\r
-        try {\r
-            HttpPost httpPost = new HttpPost(url);\r
-            log.info("url:" + url + "," + "post:" + httpPost);\r
-            setHeader(httpPost);\r
-            if (StringUtils.isNotEmpty(content)) {\r
-                httpPost.setEntity(new ByteArrayEntity(content.getBytes()));\r
-            }\r
-            return httpClient.execute(httpPost);\r
-        } finally {\r
-            httpClient.close();\r
-        }\r
-    }\r
-\r
-    private HttpResponse putRequest(String url, String content) throws IOException {\r
-        CloseableHttpClient httpClient = HttpClients.createDefault();\r
-        try {\r
-            HttpPut httpPut = new HttpPut(url);\r
-            setHeader(httpPut);\r
-            if (StringUtils.isNotEmpty(content)) {\r
-                httpPut.setEntity(new ByteArrayEntity(content.getBytes()));\r
-            }\r
-            HttpResponse response = httpClient.execute(httpPut);\r
-            log.info("Return value for put request is " + EntityUtils.toString(response.getEntity()) + ".");\r
-            return response;\r
-        } finally {\r
-            httpClient.close();\r
-        }\r
-    }\r
-\r
-    private HttpResponse deleteRequest(String url) throws IOException {\r
-        CloseableHttpClient httpClient = HttpClients.createDefault();\r
-        try {\r
-            HttpDelete httpDelete = new HttpDelete(url);\r
-            setHeader(httpDelete);\r
-            return httpClient.execute(httpDelete);\r
-        } finally {\r
-            httpClient.close();\r
-        }\r
-    }\r
-\r
-    private void setHeader(HttpRequestBase httpRequestBase) {\r
-        httpRequestBase.setHeader("Accept", "application/json");\r
-        httpRequestBase.setHeader("Content-Type", "application/json");\r
-    }\r
-\r
-    public String getResponseContent(HttpResponse response) {\r
-        HttpEntity entity = response.getEntity();\r
-        InputStream is = null;\r
-        if (entity != null) {\r
-            try {\r
-                is = entity.getContent();\r
-                final ContentType contentType = ContentType.getOrDefault(entity);\r
-                Charset charset = contentType.getCharset();\r
-                if (charset == null) {\r
-                    charset = HTTP.DEF_CONTENT_CHARSET;\r
-                }\r
-                final StringBuilder b = new StringBuilder();\r
-                final char[] tmp = new char[1024];\r
-                final Reader reader = new InputStreamReader(is, charset);\r
-                try {\r
-                    int l;\r
-                    while ((l = reader.read(tmp)) != -1) {\r
-                        b.append(tmp, 0, l);\r
-                    }\r
-                } catch (ConnectionClosedException ignore) {\r
-\r
-                } catch (IOException e) {\r
-                    log.info("Failed to read the contents of the input stream of the http entity.", e);\r
-                }\r
-                return b.toString();\r
-            } catch (IOException e) {\r
-                log.info("Failed to read the contents of the http entity.", e);\r
-            } finally {\r
-                try {\r
-                    if (is != null) {\r
-                        is.close();\r
-                    }\r
-                } catch (IOException e) {\r
-                    log.info("Failed to close the input stream of the http entity.", e);\r
-                }\r
-            }\r
-        }\r
-        return "{}";\r
-    }\r
-\r
-    public byte[] getData(HttpEntity httpEntity) throws IOException {\r
-        log.info("Rule deployed. Package name: " + httpEntity.getContent().toString()\r
-                + ". Content length: " + httpEntity.getContentLength());\r
-        BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(httpEntity);\r
-        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();\r
-        bufferedHttpEntity.writeTo(byteArrayOutputStream);\r
-        byte[] responseBytes = byteArrayOutputStream.toByteArray();\r
-        return responseBytes;\r
-    }\r
-\r
-//    public String getResponseContent(HttpResponse httpResponse) throws CorrelationException {\r
-//        byte[] dataByte;\r
-//        String result = null;\r
-//        try {\r
-//            HttpEntity httpEntity = httpResponse.getEntity();\r
-//            if (httpEntity != null) {\r
-//                byte[] responseBytes = getData(httpEntity);\r
-//                dataByte = responseBytes;\r
-//                result = bytesToString(dataByte);\r
-//            }\r
-//            return result;\r
-//        } catch (Exception e) {\r
-//            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_PARSE_DEPLOY_RESULT_ERROR, e);\r
-//        }\r
-//    }\r
-\r
-    private String bytesToString(byte[] bytes) throws UnsupportedEncodingException {\r
-        if (bytes != null) {\r
-            String returnStr = new String(bytes, "utf-8");\r
-            returnStr = StringUtils.trim(returnStr);\r
-            return returnStr;\r
-        }\r
-        return null;\r
+        WebTarget webTarget = client.target(url + RuleMgtConstant.ENGINE_PATH);\r
+        return webTarget.request(MediaType.APPLICATION_JSON).put(Entity.entity(content, MediaType.APPLICATION_JSON));\r
     }\r
 }\r
index a65d88b..c568723 100644 (file)
  */\r
 package org.openo.holmes.rulemgt.bolt.enginebolt;\r
 \r
-import java.io.IOException;\r
 import javax.inject.Inject;\r
+import javax.ws.rs.core.Response;\r
 import lombok.extern.slf4j.Slf4j;\r
 import net.sf.json.JSONObject;\r
-import org.apache.http.HttpResponse;\r
-import org.apache.http.util.EntityUtils;\r
 import org.jvnet.hk2.annotations.Service;\r
 import org.openo.holmes.common.exception.CorrelationException;\r
 import org.openo.holmes.common.utils.I18nProxy;\r
@@ -36,18 +34,16 @@ public class EngineWrapper {
     private EngineService engineService;\r
 \r
     public String deployEngine(CorrelationDeployRule4Engine correlationRule) throws CorrelationException {\r
-        HttpResponse httpResponse;\r
+        Response response;\r
         try {\r
-            httpResponse = engineService.deploy(correlationRule);\r
+            response = engineService.deploy(correlationRule);\r
         } catch (Exception e) {\r
             throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED, e);\r
         }\r
-        if (httpResponse.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) {\r
+        if (response.getStatus() == RuleMgtConstant.RESPONSE_STATUS_OK) {\r
             log.info("Call deploy rule rest interface in engine successfully.");\r
-            String content = engineService.getResponseContent(httpResponse);\r
             try {\r
-                log.info("Deploy result from the engine is: " + content + ".");\r
-                JSONObject json = JSONObject.fromObject(content);\r
+                JSONObject json = JSONObject.fromObject(response.readEntity(String.class));\r
                 return json.get(RuleMgtConstant.PACKAGE).toString();\r
             } catch (Exception e) {\r
                 throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_PARSE_DEPLOY_RESULT_ERROR, e);\r
@@ -58,13 +54,13 @@ public class EngineWrapper {
     }\r
 \r
     public boolean deleteRuleFromEngine(String packageName) throws CorrelationException {\r
-        HttpResponse httpResponse;\r
+        Response response;\r
         try {\r
-            httpResponse = engineService.delete(packageName);\r
+            response = engineService.delete(packageName);\r
         } catch (Exception e) {\r
             throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_DELETE_RULE_REST_FAILED, e);\r
         }\r
-        if (httpResponse.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) {\r
+        if (response.getStatus() == RuleMgtConstant.RESPONSE_STATUS_OK) {\r
             log.info("Call delete rule rest interface in engine successfully.");\r
             return true;\r
         } else {\r
@@ -75,25 +71,17 @@ public class EngineWrapper {
     public boolean checkRuleFromEngine(CorrelationCheckRule4Engine correlationCheckRule4Engine)\r
             throws CorrelationException {\r
         log.info("content:" + correlationCheckRule4Engine.getContent());\r
-        HttpResponse httpResponse;\r
+        Response response;\r
         try {\r
-            httpResponse = engineService.check(correlationCheckRule4Engine);\r
+            response = engineService.check(correlationCheckRule4Engine);\r
         } catch (Exception e) {\r
             throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_CHECK_RULE_REST_FAILED, e);\r
         }\r
-        if (httpResponse.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) {\r
+        if (response.getStatus() == RuleMgtConstant.RESPONSE_STATUS_OK) {\r
             log.info("Call check rule rest interface in engine successfully.");\r
             return true;\r
         } else {\r
-            try {\r
-                log.info(httpResponse.getStatusLine().getStatusCode() + "," + EntityUtils\r
-                        .toString(httpResponse.getEntity()));\r
-                throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CHECK_NO_PASS);\r
-            } catch (IOException e) {\r
-                log.info(httpResponse.getStatusLine().getStatusCode() + "," + httpResponse.getStatusLine()\r
-                        .getReasonPhrase());\r
-                throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CHECK_NO_PASS, e);\r
-            }\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CHECK_NO_PASS);\r
         }\r
     }\r
 }\r
index f800f0c..3a7f300 100644 (file)
@@ -31,7 +31,7 @@ import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
 public abstract class CorrelationRuleDao {\r
 \r
     @GetGeneratedKeys\r
-    @SqlUpdate("INSERT INTO APLUS_RULE  (NAME,DESCRIPTION,ENABLE,TEMPLATEID,ENGINETYPE,CREATOR,UPDATOR,PARAMS,DOMAIN ,CONTENT ,VENDOR,CREATETIME,UPDATETIME,ENGINEID,ISMANUAL,PACKAGE,RID) VALUES (:name,:description,:enabled,:templateID,:engineType,:creator,:modifier,:params,:domain,:content,:vendor,:createTime,:updateTime,:engineId,:isManual,:packageName,:rid)")\r
+    @SqlUpdate("INSERT INTO APLUS_RULE  (NAME,DESCRIPTION,ENABLE,TEMPLATEID,ENGINETYPE,CREATOR,UPDATOR,PARAMS,CONTENT ,VENDOR,CREATETIME,UPDATETIME,ENGINEID,PACKAGE,RID) VALUES (:name,:description,:enabled,:templateID,:engineType,:creator,:modifier,:params,:content,:vendor,:createTime,:updateTime,:engineID,:packageName,:rid)")\r
     protected abstract int addRule(@BindBean CorrelationRule correlationRule);\r
 \r
     @SqlUpdate("UPDATE APLUS_RULE SET DESCRIPTION=:description,ENABLE=:enabled,CONTENT=:content,UPDATOR=:modifier,UPDATETIME=:updateTime WHERE RID=:rid")\r
index 3b1c9bd..f4275eb 100644 (file)
@@ -20,15 +20,11 @@ package org.openo.holmes.rulemgt.bolt.enginebolt;
 \r
 import org.apache.http.HttpResponse;\r
 import org.apache.http.client.methods.CloseableHttpResponse;\r
-import org.apache.http.client.methods.HttpPut;\r
 import org.apache.http.impl.client.CloseableHttpClient;\r
 import org.apache.http.impl.client.HttpClients;\r
-import org.easymock.EasyMock;\r
 import org.junit.Before;\r
 import org.junit.Rule;\r
-import org.junit.Test;\r
 import org.junit.rules.ExpectedException;\r
-import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
 import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
 import org.powermock.api.easymock.PowerMock;\r
 import org.powermock.core.classloader.annotations.PrepareForTest;\r
@@ -57,39 +53,4 @@ public class EngineServiceTest {
         correlationDeployRule4Engine.setContent("{\"package\":\"test\"}");\r
         correlationDeployRule4Engine.setEngineId("engine_id");\r
     }\r
-\r
-    @Test\r
-    public void getResponseContent_http_entity_is_null() throws Exception {\r
-        EasyMock.expect(httpResponseMock.getEntity()).andReturn(null);\r
-        PowerMock.replayAll();\r
-\r
-        engineService.getResponseContent(httpResponseMock);\r
-\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void delete_exception() throws Exception {\r
-        thrown.expect(Exception.class);\r
-\r
-        engineService.delete("test");\r
-\r
-    }\r
-\r
-    @Test\r
-    public void deploy_exception() throws Exception {\r
-\r
-        thrown.expect(Exception.class);\r
-\r
-        engineService.deploy(correlationDeployRule4Engine);\r
-\r
-    }\r
-\r
-    @Test\r
-    public void check_normal() throws Exception {\r
-        thrown.expect(Exception.class);\r
-\r
-        engineService.check(new CorrelationCheckRule4Engine());\r
-\r
-    }\r
 }
\ No newline at end of file
index 7746394..fe7696b 100644 (file)
@@ -20,7 +20,7 @@ package org.openo.holmes.rulemgt.bolt.enginebolt;
 import static org.hamcrest.MatcherAssert.assertThat;\r
 import static org.hamcrest.Matchers.equalTo;\r
 \r
-import org.apache.http.HttpResponse;\r
+import javax.ws.rs.core.Response;\r
 import org.apache.http.StatusLine;\r
 import org.easymock.EasyMock;\r
 import org.junit.Before;\r
@@ -40,13 +40,13 @@ public class EngineWrapperTest {
     public ExpectedException thrown = ExpectedException.none();\r
     private EngineWrapper engineWrapper = new EngineWrapper();\r
     private EngineService engineServiceMock;\r
-    private HttpResponse httpResponseMock;\r
+    private Response response;\r
     private StatusLine statusLineMock;\r
 \r
     @Before\r
     public void setUp() throws Exception {\r
         engineServiceMock = PowerMock.createMock(EngineService.class);\r
-        httpResponseMock = PowerMock.createMock(HttpResponse.class);\r
+        response = PowerMock.createMock(Response.class);\r
         statusLineMock = PowerMock.createMock(StatusLine.class);\r
         Whitebox.setInternalState(engineWrapper, "engineService", engineServiceMock);\r
     }\r
@@ -71,10 +71,8 @@ public class EngineWrapperTest {
         thrown.expectMessage(I18nProxy.ENGINE_DEPLOY_RULE_FAILED);\r
 \r
         EasyMock.expect(engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))\r
-                .andReturn(httpResponseMock);\r
-        EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);\r
-        EasyMock.expect(statusLineMock.getStatusCode()).andReturn(400);\r
-\r
+                .andReturn(response);\r
+        EasyMock.expect(response.getStatus()).andReturn(400);\r
         PowerMock.replayAll();\r
 \r
         engineWrapper.deployEngine(new CorrelationDeployRule4Engine());\r
@@ -89,12 +87,9 @@ public class EngineWrapperTest {
         thrown.expect(CorrelationException.class);\r
         thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_PARSE_DEPLOY_RESULT_ERROR);\r
         EasyMock.expect(engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))\r
-                .andReturn(httpResponseMock);\r
-        EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);\r
-        EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);\r
-        EasyMock.expect(engineServiceMock.getResponseContent(EasyMock.anyObject(HttpResponse.class)))\r
-                .andReturn(content);\r
-\r
+                .andReturn(response);\r
+        EasyMock.expect(response.getStatus()).andReturn(200);\r
+        EasyMock.expect(response.readEntity(String.class)).andReturn(content);\r
         PowerMock.replayAll();\r
 \r
         engineWrapper.deployEngine(new CorrelationDeployRule4Engine());\r
@@ -106,11 +101,9 @@ public class EngineWrapperTest {
     public void deployEngine_success() throws Exception {\r
         String content = "{\"package\":\"test\"}";\r
         EasyMock.expect(engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))\r
-                .andReturn(httpResponseMock);\r
-        EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);\r
-        EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);\r
-        EasyMock.expect(engineServiceMock.getResponseContent(EasyMock.anyObject(HttpResponse.class)))\r
-                .andReturn(content);\r
+                .andReturn(response);\r
+        EasyMock.expect(response.getStatus()).andReturn(200);\r
+        EasyMock.expect(response.readEntity(String.class)).andReturn(content);\r
         PowerMock.replayAll();\r
 \r
         String result = engineWrapper.deployEngine(new CorrelationDeployRule4Engine());\r
@@ -139,9 +132,8 @@ public class EngineWrapperTest {
         thrown.expectMessage(I18nProxy.ENGINE_DELETE_RULE_FAILED);\r
 \r
         EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class)))\r
-                .andReturn(httpResponseMock);\r
-        EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);\r
-        EasyMock.expect(statusLineMock.getStatusCode()).andReturn(400);\r
+                .andReturn(response);\r
+        EasyMock.expect(response.getStatus()).andReturn(400);\r
 \r
         PowerMock.replayAll();\r
 \r
@@ -153,9 +145,8 @@ public class EngineWrapperTest {
     @Test\r
     public void deleteRuleFromEngine_success() throws Exception {\r
         EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class)))\r
-                .andReturn(httpResponseMock);\r
-        EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);\r
-        EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);\r
+                .andReturn(response);\r
+        EasyMock.expect(response.getStatus()).andReturn(200);\r
 \r
         PowerMock.replayAll();\r
 \r
@@ -181,9 +172,8 @@ public class EngineWrapperTest {
     @Test\r
     public void checkRuleFromEngine_success() throws Exception {\r
         EasyMock.expect(engineServiceMock.check(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
-                .andReturn(httpResponseMock);\r
-        EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);\r
-        EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);\r
+                .andReturn(response);\r
+        EasyMock.expect(response.getStatus()).andReturn(200);\r
 \r
         PowerMock.replayAll();\r
 \r