Beispiel #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;
 }
  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;
  }
  @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);
    }
  }
  public void doGet(HttpServletRequest req, HttpServletResponse res) {
    res.setContentType("application/download-xml-file");

    String messageId = req.getParameter("message");

    OMElement report = null;

    try {
      Message m = new Message(messageId);
      m.readMessage();

      report = buildReport(m);

    } catch (LoggerException e) {
      report = omFactory.createOMElement(new QName("NoReportAvailable"));
      report.setText(e.getMessage().replaceAll("<", "&lt;"));
    } catch (ServletException e) {
      report = omFactory.createOMElement(new QName("NoReportAvailable"));
      report.setText(e.getMessage().replaceAll("<", "&lt;"));
    }

    try {
      res.getWriter().write(report.toString());
    } catch (IOException e) {
    }
  }
  /**
   * Contains the logic to create URITemplate XML Element from the swagger 2.0 resource.
   *
   * @param swaggerDocObject swagger document
   * @return URITemplate element.
   */
  private static List<OMElement> createURITemplateFromSwagger2(JsonObject swaggerDocObject) {

    List<OMElement> uriTemplates = new ArrayList<>();

    JsonObject paths = swaggerDocObject.get(SwaggerConstants.PATHS).getAsJsonObject();
    Set<Map.Entry<String, JsonElement>> pathSet = paths.entrySet();

    for (Map.Entry path : pathSet) {
      JsonObject urlPattern = ((JsonElement) path.getValue()).getAsJsonObject();
      String pathText = path.getKey().toString();
      Set<Map.Entry<String, JsonElement>> operationSet = urlPattern.entrySet();

      for (Map.Entry operationEntry : operationSet) {
        OMElement uriTemplateElement = factory.createOMElement(URI_TEMPLATE, namespace);
        OMElement urlPatternElement = factory.createOMElement(URL_PATTERN, namespace);
        OMElement httpVerbElement = factory.createOMElement(HTTP_VERB, namespace);
        OMElement authTypeElement = factory.createOMElement(AUTH_TYPE, namespace);

        urlPatternElement.setText(pathText);
        httpVerbElement.setText(operationEntry.getKey().toString());

        uriTemplateElement.addChild(urlPatternElement);
        uriTemplateElement.addChild(httpVerbElement);
        uriTemplateElement.addChild(authTypeElement);
        uriTemplates.add(uriTemplateElement);
      }
    }
    return uriTemplates;
  }
  private void increaseSearchIndexStartTimeDelay() throws Exception {
    FileOutputStream fileOutputStream = null;
    XMLStreamWriter writer = null;
    OMElement documentElement = getRegistryXmlOmElement();
    try {
      AXIOMXPath xpathExpression =
          new AXIOMXPath("/wso2registry/indexingConfiguration/startingDelayInSeconds");
      OMElement indexConfigNode = (OMElement) xpathExpression.selectSingleNode(documentElement);
      indexConfigNode.setText("2");

      AXIOMXPath xpathExpression1 =
          new AXIOMXPath("/wso2registry/indexingConfiguration/indexingFrequencyInSeconds");
      OMElement indexConfigNode1 = (OMElement) xpathExpression1.selectSingleNode(documentElement);
      indexConfigNode1.setText("1");

      fileOutputStream = new FileOutputStream(getRegistryXMLPath());
      writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream);
      documentElement.serialize(writer);
      documentElement.build();
      Thread.sleep(2000);

    } catch (Exception e) {
      log.error("registry.xml edit fails" + e.getMessage());
      throw new Exception("registry.xml edit fails" + e.getMessage());
    } finally {
      assert fileOutputStream != null;
      fileOutputStream.close();
      assert writer != null;
      writer.flush();
    }
  }
  public static void transferFile(File file, String destinationFile) throws Exception {

    Options options = new Options();
    options.setTo(targetEPR);
    options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE);
    options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
    // Increase the time out when sending large attachments
    options.setTimeOutInMilliSeconds(10000);
    options.setTo(targetEPR);
    options.setAction("urn:uploadFile");

    // assume the use runs this sample at
    // <axis2home>/samples/soapwithattachments/ dir
    ConfigurationContext configContext =
        ConfigurationContextFactory.createConfigurationContextFromFileSystem(
            "../../repository", null);

    ServiceClient sender = new ServiceClient(configContext, null);
    sender.setOptions(options);
    OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);

    MessageContext mc = new MessageContext();
    FileDataSource fileDataSource = new FileDataSource(file);

    // Create a dataHandler using the fileDataSource. Any implementation of
    // javax.activation.DataSource interface can fit here.
    DataHandler dataHandler = new DataHandler(fileDataSource);
    String attachmentID = mc.addAttachment(dataHandler);

    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope env = fac.getDefaultEnvelope();
    OMNamespace omNs = fac.createOMNamespace("http://service.soapwithattachments.sample", "swa");
    OMElement uploadFile = fac.createOMElement("uploadFile", omNs);
    OMElement nameEle = fac.createOMElement("name", omNs);
    nameEle.setText(destinationFile);
    OMElement idEle = fac.createOMElement("attchmentID", omNs);
    idEle.setText(attachmentID);
    uploadFile.addChild(nameEle);
    uploadFile.addChild(idEle);
    env.getBody().addChild(uploadFile);
    mc.setEnvelope(env);

    mepClient.addMessageContext(mc);
    mepClient.execute(true);
    MessageContext response = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
    SOAPBody body = response.getEnvelope().getBody();
    OMElement element =
        body.getFirstElement()
            .getFirstChildWithName(
                new QName("http://service.soapwithattachments.sample", "return"));
    System.out.println(element.getText());
  }
 private static void addPropertyElements(
     OMFactory factory,
     OMElement parent,
     String className,
     String description,
     Map<String, String> properties) {
   if (className != null) {
     parent.addAttribute(UserCoreConstants.RealmConfig.ATTR_NAME_CLASS, className, null);
   }
   if (description != null) {
     parent.addAttribute(UserCoreConstants.RealmConfig.CLASS_DESCRIPTION, description, null);
   }
   Iterator<Map.Entry<String, String>> ite = properties.entrySet().iterator();
   while (ite.hasNext()) {
     Map.Entry<String, String> entry = ite.next();
     String name = entry.getKey();
     String value = entry.getValue();
     OMElement propElem =
         factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_PROPERTY));
     OMAttribute propAttr =
         factory.createOMAttribute(UserCoreConstants.RealmConfig.ATTR_NAME_PROP_NAME, null, name);
     propElem.addAttribute(propAttr);
     propElem.setText(value);
     parent.addChild(propElem);
   }
 }
  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;
  }
