Details

      Description

      If you get to

      content/control/EditLayout?drDataResourceId=NOCONTENTFOUND&contentId=NOCONTENTFOUND
      

      When trying to editing you get an error

      2016-04-11 10:48:42,932 |http-bio-8443-exec-9 |ScreenFactory                 |I| Got 9 screens in 0.004s from: file:/C:/projectASF-Mars/ofbiz/applications/content/widget/layout/LayoutScreens.xml
      2016-04-11 10:48:43,051 |http-bio-8443-exec-9 |ScriptUtil                    |W| Error running script at location [component://content/webapp/content/WEB-INF/actions/layout/EditSubContent.groovy]: org.ofbiz.b
      ase.util.GeneralException: The desired mime-type is not a text type, cannot render as text: image/png
      org.ofbiz.base.util.GeneralException: The desired mime-type is not a text type, cannot render as text: image/png
              at org.ofbiz.content.data.DataResourceWorker.renderDataResourceAsText(DataResourceWorker.java:624) ~[ofbiz-content.jar:?]
              at org.ofbiz.content.data.DataResourceWorker.renderDataResourceAsText(DataResourceWorker.java:603) ~[ofbiz-content.jar:?]
              at org.ofbiz.content.data.DataResourceWorker$renderDataResourceAsText.call(Unknown Source) ~[?:?]
              at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) ~[groovy-all-2.4.5.jar:2.4.5]
              at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) ~[groovy-all-2.4.5.jar:2.4.5]
              at EditSubContent.run(EditSubContent.groovy:50) ~[?:?]
      
      1. Image 018.png
        58 kB
        Jacques Le Roux
      2. nocontentfound.png
        3 kB
        Jacques Le Roux
      3. OFBIZ-7000.patch
        5 kB
        Mohammed Rehan Khan
      4. OFBIZ-7000.patch
        0.8 kB
        Mohammed Rehan Khan

        Issue Links

          Activity

          Hide
          rehan.khan Mohammed Rehan Khan added a comment -

          Hi,
          I have explored the issue and found that there is a condition in DataResourceWorker method to render content of 'text' mime type only, for others it returns exception.

          // if the target mimeTypeId is not a text type, throw an exception
          if (!targetMimeTypeId.startsWith("text/"))

          { throw new GeneralException("The desired mime-type is not a text type, cannot render as text: " + targetMimeTypeId); }

          We can fix this by setting up mimeTypeID as null in request param

          I have added the patch with the changes and also test the same for all contents, kindly share your thoughts on this.

          Show
          rehan.khan Mohammed Rehan Khan added a comment - Hi, I have explored the issue and found that there is a condition in DataResourceWorker method to render content of 'text' mime type only, for others it returns exception. // if the target mimeTypeId is not a text type, throw an exception if (!targetMimeTypeId.startsWith("text/")) { throw new GeneralException("The desired mime-type is not a text type, cannot render as text: " + targetMimeTypeId); } We can fix this by setting up mimeTypeID as null in request param I have added the patch with the changes and also test the same for all contents, kindly share your thoughts on this.
          Hide
          rehan.khan Mohammed Rehan Khan added a comment -

          Hello,

          Here is some additional detail-
          Question: Why setting up mimeTypeTypeId as 'null' is fixing this issue?
          Answer: As we don't have image specific worker method for rendering these type of contents, so we are using DataResourceWorker.renderDataResourceAsText() to render image type content as well. Due to following condition, targetMimeTypeId is setting up as "text/html" if sent null and hence not throwing the exception reported in the ticket.
          if (UtilValidate.isEmpty(targetMimeTypeId))

          { targetMimeTypeId = "text/html"; }
          Show
          rehan.khan Mohammed Rehan Khan added a comment - Hello, Here is some additional detail- Question: Why setting up mimeTypeTypeId as 'null' is fixing this issue? Answer: As we don't have image specific worker method for rendering these type of contents, so we are using DataResourceWorker.renderDataResourceAsText() to render image type content as well. Due to following condition, targetMimeTypeId is setting up as "text/html" if sent null and hence not throwing the exception reported in the ticket. if (UtilValidate.isEmpty(targetMimeTypeId)) { targetMimeTypeId = "text/html"; }
          Hide
          pandeypranay Pranay Pandey added a comment -

          Hi Jacques,

          Details provided by Mohammed Rehan Khan is looking good to me, as we don't have any specific methods for serving content of different types, we use the one we have and it has to be handling it. Please share your thoughts on suggested fix and we'll go from there.

          Thanks.

          Show
          pandeypranay Pranay Pandey added a comment - Hi Jacques, Details provided by Mohammed Rehan Khan is looking good to me, as we don't have any specific methods for serving content of different types, we use the one we have and it has to be handling it. Please share your thoughts on suggested fix and we'll go from there. Thanks.
          Hide
          jacques.le.roux Jacques Le Roux added a comment -

          I tried the patch, I now get this error when I click on the [Edit] button

               [java] 2016-05-22 13:56:36,255 |http-nio-8443-exec-3 |runtime                       |E| Error executing FreeMarker template
               [java] freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
               [java] ==> contentId  [in template "component://content/template/mime-type/Image.ftl" at line 19, column 79]
               [java]
               [java] ----
               [java] Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>
          when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
               [java] ----
               [java]
               [java] ----
               [java] FTL stack trace ("~" means nesting-related):
               [java]     - Failed at: ${contentId}  [in template "component://content/template/mime-type/Image.ftl" at line 19, column 77]
               [java]     - Reached through: @ofbizUrl secure="${request.isSecure(...  [in template "component://content/template/mime-type/Image.ftl" at line 19, column 11]
               [java] ----
               [java]     at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134) ~[freemarker-2.3.24.jar:2.3.24]
          

          I thought a trick could be to use this patch

          Index: applications/content/template/mime-type/Image.ftl
          ===================================================================
          --- applications/content/template/mime-type/Image.ftl	(revision 1745030)
          +++ applications/content/template/mime-type/Image.ftl	(working copy)
          @@ -16,4 +16,8 @@
             specific language governing permissions and limitations
             under the License.
             -->
          -<img src="<@ofbizUrl secure="${request.isSecure()?string}">stream?contentId=${contentId}</@ofbizUrl>"/>
          \ No newline at end of file
          +<#if contentId??>
          +    <img src="<@ofbizUrl secure="${request.isSecure()?string}">/content/control/stream?contentId=${contentId}</@ofbizUrl>"/>
          +<#else>
          +    This image cannot be rendered! Try to change the image file path.
          +</#if>
          \ No newline at end of file
          

          But it would only prevent the error and will not solve the problem, because when you then try to use another file by changing the file patch from
          /applications/content/webapp/content/images/nocontentfound.png
          to eg
          /applications/content/webapp/content/images/Presse-papiers-1.png

          you then get this error

               [java] java.lang.Exception: Error in simple-method [Update Electronic Text [file:/C:/projectASF-Mars/ofbiz/applications/content/script/org/ofbiz/content/data/DataServices.xml#updateElectronicText]]: Erro
          r running the simple-method: Entity value not found with name: lookedUpValue Method = updateElectronicText, File = file:/C:/projectASF-Mars/ofbiz/applications/content/script/org/ofbiz/content/data/DataService
          s.xml, Element = <set-nonpk-fields>, Line 309null
               [java]     at org.ofbiz.entity.transaction.TransactionUtil.setRollbackOnly(TransactionUtil.java:360) [ofbiz-entity.jar:?]
          

          I also noticed that the Mime type is

          image&#x2f;png

          should it not be

          image&#x2e;png

          (http://do.remifa.so/archives/unicode/latin1.html) or even rather image.png. Anyway I gave up at this stage finally wondering if changing the "nocontentfound.png" file makes any sense OOTB (of course we then let the problem to custom project :/)

          Show
          jacques.le.roux Jacques Le Roux added a comment - I tried the patch, I now get this error when I click on the [Edit] button [java] 2016-05-22 13:56:36,255 |http-nio-8443-exec-3 |runtime |E| Error executing FreeMarker template [java] freemarker.core.InvalidReferenceException: The following has evaluated to null or missing: [java] ==> contentId [in template "component: //content/template/mime-type/Image.ftl" at line 19, column 79] [java] [java] ---- [java] Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <# if myOptionalVar??> when-present<# else >when-missing</# if >. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? [java] ---- [java] [java] ---- [java] FTL stack trace ( "~" means nesting-related): [java] - Failed at: ${contentId} [in template "component: //content/template/mime-type/Image.ftl" at line 19, column 77] [java] - Reached through: @ofbizUrl secure= "${request.isSecure(... [in template " component: //content/template/mime-type/Image.ftl" at line 19, column 11] [java] ---- [java] at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134) ~[freemarker-2.3.24.jar:2.3.24] I thought a trick could be to use this patch Index: applications/content/template/mime-type/Image.ftl =================================================================== --- applications/content/template/mime-type/Image.ftl (revision 1745030) +++ applications/content/template/mime-type/Image.ftl (working copy) @@ -16,4 +16,8 @@ specific language governing permissions and limitations under the License. --> -<img src= "<@ofbizUrl secure=" ${request.isSecure()?string} ">stream?contentId=${contentId}</@ofbizUrl>" /> \ No newline at end of file +<# if contentId??> + <img src= "<@ofbizUrl secure=" ${request.isSecure()?string} ">/content/control/stream?contentId=${contentId}</@ofbizUrl>" /> +<# else > + This image cannot be rendered! Try to change the image file path. +</# if > \ No newline at end of file But it would only prevent the error and will not solve the problem, because when you then try to use another file by changing the file patch from /applications/content/webapp/content/images/nocontentfound.png to eg /applications/content/webapp/content/images/Presse-papiers-1.png you then get this error [java] java.lang.Exception: Error in simple-method [Update Electronic Text [file:/C:/projectASF-Mars/ofbiz/applications/content/script/org/ofbiz/content/data/DataServices.xml#updateElectronicText]]: Erro r running the simple-method: Entity value not found with name: lookedUpValue Method = updateElectronicText, File = file:/C:/projectASF-Mars/ofbiz/applications/content/script/org/ofbiz/content/data/DataService s.xml, Element = <set-nonpk-fields>, Line 309null [java] at org.ofbiz.entity.transaction.TransactionUtil.setRollbackOnly(TransactionUtil.java:360) [ofbiz-entity.jar:?] I also noticed that the Mime type is image&#x2f;png should it not be image&#x2e;png ( http://do.remifa.so/archives/unicode/latin1.html ) or even rather image.png. Anyway I gave up at this stage finally wondering if changing the "nocontentfound.png" file makes any sense OOTB (of course we then let the problem to custom project :/)
          Hide
          rehan.khan Mohammed Rehan Khan added a comment -

          Thanks Jacques Le Roux. I am looking into this.

          Show
          rehan.khan Mohammed Rehan Khan added a comment - Thanks Jacques Le Roux . I am looking into this.
          Hide
          rehan.khan Mohammed Rehan Khan added a comment -

          Hello Jacques Le Roux,

          Here is the updated patch to fix the issue.

          I needed to make changes in the patch provided earlier which are as follows:

          • Updated groovy file reference as per new structure.
          • Added if_exist check to prevent null pointer exception.
          • Corrected condition to update dataResource in "persistDataResourceAndDataMethod".


          Thanks

          Show
          rehan.khan Mohammed Rehan Khan added a comment - Hello Jacques Le Roux , Here is the updated patch to fix the issue. I needed to make changes in the patch provided earlier which are as follows: Updated groovy file reference as per new structure. Added if_exist check to prevent null pointer exception. Corrected condition to update dataResource in "persistDataResourceAndDataMethod". – Thanks
          Hide
          jacques.le.roux Jacques Le Roux added a comment -

          Thanks Mohammed,

          Unfortunately when changing the file (rotation) I get this error when getting to
          https://localhost:8443/content/control/EditLayout?drDataResourceId=NOCONTENTFOUND&contentId=NOCONTENTFOUND

          Error rendering included template at location [component://content/template/layout/RenderSubContent.ftl]: java.io.IOException: Error rendering contentorg.apache.ofbiz.base.util.GeneralException: The desired mime-type is not a text type, cannot render as text: image/png

          Of course there is more in the log

          Show
          jacques.le.roux Jacques Le Roux added a comment - Thanks Mohammed, Unfortunately when changing the file (rotation) I get this error when getting to https://localhost:8443/content/control/EditLayout?drDataResourceId=NOCONTENTFOUND&contentId=NOCONTENTFOUND Error rendering included template at location [component://content/template/layout/RenderSubContent.ftl] : java.io.IOException: Error rendering contentorg.apache.ofbiz.base.util.GeneralException: The desired mime-type is not a text type, cannot render as text: image/png Of course there is more in the log
          Hide
          jacques.le.roux Jacques Le Roux added a comment -

          Ah wait, I have to retry, I was not up to date (not using trunk HEAD)

          Show
          jacques.le.roux Jacques Le Roux added a comment - Ah wait, I have to retry, I was not up to date (not using trunk HEAD)
          Hide
          jacques.le.roux Jacques Le Roux added a comment -

          I confirm, still an issue

          Show
          jacques.le.roux Jacques Le Roux added a comment - I confirm, still an issue
          Hide
          jacques.le.roux Jacques Le Roux added a comment - - edited

          OK it works after cleaning all. I'll try to backport

          Show
          jacques.le.roux Jacques Le Roux added a comment - - edited OK it works after cleaning all. I'll try to backport
          Hide
          jacques.le.roux Jacques Le Roux added a comment -

          Thanks Mohammed,

          Your patch is in
          trunk r1765094
          R15.12, 14.12, 13.07 r1765096

          Show
          jacques.le.roux Jacques Le Roux added a comment - Thanks Mohammed, Your patch is in trunk r1765094 R15.12, 14.12, 13.07 r1765096
          Hide
          rehan.khan Mohammed Rehan Khan added a comment -

          Thank you Jacques Le Roux !

          Show
          rehan.khan Mohammed Rehan Khan added a comment - Thank you Jacques Le Roux !

            People

            • Assignee:
              jacques.le.roux Jacques Le Roux
              Reporter:
              jacques.le.roux Jacques Le Roux
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development