Need help with HTTP Post to TN using Java

I have a partner that is wanting to POST their xml to our Trading Networks. Searching the forums and documentation I cannot find an example of code to do this, so I have attempted to write my own - but it will not work. Can anyone tell me what I am doing wrong?


import java.util.

public class testPost2TN

public static void main(String args) throws Exception
// Open HTTP connection
//URL url = new URL(“http://localhost:8080/testServlet.jsp”);
URL url = new URL(“http://user:pswd@TNURL:5555/invoke/”);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;

// Set the appropriate HTTP parameters.
httpConn.setRequestProperty(“Content-Type”,“text/xml; charset=utf-8”);

// Set the Action header
httpConn.setRequestMethod( “POST” );

// Post the message.
OutputStream out = httpConn.getOutputStream() ;
String xmldata = “TESTUSERPASSWORD”;
byte requestXML = xmldata.getBytes();
out.close() ;

catch (Exception e)
System.out.println(“Exception Message\n-----------------”);

When I run this code to a jsp servlet (commented out) I have on my local machine the xml gets displayed just like it should. When I cut and paste the actual URL and data to the Address line in IE it posts to TN so I dont have the wrong user/password, etc.


Since that works in IE I tried opening the URL with the above and that doesnt work either.

I compiled and ran the code pasted above and get the following error:
Exception Message TNURL

When I run it with the actual URL, user and password I get no error message and TN has no information.

Please help.

I was finally able to get some java code that works after someone suggested using the Compose - Generate Code option on a simple service. I then changed the code to use the service with $xmldata for the data parameter and changed the command line read in getString() to read from a file. This solution would require the partner to have the client.jar file on their system.

Isn’t there a way to HTTP Post to TN from java without having to use the client.jar?



Of course you can use the Java apis to POST without client.jar. But using client.jar is so much easier, why wouldn’t you do that instead?

Because our Partner doesnt have any Web Methods software and many companies are unwilling to install code from third parties where they dont have contractual agreements to protect them.

The built-in Java URL/HttpURLConnection classes do not directly support the name and password in the URL. You can POST to the Integration Server without using the client.jar; but the work required depends on the JVM version you are using.

If you have access to the 1.3 and higher VMs, take a look at the class This allows you to register an instance of a class to participate in the user authentication when you receive an HTTP 401/Access Denied