XML序列化程序错误

时间:2014-04-22 10:34:02

标签: java xml serialization

准备文档并返回时,我收到以下错误。

请找到以下代码

        public static Document requestParamMissing (String params, String codeException, String message, String APIMethod, Exception e, subscriberID,
String UDID, StringBuilder listParams, String requestID, String APIUrl){

    Document doc = null;

    String errorCodeNumber = '';
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    doc = docBuilder.newDocument();
    Element rootElement = doc.createElement("Error");
    doc.appendChild(rootElement);
    Element errorCode = doc.createElement("Code");
    Element errorMessage = doc.createElement("Message");
    if(codeException.equals('RequestException')){
        errorCodeNumber = '1000';
        errorCode.appendChild(doc.createTextNode('1000'));
        errorMessage.appendChild(doc.createTextNode(message));
    }else{
        if(e?.toString()?.contains('UnknownHostException')){
            errorCodeNumber = '2000';
            errorCode.appendChild(doc.createTextNode('2000'));
            errorMessage.appendChild(doc.createTextNode('UnknownHostException'));
        }else if(e?.toString()?.contains('SocketTimeoutException')){
            errorCodeNumber = '3000';
            errorCode.appendChild(doc.createTextNode('3000'));
            errorMessage.appendChild(doc.createTextNode('SocketTimeoutException'));
        }else if(e?.toString()?.contains('ClientException')){
            errorCodeNumber = '4000';
            errorCode.appendChild(doc.createTextNode('4000'));
            errorMessage.appendChild(doc.createTextNode('ClientException'));
        }else if(e?.toString()?.contains('HttpResponseException')){
            errorCodeNumber = '5000';
            errorCode.appendChild(doc.createTextNode('5000'));
            errorMessage.appendChild(doc.createTextNode("HttpResponseException"));
        }else{
            errorCodeNumber = '6000';
            errorCode.appendChild(doc.createTextNode('6000'));
            errorMessage.appendChild(doc.createTextNode(e.toString()));
        }
    }

    rootElement.appendChild(errorCode);
    rootElement.appendChild(errorMessage);

    Element errorApiMethod = doc.createElement("ApiMethod");
    errorApiMethod.appendChild(doc.createTextNode(APIMethod));
    rootElement.appendChild(errorApiMethod);

    Element errorApiUrl = doc.createElement("ApiUrl");
    errorApiUrl.appendChild(doc.createTextNode(APIUrl));
    rootElement.appendChild(errorApiUrl);

    Element errorException = doc.createElement("Exception");
    if(e != null){
        errorException.appendChild(doc.createTextNode(e.toString()));
    }else{
        errorException.appendChild(doc.createTextNode(''));
    }
    rootElement.appendChild(errorException);

    Element errorMissingParam = doc.createElement("MissingParamValue");
    errorMissingParam.appendChild(doc.createTextNode(params));
    rootElement.appendChild(errorMissingParam);
    LOGGER.error('EF Response Time: Errors [API Request URL Method:' + APIMethod + ';Error Code :' + errorCodeNumber + ';Status:' +
            'Failure in Teleflora ' + APIUrl +' request;params:' + listParams +';Exception:' + e +
            ';UDID:' + UDID + ';RequestID:' + requestID + ']---> subscriberID:'+ subscriberID);

    return doc;
}

错误:

     java.lang.NullPointerException
at org.apache.xml.serializer.TreeWalker.dispatachChars(TreeWalker.java:246)
at org.apache.xml.serializer.TreeWalker.startNode(TreeWalker.java:416)
at org.apache.xml.serializer.TreeWalker.traverse(TreeWalker.java:145)
at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:390)
at com.sun.jersey.core.impl.provider.entity.DocumentProvider.writeTo(DocumentProvider.java:120)
at com.sun.jersey.core.impl.provider.entity.DocumentProvider.writeTo(DocumentProvider.java:70)
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

1 个答案:

答案 0 :(得分:0)

FWIW,它是由附加空文本值引起的。检查该消息是否为空。较新的序列化程序也可以解决问题。