Search in sources :

Example 11 with Endpoint

use of org.apache.cxf.endpoint.Endpoint in project tomee by apache.

the class CxfRsHttpListener method newFactory.

private JAXRSServerFactoryBean newFactory(final String prefix, final String service, final String endpoint) {
    final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean() {

        @Override
        protected Endpoint createEndpoint() throws BusException, EndpointException {
            final Endpoint created = super.createEndpoint();
            created.put(ManagedEndpoint.SERVICE_NAME, service);
            created.put(ManagedEndpoint.ENDPOINT_NAME, endpoint);
            return created;
        }
    };
    factory.setDestinationFactory(transportFactory);
    factory.setBus(CxfUtil.getBus());
    factory.setAddress(prefix);
    return factory;
}
Also used : ManagedEndpoint(org.apache.cxf.endpoint.ManagedEndpoint) Endpoint(org.apache.cxf.endpoint.Endpoint) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean)

Example 12 with Endpoint

use of org.apache.cxf.endpoint.Endpoint in project camel by apache.

the class DefaultCxfBinding method populateCxfResponseFromExchange.

/**
     * This method is called by {@link CxfConsumer} to populate a CXF response exchange 
     * from a Camel exchange.
     */
public void populateCxfResponseFromExchange(Exchange camelExchange, org.apache.cxf.message.Exchange cxfExchange) {
    if (cxfExchange.isOneWay()) {
        return;
    }
    // create response context
    Map<String, Object> responseContext = new HashMap<String, Object>();
    org.apache.camel.Message response;
    if (camelExchange.getPattern().isOutCapable()) {
        if (camelExchange.hasOut()) {
            response = camelExchange.getOut();
            LOG.trace("Get the response from the out message");
        } else {
            // Take the in message as a fall back
            response = camelExchange.getIn();
            LOG.trace("Get the response from the in message as a fallback");
        }
    } else {
        response = camelExchange.getIn();
        LOG.trace("Get the response from the in message");
    }
    // propagate response context
    Map<String, Object> camelHeaders = response.getHeaders();
    extractInvocationContextFromCamel(camelExchange, camelHeaders, responseContext, Client.RESPONSE_CONTEXT);
    propagateHeadersFromCamelToCxf(camelExchange, camelHeaders, cxfExchange, responseContext);
    // create out message
    Endpoint ep = cxfExchange.get(Endpoint.class);
    Message outMessage = ep.getBinding().createMessage();
    cxfExchange.setOutMessage(outMessage);
    DataFormat dataFormat = camelExchange.getProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.class);
    // make sure the "requestor role" property does not get propagated as we do switch role
    responseContext.remove(Message.REQUESTOR_ROLE);
    outMessage.putAll(responseContext);
    // Do we still need to put the response context back like this
    outMessage.put(Client.RESPONSE_CONTEXT, responseContext);
    LOG.trace("Set out response context = {}", responseContext);
    // set body
    Object outBody = DefaultCxfBinding.getBodyFromCamel(response, dataFormat);
    if (outBody != null) {
        if (dataFormat == DataFormat.PAYLOAD) {
            CxfPayload<?> payload = (CxfPayload<?>) outBody;
            outMessage.setContent(List.class, getResponsePayloadList(cxfExchange, payload.getBodySources()));
            outMessage.put(Header.HEADER_LIST, payload.getHeaders());
        } else {
            if (responseContext.get(Header.HEADER_LIST) != null) {
                outMessage.put(Header.HEADER_LIST, responseContext.get(Header.HEADER_LIST));
            }
            MessageContentsList resList = null;
            // Create a new MessageContentsList to avoid OOM from the HolderOutInterceptor
            if (outBody instanceof List) {
                resList = new MessageContentsList((List<?>) outBody);
            } else if (outBody.getClass().isArray()) {
                resList = new MessageContentsList((Object[]) outBody);
            } else {
                resList = new MessageContentsList(outBody);
            }
            if (resList != null) {
                outMessage.setContent(List.class, resList);
                LOG.trace("Set Out CXF message content = {}", resList);
            }
        }
    } else if (!cxfExchange.isOneWay() && cxfExchange.getInMessage() != null && MessageUtils.isTrue(cxfExchange.getInMessage().getContextualProperty("jaxws.provider.interpretNullAsOneway"))) {
        // treat this non-oneway call as oneway when the provider returns a null
        changeToOneway(cxfExchange);
        return;
    }
    // propagate attachments
    Set<Attachment> attachments = null;
    boolean isXop = Boolean.valueOf(camelExchange.getProperty(Message.MTOM_ENABLED, String.class));
    for (Map.Entry<String, org.apache.camel.Attachment> entry : camelExchange.getOut().getAttachmentObjects().entrySet()) {
        if (attachments == null) {
            attachments = new HashSet<Attachment>();
        }
        AttachmentImpl attachment = new AttachmentImpl(entry.getKey());
        org.apache.camel.Attachment camelAttachment = entry.getValue();
        attachment.setDataHandler(camelAttachment.getDataHandler());
        for (String name : camelAttachment.getHeaderNames()) {
            attachment.setHeader(name, camelAttachment.getHeader(name));
        }
        attachment.setXOP(isXop);
        attachments.add(attachment);
    }
    if (attachments != null) {
        outMessage.setAttachments(attachments);
    }
    BindingOperationInfo boi = cxfExchange.get(BindingOperationInfo.class);
    if (boi != null) {
        cxfExchange.put(BindingMessageInfo.class, boi.getOutput());
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.message.Message) MessageContentsList(org.apache.cxf.message.MessageContentsList) HashMap(java.util.HashMap) DefaultAttachment(org.apache.camel.impl.DefaultAttachment) Attachment(org.apache.cxf.message.Attachment) Endpoint(org.apache.cxf.endpoint.Endpoint) MessageContentsList(org.apache.cxf.message.MessageContentsList) List(java.util.List) ArrayList(java.util.ArrayList) AttachmentImpl(org.apache.cxf.attachment.AttachmentImpl) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) TreeMap(java.util.TreeMap)

