本文介绍了使用拦截器更改CXF中的前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body>to

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body>

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body>

我正在使用Mule和CXF.我们正在公开一个SOAP服务,而wsdl来自旧系统(我们将其导入并生成类).有必要将前缀从"soap"更改为"s".我看到拦截器可以实现此功能,但是由于某些原因,我无法使其正常工作.这是我的拦截器的代码:

I am using Mule and CXF. We are exposing a SOAP service and the wsdl is from a legacy system (we imported it and generated the classes). It is necessary to change the prefix from 'soap' to just 's'. I see that this is possible with an Interceptor, but for some reason I cant make it work. Here is the code for my interceptor:

package se.comaround.interceptors;

import java.util.HashMap;
import java.util.Map;

import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;

public class ComAroundSoapResponceInterceptor extends
		AbstractPhaseInterceptor<SoapMessage> {

	public ComAroundSoapResponceInterceptor() {
		super(Phase.PREPARE_SEND);
	}

	public void handleMessage(SoapMessage message) {
		Map<String, String> hmap = new HashMap<String, String>();
		hmap.put("s", "http://schemas.xmlsoap.org/soap/envelope/");
		message.setContextualProperty("soap.env.ns.map", hmap);
		message.setContextualProperty("disable.outputstream.optimization", true);

		System.out.println("Set up");
	}

}

此外,我可以更改响应中模式的前缀吗?

Furthermore, can I change the prefixes for the schemas inside the response?

推荐答案

经过一番测试后,它仍然有效.这看起来很愚蠢,下巴掉了好几次,我重新启动,清理了所有现金,重新构建,当我添加额外的行时,拦截器似乎起作用了,我知道这真是难以置信:

After some testing around, it worked. It might seem very stupid and my jaw dopped a couple of times, I restarted, cleared all cash, re-built and it seems like the interceptor :

package se.comaround.interceptors;

import java.util.HashMap;
import java.util.Map;

import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.phase.Phase;

public class ComAroundSoapResponceInterceptor  
        extends  AbstractSoapInterceptor {

    public ComAroundSoapResponceInterceptor() {
        super(Phase.PREPARE_SEND);
    }

    public void handleMessage(SoapMessage message) {
        Map<String, String> hmap = new HashMap<String, String>();
        hmap.put("s", "http://schemas.xmlsoap.org/soap/envelope/");
                message.put("soap.env.ns.map", hmap);
                message.put("disable.outputstream.optimization", true);
    }
}

我不得不喝点咖啡,要花一些时间才能知道它实际上是这样工作的.因此,或多或少他们在这里提出的建议:

I had to drink some coffee, take some time before I got it that it actually is working this way. So, more or less what they suggest here:

http://cxf.547215.n5.nabble.com/How-to-customize-namespaces-position-and-prefix-in-CXF-response-td3423069.html

这篇关于使用拦截器更改CXF中的前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 13:16