This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File COuld not be posted on IIS 5.0 via Servlet

 
Rakesh Jain
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi There

We have a working code that was running all well with Win NT server. The server was recently migrated to Win2K/ IIS5.0 and then we have all problem of doing an Http Put on the virtual directory on IIS5.0. No Idea why is this happenning. Surprisingly we could aboe to post the file in the virtual dirctory but then I think the server is not sending the reposnse back tot he Java programme and a user defined exception 'Failed to post attachment is printed in the Log file".
For your reference please find the code used to put the file in the Win2K IIS5.0 combination
try {

out.println("Going to read from : " + ATT_DIR + ATTFilename + "<br>");
FileInputStream fin = new FileInputStream (ATT_DIR + ATTFilename);
retval = putFile(ATT_POST_URL + ATTFilename, fin);
//fin.close();

}
catch (Exception e) {

// The post failed. Let's exit.
String err_message = "Failed to post attachment to virtual directory.";
eCO_API_Servlet_Utils.write_trans_log_servlet( local_program_details, err_message );
eCO_API_Servlet_Utils.write_error_log_servlet( local_program_details, err_message );
String xml_response = eCO_API_Servlet_Utils.create_xml_file_upload_ack ( XMLOriginalFilename,
ECO_CONSTANTS.ATT_FILE_UPLOAD_RESPONSE_CODE_POST,
ECO_CONSTANTS.ATT_FILE_UPLOAD_RESPONSE_TEXT_POST );
out.println( xml_response );
out.close();
try { db_connection_work.close(); } catch ( Exception zzz){} // Close d/b connection
db_connection_work = null;
return;
}
}

********************
********************
public static boolean putFile (String reqURL, FileInputStream fin) throws Exception {

HttpURLConnection conn = null;
URL url= null;
String line = new String();
StringBuffer buf = new StringBuffer();
String retval = new String("Not Defined");
BufferedOutputStream bo = null;
boolean success = false;
String err_message = "This is For testing";
try {
url= new URL (reqURL);
conn = (HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("PUT");

byte[] block = new byte[1];
int readval =0;
bo = new BufferedOutputStream (conn.getOutputStream());

while (readval > -1) {

readval = fin.read(block,0,1);
bo.write(block,0,1);

}
fin.close();
eCO_API_Servlet_Utils.write_trans_log_servlet( local_program_details, err_message );
bo.close();
eCO_API_Servlet_Utils.write_trans_log_servlet( local_program_details, err_message );


InputStreamReader in = new InputStreamReader(conn.getInputStream());
BufferedReader data = new BufferedReader(in);

while ((line = data.readLine()) != null) {
buf.append(line + "\n");
}
retval = buf.toString();
in.close();
eCO_API_Servlet_Utils.write_trans_log_servlet( local_program_details, err_message );
return true;

} catch (Exception e) {

Exception ex = new IOException (e.getMessage());
throw ex;
}
}
/** End of PUT */
}

An early repsonse on this will be much apprciated

Cheers
Rakesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic