aboutsummaryrefslogtreecommitdiffstats
path: root/utils/webseal-simulator/src
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-06-11 14:22:02 +0300
committerMichael Lando <ml636r@att.com>2017-06-11 17:48:32 +0300
commitb3d4898d9e8452ea0b8d848c048e712d43b8d9a3 (patch)
tree0609319203be13f6c29ccbe24cb39c9d64f90095 /utils/webseal-simulator/src
parentaf9929df75604ce407d0ca542b200630164e0ae6 (diff)
[SDC-29] rebase continue work to align source
Change-Id: I218f1c5ee23fb2c8314f1c70921d3ad8682c10f4 Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'utils/webseal-simulator/src')
-rw-r--r--utils/webseal-simulator/src/main/java/org/openecomp/sdc/webseal/simulator/Login.java6
-rw-r--r--utils/webseal-simulator/src/main/java/org/openecomp/sdc/webseal/simulator/RequestsClient.java75
-rw-r--r--utils/webseal-simulator/src/main/resources/webseal.conf18
3 files changed, 53 insertions, 46 deletions
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("</table>");
- writer.println("<hr/><iframe name='resultFrame' width='400' height='50'></iframe>");
+ writer.println("<a href='create?all=true' target='resultFrame'>Create All</a>");
+ writer.println("<hr/><iframe name='resultFrame' width='400' height='300'></iframe>");
writer.println("</body>");
writer.println("</html>");
-
+
}
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<String, User> 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) + "<br>");
+ }
+ } 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<String, String> headers = new HashMap<String, String>();
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<String, String> headers) throws IOException {
-
- String responseString="";
+
+ private int sendHttpPost(String url, String body, Map<String, String> 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<String, List<String>> headerFields = con.getHeaderFields();
- //String responseMessage = con.getResponseMessage();
+ // Map<String, List<String>> 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"
}
]
}