简体   繁体   English

使用 apache-camel [2.24.3] 使用 SOAP 服务时出错

[英]Error while consuming SOAP service using apache-camel[2.24.3]

I am getting error while I am trying to consume SOAP service, which is deployed in Jboss EAP 7.1 and My Server with Apache camel[2.24.3] and spring [5.2.2.RELEASE] deployed in Weblogic12c . I am getting error while I am trying to consume SOAP service, which is deployed in Jboss EAP 7.1 and My Server with Apache camel[2.24.3] and spring [5.2.2.RELEASE] deployed in Weblogic12c . After exchange happend, it needs to give getMandatoryBody() in string format but its returning in DOMSource, where camel is failing to cast DOMService to string.交换发生后,它需要以字符串格式提供 getMandatoryBody() 但它在 DOMSource 中返回,骆驼无法将 DOMService 转换为字符串。

The Exception I am getting is:我得到的例外是:

No body available of type: java.lang.String but has value: javax.xml.transform.dom.DOMSource@37279c86 of type: javax.xml.transform.dom.DOMSource on: Message[ID-everest2-1589967071589-0-11]. Caused by: Error during type conversion from type: java.lang.String to the required type: java.lang.String with value [Body is instance of java.xml.transform.Source] due javax.xml.transform.TransformerException: java.lang.RuntimeException: com.ctc.wstx.exc.WstxIOException: Stream closed. Exchange[ID-everest2-1589967071589-0-10]. Caused by: [org.apache.camel.TypeConversionException - Error during type conversion from type: java.lang.String to the required type: java.lang.String with value [Body is instance of java.xml.transform.Source] due javax.xml.transform.TransformerException: java.lang.RuntimeException: com.ctc.wstx.exc.WstxIOException: Stream closed

The problem is happening only when i deploy my server[with camel and spring] in weblogic 12c.只有当我在 weblogic 12c 中部署我的服务器 [with camel and spring] 时才会出现问题。 Other application servers Tomcat 8.5.35 and jboss-EAP7.2.Its working fine.其他应用服务器 Tomcat 8.5.35 和 jboss-EAP7.2。它工作正常。

I tried by downgrading camel-spring-ws version to [2.17.3] its working fine.我尝试将 camel-spring-ws 版本降级到 [2.17.3] 它工作正常。

Your exception clearly states that from getMandatoryBody() method, you are getting a javax.xml.transform.dom.DOMSource type of value and not a String value.您的异常清楚地表明,从 getMandatoryBody() 方法中,您将获得 javax.xml.transform.dom.DOMSource 类型的值,而不是 String 值。 So, you might need to read the value of getMandatoryBody() as DOMSource.因此,您可能需要将 getMandatoryBody() 的值读取为 DOMSource。 The conversion from DOMSource to String is easy using the Java Code:使用 Java 代码可以轻松地从 DOMSource 转换为 String:

import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;

//method to convert Document to String
public String getStringFromDocument(DOMSource domSource)
{
    try
    {
       StringWriter writer = new StringWriter();
       StreamResult result = new StreamResult(writer);
       TransformerFactory tf = TransformerFactory.newInstance();
       Transformer transformer = tf.newTransformer();
       transformer.transform(domSource, result);
       return writer.toString();
    }
    catch(TransformerException ex)
    {
       ex.printStackTrace();
       return null;
    }
}

If you are sure about the String value in the Exchange, perform a debug on the Exchange object to see what possible values are present there.如果您确定 Exchange 中的字符串值,请在 Exchange object 上执行调试以查看那里存在哪些可能的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM