Пример #1
1
 public static OMElement serializeHandlerConfiguration(HandlerConfigurationBean bean) {
   OMFactory factory = OMAbstractFactory.getOMFactory();
   OMElement handler = factory.createOMElement("handler", null);
   handler.addAttribute(factory.createOMAttribute("class", null, bean.getHandlerClass()));
   if (bean.getTenant() != null) {
     handler.addAttribute(factory.createOMAttribute("tenant", null, bean.getTenant()));
   }
   StringBuilder sb = new StringBuilder();
   for (String method : bean.getMethods()) {
     if (method != null && method.length() > 0) {
       sb.append(method).append(",");
     }
   }
   // Remove last ","
   if (sb.length() > 0) {
     sb.deleteCharAt(sb.length() - 1);
     handler.addAttribute(factory.createOMAttribute("methods", null, sb.toString()));
   }
   for (String property : bean.getPropertyList()) {
     OMElement temp = factory.createOMElement("property", null);
     temp.addAttribute(factory.createOMAttribute("name", null, property));
     OMElement xmlProperty = bean.getXmlProperties().get(property);
     if (xmlProperty != null) {
       //                The serialization happens by adding the whole XML property value to the
       // bean.
       //                Therefore if it is a XML property, we take that whole element.
       handler.addChild(xmlProperty);
     } else {
       String nonXMLProperty = bean.getNonXmlProperties().get(property);
       if (nonXMLProperty != null) {
         temp.setText(nonXMLProperty);
         handler.addChild(temp);
       }
     }
   }
   OMElement filter = factory.createOMElement("filter", null);
   filter.addAttribute(
       factory.createOMAttribute("class", null, bean.getFilter().getFilterClass()));
   for (String property : bean.getFilter().getPropertyList()) {
     OMElement temp = factory.createOMElement("property", null);
     temp.addAttribute(factory.createOMAttribute("name", null, property));
     OMElement xmlProperty = bean.getFilter().getXmlProperties().get(property);
     if (xmlProperty != null) {
       temp.addAttribute(factory.createOMAttribute("type", null, "xml"));
       temp.addChild(xmlProperty);
       filter.addChild(temp);
     } else {
       String nonXMLProperty = bean.getFilter().getNonXmlProperties().get(property);
       if (nonXMLProperty != null) {
         temp.setText(nonXMLProperty);
         filter.addChild(temp);
       }
     }
   }
   handler.addChild(filter);
   return handler;
 }
Пример #2
0
 public OMElement buildXML() {
   OMFactory fac = OMAbstractFactory.getOMFactory();
   OMElement confEl = fac.createOMElement("config", null);
   if (this.getId() != null) {
     confEl.addAttribute("id", this.getId(), null);
   }
   /* build properties */
   Iterator<Property> iterator = this.getProperties().iterator();
   while (iterator.hasNext()) {
     Property property = iterator.next();
     if (this.isUseSecretAliasForPassword()
         && (property.getName().equals(RDBMS.PASSWORD)
             || property.getName().equals(RDBMS_OLD.PASSWORD)
             || property.getName().equals(GSpread.PASSWORD)
             || property.getName().equals(JNDI.PASSWORD))) {
       OMFactory factory = OMAbstractFactory.getOMFactory();
       OMElement propEl = factory.createOMElement("property", null);
       propEl.addAttribute("name", property.getName(), null);
       propEl.addAttribute("svns:secretAlias", (String) property.getValue(), null);
       confEl.addChild(propEl);
     } else {
       if (property.buildXML() != null) {
         confEl.addChild(property.buildXML());
       }
     }
   }
   return confEl;
 }
 @Override
 public void setSoapVersion(SoapVersion version) {
   if (SoapVersion.SOAP_11 == version) {
     soapFactory = OMAbstractFactory.getSOAP11Factory();
   } else if (SoapVersion.SOAP_12 == version) {
     soapFactory = OMAbstractFactory.getSOAP12Factory();
   } else {
     throw new IllegalArgumentException(
         "Invalid version [" + version + "]. " + "Expected the SOAP_11 or SOAP_12 constant");
   }
 }
Пример #4
0
  public static SynapseMessageContext createLightweightSynapseMessageContext(String payload)
      throws Exception {
    MessageContext mc = new OldMessageContext();
    SynapseConfiguration config = new SynapseConfiguration();
    SynapseEnvironment env = new Axis2SynapseEnvironment(config);
    SynapseMessageContext synMc = Axis2SynapseMessageContextImpl.newInstance(mc, config, env);
    SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
    OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
    omDoc.addChild(envelope);

    envelope.getBody().addChild(createOMElement(payload));

    synMc.setEnvelope(envelope);
    return synMc;
  }
  private SOAPEnvelope buildSoapEnvelope(String clientID, String value) {

    String targetEPR = "http://localhost:9000/soap/Service1";
    String opration = "sampleOperation";

    SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();

    OMNamespace wsaNamespace =
        soapFactory.createOMNamespace("http://www.w3.org/2005/08/addressing", "wsa");

    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();

    SOAPHeader header = soapFactory.createSOAPHeader();
    envelope.addChild(header);

    OMNamespace synNamespace =
        soapFactory.createOMNamespace("http://ws.apache.org/ns/synapse", "syn");
    OMElement clientIDElement = soapFactory.createOMElement("ClientID", synNamespace);
    clientIDElement.setText(clientID);
    header.addChild(clientIDElement);

    SOAPBody body = soapFactory.createSOAPBody();
    envelope.addChild(body);

    OMElement valueElement = soapFactory.createOMElement("Value", null);
    valueElement.setText(value);
    body.addChild(valueElement);

    return envelope;
  }
Пример #6
0
 public static OMElement queryToOM(Query query) {
   OMFactory factory = OMAbstractFactory.getOMFactory();
   OMElement queryChild =
       factory.createOMElement(
           new QName(
               CEPConstants.CEP_CONF_NAMESPACE,
               CEPConstants.CEP_CONF_ELE_QUERY,
               CEPConstants.CEP_CONF_CEP_NAME_SPACE_PREFIX));
   Expression queryExpression = query.getExpression();
   String queryName = query.getName();
   OMElement queryIP = null;
   List<String> ipList = query.getIpList();
   for (String ip : ipList) {
     queryIP = factory.createOMElement(new QName(CEPConstants.CEP_CONF_QUERY_IP));
     queryIP.setText(ip);
     queryChild.addChild(queryIP);
   }
   queryChild.addAttribute(CEPConstants.CEP_CONF_ATTR_NAME, queryName, null);
   OMElement omQueryExpression = ExpressionHelper.expressionToOM(queryExpression);
   queryChild.addChild(omQueryExpression);
   if (query.getOutput() != null) {
     OMElement queryOutput = OutputHelper.outputToOM(query.getOutput());
     queryChild.addChild(queryOutput);
   }
   return queryChild;
 }
Пример #7
0
 /** Creates OMElement using error details. */
 public static OMElement createDSFaultOM(String msg) {
   OMFactory fac = OMAbstractFactory.getOMFactory();
   OMElement ele =
       fac.createOMElement(new QName(DBConstants.WSO2_DS_NAMESPACE, DBConstants.DS_FAULT_ELEMENT));
   ele.setText(msg);
   return ele;
 }
Пример #8
0
  public static OMElement getOMElement(SOAPEnvelope response) {
    XMLStreamReader parser = response.getXMLStreamReader();

    StAXOMBuilder builder = new StAXOMBuilder(OMAbstractFactory.getOMFactory(), parser);

    return builder.getDocumentElement();
  }
  /**
   * Retrieve all entries from service.
   *
   * @return All entries of type Entry from the service.
   * @exception FailureFaultException If an error communication with the service occurs.
   */
  public Entry[] retrieve() throws FailureFaultException {
    final String method = "retrieve";
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace namespace = factory.createOMNamespace(SERVICE, method);

    // Create a request
    OMElement request = factory.createOMElement("RetrieveRequest", namespace);

    // Configure connection
    Options options = new Options();
    options.setTo(new EndpointReference(url.toString()));
    options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
    options.setAction(method);

    // Create a client
    try {
      ServiceClient client = new ServiceClient();
      client.setOptions(options);

      // Try send request and receive response, could throw AxisFault
      OMElement response = client.sendReceive(request);

      // Debug
      printDebug("RESPONSE", response);

      // Parse and return result
      Entry[] result = XMLUtil.parseScores(response);
      return result;
    } catch (AxisFault e) {
      throw new FailureFaultException("Exception from service: ", e);
    }
  }
Пример #10
0
  public static OMFactory getOMFactory() {
    if (reuse) return OMAbstractFactory.getOMFactory();
    String omFactory;
    try {
      omFactory = System.getProperty(OM_FACTORY_NAME_PROPERTY);
      if (omFactory == null || "".equals(omFactory)) {
        omFactory = DEFAULT_OM_FACTORY_CLASS_NAME;
      }
    } catch (SecurityException e) {
      omFactory = DEFAULT_OM_FACTORY_CLASS_NAME;
    }

    OMFactory defaultOMFactory;
    try {
      defaultOMFactory =
          (OMFactory) ClassLoader.getSystemClassLoader().loadClass(omFactory).newInstance();
    } catch (InstantiationException e) {
      throw new OMException(e);
    } catch (IllegalAccessException e) {
      throw new OMException(e);
    } catch (ClassNotFoundException e) {
      throw new OMException(e);
    }
    return defaultOMFactory;
  }
Пример #11
0
  private OMElement getRSTTemplate() throws TrustException {
    OMFactory omFac = OMAbstractFactory.getOMFactory();
    OMElement element = omFac.createOMElement(SP11Constants.REQUEST_SECURITY_TOKEN_TEMPLATE);

    if (ClientConstants.SAML_TOKEN_TYPE_20.equals(tokenType)) {
      TrustUtil.createTokenTypeElement(RahasConstants.VERSION_05_02, element)
          .setText(RahasConstants.TOK_TYPE_SAML_20);
    } else if (ClientConstants.SAML_TOKEN_TYPE_11.equals(tokenType)) {
      TrustUtil.createTokenTypeElement(RahasConstants.VERSION_05_02, element)
          .setText(RahasConstants.TOK_TYPE_SAML_10);
    }

    if (ClientConstants.SUBJECT_CONFIRMATION_BEARER.equals(subjectConfirmationMethod)) {
      TrustUtil.createKeyTypeElement(
          RahasConstants.VERSION_05_02, element, RahasConstants.KEY_TYPE_BEARER);
    } else if (ClientConstants.SUBJECT_CONFIRMATION_HOLDER_OF_KEY.equals(
        subjectConfirmationMethod)) {
      TrustUtil.createKeyTypeElement(
          RahasConstants.VERSION_05_02, element, RahasConstants.KEY_TYPE_SYMM_KEY);
    }

    // request claims in the token.
    OMElement claimElement =
        TrustUtil.createClaims(RahasConstants.VERSION_05_02, element, claimDialect);
    // Populate the <Claims/> element with the <ClaimType/> elements
    addClaimType(claimElement, claimUris);

    return element;
  }
