It looks like you are not properly supplying arguments for "POST" method
The right order based on Jason Hunter book example is below:
To use it in your case just put your xml string into Properties object
as a value against "cmd" as a name
public static final InputStream sendPostMessage(Properties args, URL
destination)
throws IOException
{
String argString = "";
if (args != null)
{
argString = toEncodedString(args);
}
URLConnection con = destination.openConnection();
// Prepare for both input and output
con.setDoInput(true);
con.setDoOutput(true);
// Turn off caching
con.setUseCaches(false);
// Work around a Netscape bug
con.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
// Write the arguments as post data
DataOutputStream out = new DataOutputStream(con.getOutputStream());
out.writeBytes(argString);
out.flush();
out.close();
return (con.getInputStream());
}
/////////////////sendPostMessage
private static final String toEncodedString(Properties args)
{
StringBuffer buf = new StringBuffer();
Enumeration names = args.propertyNames();
while (names.hasMoreElements())
{
String name = (String) names.nextElement();
String value = args.getProperty(name);
buf.append(URLEncoder.encode(name) + "=" + URLEncoder.encode(value));
if (names.hasMoreElements())
buf.append("&");
}
return buf.toString();
}
////////////////////toEncodedString
Hope it helps
~boris
Milton S wrote:
>
> Orion Interest Group,
>
> I have written a Java class to test server to server communication for a
> servlet running on Orion 1.5.2. Nothing seems to happen when I run the
> class while the same URL sent from the address/location edit box on a
> browser works perfectly. The host URL I am using is
> "http://ducati:8080/petroweb/report" where ducati is the name of my
> notebook, petroweb is the application name, and report is the servlet I
> am trying to access. Following is the code I am using to make the
> "POST". What should I look for to make this work?
>
> I have "System.out.println's" in my servlet code to notify the open
> command prompt, in which Orion is running, of any requests received. I
> also have, in my servlet, all "GET" requests resolving to the "doPost"
> method.
>
> My environment is Intel P850, MS Windows 2000 Professional. Sun jdks,
> Orion 1.5.2 (stable binaries).
>
> Thank you for your help.
>
> import java.io.*;
> import java.net.*;
> import java.util.*;
>
> public class PostTest {
>
> public static void main( String args[] ){
> String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
> "<pwCmdXML>" +
> "<Command>SubmitJob</Command>" +
> "<CommandPassword>aPwd</CommandPassword>" +
> "<ProjectName>TheProject</ProjectName>" +
> "<ProjectType>pType</ProjectType>" +
> "<ObjectClass>stuff</ObjectClass>" +
> "<ObjectList>1,2,3,4,5,6,7,8,9,10,11,12,13,14,15," +
> "16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31," +
> "32,33,34,35,36</ObjectList>" +
> "</pwCmdXML>";
>
> try{
> URL url = new URL( "http://ducati:8080/petroweb/report?" );
> HttpURLConnection conn = (HttpURLConnection)url.openConnection();
>
> conn.setDoOutput( true );
> conn.setRequestMethod( "POST" );
> PrintWriter out = new PrintWriter(conn.getOutputStream() );
>
> out.println( "cmd=" + URLEncoder.encode( xml ) );
> conn.connect();
> out.flush();
> out.close();
> }
> catch( MalformedURLException err ){
> System.out.println( "MalformedURLException = " + err.getMessage()
> );
> }
> catch( IOException err ){
> System.out.println( "IOException = " + err.getMessage() );
> }
> }
> }