Beispiel #10
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;
 }
Beispiel #11
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;
  }
Beispiel #12
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;
 }
  OMElement buildReport(Message m) throws ServletException {
    if (!verifyTables(m)) {
      throw new ServletException("Missing Table");
    }

    System.out.println(index(m));

    HashMap<String, HashMap<String, Object>> mm = m.toHashMap();

    OMElement report = omFactory.createOMElement(new QName("XdsEvsResult"));

    addParm(report, mm, "Test", "other", "Service");
    addParm(report, mm, "Date", "main", "Timestamp");
    addParm(report, mm, "Source", "http", "IP_address_From");

    OMElement ele = omFactory.createOMElement(new QName("Target"));
    ele.setText(localIPAddress());
    report.addChild(ele);

    addParm(report, mm, "Endpoint", "http", "URI_To");
    addParm(report, mm, "Result", "main", "Pass");
    addParm(report, mm, "LogEvent", "main", "MessageId");

    addParm(report, mm, "Error", "error", "Error");

    // System.out.println("errors are:\n" + mm.get("error"));

    return report;
  }
Beispiel #14
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;
  }
 @Override
 public OMElement buildRFC3881() {
   OMNamespace namespace = null;
   OMElement root = axiom.createOMElement(RFC3881.ParticipantObjectName.getTag(), namespace);
   if (value != null) {
     root.setText(value);
   }
   return root;
 }
 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;
 }
 private OMElement getTextElement(String content) {
   OMFactory factory = OMAbstractFactory.getOMFactory();
   OMElement textElement = factory.createOMElement(TEXT_ELEMENT);
   if (content == null) {
     content = "";
   }
   textElement.setText(content);
   return textElement;
 }
