import java.io.*;
import java.net.*;
import java.util.Hashtable;
import javax.naming.Context;
public class DSMLSoapClient {
public static void main(String[] args) throws Exception {
if (args.length < 4) {
System.err.println("Usage: java DSMLSoapClient " +
"http://DsmlURL dsmlfile.xml" +
" loginDN" + " userpassword");
System.err.println("Example:");
System.err.println("java DSMLSoapClient " +
"http://acme.com:8080/novell-dsml/stream " +
"e:\\dsml.xml \"cn=admin,o=acme\" \"secret\"");
System.exit(1);
}
String DsmlURL = args[0];
String DsmlDoc = args[1];
String loginDN = args[2];
String password = args[3];
String cred;
URL url;
URLConnection connection;
HttpURLConnection httpConn;
String SOAPAction = "\"#batchRequest\"";
cred=loginDN + ":" + password;
String encoding = new sun.misc.BASE64Encoder().encode (
cred.getBytes());
url = new URL(DsmlURL);
connection = url.openConnection();
connection.setRequestProperty ("Authorization", "Basic " + encoding);
httpConn = (HttpURLConnection) connection;
FileInputStream instr = new FileInputStream(DsmlDoc);
ByteArrayOutputStream outstr = new ByteArrayOutputStream();
copy(instr,outstr);
instr.close();
byte[] b = outstr.toByteArray();
httpConn.setRequestProperty( "Content-Length",
String.valueOf( b.length ) );
httpConn.setRequestProperty("Content-Type","text/xml; charset=utf-8");
httpConn.setRequestProperty("SOAPAction",SOAPAction);
httpConn.setRequestMethod( "POST" );
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
OutputStream out = httpConn.getOutputStream();
out.write( b );
out.close();
InputStreamReader ireader =
new InputStreamReader(httpConn.getInputStream());
BufferedReader in = new BufferedReader(ireader);
String inputLine;
System.out.println("\n--------------------------------------------------"
+ "------------------------");
System.out.println("\n DSML v2/SOAP Response");
System.out.println("\n--------------------------------------------------"
+ "------------------------");
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
public static void copy(InputStream in, OutputStream out)
throws IOException
{
synchronized (in) {
synchronized (out) {
byte[] buffer = new byte[256];
while (true) {
int bytesRead = in.read(buffer);
if (bytesRead == -1) break;
out.write(buffer, 0, bytesRead);
}
}
}
}
}