Search in sources :

Example 1 with Consumes

use of org.ow2.petals.component.framework.jbidescriptor.generated.Consumes in project petals-se-flowable by petalslink.

the class NormalizedMessageOutputStream method close.

@Override
public void close() throws IOException {
    super.close();
    // needed so that logs are put in the right flow instance folder
    PetalsExecutionContext.putFlowAttributes(this.flowAttributes);
    final Exchange cxfExchange = this.cxfMessage.getExchange();
    final EndpointInfo endpointInfo = cxfExchange.getEndpoint().getEndpointInfo();
    final QName interfaceName = endpointInfo.getInterface().getName();
    final QName serviceName = endpointInfo.getService().getName();
    final OperationInfo operationInfo = cxfExchange.getBindingOperationInfo().getOperationInfo();
    final QName operationName = operationInfo.getName();
    try {
        Consumes consume = this.sender.getComponent().getServiceUnitManager().getConsumesFromDestination(null, serviceName, interfaceName, operationName);
        final MEPPatternConstants mep = getMEP(operationInfo, consume);
        if (consume == null) {
            this.sender.getLogger().log(Level.WARNING, String.format("No Consumes declared in the JBI descriptor for the request to send, using informations from the process and default timeout: interface=%s, serviceName=%s, operation=%s, mep=%s", interfaceName, serviceName, operationName, mep));
            consume = new Consumes();
            // TODO: Create a unit test where the interface name is missing
            consume.setInterfaceName(interfaceName);
            // TODO: Create a unit test where the service name is missing
            consume.setServiceName(serviceName);
        } else {
            if (interfaceName != null && !consume.getInterfaceName().equals(interfaceName)) {
                this.sender.getLogger().log(Level.WARNING, "Mismatch between JBI Consumes interface name and process information (" + consume.getInterfaceName() + " vs " + interfaceName + "), using Consumes information.");
            }
            if (serviceName != null && !serviceName.equals(consume.getServiceName())) {
                this.sender.getLogger().log(Level.WARNING, "Mismatch between JBI Consumes service name and process information (" + consume.getServiceName() + " vs " + serviceName + "), using Consumes information.");
            }
        }
        // TODO: Find a way to define the endpoint name to use: maybe the address could contain it in endpointInfo?
        // TODO: Create a unit test where the endpoint name is missing
        // TODO: Create a unit test where the operation name is missing
        final org.ow2.petals.component.framework.api.message.Exchange jbiExchange = this.sender.createExchange(consume, mep, this.extFlowTracingActivated);
        // We always use the operation from the process (the JBI Consumes defines the service used, not the
        // operation)
        jbiExchange.setOperation(operationName);
        // Set timeout at CXF level. It must be upper than the timeout defined into SU JBI descriptor level)
        final long timeout = this.sender.getTimeout(consume);
        if (timeout > 0) {
            cxfExchange.getOutMessage().put(ClientImpl.SYNC_TIMEOUT, timeout + CXF_SYNC_TIMEOUT_INTERNAL_PART);
        }
        // TODO: Add support for attachments
        // TODO: MUST be optimized generating directly an XML message by CXF or Flowable
        // The buffer contains a SOAP message, we just remove the SOAP envelope
        final DocumentBuilder docBuilder = DocumentBuilders.takeDocumentBuilder();
        try {
            if (this.sender.getLogger().isLoggable(Level.FINE)) {
                this.sender.getLogger().fine("Request to send: " + new String(buf));
            }
            final Document doc = docBuilder.parse(new ByteArrayInputStream(buf));
            final NodeList soapBodies = doc.getElementsByTagNameNS("http://schemas.xmlsoap.org/soap/envelope/", "Body");
            if (soapBodies.item(0).hasChildNodes()) {
                final Node xmlPayload = soapBodies.item(0).getFirstChild();
                jbiExchange.setInMessageContent(new DOMSource(xmlPayload));
            } else {
                throw new IOException("Empty service task request");
            }
        } catch (final SAXException e) {
            throw new IOException(e);
        } finally {
            DocumentBuilders.releaseDocumentBuilder(docBuilder);
        }
        // TODO: Try to find a way to send exchange asynchronously
        if (cxfExchange.isOneWay()) {
            if (this.sender.sendSync(jbiExchange)) {
                if (jbiExchange.isErrorStatus()) {
                    // An error was returned
                    throw jbiExchange.getError();
                } else if (jbiExchange.isDoneStatus()) {
                // Status DONE returned
                } else {
                    // A fault was returned
                    final Message cxfInMessage = new MessageImpl();
                    cxfInMessage.setExchange(cxfExchange);
                    final Document faultReceived = PetalsConduit.wrapAsSoapFault(jbiExchange.getFault());
                    final EasyByteArrayOutputStream ebaos = new EasyByteArrayOutputStream();
                    DOMHelper.prettyPrint(faultReceived, ebaos);
                    if (LOG.isLoggable(Level.FINE)) {
                        LOG.fine("Fault XML payload received: " + ebaos.toString());
                    }
                    cxfInMessage.setContent(InputStream.class, ebaos.toByteArrayInputStream());
                    this.conduit.getMessageObserver().onMessage(cxfInMessage);
                    jbiExchange.setDoneStatus();
                    this.sender.send(jbiExchange);
                }
            } else {
                // A timeout occurs
                throw new MessagingException("A timeout occurs invoking service.");
            }
        } else {
            this.sender.sendAsync(jbiExchange, new PetalsFlowableAsyncContext(cxfExchange, this.asyncCallback));
        }
    } catch (final IOException e) {
        throw e;
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) DOMSource(javax.xml.transform.dom.DOMSource) Message(org.apache.cxf.message.Message) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Consumes(org.ow2.petals.component.framework.jbidescriptor.generated.Consumes) PetalsFlowableAsyncContext(org.ow2.petals.flowable.outgoing.PetalsFlowableAsyncContext) EasyByteArrayOutputStream(com.ebmwebsourcing.easycommons.stream.EasyByteArrayOutputStream) MessagingException(javax.jbi.messaging.MessagingException) QName(javax.xml.namespace.QName) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) IOException(java.io.IOException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) MessagingException(javax.jbi.messaging.MessagingException) Exchange(org.apache.cxf.message.Exchange) MessageExchange(javax.jbi.messaging.MessageExchange) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) MEPPatternConstants(org.ow2.easywsdl.wsdl.api.abstractItf.AbsItfOperation.MEPPatternConstants) MessageImpl(org.apache.cxf.message.MessageImpl)

Example 2 with Consumes

use of org.ow2.petals.component.framework.jbidescriptor.generated.Consumes in project petals-bc-gateway by petalslink.

the class ConsumerDomain method logAfterReceivingFromChannel.

@Override
protected void logAfterReceivingFromChannel(final TransportedMessage m) {
    // a new consumes ext starts here
    if (m.step == 1) {
        final FlowAttributes consumeExtStep = PetalsExecutionContext.initFlowAttributes();
        final FlowAttributes provideExtStep = m.provideExtStep;
        assert provideExtStep != null;
        // we remember the step of the consumer partner through the correlated flow attributes
        this.logMonitTrace(m, new BcGatewayConsumeExtFlowStepBeginLogData(consumeExtStep, // this is a correlated flow id
        provideExtStep, // TODO id unique inside the SU, not the component
        getId()));
    }
}
Also used : FlowAttributes(org.ow2.petals.commons.log.FlowAttributes) BcGatewayConsumeExtFlowStepBeginLogData(org.ow2.petals.bc.gateway.utils.BcGatewayConsumeExtFlowStepBeginLogData)

Example 3 with Consumes

use of org.ow2.petals.component.framework.jbidescriptor.generated.Consumes in project petals-bc-gateway by petalslink.

the class ProviderDomain method register.

/**
 * Register propagated consumes for the JBI listener, can be called after or before the component has started (i.e.,
 * {@link #connect(boolean)} has been called).
 */
public void register() throws PEtALSCDKException {
    mainLock.lock();
    try {
        for (final Entry<ServiceKey, ServiceData> e : services.entrySet()) {
            final ServiceKey sk = e.getKey();
            final ServiceData data = e.getValue();
            assert sk != null;
            assert data != null;
            registerProviderService(sk, data);
        }
        init = true;
    } catch (final PEtALSCDKException e) {
        logger.severe("Error during ProviderDomain init, undoing everything");
        for (final ServiceData data : services.values()) {
            assert data != null;
            deregisterOrStoreOrLog(data, null);
        }
        throw e;
    } finally {
        mainLock.unlock();
    }
}
Also used : ServiceKey(org.ow2.petals.bc.gateway.commons.messages.ServiceKey) PEtALSCDKException(org.ow2.petals.component.framework.api.exception.PEtALSCDKException)

Example 4 with Consumes

use of org.ow2.petals.component.framework.jbidescriptor.generated.Consumes in project petals-bc-gateway by petalslink.

the class ExchangeHelper method updateStoredExchange.

