I'm having difficulties getting images to display on a JSP web application running in Tomcat. I've tried everything from adding MIME mapping to changing the context.xml file to reference the directory outside of the webapp. I've have also changed the directory ownership permissions and I am still not getting the intended results. The file path values are stored in a database.
THIS path works: /opt/tomcat/Harvester/Results/REQUESTID/REQUESTID_Image.FITS
This path does not: /home/tomcat/harvester/results/REQUESTID/REQUESTID_Image.FITS
I've confirmed that the files exist and I don't know what else needs to be configured to display the images referenced in the second location.
The environment:
- Cent OS 7
- Apache Tomcat 7
- java version "1.8.0_191" Java(TM) SE Runtime Environment (build 1.8.0_191-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
- primefaces 5.3
Requests.xhtml data table with issues:
<p:dataTable id="RequestResults" var="RequestResult" value="#{Requests.allrequestresults}" selection="#{Requests.selectedrequestresults}" rowKey="#{RequestResult.id}" sortMode="multiple"
rows="10" paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15,20,50,100"
resizableColumns="true" liveResize="true"
draggableColumns="true"
style="margin-bottom:20px; table-layout:auto;"
>
<f:facet name="header">
Results
</f:facet>
<p:column selectionMode="multiple" style="width:16px;text-align:center"/>
<p:column headerText="Result ID" sortBy="#{RequestResult.id}" style="width: 200px">
<h:outputText value="#{RequestResult.id}" />
</p:column>
<p:column headerText="Request ID" sortBy="#{RequestResult.requestid}" style="width: 200px">
<h:outputText value="#{RequestResult.requestid}" />
</p:column>
<p:column headerText="File Name" sortBy="#{RequestResult.filename}" style="width: 200px">
<h:outputText value="#{RequestResult.filename}" />
</p:column>
<p:column headerText="Image" style="width: 100%">
<h:graphicImage id="image" name="results/#{RequestResult.imagename}" width="300" height="300"/>
<p:resizable for="image" animate="true" ghost="true"/>
</p:column>
</p:dataTable>
Requests.java
public void LoadRequestResults(){
MySqlDB mysqldb = new MySqlDB(); //Open and close of the connection and it's contents must be handled
ResultSet resultsRS = null;
allrequestresults = new ArrayList();
String RequestReviewList = "";
for(Request r : selectedrequests)
{
if(RequestReviewList.matches("")) RequestReviewList = "'" + r.getId() + "'";
else RequestReviewList += ",'" + r.getId() + "'";
}
try{
String query = String.format("Select id, requestid, filename from RESULTS where requestid in (%s) order by requestid",
RequestReviewList);
resultsRS = mysqldb.ExecuteDataTable(query);
while (resultsRS.next()) {
allrequestresults.add(new RequestResult(resultsRS.getInt("id"),
resultsRS.getInt("requestid"),
resultsRS.getString("filename"),
RequestResult.convertFITSToPNGString(new File(resultsRS.getString("filename")), config.TempDir)
));
}
}catch(IOException | SQLException e){
downloadmsg = "Failed to load.: " + e.toString();
}
finally{
try{
mysqldb.close((Connection)((Statement)resultsRS.getStatement()).getConnection(),(Statement)resultsRS.getStatement(),resultsRS);
}
catch(Exception e) {
}
}
try{Thread.sleep(2000);}catch(Exception e){} //Wait for the files to be recognized by the web site
}
RequestResult.java
public static String convertFITSToPNGString(File file, String tempfiledir){
String ReturnFileName = null;
try {
String TempFileName = file.getName().substring(0, file.getName().lastIndexOf(".")) + ".jpeg";
String TempFile = tempfiledir + TempFileName;
File f = new File(TempFile);
if(!f.exists())
{
Opener op = new Opener();
ImagePlus Imp = op.openImage(file.getPath());
FileSaver fileSaver = new FileSaver(Imp);
fileSaver.saveAsJpeg(TempFile);
}
ReturnFileName = TempFileName;
}catch(Exception e)
{
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, e.toString(), null));
//errorMSG = e.toString();
}
return ReturnFileName;
}
Tomcat log using "journalctl -xe -u tomcat"
Dec 31 22:30:51 server[4153]: Unsupported format or not found
Dec 31 22:30:51 server[4153]: Unsupported format or not found
Dec 31 22:30:51 server[4153]: Dec 31, 2019 10:30:51 PM com.sun.faces.context.ExternalContextImpl getMimeType
Dec 31 22:30:51 server[4153]: WARNING: JSF1091: No mime type could be found for file results/. To resolve this, add a mime-type mapping to the applications web.xml.
Dec 31 22:30:51 server[4153]: Dec 31, 2019 10:30:51 PM com.sun.faces.application.resource.WebappResourceHelper findResource
Dec 31 22:30:51 server[4153]: WARNING: jsf.application.resource.unable_to_determine_resource_version.
Dec 31 22:30:51 server[4153]: Dec 31, 2019 10:30:51 PM com.sun.faces.context.ExternalContextImpl getMimeType
Dec 31 22:30:51 server[4153]: WARNING: JSF1091: No mime type could be found for file results/. To resolve this, add a mime-type mapping to the applications web.xml.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.context.ExternalContextImpl getMimeType
Dec 31 22:30:53 server[4153]: WARNING: JSF1091: No mime type could be found for file results/. To resolve this, add a mime-type mapping to the applications web.xml.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.application.resource.WebappResourceHelper findResource
Dec 31 22:30:53 server[4153]: WARNING: jsf.application.resource.unable_to_determine_resource_version.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.context.ExternalContextImpl getMimeType
Dec 31 22:30:53 server[4153]: WARNING: JSF1091: No mime type could be found for file results/. To resolve this, add a mime-type mapping to the applications web.xml.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.context.ExternalContextImpl getMimeType
Dec 31 22:30:53 server[4153]: WARNING: JSF1091: No mime type could be found for file results/. To resolve this, add a mime-type mapping to the applications web.xml.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.application.resource.WebappResourceHelper findResource
Dec 31 22:30:53 server[4153]: WARNING: jsf.application.resource.unable_to_determine_resource_version.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.context.ExternalContextImpl getMimeType
Dec 31 22:30:53 server[4153]: WARNING: JSF1091: No mime type could be found for file results/. To resolve this, add a mime-type mapping to the applications web.xml.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.context.ExternalContextImpl getMimeType
Dec 31 22:30:53 server[4153]: WARNING: JSF1091: No mime type could be found for file results/. To resolve this, add a mime-type mapping to the applications web.xml.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.application.resource.WebappResourceHelper findResource
Dec 31 22:30:53 server[4153]: WARNING: jsf.application.resource.unable_to_determine_resource_version.
Dec 31 22:30:53 server[4153]: Dec 31, 2019 10:30:53 PM com.sun.faces.context.ExternalContextImpl getMimeType
Dec 31 22:30:53 server[4153]: WARNING: JSF1091: No mime type could be found for file results/. To resolve this, add a mime-type mapping to the applications web.xml.
Using the "inspect" tool on Google Chrome reveals that the image URL is incomplete:
<img id="form:RequestResults:0:image" src="/Website/javax.faces.resource/results/.xhtml" alt="" height="300" width="300">