Beispiel #18
0
  private static OMElement getPingOMBlock(String text) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace namespace = fac.createOMNamespace(applicationNamespaceName, "ns1");
    OMElement pingElem = fac.createOMElement(ping, namespace);
    OMElement textElem = fac.createOMElement(Text, namespace);

    textElem.setText(text);
    pingElem.addChild(textElem);

    return pingElem;
  }
Beispiel #19
0
  public static MessageContext sendUsingSwA(String fileName, String targetEPR) throws IOException {

    Options options = new Options();
    options.setTo(new EndpointReference(targetEPR));
    options.setAction("urn:uploadFileUsingSwA");
    options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE);

    ServiceClient sender = new ServiceClient();
    sender.setOptions(options);
    OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);

    MessageContext mc = new MessageContext();

    System.out.println("Sending file : " + fileName + " as SwA");
    FileDataSource fileDataSource = new FileDataSource(new File(fileName));
    DataHandler dataHandler = new DataHandler(fileDataSource);
    String attachmentID = mc.addAttachment(dataHandler);

    SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope env = factory.getDefaultEnvelope();
    OMNamespace ns = factory.createOMNamespace("http://services.samples/xsd", "m0");
    OMElement payload = factory.createOMElement("uploadFileUsingSwA", ns);
    OMElement request = factory.createOMElement("request", ns);
    OMElement imageId = factory.createOMElement("imageId", ns);
    imageId.setText(attachmentID);
    request.addChild(imageId);
    payload.addChild(request);
    env.getBody().addChild(payload);
    mc.setEnvelope(env);

    mepClient.addMessageContext(mc);
    mepClient.execute(true);
    MessageContext response = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);

    SOAPBody body = response.getEnvelope().getBody();
    String imageContentId =
        body.getFirstChildWithName(
                new QName("http://services.samples/xsd", "uploadFileUsingSwAResponse"))
            .getFirstChildWithName(new QName("http://services.samples/xsd", "response"))
            .getFirstChildWithName(new QName("http://services.samples/xsd", "imageId"))
            .getText();

    Attachments attachment = response.getAttachmentMap();
    dataHandler = attachment.getDataHandler(imageContentId);
    File tempFile = File.createTempFile("swa-", ".gif");
    FileOutputStream fos = new FileOutputStream(tempFile);
    dataHandler.writeTo(fos);
    fos.flush();
    fos.close();

    System.out.println("Saved response to file : " + tempFile.getAbsolutePath());

    return response;
  }
  private OMElement getPlaceOrderPayload(String symbolValue) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://services.samples", "ser");
    OMNamespace xsdNs = fac.createOMNamespace("http://services.samples", "xsd");
    OMElement payload = fac.createOMElement("placeOrder", omNs);
    OMElement order = fac.createOMElement("order", omNs);

    OMElement price = fac.createOMElement("price", xsdNs);
    price.setText("invalid");
    OMElement quantity = fac.createOMElement("quantity", xsdNs);
    quantity.setText("invalid");
    OMElement symbol = fac.createOMElement("symbol", xsdNs);
    symbol.setText(symbolValue);

    order.addChild(price);
    order.addChild(quantity);
    order.addChild(symbol);
    payload.addChild(order);
    return payload;
  }
