File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes HttpUrlConnection - cXML PunchOutSetupRequest Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "HttpUrlConnection - cXML PunchOutSetupRequest" Watch "HttpUrlConnection - cXML PunchOutSetupRequest" New topic

HttpUrlConnection - cXML PunchOutSetupRequest

Ron Khera

Joined: Jun 27, 2005
Posts: 4
Hi folks

I am creating an application to send cXML documents using a HttpURLConnection. My problem is that a response document I receive contains a string url that I need to luanch in a browser. When I copy the url into my browser its get http 401 error. How can I luanch a browser from my java app. Is there any connection info in the response needed to luanch the browser ? Below is my code with the response.

*** Headers ***
Content-Type: text/xml
Set-Cookie: ssnid=; path=/;
Connection: Keep-Alive
Content-Length: 765

*** Connection Detail ***
Follow Redirects: true
Request Method: POST
getContentType: text/xml
getContentLength: 765
getContentEncoding: null
getDate: 0
getExpiration: 0
getLastModifed: 0
Response Code: 200
Response Message: OK

*** Content ***
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE cXML SYSTEM ""> <cXML version="1.1" payloadID="20050810.133143_627804_uscobrmfa-sw-04" timestamp="2005-08-10T13:31:43-06:00"> <Response> <Status code="200" text="OK"/> <PunchOutSetupResponse> <StartPage> <URL></URL> </StartPage> </PunchOutSetupResponse> </Response></cXML>

The URL tag should be launchable (new word)

This is my HTTP POST method.

public StringBuffer post() {
// StringBuffer will contain result of post or any exception thown
StringBuffer result = new StringBuffer();

try {
// URL must use the http protocol!
URL url = new URL(urlName);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

// HTTP Method and options

// Set Headers
conn.setRequestProperty("Content-Type", "text/xml; charset=\"utf-8\"");
conn.setRequestProperty("Content-length", Integer.toString(postData.length()));

// Get the output stream to POST our data
OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(),"UTF8");

// Display Headers
if(dspHeaders) {

// Store the response in the result StringBuffer
InputStream rawInStream = conn.getInputStream();
BufferedReader rdr = new BufferedReader(new InputStreamReader(rawInStream, "UTF8"));
String line;
while ((line = rdr.readLine()) != null) {
} catch (Exception e) {
result.append("** Post Error: " + e + " **\n");
return result;
public StringBuffer getHeaders(HttpURLConnection cn) {
StringBuffer sb = new StringBuffer();
try {
int n = 1;
String key;
sb.append("*** Headers ***\n");
while ((key = cn.getHeaderFieldKey(n)) != null) {
String value = cn.getHeaderField(n);
sb.append(key + ": " + value + "\n");
sb.append("\n*** Connection Detail ***\n");
sb.append("Follow Redirects: "+cn.getFollowRedirects()+"\n");
sb.append("Request Method: "+cn.getRequestMethod()+"\n");
sb.append("getContentType: " + cn.getContentType()+"\n");
sb.append("getContentLength: " + cn.getContentLength()+"\n");
sb.append("getContentEncoding: " + cn.getContentEncoding()+"\n");
sb.append("getDate: " + cn.getDate()+"\n");
sb.append("getExpiration: " + cn.getExpiration()+"\n");
sb.append("getLastModifed: " + cn.getLastModified()+"\n");
sb.append("Response Code: "+cn.getResponseCode()+"\n");
sb.append("Response Message: "+cn.getResponseMessage()+"\n");
sb.append("\n*** Content ***\n");
catch (Exception e) {
sb.append("** getHeader Errors : "+e);
return sb;
I agree. Here's the link:
subject: HttpUrlConnection - cXML PunchOutSetupRequest
It's not a secret anymore!