mirror of https://github.com/apache/jclouds.git
reverted as much custom vijava code as possible
This commit is contained in:
parent
e182253658
commit
78b77c8172
|
@ -30,6 +30,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
package com.vmware.vim25.mo;
|
package com.vmware.vim25.mo;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
import java.rmi.RemoteException;
|
import java.rmi.RemoteException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
@ -56,12 +57,8 @@ import com.vmware.vim25.ws.WSClient;
|
||||||
* @author Steve JIN (sjin@vmware.com)
|
* @author Steve JIN (sjin@vmware.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ServiceInstance extends ManagedObject {
|
public class ServiceInstance extends ManagedObject
|
||||||
|
{
|
||||||
// @Resource
|
|
||||||
// @Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
|
||||||
// protected Logger logger = Logger.NULL;
|
|
||||||
|
|
||||||
private ServiceContent serviceContent = null;
|
private ServiceContent serviceContent = null;
|
||||||
final static ManagedObjectReference SERVICE_INSTANCE_MOR;
|
final static ManagedObjectReference SERVICE_INSTANCE_MOR;
|
||||||
public final static String VIM25_NAMESPACE = " xmlns=\"urn:vim25\">";
|
public final static String VIM25_NAMESPACE = " xmlns=\"urn:vim25\">";
|
||||||
|
@ -74,10 +71,11 @@ public class ServiceInstance extends ManagedObject {
|
||||||
SERVICE_INSTANCE_MOR.setType("ServiceInstance");
|
SERVICE_INSTANCE_MOR.setType("ServiceInstance");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PATCHED CONSTRUCTOR
|
||||||
public ServiceInstance(WSClient wsc, String username, String password, String ignoreCert)
|
public ServiceInstance(WSClient wsc, String username, String password, String ignoreCert)
|
||||||
throws RemoteException, MalformedURLException {
|
throws RemoteException, MalformedURLException
|
||||||
|
{
|
||||||
|
|
||||||
//logger.debug(">> ServiceInstance(%s, %s, %s, %s)", username, password, ignoreCert);
|
|
||||||
if(ignoreCert.equals("true")) {
|
if(ignoreCert.equals("true")) {
|
||||||
this.ignoreCertificate();
|
this.ignoreCertificate();
|
||||||
}
|
}
|
||||||
|
@ -88,7 +86,7 @@ public class ServiceInstance extends ManagedObject {
|
||||||
|
|
||||||
setMOR(SERVICE_INSTANCE_MOR);
|
setMOR(SERVICE_INSTANCE_MOR);
|
||||||
|
|
||||||
VimPortType vimService_ = new VimPortType(wsc.getBaseUrl().toString(), ignoreCert.equals("true"));
|
// PATCH TO USE OUR wsc
|
||||||
VimPortType vimService = new VimPortType(wsc);
|
VimPortType vimService = new VimPortType(wsc);
|
||||||
vimService.getWsc().setVimNameSpace(wsc.getVimNameSpace());
|
vimService.getWsc().setVimNameSpace(wsc.getVimNameSpace());
|
||||||
|
|
||||||
|
@ -105,10 +103,82 @@ public class ServiceInstance extends ManagedObject {
|
||||||
.replace("'", "'");
|
.replace("'", "'");
|
||||||
|
|
||||||
UserSession userSession = getSessionManager().login(username, password, null);
|
UserSession userSession = getSessionManager().login(username, password, null);
|
||||||
// it appears that this data is never used anywhere via reference checks
|
getServerConnection().setUserSession(userSession);
|
||||||
// getServerConnection().setUserSession(userSession);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServiceInstance(URL url, String username, String password)
|
||||||
|
throws RemoteException, MalformedURLException
|
||||||
|
{
|
||||||
|
this(url, username, password, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceInstance(URL url, String username, String password, boolean ignoreCert)
|
||||||
|
throws RemoteException, MalformedURLException
|
||||||
|
{
|
||||||
|
this(url, username, password, ignoreCert, VIM25_NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceInstance(URL url, String username, String password, boolean ignoreCert, String namespace)
|
||||||
|
throws RemoteException, MalformedURLException
|
||||||
|
{
|
||||||
|
if(url == null || username==null)
|
||||||
|
{
|
||||||
|
throw new NullPointerException("None of url, username can be null.");
|
||||||
|
}
|
||||||
|
|
||||||
|
setMOR(SERVICE_INSTANCE_MOR);
|
||||||
|
|
||||||
|
VimPortType vimService = new VimPortType(url.toString(), ignoreCert);
|
||||||
|
vimService.getWsc().setVimNameSpace(namespace);
|
||||||
|
|
||||||
|
serviceContent = vimService.retrieveServiceContent(SERVICE_INSTANCE_MOR);
|
||||||
|
vimService.getWsc().setSoapActionOnApiVersion(serviceContent.getAbout().getApiVersion());
|
||||||
|
setServerConnection(new ServerConnection(url, vimService, this));
|
||||||
|
|
||||||
|
// escape 5 special chars
|
||||||
|
// http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
|
||||||
|
password = password.replace("&", "&")
|
||||||
|
.replace("<", "<")
|
||||||
|
.replace(">", ">")
|
||||||
|
.replace("\"", """)
|
||||||
|
.replace("'", "'");
|
||||||
|
|
||||||
|
UserSession userSession = getSessionManager().login(username, password, null);
|
||||||
|
getServerConnection().setUserSession(userSession);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceInstance(URL url, String sessionStr, boolean ignoreCert)
|
||||||
|
throws RemoteException, MalformedURLException
|
||||||
|
{
|
||||||
|
this(url, sessionStr, ignoreCert, VIM25_NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// sessionStr format: "vmware_soap_session=\"B3240D15-34DF-4BB8-B902-A844FDF42E85\""
|
||||||
|
public ServiceInstance(URL url, String sessionStr, boolean ignoreCert, String namespace)
|
||||||
|
throws RemoteException, MalformedURLException
|
||||||
|
{
|
||||||
|
if(url == null || sessionStr ==null)
|
||||||
|
{
|
||||||
|
throw new NullPointerException("None of url, session string can be null.");
|
||||||
|
}
|
||||||
|
|
||||||
|
setMOR(SERVICE_INSTANCE_MOR);
|
||||||
|
|
||||||
|
VimPortType vimService = new VimPortType(url.toString(), ignoreCert);
|
||||||
|
WSClient wsc = vimService.getWsc();
|
||||||
|
wsc.setCookie(sessionStr);
|
||||||
|
wsc.setVimNameSpace(namespace);
|
||||||
|
|
||||||
|
serviceContent = vimService.retrieveServiceContent(SERVICE_INSTANCE_MOR);
|
||||||
|
setServerConnection(new ServerConnection(url, vimService, this));
|
||||||
|
UserSession userSession = (UserSession) getSessionManager().getCurrentProperty("currentSession");
|
||||||
|
getServerConnection().setUserSession(userSession);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceInstance(ServerConnection sc)
|
||||||
|
{
|
||||||
|
super(sc, SERVICE_INSTANCE_MOR);
|
||||||
|
}
|
||||||
|
|
||||||
public Calendar getServerClock()
|
public Calendar getServerClock()
|
||||||
{
|
{
|
||||||
|
|
|
@ -64,13 +64,10 @@ import org.jclouds.util.Strings2;
|
||||||
import com.vmware.vim25.ManagedObjectReference;
|
import com.vmware.vim25.ManagedObjectReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Patched to include logging
|
|
||||||
*
|
|
||||||
* The Web Service Engine
|
* The Web Service Engine
|
||||||
* @author Steve Jin (sjin@vmware.com)
|
* @author Steve Jin (sjin@vmware.com)
|
||||||
*/
|
*/
|
||||||
|
// MARKED NOT FINAL
|
||||||
public class WSClient
|
public class WSClient
|
||||||
{
|
{
|
||||||
private final static String SOAP_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><soapenv:Body>";
|
private final static String SOAP_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><soapenv:Body>";
|
||||||
|
@ -86,36 +83,34 @@ public class WSClient
|
||||||
private int connectTimeout = 0;
|
private int connectTimeout = 0;
|
||||||
private int readTimeout = 0;
|
private int readTimeout = 0;
|
||||||
|
|
||||||
|
public WSClient(String serverUrl) throws MalformedURLException
|
||||||
|
{
|
||||||
public WSClient(String serverUrl) throws MalformedURLException {
|
|
||||||
this(serverUrl, true);
|
this(serverUrl, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public WSClient(String serverUrl, boolean ignoreCert) throws MalformedURLException {
|
public WSClient(String serverUrl, boolean ignoreCert) throws MalformedURLException
|
||||||
if(serverUrl.endsWith("/")) {
|
{
|
||||||
|
if(serverUrl.endsWith("/"))
|
||||||
|
{
|
||||||
serverUrl = serverUrl.substring(0, serverUrl.length()-1);
|
serverUrl = serverUrl.substring(0, serverUrl.length()-1);
|
||||||
}
|
}
|
||||||
this.baseUrl = new URL(serverUrl);
|
this.baseUrl = new URL(serverUrl);
|
||||||
if(ignoreCert) {
|
if(ignoreCert)
|
||||||
ignoreCertificates();
|
{
|
||||||
}
|
try
|
||||||
}
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void ignoreCertificates() {
|
|
||||||
try {
|
|
||||||
trustAllHttpsCertificates();
|
trustAllHttpsCertificates();
|
||||||
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
|
HttpsURLConnection.setDefaultHostnameVerifier
|
||||||
public boolean verify(String urlHostName, SSLSession session) {
|
(
|
||||||
|
new HostnameVerifier()
|
||||||
|
{
|
||||||
|
public boolean verify(String urlHostName, SSLSession session)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
} catch (Exception e) {
|
);
|
||||||
// TODO
|
} catch (Exception e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,20 +128,6 @@ public WSClient(String serverUrl) throws MalformedURLException {
|
||||||
Element body = (Element) root.elements().get(0);
|
Element body = (Element) root.elements().get(0);
|
||||||
Element resp = (Element) body.elements().get(0);
|
Element resp = (Element) body.elements().get(0);
|
||||||
|
|
||||||
// System.out.println("\n\n++++ methodName " + methodName);
|
|
||||||
//
|
|
||||||
// for (Argument argument : paras) {
|
|
||||||
// System.out.println("par: " + argument.getName() + ", " + argument.getValue());
|
|
||||||
// if(argument.getValue() instanceof ManagedObjectReference)
|
|
||||||
// System.out.println("\t** " + ((ManagedObjectReference) argument.getValue()).getVal());
|
|
||||||
// else if(argument.getValue() instanceof PropertyFilterSpec) {
|
|
||||||
// for (ObjectSpec p : ((PropertyFilterSpec) argument.getValue()).getObjectSet()) {
|
|
||||||
// System.out.println("\t-- " + p.getObj().getVal());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if(resp.getName().indexOf("Fault")!=-1)
|
if(resp.getName().indexOf("Fault")!=-1)
|
||||||
{
|
{
|
||||||
SoapFaultException sfe = null;
|
SoapFaultException sfe = null;
|
||||||
|
@ -187,8 +168,8 @@ public WSClient(String serverUrl) throws MalformedURLException {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Element invoke(String methodName, Argument[] paras) throws RemoteException {
|
public Element invoke(String methodName, Argument[] paras) throws RemoteException
|
||||||
|
{
|
||||||
String soapMsg = createSoapMessage(methodName, paras);
|
String soapMsg = createSoapMessage(methodName, paras);
|
||||||
|
|
||||||
Element root = null;
|
Element root = null;
|
||||||
|
@ -226,7 +207,8 @@ public WSClient(String serverUrl) throws MalformedURLException {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String createSoapMessage(String methodName, Argument[] paras) {
|
private String createSoapMessage(String methodName, Argument[] paras)
|
||||||
|
{
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
sb.append(SOAP_HEADER);
|
sb.append(SOAP_HEADER);
|
||||||
|
|
||||||
|
@ -242,7 +224,6 @@ public WSClient(String serverUrl) throws MalformedURLException {
|
||||||
|
|
||||||
sb.append("</" + methodName + ">");
|
sb.append("</" + methodName + ">");
|
||||||
sb.append(SOAP_END);
|
sb.append(SOAP_END);
|
||||||
// System.out.println("sb.tostring: " + sb.toString());
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,14 +252,12 @@ public WSClient(String serverUrl) throws MalformedURLException {
|
||||||
|
|
||||||
OutputStream os = postCon.getOutputStream();
|
OutputStream os = postCon.getOutputStream();
|
||||||
OutputStreamWriter out = new OutputStreamWriter(os);
|
OutputStreamWriter out = new OutputStreamWriter(os);
|
||||||
|
|
||||||
// PRINT REQUEST
|
// PRINT REQUEST
|
||||||
try {
|
try {
|
||||||
System.out.printf("%s %s HTTP/1.1%n", "POST", baseUrl.toURI().toASCIIString());
|
System.out.printf("%s %s HTTP/1.1%n", "POST", baseUrl.toURI().toASCIIString());
|
||||||
for( Entry<String, List<String>> i :postCon.getRequestProperties().entrySet()){
|
System.out.printf("%s: %s%n", SOAP_ACTION_HEADER, soapAction);
|
||||||
for (String v: i.getValue())
|
if(cookie!=null)
|
||||||
System.out.printf("%s: %s%n", i.getKey(), v);
|
System.out.printf("%s: %s%n", "Cookie", cookie);
|
||||||
}
|
|
||||||
System.out.println(soapMsg);
|
System.out.println(soapMsg);
|
||||||
|
|
||||||
} catch (URISyntaxException e1) {
|
} catch (URISyntaxException e1) {
|
||||||
|
@ -300,26 +279,25 @@ public WSClient(String serverUrl) throws MalformedURLException {
|
||||||
is = postCon.getErrorStream();
|
is = postCon.getErrorStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
// PRINT RESPONSE
|
|
||||||
|
|
||||||
System.out.printf("HTTP/1.1 %d %s", postCon.getResponseCode(), postCon.getResponseMessage());
|
|
||||||
|
|
||||||
for( Entry<String, List<String>> i :postCon.getHeaderFields().entrySet()){
|
|
||||||
for (String v: i.getValue())
|
|
||||||
System.out.printf("%s: %s%n", i.getKey(), v);
|
|
||||||
}
|
|
||||||
|
|
||||||
String response = Strings2.toStringAndClose(is);
|
|
||||||
System.out.println(response);
|
|
||||||
|
|
||||||
is = new ByteArrayInputStream(response.getBytes());
|
|
||||||
|
|
||||||
// END PRINT RESPONSE
|
|
||||||
|
|
||||||
if(cookie==null)
|
if(cookie==null)
|
||||||
{
|
{
|
||||||
cookie = postCon.getHeaderField("Set-Cookie");
|
cookie = postCon.getHeaderField("Set-Cookie");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PRINT RESPONSE
|
||||||
|
|
||||||
|
System.out.printf("HTTP/1.1 %d %s", postCon.getResponseCode(), postCon.getResponseMessage());
|
||||||
|
|
||||||
|
for (Entry<String, List<String>> i : postCon.getHeaderFields().entrySet()) {
|
||||||
|
for (String v : i.getValue())
|
||||||
|
System.out.printf("%s: %s%n", i.getKey(), v);
|
||||||
|
}
|
||||||
|
String response = Strings2.toStringAndClose(is);
|
||||||
|
System.out.println(response);
|
||||||
|
is = new ByteArrayInputStream(response.getBytes());
|
||||||
|
|
||||||
|
// END PRINT RESPONSE
|
||||||
|
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,7 +408,5 @@ public WSClient(String serverUrl) throws MalformedURLException {
|
||||||
throws CertificateException
|
throws CertificateException
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue