开发者社区> 问答> 正文

axis1.4 调用CXF 服务器端报错(cxf 整合ssh)?报错

spring整合CXF


AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server
 faultSubcode: 
 faultString: Cannot create a secure XMLInputFactory
 faultActor: 
 faultNode: 
 faultDetail: 
{http://xml.apache.org/axis/}stackTrace:Cannot create a secure XMLInputFactory
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2939)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:796)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.gdcct.ctp.base.Client.authentication(Client.java:50)

at com.gdcct.ctp.base.Client.main(Client.java:11)



// 安全验证
public class AuthenticationInterceptor extends AbstractPhaseInterceptor<SoapMessage>{
private String username;
private String password;

public AuthenticationInterceptor() {
// 指定该拦截器在哪个阶段被激发
super(Phase.PRE_INVOKE);
}

public void handleMessage(SoapMessage msg) throws Fault {
List<Header> headers = msg.getHeaders();
if (null == headers || headers.size() < 1) {
throw new Fault(new SOAPException("SOAPHeader格式错误"));
}
for (Header header : headers) {
Node root = (Node) header.getObject();
if("Authentication".equals(root.getNodeName())){
Node userNode = root.getFirstChild();
Node passwordNode = root.getLastChild();
if(userNode == null || passwordNode == null){
throw new Fault(new SOAPException("SOAPHeader需要包含Username和Password节点"));
}
if(!userNode.getNodeName().equals("Username") || !passwordNode.getNodeName().equals("Password")){
throw new Fault(new SOAPException("SOAPHeader需要包含Username和Password节点"));
}
if(username.equals(userNode.getTextContent()) && password.equals(passwordNode.getTextContent())){
System.out.println("认证通过");
}
else{
throw new Fault(new SOAPException("用户名或密码错误"));
}
}
else{
throw new Fault(new SOAPException("SOAPHeader需要包含Authentication节点"));
}
}
}



public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

}



server服务端

@WebService(targetNamespace="http://localhost:8090/api/HelloWorld")
public class HelloWorld {

public String hello(@WebParam(name="uname") String uname){
return "hello" + uname;
}
}


cxf 配置文件

 <!--导入与CXF框架有关的xml-->
        <import resource="classpath:META-INF/cxf/cxf.xml" />  
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />  
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
  
        <!--WebService接口--> 
    <jaxws:endpoint id="service"
      implementor="com.apis.HelloWorld" address="/HelloWorld">
      <jaxws:inInterceptors>    
      <bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />  
        <bean class="org.apache.cxf.binding.soap.saaj.SAAJInInterceptor" />
        
            <bean class="com.apis.security.AuthenticationInterceptor">  
                <property name="username" value="admin" />  
                <property name="password" value="admin" />  
            </bean>  
        </jaxws:inInterceptors>
    </jaxws:endpoint>



axis 客户端调用

public static void authentication(String user, String password){
try {
Call call = (Call)new Service().createCall();
String namespace = "";//命名空间
SOAPHeaderElement header = new SOAPHeaderElement(namespace,"Authentication");
header.setPrefix("");//前缀
        header.addChildElement("Username").addTextNode(user);  
        header.addChildElement("Password").addTextNode(password);
        call.addHeader(header);
        
        
        call.setTargetEndpointAddress("http://localhost:8090/api/HelloWorld");
        call.setOperationName(new QName("http://localhost:8090/api/HelloWorld","hello"));
String obj = (String) call.invoke(new Object[] {java.net.URLEncoder.encode("lihao", "UTF-8") });
System.out.println(obj);
} catch (Exception e) {
e.printStackTrace();

}

展开
收起
爱吃鱼的程序员 2020-06-22 19:10:59 537 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    少年,找到原因了?

    2020-06-22 19:11:18
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
如何运维千台以上游戏云服务器 立即下载
网站/服务器取证 实践与挑战 立即下载
ECS计算与存储分离架构实践 立即下载