SOAPMessage,提取SOAPBody时出现奇怪行为

时间:2018-10-10 10:59:49

标签: java dom soap cxf

我正在尝试使用cxf拦截器提取肥皂消息的正文。这是代码:

$this->data_to_send = array(
    // Merchant details
    'merchant_id'      => $this->merchant_id,
    'merchant_key'     => $this->merchant_key,
    'return_url'       => $this->get_return_url( $order ),
    'cancel_url'       => $order->get_cancel_order_url(),
    'notify_url'       => $this->response_url,

    // Billing details
    'name_first'       => self::get_order_prop( $order, 'billing_first_name' ),
    'name_last'        => self::get_order_prop( $order, 'billing_last_name' ),
    'email_address'    => self::get_order_prop( $order, 'billing_email' ),

    // Item details
    'm_payment_id'     => ltrim( $order->get_order_number(), _x( '#', 'hash before order number', 'woocommerce-gateway-payfast' ) ),
    'amount'           => $order->get_total(),
    'item_name'        => get_bloginfo( 'name' ) . ' - ' . $order->get_order_number(),
    /* translators: 1: blog info name */
    'item_description' => sprintf( __( 'New order from %s', 'woocommerce-gateway-payfast' ), get_bloginfo( 'name' ) ),

    //Split Payment
    'setup' => json_encode(['split_payment' => ['merchant_id' => 10000105, 'percentage'=>10, 'min' => 100, 'max' => 100000]]),

    // Custom strings
    'custom_str1'      => self::get_order_prop( $order, 'order_key' ),
    'custom_str2'      => 'WooCommerce/' . WC_VERSION . '; ' . get_site_url(),
    'custom_str3'      => self::get_order_prop( $order, 'id' ),
    'source'           => 'WooCommerce-Free-Plugin',
);

发生的事情是,当执行@Component public class SoapBodyExtractorInterceptor extends AbstractSoapInterceptor { private static final Logger logger = LogManager.getLogger(SoapBodyExtractorInterceptor.class); public SoapBodyExtractorInterceptor() { super(Phase.PRE_PROTOCOL); } @Override public void handleMessage(SoapMessage soapMessage) throws Fault { try { InputStream is = soapMessage.getContent(InputStream.class); SOAPMessage request = MessageFactory.newInstance().createMessage(null, is); SOAPBody soapBody = request.getSOAPBody(); DOMSource source = new DOMSource(soapBody); StringWriter stringResult = new StringWriter(); TransformerFactory.newInstance().newTransformer().transform(source, new StreamResult(stringResult)); soapMessage.getExchange().put(ExchangeContextEnum.XML_SOAP_BODY.toString(), stringResult.toString()); } catch (SOAPException | IOException | TransformerException e) { logger.warn("An error occurred while extracting soap body."); throw new Fault(e); } } } 方法时,它会抛出request.getSOAPBody()

原因是com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to create envelope from given source

但是,如果使用调试器在同一对象上第二次调用此方法,则它实际上可以正常工作。这种行为对我来说真的很奇怪。我该如何解决?

0 个答案:

没有答案