Shahar Havivi has uploaded a new change for review. Change subject: java sample portal: first commit ......................................................................
java sample portal: first commit Change-Id: I225d5b71e831c80cd7351161529f0f695e8d201a Signed-off-by: Shahar Havivi <shav...@redhat.com> --- A java/javauserportal/pom.xml A java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/ActionRestCommand.java A java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/LoginRestCommand.java A java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/OVirtProperties.java A java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/RestClient.java A java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/RestCommand.java A java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/UserVmsRestCommand.java A java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/VmByIdRestCommand.java A java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/VmDetails.java A java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/ovirt.properties A java/javauserportal/src/main/webapp/WEB-INF/web.xml A java/javauserportal/src/main/webapp/action.jsp A java/javauserportal/src/main/webapp/index.jsp A java/javauserportal/src/main/webapp/uservms.jsp 14 files changed, 672 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/samples-portals refs/changes/20/9520/1 diff --git a/java/javauserportal/pom.xml b/java/javauserportal/pom.xml new file mode 100644 index 0000000..b4d979d --- /dev/null +++ b/java/javauserportal/pom.xml @@ -0,0 +1,27 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.ovirt.samples.portals</groupId> + <artifactId>javauserportal</artifactId> + <packaging>war</packaging> + <version>0.0.1-SNAPSHOT</version> + <name>javauserportal Maven Webapp</name> + <url>http://maven.apache.org</url> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>commons-httpclient</groupId> + <artifactId>commons-httpclient</artifactId> + <version>3.0-rc3</version> + </dependency> + + </dependencies> + <build> + <finalName>javauserportal</finalName> + </build> +</project> diff --git a/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/ActionRestCommand.java b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/ActionRestCommand.java new file mode 100644 index 0000000..fca2474 --- /dev/null +++ b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/ActionRestCommand.java @@ -0,0 +1,75 @@ +package org.ovirt.samples.portals.javauserportal; + +import java.io.IOException; +import java.io.InputStream; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +public class ActionRestCommand extends RestCommand { + + private String failReason; + private String failDetails; + private String ticketValue; + private String ticketExpired; + + public ActionRestCommand(String url, String cookie) { + super(url, cookie); + } + + @Override + public void parseResponse(InputStream stream) { + DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = null; + Document doc = null; + + try { + builder = fact.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + this.setMessage("Document parsing error: " + e.getMessage()); + return; + } + try { + doc = builder.parse(stream); + } catch (SAXException e) { + this.setMessage("Document building error: " + e.getMessage()); + return; + } catch (IOException e) { + this.setMessage("IO Exception: " + e.getMessage()); + return; + } + + String status = doc.getElementsByTagName("state").item(0).getFirstChild().getNodeValue(); + + if (status.equals("failed")) { + this.failReason = doc.getElementsByTagName("reason").item(0).getFirstChild().getNodeValue(); + this.failDetails = doc.getElementsByTagName("detail").item(0).getFirstChild().getNodeValue(); + } else if (this.url.contains("ticket")) { + Element t = (Element)doc.getElementsByTagName("ticket").item(0); + this.ticketValue = t.getElementsByTagName("value").item(0).getFirstChild().getNodeValue(); + this.ticketExpired = t.getElementsByTagName("expiry").item(0).getFirstChild().getNodeValue(); + } + } + + public String getFailReason() { + return failReason; + } + + public String getFailDetails() { + return failDetails; + } + + public String getTicketValue() { + return ticketValue; + } + + public String getTicketExpired() { + return ticketExpired; + } +} \ No newline at end of file diff --git a/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/LoginRestCommand.java b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/LoginRestCommand.java new file mode 100644 index 0000000..2760b12 --- /dev/null +++ b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/LoginRestCommand.java @@ -0,0 +1,21 @@ +package org.ovirt.samples.portals.javauserportal; + +import java.io.InputStream; + +public class LoginRestCommand extends RestCommand { + + private boolean loggedin = false; + + public LoginRestCommand(String url, String userName, String password) { + super(url, userName, password); + } + + @Override + public void parseResponse(InputStream stream) { + this.loggedin = (this.message == ""); + } + + public boolean isLoggedin() { + return this.loggedin; + } +} diff --git a/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/OVirtProperties.java b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/OVirtProperties.java new file mode 100644 index 0000000..f52df67 --- /dev/null +++ b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/OVirtProperties.java @@ -0,0 +1,25 @@ +package org.ovirt.samples.portals.javauserportal; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +public class OVirtProperties { + private String baseUrl; + + public OVirtProperties() { + Properties prop = new Properties(); + InputStream in = getClass().getResourceAsStream("ovirt.properties"); + try { + prop.load(in); + this.baseUrl = prop.getProperty("BaseUrl"); + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public String getBaseUrl() { + return this.baseUrl; + } +} diff --git a/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/RestClient.java b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/RestClient.java new file mode 100644 index 0000000..f6558ac --- /dev/null +++ b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/RestClient.java @@ -0,0 +1,97 @@ +package org.ovirt.samples.portals.javauserportal; + +import java.io.IOException; +import java.net.HttpURLConnection; + +import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.auth.AuthScope; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.RequestEntity; +import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.apache.commons.httpclient.params.HttpMethodParams; + +public class RestClient { + public void doGetCommand(RestCommand command) { + HttpClient client = new HttpClient(); + GetMethod method = new GetMethod(command.getUrl()); + method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, + new DefaultHttpMethodRetryHandler(3, false)); + method.setRequestHeader("filter", "true"); + method.setRequestHeader("Prefer", "persistent-auth"); + + if (command.getCookie() != null) { + method.setRequestHeader("Cookie", command.getCookie()); + } else { + client.getParams().setAuthenticationPreemptive(true); + client.getState().setCredentials(AuthScope.ANY, command.getCredentials()); + } + + try { + int statusCode = client.executeMethod(method); + + if (statusCode != HttpStatus.SC_OK) { + command.setMessage("Get Method failed: " + method.getStatusLine()); + return; + } + + if (method.getResponseHeader("Set-Cookie") != null) { + command.setCookie(method.getResponseHeader("Set-Cookie").getValue()); + } + command.parseResponse(method.getResponseBodyAsStream()); + + } catch (HttpException e) { + command.setMessage("Fatal protocol violation: " + e.getMessage()); + } catch (IOException e) { + command.setMessage("Fatal transport error: " + e.getMessage()); + } finally { + method.releaseConnection(); + } + } + + public void doPostCommand(RestCommand command) { + HttpClient client = new HttpClient(); + PostMethod method = new PostMethod(command.getUrl()); + + method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, + new DefaultHttpMethodRetryHandler(3, false)); + method.setRequestHeader("Content-type", "application/xml"); + method.setRequestHeader("filter", "true"); + method.setRequestHeader("Prefer", "persistent-auth"); + + if (command.getCookie() != null) { + method.setRequestHeader("Cookie", command.getCookie()); + } else { + client.getParams().setAuthenticationPreemptive(true); + client.getState().setCredentials(AuthScope.ANY, command.getCredentials()); + } + + // @deprecated... + //method.setRequestBody("<action/>"); + RequestEntity entity = new StringRequestEntity("<action/>"); + method.setRequestEntity(entity); + + try { + if (method.getResponseHeader("Set-Cookie") != null) { + command.setCookie(method.getResponseHeader("Set-Cookie").getValue()); + } + int statusCode = client.executeMethod(method); + if (statusCode != HttpStatus.SC_OK) { + command.setMessage("Post Method failed: " + method.getStatusLine()); + } + command.parseResponse(method.getResponseBodyAsStream()); + + } catch (HttpException e) { + command.setMessage("Fatal protocol violation: " + e.getMessage()); + } catch (IOException e) { + command.setMessage("Fatal transport error: " + e.getMessage()); + } catch (Exception e) { + command.setMessage("Fatal error: " + e.getMessage()); + } finally { + method.releaseConnection(); + } + } +} diff --git a/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/RestCommand.java b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/RestCommand.java new file mode 100644 index 0000000..4332c2b --- /dev/null +++ b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/RestCommand.java @@ -0,0 +1,52 @@ +package org.ovirt.samples.portals.javauserportal; + +import java.io.InputStream; + +import org.apache.commons.httpclient.Credentials; +import org.apache.commons.httpclient.UsernamePasswordCredentials; + +public abstract class RestCommand { + protected String url; + protected String message; + private String cookie; + private Credentials credentials; + + public RestCommand(String url, String userName, String password) { + this.url = url; + this.message = ""; + this.credentials = new UsernamePasswordCredentials(userName, password); + } + + public RestCommand(String url, String cookie) { + this.url = url; + this.message = ""; + this.cookie = cookie; + } + + public String getUrl() { + return this.url; + } + + public String getCookie() { + return this.cookie; + } + + public void setCookie(String cookie) { + this.cookie = cookie; + } + + + public Credentials getCredentials() { + return this.credentials; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message += message + "\r\n<br/>"; + } + + public abstract void parseResponse(InputStream stream); +} diff --git a/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/UserVmsRestCommand.java b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/UserVmsRestCommand.java new file mode 100644 index 0000000..bf7e9d8 --- /dev/null +++ b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/UserVmsRestCommand.java @@ -0,0 +1,82 @@ +package org.ovirt.samples.portals.javauserportal; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + + +public class UserVmsRestCommand extends RestCommand { + + private List<VmDetails> vms; + + public UserVmsRestCommand(String url, String cookie) { + super(url, cookie); + this.vms = new ArrayList<VmDetails>(); + } + + @Override + public void parseResponse(InputStream stream) { + DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = null; + try { + builder = fact.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + this.message = "Cannot create DocumentBuilder: " + e.getMessage(); + return; + } + try { + Document doc = builder.parse(stream); + NodeList allVms = doc.getElementsByTagName("vm"); + for(int i=0; i < allVms.getLength(); i++) { + Element node = (Element)allVms.item(i); + this.vms.add(initVmDetails(node)); + } + + } catch (SAXException e) { + this.message = "Error parsing User Vms: " + e.getMessage(); + return; + } catch (IOException e) { + this.message = "Error parsing User Vms: " + e.getMessage(); + return; + } + } + + protected VmDetails initVmDetails(Element node) { + VmDetails vmDetails = new VmDetails(); + + vmDetails.setId(node.getAttribute("id")); + vmDetails.setName(node.getElementsByTagName("name").item(0).getFirstChild().getNodeValue()); + vmDetails.setStatus(((Element)node.getElementsByTagName("status").item(0)).getElementsByTagName("state").item(0).getFirstChild().getNodeValue()); + + Element displayElement = (Element)node.getElementsByTagName("display").item(0); + vmDetails.setDisplay(displayElement.getElementsByTagName("type").item(0).getFirstChild().getNodeValue()); + + if (displayElement.getElementsByTagName("port").getLength() > 0) { + vmDetails.setPort(displayElement.getElementsByTagName("port").item(0).getFirstChild().getNodeValue()); + } + + if (displayElement.getElementsByTagName("address").getLength() > 0) { + vmDetails.setAddress(displayElement.getElementsByTagName("address").item(0).getFirstChild().getNodeValue()); + } + + return vmDetails; + } + + public List<VmDetails> getVms() { + return vms; + } + + public void setVms(List<VmDetails> vms) { + this.vms = vms; + } +} diff --git a/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/VmByIdRestCommand.java b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/VmByIdRestCommand.java new file mode 100644 index 0000000..e362928 --- /dev/null +++ b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/VmByIdRestCommand.java @@ -0,0 +1,48 @@ +package org.ovirt.samples.portals.javauserportal; + +import java.io.IOException; +import java.io.InputStream; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +public class VmByIdRestCommand extends UserVmsRestCommand { + + private VmDetails vmDetails; + + public VmByIdRestCommand(String url, String cookie) { + super(url, cookie); + } + + @Override + public void parseResponse(InputStream stream) { + DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = null; + try { + builder = fact.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + this.message = "Cannot create DocumentBuilder: " + e.getMessage(); + return; + } + try { + Document doc = builder.parse(stream); + this.vmDetails = initVmDetails((Element)doc.getElementsByTagName("vm").item(0)); + + } catch (SAXException e) { + this.message = "Error parsing User Vms: " + e.getMessage(); + return; + } catch (IOException e) { + this.message = "Error parsing User Vms: " + e.getMessage(); + return; + } + } + + public VmDetails getVmDetails() { + return this.vmDetails; + } +} diff --git a/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/VmDetails.java b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/VmDetails.java new file mode 100644 index 0000000..efd4064 --- /dev/null +++ b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/VmDetails.java @@ -0,0 +1,55 @@ +package org.ovirt.samples.portals.javauserportal; + +public class VmDetails { + private String id; + private String name; + private String status; + private String display; + private String port; + private String address; + + public VmDetails() { + } + + public void setId(String id) { + this.id = id; + } + public String getId() { + return this.id; + } + + public void setName(String name) { + this.name = name; + } + public String getName() { + return this.name; + } + + public void setStatus(String status) { + this.status = status; + } + public String getStatus() { + return this.status; + } + + public void setDisplay(String display) { + this.display = display; + } + public String getDisplay() { + return this.display; + } + + public void setPort(String port) { + this.port = port; + } + public String getPort() { + return this.port; + } + + public void setAddress(String address) { + this.address = address; + } + public String getAddress() { + return this.address; + } +} diff --git a/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/ovirt.properties b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/ovirt.properties new file mode 100644 index 0000000..661c02d --- /dev/null +++ b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/ovirt.properties @@ -0,0 +1 @@ +BaseUrl=http://localhost:8080 diff --git a/java/javauserportal/src/main/webapp/WEB-INF/web.xml b/java/javauserportal/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..9f88c1f --- /dev/null +++ b/java/javauserportal/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,7 @@ +<!DOCTYPE web-app PUBLIC + "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" + "http://java.sun.com/dtd/web-app_2_3.dtd" > + +<web-app> + <display-name>Archetype Created Web Application</display-name> +</web-app> diff --git a/java/javauserportal/src/main/webapp/action.jsp b/java/javauserportal/src/main/webapp/action.jsp new file mode 100644 index 0000000..ce40e56 --- /dev/null +++ b/java/javauserportal/src/main/webapp/action.jsp @@ -0,0 +1,84 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<%@page import="org.ovirt.samples.portals.javauserportal.ActionRestCommand"%> +<%@page import="org.ovirt.samples.portals.javauserportal.VmByIdRestCommand"%> +<%@page import="org.ovirt.samples.portals.javauserportal.RestCommand"%> +<%@page import="org.ovirt.samples.portals.javauserportal.RestClient"%> +<html> +<body> + <% + if (session.getAttribute("cookie") == null) { + response.sendRedirect("index.jsp"); + } + + ActionRestCommand command = new ActionRestCommand(session.getAttribute("baseUrl") + "/api/vms/" + + request.getParameter("vmid") + "/" + request.getParameter("action"), + (String)session.getAttribute("cookie")); + RestClient client = new RestClient(); + client.doPostCommand(command); + %> + <% + if (command.getFailReason() != null) { + %> + <p style='color:red'>Action failed!</p> + <br/>Reason: <%= command.getFailReason() %> + <br/>Details:<%= command.getFailDetails() %> + <br/> + <button onclick=javascript:history.back()>Back</button> + <% + } else if (command.getUrl().contains("ticket")) { + VmByIdRestCommand vmCommand = new VmByIdRestCommand(session.getAttribute("baseUrl") + "/api/vms/" + + request.getParameter("vmid"), + (String)session.getAttribute("cookie")); + client.doGetCommand(vmCommand); + + if (request.getHeader("user-agent").toLowerCase().contains("windows")) { + %> + <OBJECT style='visibility: hidden' codebase='SpiceX.cab#version=1,0,0,1' ID='spice' CLASSID='CLSID:ACD6D89C-938D-49B4-8E81-DDBD13F4B48A'> + </OBJECT> + <script> + function onConnect() { + spice.HostIP = '<%= vmCommand.getVmDetails().getAddress() %>' + spice.Port = '<%= vmCommand.getVmDetails().getPort() %>' + spice.Password = '<%= command.getTicketValue() %>' + spice.Connect(); + } + </script> + + <form> + <input type=button onclick='javascript:onConnect();' value='Connect'/> + </form> + <br/> + <button onclick=javascript:location.href='uservms.jsp'>Back</button> + <% + } else { + %> + <script> + function onConnect() { + spice.hostIP = '<%= vmCommand.getVmDetails().getAddress() %>'; + spice.port = '<%= vmCommand.getVmDetails().getPort() %>'; + spice.Password = '<%= command.getTicketValue() %>'; + spice.connect(); + spice.show() + } + </script> + <embed id='spice' type="application/x-spice" width=0 height=0><br> + <form> + <input type=button value='Connent' onclick='onConnect()'/> + </form> + <br/> + <button onclick=javascript:location.href='uservms.jsp'>Back</button> + <% + } + } + else { + %> + Action success + <br/> + <button onclick=javascript:location.href='uservms.jsp'>Back</button> + </body></html> + <% + } + %> +</body> +</html> diff --git a/java/javauserportal/src/main/webapp/index.jsp b/java/javauserportal/src/main/webapp/index.jsp new file mode 100644 index 0000000..8d6b6ef --- /dev/null +++ b/java/javauserportal/src/main/webapp/index.jsp @@ -0,0 +1,52 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<%@page import="org.ovirt.samples.portals.javauserportal.OVirtProperties"%> +<%@page import="org.ovirt.samples.portals.javauserportal.RestCommand"%> +<%@page import="org.ovirt.samples.portals.javauserportal.LoginRestCommand"%> +<%@page import="org.ovirt.samples.portals.javauserportal.RestClient"%> +<html> +<body> + <form name="input" action="index.jsp" method="post"> + <% + String username = ""; + String message = ""; + + if (request.getParameter("username") != null && request.getParameter("password") != null) { + session.removeAttribute("cookie"); + OVirtProperties prop = new OVirtProperties(); + session.setAttribute("baseUrl", prop.getBaseUrl()); + + LoginRestCommand command = new LoginRestCommand(prop.getBaseUrl() + "/api", request.getParameter("username"), request.getParameter("password")); + RestClient client = new RestClient(); + client.doGetCommand(command); + if (command.isLoggedin()) { + session.setAttribute("cookie", command.getCookie()); + response.sendRedirect("uservms.jsp"); + } + else { + message = "Login Error<br/>(" + command.getMessage() + ")"; + } + } + + %> + <center> + <br/><br/> + <table> + <tr> + <td>User name:</td> + <td><input type="text" name="username" /></td> + + <tr> + <td>Password:</td> + <td><input type="password" name="password" /></td> + <tr> + <td/> + <td align="right"><input type="submit" value="Login"/></td> + </tr> + + + </table> + <p style='color:red;'><%= message %></p> + </center> + </form> +</body> +</html> diff --git a/java/javauserportal/src/main/webapp/uservms.jsp b/java/javauserportal/src/main/webapp/uservms.jsp new file mode 100644 index 0000000..88d87f8 --- /dev/null +++ b/java/javauserportal/src/main/webapp/uservms.jsp @@ -0,0 +1,46 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<%@page import="org.ovirt.samples.portals.javauserportal.UserVmsRestCommand"%> +<%@page import="org.ovirt.samples.portals.javauserportal.RestCommand"%> +<%@page import="org.ovirt.samples.portals.javauserportal.RestClient"%> +<%@page import="org.ovirt.samples.portals.javauserportal.VmDetails"%> +<html> +<body> + <% + if (session.getAttribute("cookie") == null) { + response.sendRedirect("index.jsp"); + } + + UserVmsRestCommand command = new UserVmsRestCommand(session.getAttribute("baseUrl") + "/api/vms", (String)session.getAttribute("cookie")); + RestClient client = new RestClient(); + client.doGetCommand(command); + %> + <center> + <br/><br/> + <table cellpadding="5" style='border-width: 1px; border-spacing: 2px; border-style: outset; border-color: gray; border-collapse: separate; background-color: white;'> + <tr> + <th>VM Name</th> + <th>Status</th> + <th>Display</th> + <th>Start</th> + <th>Stop</th> + <th>Launch</th> + </tr> + <% + for (VmDetails vm: command.getVms()) { + %> + <tr> + <td><%= vm.getName() %></td> + <td><%= vm.getStatus() %></td> + <td><%= vm.getDisplay() %></td> + <td><button %s onclick=javascript:location.href='action.jsp?vmid=<%= vm.getId() %>&action=start' type='button'>Start</button></td> + <td><button %s onclick=javascript:location.href='action.jsp?vmid=<%= vm.getId() %>&action=stop' type='button'>Stop</button></td> + <td><button %s onclick=javascript:location.href='action.jsp?vmid=<%= vm.getId() %>&action=ticket' type='button'>Launch</button></td> + </tr> + <% + } + %> + </table> + + </center> +</body> +</html> -- To view, visit http://gerrit.ovirt.org/9520 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I225d5b71e831c80cd7351161529f0f695e8d201a Gerrit-PatchSet: 1 Gerrit-Project: samples-portals Gerrit-Branch: master Gerrit-Owner: Shahar Havivi <shav...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches