Search in sources :

Example 1 with StreamingHandler

use of com.sun.xml.rpc.spi.runtime.StreamingHandler 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 StreamingHandler

use of com.sun.xml.rpc.spi.runtime.StreamingHandler 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)

Example 3 with StreamingHandler

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

the class WsUtil method getInvMethod.

/**
 *@return a method object representing the target of a web service
 * invocation
 */
public Method getInvMethod(Tie webServiceTie, MessageContext context) throws Exception {
    // Use tie to get Method from SOAP message inv.webServiceTie
    SOAPMessageContext soapMsgContext = (SOAPMessageContext) context;
    SOAPMessage message = soapMsgContext.getMessage();
    if (!(webServiceTie instanceof StreamingHandler)) {
        throw new IllegalArgumentException(webServiceTie + "is not instance of StreamingHandler.");
    }
    StreamingHandler streamingHandler = (StreamingHandler) webServiceTie;
    int opcode = streamingHandler.getOpcodeForRequestMessage(message);
    return streamingHandler.getMethodForOpcode(opcode);
}
Also used : SOAPMessageContext(javax.xml.rpc.handler.soap.SOAPMessageContext) StreamingHandler(com.sun.xml.rpc.spi.runtime.StreamingHandler) UserDataConstraint(com.sun.enterprise.deployment.web.UserDataConstraint) SecurityConstraint(com.sun.enterprise.deployment.web.SecurityConstraint)

Aggregations

StreamingHandler (com.sun.xml.rpc.spi.runtime.StreamingHandler)3 SOAPMessageContext (com.sun.xml.rpc.spi.runtime.SOAPMessageContext)2 SOAPMessage (javax.xml.soap.SOAPMessage)2 SecurityConstraint (com.sun.enterprise.deployment.web.SecurityConstraint)1 UserDataConstraint (com.sun.enterprise.deployment.web.UserDataConstraint)1 Implementor (com.sun.xml.rpc.spi.runtime.Implementor)1 Tie (com.sun.xml.rpc.spi.runtime.Tie)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 SOAPMessageContext (javax.xml.rpc.handler.soap.SOAPMessageContext)1 MimeHeaders (javax.xml.soap.MimeHeaders)1 EJBInvocation (org.glassfish.ejb.api.EJBInvocation)1