public void addIds(
     String strOperation, String strParamName, MessageContext synCtx, SynapseLog synLog) {
   SOAPEnvelope envelope = synCtx.getEnvelope();
   OMFactory fac = OMAbstractFactory.getOMFactory();
   SOAPBody body = envelope.getBody();
   Iterator<OMElement> bodyChildElements = body.getChildrenWithLocalName(strOperation);
   if (bodyChildElements.hasNext()) {
     try {
       OMElement bodyElement = bodyChildElements.next();
       Iterator<OMElement> cElements = bodyElement.getChildElements();
       if (cElements != null && cElements.hasNext()) {
         cElements.next();
       }
       String strSobject = (String) ConnectorUtils.lookupTemplateParamater(synCtx, strParamName);
       OMElement sObjects = AXIOMUtil.stringToOM(strSobject);
       Iterator<OMElement> sObject = sObjects.getChildElements();
       OMNamespace omNsurn = fac.createOMNamespace("urn:partner.soap.sforce.com", "urn");
       // Loops sObject
       while (sObject.hasNext()) {
         OMElement currentElement = sObject.next();
         OMElement newElement = fac.createOMElement("ids", omNsurn);
         // Add the fields
         newElement.addChild(fac.createOMText(currentElement.getText()));
         bodyElement.addChild(newElement);
       }
     } catch (Exception e) {
       synLog.error("Saleforce adaptor - error injecting sObjects to payload : " + e);
     }
   }
 }
  /**
   * Modify request body before sending to the end point.
   *
   * @param messageContext MessageContext - The message context.
   * @throws ConnectException if connection is failed.
   */
  @SuppressWarnings("unchecked")
  public void connect(MessageContext messageContext) throws ConnectException {

    SOAPEnvelope envelope = messageContext.getEnvelope();
    SOAPBody body = envelope.getBody();
    Iterator<OMElement> nameValueListElements = body.getChildrenWithLocalName(SEARCH_BY_MODULE_TAG);

    try {

      OMElement nameValueListElement = nameValueListElements.next();
      Iterator<OMElement> omElementIterator =
          nameValueListElement.getChildrenWithLocalName(MODULES_TAG);

      if (omElementIterator.hasNext()) {
        OMFactory omFactory = OMAbstractFactory.getOMFactory();
        OMElement item = omElementIterator.next();
        String moduleListString =
            (String) ConnectorUtils.lookupTemplateParamater(messageContext, MODULES_TAG);
        SugarCRMUtil.getItemElement(omFactory, messageContext, item, moduleListString);
      }

    } catch (Exception e) {
      log.error(SugarCRMUtil.EXCEPTION + SugarCRMUtil.getStackTraceAsString(e));
      throw new ConnectException(e);
    }
  }
  public void connect(MessageContext messageContext) throws ConnectException {
    SynapseLog log = getLog(messageContext);
    log.auditLog("Start: create account");
    String friendlyName =
        (String)
            ConnectorUtils.lookupTemplateParamater(messageContext, TwilioUtil.PARAM_FRIENDLY_NAME);

    // Build a filter for the AccountList
    Map<String, String> params = new HashMap<String, String>();

    // If a friendly name has been provided for the account;
    // if not will use the current date and time (Default by Twilio).
    if (friendlyName != null) {
      params.put(TwilioUtil.TWILIO_FRIENDLY_NAME, friendlyName);
    }

    try {
      TwilioRestClient twilioRestClient = TwilioUtil.getTwilioRestClient(messageContext);

      AccountFactory accountFactory = twilioRestClient.getAccountFactory();
      Account account = accountFactory.create(params);

      OMElement omResponse = TwilioUtil.parseResponse("account.create.success");
      TwilioUtil.addElement(omResponse, TwilioUtil.TWILIO_ACCOUNT_SID, account.getSid());
      TwilioUtil.preparePayload(messageContext, omResponse);
    } catch (Exception e) {
      log.error(e.getMessage());
      TwilioUtil.handleException(e, "0001", messageContext);
      throw new SynapseException(e);
    }
    log.auditLog("End: create account");
  }
  public void addSobjects(
      String strOperation,
      String strParamName,
      MessageContext synCtx,
      SynapseLog synLog,
      String strExternalId) {
    SOAPEnvelope envelope = synCtx.getEnvelope();
    OMFactory fac = OMAbstractFactory.getOMFactory();
    SOAPBody body = envelope.getBody();
    Iterator<OMElement> bodyChildElements = body.getChildrenWithLocalName(strOperation);
    if (bodyChildElements.hasNext()) {
      try {
        OMElement bodyElement = bodyChildElements.next();
        if (strExternalId != null) {
          OMNamespace omNs = fac.createOMNamespace("urn:partner.soap.sforce.com", "urn");
          OMElement value = fac.createOMElement("externalIDFieldName", omNs);
          value.addChild(fac.createOMText(strExternalId));
          bodyElement.addChild(value);
        }
        String strSobject = (String) ConnectorUtils.lookupTemplateParamater(synCtx, strParamName);
        OMElement sObjects = AXIOMUtil.stringToOM(strSobject);
        Iterator<OMElement> sObject = sObjects.getChildElements();
        String strType =
            sObjects.getAttributeValue(new QName(SalesforceUtil.SALESFORCE_CREATE_SOBJECTTYPE));
        OMElement tmpElement = null;
        OMNamespace omNsurn = fac.createOMNamespace("urn:partner.soap.sforce.com", "urn");
        OMNamespace omNsurn1 = fac.createOMNamespace("urn:sobject.partner.soap.sforce.com", "urn1");
        // Loops sObject
        while (sObject.hasNext()) {
          OMElement currentElement = sObject.next();
          OMElement newElement = fac.createOMElement("sObjects", omNsurn);
          // Add Object type
          if (strType != null) {
            tmpElement = fac.createOMElement("type", omNsurn1);
            tmpElement.addChild(fac.createOMText(strType));
            newElement.addChild(tmpElement);
          }
          // Add the fields
          Iterator<OMElement> sObjectFields = currentElement.getChildElements();
          while (sObjectFields.hasNext()) {
            OMElement sObjectField = sObjectFields.next();
            tmpElement = fac.createOMElement(sObjectField.getLocalName(), omNsurn1);
            tmpElement.addChild(fac.createOMText(sObjectField.getText()));
            newElement.addChild(tmpElement);
          }

          bodyElement.addChild(newElement);
        }
      } catch (Exception e) {
        synLog.error("Saleforce adaptor - error injecting sObjects to payload : " + e);
      }
    }
  }
