org.apache.cxf.jaxws.context.WebServiceContextImpl Java Examples

The following examples show how to use org.apache.cxf.jaxws.context.WebServiceContextImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProviderImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
public Endpoint createEndpoint(String bindingId, Class<?> implementorClass,
                               Invoker invoker, WebServiceFeature ... features) {
    if (EndpointUtils.isValidImplementor(implementorClass)) {
        Bus bus = BusFactory.getThreadDefaultBus();
        JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
        if (features != null) {
            factory.getJaxWsServiceFactory().setWsFeatures(Arrays.asList(features));
        }
        if (invoker != null) {
            factory.setInvoker(new JAXWSMethodInvoker(invoker));
            try {
                invoker.inject(new WebServiceContextImpl());
            } catch (Exception e) {
                throw new WebServiceException(new Message("ENDPOINT_CREATION_FAILED_MSG",
                                                          LOG).toString(), e);
            }
        }
        EndpointImpl ep = new EndpointImpl(bus, null, factory);
        ep.setImplementorClass(implementorClass);
        return ep;
    }
    throw new WebServiceException(new Message("INVALID_IMPLEMENTOR_EXC", LOG).toString());
}
 
Example #2
Source File: KumuluzWSInvoker.java    From kumuluzee with MIT License 5 votes vote down vote up
@Override
protected Object performInvocation(Exchange exchange, final Object serviceObject, Method m, Object[] paramArray) throws Exception {
    WebServiceContext wsContext = new WebServiceContextImpl(null);

    try {
        KumuluzWebServiceContext.getInstance().setMessageContext(wsContext);

        return super.performInvocation(exchange, serviceObject, m, paramArray);
    } finally {
        KumuluzWebServiceContext.getInstance().setMessageContext(null);
    }
}
 
Example #3
Source File: HandlerChainInvoker.java    From cxf with Apache License 2.0 5 votes vote down vote up
private boolean invokeHandlerChain(List<? extends Handler<?>> handlerChain, MessageContext ctx) {
    if (handlerChain.isEmpty()) {
        LOG.log(Level.FINEST, "no handlers registered");
        return true;
    }

    if (isClosed()) {
        return false;
    }

    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "invoking handlers, direction: " + (outbound ? "outbound" : "inbound"));
    }

    if (!outbound) {
        handlerChain = reverseHandlerChain(handlerChain);
    }

    boolean continueProcessing = true;
    MessageContext oldCtx = null;
    try {
        oldCtx = WebServiceContextImpl.setMessageContext(ctx);
        continueProcessing = invokeHandleMessage(handlerChain, ctx);
    } finally {
        // restore the WebServiceContextImpl's ThreadLocal variable to the previous value
        if (oldCtx == null) {
            WebServiceContextImpl.clear();
        } else {
            WebServiceContextImpl.setMessageContext(oldCtx);
        }
    }

    return continueProcessing;
}
 
Example #4
Source File: HandlerChainInvoker.java    From cxf with Apache License 2.0 4 votes vote down vote up
private boolean invokeHandlerChainHandleFault(List<? extends Handler<?>> handlerChain,
    MessageContext ctx) {
    if (handlerChain.isEmpty()) {
        LOG.log(Level.FINEST, "no handlers registered");
        return true;
    }

    if (isClosed()) {
        return false;
    }

    //The fault is raised from previous handlers, in this case, we only invoke handleFault
    //if the fault is a ProtocolException
    if (fault != null) {
        if (!(fault instanceof ProtocolException)) {
            return true;
        } else if (!responseExpected && !messageDirectionReversed) {
            // According to jsr224 9.3.2.1,
            // If throw ProtocolException or a subclass:
            // No response, normal message processing stops, close is called on each previously invoked handler
            // in the chain, the exception is dispatched (see section 9.1.2.3).
            return true;
        }
    }

    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "invoking handlers, direction: " + (outbound ? "outbound" : "inbound"));
    }
    setMessageOutboundProperty(ctx);

    if (!outbound) {
        handlerChain = reverseHandlerChain(handlerChain);
    }

    boolean continueProcessing = true;
    MessageContext oldCtx = null;
    try {
        oldCtx = WebServiceContextImpl.setMessageContext(ctx);
        continueProcessing = invokeHandleFault(handlerChain, ctx);
    } finally {
        // restore the WebServiceContextImpl's ThreadLocal variable to the previous value
        if (oldCtx == null) {
            WebServiceContextImpl.clear();
        } else {
            WebServiceContextImpl.setMessageContext(oldCtx);
        }
    }

    return continueProcessing;
}
 
Example #5
Source File: JAXWSMethodInvoker.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
protected Object invoke(Exchange exchange,
                        final Object serviceObject, Method m,
                        List<Object> params) {

    // set up the webservice request context
    WrappedMessageContext ctx = new WrappedMessageContext(exchange.getInMessage(), Scope.APPLICATION);

    Map<String, Object> handlerScopedStuff = removeHandlerProperties(ctx);

    final MessageContext oldCtx = WebServiceContextImpl.setMessageContext(ctx);
    List<Object> res = null;
    try {
        if ((params == null || params.isEmpty()) && serviceObject instanceof Provider) {
            params = Collections.singletonList(null);
        }
        res = CastUtils.cast((List<?>)super.invoke(exchange, serviceObject, m, params));

        if ((serviceObject instanceof Provider)
            && MessageUtils.getContextualBoolean(exchange.getInMessage(),
                                                 "jaxws.provider.interpretNullAsOneway",
                                                 true)
            && (res != null && !res.isEmpty() && res.get(0) == null)
            && exchange.getInMessage().getInterceptorChain().getState() == InterceptorChain.State.EXECUTING) {
            // treat the non-oneway call as oneway when a provider returns null
            // and the chain is not suspended due to a continuation suspend
            res = null;
            changeToOneway(exchange);
        }
        //update the webservice response context
        updateWebServiceContext(exchange, ctx);
    } catch (Fault f) {
        //get chance to copy over customer's header
        if (MessageUtils.getContextualBoolean(exchange.getInMessage(), COPY_SOAP_HEADERS_BY_FAULT, true)) {
            updateHeader(exchange, ctx);
        }
        throw f;
    } finally {
        //restore the WebServiceContextImpl's ThreadLocal variable to the previous value
        if (oldCtx == null) {
            WebServiceContextImpl.clear();
        } else {
            WebServiceContextImpl.setMessageContext(oldCtx);
        }

        addHandlerProperties(ctx, handlerScopedStuff);
    }
    return res;
}