Example 13 with Endpoint

use of org.apache.cxf.endpoint.Endpoint in project tomee by apache.

the class CalculatorTest method testCalculatorViaWsInterfaceWithTimestamp2ways.

public void testCalculatorViaWsInterfaceWithTimestamp2ways() throws Exception {
    final Service calcService = Service.create(new URL("http://localhost:" + port + "/webservice-ws-security/CalculatorImplTimestamp2ways?wsdl"), new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
    assertNotNull(calcService);
    // for debugging (ie. TCPMon)
    calcService.addPort(new QName("http://superbiz.org/wsdl", "CalculatorWsService2"), SOAPBinding.SOAP12HTTP_BINDING, "http://127.0.0.1:8204/CalculatorImplTimestamp2ways");
    //        CalculatorWs calc = calcService.getPort(
    //        	new QName("http://superbiz.org/wsdl", "CalculatorWsService2"),
    //		CalculatorWs.class);
    final CalculatorWs calc = calcService.getPort(CalculatorWs.class);
    final Client client = ClientProxy.getClient(calc);
    final Endpoint endpoint = client.getEndpoint();
    endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
    endpoint.getInInterceptors().add(new SAAJInInterceptor());
    final Map<String, Object> outProps = new HashMap<String, Object>();
    outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);
    final WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
    endpoint.getOutInterceptors().add(wssOut);
    final Map<String, Object> inProps = new HashMap<String, Object>();
    inProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);
    final WSS4JInInterceptor wssIn = new WSS4JInInterceptor(inProps);
    endpoint.getInInterceptors().add(wssIn);
    assertEquals(12, calc.multiply(3, 4));
}
Also used : SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) Endpoint(org.apache.cxf.endpoint.Endpoint) WSS4JInInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Client(org.apache.cxf.endpoint.Client)

Example 14 with Endpoint

use of org.apache.cxf.endpoint.Endpoint in project tomee by apache.

the class CalculatorTest method testCalculatorViaWsInterfaceWithUsernameTokenPlainPasswordEncrypt.

public void testCalculatorViaWsInterfaceWithUsernameTokenPlainPasswordEncrypt() throws Exception {
    final Service calcService = Service.create(new URL("http://localhost:" + port + "/webservice-ws-security/CalculatorImplUsernameTokenPlainPasswordEncrypt?wsdl"), new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
    assertNotNull(calcService);
    // for debugging (ie. TCPMon)
    calcService.addPort(new QName("http://superbiz.org/wsdl", "CalculatorWsService2"), SOAPBinding.SOAP12HTTP_BINDING, "http://127.0.0.1:8204/CalculatorImplUsernameTokenPlainPasswordEncrypt");
    //        CalculatorWs calc = calcService.getPort(
    //        	new QName("http://superbiz.org/wsdl", "CalculatorWsService2"),
    //        	CalculatorWs.class);
    final CalculatorWs calc = calcService.getPort(CalculatorWs.class);
    final Client client = ClientProxy.getClient(calc);
    final Endpoint endpoint = client.getEndpoint();
    endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
    final Map<String, Object> outProps = new HashMap<String, Object>();
    outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN + " " + WSHandlerConstants.ENCRYPT);
    outProps.put(WSHandlerConstants.USER, "jane");
    outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    outProps.put(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler() {

        @Override
        public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            final WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
            pc.setPassword("waterfall");
        }
    });
    outProps.put(WSHandlerConstants.ENC_PROP_FILE, "META-INF/CalculatorImplUsernameTokenPlainPasswordEncrypt-client.properties");
    outProps.put(WSHandlerConstants.ENCRYPTION_USER, "serveralias");
    final WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
    endpoint.getOutInterceptors().add(wssOut);
    assertEquals(10, calc.sum(4, 6));
}
Also used : SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) CallbackHandler(javax.security.auth.callback.CallbackHandler) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) IOException(java.io.IOException) URL(java.net.URL) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) Callback(javax.security.auth.callback.Callback) Endpoint(org.apache.cxf.endpoint.Endpoint) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Client(org.apache.cxf.endpoint.Client) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback)

