Search in sources :

Example 1 with SOAPMessageContext

use of com.sun.xml.rpc.spi.runtime.SOAPMessageContext in project Payara by payara.

the class ServletSystemHandlerDelegate method processRequest.

/**
 * The processRequest method is invoked with an object that
 * implements com.sun.xml.rpc.spi.runtime.SOAPMessageContext.
 * <p>
 * When this method is called by the JAXRPCServletDelegate
 * (on the server side of jaxrpc servlet container invocation processing)
 * it must be called just before the call to implementor.getTie().handle(),
 * and at the time of the request message and the following properties
 * must have been set on the SOAPMessageContext.
 * <p>
 * com.sun.xml.rpc.server.http.MessageContextProperties.IMPLEMENTOR
 * <br>
 * This property must be set to the com.sun.xml.rpc.spi.runtime.Implementor
 * object corresponding to the target endpoint.
 * <p>
 * com.sun.xml.rpc.server.http.MessageContextProperties.HTTP_SERVLET_REQUEST
 * <br>
 * This property must be
 * set to the javax.servlet.http.HttpServletRequest object containing the
 * JAXRPC invocation.
 * <p>
 * com.sun.xml.rpc.server.http.MessageContextProperties.HTTP_SERVLET_RESPONSE
 * <br>
 * This property must be
 * set to the javax.servlet.http.HttpServletResponse object corresponding to
 * the JAXRPC invocation.
 * <p>
 * com.sun.xml.rpc.server.MessageContextProperties.HTTP_SERVLET_CONTEXT
 * <br>
 * This property must be
 * set to the javax.servlet.ServletContext object corresponding to web application
 * in which the JAXRPC servlet is running.
 * @param messageContext the SOAPMessageContext object containing the request
 * message and the properties described above.
 * @return true if processing by the delegate was such that the caller
 * should continue with its normal message processing. Returns false if the
 * processing by the delegate resulted in the messageContext containing a response
 * message that should be returned without the caller proceding to its normal
 * message processing.
 * @throws java.lang.RuntimeException when the processing by the delegate failed,
 * without yielding a response message. In this case, the expectation is that
 * the caller will return a HTTP layer response code reporting that an internal
 * error occured.
 */
public boolean processRequest(SOAPMessageContext messageContext) {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("ws.processRequest");
    }
    final SOAPMessageContext finalMC = messageContext;
    Implementor implementor = (Implementor) messageContext.getProperty(IMPLEMENTOR);
    final Tie tie = implementor.getTie();
    StreamingHandler handler = (StreamingHandler) implementor.getTie();
    SOAPMessage request = finalMC.getMessage();
    final ServerAuthContext sAC = config_.getAuthContext(handler, request);
    boolean status = true;
    try {
        if (sAC != null) {
            status = false;
            // proceed to process message security
            status = WebServiceSecurity.validateRequest(finalMC, sAC);
            if (status) {
                messageContext.setProperty(SERVER_AUTH_CONTEXT, sAC);
            }
        }
    } catch (AuthException ae) {
        _logger.log(Level.SEVERE, LogUtils.ERROR_REQUEST_VALIDATION, ae);
        throw new RuntimeException(ae);
    } finally {
        WebServiceSecurity.auditInvocation(messageContext, endpoint_, status);
    }
    if (status) {
        if (System.getSecurityManager() != null) {
            // on this branch, the endpoint invocation and the
            // processing of the response will be initiated from
            // within the system handler delegate. delegate returns
            // false so that dispatcher will not invoke the endpoint.
            status = false;
            try {
                Subject.doAsPrivileged(SecurityContext.getCurrent().getSubject(), new PrivilegedExceptionAction() {

                    public Object run() throws Exception {
                        tie.handle(finalMC);
                        processResponse(finalMC);
                        return null;
                    }
                }, null);
            } catch (PrivilegedActionException pae) {
                Throwable cause = pae.getCause();
                if (cause instanceof AuthException) {
                    _logger.log(Level.SEVERE, LogUtils.ERROR_RESPONSE_SECURING, cause);
                }
                RuntimeException re = null;
                if (cause instanceof RuntimeException) {
                    re = (RuntimeException) cause;
                } else {
                    re = new RuntimeException(cause);
                }
                throw re;
            }
        }
    }
    return status;
}
Also used : Implementor(com.sun.xml.rpc.spi.runtime.Implementor) PrivilegedActionException(java.security.PrivilegedActionException) StreamingHandler(com.sun.xml.rpc.spi.runtime.StreamingHandler) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) SOAPMessage(javax.xml.soap.SOAPMessage) PrivilegedActionException(java.security.PrivilegedActionException) Tie(com.sun.xml.rpc.spi.runtime.Tie) SOAPMessageContext(com.sun.xml.rpc.spi.runtime.SOAPMessageContext)

