Shahar Havivi has uploaded a new change for review. Change subject: java: support for oVirt SDK ......................................................................
java: support for oVirt SDK Change the connection with oVirt engine to work with oVirt SDK and not via direct RESTful calls Change-Id: Ieab9134ab61e136a3eb1ccc85bdef7aac728a2f7 Signed-off-by: Shahar Havivi <shav...@redhat.com> --- M java/javauserportal/README M java/javauserportal/pom.xml M java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/ActionRestCommand.java A java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/OVirtSDKWrapper.java M java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/RestClient.java M java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/ovirt.properties M java/javauserportal/src/main/webapp/index.jsp 7 files changed, 61 insertions(+), 15 deletions(-) git pull ssh://gerrit.ovirt.org:29418/samples-portals refs/changes/92/11092/1 diff --git a/java/javauserportal/README b/java/javauserportal/README index eb1ae45..3dcf508 100644 --- a/java/javauserportal/README +++ b/java/javauserportal/README @@ -1 +1,9 @@ -... +Edit the file "./src/main/java/org/ovirt/samples/portals/javauserportal/ovirt.properties" with the proper oVirt base Url + +Compile the project: +$ mvn clean install + +Deploy the war (in this case JBoss 7.1): +$ cp target/javauserportal.war /usr/local/jboss-as-8.1.1.Final/standalone/deployments/ + + diff --git a/java/javauserportal/pom.xml b/java/javauserportal/pom.xml index b4d979d..69410df 100644 --- a/java/javauserportal/pom.xml +++ b/java/javauserportal/pom.xml @@ -19,7 +19,13 @@ <artifactId>commons-httpclient</artifactId> <version>3.0-rc3</version> </dependency> - + <dependency> + <groupId>org.ovirt.engine.sdk</groupId> + <artifactId>ovirt-engine-sdk-java</artifactId> + <version>1.0.0.1-1</version> + <type>jar</type> + <scope>compile</scope> + </dependency> </dependencies> <build> <finalName>javauserportal</finalName> 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 index f0188e2..7896e14 100644 --- 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 @@ -9,7 +9,6 @@ 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 { diff --git a/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/OVirtSDKWrapper.java b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/OVirtSDKWrapper.java new file mode 100644 index 0000000..6967b16 --- /dev/null +++ b/java/javauserportal/src/main/java/org/ovirt/samples/portals/javauserportal/OVirtSDKWrapper.java @@ -0,0 +1,36 @@ +package org.ovirt.samples.portals.javauserportal; + +import java.io.IOException; + +import org.apache.http.client.ClientProtocolException; +import org.ovirt.engine.sdk.Api; +import org.ovirt.engine.sdk.exceptions.ServerException; +import org.ovirt.engine.sdk.exceptions.UnsecuredConnectionAttemptError; + +public class OVirtSDKWrapper { + private Api api; + private String message; + + public void login(String baseUrl, String userName, String password) { + try { + // true for filter, ie enable regular users to login + this.api = new Api(baseUrl, userName, password, null, null, null, null, null, null, null, true, null); + } catch (ClientProtocolException e) { + this.message = "Protocol Exception: " + e.getMessage(); + } catch (ServerException e) { + this.message = "Server Exception: " + e.getMessage(); + } catch (UnsecuredConnectionAttemptError e) { + this.message = "Unsecured Connection Exception: " + e.getMessage(); + } catch (IOException e) { + this.message = "IOException Exception: " + e.getMessage(); + } + } + + public boolean isLoggedin() { + return this.api != null; + } + + public String getMessage() { + return this.message; + } +} 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 index f1410cc..36da6fa 100644 --- 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 @@ -1,7 +1,6 @@ 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; 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 index 661c02d..36c8b7c 100644 --- 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 @@ -1 +1 @@ -BaseUrl=http://localhost:8080 +BaseUrl=http://localhost:8700 diff --git a/java/javauserportal/src/main/webapp/index.jsp b/java/javauserportal/src/main/webapp/index.jsp index 56bb97d..bc8fad6 100644 --- a/java/javauserportal/src/main/webapp/index.jsp +++ b/java/javauserportal/src/main/webapp/index.jsp @@ -1,3 +1,4 @@ +<%@page import="org.ovirt.samples.portals.javauserportal.OVirtSDKWrapper"%> <%@ 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"%> @@ -7,23 +8,20 @@ <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"); + OVirtSDKWrapper wrapper = new OVirtSDKWrapper(); + session.setAttribute("wrapper", wrapper); + + wrapper.login(prop.getBaseUrl() + "/api", request.getParameter("username"), request.getParameter("password")); + if (wrapper.isLoggedin()) { + response.sendRedirect("uservms.jsp"); } else { - message = "Login Error<br/>(" + command.getMessage() + ")"; + message = "Login Error<br/>(" + wrapper.getMessage() + ")"; } } -- To view, visit http://gerrit.ovirt.org/11092 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ieab9134ab61e136a3eb1ccc85bdef7aac728a2f7 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