Tuesday, August 21, 2012

How-to fix: ResourceServlet._setHeaders(): Content type for /oracle/webcenter/portalapp/shared/png/image.png is NULL!

While browsing the error log of webcenter portal application I noticed recurrent error:

[2012-08-02T17:21:00.486+02:00] [WC_Portlet1] [WARNING] [] [org.apache.myfaces.trinidad.webapp.ResourceServlet] [tid: [ACTIVE].ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: myUser] [ecid: 0000JZbvEp6Cwk85njP5iZ1G6c2e0000NQ,0] [APP: Portal_application1#V2.0] ResourceServlet._setHeaders(): Content type for /oracle/webcenter/portalapp/shared/png/settings.png is NULL![[
Cause: Unknown file extension
]]

The error isn't fatal, but clutters the log. To fix this error I did small investigation. In the first step I went to org.apache.myfaces.trinidad.webapp.ResourceServlet class source (I found it on grepcode.com). Then I found the source of our error in _setHeaders function:

if (contentType == null || "content/unknown".equals(contentType))
    {
      url = connection.getURL();
      resourcePath = url.getPath();

      // 'Case' statement for unknown content types
      if (resourcePath.endsWith(".css"))
        contentType = "text/css";
      else if (resourcePath.endsWith(".js"))
        contentType = "application/x-javascript";
      else if (resourcePath.endsWith(".cur") || resourcePath.endsWith(".ico"))
        contentType = "image/vnd.microsoft.icon";
      else
        contentType = getServletContext().getMimeType(resourcePath);

      // The resource has an file extension we have not
      // included in the case statement above
      if (contentType == null)
      {
        _LOG.warning("ResourceServlet._setHeaders(): " +
                     "Content type for {0} is NULL!\n" +
                     "Cause: Unknown file extension",
                     resourcePath);
      }
    }
  
It can be seen clearly the problem lays in line 14:

contentType = getServletContext().getMimeType(resourcePath);

where function  getMimeType definitely returns null.

To check what happens in this function I went to documentation of javax.servlet.ServletContext class. In javadoc we can read:

"Returns (getMimeType) the MIME type of the specified file, or null if the MIME type is not known. The MIME type is determined by the configuration of the servlet container, and may be specified in a web application deployment descriptor. Common MIME types are "text/html" and "image/gif"."

The key to solve our problem lays in words: "The MIME type is determined by the configuration of the servlet container, and may be specified in a web application deployment descriptor"

The mime types for web application can be configured in a web.xml deployment descriptor. A mapping between an extension and a mime type defines fhe mime-mapping element. As described in documentation the following elements you can define within a mime-mapping element:

<extension>  A string describing an extension, for example: txt.
<mime-type> A string describing the defined mime type, for example: text/plain.

In accordance with these instructions to configure mime-types for png files I added to my web.xml descriptor:

<mime-mapping>

    <extension>png</extension>

    <mime-type>image/png</mime-type>

</mime-mapping>
 
After redeployment all should work fine. And really works:)

Thursday, August 9, 2012

How to: force loading "managed server wide" jar library in Weblogic

To force loading custom java jar library on application server start, usually you have to put jar file to appropriate folder of the application server. For example:

Apache Tomcat 5.5: [SERVER_DIR]/common/classes/
Apache Tomcat 6.x: [SERVER_DIR]/lib/
jBoss 4.x, 5.x: [SERVER_DIR]/server/[SERVER_TYPE]/conf/
Glassfish 2.x, 3.x: [SERVER_DIR]/domain/[DOMAIN]/lib/classes/

In the case of Weblogic 11g/12c server you can force loading of jar library on all managed servers in the domain by putting file to folder

[DOMAIN_DIR]/lib

You can also configure each managed server separately to load library by putting path to jar in managed server classpath. To do this run weblogic server administration console and next go to Environment | Servers | (Configuration Tab) | Selected_Server. Go to managed server configuration and find Server Start tab. The below image shows where you can put path to jar file:

Saturday, August 4, 2012

JDeveloper 11.1.1.6 error: Failed to validate the xml content. SchemaLocation: schemaLocation value = 'http://xmlns.oracle.com/oracleas/schema/11/jps-config-11_1.xsd' must have even number of URI's. Location: unavailable.

We can enjoy next bonus received in the package along with the JDeveloper.
This time it is XML validation error:

Failed to validate the xml content. 
SchemaLocation: schemaLocation value = 
'http://xmlns.oracle.com/oracleas/schema/11/jps-config-11_1.xsd' 
must have even number of URI's. Location: unavailable.
 

On OTN (https://forums.oracle.com/forums/thread.jspa?threadID=2376404) I found "solution":
"You have wait for the next version". Rrrrrrrrrrr.