0
votes

I'm trying to render a picture in my application. I have choosen a4j:mediaOutput to render that. I use the example from the jboss doc link and it shows the error:

11:49:53,716 SEVERE [org.richfaces.log.Resource] (http-localhost/127.0.0.1:9080-25) Input error for deserialize data : java.io.InvalidClassException: Unauthorized deserialization attempt; simple.MediaData at org.richfaces.util.LookAheadObjectInputStream.resolveClass(LookAheadObjectInputStream.java:100) [richfaces-core-4.5.17.Final.jar:4.5.17.Final] at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1695) [rt.jar:1.8.0] at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1600) [rt.jar:1.8.0] at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1875) [rt.jar:1.8.0] at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1432) [rt.jar:1.8.0] at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2094) [rt.jar:1.8.0] at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2019) [rt.jar:1.8.0] at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1902) [rt.jar:1.8.0] at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1432) [rt.jar:1.8.0] at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1789) [rt.jar:1.8.0] at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1426) [rt.jar:1.8.0] at java.io.ObjectInputStream.readObject(ObjectInputStream.java:428) [rt.jar:1.8.0] at org.richfaces.resource.ResourceUtils.decodeObjectData(ResourceUtils.java:247) [richfaces-core-4.5.17.Final.jar:4.5.17.Final] at org.richfaces.resource.DefaultCodecResourceRequestData.getData(DefaultCodecResourceRequestData.java:96) [richfaces-core-4.5.17.Final.jar:4.5.17.Final] at org.richfaces.resource.ResourceFactoryImpl.createResource(ResourceFactoryImpl.java:325) [richfaces-core-4.5.17.Final.jar:4.5.17.Final] at org.richfaces.resource.ResourceHandlerImpl.handleResourceRequest(ResourceHandlerImpl.java:111) [richfaces-core-4.5.17.Final.jar:4.5.17.Final] at javax.faces.webapp.FacesServlet.service(FacesServlet.java:591) [jboss-jsf-api_2.1_spec-2.1.28.Final-redhat-1.jar:2.1.28.Final-redhat-1] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:150) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:400) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:355) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:911) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.tomcat.util.net.NioEndpoint$ChannelProcessor.run(NioEndpoint.java:936) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1153) [rt.jar:1.8.0] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [rt.jar:1.8.0] at org.apache.tomcat.util.net.NioEndpoint$DefaultThreadFactory$1$1.run(NioEndpoint.java:1249) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at java.lang.Thread.run(Thread.java:785) [vm.jar:1.8.0]

11:49:53,724 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/outputmediaTest].[Faces Servlet]] (http-localhost/127.0.0.1:9080-25) JBWEB000236: Servlet.service() for servlet Faces Servlet threw exception: java.lang.NullPointerException at org.richfaces.resource.MediaOutputResource.encode(MediaOutputResource.java:65) [richfaces-a4j-4.5.17.Final.jar:4.5.17.Final] at org.richfaces.resource.UserResourceWrapperImpl.encode(UserResourceWrapperImpl.java:187) [richfaces-core-4.5.17.Final.jar:4.5.17.Final] at org.richfaces.resource.ResourceHandlerImpl.handleResourceRequest(ResourceHandlerImpl.java:184) [richfaces-core-4.5.17.Final.jar:4.5.17.Final] at javax.faces.webapp.FacesServlet.service(FacesServlet.java:591) [jboss-jsf-api_2.1_spec-2.1.28.Final-redhat-1.jar:2.1.28.Final-redhat-1] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:150) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:400) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:355) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:911) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at org.apache.tomcat.util.net.NioEndpoint$ChannelProcessor.run(NioEndpoint.java:936) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1153) [rt.jar:1.8.0] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [rt.jar:1.8.0] at org.apache.tomcat.util.net.NioEndpoint$DefaultThreadFactory$1$1.run(NioEndpoint.java:1249) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1] at java.lang.Thread.run(Thread.java:785) [vm.jar:1.8.0]

When I change MediaData to implements org.richfaces.resource.SerializableResource rather than Serializable, it starts to say awt.Color can't be serialized.

To be clear, my xhtml file is:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:a4j="http://richfaces.org/a4j">
<h:form id="form">
<h1>TEST</h1>
<a4j:mediaOutput element="img" cacheable="false" id="img" createContent="#{mediaBean.paint}"
        value="#{mediaData}" mimeType="image/jpeg" />
