Package org.apache.ode.bpel.iapi

Examples of org.apache.ode.bpel.iapi.PartnerRoleMessageExchange


   
    return executionEnvironment.getScheduler().execTransaction(new Callable<Object>(){

      public Object call() throws Exception {
        //We need to get a new mex from persistence layer.
        PartnerRoleMessageExchange mex = (PartnerRoleMessageExchange) engine.getBpelServer().getEngine().getMessageExchange(mexId);
            try
            {
              // Create SOAPMessage
              SOAPMessage soapRequestMessage = MessageFactory.newInstance().createMessage();
              if(log.isDebugEnabled())
                log.debug( "ODE outbound message: \n" +DOMWriter.printNode(mex.getRequest().getMessage(), true) );
             
              String soapAction=messageAdapter.createSoapRequest(soapRequestMessage,
                      new ODEMessageAdapter(mex.getRequest()), mex.getOperation());
             
              if (log.isDebugEnabled()) {
                log.debug("Riftsaw soap request message: \n" + JavaUtils.getSoapMessageASString(soapRequestMessage));
              }
             
              org.apache.ode.bpel.iapi.EndpointReference odeepr=mex.getEndpointReference();
              javax.xml.ws.EndpointReference epr=null;
             
              if (odeepr != null) {
                if (odeepr instanceof org.apache.ode.bpel.epr.URLEndpoint) {
                  org.apache.ode.bpel.epr.URLEndpoint url=(org.apache.ode.bpel.epr.URLEndpoint)odeepr;
                 
                  javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder builder=
                        new javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder();
                 
                  epr = builder.address(url.getUrl())
                          .serviceName(serviceName)
                          .endpointName(port)
                          .build();
                 
                  if (log.isDebugEnabled()) {
                    log.debug("EPR = " + epr);
                  }
                }
               
              } else if (log.isDebugEnabled()) {
                log.debug("ODE has no EPR for this message exchange");
              }
             
              // The actual WS invocation
              Dispatch<SOAPMessage> proxy = getDispatcher(epr, port);
              setEndpointFromUDDI(proxy);
             
              try {
                // Set SOAPAction
                if (soapAction != null) {
                  // Setting soap action using both approaches, as CXF needs one and JBossWS-Native the other
                  proxy.getRequestContext().put(Dispatch.SOAPACTION_URI_PROPERTY, soapAction);
                  MimeHeaders hd = soapRequestMessage.getMimeHeaders();
                  hd.addHeader("SOAPAction", soapAction);
                } else if (log.isDebugEnabled()) {
                  log.debug("SOAPAction not set");
                }

                // Set client side timeout for the invocation
                proxy.getRequestContext().put("javax.xml.ws.client.receiveTimeout", Long.toString(timeout));
               
                  SOAPMessage soapResponseMessage = proxy.invoke(soapRequestMessage);

                  if (log.isDebugEnabled()) {
                    log.debug("Riftsaw soap response message: \n" + JavaUtils.getSoapMessageASString(soapResponseMessage));
                  }
                 
                  // Create ODE response
                  Message odeResponse = mex.createMessage(mex.getOperation().getOutput().getMessage().getQName());
                  if(soapResponseMessage.getSOAPBody().hasFault())
                  {
                    // fault handling
                    Document odeMsg = DOMUtils.newDocument();
                    Element odeMsgEl = odeMsg.createElementNS(null, "message");
                    odeMsg.appendChild(odeMsgEl);
                   
                    Fault fault = messageAdapter.parseSoapFault(odeMsgEl, soapResponseMessage, mex.getOperation());

                    handleFault(mex, fault, soapResponseMessage.getSOAPBody().getFault(), odeMsgEl);
                   
                  }
                  else
                  {
                    messageAdapter.parseSoapResponse(new ODEMessageAdapter(odeResponse),
                            soapResponseMessage,mex.getOperation());
                    mex.reply(odeResponse);
                  }

                  if(log.isDebugEnabled())
                    log.debug( "ODE inbound message: \n" +DOMWriter.printNode(odeResponse.getMessage(), true) );
                 
              } catch(javax.xml.ws.soap.SOAPFaultException fe) {
               
                    // fault handling
                    Document odeMsg = DOMUtils.newDocument();
                    Element odeMsgEl = odeMsg.createElementNS(null, "message");
                    odeMsg.appendChild(odeMsgEl);
                   
                  if (log.isDebugEnabled()) {
                    log.debug("Riftsaw soap fault: \n" + DOMWriter.printNode(fe.getFault(), true));
                  }
                 
                    Fault fault=messageAdapter.parseSoapFault(odeMsgEl, fe.getFault(),
                                mex.getOperation());

                    handleFault(mex, fault, fe.getFault(), odeMsgEl);
              }
            }
            catch (Throwable e)
            {
              log.error("WS invocation failed", e);
              mex.replyWithFailure(MessageExchange.FailureType.COMMUNICATION_ERROR, e.getMessage(), null);
            }
            return null;
      }
           
    });
