IE: What method does it use...proprietary? DCOM, RMI, XML-RPC, etc?
(please excude my ignorance about Java
Moderator: General Moderators
Code: Select all
package com.b2b.test;
//Base Imports
import java.io.*;
import java.net.*;
import java.util.*;
import java.text.SimpleDateFormat;
public class TestClient {
public void test() {
System.out.println("Starting");
// URL to perform post()
String urlString =
"https://someplace.com/blah";
// setup SSL
try {
https.System.setProperty(
"java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
java.security.Security.addProvider(
(java.security.Provider) Class
.forName("com.sun.net.ssl.internal.ssl.Provider")
.newInstance());
} catch (Exception ex) {
// unable to setup SSL
System.out.println(
"Error in setting up SSL stuff, make sure youhave JSSE jars in classpath "
+ ex);
}
URL url = null;
try {
url = new URL(urlString);
} catch (Exception e) {
System.out.println("URL creation error");
e.printStackTrace();
}
URLConnection conn = null;
try {
conn = url.openConnection();
} catch (Exception e) {
System.out.println("connection error");
e.printStackTrace();
System.exit(1);
}
conn.setUseCaches(false);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestProperty("Content-type", "text/xml");
// if you want to read the XML from a file
StringBuffer xmlStrBuff = new StringBuffer();
try {
FileReader fr = new FileReader("c\\:your_request_file.xml");
BufferedReader br = new BufferedReader(fr);
int ch;
while ((ch = br.read()) > -1) {
xmlStrBuff.append((char) ch);
}
} catch (IOException e) {
System.out.println("Error in reading file " + e);
e.printStackTrace();
}
String xmlstr = xmlStrBuff.toString();
System.out.println("Sending xml string = \n" + xmlstr);
OutputStream out = null;
try {
out = conn.getOutputStream();
out.write(xmlstr.getBytes());
out.close();
} catch (Exception e) {
System.out.println("output stream error");
e.printStackTrace();
System.exit(1);
}
InputStream in = null;
try {
System.out.println("\n\n////////////////////////////////////response times");
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy h:m:s.SSS");
System.out.println(sdf.format(new Date()) + " - Sent Request to theServlet");
//finally, invoke the servlet
in = conn.getInputStream();
System.out.println(
sdf.format(new Date()) + " - Received Responsefrom the Servlet");
BufferedReader bufRead = new BufferedReader(new InputStreamReader(in));
StringBuffer xmlRespStringBuf = new StringBuffer(1024);
int c = in.read();
// while there is data to read
while (c != -1) {
// append the last char read
xmlRespStringBuf.append((char) c);
// read another char
c = in.read();
}
in.close();
System.out.println("Response = " + xmlRespStringBuf);
} catch (IOException e) {
System.out.println("input stream error");
e.printStackTrace();
}
System.out.println("Done");
}
}