日期:2014-05-19  浏览次数:20732 次

关于 Invalid byte 1 of 1-byte UTF-8 sequence
不知各位有没遇到过这样的问题呢?
问题描述:像一个url请求,获取得到的参数response如下
Java code

<?xml version='1.0' encoding='UTF-8'?><applyPrivilegeRet><formnum>100010</formnum><retn>-1</retn><desc>用户已经开通XXX套餐,不需要重复开通</desc><packages><opertype>1</opertype><privID>122216</privID><startdate>20120705</startdate></packages></applyPrivilegeRet>


通过以下代码解析该返回值,
Java code

    
    /**
     * 将xml输入流转成map对象
     * @param in -- xml输入流
     * @return -- map对象
     */
    public static Map toMap(InputStream in) {

        try {            
            SAXReader reader = new SAXReader();
            Document doc = reader.read(in);
            return toMap(doc.getRootElement());
        } catch (Exception ex) {
            throw new RuntimeException("解析xml成map对象异常", ex);
        } 
    }
     public static Map toMap(String xml) {
        ByteArrayInputStream sin = new ByteArrayInputStream(xml.getBytes());
        return toMap(sin);
    }

      public MyTest(String xml){
      toMap(response);
}                    


在两台linux服务器上,一台解析是没有任何问题的,另外一台出现java.lang.RuntimeException: 解析xml成map对象异常
  at com.aspire.commons.util.XmlUtil.toMap(XmlUtil.java:46)
  at com.aspire.commons.util.XmlUtil.toMap(XmlUtil.java:31)
  at com.aspire.boss.servlet.SubscribeFromBossServlet.parseApplyPrivilege(SubscribeFromBossServlet.java:203)
  at com.aspire.boss.servlet.SubscribeFromBossServlet.applyToHuawei(SubscribeFromBossServlet.java:366)
  at com.aspire.boss.servlet.SubscribeFromBossServlet.doPost(SubscribeFromBossServlet.java:106)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
  at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
  at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478)
  at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
  at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:480)
  at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:225)
  at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937)
  at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
  at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
  at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)
  at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
  at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:247)
  at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
  at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
  at org.eclipse.jetty.server.Server.handle(Server.java:346)
  at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:589)
  at org.eclips