我正在开发一个Web服务,它将输入参数作为两个字符串值。第一个标识用于导入xml数据的服务,第二个标识XML数据字符串。以下是SOAP请求的示例
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices.dataexchange.xxx.com/">
<soapenv:Header/>
<soapenv:Body>
<web:importDataExchange>
<ServiceID>XmlImportServiceName</ServiceID>
<ExchangeData><?xml version="1.0" encoding="UTF-8"?><srv:exchange xmlns:cnt="Container" xmlns:core="Core" xmlns:srv="Service" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="Service http://xxx/xxx.xsd"></srv:exchange></ExchangeData>
</web:importDataExchange>
</soapenv:Body>
</soapenv:Envelope>
不幸的是,每当我尝试解析SOAPMessage时,都会收到以下错误:
javax.xml.bind.UnmarshalException
- with linked exception:
[com.ctc.wstx.exc.WstxParsingException: Illegal processing instruction target ("xml"); xml (case insensitive) is reserved by the specs.
at [row,col {unknown-source}]: [6,28]]
这显然是因为我实现的JAX-WS正试图解组<ExchangeData>
元素的内容。当然,这可以通过将<ExchangeData>
的内容包装在<![CDATA[ ]]>
元素中来解决,但是,我无法控制数据如何发送到服务器。因此,我需要一种方法来拦截SOAPMessage并将ExchangeData作为字符串提取而不使用Unmarshalling它。或者,我需要一种方法让Web服务将ExchangeData节点的内容视为字符串而不是SOAPMessage主体/有效负载中的另一个XML节点。
我尝试过实现SOAPHandler和LogicalHandler,但是在两个实例中,只要获取Message / Payload,Web服务器就会尝试解组SOAP消息,这会再次重现相同的错误。
这是我迄今为止开发的ImportServiceEndpoint。
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@WebService(serviceName = "ImportServiceEndpoint", portName = "dataexchange")
// @HandlerChain(file = "handlers.xml")
public class ImportServiceEndpoint extends SpringBeanAutowiringSupport {
private static final Logger LOGGER = LoggerFactory.getLogger(ImportServiceEndpoint.class);
/**
* The soap implementation of the data exchange service.
*
* @param serviceID
* the id of the service
* @param exchangeData
* the xml data for the request.
* @return a response about the success/failure of the dataexchange.
*/
@WebMethod
@WebResult(name = "importDataExchangeResponse")
public String importDataExchange(@ModelAttribute("ServiceID") @WebParam(name = "ServiceID") final String serviceID,
@ModelAttribute("ExchangeData") @WebParam(name = "ExchangeData") final String exchangeData) {
LOGGER.debug("Recevied Soap request for service {} with xml data '{}'", serviceID, exchangeData);
return "Message Received";
}
}
如果有任何帮助,我将不胜感激。我已经非常沮丧,因为我已经在这几天工作了几天没有什么可展示的。