aspose file tools*
The moose likes Struts and the fly likes Getting some  Exceptions !!!! Plse Help me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Getting some  Exceptions !!!! Plse Help me" Watch "Getting some  Exceptions !!!! Plse Help me" New topic
Author

Getting some Exceptions !!!! Plse Help me

Eldhose Jacob
Greenhorn

Joined: Apr 04, 2006
Posts: 6
I added these codes in my server.xml file.
<Logger className="org.apache.catalina.logger.FileLogger"
directory="logs" prefix="localhost_log." suffix=".txt"
timestamp="true"/>
So tomcat will creat a local host log file daily basis. And i am getting some exceptions in that file. Unable to find the root cause. Apllication is working properly. If i am clicking on some links in my application it will go to the server and download some jarsto client PC and after that it will work as a standalone.
This error is comming only at the time of this downloading time. I am attaching that exception message and my servlet file along with this query. Plse give me some hint about this type of exceptions.

exceptions
------------------
2006-04-05 06:09:56 StandardWrapperValve[default]: Servlet.service() for servlet default threw exception
java.io.IOException: There is no process to read data written to a pipe.
at java.net.SocketOutputStream.socketWrite(Native Method)
at java.net.SocketOutputStream.write(SocketOutputStream.java(Compiled Code))
at org.apache.catalina.connector.ResponseBase.flushBuffer(ResponseBase.java(Compiled Code))
at org.apache.catalina.connector.ResponseBase.write(ResponseBase.java(Compiled Code))
at org.apache.catalina.connector.ResponseBase.write(ResponseBase.java(Compiled Code))
at org.apache.catalina.connector.http.HttpResponseStream.write(HttpResponseStream.java(Compiled Code))
at org.apache.catalina.connector.http.HttpResponseStream.write(HttpResponseStream.java(Compiled Code))
at org.apache.catalina.servlets.DefaultServlet.copyRange(DefaultServlet.java(Compiled Code))
at org.apache.catalina.servlets.DefaultServlet.copy(DefaultServlet.java(Compiled Code))
at org.apache.catalina.servlets.DefaultServlet.serveResource(DefaultServlet.java(Compiled Code))
at org.apache.catalina.servlets.DefaultServlet.doGet(DefaultServlet.java(Compiled Code))
at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java(Compiled Code))
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java(Compiled Code))
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java(Compiled Code))
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java(Compiled Code))
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java(Compiled Code))
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java(Compiled Code))
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java(Compiled Code))
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java(Compiled Code))
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java(Compiled Code))
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java(Compiled Code))
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java(Compiled Code))
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java(Compiled Code))
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java(Compiled Code))
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java(Compiled Code))
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java(Compiled Code))
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java(Compiled Code))
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java(Compiled Code))
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java(Compiled Code))
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java(Compiled Code))
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java(Compiled Code))
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java(Compiled Code))
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java(Compiled Code))
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java(Compiled Code))
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java(Compiled Code))
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java(Compiled Code))
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java(Compiled Code))
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java(Compiled Code))
at java.lang.Thread.run(Thread.java:498)

2006-04-05 06:09:56 ErrorDispatcherValve[localhost]: Exception Processing ErrorPage[exceptionType=java.lang.Exception, location=/error]
java.lang.IllegalStateException
at java.lang.IllegalStateException.<init>(IllegalStateException.java:36)
at org.apache.catalina.connector.ResponseFacade.reset(ResponseFacade.java:243)
at org.apache.catalina.valves.ErrorDispatcherValve.custom(ErrorDispatcherValve.java:384)
at org.apache.catalina.valves.ErrorDispatcherValve.throwable(ErrorDispatcherValve.java:250)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java(Compiled Code))
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java(Compiled Code))
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java(Compiled Code))
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java(Compiled Code))
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java(Compiled Code))
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java(Compiled Code))
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java(Compiled Code))
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java(Compiled Code))
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java(Compiled Code))
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java(Compiled Code))
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java(Compiled Code))
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java(Compiled Code))
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java(Compiled Code))
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java(Compiled Code))
at java.lang.Thread.run(Thread.java:498)

-----------------
Servlet file
------------
public class DynamicJNLPServlet extends HttpServlet
{
private static char replaceChar='/';
private static String strjnlpCodeBasePath="JNLP_CODEBASE_PATH";
private static String strjnlpCjarsPath="JNLP_CJARS_PATH";
private static String strjnlpSjarsPath="JNLP_SJARS_PATH";
private static String strjnlpFileName="JNLP_FILE_NAME";
private static String strCommonJnlpFileName="JNLP_COMMON_FILE_NAME";
private static String strDynamicJarFileName="JNLP_DYNAMIC_JAR_FILE";
private static String strJnlpTemplatePath="JNLP_TEMPLATE_PATH";
private static String ApplCtxPath=null;

public void init(ServletConfig config) throws ServletException
{
super.init( config );
}

protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
String strCertCode="";
String strTemp = req.getContextPath();
String strServerName = req.getServerName();
int iport = req.getServerPort();
ApplCtxPath=req.getContextPath();
HttpSession session = null;
String tmpJnlp = null;
String tmpCjars = null;
BufferedReader bReader = null;
BufferedWriter bWriter = null;
File tempJnlpFolder = null;
File tempCjarsFolder = null;
File templateJnlpFile = null;
File actualJnlpFile = null;
session=req.getSession();
String readLine = null; // used to store each line read from file
StringBuffer buffer = new StringBuffer(); // used to store the each line read from file and replace the
// key words defined in jnlp template with the actual value
String cjarFileTobeDeleted = null; // this jar file will be coppied to temp cjar folder and after 2 min
// this jar will get deleted
String loggerdUser = null;
boolean jnlp_extension=false;
String localTempJnlpPath = null; // used to store the path of temp jnlp folder to be create at run time
String localTempCjarsPath = null; // used to store the path of temp cjars folder to be create at run time
String localCjarPath=null; //used to store the path from where one common jar file need to be copied
// to the cjar folder under temp folder
String originalCodeBase=null;

String jnlpCodeBasePath = null; // values will be read from any datasource
String jnlpCjarsPath = null; // values will be read from any datasource
String jnlpSjarsPath = null; // values will be read from any datasource
String jnlpTemplatePath = null; // values will be read from any datasource
String jnlpFileName = null; // value will be obtain from request object
String localJnlpTemplatePath = null; // this will be created at run time after assing the value of JNLP_TEMPLATE_PATH
String commonJnlpFileName=null; // values will be red from any datasource
// and used to read the template file
SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// check file separator for the OS in which application is running
if (File.separator.equals("\\"))
replaceChar = '/';
else if (File.separator.equals("/"))
replaceChar = '\\';
// read these following values from datasource and request
// JNLP_CODEBASE_PATH,JNLP_CJARS_PATH,
// JNLP_SJARS_PATH,JNLP_TEMPLATE_PATH
// get the JNLP_FILE_NAME from incomming request

//Added By Venkat for Application usage logging
if (req.getParameter("certcode") != null) {
strCertCode = (String) req.getParameter("certcode");
}

Connection con = (Connection)session.getAttribute("dcsconnection");
//Added By Venkat for Application usage logging
User user = (User)session.getAttribute("user");
try
{
ApplicationHelper.writeUsageInfo(con, user, strCertCode);
}
catch(SQLException e)
{
this.getServletContext().log("*******Error in ApplicationHelper.writeUsageInfo(************" + e.toString());

}

if (req.getParameter("filename") != null)
{
jnlpFileName= (String) req.getParameter("filename");
}
else
throw new ServletException("CLASS :- DynamicJNLPServlet METHOD :-service ERROR MSG :- "+
" could not find JNLP FILE NAME in the request object ");

if (req.getParameter("jarfilename") != null)
cjarFileTobeDeleted =(String) req.getParameter("jarfilename");
else
throw new ServletException("CLASS :- DynamicJNLPServlet METHOD :-service ERROR MSG :- "+
" could not find CJAR FILE NAME in the request object ");



if( session.getAttribute("jnlpCodeBasePath") == null ||
session.getAttribute("jnlpCjarsPath")== null ||
session.getAttribute("jnlpSjarsPath")== null ||
session.getAttribute("jnlpTemplatePath")== null ||
session.getAttribute("commonJnlpFileName")== null)
// || session.getAttribute("cjarFileTobeDeleted")==null
{

try
{

Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT SYS_PARAM,SYS_VALUE FROM sys_keys WHERE sys_param like 'JNLP%'");

while(rs.next())
{
if(rs.getString(1)!=null && rs.getString(1).equals(strjnlpCodeBasePath))
{
jnlpCodeBasePath = rs.getString(2);
originalCodeBase= rs.getString(2);
jnlpCodeBasePath = "http://"+strServerName+":"+iport+strTemp +jnlpCodeBasePath;
originalCodeBase = "http://"+strServerName+":"+iport+strTemp+originalCodeBase;
}
if(rs.getString(1)!=null && rs.getString(1).equals(strjnlpCjarsPath))
jnlpCjarsPath = rs.getString(2);
if(rs.getString(1)!=null && rs.getString(1).equals(strjnlpSjarsPath))
jnlpSjarsPath = rs.getString(2);
if(rs.getString(1)!=null && rs.getString(1).equals(strJnlpTemplatePath))
{
jnlpTemplatePath = rs.getString(2);
localJnlpTemplatePath=rs.getString(2);
}
if(rs.getString(1)!=null && rs.getString(1).equals(strCommonJnlpFileName))
commonJnlpFileName=rs.getString(2);
}
}
catch(Exception sq)
{
//sq.printStackTrace();
System.out.println(myFormat.format(new java.util.Date()) +" Error in CLASS :- DynamicJNLPServlet METHOD :-service ERROR MSG :-"+sq.getMessage());
}



if( jnlpCodeBasePath ==null)
throw new ServletException(myFormat.format(new java.util.Date()) +" CLASS :- DynamicJNLPServlet METHOD :-service ERROR MSG :- "+
"could not find entry for JNLP_CODEBASE_PATH sys_param in sys_keys database table");
if( jnlpCjarsPath ==null)
throw new ServletException(myFormat.format(new java.util.Date()) +" CLASS :- DynamicJNLPServlet METHOD :-service ERROR MSG :- " +
" could not find entry for JNLP_CJARS_PATH sys_param in sys_keys database table");

if( jnlpSjarsPath ==null)
throw new ServletException(myFormat.format(new java.util.Date()) +" CLASS :- DynamicJNLPServlet METHOD :-service ERROR MSG :- "+
" could not find entry for JNLP_SJARS_PATH sys_param in sys_keys database table");

if( jnlpTemplatePath ==null)
throw new ServletException(myFormat.format(new java.util.Date()) +" CLASS :- DynamicJNLPServlet METHOD :-service ERROR MSG :- "+
" could not find entry for JNLP_TEMPLATE_PATH sys_param in sys_keys database table");

if( commonJnlpFileName ==null)
throw new ServletException(myFormat.format(new java.util.Date()) +" CLASS :- DynamicJNLPServlet METHOD :-service ERROR MSG :- "+
" could not find entry for JNLP_COMMON_FILE_NAME sys_param in sys_keys database table");

session.setAttribute("jnlpCodeBasePath",jnlpCodeBasePath);
session.setAttribute("jnlpCjarsPath",jnlpCjarsPath);
session.setAttribute("jnlpSjarsPath",jnlpSjarsPath);
session.setAttribute("jnlpTemplatePath",jnlpTemplatePath);
session.setAttribute("commonJnlpFileName",commonJnlpFileName);
// session.setAttribute("cjarFileTobeDeleted",cjarFileTobeDeleted);
}
else
{
jnlpCodeBasePath = (String)session.getAttribute("jnlpCodeBasePath");
originalCodeBase= (String)session.getAttribute("jnlpCodeBasePath");
jnlpCjarsPath = (String)session.getAttribute("jnlpCjarsPath");
jnlpSjarsPath = (String)session.getAttribute("jnlpSjarsPath");
jnlpTemplatePath = (String)session.getAttribute("jnlpTemplatePath");
localJnlpTemplatePath=(String)session.getAttribute("jnlpTemplatePath");
commonJnlpFileName=(String)session.getAttribute("commonJnlpFileName");
// cjarFileTobeDeleted =(String)session.getAttribute("cjarFileTobeDeleted");
}
loggerdUser = req.getParameter("user");

tmpJnlp = "temp" + File.separator + loggerdUser + "_" + req.getRemoteAddr() +File.separator + "jnlp";
tmpCjars = "temp" + File.separator + loggerdUser + "_" + req.getRemoteAddr() +File.separator + "cjars";

// creating the folder structure in local m/c where the appl runs for the folder Jnlp Template
// first check if the file path separator in the variable jnlpTemplatePath is compatible to OS
if (localJnlpTemplatePath.indexOf(replaceChar) != -1)
{
localJnlpTemplatePath = localJnlpTemplatePath.replace(replaceChar,File.separatorChar);
}

// so now all the template file be located under this path held by variable localJnlpTemplatePath
localJnlpTemplatePath = this.getServletContext().getRealPath(localJnlpTemplatePath);
// first check if the last index of slash is one less than the total length of template path it means
// the value stored in localJnlpTemplatePath has slash at the end and we need to remove it
if (localJnlpTemplatePath.lastIndexOf(File.separator) ==localJnlpTemplatePath.length() - 1)
{
localJnlpTemplatePath = localJnlpTemplatePath.substring(0,
localJnlpTemplatePath.length() - 1);
}

// we will assign the value of localJnlpTemplatePath to localTmpPath and replace the template folder with
// the value tmpJnlp and then tmpCjars
localTempJnlpPath = localJnlpTemplatePath;
//========================== creating temp folders =======================================================
// Now we will create a temp folder at the same level as the jnlp template folder reside. This is created by
// taking the path of jnlp template folder and replacing the template folder name with the values stored in
// variable tmpJnlp and then tmpCjars
// NOTE : under this temp folder there will be multiple folder created the format will be like this
// username_ipaddress_of_user\jnlp and username_ipaddress_of_user\cjars where username and ip address
// are read at run time from the request object

int lastIndexOf = localJnlpTemplatePath.lastIndexOf(File.separator) + 1;
localTempJnlpPath = localTempJnlpPath.substring(0, lastIndexOf);

// now append the complete temp folder path for jnlp the variable
localTempJnlpPath = localTempJnlpPath + tmpJnlp;

// now create the temp folder
tempJnlpFolder = new File(localTempJnlpPath);
tempJnlpFolder.mkdirs();
//=====================================================================================


//============== read jnlp template file and write to new JNLP file ==================
// start reading the jnlp template file and write the contents to new JNLP file by replacing
// the key words like JNLP_CODEBASE_PATH, JNLP_CJARS_PATH , JNLP_SJARS_PATH , JNLP_TEMPLATE_PATH
// JNLP_FILE_NAME with their respective values stored in the variables

//!!! only when the jnlp file being created is not a common.jnlp file !!!
// Also replace the codebase's last folder with tmpJnlp so that Java web start will look for jnlp file
// under the tmpJnlp for this first we check if the last index of slash is one less than the total length
// of template path it means the value stored in jnlpCodeBasePath has slash at the end and we need to
// remove it
if(jnlpFileName.indexOf("comm")==-1)
{
if (jnlpCodeBasePath.lastIndexOf("\\") == jnlpCodeBasePath.length() - 1)
jnlpCodeBasePath = jnlpCodeBasePath.substring(0,jnlpCodeBasePath.length() - 1);
else if (jnlpCodeBasePath.lastIndexOf("/") == jnlpCodeBasePath.length() - 1)
jnlpCodeBasePath = jnlpCodeBasePath.substring(0,jnlpCodeBasePath.length() - 1);
else
jnlpCodeBasePath = jnlpCodeBasePath;
// now remove the last folder from the codebase path
if (jnlpCodeBasePath.lastIndexOf("\\") != -1)
{
jnlpCodeBasePath = jnlpCodeBasePath.substring(0,jnlpCodeBasePath.lastIndexOf("\\"));
jnlpCodeBasePath = jnlpCodeBasePath.concat("\\");
tmpJnlp = tmpJnlp.replace('/', '\\');
}
else if (jnlpCodeBasePath.lastIndexOf("/") != -1)
{
jnlpCodeBasePath = jnlpCodeBasePath.substring(0,jnlpCodeBasePath.lastIndexOf("/"));
jnlpCodeBasePath = jnlpCodeBasePath.concat("/");
tmpJnlp = tmpJnlp.replace('\\', '/');
}
// now append the tmpJnlp path into this modified codebasepath
jnlpCodeBasePath = jnlpCodeBasePath.concat(tmpJnlp);
}

//!!!

/*
Before creating any application specific jnlp we first check if the temp_ common jnlp file is existing
in the template folder or not if not create a new one the contents of this temp_ common jnlp file will
be same as the common jnlp name specified in the database but the tags like JNLP_CODEBASE_PATH
JNLP_CJARS_PATH JNLP_SJARS_PATH etc will get replace with the value retreived from the data source
inside this temp_ common jnlp file

or if the temp_ common jnlp file exists but there has been some changes made in the data source
table sys_keys then this temp_ common jnlp file should be be recreated
the checking for the values JNLP_CODEBASE_PATH JNLP_CJARS_PATH
JNLP_TEMPLATE_PATH JNLP_COMMON_FILE_NAME JNLP_SJARS_PATH in sys_keys table is done by
comparing these values in the system properties with the latest values obtained from DB

*/

if(System.getProperty("OLD_JNLP_SJARS_PATH")==null)
System.setProperty("OLD_JNLP_SJARS_PATH",jnlpSjarsPath);
if(System.getProperty("OLD_JNLP_CODEBASE_PATH")==null)
System.setProperty("OLD_JNLP_CODEBASE_PATH",originalCodeBase);
if(System.getProperty("OLD_JNLP_CJARS_PATH")==null)
System.setProperty("OLD_JNLP_CJARS_PATH",jnlpCjarsPath);
if(System.getProperty("OLD_JNLP_COMMON_FILE_NAME")==null)
System.setProperty("OLD_JNLP_COMMON_FILE_NAME",commonJnlpFileName);

// creating File Object for template jnlp file and the new jnlp file to be created

actualJnlpFile = new File(localJnlpTemplatePath + File.separator +"temp_"+commonJnlpFileName);
int start = 0;
int end = 0;
if(!actualJnlpFile.exists() || !System.getProperty("OLD_JNLP_SJARS_PATH").equals(jnlpSjarsPath)
|| !System.getProperty("OLD_JNLP_CODEBASE_PATH").equals(originalCodeBase)
|| !System.getProperty("OLD_JNLP_CJARS_PATH").equals(jnlpCjarsPath)
|| !System.getProperty("OLD_JNLP_COMMON_FILE_NAME").equals(commonJnlpFileName)
)
{
// actualJnlpFile.createNewFile();
templateJnlpFile = new File(localJnlpTemplatePath + File.separator +commonJnlpFileName);
bReader = new BufferedReader(new FileReader(templateJnlpFile));
bWriter = new BufferedWriter(new FileWriter(actualJnlpFile));
readLine = bReader.readLine();
start = 0;
end = 0;
while (readLine != null)
{
buffer.delete(0, buffer.toString().length()); // clean the buffer
buffer.append(readLine);

if (buffer.toString().indexOf(strjnlpSjarsPath) != -1)
{
start = 0;
end = 0;
start = buffer.toString().indexOf(strjnlpSjarsPath);
end = strjnlpSjarsPath.length() + start;
buffer.replace(start, end,ApplCtxPath+jnlpSjarsPath);
}

if (buffer.toString().indexOf(strjnlpCodeBasePath) != -1)
{
start = 0;
end = 0;
start = buffer.toString().indexOf(strjnlpCodeBasePath);
end = strjnlpCodeBasePath.length() + start;
buffer.replace(start, end,originalCodeBase);
}

if (buffer.toString().indexOf(strjnlpCjarsPath) != -1)
{
start = 0;
end = 0;
start = buffer.toString().indexOf(strjnlpCjarsPath);
end = strjnlpCjarsPath.length() + start;
buffer.replace(start, end,ApplCtxPath+jnlpCjarsPath);
}

if (buffer.toString().indexOf(strCommonJnlpFileName) != -1)
{
start = 0;
end = 0;
start = buffer.toString().indexOf(strCommonJnlpFileName);
end = strCommonJnlpFileName.length() + start; ;
buffer.replace(start, end, "temp_"+commonJnlpFileName);
}
bWriter.write("\n"+buffer.toString());
readLine = bReader.readLine();
}
bWriter.flush();
bWriter.close();
bReader.close();
}

System.setProperty("OLD_JNLP_SJARS_PATH",jnlpSjarsPath);
System.setProperty("OLD_JNLP_CODEBASE_PATH",originalCodeBase);
System.setProperty("OLD_JNLP_CJARS_PATH",jnlpCjarsPath);
System.setProperty("OLD_JNLP_COMMON_FILE_NAME",commonJnlpFileName);
// change the name of the common jnlp obt from data source to temp_ common jnlp
// so that modified appl jnlp file will refer to this new temp_ common jnlp file
//
commonJnlpFileName="temp_"+commonJnlpFileName;

templateJnlpFile = new File(localJnlpTemplatePath + File.separator +jnlpFileName);
actualJnlpFile = new File(localTempJnlpPath + File.separator +jnlpFileName);
if (actualJnlpFile != null)
actualJnlpFile.createNewFile();
bReader = new BufferedReader(new FileReader(templateJnlpFile));
bWriter = new BufferedWriter(new FileWriter(actualJnlpFile));
readLine = bReader.readLine();
start = 0;
end = 0;
while (readLine != null)
{
buffer.delete(0, buffer.toString().length()); // clean the buffer
buffer.append(readLine);
jnlp_extension=false;
/*
if the line read contain the common jnlp file name tag JNLP_COMMON_FILE_NAME
then replace it with the file name set the flag to true
*/
if (buffer.toString().indexOf(strCommonJnlpFileName) != -1)
{
start = 0;
end = 0;
start = buffer.toString().indexOf(strCommonJnlpFileName);
end = strCommonJnlpFileName.length() + start;
buffer.replace(start, end, commonJnlpFileName);
jnlp_extension=true;
}
/*
if jnlp_extension is true it means we are not working with common.jnlp file and tag JNLP_CODEBASE_PATH
is contain in this line is the code base for extension jnlp for common.jnlp file so this value should
be same as that is read from datasource
*/
if (buffer.toString().indexOf(strjnlpCodeBasePath) != -1)
{
start = 0;
end = 0;
start = buffer.toString().indexOf(strjnlpCodeBasePath);
end = strjnlpCodeBasePath.length() + start;
if(jnlp_extension)
buffer.replace(start, end, originalCodeBase);
else
buffer.replace(start, end, jnlpCodeBasePath);
}
/*
checking if this line has JNLP_CJARS_PATH tag then we check if there is cjar file that is to be
deleted for security reason if yes then append the cjarTemp Path to the JNLP_CJARS_PATH obt
from datasource
else directly replace the tag JNLP_CJARS_PATH with datasource value
*/
if (buffer.toString().indexOf(strjnlpCjarsPath) != -1)
{
start = 0;
end = 0;
start = buffer.toString().indexOf(strjnlpCjarsPath);
end = strjnlpCjarsPath.length() + start;
if (buffer.toString().indexOf(strDynamicJarFileName) != -1)
{
String localtmpJnlp = null;
if (jnlpCjarsPath.lastIndexOf("\\") == jnlpCjarsPath.length() - 1)
localTempCjarsPath = jnlpCjarsPath.substring(0,jnlpCjarsPath.length() - 1);
else if (jnlpCjarsPath.lastIndexOf("/") == jnlpCjarsPath.length() - 1)
localTempCjarsPath = jnlpCjarsPath.substring(0,jnlpCjarsPath.length() - 1);
else
localTempCjarsPath = jnlpCjarsPath;

if (jnlpCjarsPath.indexOf("\\") != -1)
{
if (tmpCjars.indexOf("\\") == -1)
localtmpJnlp = tmpCjars.replace('/', '\\');
else
localtmpJnlp= tmpCjars;

lastIndexOf = localTempCjarsPath.lastIndexOf("\\") + 1;
localTempCjarsPath = localTempCjarsPath.substring(0, lastIndexOf);
}

if (jnlpCjarsPath.indexOf("/") != -1)
{
if (tmpCjars.indexOf("/") == -1)
localtmpJnlp = tmpCjars.replace('\\', '/');
else
localtmpJnlp = tmpCjars;
lastIndexOf = localTempCjarsPath.lastIndexOf("/") + 1;
localTempCjarsPath = localTempCjarsPath.substring(0, lastIndexOf);
}
// now append the complete temp folder path for cjars to these variable
localTempCjarsPath = localTempCjarsPath + localtmpJnlp;
buffer.replace(start, end, ApplCtxPath+localTempCjarsPath);
}
else
buffer.replace(start, end,ApplCtxPath+jnlpCjarsPath);

if (buffer.toString().indexOf(strDynamicJarFileName) != -1)
{
start = 0;
end = 0;
start = buffer.toString().indexOf(strDynamicJarFileName);
end = strDynamicJarFileName.length() + start;
buffer.replace(start, end, cjarFileTobeDeleted);
}
}

/*
checking if this line has JNLP_SJARS_PATH tag then we check if there is cjar file that is to be
deleted for security reason if yes then append the cjarTemp Path to the JNLP_SJARS_PATH obt
from datasource
else directly replace the tag JNLP_SJARS_PATH with datasource value
*/
if (buffer.toString().indexOf(strjnlpSjarsPath) != -1)
{
start = 0;
end = 0;
start = buffer.toString().indexOf(strjnlpSjarsPath);
end = strjnlpSjarsPath.length() + start;
if (buffer.toString().indexOf(strDynamicJarFileName) != -1)
{
String localtmpJnlp = null;
if (jnlpCjarsPath.lastIndexOf("\\") == jnlpCjarsPath.length() - 1)
localTempCjarsPath = jnlpCjarsPath.substring(0,jnlpCjarsPath.length() - 1);
else if (jnlpCjarsPath.lastIndexOf("/") == jnlpCjarsPath.length() - 1)
localTempCjarsPath = jnlpCjarsPath.substring(0,jnlpCjarsPath.length() - 1);
else
localTempCjarsPath = jnlpCjarsPath;
if (jnlpCjarsPath.indexOf("\\") != -1)
{
if (tmpCjars.indexOf("\\") == -1)
localtmpJnlp = tmpCjars.replace('/', '\\');
else
localtmpJnlp = tmpCjars;
lastIndexOf = localTempCjarsPath.lastIndexOf("\\") + 1;
localTempCjarsPath = localTempCjarsPath.substring(0, lastIndexOf);
}

if (jnlpCjarsPath.indexOf("/") != -1)
{
if (tmpCjars.indexOf("/") == -1)
localtmpJnlp = tmpCjars.replace('\\', '/');
else
localtmpJnlp = tmpCjars;
lastIndexOf = localTempCjarsPath.lastIndexOf("/") + 1;
localTempCjarsPath = localTempCjarsPath.substring(0, lastIndexOf);
}

// now append the complete temp folder path for cjars to these variable
localTempCjarsPath = localTempCjarsPath + localtmpJnlp;
buffer.replace(start, end, ApplCtxPath+localTempCjarsPath);
}
else
{
buffer.replace(start, end, ApplCtxPath+jnlpSjarsPath);
}
if (buffer.toString().indexOf(strDynamicJarFileName) != -1)
{
start = 0;
end = 0;
start = buffer.toString().indexOf(strDynamicJarFileName);
end = strDynamicJarFileName.length() + start;
buffer.replace(start, end, cjarFileTobeDeleted);
}
}
/*
Checking for the tag JNLP_FILE_NAME in this line then replacing with the value obtain from database
*/
if (buffer.toString().indexOf(strjnlpFileName) != -1)
{
start = 0;
end = 0;
start = buffer.toString().indexOf(strjnlpFileName);
end = strjnlpFileName.length() + start; ;
buffer.replace(start, end, jnlpFileName);
}

/*
Checking for the tag $ in this line then replacing it with the user name
*/

if (buffer.toString().indexOf("$") != -1)
{
start = 0;
end = 0;
start = buffer.toString().indexOf("$");
buffer.replace(start, start + 1, loggerdUser);
}

bWriter.write("\n"+buffer.toString());
readLine = bReader.readLine();
}
bWriter.flush();
bWriter.close();
bReader.close();

//======================= completed the jnlp file creation ==============================

//==================== Copying one of the CJar file into temp folder ====================
// this is done for security reason
/*
first checking if the localTempCjarsPath has the file separator according to OS
if not replace them
*/
if (localTempCjarsPath.indexOf(File.separator) == -1 && localTempCjarsPath.indexOf("\\") > -1)
localTempCjarsPath = localTempCjarsPath.replace('\\',replaceChar );
if (localTempCjarsPath.indexOf(File.separator) == -1 && localTempCjarsPath.indexOf("/") > -1)
localTempCjarsPath = localTempCjarsPath.replace('/', replaceChar);

// getting the local path for temp cjar in the server using servletContext
localTempCjarsPath = this.getServletContext().getRealPath(localTempCjarsPath);
// creating File Object for creating temp and cjar folder from which jar file will be deleted
tempCjarsFolder = new File(localTempCjarsPath+File.separator);
if (tempCjarsFolder != null)
tempCjarsFolder.mkdirs();
// getting the local cjar path in the server using servletContext
localCjarPath=this.getServletContext().getRealPath(jnlpSjarsPath);
// copy the cjar file to be deleted from cjar folder to temp cjar folder
try
{
packjnlp.FSDeleteFile.copyFile(localCjarPath+ File.separator+cjarFileTobeDeleted,
localTempCjarsPath+ File.separator+cjarFileTobeDeleted);
}
catch(Exception exp)
{
System.out.println(myFormat.format(new java.util.Date()) +" CLASS :- DynamicJNLPServlet METHOD :-service ERROR MSG :- WHILE " +
"trying to copy the jar file that need to be deleted from folder " +localCjarPath+
File.separator+cjarFileTobeDeleted + " to folder is " + localTempCjarsPath+
File.separator+cjarFileTobeDeleted );
//exp.printStackTrace();

}

// setting the System property for delete path this will help FSDeleteFile to delete the files
// under this folder
String strDelete_Path = localTempCjarsPath.substring(0,localTempCjarsPath.indexOf("temp")+4);
if (System.getProperty("DELETE_PATH") == null)
System.setProperty("DELETE_PATH", strDelete_Path);
//=======================================================================================

start=jnlpCodeBasePath.indexOf(req.getContextPath())+req.getContextPath().length()+1;
end=jnlpCodeBasePath.length();
String requestDespPath=jnlpCodeBasePath.substring(start,end);
if(requestDespPath.indexOf("\\")!=-1)
requestDespPath=requestDespPath.concat("\\");
else if(requestDespPath.indexOf("/")!=-1)
requestDespPath=requestDespPath.concat("/");
requestDespPath=requestDespPath.concat(jnlpFileName);
RequestDispatcher rd = req.getRequestDispatcher(requestDespPath);
res.setContentType("application/x-java-jnlp");
rd.forward(req, res);
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting some Exceptions !!!! Plse Help me
 
Similar Threads
need to encode a string
How to update a image using servlet?
NullPointerException Just Does Not Make Sense
Understanding logic on for loop
Is it possible to get a string representation of a PreparedStatement?