public static Exchange updateStoredExchange(@Nullable final Exchange exchange, final TransportedMessage m, final JBISender sender, final Boolean isFlowTracingActivationPropagated, final Boolean isFlowTracingActivated) throws MessagingException {
    final Exchange result;
    if (m.step == 1) {
        assert exchange == null;
        assert isFlowTracingActivationPropagated != null;
        assert isFlowTracingActivated != null;
        // this is a Consumes I propagated on the other side
        // TODO should I rely on information sent by the other side or should I keep a map somewhere for security
        // reasons?
        final ServiceKey service = m.service;
        result = sender.createExchange(service.interfaceName, service.service, service.endpointName, m.exchange.getPattern());
        setProperties(m.exchange, result.getMessageExchange());
        result.setOperation(m.exchange.getOperation());
        result.setInMessage(m.exchange.getMessage(Exchange.IN_MESSAGE_NAME));
    } else if (!m.last) {
        assert exchange != null;
        updateProperties(m.exchange, exchange.getMessageExchange());
        final NormalizedMessage out = m.exchange.getMessage(Exchange.OUT_MESSAGE_NAME);
        if (out != null && !exchange.isOutMessage()) {
            exchange.setOutMessage(out);
        } else if (m.exchange.getFault() != null && exchange.getFault() == null) {
            exchange.setFault(m.exchange.getFault());
        }
        result = exchange;
    } else {
        assert exchange != null;
        assert m.exchange.getStatus() != ExchangeStatus.ACTIVE;
        updateProperties(m.exchange, exchange.getMessageExchange());
        if (m.exchange.getStatus() == ExchangeStatus.ERROR) {
            // let's set it by hand too if the error is null
            exchange.setErrorStatus();
            exchange.setError(m.exchange.getError());
        } else if (m.exchange.getStatus() == ExchangeStatus.DONE) {
            exchange.setDoneStatus();
        }
        result = exchange;
    }
    if (isFlowTracingActivationPropagated.booleanValue()) {
        result.setProperty(Message.FLOW_TRACING_ACTIVATION_MSGEX_PROP, isFlowTracingActivated);
    } else {
        result.setProperty(Message.FLOW_TRACING_ACTIVATION_MSGEX_PROP, null);
    }
    return result;
}
Also used : Exchange(org.ow2.petals.component.framework.api.message.Exchange) MessageExchange(javax.jbi.messaging.MessageExchange) NormalizedMessage(javax.jbi.messaging.NormalizedMessage) ServiceKey(org.ow2.petals.bc.gateway.commons.messages.ServiceKey)

Example 5 with Consumes

use of org.ow2.petals.component.framework.jbidescriptor.generated.Consumes in project petals-bc-gateway by petalslink.

the class BcGatewayJbiHelper method getConsumerDomains.

private static Collection<String> getConsumerDomains(@Nullable final Consumes consumes) throws PEtALSCDKException {
    assert consumes != null;
    final Collection<JbiConsumesConfig> confs = getAll(consumes.getAny(), EL_CONSUMER, JbiConsumesConfig.class);
    if (confs.isEmpty()) {
        throw new PEtALSCDKException("Missing consumer in Consumes " + toString(consumes));
    }
    final List<String> res = new ArrayList<>();
    for (final JbiConsumesConfig conf : confs) {
        final String domain = conf.getDomain();
        assert domain != null;
        res.add(domain);
    }
    return res;
}
Also used : JbiConsumesConfig(org.ow2.petals.bc.gateway.jbidescriptor.generated.JbiConsumesConfig) ArrayList(java.util.ArrayList) PEtALSCDKException(org.ow2.petals.component.framework.api.exception.PEtALSCDKException)

Aggregations

Consumes (org.ow2.petals.component.framework.jbidescriptor.generated.Consumes)7 PEtALSCDKException (org.ow2.petals.component.framework.api.exception.PEtALSCDKException)6 ServiceKey (org.ow2.petals.bc.gateway.commons.messages.ServiceKey)5 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 JbiConsumerDomain (org.ow2.petals.bc.gateway.jbidescriptor.generated.JbiConsumerDomain)3 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 MessageExchange (javax.jbi.messaging.MessageExchange)2 QName (javax.xml.namespace.QName)2 InvalidMessage (org.ow2.petals.InvalidMessage)2 TransportedDocument (org.ow2.petals.bc.gateway.commons.messages.TransportedDocument)2 ConsumerDomain (org.ow2.petals.bc.gateway.inbound.ConsumerDomain)2 Provides (org.ow2.petals.component.framework.jbidescriptor.generated.Provides)2 Message (org.ow2.petals.component.framework.junit.Message)2 RequestMessage (org.ow2.petals.component.framework.junit.RequestMessage)2 ResponseMessage (org.ow2.petals.component.framework.junit.ResponseMessage)2 StatusMessage (org.ow2.petals.component.framework.junit.StatusMessage)2