尝试在JBoss EAP 6.4上使用a4j:mediaOutput的错误

时间:2018-08-31 20:00:37

标签: jsf richfaces jboss6.x jboss-eap-6

我正在尝试在应用程序中渲染图片。我选择了a4j:mediaOutput进行渲染。我使用来自jboss doc link的示例,它显示了错误:

  

11:49:53,716严重[org.richfaces.log.Resource](http-localhost / 127.0.0.1:9080-25)反序列化数据的输入错误:java.io.InvalidClassException:未经授权的反序列化尝试; simple.MediaData       在org.richfaces.util.LookAheadObjectInputStream.resolveClass(LookAheadObjectInputStream.java:100)[richfaces-core-4.5.17.Final.jar:4.5.17.Final]       在java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1695)[rt.jar:1.8.0]       在java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1600)[rt.jar:1.8.0]       在java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1875)[rt.jar:1.8.0]       在java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1432)[rt.jar:1.8.0]       在java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2094)[rt.jar:1.8.0]       在java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2019)[rt.jar:1.8.0]       在java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1902)[rt.jar:1.8.0]       在java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1432)[rt.jar:1.8.0]       在java.io.ObjectInputStream.readArray(ObjectInputStream.java:1789)[rt.jar:1.8.0]       在java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1426)[rt.jar:1.8.0]       在java.io.ObjectInputStream.readObject(ObjectInputStream.java:428)[rt.jar:1.8.0]       在org.richfaces.resource.ResourceUtils.decodeObjectData(ResourceUtils.java:247)[richfaces-core-4.5.17.Final.jar:4.5.17.Final]       org.richfaces.resource.DefaultCodecResourceRequestData.getData(DefaultCodecResourceRequestData.java:96)[richfaces-core-4.5.17.Final.jar:4.5.17.Final]       在org.richfaces.resource.ResourceFactoryImpl.createResource(ResourceFactoryImpl.java:325)[richfaces-core-4.5.17.Final.jar:4.5.17.Final]       org.richfaces.resource.ResourceHandlerImpl.handleResourceRequest(ResourceHandlerImpl.java:111)[richfaces-core-4.5.17.Final.jar:4.5.17.Final]       在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]       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295)[jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)[jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]       在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231)[jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]       在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)[jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]       在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]       在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:150)[jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]       在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)[jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]       在org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:400)[jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]       在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)上[jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]       在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)[jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]       在org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:355)[jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]       在org.apache.coyote.http11.Http11NioProtocol $ Http11ConnectionHandler.process(Http11NioProtocol.java:911)[jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]       在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]       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1153)[rt.jar:1.8.0]       在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:628)[rt.jar:1.8.0]       在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]       在java.lang.Thread.run(Thread.java:785)[vm.jar:1.8.0]

     

11:49:53,724错误   [org.apache.catalina.core.ContainerBase。[jboss.web]。[default-host]。[/ outputmediaTest]。[面孔   Servlet]](http-localhost / 127.0.0.1:9080-25)JBWEB000236:   Servlet Faces Servlet的Servlet.service()抛出异常:   java.lang.NullPointerException在   org.richfaces.resource.MediaOutputResource.encode(MediaOutputResource.java:65)   [richfaces-a4j-4.5.17.Final.jar:4.5.17.Final]在   org.richfaces.resource.UserResourceWrapperImpl.encode(UserResourceWrapperImpl.java:187)   [richfaces-core-4.5.17.Final.jar:4.5.17.Final]在   org.richfaces.resource.ResourceHandlerImpl.handleResourceRequest(ResourceHandlerImpl.java:184)   [richfaces-core-4.5.17.Final.jar:4.5.17.Final]在   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]     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295)   [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)   [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231)   [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)   [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]在   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]在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:150)   [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)   [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]在   org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:400)   [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)   [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)   [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]在   org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:355)   [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]在   org.apache.coyote.http11.Http11NioProtocol $ Http11ConnectionHandler.process(Http11NioProtocol.java:911)   [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]在   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]在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1153)   [rt.jar:1.8.0]位于   java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:628)   [rt.jar:1.8.0]位于   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]在   java.lang.Thread.run(Thread.java:785)[vm.jar:1.8.0]

当我更改MediaData来实现org.richfaces.resource.SerializableResource而不是Serializable时,它开始说awt.Color无法序列化。

请注意,我的xhtml文件是:

<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>

我的POM.xml是:

<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>

我使用的是JBoss EAP 6.4,还尝试了带有jsf impl的Tomcat 8.0:

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

错误是相同的。

2 个答案:

答案 0 :(得分:2)

第一个例外很重要。

@value必须是基本数据类型或实现white-listed classes

之一

答案 1 :(得分:0)

正如Makhiel所说,我发现使mediaData实现SerializableResource可以解决第一个错误。通过一些解决方法,它可以工作并显示图像。

下面是一个简单的示例,它可以帮助其他尝试查看组件工作的人,因为官方展示架似乎不起作用。只需使用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();
    }
}

和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>

/images/image.jpg放在webapp文件夹中,它应该显示该图像。

尽管如此,我仍想在工作环境中收到第二条错误消息。

经过研究,我发现在Tomcat上创建的用于测试的迷你项目中,我使用了 JSF 2.2.10 ,在我的工作环境中,我使用的是JBoss EAP 6.4 JSF 2.0.3-b05 附带的。在这两个版本中,我都使用RichFaces 4.5.17.Final,显然该版本与JSF 2.0.3-b05不兼容。

尝试使用该版本时,我收到错误消息:

  

org.apache.catalina.core.StandardContext监听器启动GRAVE:   将上下文初始化事件发送到的侦听器实例的异常   类[com.sun.faces.config.ConfigureListener]   com.sun.faces.config.ConfigurationException:配置失败!的   JSF实施2.0.3-不支持RichFaces   ExtendedPartialViewContext。请至少升级到Mojarra 2.1.28   或2.2.6

当我们开始从JBoss 6.1迁移到6.4并更改RichFaces版本时,问题就开始了。因此,我认为这是问题的原因,可能的解决方案是升级JSF版本。