View Full Code Here


  public Object call() throws Exception {
    return executionEnvironment.getScheduler().execTransaction(new Callable<Object>(){

      public Object call() throws Exception {
        //We need to get a new mex from persistence layer.
        PartnerRoleMessageExchange mex = (PartnerRoleMessageExchange) engine.getBpelServer().getEngine().getMessageExchange(mexId);
                try
                {
                  // Create SOAPMessage
                  SOAPMessage soapRequestMessage = MessageFactory.newInstance().createMessage();
                  if(log.isDebugEnabled())
                    log.debug( "ODE outbound message: \n" +DOMWriter.printNode(mex.getRequest().getMessage(), true) );
                 
              String soapAction=messageAdapter.createSoapRequest(soapRequestMessage,
                          new ODEMessageAdapter(mex.getRequest()), mex.getOperation());

                  if (log.isDebugEnabled()) {
                    log.debug("Riftsaw soap request message: \n" + JavaUtils.getSoapMessageASString(soapRequestMessage));
                  }
                 
                org.apache.ode.bpel.iapi.EndpointReference odeepr=mex.getEndpointReference();
                javax.xml.ws.EndpointReference epr=null;
               
                if (odeepr != null) {
                  if (odeepr instanceof org.apache.ode.bpel.epr.URLEndpoint) {
                    org.apache.ode.bpel.epr.URLEndpoint url=(org.apache.ode.bpel.epr.URLEndpoint)odeepr;
                   
                    javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder builder=
                          new javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder();
                   
                    epr = builder.address(url.getUrl())
                            .serviceName(serviceName)
                            .endpointName(port)
                            .build();
                   
                    if (log.isDebugEnabled()) {
                      log.debug("EPR = " + epr);
                    }
                  }
                 
                } else if (log.isDebugEnabled()) {
                  log.debug("ODE has no EPR for this message exchange");
                }
               
                  // The actual WS invocation
                  Dispatch<SOAPMessage> proxy = getDispatcher(epr, port);
                  setEndpointFromUDDI(proxy);
                 
                  // Set SOAPAction
                  if (soapAction != null) {
                    // Setting soap action using both approaches, as CXF needs one and JBossWS-Native the other
                    proxy.getRequestContext().put(Dispatch.SOAPACTION_URI_PROPERTY, soapAction);
                    MimeHeaders hd = soapRequestMessage.getMimeHeaders();
                    hd.addHeader("SOAPAction", soapAction);
                  } else if (log.isDebugEnabled()) {
                    log.debug("SOAPAction not set");
                  }
                 
                  proxy.invokeOneWay(soapRequestMessage);

                }
                catch (Throwable e)
                {
                  log.error("WS invocation failed", e);
                  mex.replyWithFailure(MessageExchange.FailureType.COMMUNICATION_ERROR, e.getMessage(), null);
                }

                return null;
      }     
     
View Full Code Here

            mex.setStatus(MessageExchange.Status.RESPONSE.toString());
            evt.setAspect(ProcessMessageExchangeEvent.PROCESS_OUTPUT);
        }

        if (mex.getPipedMessageExchangeId() != null) {
            PartnerRoleMessageExchange pmex = (PartnerRoleMessageExchange) _bpelProcess
                    .getEngine().getMessageExchange(mex.getPipedMessageExchangeId());
            if (BpelProcess.__log.isDebugEnabled()) {
                __log.debug("Replying to a p2p mex, myrole " + m + " - partnerole " + pmex);
            }
            try {
                switch (m.getStatus()) {
                    case FAILURE:
                        // We can't seem to get the failure out of the myrole mex?
                        pmex.replyWithFailure(MessageExchange.FailureType.OTHER, "operation failed", null);
                        break;
                    case FAULT:
                        Message faultRes = pmex.createMessage(pmex.getOperation().getFault(m.getFault().getLocalPart())
                                .getMessage().getQName());
                        faultRes.setMessage(m.getResponse().getMessage());
                        pmex.replyWithFault(m.getFault(), faultRes);
                        break;
                    case RESPONSE:
                        Message response = pmex.createMessage(pmex.getOperation().getOutput().getMessage().getQName());
                        response.setMessage(m.getResponse().getMessage());
                        pmex.reply(response);
                        break;
                    default:
                        __log.warn("Unexpected state: " + m.getStatus());
                        break;
                }
View Full Code Here

            final Element details) {
        // ODE MEX needs to be invoked in a TX.
        try {
            _sched.execIsolatedTransaction(new Callable<Void>() {
                public Void call() throws Exception {
                    PartnerRoleMessageExchange odeMex = (PartnerRoleMessageExchange_server.getEngine().getMessageExchange(odeMexId);
                    odeMex.replyWithFailure(error, errmsg, details);
                    return null;
                }
            });

        } catch (Exception e) {
View Full Code Here

        // ODE MEX needs to be invoked in a TX.
        try {
            _sched.execIsolatedTransaction(new Callable<Void>() {
                public Void call() throws Exception {
                    PartnerRoleMessageExchange odeMex = (PartnerRoleMessageExchange_server.getEngine().getMessageExchange(odeMexId);
                    Message response = fault ? odeMex.createMessage(odeMex.getOperation().getFault(
                            faultType.getLocalPart()).getMessage().getQName()) : odeMex.createMessage(odeMex
                            .getOperation().getOutput().getMessage().getQName());
                    try {
                        if (__log.isDebugEnabled()) {
                            __log.debug("Received response for MEX " + odeMex);
                        }
                        response.setMessage(odeMsgEl);
                        if (fault) {
                            if (faultType != null) {
                                if (__log.isDebugEnabled()) {
                                    __log.debug("FAULT RESPONSE(" + faultType + "): " + DOMUtils.domToString(odeMsgEl));
                                }
                                odeMex.replyWithFault(faultType, response);
                            } else {
                                if (__log.isDebugEnabled()) {
                                    __log.debug("FAULT RESPONSE(unknown fault type): " + DOMUtils.domToString(odeMsgEl));
                                }
                                odeMex.replyWithFailure(FailureType.OTHER, reply.getEnvelope().getBody()
                                        .getFault().getText(), null);
                            }
                        } else {
                            if (__log.isDebugEnabled()) {
                                __log.debug("RESPONSE (NORMAL): " + DOMUtils.domToString(odeMsgEl));
                            }
                            odeMex.reply(response);

                        }
                    } catch (Exception ex) {
                        String errmsg = "Unable to process response: " + ex.getMessage();
                        __log.error(errmsg, ex);
                        odeMex.replyWithFailure(FailureType.OTHER, errmsg, null);
                    }
                    return null;
                }
            });
View Full Code Here

            Object[] inouts = _mexTimeouts.keySet().toArray();
            for (int i=0; i<inouts.length; i++) {
                long timeout = _mexTimeouts.get(inouts[i]);
                if (timeout >= now) {
                    _mexTimeouts.remove(inouts[i]);
                    final PartnerRoleMessageExchange pmex = _outstandingExchanges.remove(inouts[i]);

                    if (pmex == null) /* no worries, got a response. */
                        continue;

                    __log.warn("Timeout on JBI message exchange " + inouts[i]);
        try {
            _ode._scheduler.execIsolatedTransaction(new Callable<Void>() {
                public Void call() throws Exception {
                    pmex.replyWithFailure(FailureType.NO_RESPONSE, "Response not received after " + _responseTimeout + "ms.", null);
                    return null;
                }
            });
        } catch (Exception ex) {
            __log.error("Error executing transaction:  ", ex);
View Full Code Here

            mex.setStatus(MessageExchange.Status.RESPONSE.toString());
            evt.setAspect(ProcessMessageExchangeEvent.PROCESS_OUTPUT);
        }

        if (mex.getPipedMessageExchangeId() != null) {
            PartnerRoleMessageExchange pmex = (PartnerRoleMessageExchange) _bpelProcess
                    .getEngine().getMessageExchange(mex.getPipedMessageExchangeId());
            if (BpelProcess.__log.isDebugEnabled()) {
                __log.debug("Replying to a p2p mex, myrole " + m + " - partnerole " + pmex);
            }
            try {
                switch (m.getStatus()) {
                    case FAILURE:
                        // We can't seem to get the failure out of the myrole mex?
                        pmex.replyWithFailure(MessageExchange.FailureType.OTHER, "operation failed", null);
                        break;
                    case FAULT:
                        Message faultRes = pmex.createMessage(pmex.getOperation().getFault(m.getFault().getLocalPart())
                                .getMessage().getQName());
                        faultRes.setMessage(m.getResponse().getMessage());
                        pmex.replyWithFault(m.getFault(), faultRes);
                        break;
                    case RESPONSE:
                        Message response = pmex.createMessage(pmex.getOperation().getOutput().getMessage().getQName());
                        response.setMessage(m.getResponse().getMessage());
                        pmex.reply(response);
                        break;
                    default:
                        __log.warn("Unexpected state: " + m.getStatus());
                        break;
                }
View Full Code Here

            } catch (final IOException e) {
                // ODE MEX needs to be invoked in a TX.
                try {
                    scheduler.execIsolatedTransaction(new Callable<Void>() {
                        public Void call() throws Exception {
                            PartnerRoleMessageExchange odeMex = (PartnerRoleMessageExchange) server.getEngine().getMessageExchange(mexId);                           
                            String errmsg = "Unable to execute http request : " + e.getMessage();
                            log.error(errmsg, e);
                            odeMex.replyWithFailure(MessageExchange.FailureType.COMMUNICATION_ERROR, errmsg, null);
                            return null;
                        }
                    });
                } catch (Exception e1) {
                    String errmsg = "Error executing reply transaction; reply will be lost.";
View Full Code Here

                log.error(errmsg, e);
            }
        }

        private void unmanagedStatus() throws IOException {
            PartnerRoleMessageExchange odeMex = (PartnerRoleMessageExchange) server.getEngine().getMessageExchange(mexId);
            String errmsg = "Unmanaged Status Code! " + method.getStatusLine();
            log.error(errmsg);
            odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg, HttpClientHelper.prepareDetailsElement(method));
        }
View Full Code Here

         * @throws IOException
         */
        private void _5xx_serverError() throws IOException {
            String errmsg = "Internal Server Error! " + method.getStatusLine();
            log.error(errmsg);
            PartnerRoleMessageExchange odeMex = (PartnerRoleMessageExchange) server.getEngine().getMessageExchange(mexId);
            Operation opDef = odeMex.getOperation();
            BindingOperation opBinding = portBinding.getBindingOperation(opDef.getName(), opDef.getInput().getName(), opDef.getOutput().getName());
            if (opDef.getFaults().isEmpty()) {
                errmsg = "Operation has no fault. This 500 error will be considered as a failure.";
                if (log.isDebugEnabled()) log.debug(errmsg);
                odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg, HttpClientHelper.prepareDetailsElement(method));
            } else if (opBinding.getBindingFaults().isEmpty()) {
                errmsg = "No fault binding. This 500 error will be considered as a failure.";
                if (log.isDebugEnabled()) log.debug(errmsg);
                odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg, HttpClientHelper.prepareDetailsElement(method));
            } else if (method.getResponseBodyAsStream() == null) {
                errmsg = "No body in the response. This 500 error will be considered as a failure.";
                if (log.isDebugEnabled()) log.debug(errmsg);
                odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg, HttpClientHelper.prepareDetailsElement(method));
            } else {
                final InputStream bodyAsStream = method.getResponseBodyAsStream();
                try {
                    Element bodyEl = DOMUtils.parse(bodyAsStream).getDocumentElement();
                    QName bodyName = new QName(bodyEl.getNamespaceURI(), bodyEl.getNodeName());
                    Fault faultDef = WsdlUtils.inferFault(opDef, bodyName);

                    // is this fault bound with ODE extension?
                    if (!WsdlUtils.isOdeFault(opBinding.getBindingFault(faultDef.getName()))) {
                        errmsg = "Fault " + bodyName + " is not bound with " + new QName(Namespaces.ODE_HTTP_EXTENSION_NS, "fault") + ". This 500 error will be considered as a failure.";
                        if (log.isDebugEnabled()) log.debug(errmsg);
                        odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg, HttpClientHelper.prepareDetailsElement(method));
                    } else {
                        Part partDef = (Part) faultDef.getMessage().getParts().values().iterator().next();

                        // build the element to be sent back
                        Document odeMsg = DOMUtils.newDocument();
                        Element odeMsgEl = odeMsg.createElementNS(null, "message");
                        Element partEl = odeMsgEl.getOwnerDocument().createElementNS(null, partDef.getName());
                        odeMsgEl.appendChild(partEl);
                        // import the response body
                        partEl.appendChild(odeMsgEl.getOwnerDocument().importNode(bodyEl, true));

                        QName faultType = new QName(targetNamespace, faultDef.getName());
                        Message response = odeMex.createMessage(faultType);
                        response.setMessage(odeMsgEl);

                        // extract and set headers
                         httpMethodConverter.extractHttpResponseHeaders(response, method, faultDef.getMessage(), opBinding.getBindingOutput());

                        // finally send the fault. We did it!
                        odeMex.replyWithFault(faultType, response);
                    }
                } catch (Exception e) {
                    errmsg = "Unable to parse the response body as xml. This 500 error will be considered as a failure.";
                    if (log.isDebugEnabled()) log.debug(errmsg, e);
                    odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg, HttpClientHelper.prepareDetailsElement(method, false));
                }
            }

        }
View Full Code Here

TOP

Related Classes of org.apache.ode.bpel.iapi.PartnerRoleMessageExchange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.