Пример #12
0
  private static boolean JARServiceTest() {
    boolean JARServiceStatus = false;
    OMElement result;
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://ws.apache.org/axis2", "ns1");
    OMElement payload = fac.createOMElement("echo", omNs);
    OMElement value = fac.createOMElement("args0", omNs);
    value.addChild(fac.createOMText(value, "Hello-World"));
    payload.addChild(value);

    ServiceClient serviceclient;
    try {
      serviceclient = new ServiceClient();
      Options opts = new Options();

      opts.setTo(new EndpointReference(HTTP_APPSERVER_STRATOSLIVE_URL + "/SimpleJarService"));
      opts.setAction("echo");
      // bypass http protocol exception
      opts.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);

      serviceclient.setOptions(opts);

      result = serviceclient.sendReceive(payload);

      if ((result.toString().indexOf("Hello-World")) > 0) {
        JARServiceStatus = true;
      }
      assertTrue("Jar service invocation failed", JARServiceStatus);

    } catch (AxisFault axisFault) {
      log.error("Jar service invocation failed:" + axisFault.getMessage());
      fail("Jar service invocation failed:" + axisFault.getMessage());
    }
    return JARServiceStatus;
  }
  private OMElement createRequestPayload() {
    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
    OMNamespace omNs = fac.createOMNamespace("http://services.samples", "ns");
    OMElement top = fac.createOMElement("getQuotes", omNs);

    for (int i = 0; i < 3; i++) {
      OMElement method = fac.createOMElement("getQuote", omNs);
      OMElement value1 = fac.createOMElement("request", omNs);
      OMElement value2 = fac.createOMElement("symbol", omNs);
      value2.addChild(fac.createOMText(value1, "WSO2"));
      value1.addChild(value2);
      method.addChild(value1);
      top.addChild(method);
    }

    for (int i = 0; i < 3; i++) {
      OMElement method = fac.createOMElement("dummy", omNs);
      OMElement value1 = fac.createOMElement("request", omNs);
      OMElement value2 = fac.createOMElement("symbol", omNs);
      value2.addChild(fac.createOMText(value1, "WSO2"));
      value1.addChild(value2);
      method.addChild(value1);
      top.addChild(method);
    }

    return top;
  }
  public void sendUsingMTOM(String fileName, String targetEPR) throws IOException {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
    OMElement payload = factory.createOMElement("uploadFileUsingMTOM", ns);
    OMElement request = factory.createOMElement("request", ns);
    OMElement image = factory.createOMElement("image", ns);

    FileDataSource fileDataSource = new FileDataSource(new File(fileName));
    DataHandler dataHandler = new DataHandler(fileDataSource);
    OMText textData = factory.createOMText(dataHandler, true);
    image.addChild(textData);
    request.addChild(image);
    payload.addChild(request);

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(targetEPR));
    options.setAction("urn:uploadFileUsingMTOM");
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
    options.setCallTransportCleanup(true);
    serviceClient.setOptions(options);
    OMElement response = serviceClient.sendReceive(payload);
    Assert.assertTrue(
        response
            .toString()
            .contains(
                "<m:testMTOM xmlns:m=\"http://services.samples/xsd\">"
                    + "<m:test1>testMTOM</m:test1></m:testMTOM>"));
  }
Пример #15
0
 public static boolean generateHandler(Registry configSystemRegistry, String resourceFullPath)
     throws RegistryException, XMLStreamException {
   RegistryContext registryContext = configSystemRegistry.getRegistryContext();
   if (registryContext == null) {
     return false;
   }
   Resource resource = configSystemRegistry.get(resourceFullPath);
   if (resource != null) {
     String content = null;
     if (resource.getContent() != null) {
       content = RegistryUtils.decodeBytes((byte[]) resource.getContent());
     }
     if (content != null) {
       OMElement handler = AXIOMUtil.stringToOM(content);
       if (handler != null) {
         OMElement dummy = OMAbstractFactory.getOMFactory().createOMElement("dummy", null);
         dummy.addChild(handler);
         try {
           configSystemRegistry.beginTransaction();
           boolean status =
               RegistryConfigurationProcessor.updateHandler(
                   dummy,
                   configSystemRegistry.getRegistryContext(),
                   HandlerLifecycleManager.USER_DEFINED_HANDLER_PHASE);
           configSystemRegistry.commitTransaction();
           return status;
         } catch (Exception e) {
           configSystemRegistry.rollbackTransaction();
           throw new RegistryException("Unable to add handler", e);
         }
       }
     }
   }
   return false;
 }
Пример #16
0
  /**
   * 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);
    }
  }
  Namespace(String namespace, String prefix) {
    this.setNamespace(namespace);
    this.setPrefix(prefix);

    SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
    OMNamespace = factory.createOMNamespace(namespace, prefix);
  }
Пример #18
0
/** Serializer for {@link org.apache.synapse.mediators.Value} instances. */
public class ValueSerializer {
  protected static final OMFactory fac = OMAbstractFactory.getOMFactory();
  protected static final OMNamespace nullNS =
      fac.createOMNamespace(XMLConfigConstants.NULL_NAMESPACE, "");