Beispiel #21
0
  private static OMElement getPayload(String value) {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns =
        factory.createOMNamespace("http://sample05.policy.samples.rampart.apache.org", "ns1");
    OMElement elem = factory.createOMElement("echo", ns);
    OMElement childElem = factory.createOMElement("param0", null);
    childElem.setText(value);
    elem.addChild(childElem);

    return elem;
  }
  /**
   * Creates uri template elements for HTTP action verbs.
   *
   * @param resourcePath resource path.
   * @param methods http verbs.
   * @return Uri template element list.
   */
  private static List<OMElement> getUriTemplateElementFromMethods(
      String resourcePath, Iterator methods) {
    List<OMElement> uriTemplates = new ArrayList<>();
    while (methods.hasNext()) {
      OMElement method = (OMElement) methods.next();
      String httpVerb = method.getAttributeValue(new QName(NAME));
      OMElement uriTemplateElement = factory.createOMElement(URI_TEMPLATE, namespace);
      OMElement urlPatternElement = factory.createOMElement(URL_PATTERN, namespace);
      OMElement httpVerbElement = factory.createOMElement(HTTP_VERB, namespace);
      OMElement authTypeElement = factory.createOMElement(AUTH_TYPE, namespace);

      urlPatternElement.setText(resourcePath);
      httpVerbElement.setText(httpVerb);
      uriTemplateElement.addChild(urlPatternElement);
      uriTemplateElement.addChild(httpVerbElement);
      uriTemplateElement.addChild(authTypeElement);

      uriTemplates.add(uriTemplateElement);
    }
    return uriTemplates;
  }
Beispiel #23
0
  private static OMElement getEchoOMBlock(String text, String sequenceKey) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace applicationNamespace = fac.createOMNamespace(applicationNamespaceName, "ns1");
    OMElement echoStringElement = fac.createOMElement(echoString, applicationNamespace);
    OMElement textElem = fac.createOMElement(Text, applicationNamespace);
    OMElement sequenceElem = fac.createOMElement(Sequence, applicationNamespace);

    textElem.setText(text);
    sequenceElem.setText(sequenceKey);
    echoStringElement.addChild(textElem);
    echoStringElement.addChild(sequenceElem);

    OMNamespace namespace =
        fac.createOMNamespace(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI, "env");
    OMAttribute attr =
        fac.createOMAttribute(
            "encodingStyle", namespace, "http://schemas.xmlsoap.org/soap/encoding/");

    echoStringElement.addAttribute(attr);

    return echoStringElement;
  }
 void addParm(
     OMElement report,
     HashMap<String, HashMap<String, Object>> mm,
     String name,
     String section,
     String parm) {
   Object value = getParm(mm, section, parm);
   if (value instanceof String) {
     OMElement ele = omFactory.createOMElement(new QName(name));
     String txt = (String) value;
     txt = extractPrefix(txt);
     ele.setText(txt);
     report.addChild(ele);
   } else if (value instanceof ArrayList) {
     ArrayList<String> txts = (ArrayList<String>) value;
     for (String txt : txts) {
       OMElement ele = omFactory.createOMElement(new QName(name));
       txt = extractPrefix(txt);
       ele.setText(txt);
       report.addChild(ele);
     }
   }
 }
  public static OMElement addExtraElements(OMElement data, HttpServletRequest request) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    // adding required fields at the top of the xml which will help to easily read in service side
    OMElement operation = fac.createOMElement("operation", null);
    OMElement currentName = fac.createOMElement("currentName", null);
    OMElement currentNamespace = fac.createOMElement("currentNamespace", null);

    String operationValue = request.getParameter("operation");
    if (operationValue != null) {
      operation.setText(operationValue);
      data.addChild(operation);
    }
    String name = request.getParameter("currentname");
    if (name != null) {
      currentName.setText(name);
      data.addChild(currentName);
    }
    String namespace = request.getParameter("currentnamespace");
    if (namespace != null) {
      currentNamespace.setText(namespace);
      data.addChild(currentNamespace);
    }
    return data;
  }
  /**
   * Contains the logic to create URITemplate XML Element from the swagger 1.2 resource.
   *
   * @param resourceObjects the path resource documents.
   * @return URITemplate element.
   */
  private static List<OMElement> createURITemplateFromSwagger12(List<JsonObject> resourceObjects) {

    List<OMElement> uriTemplates = new ArrayList<>();

    for (JsonObject resourceObject : resourceObjects) {
      JsonArray pathResources = resourceObject.getAsJsonArray(SwaggerConstants.APIS);

      // Iterating through the Paths
      for (JsonElement pathResource : pathResources) {
        JsonObject path = pathResource.getAsJsonObject();
        String pathText = path.get(SwaggerConstants.PATH).getAsString();
        JsonArray methods = path.getAsJsonArray(SwaggerConstants.OPERATIONS);

        // Iterating through HTTP methods (Actions)
        for (JsonElement method : methods) {
          JsonObject methodObj = method.getAsJsonObject();

          OMElement uriTemplateElement = factory.createOMElement(URI_TEMPLATE, namespace);
          OMElement urlPatternElement = factory.createOMElement(URL_PATTERN, namespace);
          OMElement httpVerbElement = factory.createOMElement(HTTP_VERB, namespace);
          OMElement authTypeElement = factory.createOMElement(AUTH_TYPE, namespace);

          urlPatternElement.setText(pathText);
          httpVerbElement.setText(methodObj.get(SwaggerConstants.METHOD).getAsString());

          // Adding urlPattern element to URITemplate element.
          uriTemplateElement.addChild(urlPatternElement);
          uriTemplateElement.addChild(httpVerbElement);
          uriTemplateElement.addChild(authTypeElement);
          uriTemplates.add(uriTemplateElement);
        }
      }
    }

    return uriTemplates;
  }