Example 15 with Endpoint

use of org.apache.cxf.endpoint.Endpoint in project tomee by apache.

the class EjbInterceptor method intercept.

@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
    Endpoint endpoint = this.exchange.get(Endpoint.class);
    Service service = endpoint.getService();
    Binding binding = ((JaxWsEndpointImpl) endpoint).getJaxwsBinding();
    this.exchange.put(InvocationContext.class, context);
    if (binding.getHandlerChain() == null || binding.getHandlerChain().isEmpty()) {
        // no handlers so let's just directly invoke the bean
        log.debug("No handlers found.");
        EjbMethodInvoker invoker = (EjbMethodInvoker) service.getInvoker();
        return invoker.directEjbInvoke(this.exchange, this.method, this.params);
    } else {
        // have handlers so have to run handlers now and redo data binding
        // as handlers can change the soap message
        log.debug("Handlers found.");
        Message inMessage = exchange.getInMessage();
        PhaseInterceptorChain chain = new PhaseInterceptorChain(bus.getExtension(PhaseManager.class).getInPhases());
        chain.setFaultObserver(endpoint.getOutFaultObserver());
        /*
             * Since we have to re-do data binding and the XMLStreamReader
             * contents are already consumed by prior data binding step
             * we have to reinitialize the XMLStreamReader from the SOAPMessage
             * created by SAAJInInterceptor.
             */
        if (inMessage instanceof SoapMessage) {
            try {
                reserialize((SoapMessage) inMessage);
            } catch (Exception e) {
                throw new ServerRuntimeException("Failed to reserialize soap message", e);
            }
        } else {
        // TODO: how to handle XML/HTTP binding?
        }
        this.exchange.setOutMessage(null);
        // install default interceptors
        chain.add(new ServiceInvokerInterceptor());
        //chain.add(new OutgoingChainInterceptor()); // it is already in the enclosing chain, if we add it there we are in the tx so we write the message in the tx!
        // See http://cwiki.apache.org/CXF20DOC/interceptors.html
        // install Holder and Wrapper interceptors
        chain.add(new WrapperClassInInterceptor());
        chain.add(new HolderInInterceptor());
        // install interceptors for handler processing
        chain.add(new MustUnderstandInterceptor());
        chain.add(new LogicalHandlerInInterceptor(binding));
        chain.add(new SOAPHandlerInterceptor(binding));
        // install data binding interceptors - todo: check we need it
        copyDataBindingInterceptors(chain, inMessage.getInterceptorChain());
        InterceptorChain oldChain = inMessage.getInterceptorChain();
        inMessage.setInterceptorChain(chain);
        try {
            chain.doIntercept(inMessage);
        } finally {
            inMessage.setInterceptorChain(oldChain);
        }
        // TODO: the result should be deserialized from SOAPMessage
        Object result = getResult();
        return result;
    }
}
Also used : Binding(javax.xml.ws.Binding) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SOAPMessage(javax.xml.soap.SOAPMessage) HolderInInterceptor(org.apache.cxf.jaxws.interceptors.HolderInInterceptor) SOAPHandlerInterceptor(org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) Service(org.apache.cxf.service.Service) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Endpoint(org.apache.cxf.endpoint.Endpoint) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) LogicalHandlerInInterceptor(org.apache.cxf.jaxws.handler.logical.LogicalHandlerInInterceptor) ServiceInvokerInterceptor(org.apache.cxf.interceptor.ServiceInvokerInterceptor) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) WrapperClassInInterceptor(org.apache.cxf.jaxws.interceptors.WrapperClassInInterceptor) AroundInvoke(javax.interceptor.AroundInvoke)

Aggregations

Endpoint (org.apache.cxf.endpoint.Endpoint)17 HashMap (java.util.HashMap)8 Client (org.apache.cxf.endpoint.Client)8 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)8 URL (java.net.URL)7 QName (javax.xml.namespace.QName)7 Service (javax.xml.ws.Service)7 SAAJOutInterceptor (org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor)7 Message (org.apache.cxf.message.Message)6 IOException (java.io.IOException)5 Callback (javax.security.auth.callback.Callback)5 CallbackHandler (javax.security.auth.callback.CallbackHandler)5 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)5 WSPasswordCallback (org.apache.wss4j.common.ext.WSPasswordCallback)4 MessageImpl (org.apache.cxf.message.MessageImpl)3 List (java.util.List)2 SAAJInInterceptor (org.apache.cxf.binding.soap.saaj.SAAJInInterceptor)2 OutgoingChainInterceptor (org.apache.cxf.interceptor.OutgoingChainInterceptor)2 Attachment (org.apache.cxf.message.Attachment)2 ClientPasswordHandler (com.evolveum.midpoint.cli.ninja.util.ClientPasswordHandler)1