From b3d4898d9e8452ea0b8d848c048e712d43b8d9a3 Mon Sep 17 00:00:00 2001 From: Michael Lando Date: Sun, 11 Jun 2017 14:22:02 +0300 Subject: [SDC-29] rebase continue work to align source Change-Id: I218f1c5ee23fb2c8314f1c70921d3ad8682c10f4 Signed-off-by: Michael Lando --- .../org/openecomp/sdc/webseal/simulator/Login.java | 6 +- .../sdc/webseal/simulator/RequestsClient.java | 75 ++++++++++++++-------- .../src/main/resources/webseal.conf | 18 +----- 3 files changed, 53 insertions(+), 46 deletions(-) (limited to 'utils/webseal-simulator/src/main') diff --git a/utils/webseal-simulator/src/main/java/org/openecomp/sdc/webseal/simulator/Login.java b/utils/webseal-simulator/src/main/java/org/openecomp/sdc/webseal/simulator/Login.java index bc6dee0ce4..db4853a8f1 100644 --- a/utils/webseal-simulator/src/main/java/org/openecomp/sdc/webseal/simulator/Login.java +++ b/utils/webseal-simulator/src/main/java/org/openecomp/sdc/webseal/simulator/Login.java @@ -12,6 +12,7 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.openecomp.sdc.webseal.simulator.User; import org.openecomp.sdc.webseal.simulator.conf.Conf; public class Login extends HttpServlet { @@ -94,11 +95,12 @@ public class Login extends HttpServlet { } writer.println(""); - writer.println("
"); + writer.println("Create All"); + writer.println("
"); writer.println(""); writer.println(""); - + } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { diff --git a/utils/webseal-simulator/src/main/java/org/openecomp/sdc/webseal/simulator/RequestsClient.java b/utils/webseal-simulator/src/main/java/org/openecomp/sdc/webseal/simulator/RequestsClient.java index 5f4cfa93d2..a5e4a8a0eb 100644 --- a/utils/webseal-simulator/src/main/java/org/openecomp/sdc/webseal/simulator/RequestsClient.java +++ b/utils/webseal-simulator/src/main/java/org/openecomp/sdc/webseal/simulator/RequestsClient.java @@ -17,29 +17,51 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; +import org.openecomp.sdc.webseal.simulator.conf.Conf; public class RequestsClient extends HttpServlet { private static final long serialVersionUID = 1L; @Override - protected void doGet(final HttpServletRequest request, final HttpServletResponse response) - throws ServletException, IOException { + protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { + + String hostname = request.getParameter("hostname") != null ? request.getParameter("hostname") : "127.0.0.1"; + String port = request.getParameter("port") != null ? request.getParameter("port") : "8080"; + String adminId = request.getParameter("adminId") != null ? request.getParameter("adminId") : "jh0003"; + + String createAll = request.getParameter("all"); - String userId = request.getParameter("userId"); - String role = request.getParameter("role"); - String firstName = request.getParameter("firstName"); - String lastName = request.getParameter("lastName"); - String email = request.getParameter("email"); + PrintWriter writer = response.getWriter(); - String hostname = request.getParameter("hostname") != null?request.getParameter("hostname"):"127.0.0.1"; - String port = request.getParameter("port") != null?request.getParameter("port"):"8080"; - String adminId = request.getParameter("adminId") != null?request.getParameter("adminId"):"jh0003"; + int resultCode; + + if ("true".equals(createAll)) { + Map users = Conf.getInstance().getUsers(); + for (User user : users.values()) { + resultCode = createUser(response, user.getUserId(), user.getRole().toUpperCase(), user.getFirstName(), user.getLastName(), user.getEmail(), hostname, port, adminId); + writer.println("User "+ user.getFirstName() + " " + user.getLastName() + getResultMessage(resultCode) + "
"); + } + } else { + String userId = request.getParameter("userId"); + String role = request.getParameter("role").toUpperCase(); + String firstName = request.getParameter("firstName"); + String lastName = request.getParameter("lastName"); + String email = request.getParameter("email"); + resultCode = createUser(response, userId, role, firstName, lastName, email, hostname, port, adminId); + writer.println("User "+ firstName + " " + lastName +getResultMessage(resultCode)); + } + + + } + + private String getResultMessage(int resultCode){ + return 201 == resultCode? " created successfuly":" not created ("+ resultCode +")"; + } + + private int createUser(final HttpServletResponse response, String userId, String role, String firstName, String lastName, String email, String hostname, String port, String adminId) throws IOException { response.setContentType("text/html"); - PrintWriter writer = response.getWriter(); - writer.println("userId: " + userId); - writer.println("role: " + role); // Fill the data of the request String url = "http://" + hostname + ":" + port + "/sdc2/rest/v1/user"; @@ -47,13 +69,12 @@ public class RequestsClient extends HttpServlet { HashMap headers = new HashMap(); headers.put("Content-Type", "application/json"); headers.put("USER_ID", adminId); - sendHttpPost(url, body, headers); - + return sendHttpPost(url, body, headers); } - - private String sendHttpPost(String url, String body, Map headers) throws IOException { - - String responseString=""; + + private int sendHttpPost(String url, String body, Map headers) throws IOException { + + String responseString = ""; URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); @@ -79,8 +100,8 @@ public class RequestsClient extends HttpServlet { } int responseCode = con.getResponseCode(); - //logger.debug("Send POST http request, url: {}", url); - //logger.debug("Response Code: {}", responseCode); + // logger.debug("Send POST http request, url: {}", url); + // logger.debug("Response Code: {}", responseCode); StringBuffer response = new StringBuffer(); try { @@ -91,7 +112,7 @@ public class RequestsClient extends HttpServlet { } in.close(); } catch (Exception e) { - //logger.debug("response body is null"); + // logger.debug("response body is null"); } String result; @@ -103,18 +124,18 @@ public class RequestsClient extends HttpServlet { } catch (Exception e2) { result = null; } - //logger.debug("Response body: {}", response); + // logger.debug("Response body: {}", response); if (response != null) { responseString = response.toString(); } - //Map> headerFields = con.getHeaderFields(); - //String responseMessage = con.getResponseMessage(); + // Map> headerFields = con.getHeaderFields(); + // String responseMessage = con.getResponseMessage(); con.disconnect(); - return responseString; + return responseCode; } - + } diff --git a/utils/webseal-simulator/src/main/resources/webseal.conf b/utils/webseal-simulator/src/main/resources/webseal.conf index 869b17bebc..a7026e39fa 100644 --- a/utils/webseal-simulator/src/main/resources/webseal.conf +++ b/utils/webseal-simulator/src/main/resources/webseal.conf @@ -7,7 +7,7 @@ password="123123a" firstName="Carlos" lastName="Santana" - role="Desiner" + role="Designer" email="csantana@sdc.com" }, { @@ -41,22 +41,6 @@ lastName="Shadmi" role="Governor" email="governor@sdc.com" - }, - { - userId="pm0001" - password="123123a" - firstName="Teddy" - lastName="Isashar" - role="Product Manager" - email="pm1@sdc.com" - }, - { - userId="ps0001" - password="123123a" - firstName="Eden" - lastName="Rozin" - role="Product Strategist" - email="ps1@sdc.com" } ] } -- cgit 1.2.3-korg