  /**
   * Serialize the Value object to an OMElement representing the entry
   *
   * @param key Value to serialize
   * @param elem OMElement
   * @return OMElement
   */
  public OMElement serializeValue(Value key, String name, OMElement elem) {
    if (key != null) {
      if (key.getExpression() == null) {
        // static key
        elem.addAttribute(fac.createOMAttribute(name, nullNS, key.getKeyValue()));
      } else {
        String startChar = "{", endChar = "}";
        // if this is an expr type key we add an additional opening and closing brace
        if (key.hasExprTypeKey()) {
          startChar = startChar + "{";
          endChar = endChar + "}";
        }
        // dynamic key
        SynapsePathSerializer.serializePath(
            key.getExpression(), startChar + key.getExpression().toString() + endChar, elem, name);
      }
    }
    return elem;
  }

  /**
   * Serialize the Value object to an OMElement representing the entry
   *
   * @param key Value to serialize
   * @param elem OMElement
   * @return OMElement
   */
  public OMElement serializeTextValue(Value key, String name, OMElement elem) {
    if (key != null) {
      if (key.getExpression() == null) {
        // static key
        elem.setText(key.getKeyValue());
      } else {
        String startChar = "{", endChar = "}";
        // if this is an expr type key we add an additional opening and
        // closing brace
        if (key.hasExprTypeKey()) {
          startChar = startChar + "{";
          endChar = endChar + "}";
        }
        // dynamic key
        SynapsePathSerializer.serializeTextPath(
            key.getExpression(), startChar + key.getExpression().toString() + endChar, elem, name);
      }
    }
    return elem;
  }
}
Пример #19
0
  @Override
  public void connect(MessageContext messageContext) throws ConnectException {
    String providerUrl = LDAPUtils.lookupContextParams(messageContext, LDAPConstants.PROVIDER_URL);
    String dn = (String) getParameter(messageContext, "dn");
    String password = (String) getParameter(messageContext, "password");

    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace(LDAPConstants.CONNECTOR_NAMESPACE, "ns");
    OMElement result = factory.createOMElement("result", ns);
    OMElement message = factory.createOMElement("message", ns);

    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, providerUrl);
    env.put(Context.SECURITY_PRINCIPAL, dn);
    env.put(Context.SECURITY_CREDENTIALS, password);

    org.apache.axis2.context.MessageContext axis2MessageContext =
        ((Axis2MessageContext) messageContext).getAxis2MessageContext();

    boolean logged = false;
    DirContext ctx = null;
    try {
      ctx = new InitialDirContext(env);
      message.setText("Success");
      result.addChild(message);
      LDAPUtils.preparePayload(messageContext, result);
    } catch (NamingException e) {
      message.setText("Fail");
      result.addChild(message);
      LDAPUtils.preparePayload(messageContext, result);
    }
  }
  private OMElement handleSLORequest(MessageContext messageContext, LogoutRequest logoutRequest) {

    // Get the session index from the SLORequest and remove the relevant session.
    String sessionIndex = logoutRequest.getSessionIndexes().get(0).getSessionIndex();

    String sessionId = CacheManager.getInstance().getSessionIndexMappingCache().get(sessionIndex);

    if (sessionId != null) {
      GatewayUtils.logWithRequestInfo(
          log,
          messageContext,
          String.format(
              "Found a session id (md5 : '%s')for the given session index in the SLO request: '%s'. Clearing the session",
              GatewayUtils.getMD5Hash(sessionId), sessionIndex));
      SessionStore.getInstance().removeSession(sessionId);
      CacheManager.getInstance().getSessionIndexMappingCache().remove(sessionIndex);
    } else {
      GatewayUtils.logWithRequestInfo(
          log,
          messageContext,
          String.format(
              "Couldn't find a session id for the given session index : '%s'", sessionIndex));
    }

    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace ns = fac.createOMNamespace("http://wso2.org/appm", "appm");
    OMElement payload = fac.createOMElement("SLOResponse", ns);

    OMElement errorMessage = fac.createOMElement("message", ns);
    errorMessage.setText("SLORequest has been successfully processed by WSO2 App Manager");

    payload.addChild(errorMessage);

    return payload;
  }