Example 2 with SOAPMessageContext

use of com.sun.xml.rpc.spi.runtime.SOAPMessageContext in project Payara by payara.

the class EjbWebServiceDispatcher method createSOAPMessage.

protected SOAPMessage createSOAPMessage(HttpServletRequest request, MimeHeaders headers) throws IOException {
    InputStream is = request.getInputStream();
    byte[] bytes = readFully(is);
    int length = request.getContentLength() == -1 ? bytes.length : request.getContentLength();
    ByteInputStream in = new ByteInputStream(bytes, length);
    SOAPMessageContext msgContext = rpcFactory.createSOAPMessageContext();
    SOAPMessage message = msgContext.createMessage(headers, in);
    return message;
}
Also used : ByteInputStream(com.sun.xml.messaging.saaj.util.ByteInputStream) SOAPMessageContext(com.sun.xml.rpc.spi.runtime.SOAPMessageContext) ByteInputStream(com.sun.xml.messaging.saaj.util.ByteInputStream) InputStream(java.io.InputStream) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 3 with SOAPMessageContext

use of com.sun.xml.rpc.spi.runtime.SOAPMessageContext in project Payara by payara.

the class EjbWebServiceDispatcher method handlePost.

private void handlePost(HttpServletRequest req, HttpServletResponse resp, EjbRuntimeEndpointInfo endpointInfo) throws IOException, SOAPException {
    JAXRPCEndpointImpl endpoint = null;
    String messageID = null;
    SOAPMessageContext msgContext = null;
    try {
        MimeHeaders headers = wsUtil.getHeaders(req);
        if (!wsUtil.hasTextXmlContentType(headers)) {
            wsUtil.writeInvalidContentType(resp);
            return;
        }
        msgContext = rpcFactory.createSOAPMessageContext();
        SOAPMessage message = createSOAPMessage(req, headers);
        boolean wssSucceded = true;
        if (message != null) {
            msgContext.setMessage(message);
            // get the endpoint info
            endpoint = (JAXRPCEndpointImpl) endpointInfo.getEndpoint().getExtraAttribute(EndpointImpl.NAME);
            if (endpoint != null) {
                // first global notification
                if (wsEngine.hasGlobalMessageListener()) {
                    messageID = wsEngine.preProcessRequest(endpoint);
                }
            } else {
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE, LogUtils.MISSING_MONITORING_INFO, req.getRequestURI());
                }
            }
            AdapterInvocationInfo aInfo = null;
            if (!(endpointInfo instanceof Ejb2RuntimeEndpointInfo)) {
                throw new IllegalArgumentException(endpointInfo + "is not instance of Ejb2RuntimeEndpointInfo.");
            }
            try {
                Ejb2RuntimeEndpointInfo endpointInfo2 = (Ejb2RuntimeEndpointInfo) endpointInfo;
                // Do ejb container pre-invocation and pre-handler
                // logic
                aInfo = endpointInfo2.getHandlerImplementor();
                // Set message context in invocation
                EJBInvocation.class.cast(aInfo.getInv()).setMessageContext(msgContext);
                // Set http response object so one-way operations will
                // response before actual business method invocation.
                msgContext.setProperty(HTTP_SERVLET_RESPONSE, resp);
                if (secServ != null) {
                    wssSucceded = secServ.validateRequest(endpointInfo2.getServerAuthConfig(), (StreamingHandler) aInfo.getHandler(), msgContext);
                }
                // Trace if necessary
                if (messageID != null || (endpoint != null && endpoint.hasListeners())) {
                    // create the thread local
                    ThreadLocalInfo threadLocalInfo = new ThreadLocalInfo(messageID, req);
                    wsEngine.getThreadLocal().set(threadLocalInfo);
                    if (endpoint != null) {
                        endpoint.processRequest(msgContext);
                    } else {
                        if (logger.isLoggable(Level.FINE)) {
                            logger.log(Level.FINE, LogUtils.MISSING_MONITORING_INFO, req.getRequestURI());
                        }
                    }
                }
                // which will be flow back into the ejb container.
                if (wssSucceded) {
                    aInfo.getHandler().handle(msgContext);
                }
            } finally {
                // if implementor is null.
                if (aInfo != null) {
                    endpointInfo.releaseImplementor(aInfo.getInv());
                }
            }
        } else {
            String errorMsg = MessageFormat.format(logger.getResourceBundle().getString(LogUtils.NULL_MESSAGE), endpointInfo.getEndpoint().getEndpointName(), endpointInfo.getEndpointAddressUri());
            if (logger.isLoggable(Level.FINE)) {
                logger.fine(errorMsg);
            }
            msgContext.writeSimpleErrorResponse(FAULT_CODE_CLIENT, errorMsg);
        }
        if (messageID != null || endpoint != null) {
            endpoint.processResponse(msgContext);
        }
        SOAPMessage reply = msgContext.getMessage();
        if (secServ != null && wssSucceded) {
            if (!(endpointInfo instanceof Ejb2RuntimeEndpointInfo)) {
                throw new IllegalArgumentException(endpointInfo + "is not instance of Ejb2RuntimeEndpointInfo.");
            }
            Ejb2RuntimeEndpointInfo endpointInfo2 = (Ejb2RuntimeEndpointInfo) endpointInfo;
            secServ.secureResponse(endpointInfo2.getServerAuthConfig(), (StreamingHandler) endpointInfo2.getHandlerImplementor().getHandler(), msgContext);
        }
        if (reply.saveRequired()) {
            reply.saveChanges();
        }
        wsUtil.writeReply(resp, msgContext);
    } catch (Throwable e) {
        String errorMessage = MessageFormat.format(logger.getResourceBundle().getString(LogUtils.ERROR_ON_EJB), new Object[] { endpointInfo.getEndpoint().getEndpointName(), endpointInfo.getEndpointAddressUri(), e.getMessage() });
        logger.log(Level.WARNING, errorMessage, e);
        SOAPMessageContext errorMsgContext = rpcFactory.createSOAPMessageContext();
        errorMsgContext.writeSimpleErrorResponse(SOAPConstants.FAULT_CODE_SERVER, errorMessage);
        resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        if (messageID != null || endpoint != null) {
            endpoint.processResponse(errorMsgContext);
        }
        wsUtil.writeReply(resp, errorMsgContext);
    }
    // final tracing notification
    if (messageID != null) {
        HttpResponseInfoImpl response = new HttpResponseInfoImpl(resp);
        wsEngine.postProcessResponse(messageID, response);
    }
}
Also used : StreamingHandler(com.sun.xml.rpc.spi.runtime.StreamingHandler) SOAPMessage(javax.xml.soap.SOAPMessage) MimeHeaders(javax.xml.soap.MimeHeaders) SOAPMessageContext(com.sun.xml.rpc.spi.runtime.SOAPMessageContext) EJBInvocation(org.glassfish.ejb.api.EJBInvocation)

Aggregations

SOAPMessageContext (com.sun.xml.rpc.spi.runtime.SOAPMessageContext)3 SOAPMessage (javax.xml.soap.SOAPMessage)3 StreamingHandler (com.sun.xml.rpc.spi.runtime.StreamingHandler)2 ByteInputStream (com.sun.xml.messaging.saaj.util.ByteInputStream)1 Implementor (com.sun.xml.rpc.spi.runtime.Implementor)1 Tie (com.sun.xml.rpc.spi.runtime.Tie)1 InputStream (java.io.InputStream)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 MimeHeaders (javax.xml.soap.MimeHeaders)1 EJBInvocation (org.glassfish.ejb.api.EJBInvocation)1