我在weblogic 12c中部署CXF客户端时遇到问题。
如果我用jetty运行客户端我没有问题,这就是请求:
<soap:Body>
<ns2:getSegmento xmlns:ns2="http://api.service.web.dummy.com/" xmlns:ns3="http://model.api.dummy.com">
<descripcionSegmento>EXTG</descripcionSegmento>
</ns2:getSegmento>
但是weblogic中的同一个客户端会生成此请求:
<env:Body>
<getSegmento xmlns="http://api.service.web.dummy.com/" xmlns:ns3="http://model.api.dummy.com" xmlns:ns2="http://api.service.web.dummy.com/">
<descripcionSegmento>EXTG</descripcionSegmento>
</getSegmento>
我注意到weblogic中缺少名称空间,可能是依赖项?
依赖关系:
org.apache.cxf:cxf-rt-frontend-jaxws:3.1.9
org.apache.cxf:cxf-rt-transports-http:3.1.9
org.apache.cxf:cxf-rt-databinding-aegis:3.1.9
org.apache.cxf:cxf-rt-bindings-corba:3.1.9
org.apache.cxf:cxf-rt-transports-jms:3.1.9
org.apache.cxf:cxf-rt-ws-security:3.1.9
Weblogic配置:
<prefer-application-packages>
<package-name>antlr.*</package-name>
<package-name>javax.servlet.jsp.jstl.*</package-name>
<package-name>javax.wsdl.*</package-name>
<package-name>org.antlr.*</package-name>
<package-name>org.aopalliance.*</package-name>
<package-name>org.apache.*</package-name>
<package-name>org.apache.xerces.*</package-name>
<package-name>org.aspectj.*</package-name>
<package-name>org.hibernate.*</package-name>
<package-name>org.mozilla.*</package-name>
<package-name>org.slf4j.*</package-name>
<package-name>org.springframework.*</package-name>
</prefer-application-packages>
我在服务中遇到了这个带有weblogic请求的错误:
Root cause of ServletException.
javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error: unexpected element (uri:"http://api.service.web.dummy.com/", local:"descripcionSegmento"). Expected elements are <{}descripcionSegmento>
请提供任何想法/帮助,将不胜感激
答案 0 :(得分:0)
我确实遇到了这个问题,我在下面尝试过但没有帮助:
我最终编写了拦截器来替换整个&#34; getSegmento &#34;身体下的元素,如下所示:
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPMessage;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.apache.cxf.phase.PhaseInterceptor;
import org.w3c.dom.Element;
public class MyRequestInterceptor extends AbstractPhaseInterceptor<SoapMessage> {
private List<PhaseInterceptor<? extends Message>> extras = new ArrayList<PhaseInterceptor<? extends Message>>(1);
public MyRequestInterceptor() {
super(Phase.USER_PROTOCOL);
extras.add(new SAAJOutInterceptor());
}
public Collection<PhaseInterceptor<? extends Message>> getAdditionalInterceptors() {
return extras;
}
public void handleMessage(SoapMessage message) throws Fault {
SOAPMessage msg = message.getContent(SOAPMessage.class);
try {
SOAPBody e = msg.getSOAPBody();
Element actionElement = msg.getSOAPPart().createElementNS("http://api.service.web.dummy.com/",
"ns2:getSegmento");
actionElement.appendChild(e.getFirstChild().getFirstChild());
e.replaceChild(actionElement, e.getFirstChild());
} catch (Exception e) {
throw new Fault(e);
}
}
}
在客户端创建期间添加了此拦截器:
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(serviceInterfaceClass);
factory.setAddress(endpoint);
MyRequestInterceptor interceptr = new MyRequestInterceptor();
factory.getOutInterceptors().add(interceptr);
答案 1 :(得分:0)
如果应用程序是企业应用程序(ear),则在 weblogic-application.xml 中添加以下标记
<prefer-application-packages>
<package-name>org.apache.cxf.*</package-name>
</prefer-application-packages>
如果应用程序是web-application(war),则将以上行添加到 weblogic.xml 中
preferred-application-packages元素指定必须始终从应用程序加载的类的软件包列表。
请参阅https://docs.oracle.com/cd/E24329_01/web.1211/e21049/weblogic_xml.htm#WBAPP663