Пример #21
0
  public OMElement toOM() {

    OMFactory omFactory = OMAbstractFactory.getOMFactory();

    OMElement targetElement =
        omFactory.createOMElement(
            Constants.RULE_CONF_ELE_TARGET,
            Constants.RULE_CONF_NAMESPACE,
            Constants.RULE_CONF_NAMESPACE_PREFIX);
    if (this.xpath != null) {
      targetElement.addAttribute(Constants.RULE_CONF_ATTR_XPATH, this.xpath, null);
    }

    if (this.resultXpath != null) {
      targetElement.addAttribute(Constants.RULE_CONF_ATTR_RESULT_XPATH, this.resultXpath, null);
    }

    if (this.action != null) {
      targetElement.addAttribute(Constants.RULE_CONF_ATTR_ACTION, this.action, null);
    }

    if (this.value != null) {
      targetElement.setText(this.value);
    }

    if (this.prefixToNamespaceMap != null) {

      for (String prefix : this.prefixToNamespaceMap.keySet()) {

        String nsURI = this.prefixToNamespaceMap.get(prefix);
        targetElement.declareNamespace(nsURI, prefix);
      }
    }
    return targetElement;
  }
Пример #22
0
 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);
     }
   }
 }
Пример #23
0
  public static String sendSOAP(
      EndpointReference soapEPR, String requestString, String action, String operation)
      throws Exception {

    ServiceClient sender = PmServiceClient.getServiceClient();
    OperationClient operationClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);

    // creating message context
    MessageContext outMsgCtx = new MessageContext();
    // assigning message context's option object into instance variable
    Options opts = outMsgCtx.getOptions();
    // setting properties into option
    log.debug(soapEPR);
    opts.setTo(soapEPR);
    opts.setAction(action);
    opts.setTimeOutInMilliSeconds(180000);

    log.debug(requestString);

    SOAPEnvelope envelope = null;

    try {
      SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
      envelope = fac.getDefaultEnvelope();
      OMNamespace omNs =
          fac.createOMNamespace(
              "http://rpdr.partners.org/", //$NON-NLS-1$
              "rpdr"); //$NON-NLS-1$

      // creating the SOAP payload
      OMElement method = fac.createOMElement(operation, omNs);
      OMElement value = fac.createOMElement("RequestXmlString", omNs); // $NON-NLS-1$
      value.setText(requestString);
      method.addChild(value);
      envelope.getBody().addChild(method);
    } catch (FactoryConfigurationError e) {
      log.error(e.getMessage());
      throw new Exception(e);
    }

    outMsgCtx.setEnvelope(envelope);

    operationClient.addMessageContext(outMsgCtx);
    operationClient.execute(true);

    MessageContext inMsgtCtx = operationClient.getMessageContext("In"); // $NON-NLS-1$
    SOAPEnvelope responseEnv = inMsgtCtx.getEnvelope();

    OMElement soapResponse = responseEnv.getBody().getFirstElement();
    //		System.out.println("Sresponse: "+ soapResponse.toString());
    OMElement soapResult = soapResponse.getFirstElement();
    //		System.out.println("Sresult: "+ soapResult.toString());

    String i2b2Response = soapResult.getText();
    log.debug(i2b2Response);

    return i2b2Response;
  }
Пример #24
0
 private OMElement createCustomQuoteRequest(String symbol) {
   OMFactory factory = OMAbstractFactory.getOMFactory();
   OMNamespace ns = factory.createOMNamespace("http://services.samples", "ns");
   OMElement chkPrice = factory.createOMElement("CheckPriceRequest", ns);
   OMElement code = factory.createOMElement("Code", ns);
   chkPrice.addChild(code);
   code.setText(symbol);
   return chkPrice;
 }
