2 Replies Latest reply: Jun 1, 2014 7:15 AM by maoua RSS

    java.io.UTFDataFormatException: Invalid UTF8 encoding

    maoua

      I created a Controller to generate PDF report in arabic lang, at runtime I get the report with '?' in place of arabic characters. This is my class:

       

      Public class PeopleCO extends OAControllerImpl {

          public static final String APP_NAME = "PER";

          public static final String TEMPLATE_CODE = "XXTU_EMP_DATA_CU";

       

          /**

           * Procedure to handle form submissions for form elements in

           * a region.

           * @param pageContext the current OA page context

           * @param webBean the web bean corresponding to the region

           */

          public void processFormRequest(OAPageContext pageContext, OAWebBean webBean) {

              super.processFormRequest(pageContext, webBean);

              OAApplicationModule am = pageContext.getApplicationModule(webBean);

             if ("print".equals(pageContext.getParameter(OAWebBeanConstants.EVENT_PARAM))) {

              am.invokeMethod("initDetails", parameters);

              print(pageContext, webBean);

              }

          }

       

       

          private void print(OAPageContext pageContext, OAWebBean webBean) {

              OAApplicationModule am = pageContext.getApplicationModule(webBean);

              DataObject sessionDictionary = pageContext.getNamedDataObject("_SessionParameters");

              HttpServletResponse response = (HttpServletResponse)sessionDictionary.selectValue(null, "HttpServletResponse");

             response.setHeader("Content-Disposition", "inline;filename=report.pdf");

              response.setCharacterEncoding("WINDOWS-1256");

              response.setContentType("application/pdf");

              try {

                  XMLNode xmlNode = (XMLNode)am.invokeMethod("getDataXML");

                  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

                  xmlNode.print(outputStream);

                  ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());

                  ByteArrayOutputStream pdfFile = new ByteArrayOutputStream();

       

                  TemplateHelper.processTemplate(((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getAppsContext(),

                                                 APP_NAME,

                                                 TEMPLATE_CODE,

                                                 ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getLanguage(),

                                                 ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getCountry(),

                                                 inputStream,

                                                 TemplateHelper.OUTPUT_TYPE_PDF,

                                                 null,

                                                 pdfFile);

       

                  byte[] b = pdfFile.toByteArray();

                  response.setContentLength(b.length);

                  ServletOutputStream os = response.getOutputStream();

                  os.write(b, 0, b.length);

                  os.flush();

                  os.close();

              } catch (Exception e) {

                  response.setContentType("text/html");

                  throw new OAException(e.getMessage(), OAException.ERROR);

              }

              pageContext.setDocumentRendered(true);

       

       

          }

       

      }


      when I change the line xmlNode.print(outputStream); by xmlNode.print(outputStream, "WINDOWS-1256");

        I get this exception : java.io.UTFDataFormatException: Invalid UTF8 encoding

      Anyone can help me to resolve this problem please?