Пример #1
0
  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");
  }