Пример #25
0
 private static OMElement createPayLoad() {
   OMFactory fac = OMAbstractFactory.getOMFactory();
   OMNamespace omNs = fac.createOMNamespace("http://service.carbon.wso2.org", "ns1");
   OMElement method = fac.createOMElement("echoString", omNs);
   OMElement value = fac.createOMElement("s", omNs);
   value.addChild(fac.createOMText(value, "Hello World"));
   method.addChild(value);
   return method;
 }
Пример #26
0
 /** @deprecated Not used anywhere */
 public void init(InputStream inputStream, String charSetEncoding, String url, String contentType)
     throws OMException {
   try {
     this.parser = StAXUtils.createXMLStreamReader(inputStream);
   } catch (XMLStreamException e1) {
     throw new OMException(e1);
   }
   omfactory = OMAbstractFactory.getOMFactory();
 }
 private OMElement getTextElement(String content) {
   OMFactory factory = OMAbstractFactory.getOMFactory();
   OMElement textElement = factory.createOMElement(TEXT_ELEMENT);
   if (content == null) {
     content = "";
   }
   textElement.setText(content);
   return textElement;
 }
Пример #28
0
  /** This will be invoked by the schedular to inject the message in to the SynapseEnvironment */
  public void execute() {
    log.debug("execute");
    if (synapseEnvironment == null) {
      log.error("Synapse Environment not set");
      return;
    }
    if (message == null) {
      log.error("message not set");
      return;
    }
    if (to == null) {
      log.error("to address not set");
      return;
    }

    MessageContext mc = synapseEnvironment.createMessageContext();
    //        AspectHelper.setGlobalAudit(mc);    TODO
    mc.pushFaultHandler(new MediatorFaultHandler(mc.getFaultSequence()));
    mc.setTo(new EndpointReference(to));
    if (format == null) {
      PayloadHelper.setXMLPayload(mc, message.cloneOMElement());
    } else {
      try {
        if (SOAP11_FORMAT.equalsIgnoreCase(format)) {
          mc.setEnvelope(OMAbstractFactory.getSOAP11Factory().createSOAPEnvelope());
        } else if (SOAP12_FORMAT.equalsIgnoreCase(format)) {
          mc.setEnvelope(OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope());
        } else if (POX_FORMAT.equalsIgnoreCase(format)) {
          mc.setDoingPOX(true);
        } else if (GET_FORMAT.equalsIgnoreCase(format)) {
          mc.setDoingGET(true);
        }
        PayloadHelper.setXMLPayload(mc, message.cloneOMElement());
      } catch (AxisFault axisFault) {
        String msg = "Error in setting the message payload : " + message;
        log.error(msg, axisFault);
        throw new SynapseException(msg, axisFault);
      }
    }
    if (soapAction != null) {
      mc.setSoapAction(soapAction);
    }
    synapseEnvironment.injectMessage(mc);
  }
  private org.apache.axiom.om.OMElement toOM(com.pa.GetEmpResponse param, boolean optimizeContent)
      throws org.apache.axis2.AxisFault {

    try {
      return param.getOMElement(
          com.pa.GetEmpResponse.MY_QNAME, org.apache.axiom.om.OMAbstractFactory.getOMFactory());
    } catch (org.apache.axis2.databinding.ADBException e) {
      throw org.apache.axis2.AxisFault.makeFault(e);
    }
  }
Пример #30
0
 private static OMElement getRSTTemplate() throws Exception {
   OMFactory fac = OMAbstractFactory.getOMFactory();
   OMElement elem = fac.createOMElement(SP11Constants.REQUEST_SECURITY_TOKEN_TEMPLATE);
   TrustUtil.createTokenTypeElement(RahasConstants.VERSION_05_02, elem)
       .setText(RahasConstants.TOK_TYPE_SAML_10);
   TrustUtil.createKeyTypeElement(
       RahasConstants.VERSION_05_02, elem, RahasConstants.KEY_TYPE_SYMM_KEY);
   TrustUtil.createKeySizeElement(RahasConstants.VERSION_05_02, elem, 256);
   return elem;
 }