SSL (glassfish 3.1.2 および jax-ws) で保護された ejb エンドポイント Web サービスがあります。インターセプターを使用してユーザーのアクティビティをログに記録しています。
@Statless
public class WebServiceInterceptor {
@Resource
WebServiceContext wsContext;
@AroundInvoke
protected Object audit(InvocationContext ctx) throws Exception {
MessageContext mc = wsContext.getMessageContext();
try {
Principal principal = wsContext.getUserPrincipal();
user = principal.getName();
System.out.println("user:" + user);
} catch (Exception e) {
System.out.println("log faild!");
}
}
インターセプターがトリガーされると、次の例外が発生します。
ATTENTION: invocation error on ejb endpoint Oculus_ws_v1 at /mywebservice/mywebservice : com.ctc.wstx.exc.WstxIOException: null
javax.xml.ws.WebServiceException: com.ctc.wstx.exc.WstxIOException: null
at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:130)
at com.sun.xml.ws.security.encoding.LazyStreamCodec.encode(LazyStreamCodec.java:88)
at com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:285)
at com.sun.xml.ws.transport.http.HttpAdapter.encodePacket(HttpAdapter.java:421)
at com.sun.xml.ws.transport.http.HttpAdapter.access$100(HttpAdapter.java:99)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:650)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:263)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:163)
at org.glassfish.webservices.Ejb3MessageDispatcher.handlePost(Ejb3MessageDispatcher.java:120)
at org.glassfish.webservices.Ejb3MessageDispatcher.invoke(Ejb3MessageDispatcher.java:91)
at org.glassfish.webservices.EjbWebServiceServlet.dispatchToEjbEndpoint(EjbWebServiceServlet.java:200)
at org.glassfish.webservices.EjbWebServiceServlet.service(EjbWebServiceServlet.java:131)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at com.sun.grizzly.http.servlet.ServletAdapter$FilterChainImpl.doFilter(ServletAdapter.java:1059)
at com.sun.grizzly.http.servlet.ServletAdapter$FilterChainImpl.invokeFilterChain(ServletAdapter.java:999)
at com.sun.grizzly.http.servlet.ServletAdapter.doService(ServletAdapter.java:434)
at com.sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:384)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)
Caused by: com.ctc.wstx.exc.WstxIOException: null
at com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:263)
at com.sun.xml.ws.util.xml.XMLStreamWriterFilter.flush(XMLStreamWriterFilter.java:71)
at com.sun.xml.ws.streaming.XMLStreamWriterUtil.getOutputStream(XMLStreamWriterUtil.java:103)
at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:382)
at com.sun.xml.ws.security.opt.impl.message.SOAPBody.writePayload(SOAPBody.java:132)
at com.sun.xml.ws.security.opt.impl.message.SOAPBody.writeTo(SOAPBody.java:166)
at com.sun.xml.ws.security.opt.impl.message.SecuredMessage.writeTo(SecuredMessage.java:364)
at com.sun.xml.ws.security.opt.impl.message.MessageWrapper.writeTo(MessageWrapper.java:355)
at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:127)
... 34 more
Caused by: ClientAbortException: java.io.IOException: SSLOutputWriter: CLOSED
at com.sun.grizzly.tcp.http11.GrizzlyOutputBuffer.doFlush(GrizzlyOutputBuffer.java:439)
at com.sun.grizzly.tcp.http11.GrizzlyOutputBuffer.flush(GrizzlyOutputBuffer.java:405)
at com.sun.grizzly.tcp.http11.GrizzlyOutputStream.flush(GrizzlyOutputStream.java:140)
at com.sun.grizzly.http.servlet.ServletOutputStreamImpl.flush(ServletOutputStreamImpl.java:100)
at com.ctc.wstx.io.UTF8Writer.flush(UTF8Writer.java:103)
at com.ctc.wstx.sw.BufferingXmlWriter.flush(BufferingXmlWriter.java:225)
at com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:261)
... 42 more
Caused by: java.io.IOException: SSLOutputWriter: CLOSED
at com.sun.grizzly.util.SSLOutputWriter.flushChannel(SSLOutputWriter.java:98)
at com.sun.grizzly.ssl.SSLOutputBuffer.flushChannel(SSLOutputBuffer.java:138)
at com.sun.grizzly.http.SocketChannelOutputBuffer.flushBuffer(SocketChannelOutputBuffer.java:498)
at com.sun.grizzly.http.SocketChannelOutputBuffer.flush(SocketChannelOutputBuffer.java:476)
at com.sun.grizzly.http.ProcessorTask.action(ProcessorTask.java:1287)
at com.sun.grizzly.ssl.SSLProcessorTask.action(SSLProcessorTask.java:164)
at com.sun.grizzly.tcp.Response.action(Response.java:268)
at com.sun.grizzly.tcp.http11.GrizzlyOutputBuffer.doFlush(GrizzlyOutputBuffer.java:434)
... 48 more
INFO: user:super_hd
ATTENTION: invocation error on ejb endpoint Oculus_ws_v1 at /Oculus_ws_v1/Oculus_ws_v1 : com.ctc.wstx.exc.WstxIOException: null
javax.xml.ws.WebServiceException: com.ctc.wstx.exc.WstxIOException: null
at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:130)
at com.sun.xml.ws.security.encoding.LazyStreamCodec.encode(LazyStreamCodec.java:88)
at com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:285)
at com.sun.xml.ws.transport.http.HttpAdapter.encodePacket(HttpAdapter.java:421)
at com.sun.xml.ws.transport.http.HttpAdapter.access$100(HttpAdapter.java:99)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:650)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:263)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:163)
at org.glassfish.webservices.Ejb3MessageDispatcher.handlePost(Ejb3MessageDispatcher.java:120)
at org.glassfish.webservices.Ejb3MessageDispatcher.invoke(Ejb3MessageDispatcher.java:91)
at org.glassfish.webservices.EjbWebServiceServlet.dispatchToEjbEndpoint(EjbWebServiceServlet.java:200)
at org.glassfish.webservices.EjbWebServiceServlet.service(EjbWebServiceServlet.java:131)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at com.sun.grizzly.http.servlet.ServletAdapter$FilterChainImpl.doFilter(ServletAdapter.java:1059)
at com.sun.grizzly.http.servlet.ServletAdapter$FilterChainImpl.invokeFilterChain(ServletAdapter.java:999)
at com.sun.grizzly.http.servlet.ServletAdapter.doService(ServletAdapter.java:434)
at com.sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:384)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)
Caused by: com.ctc.wstx.exc.WstxIOException: null
at com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:263)
at com.sun.xml.ws.util.xml.XMLStreamWriterFilter.flush(XMLStreamWriterFilter.java:71)
at com.sun.xml.ws.streaming.XMLStreamWriterUtil.getOutputStream(XMLStreamWriterUtil.java:103)
at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:382)
at com.sun.xml.ws.security.opt.impl.message.SOAPBody.writePayload(SOAPBody.java:132)
at com.sun.xml.ws.security.opt.impl.message.SOAPBody.writeTo(SOAPBody.java:166)
at com.sun.xml.ws.security.opt.impl.message.SecuredMessage.writeTo(SecuredMessage.java:364)
at com.sun.xml.ws.security.opt.impl.message.MessageWrapper.writeTo(MessageWrapper.java:355)
at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:127)
... 34 more
Caused by: ClientAbortException: java.io.IOException: SSLOutputWriter: CLOSED
at com.sun.grizzly.tcp.http11.GrizzlyOutputBuffer.doFlush(GrizzlyOutputBuffer.java:439)
at com.sun.grizzly.tcp.http11.GrizzlyOutputBuffer.flush(GrizzlyOutputBuffer.java:405)
at com.sun.grizzly.tcp.http11.GrizzlyOutputStream.flush(GrizzlyOutputStream.java:140)
at com.sun.grizzly.http.servlet.ServletOutputStreamImpl.flush(ServletOutputStreamImpl.java:100)
at com.ctc.wstx.io.UTF8Writer.flush(UTF8Writer.java:103)
at com.ctc.wstx.sw.BufferingXmlWriter.flush(BufferingXmlWriter.java:225)
at com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:261)
... 42 more
Caused by: java.io.IOException: SSLOutputWriter: CLOSED
at com.sun.grizzly.util.SSLOutputWriter.flushChannel(SSLOutputWriter.java:98)
at com.sun.grizzly.ssl.SSLOutputBuffer.flushChannel(SSLOutputBuffer.java:138)
at com.sun.grizzly.http.SocketChannelOutputBuffer.flushBuffer(SocketChannelOutputBuffer.java:498)
at com.sun.grizzly.http.SocketChannelOutputBuffer.flush(SocketChannelOutputBuffer.java:476)
at com.sun.grizzly.http.ProcessorTask.action(ProcessorTask.java:1287)
at com.sun.grizzly.ssl.SSLProcessorTask.action(SSLProcessorTask.java:164)
at com.sun.grizzly.tcp.Response.action(Response.java:268)
at com.sun.grizzly.tcp.http11.GrizzlyOutputBuffer.doFlush(GrizzlyOutputBuffer.java:434)
... 48 more
SSL暗号化を無効にするかコメントすると、wsContext.getUserPrincipal();
すべて正常に動作します。ありがとう
編集1:このメソッドを呼び出すと、これはインターセプターの使用とは関係ないようです:
@Resource
WebServiceContext wsContext;
@WebMethod(operationName = "hello")
public String hello(@WebParam(name = "name") String txt) {
System.out.println("ws context:" + wsContext.getUserPrincipal());
return "Hello " + txt + " !";
}
ほぼ同じ例外が発生します
ATTENTION: processorTask.exceptionSSLcert
javax.net.ssl.SSLException: SSLEngine is closing/closed
at com.sun.net.ssl.internal.ssl.SSLEngineImpl.kickstartHandshake(SSLEngineImpl.java:656)
at com.sun.net.ssl.internal.ssl.SSLEngineImpl.beginHandshake(SSLEngineImpl.java:689)
at com.sun.grizzly.util.SSLUtils.doPeerCertificateChain(SSLUtils.java:563)
at com.sun.grizzly.filter.SSLReadFilter.doPeerCertificateChain(SSLReadFilter.java:340)
at com.sun.grizzly.ssl.SSLProcessorTask.action(SSLProcessorTask.java:153)
at com.sun.grizzly.tcp.Request.action(Request.java:430)
at com.sun.grizzly.tcp.http11.GrizzlyRequest.getAttribute(GrizzlyRequest.java:835)
at com.sun.grizzly.tcp.http11.GrizzlyRequest.getUserPrincipal(GrizzlyRequest.java:1845)
at com.sun.grizzly.http.servlet.HttpServletRequestImpl.getUserPrincipal(HttpServletRequestImpl.java:906)
at com.sun.xml.ws.transport.http.servlet.ServletConnectionImpl.getUserPrincipal(ServletConnectionImpl.java:219)
at com.sun.xml.ws.server.AbstractWebServiceContext.getUserPrincipal(AbstractWebServiceContext.java:84)
at org.glassfish.webservices.WebServiceContextImpl.getUserPrincipal(WebServiceContextImpl.java:112)
at Ws.PocWS.hello(PocWS.java:32)
どんな回避策もいいでしょう。