如何将 JBoss 5 编码设置为像以前的 JBoss 4.1 一样?

发布于 2024-10-01 05:52:02 字数 3828 浏览 6 评论 0原文

它是一个使用seam 2.2构建的应用程序,并且在Jboss 4.1.2下完美运行。由于我的 ISP 的支持,我必须将 JBoss 升级到版本 5.1。我确实尝试在 JBoss 5 下运行相同的应用程序,一切看起来都很好,但有一件事失败了。

它是一段代码,生成一些 JSon 来提供使用 打开 Flash 图表库构建的图表。我还使用 JOFC 库 为这些图表生成 JSon。好吧,我们使用的方法基本上有一个打印 JSon 的接缝工厂,然后我们在空白的 .xhtml 页面中引用该工厂,图表从该页面加载正确渲染所需的 JSon。遵循一些片段:

调用接缝工厂的 xhtml 页面:

<f:view xmlns="http://www.w3.org/1999/xhtml"
   xmlns:f="http://java.sun.com/jsf/core"
   contentType="text/json; charset=UTF-8">

   #{jsonGraficoPesoUsuario}

</f:view> 

生成 JSon 字符串的工厂方法:

@Factory("jsonGraficoPesoUsuario")
 public String graficoPesoUsuario()
 {
...

   String jsonString = chart.toString();
   log.info("JSonString ==>> " + jsonString);
//   try {
//    jsonString = URLEncoder.encode(jsonString, "UTF-8");
//   } catch (UnsupportedEncodingException e) {
//    log.error("Erro ao tentar fazer o encode da string json ==>> " + e.getMessage());
//    e.printStackTrace();
//   }
   return jsonString;

代码还显示,我们在发送之前尝试对 json 字符串进行编码,但再次没有成功。在将 json 打印到 log.info 的行中,json 字符串被完美保留,但使用 JBoss5 时发生的情况是“(双引号)字符被 html 转义字符替换。

接下来的 json 字符串预计会正确提供图表并且在 jboss4 下行为正确:

{"y_axis":{"min":100,"colour":"#96A9C5","grid-colour":"#DDDEE1","max":112},"title":{"text"
:"Gráfico de evolução de Peso"},"bg_colour":"#FFFFFF","is_decimal_separator_comma":1,"elements":[{"text":"Peso","values":[100.5,101.5,102.5,
102,103,107,109,110.5,108],"font-size":10,"type":"line","tip":"Linha do Peso"}],"num_decimals":2,"is_fixed_num_decimals_forced":1,"x_axis":{
"colour":"#96A9C5","grid-colour":"#DDDEE1","labels":{"rotate":"-24","labels":["01/05/10","15/05/10","25/05/10","01/06/10","09/06/10","25/06/
10","05/07/10","10/07/10","20/07/10"]}},"is_thousand_separator_disabled":0} 

但是与使用 JBoss5 相比,打印了以下字符串,请注意双引号的 html 编码替换:

{&quot;y_axis&quot;:{&quot;min&quot;:100,&quot;colour&quot;:&quot;#96A9C5&quot;,&quot;grid-colour&quot;:&quot;#DDDEE1&quot;,&quot;max&quot;:112},&quot;title&quot;:{&quot;text&quot;:&quot;Gr&aacute;fico de evolu&ccedil;&atilde;o de Peso&quot;},&quot;bg_colour&quot;:&quot;#FFFFFF&quot;,&quot;is_decimal_separator_comma&quot;:1,&quot;elements&quot;:[{&quot;text&quot;:&quot;Peso&quot;,&quot;values&quot;:[100.5,101.5,102.5,102,103,107,109,110.5,108],&quot;font-size&quot;:10,&quot;type&quot;:&quot;line&quot;,&quot;tip&quot;:&quot;Linha do Peso&quot;}],&quot;num_decimals&quot;:2,&quot;is_fixed_num_decimals_forced&quot;:1,&quot;x_axis&quot;:{&quot;colour&quot;:&quot;#96A9C5&quot;,&quot;grid-colour&quot;:&quot;#DDDEE1&quot;,&quot;labels&quot;:{&quot;rotate&quot;:&quot;-24&quot;,&quot;labels&quot;:[&quot;01/05/10&quot;,&quot;15/05/10&quot;,&quot;25/05/10&quot;,&quot;01/06/10&quot;,&quot;09/06/10&quot;,&quot;25/06/10&quot;,&quot;05/07/10&quot;,&quot;10/07/10&quot;,&quot;20/07/10&quot;]}},&quot;is_thousand_separator_disabled&quot;:0}

我已经检查了操作系统区域设置,并且还在 jboss http 通道上进行了配置以对 server.xml 中的正文进行编码:

<!-- A HTTP/1.1 Connector on port 8080 -->
      <Connector protocol="HTTP/1.1" port="8080" address="${jboss.bind.address}" 
               connectionTimeout="20000" redirectPort="8443" useBodyEncodingForURI="true"/>

它不起作用。我们的应用程序中的所有资源和页面都使用 UTF-8。

任何线索吗?

有 []s

It is an application that has been built using seam 2.2 and it is running perfectly under Jboss 4.1.2. Because of support from my ISP I will have to upgrade JBoss to version 5.1 . I did try to run same app under JBoss 5 and everything looked fine but one single thing failed.

It is a piece of code that generates some JSon to feed a Chart built using Open Flash Chart libraries. I also use JOFC libraries to generate the JSon for these charts. Well the approach we have used basically has a seam factory which prints a JSon and than we do reference this factory in a blank .xhtml page from where the chart loads the required JSon to render properly. Follow some snippets:

The xhtml page where the seam factory gets called:

<f:view xmlns="http://www.w3.org/1999/xhtml"
   xmlns:f="http://java.sun.com/jsf/core"
   contentType="text/json; charset=UTF-8">

   #{jsonGraficoPesoUsuario}

</f:view> 

The factory method which generates the JSon string:

@Factory("jsonGraficoPesoUsuario")
 public String graficoPesoUsuario()
 {
...

   String jsonString = chart.toString();
   log.info("JSonString ==>> " + jsonString);
//   try {
//    jsonString = URLEncoder.encode(jsonString, "UTF-8");
//   } catch (UnsupportedEncodingException e) {
//    log.error("Erro ao tentar fazer o encode da string json ==>> " + e.getMessage());
//    e.printStackTrace();
//   }
   return jsonString;

Well the code shows also that we have tryied encoding the json string before sending but again no success. In the line where it is printed json to log.info the json string is perfectly preserved, but using JBoss5 what happens is that the " (double quote) chars are replaced by html escape characters.

The follow json string is expected to properly feed the chart and this behaves correctly under jboss4:

{"y_axis":{"min":100,"colour":"#96A9C5","grid-colour":"#DDDEE1","max":112},"title":{"text"
:"Gráfico de evolução de Peso"},"bg_colour":"#FFFFFF","is_decimal_separator_comma":1,"elements":[{"text":"Peso","values":[100.5,101.5,102.5,
102,103,107,109,110.5,108],"font-size":10,"type":"line","tip":"Linha do Peso"}],"num_decimals":2,"is_fixed_num_decimals_forced":1,"x_axis":{
"colour":"#96A9C5","grid-colour":"#DDDEE1","labels":{"rotate":"-24","labels":["01/05/10","15/05/10","25/05/10","01/06/10","09/06/10","25/06/
10","05/07/10","10/07/10","20/07/10"]}},"is_thousand_separator_disabled":0} 

But than using JBoss5 the follow string is printed, notice the html encode replacement for double quotes:

{"y_axis":{"min":100,"colour":"#96A9C5","grid-colour":"#DDDEE1","max":112},"title":{"text":"Gráfico de evolução de Peso"},"bg_colour":"#FFFFFF","is_decimal_separator_comma":1,"elements":[{"text":"Peso","values":[100.5,101.5,102.5,102,103,107,109,110.5,108],"font-size":10,"type":"line","tip":"Linha do Peso"}],"num_decimals":2,"is_fixed_num_decimals_forced":1,"x_axis":{"colour":"#96A9C5","grid-colour":"#DDDEE1","labels":{"rotate":"-24","labels":["01/05/10","15/05/10","25/05/10","01/06/10","09/06/10","25/06/10","05/07/10","10/07/10","20/07/10"]}},"is_thousand_separator_disabled":0}

I have already checked O.S locale and also did a configuration on jboss http channel to encode the body in server.xml:

<!-- A HTTP/1.1 Connector on port 8080 -->
      <Connector protocol="HTTP/1.1" port="8080" address="${jboss.bind.address}" 
               connectionTimeout="20000" redirectPort="8443" useBodyEncodingForURI="true"/>

It didn't work. We use UTF-8 for all resources and pages in our app.

Any clues?

Tx in advance.
[]s

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

趴在窗边数星星i 2024-10-08 05:52:02

我查看了 jsf 文档并进行了审查,发现了 f:verbatim 标签。它解决了这个问题。现在,打印 json 字符串的 .xhtml 页面如下所示:

<f:view xmlns="http://www.w3.org/1999/xhtml"
   xmlns:f="http://java.sun.com/jsf/core"
   contentType="text/json" >

  <f:verbatim> 
   #{jsonGraficoPesoUsuario}
   </f:verbatim>
</f:view>

现在结果 json 字符串没有更改,并且图形可以正确呈现。

[]s

I took a look at jsf documentation to review it and found f:verbatim tag. It fixed the issue. Now my .xhtml page where the json string is printed is like:

<f:view xmlns="http://www.w3.org/1999/xhtml"
   xmlns:f="http://java.sun.com/jsf/core"
   contentType="text/json" >

  <f:verbatim> 
   #{jsonGraficoPesoUsuario}
   </f:verbatim>
</f:view>

Now the result json string is not changed and the graphic renders properly.

[]s

遗忘曾经 2024-10-08 05:52:02

我不知道这是否有帮助,但我会尝试。

在 Components.xml 中设置

<web:character-encoding-filter encoding="UTF-8" override-client="true" url-pattern="*.seam" />

创建一个过滤器,将所有内容设置为 UTF-8

public class UTF8Filter implements Filter {

  public void destroy() {}

  public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)   throws IOException, ServletException {
    // set encoding to UTF-8
    req.setCharacterEncoding("UTF-8");
    chain.doFilter(req, res);
    return;
  }

  public void init(FilterConfig arg0) throws ServletException {}

}

并在 web.xml 中启用此过滤器

<filter>
  <filter-name>UTF8 Filter</filter-name>
  <filter-class>my.package.filter.UTF8Filter</filter-class>
</filter>

如果这没有帮助,您可以手动编码字符串

 //If you only have problem with " you can do this
 jsonString.replaceAll(""","\\\"");

我不确定正则表达式能否正常工作,但您可以尝试。您也许还可以使用 StringEscapeUtils Apache Commons 能够正确转义所有 HTML。

I don't know if this will help, but I will try.

In components.xml set

<web:character-encoding-filter encoding="UTF-8" override-client="true" url-pattern="*.seam" />

Create a Filter that will set everything to UTF-8

public class UTF8Filter implements Filter {

  public void destroy() {}

  public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)   throws IOException, ServletException {
    // set encoding to UTF-8
    req.setCharacterEncoding("UTF-8");
    chain.doFilter(req, res);
    return;
  }

  public void init(FilterConfig arg0) throws ServletException {}

}

And enable this filter in web.xml

<filter>
  <filter-name>UTF8 Filter</filter-name>
  <filter-class>my.package.filter.UTF8Filter</filter-class>
</filter>

If this doesn't help, you can manually encode the string

 //If you only have problem with " you can do this
 jsonString.replaceAll(""","\\\"");

I am not sure the regex will work correctly, but you can try. You can also perhaps use StringEscapeUtils from Apache Commons to correctly escape all HTML.

轻拂→两袖风尘 2024-10-08 05:52:02
String output=new String(input.getBytes(),"UTF-8");

这样的付出解决了问题。

String output=new String(input.getBytes(),"UTF-8");

Giving like this solved the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文