Esempio n. 1
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);
    }
  }
  public void createSoapBody(
      org.apache.axiom.soap.SOAPBody sb,
      SOAPBody soapBody,
      Message msgDef,
      Element message,
      String rpcWrapper)
      throws AxisFault {
    OMElement partHolder =
        isRPC
            ? soapFactory.createOMElement(
                new QName(soapBody.getNamespaceURI(), rpcWrapper, "odens"), sb)
            : sb;
    List<Part> parts = msgDef.getOrderedParts(soapBody.getParts());

    for (Part part : parts) {
      Element srcPartEl = DOMUtils.findChildByName(message, new QName(null, part.getName()));
      if (srcPartEl == null) {
        throw new AxisFault("Missing required part in ODE Message");
      }

      OMElement omPart = OMUtils.toOM(srcPartEl, soapFactory);
      if (isRPC) {
        partHolder.addChild(omPart);
      } else {
        for (Iterator<OMNode> i = omPart.getChildren(); i.hasNext(); ) {
          partHolder.addChild(i.next());
        }
      }
    }
  }
  private OMNode createStatementElement(Statement statement) {

    OMElement stmntElt =
        fac.createOMElement(AbstractDBMediatorFactory.STMNT_Q.getLocalPart(), synNS);

    OMElement sqlElt = fac.createOMElement(AbstractDBMediatorFactory.SQL_Q.getLocalPart(), synNS);
    OMText sqlText = fac.createOMText(statement.getRawStatement(), XMLStreamConstants.CDATA);
    sqlElt.addChild(sqlText);
    stmntElt.addChild(sqlElt);

    // serialize parameters of the statement
    for (Statement.Parameter param : statement.getParameters()) {
      OMElement paramElt = createStatementParamElement(param);
      stmntElt.addChild(paramElt);
    }

    // serialize any optional results of the statement
    for (String name : statement.getResultsMap().keySet()) {

      String columnStr = statement.getResultsMap().get(name);

      OMElement resultElt =
          fac.createOMElement(AbstractDBMediatorFactory.RESULT_Q.getLocalPart(), synNS);

      resultElt.addAttribute(fac.createOMAttribute("name", nullNS, name));
      resultElt.addAttribute(fac.createOMAttribute("column", nullNS, columnStr));

      stmntElt.addChild(resultElt);
    }

    return stmntElt;
  }
  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>"));
  }
