0
回答
cxf 拦截器 异常
华为云4核8G,高性能云服务器,免费试用   
org.apache.cxf.binding.soap.SoapFault: Error reading XMLStreamReader.
	at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:237)
	at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:60)
	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
	at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
	at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:342)
	at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:310)
	at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:939)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:875)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:247)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
	at org.eclipse.jetty.server.Server.handle(Server.java:346)
	at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:589)
	at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1065)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:823)
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:220)
	at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:411)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:535)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:529)
	at java.lang.Thread.run(Thread.java:662)
Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
 at [row,col {unknown-source}]: [1,0]
	at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:677)
	at com.ctc.wstx.sr.BasicStreamReader.handleEOF(BasicStreamReader.java:2116)
	at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2022)
	at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1114)
	at com.ctc.wstx.sr.BasicStreamReader.nextTag(BasicStreamReader.java:1137)
	at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:138)
	... 21 more

这是程序异常,我写了个拦截器,在接受到soap消息时,从中解析出某个字段,解析的时候都是没有问题的代码如下

public class ProxyInterceptor extends AbstractPhaseInterceptor<SoapMessage> {
	
	private SAAJInInterceptor saa = new SAAJInInterceptor();
	private static String BODY_TAG="arg0";
	private static String TARGET_TAG="name";
	private static String LEFT_TAG = "<";
	private static String RIGHT_TAG = ">";
	private static String END_LEFT_TAG = "</";
	private static int TAG_LENGTH = 2;
	private static int END_TAG_LENGTH=3;
	private Logger logger = Logger.getLogger(ProxyInterceptor.class);
	@Override
	public void handleMessage(SoapMessage message) throws Fault {
		phaseSoap(message);
	}

	public ProxyInterceptor(){
		super(Phase.RECEIVE);
	}
	
	/**
	 * 解析soap请求,获取key值
	 * @author xuqi
	 * @title: phaseSoap
	 * @date 2015-10-26 上午10:00:06
	 * @param message
	 * @return String
	 */
	public String phaseSoap(SoapMessage message){
		String value=null;
		try {
			//获取message对应的输入流
			InputStream is = message.getContent(InputStream.class);
			//转换字符流
			InputStreamReader reader = new InputStreamReader(is);
			int i;
			StringBuilder sb = new StringBuilder();
			while((i=reader.read())!=-1){
				sb.append((char)i);
			}
			String xml = sb.toString();
			logger.info("soap message:"+"\n"+xml);
			System.out.println(BODY_TAG.length());
			String body = xml.substring(xml.indexOf(LEFT_TAG+BODY_TAG+RIGHT_TAG), xml.indexOf(END_LEFT_TAG+BODY_TAG+RIGHT_TAG)+BODY_TAG.length()+END_TAG_LENGTH);
			logger.info("body:"+"\n"+body);
			value = body.substring(body.indexOf(LEFT_TAG+TARGET_TAG+RIGHT_TAG)+TAG_LENGTH, body.indexOf(END_LEFT_TAG+TARGET_TAG+RIGHT_TAG));
		} catch (IOException e) {
			e.printStackTrace();
		}
		return value;
	}
	
	
}



有哪位大神有遇到这种情况的么?静候佳音。



举报
鬼之谷子
发帖于3年前 0回/263阅
顶部