added debug to vsphere adapter

This commit is contained in:
Adrian Cole 2011-01-23 12:41:00 -08:00
parent ee4845905d
commit e182253658
2 changed files with 50 additions and 18 deletions

View File

@ -30,6 +30,7 @@ POSSIBILITY OF SUCH DAMAGE.
package com.vmware.vim25.ws; package com.vmware.vim25.ws;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -38,12 +39,15 @@ import java.io.OutputStreamWriter;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.ProtocolException; import java.net.ProtocolException;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Map.Entry;
import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
@ -55,11 +59,9 @@ import javax.net.ssl.X509TrustManager;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.io.SAXReader; import org.dom4j.io.SAXReader;
import org.jclouds.util.Strings2;
import com.vmware.vim25.ManagedObjectReference; import com.vmware.vim25.ManagedObjectReference;
import com.vmware.vim25.ObjectSpec;
import com.vmware.vim25.PropertyFilterSpec;
import com.vmware.vim25.PropertySpec;
/** /**
* *
@ -270,6 +272,20 @@ 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
try {
System.out.printf("%s %s HTTP/1.1%n", "POST", baseUrl.toURI().toASCIIString());
for( Entry<String, List<String>> i :postCon.getRequestProperties().entrySet()){
for (String v: i.getValue())
System.out.printf("%s: %s%n", i.getKey(), v);
}
System.out.println(soapMsg);
} catch (URISyntaxException e1) {
}
// END PRINT REQUEST
out.write(soapMsg); out.write(soapMsg);
out.close(); out.close();
@ -284,6 +300,22 @@ 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");

View File

@ -23,7 +23,6 @@ import static com.google.common.base.Predicates.notNull;
import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Iterables.transform;
import static org.jclouds.vi.reference.ViConstants.PROPERTY_VI_XML_NAMESPACE; import static org.jclouds.vi.reference.ViConstants.PROPERTY_VI_XML_NAMESPACE;
import static org.jclouds.vi.reference.ViConstants.PROPERTY_VI_IGNORE_CERTIFICATE;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -87,8 +86,7 @@ public class ViComputeServiceContextModule
extends extends
ComputeServiceAdapterContextModule<ServiceInstance, ServiceInstance, VirtualMachine, VirtualMachine, Image, Datacenter> { ComputeServiceAdapterContextModule<ServiceInstance, ServiceInstance, VirtualMachine, VirtualMachine, Image, Datacenter> {
public ViComputeServiceContextModule() {
public ViComputeServiceContextModule() {
super(ServiceInstance.class, ServiceInstance.class); super(ServiceInstance.class, ServiceInstance.class);
} }
@ -112,28 +110,30 @@ public class ViComputeServiceContextModule
@Provides @Provides
@Singleton @Singleton
protected ServiceInstance createConnection(JcloudsWSClient client, protected ServiceInstance createConnection(JcloudsWSClient client,
@Named(Constants.PROPERTY_IDENTITY) String identity, @Named(Constants.PROPERTY_CREDENTIAL) String credential, @Named(Constants.PROPERTY_IDENTITY) String identity,
@Named(PROPERTY_VI_IGNORE_CERTIFICATE) String ignoreCertificate) @Named(Constants.PROPERTY_CREDENTIAL) String credential,
throws RemoteException, MalformedURLException { @Named(Constants.PROPERTY_TRUST_ALL_CERTS) boolean ignoreCertificate) throws RemoteException,
return new ServiceInstance(client, identity, credential, ignoreCertificate); MalformedURLException {
// uncomment this to use jclouds http commands
// return new ServiceInstance(client, identity, credential, ignoreCertificate);
return new ServiceInstance(new WSClient(client.getBaseUrl().toString(), ignoreCertificate), identity, credential,
ignoreCertificate + "");
} }
@Singleton @Singleton
public public static class JcloudsWSClient extends WSClient {
static class JcloudsWSClient extends WSClient {
private final HttpClient client; private final HttpClient client;
@Inject @Inject
public JcloudsWSClient(HttpClient client, @Provider URI baseUrl, public JcloudsWSClient(HttpClient client, @Provider URI baseUrl,
@Named(PROPERTY_VI_XML_NAMESPACE) String vimNameSpace, @Named(PROPERTY_VI_XML_NAMESPACE) String vimNameSpace,
@Named(PROPERTY_VI_IGNORE_CERTIFICATE) String ignoreCert) throws MalformedURLException { @Named(Constants.PROPERTY_TRUST_ALL_CERTS) boolean ignoreCert) throws MalformedURLException {
super(baseUrl.toASCIIString(), ignoreCert.equals("true")); super(baseUrl.toASCIIString(), ignoreCert);
this.setVimNameSpace(vimNameSpace); this.setVimNameSpace(vimNameSpace);
this.client = client; this.client = client;
} }
@Override @Override
public InputStream post(String soapMsg) throws IOException { public InputStream post(String soapMsg) throws IOException {