Beispiel #27
0
  private OMElement getPayload(String value) {
    OMFactory factory = null;
    OMNamespace ns = null;
    OMElement elem = null;
    OMElement childElem = null;

    factory = OMAbstractFactory.getOMFactory();
    ns = factory.createOMNamespace("http://echo.services.core.carbon.wso2.org", "ns");
    elem = factory.createOMElement("echoString", ns);
    childElem = factory.createOMElement("in", null);
    childElem.setText(value);
    elem.addChild(childElem);

    return elem;
  }
  /**
   * Adding the attachment ids iteratively to the SOAP Header
   *
   * @param header Header Element where the child elements going to be included
   * @param attachmentIDList attachment ids
   */
  private void addAttachmentIDHeader(SOAPHeader header, List<Long> attachmentIDList) {
    final String namespace = Constants.ATTACHMENT_ID_NAMESPACE;
    final String namespacePrefix = Constants.ATTACHMENT_ID_NAMESPACE_PREFIX;
    final String parentElementName = Constants.ATTACHMENT_ID_PARENT_ELEMENT_NAME;
    final String childElementName = Constants.ATTACHMENT_ID_CHILD_ELEMENT_NAME;

    OMNamespace omNs = soapFactory.createOMNamespace(namespace, namespacePrefix);
    OMElement headerElement = soapFactory.createOMElement(parentElementName, omNs);

    for (Long id : attachmentIDList) {
      OMElement idElement = soapFactory.createOMElement(childElementName, omNs);
      idElement.setText(String.valueOf(id));

      headerElement.addChild(idElement);
    }

    header.addChild(headerElement);
  }
 /**
  * @param message JMSMap message
  * @return XML representation of JMS Map message
  */
 public static OMElement convertJMSMapToXML(MapMessage message) {
   OMFactory fac = OMAbstractFactory.getOMFactory();
   OMNamespace jmsMapNS =
       OMAbstractFactory.getOMFactory().createOMNamespace(JMSConstants.JMS_MAP_NS, "");
   OMElement jmsMap = fac.createOMElement(JMSConstants.JMS_MAP_ELEMENT_NAME, jmsMapNS);
   try {
     Enumeration names = message.getMapNames();
     while (names.hasMoreElements()) {
       String nextName = names.nextElement().toString();
       String nextVal = message.getString(nextName);
       OMElement next = fac.createOMElement(nextName.replace(" ", ""), jmsMapNS);
       next.setText(nextVal);
       jmsMap.addChild(next);
     }
   } catch (JMSException e) {
     log.error("Error while processing the JMS Map Message. " + e.getMessage());
   }
   return jmsMap;
 }
 /**
  * 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;
 }