cxf 框架 搭建的webservice 客户端 配置了 outInterceptor 消息就发不到server 就超时报错。去掉这个拦截器 就好使了。。。。 但是这个拦截器 也没看出什么问题 。
流的问题? client端流没关闭,server端收不到?
跪求大神指点
以下是这个拦截器代码:
public class ClientOutInterceptor extends AbstractPhaseInterceptor<SoapMessage> { public ClientOutInterceptor() { super(Phase.PRE_STREAM); } public ClientOutInterceptor(String phase) { super(phase); } @Override public void handleMessage(SoapMessage message) throws Fault { try { OutputStream os = message.getContent(OutputStream.class); CachedStream cs = new CachedStream(); message.setContent(OutputStream.class, cs); message.getInterceptorChain().doIntercept(message); CachedOutputStream csnew = (CachedOutputStream) message.getContent(OutputStream.class); InputStream in = csnew.getInputStream(); String xml = IOUtils.toString(in); System.out.println(xml); // AESEncryptSafe aesEncryptSafe = new AESEncryptSafe("Kijhr3(dwjnJR6"); // xml = aesEncryptSafe.encrypt(xml); //这里对xml做处理,处理完后同理,写回流中 IOUtils.copy(new ByteArrayInputStream(xml.getBytes("UTF-8")), os); cs.close(); os.flush(); message.setContent(OutputStream.class, os); } catch (Exception e) { e.printStackTrace(); } } private class CachedStream extends CachedOutputStream { public CachedStream() { super(); } protected void doFlush() throws IOException { currentStream.flush(); } protected void doClose() throws IOException { } protected void onWrite() throws IOException { } } }
顶一下
publicvoidhandleMessage(SoapMessagesoap)throwsFault{System.out.println("开始验证用户信息");List<Header>headers=soap.getHeaders();if(headers==null||headers.size()<1){thrownewFault(newIllegalArgumentException("找不到Header,无法验证用户信息"));}Headerheader=null;for(Headerh:headers){if(h.getName().getLocalPart().equals(SOAP_CONSTRAINT.Q_NAME_LOCALPART)){header=h;break;}}if(header==null){thrownewFault(newIllegalArgumentException("头信息错误"));}Elementel=(Element)header.getObject();NodeListusers=el.getElementsByTagName("username");NodeListpasswords=el.getElementsByTagName("password");if(users.getLength()<1){thrownewFault(newIllegalArgumentException("找不到用户信息"));}Stringusername=users.item(0).getTextContent().trim();if(passwords.getLength()<1){thrownewFault(newIllegalArgumentException("找不到密码信息"));}Stringpassword=passwords.item(0).getTextContent();if(!"admin".equals(username)||!"admin".equals(password)){thrownewFault(newIllegalArgumentException("用户名或密码不正确"));}else{System.out.println("用户名密码正确允许访问");}}
我的是这样的
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。