permaculture playing cards*
The moose likes Sockets and Internet Protocols and the fly likes File COuld not be posted on IIS 5.0 via Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "File COuld not be posted on IIS 5.0 via Servlet" Watch "File COuld not be posted on IIS 5.0 via Servlet" New topic
Author

File COuld not be posted on IIS 5.0 via Servlet

Rakesh Jain
Greenhorn

Joined: Aug 18, 2004
Posts: 2
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File COuld not be posted on IIS 5.0 via Servlet
 
Similar Threads
C --> Java
FTPProtocolException:STOR and FTPProtocolException:LIST??
Cannot solve this problem
relative path name for propertiesObject.load()
Display Image in JSP using servlet