Beispiel #5
0
  public void connect(MessageContext messageContext) throws ConnectException {
    SynapseLog log = getLog(messageContext);
    log.auditLog("Start: get member");

    String queueSid =
        (String) ConnectorUtils.lookupTemplateParamater(messageContext, TwilioUtil.PARAM_QUEUE_SID);
    String callSid =
        (String) ConnectorUtils.lookupTemplateParamater(messageContext, TwilioUtil.PARAM_CALL_SID);

    try {
      TwilioRestClient twilioRestClient = TwilioUtil.getTwilioRestClient(messageContext);
      TwilioRestResponse response =
          twilioRestClient.request(
              TwilioUtil.API_URL
                  + "/"
                  + TwilioUtil.API_VERSION
                  + "/"
                  + TwilioUtil.API_ACCOUNTS
                  + "/"
                  + twilioRestClient.getAccountSid()
                  + "/"
                  + TwilioUtil.API_QUEUES
                  + "/"
                  + queueSid
                  + "/"
                  + TwilioUtil.API_MEMBERS
                  + "/"
                  + callSid,
              "GET",
              null);

      OMElement omResponse = TwilioUtil.parseResponse(response);
      TwilioUtil.preparePayload(messageContext, omResponse);
    } catch (Exception e) {
      log.error(e);
      throw new SynapseException(e);
    }
    log.auditLog("End: get member");
  }