</h:form>

and my POM.xml is:

<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.leandrolima</groupId>
<artifactId>outputmediaTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>outputmediaTest</name>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <!-- https://mvnrepository.com/artifact/org.jboss.spec/jboss-javaee-6.0 -->
    <dependency>
        <groupId>org.jboss.spec</groupId>
        <artifactId>jboss-javaee-6.0</artifactId>
        <version>3.0.3.Final</version>
        <type>pom</type>
        <scope>provided</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.richfaces/richfaces-core -->
    <dependency>
        <groupId>org.richfaces</groupId>
        <artifactId>richfaces-core</artifactId>
        <version>4.5.17.Final</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.richfaces/richfaces -->
    <dependency>
        <groupId>org.richfaces</groupId>
        <artifactId>richfaces</artifactId>
        <version>4.5.17.Final</version>
    </dependency>



</dependencies>

I am using JBoss EAP 6.4 and also tried with Tomcat 8.0 with jsf impl:

        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.10</version>
        </dependency>

the error is the same.

2
According to the stack trace the "createContent" is null, which is weird. Have you tried running the showcase? - Makhiel
Are you meaning this one showcase.richfaces.org/richfaces/… ? They use a mediaReader and doesn't show the code. - Leandro Lima
I tryed showcase using the code in this page programcreek.com/java-api-examples/… and the error is the same. I'll edit the post to say it. - Leandro Lima
I don't mean copying the code, I mean deploying the showcase locally, if it doesn't work then it's probably something with your server. What server are you running anyway? - Makhiel
I'm using JBoss EAP 6.4 and have tried with Tomcat with jsf implementation from oracle also. - Leandro Lima

2 Answers

2
votes

Well the first exception is rather important.

The @value has to be either a basic data type or implement one of the white-listed classes

0
votes

I have found that making the mediaData implement SerializableResource solves the first error, as Makhiel have said. With some workaround it worked and shown the image.

To help others trying to see the component working, since the official showcase seems not be functional, follows a simple example. Just with the MediaBean:

package simple;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.imageio.ImageIO;

@ManagedBean(name = "imageBean")
@RequestScoped
public class MediaBean {
    private static final String RICHFACES_MEDIA_OUTPUT_IMAGE_SOURCE = "/images/image.jpg";

    public void paint(final OutputStream out, final Object data) throws IOException {
        if (data == null) {
            return;
        }

        final byte[] imageData = getImage(Integer.parseInt((String) data));

        final InputStream in = new ByteArrayInputStream(imageData);
        try {
            final BufferedImage bImageFromConvert = ImageIO.read(in);
            ImageIO.write(bImageFromConvert, "png", out);
        }
        finally {
            in.close();
        }
    }

    private byte[] getImage(final int data) throws IOException {
        final ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
        final String resource = extContext.getResource(RICHFACES_MEDIA_OUTPUT_IMAGE_SOURCE).getFile();
        final BufferedImage bImage = ImageIO.read(new File(resource));
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ImageIO.write(bImage, "jpg", bos);
        return bos.toByteArray();
    }
}

and the xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:h="http://java.sun.com/jsf/html">

<h:head>
</h:head>
<body>
    <h1>TEST</h1>
    <rich:panel>
        <a4j:mediaOutput element="img" cacheable="false" session="false"
            createContent="#{imageBean.paint}" value="0" mimeType="image/jpeg" />
    </rich:panel>
</body>
</html>

Puting the /images/image.jpg in webapp folder it should show that image.

Despite that, I countinue receiving the second error message in my work environment.

Researching about, I've found that in the mini project I've create on Tomcat to test, I've used JSF 2.2.10 and in my work environment I am using JBoss EAP 6.4 that came with JSF 2.0.3-b05. In both I am using RichFaces 4.5.17.Final and apparently, that version is incompatible to JSF 2.0.3-b05.

Trying to use that version I receive the error message:

org.apache.catalina.core.StandardContext listenerStart GRAVE: Exception sending context initialized event to listener instance of class [com.sun.faces.config.ConfigureListener] com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! The JSF implementation 2.0.3- does not support the RichFaces ExtendedPartialViewContext. Please upgrade to at least Mojarra 2.1.28 or 2.2.6

The problem started when we started to migrate from JBoss 6.1 to 6.4 and change the RichFaces version. So I believe that is the cause of the problem and the possible solution is to upgrade JSF version.