package eu.guermonprez.paul.oss.iamt;
/*
* Copyright 2009 Paul Guermonprez paul@guermonprez.eu
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) version 3.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
import java.net.Authenticator;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Holder;
import eu.guermonprez.paul.oss.iamt.wsimport.remotecontrol.RemoteControlService;
import eu.guermonprez.paul.oss.iamt.wsimport.remotecontrol.RemoteControlSoapPortType;
public class HelloAMT {
/**
* @param args
* command line arguments : login password hostname [port]
*/
public static void main(String[] args) {
// parsing command line arguments
if (args.length == 0) {
printHelp();
}
String login = args[0];
String password = args[1];
String host = args[2];
String port = "16992";
if (args.length == 4) {
port = args[3];
}
// changing the default Authenticator to enable digest HTTP auth
Authenticator.setDefault(new DigestAuthenticator(login, password));
try {
// service
RemoteControlService service = new RemoteControlService();
// port logical definition from service
RemoteControlSoapPortType rcPort = (RemoteControlSoapPortType) service
.getRemoteControlSoapPort();
// port parameters : hostname, port and remote service name
((BindingProvider) rcPort).getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://" + host + ":" + port + "/RemoteControlService");
// port is ready and configured, but not called yet
// prepare holders : they carry parameters,
// as reference to variables in memory
// wouldn't work over the network
Holder status = new Holder();
Holder systemPowerState = new Holder();
// RPC call !
// the holders are empty, they will be filled
// with the results of the method call
rcPort.getSystemPowerState(status, systemPowerState);
// now the holders are full
// the holder won't give you the result,
// you need to get the value from it,
// and use the right "parser" (here Long)
long statusLong = status.value.longValue();
long systemPowerStateLong = systemPowerState.value.longValue();
// done, printing results
System.out
.println("HelloAMT : Simple software to display the status of Intel AMT aware computers\n\n"
+ "Copyright 2009 Paul Guermonprez paul@guermonprez.eu\n"
+ "GNU Lesser General Public License\n\n");
System.out.println("status : " + statusLong);
System.out.println("power : " + systemPowerStateLong);
System.out.println("host : " + host);
System.out.println("login : " + login);
System.out.println("password : " + password);
System.out.println("SOAP : " + rcPort);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void printHelp() {
System.out
.println("HelloAMT : Simple software to display the status of Intel AMT aware computers\n\n"
+ "Copyright 2009 Paul Guermonprez paul@guermonprez.eu\n"
+ "GNU Lesser General Public License\n\n"
+ "Syntax :\n"
+ "HelloAMT login password hostname [port]\n"
+ "(default port number is 16992)\n");
}
}