-1

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">
CSCMEICOMP
  • 51
  • 7
  • So it works if you run all this on windows? – Kukeltje Jan 01 '20 at 00:03
  • And [mcve] please. – Kukeltje Jan 01 '20 at 10:59
  • I have not tried to run this on a windows based system. In terms of an example what are you looking for? The webpage requires your IP to be whitelisted in order to view. – CSCMEICOMP Jan 02 '20 at 19:55
  • I'm looking for a [mcve], see also [ask] and https://www.stackoverflow.com/tags/jsf/info – Kukeltje Jan 02 '20 at 20:49
  • And if you do not know it is a linux only problem, ypu shouldd not tag it with linux. Same for tomcat7 and if you cannot reproduce with a plain jdk (so no jsf, no tomcat etc), the java(-se) tag is not correct either. In addition, the server tag is very generic. – Kukeltje Jan 02 '20 at 20:52
  • I see! Well creating a minimal reproducible example and re-configuring my application to test on a windows machine, I think would be just as much work as migrating the images to the directory that works and replacing the references in the database. So I will go for the latter (it'll essentially take two terminal commands and an sql query). Thanks for the help anyway. I was hoping a Linux guru could state why the "/home" directory was so special. – CSCMEICOMP Jan 03 '20 at 19:37
  • The reason the 'question' on 'how is the /home directory special, got, for me, lost in all the other non-relevant code then (datatable could have been replaced with a single `h:graphicImage`, the database things could have been replaced with a single static value, all these things should (yes, should (or actuall **must**)) be done when asking questions. It is stated in [ask]. It makes it easier for us to try to reproduce if needed or just make the focus of the question clear. – Kukeltje Jan 03 '20 at 20:56
  • And the home directory is not special at all, it has, like all directories on Linux (and Windows for that matter) access rights. If it was related to this, you'd get java errors (access denied exceptions or whatever) and not an empty string (`#{RequestResult.imagename}` is empty) which in turn has nothing to do with the home directory per say but more likely with code you have. Btw `src="/Website/javax.faces.resource/results/.xhtml"` points to a 'resources' folder in your deployed webapp https://stackoverflow.com/questions/11988415/what-is-the-jsf-resource-library-for-and-how-should-it-be-used – Kukeltje Jan 03 '20 at 21:03
  • You get the warnings because you effectively try to retrieve folders on the client ( the *.xhtml is stripped off) so there is no mimetype for a folder (logically so). Next time, remember about the [mcve] it is **the most relevant thing** to do before asking questions on stackoverflow. It helps you getting to the real issue, maybe even find existing duplicate and helps you create good titles good tags and makes it easier for us to help which in turn helps you. Cheers! – Kukeltje Jan 03 '20 at 21:04
  • thanks for the suggestion, I will remember to do that for future posts – CSCMEICOMP Jan 09 '20 at 04:13

1 Answers1

1

I figured out the issue while working on a different application hosted by tomcat. SELinux must have become enabled after I performed an update to the system.

SELinux is a Linux kernel module that provides a framework for configuring mandatory access control for many resources on the system.

I disabled SELINUX and then rebooted my virtual machine (powered down VM, restarted VMware, powered up VM).

Type nano /etc/sysconfig/selinux and edit file to read:

#This file controls the state of SELinux on the system. 
#SELINUX= can take one of these three values: 
#   enforcing - SELinux security policy is enforced
#   permissive - SELinux prints warnings instead of enforcing
#   disabled - No SELinux policy is loaded
SELINUX = disabled 
#SELINUXTYPE = can take one of these two values: 
#   targeted - Targeted processes are protected
#   mls - Multi Level Security protection
SELINUXTYPE=targeted

Instead of disabling SELINUX, another solution that I found involves setting the tomcat_t daemon's domain (security context) to permissive mode. In permissive mode the policy isn't enforced, but logs are generated on the access the policy would normally deny.

Type semanage permissive -a tomcat_t

CSCMEICOMP
  • 51
  • 7
  • Bad solution. Learn the details of selinux and configure it in detail to allow tomcat access. Not just disable it – Kukeltje Jan 09 '20 at 07:03
  • Once I am more familiar with SELinux, I will do that. Still new to Linux over all. At least I now know why I was unable to access certain services. – CSCMEICOMP Jan 09 '20 at 20:36