diff options
author | HuabingZhao <zhao.huabing@zte.com.cn> | 2016-09-20 13:59:27 +0800 |
---|---|---|
committer | HuabingZhao <zhao.huabing@zte.com.cn> | 2016-09-20 14:08:41 +0800 |
commit | 01bfe0bd23f92625e4b52710c1460f64f3a270b6 (patch) | |
tree | 66e5c95c3e4bc1e89b5026772d20bbb305e56959 /winery/org.eclipse.winery.highlevelrestapi/src | |
parent | fcac34d12ac374fb63926f354d19172eff430e40 (diff) |
Now we have pulled the winery source codes from github and publish the winery binary to OPEN-O third party Nexus repository. So we don't use winery code in the OPEN-O git repo anymore.
Issue id: OCS-55
Change-Id: I76fdfb17b1c90377a44c2d47f81b5698d5a220d3
Signed-off-by: HuabingZhao <zhao.huabing@zte.com.cn>
Diffstat (limited to 'winery/org.eclipse.winery.highlevelrestapi/src')
4 files changed, 0 insertions, 310 deletions
diff --git a/winery/org.eclipse.winery.highlevelrestapi/src/main/java/org/eclipse/winery/highlevelrestapi/HighLevelRestApi.java b/winery/org.eclipse.winery.highlevelrestapi/src/main/java/org/eclipse/winery/highlevelrestapi/HighLevelRestApi.java deleted file mode 100644 index 376d0da..0000000 --- a/winery/org.eclipse.winery.highlevelrestapi/src/main/java/org/eclipse/winery/highlevelrestapi/HighLevelRestApi.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 University of Stuttgart. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and the Apache License 2.0 which both accompany this distribution, - * and are available at http://www.eclipse.org/legal/epl-v10.html - * and http://www.apache.org/licenses/LICENSE-2.0 - * - * Contributors: - * Uwe Breitenbücher - initial API and implementation - * Kálmán Képes - improvements - *******************************************************************************/ -package org.eclipse.winery.highlevelrestapi; - -import org.apache.commons.httpclient.HttpMethodBase; -import org.apache.commons.httpclient.NameValuePair; -import org.apache.commons.httpclient.methods.DeleteMethod; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.PutMethod; - -/** - * This class wraps HTTP-Method functionality and thereby abstracts from low - * level code to simplify the usage. - */ -public class HighLevelRestApi { - - /** - * This method implements the HTTP Put Method - * - * @param uri Resource URI - * @param requestPayload Content which has to be put into the Resource - * @return ResponseCode of HTTP Interaction - */ - @SuppressWarnings("deprecation") - public static HttpResponseMessage Put(String uri, String requestPayload, String acceptHeaderValue) { - - PutMethod method = new PutMethod(uri); - // requestPayload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - // requestPayload; - - HighLevelRestApi.setAcceptHeader(method, acceptHeaderValue); - method.setRequestBody(requestPayload); - - HttpResponseMessage responseMessage = LowLevelRestApi.executeHttpMethod(method); - - // kill <?xml... in front of response - HighLevelRestApi.cleanResponseBody(responseMessage); - - return responseMessage; - } - - /** - * This method implements the HTTP Post Method - * - * @param uri Resource URI - * @param requestPayload Content which has to be posted into the Resource - * @return ResponseCode of HTTP Interaction - */ - @SuppressWarnings("deprecation") - public static HttpResponseMessage Post(String uri, String requestPayload, String acceptHeaderValue) { - - PostMethod method = null; - if (uri.contains("?")) { - System.out.println("Found query trying to split"); - String[] split = uri.split("\\?"); - System.out.println("Raw URI part: " + split[0]); - System.out.println("Raw Query part: " + split[1]); - method = new PostMethod(split[0]); - method.setQueryString(HighLevelRestApi.createNameValuePairArrayFromQuery(split[1])); - } else { - method = new PostMethod(uri); - ; - } - method.setRequestBody(requestPayload); - HighLevelRestApi.setAcceptHeader(method, acceptHeaderValue); - HttpResponseMessage responseMessage = LowLevelRestApi.executeHttpMethod(method); - HighLevelRestApi.cleanResponseBody(responseMessage); - return responseMessage; - } - - /** - * This method implements the HTTP Get Method - * - * @param uri Resource URI - * @return Content represented by the Resource URI - */ - public static HttpResponseMessage Get(String uri, String acceptHeaderValue) { - System.out.println("Setting URI to: \n"); - System.out.println(uri); - GetMethod method = null; - if (uri.contains("?")) { - System.out.println("Found query trying to split"); - String[] split = uri.split("\\?"); - System.out.println("Raw URI part: " + split[0]); - System.out.println("Raw Query part: " + split[1]); - method = new GetMethod(split[0]); - method.setQueryString(HighLevelRestApi.createNameValuePairArrayFromQuery(split[1])); - } else { - method = new GetMethod(uri); - } - HighLevelRestApi.setAcceptHeader(method, acceptHeaderValue); - HttpResponseMessage responseMessage = LowLevelRestApi.executeHttpMethod(method); - HighLevelRestApi.cleanResponseBody(responseMessage); - return responseMessage; - } - - private static NameValuePair[] createNameValuePairArrayFromQuery(String query) { - // example: - // csarID=Moodle.csar&serviceTemplateID={http://www.example.com/tosca/ServiceTemplates/Moodle}Moodle&nodeTemplateID={http://www.example.com/tosca/ServiceTemplates/Moodle}VmApache - System.out.println("Splitting query: " + query); - String[] pairs = query.trim().split("&"); - NameValuePair[] nameValuePairArray = new NameValuePair[pairs.length]; - int count = 0; - for (String pair : pairs) { - System.out.println("Splitting query pair: " + pair); - String[] keyValue = pair.split("="); - NameValuePair nameValuePair = new NameValuePair(); - System.out.println("Key: " + keyValue[0] + " Value: " + keyValue[1]); - nameValuePair.setName(keyValue[0]); - nameValuePair.setValue(keyValue[1]); - nameValuePairArray[count] = nameValuePair; - count++; - } - return nameValuePairArray; - } - - /** - * This method implements the HTTP Delete Method - * - * @param uri Resource URI - * @return ResponseCode of HTTP Interaction - */ - public static HttpResponseMessage Delete(String uri, String acceptHeaderValue) { - - DeleteMethod method = new DeleteMethod(uri); - HighLevelRestApi.setAcceptHeader(method, acceptHeaderValue); - HttpResponseMessage responseMessage = LowLevelRestApi.executeHttpMethod(method); - HighLevelRestApi.cleanResponseBody(responseMessage); - return responseMessage; - } - - private static void setAcceptHeader(HttpMethodBase method, String value) { - if (!value.equals("")) { - method.setRequestHeader("Accept", value); - } else { - method.setRequestHeader("Accept", "application/xml"); - } - } - - private static void cleanResponseBody(HttpResponseMessage responseMessage) { - System.out.println("ResponseBody: \n"); - System.out.println(responseMessage.getResponseBody()); - // @formatter:off - String temp = responseMessage - .getResponseBody() - .replace( - "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>", - ""); - // @formatter:on - responseMessage.setResponseBody(temp); - } -} diff --git a/winery/org.eclipse.winery.highlevelrestapi/src/main/java/org/eclipse/winery/highlevelrestapi/HttpMethod.java b/winery/org.eclipse.winery.highlevelrestapi/src/main/java/org/eclipse/winery/highlevelrestapi/HttpMethod.java deleted file mode 100644 index fedd3f0..0000000 --- a/winery/org.eclipse.winery.highlevelrestapi/src/main/java/org/eclipse/winery/highlevelrestapi/HttpMethod.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 University of Stuttgart. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and the Apache License 2.0 which both accompany this distribution, - * and are available at http://www.eclipse.org/legal/epl-v10.html - * and http://www.apache.org/licenses/LICENSE-2.0 - * - * Contributors: - * Uwe Breitenbücher - initial API and implementation - *******************************************************************************/ -package org.eclipse.winery.highlevelrestapi; - -/** - * This enum is intended to simplify identifying different HTTP-methods - */ -public enum HttpMethod { - PUT, POST, GET, DELETE -}
\ No newline at end of file diff --git a/winery/org.eclipse.winery.highlevelrestapi/src/main/java/org/eclipse/winery/highlevelrestapi/HttpResponseMessage.java b/winery/org.eclipse.winery.highlevelrestapi/src/main/java/org/eclipse/winery/highlevelrestapi/HttpResponseMessage.java deleted file mode 100644 index 14888af..0000000 --- a/winery/org.eclipse.winery.highlevelrestapi/src/main/java/org/eclipse/winery/highlevelrestapi/HttpResponseMessage.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 University of Stuttgart. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and the Apache License 2.0 which both accompany this distribution, - * and are available at http://www.eclipse.org/legal/epl-v10.html - * and http://www.apache.org/licenses/LICENSE-2.0 - * - * Contributors: - * Uwe Breitenbücher - initial API and implementation - *******************************************************************************/ -package org.eclipse.winery.highlevelrestapi; - -/** - */ -public class HttpResponseMessage { - - private int statusCode; - private String responseBody; - - - /** - * @return the statusCode - */ - public int getStatusCode() { - return this.statusCode; - } - - /** - * @param statusCode the statusCode to set - */ - protected void setStatusCode(int statusCode) { - this.statusCode = statusCode; - } - - /** - * @return the responseBody - */ - public String getResponseBody() { - return this.responseBody; - } - - /** - * @param responseBody the responseBody to set - */ - protected void setResponseBody(String responseBody) { - this.responseBody = responseBody; - } - -} diff --git a/winery/org.eclipse.winery.highlevelrestapi/src/main/java/org/eclipse/winery/highlevelrestapi/LowLevelRestApi.java b/winery/org.eclipse.winery.highlevelrestapi/src/main/java/org/eclipse/winery/highlevelrestapi/LowLevelRestApi.java deleted file mode 100644 index a99bb8f..0000000 --- a/winery/org.eclipse.winery.highlevelrestapi/src/main/java/org/eclipse/winery/highlevelrestapi/LowLevelRestApi.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 University of Stuttgart. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and the Apache License 2.0 which both accompany this distribution, - * and are available at http://www.eclipse.org/legal/epl-v10.html - * and http://www.apache.org/licenses/LICENSE-2.0 - * - * Contributors: - * Uwe Breitenbücher - initial API and implementation - * Kálmán Képes - improvements - *******************************************************************************/ -package org.eclipse.winery.highlevelrestapi; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpMethod; - -/** - * This static-class eases HTTP-method execution by self-managed fault-handling - * and automated Response-information processing - */ -public class LowLevelRestApi { - - // Local HttpClient used for every communication (Singleton implementation) - private static HttpClient httpClient = new HttpClient(); - - - /** - * Executes a passed HttpMethod (Method type is either PUT, POST, GET or - * DELETE) and returns a HttpResponseMessage - * - * @param method Method to execute - * @return HttpResponseMessage which contains all information about the - * execution - */ - public static HttpResponseMessage executeHttpMethod(HttpMethod method) { - - HttpResponseMessage responseMessage = null; - - try { - System.out.println("Method invocation on URI: \n"); - System.out.println(method.getURI().toString()); - // Execute Request - LowLevelRestApi.httpClient.executeMethod(method); - responseMessage = LowLevelRestApi.extractResponseInformation(method); - - } catch (Exception e) { - e.printStackTrace(); - } finally { - - // Release Connection anyway - method.releaseConnection(); - } - - // Extract response information and return - return responseMessage; - } - - /** - * Extracts the response information from an executed HttpMethod - * - * @param method Executed Method - * @return Packaged response information - */ - private static HttpResponseMessage extractResponseInformation(HttpMethod method) { - // Create and return HttpResponseMethod - HttpResponseMessage responseMessage = new HttpResponseMessage(); - responseMessage.setStatusCode(method.getStatusCode()); - try { - responseMessage.setResponseBody(method.getResponseBodyAsString()); - } catch (Exception e) { - e.printStackTrace(); - } - return responseMessage; - - } - -} |