Esempio n. 5
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;
 }
  /**
   * 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 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;
  }
 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);
     }
   }
 }
Esempio n. 9
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;
 }
 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;
 }
Esempio n. 11
0
 public DeploymentResult deployAssembly(String assemblyName, InputStream zip)
     throws RemoteException {
   OMElement request = element(DEPLOY_REQUEST);
   setAuthentication(request);
   request.addChild(elementText(ASSEMBLY_NAME, assemblyName));
   request.addChild(elementBinary(ZIP, zip));
   OMParser response = invoke(DEPLOY_REQUEST.getLocalPart(), request);
   return OMParser.parseDeploymentResult(response);
 }
Esempio n. 12
0
 public DeploymentResult retire(AssemblyId assemblyId) throws RemoteException {
   OMElement request = element(ACTIVATE_REQUEST);
   setAuthentication(request);
   request.addChild(elementText(ASSEMBLY_NAME, assemblyId.getAssemblyName()));
   request.addChild(
       elementText(ASSEMBLY_VERSION, Integer.toString(assemblyId.getAssemblyVersion())));
   OMParser response = invoke(DEACTIVATE_REQUEST.getLocalPart(), request);
   return OMParser.parseDeploymentResult(response);
 }
  public OMElement serializeMediator(OMElement parent, Mediator m) {

    AggregateMediator mediator = null;
    if (!(m instanceof AggregateMediator)) {
      handleException("Unsupported mediator passed in for serialization : " + m.getType());
    } else {
      mediator = (AggregateMediator) m;
    }

    OMElement aggregator = fac.createOMElement("aggregate", synNS);
    saveTracingState(aggregator, mediator);

    assert mediator != null;
    if (mediator.getCorrelateExpression() != null) {
      OMElement corelateOn = fac.createOMElement("correlateOn", synNS);
      SynapseXPathSerializer.serializeXPath(
          mediator.getCorrelateExpression(), corelateOn, "expression");
      aggregator.addChild(corelateOn);
    }

    OMElement completeCond = fac.createOMElement("completeCondition", synNS);
    if (mediator.getCompletionTimeoutMillis() != 0) {
      completeCond.addAttribute(
          "timeout", Long.toString(mediator.getCompletionTimeoutMillis() / 1000), nullNS);
    }
    OMElement messageCount = fac.createOMElement("messageCount", synNS);
    if (mediator.getMinMessagesToComplete() != 0) {
      messageCount.addAttribute(
          "min", Integer.toString(mediator.getMinMessagesToComplete()), nullNS);
    }
    if (mediator.getMaxMessagesToComplete() != 0) {
      messageCount.addAttribute(
          "max", Integer.toString(mediator.getMaxMessagesToComplete()), nullNS);
    }
    completeCond.addChild(messageCount);
    aggregator.addChild(completeCond);

    OMElement onCompleteElem = fac.createOMElement("onComplete", synNS);
    if (mediator.getAggregationExpression() != null) {
      SynapseXPathSerializer.serializeXPath(
          mediator.getAggregationExpression(), onCompleteElem, "expression");
    }
    if (mediator.getOnCompleteSequenceRef() != null) {
      onCompleteElem.addAttribute("sequence", mediator.getOnCompleteSequenceRef(), nullNS);
    } else if (mediator.getOnCompleteSequence() != null) {
      new SequenceMediatorSerializer()
          .serializeChildren(onCompleteElem, mediator.getOnCompleteSequence().getList());
    }
    aggregator.addChild(onCompleteElem);

    if (parent != null) {
      parent.addChild(aggregator);
    }

    return aggregator;
  }
  protected void serializeDBInformation(AbstractDBMediator mediator, OMElement dbParent) {

    OMElement connElt = fac.createOMElement("connection", synNS);
    connElt.addChild(createPoolElement(mediator));
    dbParent.addChild(connElt);

    // process statements
    for (Statement statement : mediator.getStatementList()) {
      dbParent.addChild(createStatementElement(statement));
    }
  }
Esempio n. 15
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;
  }
Esempio n. 16
0
  private OMElement createStandardSimpleRequest(String symbol) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://services.samples", "ns");
    OMElement method = fac.createOMElement("getSimpleQuote", omNs);
    OMElement value1 = fac.createOMElement("symbol", omNs);

    value1.addChild(fac.createOMText(method, symbol));
    method.addChild(value1);

    return method;
  }
Esempio n. 17
0
  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 OMElement createPayload() {

    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
    OMElement rpcWrapEle = fac.createOMElement("echoMTOMtoBase64", omNs);
    OMElement data = fac.createOMElement("data", omNs);
    byte[] byteArray = new byte[] {13, 56, 65, 32, 12, 12, 7, 98};
    DataHandler dataHandler = new DataHandler(new ByteArrayDataSource(byteArray));
    expectedTextData = new OMTextImpl(dataHandler, true, fac);
    data.addChild(expectedTextData);
    rpcWrapEle.addChild(data);
    return rpcWrapEle;
  }
  private OMElement getPayload() {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://services.samples", "ns");
    OMElement method = fac.createOMElement("getQuote", omNs);
    OMElement value1 = fac.createOMElement("request", omNs);
    OMElement value2 = fac.createOMElement("symbol", omNs);

    value2.addChild(fac.createOMText(value1, "Secured"));
    value1.addChild(value2);
    method.addChild(value1);

    return method;
  }
  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;
  }
  private static OMElement getPayload() {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://service.esb.wso2.org", "ns");
    OMElement method = fac.createOMElement("add", omNs);
    OMElement value1 = fac.createOMElement("x", omNs);
    OMElement value2 = fac.createOMElement("y", omNs);

    value1.addChild(fac.createOMText(value1, "10"));
    value2.addChild(fac.createOMText(value2, "10"));
    method.addChild(value1);
    method.addChild(value2);

    return method;
  }
Esempio n. 22
0
  private OMElement createMultipleQuoteRequest(String symbol, int iterations) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://services.samples", "ns");
    OMElement method = fac.createOMElement("getQuote", omNs);

    for (int i = 0; i < iterations; i++) {
      OMElement value1 = fac.createOMElement("request", omNs);
      OMElement value2 = fac.createOMElement("symbol", omNs);
      value2.addChild(fac.createOMText(value1, symbol));
      value1.addChild(value2);
      method.addChild(value1);
    }
    return method;
  }
  public OMElement getCEPPublisher(OMElement request) throws XMLStreamException {
    request.build();
    request.detach();

    OMElement tenantId =
        request.getFirstChildWithName(
            new QName(
                ManagerServiceConstants.NAMESPACE, ManagerServiceConstants.ELEMENT_TENANT_ID));
    OMElement executionPlan =
        request.getFirstChildWithName(
            new QName(
                ManagerServiceConstants.NAMESPACE, ManagerServiceConstants.ELEMENT_EXEC_PLAN));
    OMElement requesterIp =
        request.getFirstChildWithName(
            new QName(
                ManagerServiceConstants.NAMESPACE, ManagerServiceConstants.ELEMENT_REQUESTER_IP));
    String key = getKey(executionPlan.getText(), tenantId.getText());
    log.info("CEP Publisher requested for  " + key);

    Set<Endpoint> endpointSet = cepPublishers.get(key);
    Endpoint selectedEndpoint = selectEndpoint(endpointSet, requesterIp.getText());
    OMElement response =
        factory.createOMElement(
            ManagerServiceConstants.ELEMENT_CEP_PUBLISHER_RESPONSE, OMNamespace);
    if (selectedEndpoint != null) {
      OMElement hostNameElement =
          factory.createOMElement(ManagerServiceConstants.ELEMENT_HOST_NAME, OMNamespace);
      OMElement portElement =
          factory.createOMElement(ManagerServiceConstants.ELEMENT_PORT, OMNamespace);

      OMText hostNameText = factory.createOMText(hostNameElement, selectedEndpoint.getHostName());
      OMText portText =
          factory.createOMText(portElement, Integer.toString(selectedEndpoint.getPort()));

      hostNameElement.addChild(hostNameText);
      portElement.addChild(portText);
      response.addChild(hostNameElement);
      response.addChild(portElement);
      log.info(
          "Returning CEP Publisher:"
              + selectedEndpoint.getHostName()
              + ":"
              + selectedEndpoint.getPort());
    } else {
      log.warn("No CEP publishers registered " + key);
    }

    return response;
  }
 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);
   }
 }
Esempio n. 25
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;
 }
Esempio n. 26
0
  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;
  }
  public OMElement serialize(OMFactory fac) {

    if (log.isDebugEnabled() || log.isTraceEnabled()) {
      log.debug("Serialize command");
    }

    /*
     * org.apache.axiom.om.OMNamespace nullNS = fac.createOMNamespace(
     * XMLConfigConstants.NULL_NAMESPACE, "");
     */
    ValueSerializer valueSerializer = new ValueSerializer();

    OMElement root = AuditMediatorUtils.createTag(fac, this.type);

    for (Iterator iterator = params.iterator(); iterator.hasNext(); ) {
      Param param = (Param) iterator.next();

      OMElement paramTag = AuditMediatorUtils.createTag(fac, AuditMediatorUtils.PARAM_TAG_NAME);

      root.addChild(paramTag);

      paramTag.addAttribute(
          fac.createOMAttribute(
              AuditMediatorUtils.NAME_ATT_NAME, AuditMediatorUtils.nullNS, param.getName()));

      valueSerializer.serializeValue(param.getValue(), AuditMediatorUtils.VALUE_ATT_NAME, paramTag);
    }

    return root;
  }
  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;
  }
  public static OMElement outputMappingToOM(OutputMapping outputMapping, OMFactory factory) {

    MapOutputMapping mapOutputMapping = (MapOutputMapping) outputMapping;

    List<EventOutputProperty> outputPropertyConfiguration =
        mapOutputMapping.getOutputPropertyConfiguration();

    OMElement mappingOMElement =
        factory.createOMElement(new QName(EventFormatterConstants.EF_ELE_MAPPING_PROPERTY));
    mappingOMElement.declareDefaultNamespace(EventFormatterConstants.EF_CONF_NS);

    mappingOMElement.addAttribute(
        EventFormatterConstants.EF_ATTR_TYPE, EventFormatterConstants.EF_MAP_MAPPING_TYPE, null);

    if (mapOutputMapping.isCustomMappingEnabled()) {
      mappingOMElement.addAttribute(
          EventFormatterConstants.EF_ATTR_CUSTOM_MAPPING,
          EventFormatterConstants.TM_VALUE_ENABLE,
          null);

      if (outputPropertyConfiguration.size() > 0) {
        for (EventOutputProperty eventOutputProperty : outputPropertyConfiguration) {
          mappingOMElement.addChild(getPropertyOmElement(factory, eventOutputProperty));
        }
      }
    } else {
      mappingOMElement.addAttribute(
          EventFormatterConstants.EF_ATTR_CUSTOM_MAPPING,
          EventFormatterConstants.TM_VALUE_DISABLE,
          null);
    }
    return mappingOMElement;
  }
 public static OMElement serializeInboundEndpoint(
     OMElement parent, InboundEndpoint inboundEndpoint) {
   OMElement inboundEndpointElt = serializeInboundEndpoint(inboundEndpoint);
   if (parent != null) {
     parent.addChild(inboundEndpointElt);
   }
   return inboundEndpointElt;
 }