Package org.apache.jorphan.util

Examples of org.apache.jorphan.util.XMLBuffer


   * @param e
   *            !ToDo (Parameter description)
   * @return !ToDo (Return description)
   **************************************************************************/
  public SampleResult sample(Entry e) {
    XMLBuffer xmlBuffer = new XMLBuffer();
    xmlBuffer.openTag("ldapanswer"); // $NON-NLS-1$
    SampleResult res = new SampleResult();
    res.setResponseData("successfull".getBytes());
    res.setResponseMessage("Success"); // $NON-NLS-1$
    res.setResponseCode("0"); // $NON-NLS-1$
    boolean isSuccessful = true;
    res.setSampleLabel(getName());
    LdapExtClient temp_client = (LdapExtClient) ldapConnections.get(getThreadName());
    DirContext dirContext = (DirContext) ldapContexts.get(getThreadName());
    if (temp_client == null) {
      temp_client = new LdapExtClient();
      try {
        dirContext = new InitialDirContext();
      } catch (NamingException err) {
        log.error("Ldap client context creation - ", err);
      }
      ldapConnections.put(getThreadName(), temp_client);
    }

    try {
      xmlBuffer.openTag("operation"); // $NON-NLS-1$
      final String testType = getTest();
      xmlBuffer.tag("opertype", testType); // $NON-NLS-1$
      log.debug("performing test: " + testType);
      if (testType.equals(UNBIND)) {
        res.setSamplerData("Unbind");
        xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
        xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
        unbindOp(temp_client, dirContext, res);
      } else if (testType.equals(BIND)) {
        res.setSamplerData("Bind as "+getUserDN());
        xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
        xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
        xmlBuffer.tag("connectionTO",getConnTimeOut()); // $NON-NLS-1$
        bindOp(temp_client, dirContext, res);
      } else if (testType.equals(SBIND)) {
        res.setSamplerData("SingleBind as "+getUserDN());
        xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
        xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
        xmlBuffer.tag("connectionTO",getConnTimeOut()); // $NON-NLS-1$
        singleBindOp(res);
      } else if (testType.equals(COMPARE)) {
        res.setSamplerData("Compare "+getPropertyAsString(COMPAREFILT) + " "
                + getPropertyAsString(COMPAREDN));
        xmlBuffer.tag("comparedn",getPropertyAsString(COMPAREDN)); // $NON-NLS-1$
        xmlBuffer.tag("comparefilter",getPropertyAsString(COMPAREFILT)); // $NON-NLS-1$
                NamingEnumeration cmp;
        try {
          res.sampleStart();
          cmp = temp_client.compare(dirContext, getPropertyAsString(COMPAREFILT),
              getPropertyAsString(COMPAREDN));
        } finally {
          res.sampleEnd();
        }       
        if (!cmp.hasMore()) {
          res.setResponseCode("5"); // $NON-NLS-1$
          res.setResponseMessage("compareFalse");
          isSuccessful = false;
        }
      } else if (testType.equals(ADD)) {
        res.setSamplerData("Add object " + getBaseEntryDN());
        xmlBuffer.tag("attributes",getArguments().toString()); // $NON-NLS-1$
        xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
        addTest(temp_client, dirContext, res);
      } else if (testType.equals(DELETE)) {
        res.setSamplerData("Delete object " + getBaseEntryDN());
        xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
        deleteTest(temp_client, dirContext, res);
      } else if (testType.equals(MODIFY)) {
        res.setSamplerData("Modify object " + getBaseEntryDN());
        xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
        xmlBuffer.tag("attributes",getLDAPArguments().toString()); // $NON-NLS-1$
        modifyTest(temp_client, dirContext, res);
      } else if (testType.equals(RENAME)) {
        res.setSamplerData("ModDN object " + getPropertyAsString(MODDDN) + " to " + getPropertyAsString(NEWDN));
        xmlBuffer.tag("dn",getPropertyAsString(MODDDN)); // $NON-NLS-1$
        xmlBuffer.tag("newdn",getPropertyAsString(NEWDN)); // $NON-NLS-1$
        renameTest(temp_client, dirContext, res);
      } else if (testType.equals(SEARCH)) {
                final String            scopeStr = getScope();
                final int               scope = getScopeAsInt();
                final String searchFilter = getPropertyAsString(SEARCHFILTER);
        final String searchBase = getPropertyAsString(SEARCHBASE);
        final String timeLimit = getTimelim();
        final String countLimit = getCountlim();

        res.setSamplerData("Search with filter " + searchFilter);
        xmlBuffer.tag("searchfilter",searchFilter); // $NON-NLS-1$
        xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
        xmlBuffer.tag("searchbase",searchBase);// $NON-NLS-1$
        xmlBuffer.tag("scope" , scopeStr); // $NON-NLS-1$
        xmlBuffer.tag("countlimit",countLimit); // $NON-NLS-1$
        xmlBuffer.tag("timelimit",timeLimit); // $NON-NLS-1$

                NamingEnumeration srch;
        try {
          res.sampleStart();
          srch = temp_client.searchTest(
              dirContext, searchBase, searchFilter,
              scope, getCountlimAsLong(),
              getTimelimAsInt(),
              getRequestAttributes(getAttrs()),
              isRetobj(),
              isDeref());
        } finally {
          res.sampleEnd();
        }       

                if (isParseFlag()) {
          try {
            xmlBuffer.openTag("searchresults"); // $NON-NLS-1$
            writeSearchResults(xmlBuffer, srch);
          } finally {
            xmlBuffer.closeTag("searchresults"); // $NON-NLS-1$
          }         
                }
      }

    } catch (NamingException ex) {
      //log.warn("DEBUG",ex);
// e.g. javax.naming.SizeLimitExceededException: [LDAP: error code 4 - Sizelimit Exceeded]; remaining name ''
//                                                123456789012345678901
      // TODO: tidy this up
      String returnData = ex.toString();
      final int indexOfLDAPErrCode = returnData.indexOf("LDAP: error code");
      if (indexOfLDAPErrCode >= 0) {
        res.setResponseMessage(returnData.substring(indexOfLDAPErrCode + 21, returnData
            .indexOf("]"))); // $NON-NLS-1$
        res.setResponseCode(returnData.substring(indexOfLDAPErrCode + 17, indexOfLDAPErrCode + 19));
      } else {
        res.setResponseMessage(returnData);
        res.setResponseCode("800"); // $NON-NLS-1$
      }
      isSuccessful = false;
    } finally {
      xmlBuffer.closeTag("operation"); // $NON-NLS-1$
      xmlBuffer.tag("responsecode",res.getResponseCode()); // $NON-NLS-1$
      xmlBuffer.tag("responsemessage",res.getResponseMessage()); // $NON-NLS-1$
      res.setResponseData(xmlBuffer.toString().getBytes());
      res.setDataType(SampleResult.TEXT);
      res.setSuccessful(isSuccessful);
    }
    return res;
  }
View Full Code Here


     * @param e
     *            !ToDo (Parameter description)
     * @return !ToDo (Return description)
     **************************************************************************/
    public SampleResult sample(Entry e) {
        XMLBuffer xmlBuffer = new XMLBuffer();
        xmlBuffer.openTag("ldapanswer"); // $NON-NLS-1$
        SampleResult res = new SampleResult();
        res.setResponseData("successfull", null);
        res.setResponseMessage("Success"); // $NON-NLS-1$
        res.setResponseCode("0"); // $NON-NLS-1$
        res.setContentType("text/xml");// $NON-NLS-1$
        boolean isSuccessful = true;
        res.setSampleLabel(getName());
        DirContext dirContext = ldapContexts.get(getThreadName());

        try {
            xmlBuffer.openTag("operation"); // $NON-NLS-1$
            final String testType = getTest();
            xmlBuffer.tag("opertype", testType); // $NON-NLS-1$
            log.debug("performing test: " + testType);
            if (testType.equals(UNBIND)) {
                res.setSamplerData("Unbind");
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
                unbindOp(dirContext, res);
            } else if (testType.equals(BIND)) {
                res.setSamplerData("Bind as "+getUserDN());
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
                xmlBuffer.tag("connectionTO",getConnTimeOut()); // $NON-NLS-1$
                bindOp(res);
            } else if (testType.equals(SBIND)) {
                res.setSamplerData("SingleBind as "+getUserDN());
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
                xmlBuffer.tag("connectionTO",getConnTimeOut()); // $NON-NLS-1$
                singleBindOp(res);
            } else if (testType.equals(COMPARE)) {
                res.setSamplerData("Compare "+getPropertyAsString(COMPAREFILT) + " "
                                + getPropertyAsString(COMPAREDN));
                xmlBuffer.tag("comparedn",getPropertyAsString(COMPAREDN)); // $NON-NLS-1$
                xmlBuffer.tag("comparefilter",getPropertyAsString(COMPAREFILT)); // $NON-NLS-1$
                NamingEnumeration<SearchResult> cmp=null;
                try {
                    res.sampleStart();
                    cmp = LdapExtClient.compare(dirContext, getPropertyAsString(COMPAREFILT),
                            getPropertyAsString(COMPAREDN));
                    if (!cmp.hasMore()) {
                        res.setResponseCode("5"); // $NON-NLS-1$
                        res.setResponseMessage("compareFalse");
                        isSuccessful = false;
                    }
                } finally {
                    res.sampleEnd();
                    if (cmp != null) {
                        cmp.close();
                    }
                }
            } else if (testType.equals(ADD)) {
                res.setSamplerData("Add object " + getBaseEntryDN());
                xmlBuffer.tag("attributes",getArguments().toString()); // $NON-NLS-1$
                xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
                addTest(dirContext, res);
            } else if (testType.equals(DELETE)) {
                res.setSamplerData("Delete object " + getBaseEntryDN());
                xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
                deleteTest(dirContext, res);
            } else if (testType.equals(MODIFY)) {
                res.setSamplerData("Modify object " + getBaseEntryDN());
                xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
                xmlBuffer.tag("attributes",getLDAPArguments().toString()); // $NON-NLS-1$
                modifyTest(dirContext, res);
            } else if (testType.equals(RENAME)) {
                res.setSamplerData("ModDN object " + getPropertyAsString(MODDDN) + " to " + getPropertyAsString(NEWDN));
                xmlBuffer.tag("dn",getPropertyAsString(MODDDN)); // $NON-NLS-1$
                xmlBuffer.tag("newdn",getPropertyAsString(NEWDN)); // $NON-NLS-1$
                renameTest(dirContext, res);
            } else if (testType.equals(SEARCH)) {
                final String            scopeStr = getScope();
                final int               scope = getScopeAsInt();
                final String searchFilter = getPropertyAsString(SEARCHFILTER);
                final String searchBase = getPropertyAsString(SEARCHBASE);
                final String timeLimit = getTimelim();
                final String countLimit = getCountlim();

                res.setSamplerData("Search with filter " + searchFilter);
                xmlBuffer.tag("searchfilter",searchFilter); // $NON-NLS-1$
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("searchbase",searchBase);// $NON-NLS-1$
                xmlBuffer.tag("scope" , scopeStr); // $NON-NLS-1$
                xmlBuffer.tag("countlimit",countLimit); // $NON-NLS-1$
                xmlBuffer.tag("timelimit",timeLimit); // $NON-NLS-1$

                NamingEnumeration<SearchResult> srch=null;
                try {
                    res.sampleStart();
                    srch = LdapExtClient.searchTest(
                            dirContext, searchBase, searchFilter,
                            scope, getCountlimAsLong(),
                            getTimelimAsInt(),
                            getRequestAttributes(getAttrs()),
                            isRetobj(),
                            isDeref());
                    if (isParseFlag()) {
                        try {
                            xmlBuffer.openTag("searchresults"); // $NON-NLS-1$
                            writeSearchResults(xmlBuffer, srch);
                        } finally {
                            xmlBuffer.closeTag("searchresults"); // $NON-NLS-1$
                        }
                    } else {
                        xmlBuffer.tag("searchresults", // $NON-NLS-1$
                                "hasElements="+srch.hasMoreElements()); // $NON-NLS-1$
                    }
                } finally {
                    if (srch != null){
                        srch.close();
                    }
                    res.sampleEnd();
                }

            }

        } catch (NamingException ex) {
            //log.warn("DEBUG",ex);
// e.g. javax.naming.SizeLimitExceededException: [LDAP: error code 4 - Sizelimit Exceeded]; remaining name ''
//                                                123456789012345678901
            // TODO: tidy this up
            String returnData = ex.toString();
            final int indexOfLDAPErrCode = returnData.indexOf("LDAP: error code");
            if (indexOfLDAPErrCode >= 0) {
                res.setResponseMessage(returnData.substring(indexOfLDAPErrCode + 21, returnData
                        .indexOf(']'))); // $NON-NLS-1$
                res.setResponseCode(returnData.substring(indexOfLDAPErrCode + 17, indexOfLDAPErrCode + 19));
            } else {
                res.setResponseMessage(returnData);
                res.setResponseCode("800"); // $NON-NLS-1$
            }
            isSuccessful = false;
        } finally {
            xmlBuffer.closeTag("operation"); // $NON-NLS-1$
            xmlBuffer.tag("responsecode",res.getResponseCode()); // $NON-NLS-1$
            xmlBuffer.tag("responsemessage",res.getResponseMessage()); // $NON-NLS-1$
            res.setResponseData(xmlBuffer.toString(), null);
            res.setDataType(SampleResult.TEXT);
            res.setSuccessful(isSuccessful);
        }
        return res;
    }
View Full Code Here

     * @param e
     *            !ToDo (Parameter description)
     * @return !ToDo (Return description)
     **************************************************************************/
    public SampleResult sample(Entry e) {
        XMLBuffer xmlBuffer = new XMLBuffer();
        xmlBuffer.openTag("ldapanswer"); // $NON-NLS-1$
        SampleResult res = new SampleResult();
        res.setResponseData("successfull", null);
        res.setResponseMessage("Success"); // $NON-NLS-1$
        res.setResponseCode("0"); // $NON-NLS-1$
        res.setContentType("text/xml");// $NON-NLS-1$
        boolean isSuccessful = true;
        res.setSampleLabel(getName());
        DirContext dirContext = ldapContexts.get(getThreadName());

        try {
            xmlBuffer.openTag("operation"); // $NON-NLS-1$
            final String testType = getTest();
            xmlBuffer.tag("opertype", testType); // $NON-NLS-1$
            log.debug("performing test: " + testType);
            if (testType.equals(UNBIND)) {
                res.setSamplerData("Unbind");
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
                unbindOp(dirContext, res);
            } else if (testType.equals(BIND)) {
                res.setSamplerData("Bind as "+getUserDN());
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
                xmlBuffer.tag("connectionTO",getConnTimeOut()); // $NON-NLS-1$
                bindOp(dirContext, res);
            } else if (testType.equals(SBIND)) {
                res.setSamplerData("SingleBind as "+getUserDN());
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
                xmlBuffer.tag("connectionTO",getConnTimeOut()); // $NON-NLS-1$
                singleBindOp(res);
            } else if (testType.equals(COMPARE)) {
                res.setSamplerData("Compare "+getPropertyAsString(COMPAREFILT) + " "
                                + getPropertyAsString(COMPAREDN));
                xmlBuffer.tag("comparedn",getPropertyAsString(COMPAREDN)); // $NON-NLS-1$
                xmlBuffer.tag("comparefilter",getPropertyAsString(COMPAREFILT)); // $NON-NLS-1$
                NamingEnumeration<SearchResult> cmp=null;
                try {
                    res.sampleStart();
                    cmp = LdapExtClient.compare(dirContext, getPropertyAsString(COMPAREFILT),
                            getPropertyAsString(COMPAREDN));
                    if (!cmp.hasMore()) {
                        res.setResponseCode("5"); // $NON-NLS-1$
                        res.setResponseMessage("compareFalse");
                        isSuccessful = false;
                    }
                } finally {
                    res.sampleEnd();
                    if (cmp != null) {
                        cmp.close();
                    }
                }
            } else if (testType.equals(ADD)) {
                res.setSamplerData("Add object " + getBaseEntryDN());
                xmlBuffer.tag("attributes",getArguments().toString()); // $NON-NLS-1$
                xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
                addTest(dirContext, res);
            } else if (testType.equals(DELETE)) {
                res.setSamplerData("Delete object " + getBaseEntryDN());
                xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
                deleteTest(dirContext, res);
            } else if (testType.equals(MODIFY)) {
                res.setSamplerData("Modify object " + getBaseEntryDN());
                xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
                xmlBuffer.tag("attributes",getLDAPArguments().toString()); // $NON-NLS-1$
                modifyTest(dirContext, res);
            } else if (testType.equals(RENAME)) {
                res.setSamplerData("ModDN object " + getPropertyAsString(MODDDN) + " to " + getPropertyAsString(NEWDN));
                xmlBuffer.tag("dn",getPropertyAsString(MODDDN)); // $NON-NLS-1$
                xmlBuffer.tag("newdn",getPropertyAsString(NEWDN)); // $NON-NLS-1$
                renameTest(dirContext, res);
            } else if (testType.equals(SEARCH)) {
                final String            scopeStr = getScope();
                final int               scope = getScopeAsInt();
                final String searchFilter = getPropertyAsString(SEARCHFILTER);
                final String searchBase = getPropertyAsString(SEARCHBASE);
                final String timeLimit = getTimelim();
                final String countLimit = getCountlim();

                res.setSamplerData("Search with filter " + searchFilter);
                xmlBuffer.tag("searchfilter",searchFilter); // $NON-NLS-1$
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("searchbase",searchBase);// $NON-NLS-1$
                xmlBuffer.tag("scope" , scopeStr); // $NON-NLS-1$
                xmlBuffer.tag("countlimit",countLimit); // $NON-NLS-1$
                xmlBuffer.tag("timelimit",timeLimit); // $NON-NLS-1$

                NamingEnumeration<SearchResult> srch=null;
                try {
                    res.sampleStart();
                    srch = LdapExtClient.searchTest(
                            dirContext, searchBase, searchFilter,
                            scope, getCountlimAsLong(),
                            getTimelimAsInt(),
                            getRequestAttributes(getAttrs()),
                            isRetobj(),
                            isDeref());
                    if (isParseFlag()) {
                        try {
                            xmlBuffer.openTag("searchresults"); // $NON-NLS-1$
                            writeSearchResults(xmlBuffer, srch);
                        } finally {
                            xmlBuffer.closeTag("searchresults"); // $NON-NLS-1$
                        }
                    } else {
                        xmlBuffer.tag("searchresults", // $NON-NLS-1$
                                "hasElements="+srch.hasMoreElements()); // $NON-NLS-1$
                    }
                } finally {
                    if (srch != null){
                        srch.close();
                    }
                    res.sampleEnd();
                }

            }

        } catch (NamingException ex) {
            //log.warn("DEBUG",ex);
// e.g. javax.naming.SizeLimitExceededException: [LDAP: error code 4 - Sizelimit Exceeded]; remaining name ''
//                                                123456789012345678901
            // TODO: tidy this up
            String returnData = ex.toString();
            final int indexOfLDAPErrCode = returnData.indexOf("LDAP: error code");
            if (indexOfLDAPErrCode >= 0) {
                res.setResponseMessage(returnData.substring(indexOfLDAPErrCode + 21, returnData
                        .indexOf("]"))); // $NON-NLS-1$
                res.setResponseCode(returnData.substring(indexOfLDAPErrCode + 17, indexOfLDAPErrCode + 19));
            } else {
                res.setResponseMessage(returnData);
                res.setResponseCode("800"); // $NON-NLS-1$
            }
            isSuccessful = false;
        } finally {
            xmlBuffer.closeTag("operation"); // $NON-NLS-1$
            xmlBuffer.tag("responsecode",res.getResponseCode()); // $NON-NLS-1$
            xmlBuffer.tag("responsemessage",res.getResponseMessage()); // $NON-NLS-1$
            res.setResponseData(xmlBuffer.toString(), null);
            res.setDataType(SampleResult.TEXT);
            res.setSuccessful(isSuccessful);
        }
        return res;
    }
View Full Code Here

     *            !ToDo (Parameter description)
     * @return !ToDo (Return description)
     **************************************************************************/
    @Override
    public SampleResult sample(Entry e) {
        XMLBuffer xmlBuffer = new XMLBuffer();
        xmlBuffer.openTag("ldapanswer"); // $NON-NLS-1$
        SampleResult res = new SampleResult();
        res.setResponseData("successfull", null);
        res.setResponseMessage("Success"); // $NON-NLS-1$
        res.setResponseCode("0"); // $NON-NLS-1$
        res.setContentType("text/xml");// $NON-NLS-1$
        boolean isSuccessful = true;
        res.setSampleLabel(getName());
        DirContext dirContext = ldapContexts.get(getThreadName());

        try {
            xmlBuffer.openTag("operation"); // $NON-NLS-1$
            final String testType = getTest();
            xmlBuffer.tag("opertype", testType); // $NON-NLS-1$
            log.debug("performing test: " + testType);
            if (testType.equals(UNBIND)) {
                res.setSamplerData("Unbind");
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
                unbindOp(dirContext, res);
            } else if (testType.equals(BIND)) {
                res.setSamplerData("Bind as "+getUserDN());
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
                xmlBuffer.tag("connectionTO",getConnTimeOut()); // $NON-NLS-1$
                bindOp(res);
            } else if (testType.equals(SBIND)) {
                res.setSamplerData("SingleBind as "+getUserDN());
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
                xmlBuffer.tag("connectionTO",getConnTimeOut()); // $NON-NLS-1$
                singleBindOp(res);
            } else if (testType.equals(COMPARE)) {
                res.setSamplerData("Compare "+getPropertyAsString(COMPAREFILT) + " "
                                + getPropertyAsString(COMPAREDN));
                xmlBuffer.tag("comparedn",getPropertyAsString(COMPAREDN)); // $NON-NLS-1$
                xmlBuffer.tag("comparefilter",getPropertyAsString(COMPAREFILT)); // $NON-NLS-1$
                NamingEnumeration<SearchResult> cmp=null;
                try {
                    res.sampleStart();
                    cmp = LdapExtClient.compare(dirContext, getPropertyAsString(COMPAREFILT),
                            getPropertyAsString(COMPAREDN));
                    if (!cmp.hasMore()) {
                        res.setResponseCode("5"); // $NON-NLS-1$
                        res.setResponseMessage("compareFalse");
                        isSuccessful = false;
                    }
                } finally {
                    res.sampleEnd();
                    if (cmp != null) {
                        cmp.close();
                    }
                }
            } else if (testType.equals(ADD)) {
                res.setSamplerData("Add object " + getBaseEntryDN());
                xmlBuffer.tag("attributes",getArguments().toString()); // $NON-NLS-1$
                xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
                addTest(dirContext, res);
            } else if (testType.equals(DELETE)) {
                res.setSamplerData("Delete object " + getBaseEntryDN());
                xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
                deleteTest(dirContext, res);
            } else if (testType.equals(MODIFY)) {
                res.setSamplerData("Modify object " + getBaseEntryDN());
                xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
                xmlBuffer.tag("attributes",getLDAPArguments().toString()); // $NON-NLS-1$
                modifyTest(dirContext, res);
            } else if (testType.equals(RENAME)) {
                res.setSamplerData("ModDN object " + getPropertyAsString(MODDDN) + " to " + getPropertyAsString(NEWDN));
                xmlBuffer.tag("dn",getPropertyAsString(MODDDN)); // $NON-NLS-1$
                xmlBuffer.tag("newdn",getPropertyAsString(NEWDN)); // $NON-NLS-1$
                renameTest(dirContext, res);
            } else if (testType.equals(SEARCH)) {
                final String            scopeStr = getScope();
                final int               scope = getScopeAsInt();
                final String searchFilter = getPropertyAsString(SEARCHFILTER);
                final String searchBase = getPropertyAsString(SEARCHBASE);
                final String timeLimit = getTimelim();
                final String countLimit = getCountlim();

                res.setSamplerData("Search with filter " + searchFilter);
                xmlBuffer.tag("searchfilter", StringEscapeUtils.escapeXml(searchFilter)); // $NON-NLS-1$
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("searchbase",searchBase);// $NON-NLS-1$
                xmlBuffer.tag("scope" , scopeStr); // $NON-NLS-1$
                xmlBuffer.tag("countlimit",countLimit); // $NON-NLS-1$
                xmlBuffer.tag("timelimit",timeLimit); // $NON-NLS-1$

                NamingEnumeration<SearchResult> srch=null;
                try {
                    res.sampleStart();
                    srch = LdapExtClient.searchTest(
                            dirContext, searchBase, searchFilter,
                            scope, getCountlimAsLong(),
                            getTimelimAsInt(),
                            getRequestAttributes(getAttrs()),
                            isRetobj(),
                            isDeref());
                    if (isParseFlag()) {
                        try {
                            xmlBuffer.openTag("searchresults"); // $NON-NLS-1$
                            writeSearchResults(xmlBuffer, srch);
                        } finally {
                            xmlBuffer.closeTag("searchresults"); // $NON-NLS-1$
                        }
                    } else {
                        xmlBuffer.tag("searchresults", // $NON-NLS-1$
                                "hasElements="+srch.hasMoreElements()); // $NON-NLS-1$
                    }
                } finally {
                    if (srch != null){
                        srch.close();
                    }
                    res.sampleEnd();
                }

            }

        } catch (NamingException ex) {
            //log.warn("DEBUG",ex);
// e.g. javax.naming.SizeLimitExceededException: [LDAP: error code 4 - Sizelimit Exceeded]; remaining name ''
//                                                123456789012345678901
            // TODO: tidy this up
            String returnData = ex.toString();
            final int indexOfLDAPErrCode = returnData.indexOf("LDAP: error code");
            if (indexOfLDAPErrCode >= 0) {
                res.setResponseMessage(returnData.substring(indexOfLDAPErrCode + 21, returnData
                        .indexOf(']'))); // $NON-NLS-1$
                res.setResponseCode(returnData.substring(indexOfLDAPErrCode + 17, indexOfLDAPErrCode + 19));
            } else {
                res.setResponseMessage(returnData);
                res.setResponseCode("800"); // $NON-NLS-1$
            }
            isSuccessful = false;
        } finally {
            xmlBuffer.closeTag("operation"); // $NON-NLS-1$
            xmlBuffer.tag("responsecode",res.getResponseCode()); // $NON-NLS-1$
            xmlBuffer.tag("responsemessage",res.getResponseMessage()); // $NON-NLS-1$
            res.setResponseData(xmlBuffer.toString(), null);
            res.setDataType(SampleResult.TEXT);
            res.setSuccessful(isSuccessful);
        }
        return res;
    }
View Full Code Here

     * @param e
     *            !ToDo (Parameter description)
     * @return !ToDo (Return description)
     **************************************************************************/
    public SampleResult sample(Entry e) {
        XMLBuffer xmlBuffer = new XMLBuffer();
        xmlBuffer.openTag("ldapanswer"); // $NON-NLS-1$
        SampleResult res = new SampleResult();
        res.setResponseData("successfull", null);
        res.setResponseMessage("Success"); // $NON-NLS-1$
        res.setResponseCode("0"); // $NON-NLS-1$
        res.setContentType("text/xml");// $NON-NLS-1$
        boolean isSuccessful = true;
        res.setSampleLabel(getName());
        DirContext dirContext = ldapContexts.get(getThreadName());

        try {
            xmlBuffer.openTag("operation"); // $NON-NLS-1$
            final String testType = getTest();
            xmlBuffer.tag("opertype", testType); // $NON-NLS-1$
            log.debug("performing test: " + testType);
            if (testType.equals(UNBIND)) {
                res.setSamplerData("Unbind");
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
                unbindOp(dirContext, res);
            } else if (testType.equals(BIND)) {
                res.setSamplerData("Bind as "+getUserDN());
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
                xmlBuffer.tag("connectionTO",getConnTimeOut()); // $NON-NLS-1$
                bindOp(dirContext, res);
            } else if (testType.equals(SBIND)) {
                res.setSamplerData("SingleBind as "+getUserDN());
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
                xmlBuffer.tag("connectionTO",getConnTimeOut()); // $NON-NLS-1$
                singleBindOp(res);
            } else if (testType.equals(COMPARE)) {
                res.setSamplerData("Compare "+getPropertyAsString(COMPAREFILT) + " "
                                + getPropertyAsString(COMPAREDN));
                xmlBuffer.tag("comparedn",getPropertyAsString(COMPAREDN)); // $NON-NLS-1$
                xmlBuffer.tag("comparefilter",getPropertyAsString(COMPAREFILT)); // $NON-NLS-1$
                NamingEnumeration<SearchResult> cmp=null;
                try {
                    res.sampleStart();
                    cmp = LdapExtClient.compare(dirContext, getPropertyAsString(COMPAREFILT),
                            getPropertyAsString(COMPAREDN));
                    if (!cmp.hasMore()) {
                        res.setResponseCode("5"); // $NON-NLS-1$
                        res.setResponseMessage("compareFalse");
                        isSuccessful = false;
                    }
                } finally {
                    res.sampleEnd();
                    if (cmp != null) {
                        cmp.close();
                    }
                }
            } else if (testType.equals(ADD)) {
                res.setSamplerData("Add object " + getBaseEntryDN());
                xmlBuffer.tag("attributes",getArguments().toString()); // $NON-NLS-1$
                xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
                addTest(dirContext, res);
            } else if (testType.equals(DELETE)) {
                res.setSamplerData("Delete object " + getBaseEntryDN());
                xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
                deleteTest(dirContext, res);
            } else if (testType.equals(MODIFY)) {
                res.setSamplerData("Modify object " + getBaseEntryDN());
                xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
                xmlBuffer.tag("attributes",getLDAPArguments().toString()); // $NON-NLS-1$
                modifyTest(dirContext, res);
            } else if (testType.equals(RENAME)) {
                res.setSamplerData("ModDN object " + getPropertyAsString(MODDDN) + " to " + getPropertyAsString(NEWDN));
                xmlBuffer.tag("dn",getPropertyAsString(MODDDN)); // $NON-NLS-1$
                xmlBuffer.tag("newdn",getPropertyAsString(NEWDN)); // $NON-NLS-1$
                renameTest(dirContext, res);
            } else if (testType.equals(SEARCH)) {
                final String            scopeStr = getScope();
                final int               scope = getScopeAsInt();
                final String searchFilter = getPropertyAsString(SEARCHFILTER);
                final String searchBase = getPropertyAsString(SEARCHBASE);
                final String timeLimit = getTimelim();
                final String countLimit = getCountlim();

                res.setSamplerData("Search with filter " + searchFilter);
                xmlBuffer.tag("searchfilter",searchFilter); // $NON-NLS-1$
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("searchbase",searchBase);// $NON-NLS-1$
                xmlBuffer.tag("scope" , scopeStr); // $NON-NLS-1$
                xmlBuffer.tag("countlimit",countLimit); // $NON-NLS-1$
                xmlBuffer.tag("timelimit",timeLimit); // $NON-NLS-1$

                NamingEnumeration<SearchResult> srch=null;
                try {
                    res.sampleStart();
                    srch = LdapExtClient.searchTest(
                            dirContext, searchBase, searchFilter,
                            scope, getCountlimAsLong(),
                            getTimelimAsInt(),
                            getRequestAttributes(getAttrs()),
                            isRetobj(),
                            isDeref());
                    if (isParseFlag()) {
                        try {
                            xmlBuffer.openTag("searchresults"); // $NON-NLS-1$
                            writeSearchResults(xmlBuffer, srch);
                        } finally {
                            xmlBuffer.closeTag("searchresults"); // $NON-NLS-1$
                        }
                    } else {
                        xmlBuffer.tag("searchresults", // $NON-NLS-1$
                                "hasElements="+srch.hasMoreElements()); // $NON-NLS-1$
                    }
                } finally {
                    if (srch != null){
                        srch.close();
                    }
                    res.sampleEnd();
                }

            }

        } catch (NamingException ex) {
            //log.warn("DEBUG",ex);
// e.g. javax.naming.SizeLimitExceededException: [LDAP: error code 4 - Sizelimit Exceeded]; remaining name ''
//                                                123456789012345678901
            // TODO: tidy this up
            String returnData = ex.toString();
            final int indexOfLDAPErrCode = returnData.indexOf("LDAP: error code");
            if (indexOfLDAPErrCode >= 0) {
                res.setResponseMessage(returnData.substring(indexOfLDAPErrCode + 21, returnData
                        .indexOf("]"))); // $NON-NLS-1$
                res.setResponseCode(returnData.substring(indexOfLDAPErrCode + 17, indexOfLDAPErrCode + 19));
            } else {
                res.setResponseMessage(returnData);
                res.setResponseCode("800"); // $NON-NLS-1$
            }
            isSuccessful = false;
        } finally {
            xmlBuffer.closeTag("operation"); // $NON-NLS-1$
            xmlBuffer.tag("responsecode",res.getResponseCode()); // $NON-NLS-1$
            xmlBuffer.tag("responsemessage",res.getResponseMessage()); // $NON-NLS-1$
            res.setResponseData(xmlBuffer.toString(), null);
            res.setDataType(SampleResult.TEXT);
            res.setSuccessful(isSuccessful);
        }
        return res;
    }
View Full Code Here

    public TestXMLBuffer(String arg0) {
        super(arg0);
    }
   
    public void test1() throws Exception{
        XMLBuffer xb = new XMLBuffer();
        xb.openTag("start");
        assertEquals("<start></start>\n",xb.toString());
    }
View Full Code Here

        xb.openTag("start");
        assertEquals("<start></start>\n",xb.toString());
    }
   
    public void test2() throws Exception{
        XMLBuffer xb = new XMLBuffer();
        xb.tag("start","now");
        assertEquals("<start>now</start>\n",xb.toString());
    }
View Full Code Here

        XMLBuffer xb = new XMLBuffer();
        xb.tag("start","now");
        assertEquals("<start>now</start>\n",xb.toString());
    }
    public void test3() throws Exception{
        XMLBuffer xb = new XMLBuffer();
        xb.openTag("abc");
        xb.closeTag("abc");
        assertEquals("<abc></abc>\n",xb.toString());
    }
View Full Code Here

        xb.openTag("abc");
        xb.closeTag("abc");
        assertEquals("<abc></abc>\n",xb.toString());
    }
    public void test4() throws Exception{
        XMLBuffer xb = new XMLBuffer();
        xb.openTag("abc");
        try {
            xb.closeTag("abcd");
            fail("Should have caused IllegalArgumentException");
        } catch (IllegalArgumentException e) {
        }
    }
View Full Code Here

     * @param e
     *            !ToDo (Parameter description)
     * @return !ToDo (Return description)
     **************************************************************************/
    public SampleResult sample(Entry e) {
        XMLBuffer xmlBuffer = new XMLBuffer();
        xmlBuffer.openTag("ldapanswer"); // $NON-NLS-1$
        SampleResult res = new SampleResult();
        res.setResponseData("successfull".getBytes());
        res.setResponseMessage("Success"); // $NON-NLS-1$
        res.setResponseCode("0"); // $NON-NLS-1$
        res.setContentType("text/xml");// $NON-NLS-1$
        boolean isSuccessful = true;
        res.setSampleLabel(getName());
        LdapExtClient temp_client = (LdapExtClient) ldapConnections.get(getThreadName());
        DirContext dirContext = (DirContext) ldapContexts.get(getThreadName());
        if (temp_client == null) {
            temp_client = new LdapExtClient();
            try {
                dirContext = new InitialDirContext();
            } catch (NamingException err) {
                log.error("Ldap client context creation - ", err);
            }
            ldapConnections.put(getThreadName(), temp_client);
        }

        try {
            xmlBuffer.openTag("operation"); // $NON-NLS-1$
            final String testType = getTest();
            xmlBuffer.tag("opertype", testType); // $NON-NLS-1$
            log.debug("performing test: " + testType);
            if (testType.equals(UNBIND)) {
                res.setSamplerData("Unbind");
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
                unbindOp(temp_client, dirContext, res);
            } else if (testType.equals(BIND)) {
                res.setSamplerData("Bind as "+getUserDN());
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
                xmlBuffer.tag("connectionTO",getConnTimeOut()); // $NON-NLS-1$
                bindOp(temp_client, dirContext, res);
            } else if (testType.equals(SBIND)) {
                res.setSamplerData("SingleBind as "+getUserDN());
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$
                xmlBuffer.tag("connectionTO",getConnTimeOut()); // $NON-NLS-1$
                singleBindOp(res);
            } else if (testType.equals(COMPARE)) {
                res.setSamplerData("Compare "+getPropertyAsString(COMPAREFILT) + " "
                                + getPropertyAsString(COMPAREDN));
                xmlBuffer.tag("comparedn",getPropertyAsString(COMPAREDN)); // $NON-NLS-1$
                xmlBuffer.tag("comparefilter",getPropertyAsString(COMPAREFILT)); // $NON-NLS-1$
                NamingEnumeration cmp=null;
                try {
                    res.sampleStart();
                    cmp = temp_client.compare(dirContext, getPropertyAsString(COMPAREFILT),
                            getPropertyAsString(COMPAREDN));
                    if (!cmp.hasMore()) {
                        res.setResponseCode("5"); // $NON-NLS-1$
                        res.setResponseMessage("compareFalse");
                        isSuccessful = false;
                    }
                } finally {
                    res.sampleEnd();
                    if (cmp != null) {
                        cmp.close();
                    }
                }
            } else if (testType.equals(ADD)) {
                res.setSamplerData("Add object " + getBaseEntryDN());
                xmlBuffer.tag("attributes",getArguments().toString()); // $NON-NLS-1$
                xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
                addTest(temp_client, dirContext, res);
            } else if (testType.equals(DELETE)) {
                res.setSamplerData("Delete object " + getBaseEntryDN());
                xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
                deleteTest(temp_client, dirContext, res);
            } else if (testType.equals(MODIFY)) {
                res.setSamplerData("Modify object " + getBaseEntryDN());
                xmlBuffer.tag("dn",getBaseEntryDN()); // $NON-NLS-1$
                xmlBuffer.tag("attributes",getLDAPArguments().toString()); // $NON-NLS-1$
                modifyTest(temp_client, dirContext, res);
            } else if (testType.equals(RENAME)) {
                res.setSamplerData("ModDN object " + getPropertyAsString(MODDDN) + " to " + getPropertyAsString(NEWDN));
                xmlBuffer.tag("dn",getPropertyAsString(MODDDN)); // $NON-NLS-1$
                xmlBuffer.tag("newdn",getPropertyAsString(NEWDN)); // $NON-NLS-1$
                renameTest(temp_client, dirContext, res);
            } else if (testType.equals(SEARCH)) {
                final String            scopeStr = getScope();
                final int               scope = getScopeAsInt();
                final String searchFilter = getPropertyAsString(SEARCHFILTER);
                final String searchBase = getPropertyAsString(SEARCHBASE);
                final String timeLimit = getTimelim();
                final String countLimit = getCountlim();

                res.setSamplerData("Search with filter " + searchFilter);
                xmlBuffer.tag("searchfilter",searchFilter); // $NON-NLS-1$
                xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
                xmlBuffer.tag("searchbase",searchBase);// $NON-NLS-1$
                xmlBuffer.tag("scope" , scopeStr); // $NON-NLS-1$
                xmlBuffer.tag("countlimit",countLimit); // $NON-NLS-1$
                xmlBuffer.tag("timelimit",timeLimit); // $NON-NLS-1$

                NamingEnumeration srch=null;
                try {
                    res.sampleStart();
                    srch = temp_client.searchTest(
                            dirContext, searchBase, searchFilter,
                            scope, getCountlimAsLong(),
                            getTimelimAsInt(),
                            getRequestAttributes(getAttrs()),
                            isRetobj(),
                            isDeref());
                    if (isParseFlag()) {
                        try {
                            xmlBuffer.openTag("searchresults"); // $NON-NLS-1$
                            writeSearchResults(xmlBuffer, srch);
                        } finally {
                            xmlBuffer.closeTag("searchresults"); // $NON-NLS-1$
                        }
                    } else {
                        xmlBuffer.tag("searchresults", // $NON-NLS-1$
                                "hasElements="+srch.hasMoreElements()); // $NON-NLS-1$
                    }
                } finally {
                    if (srch != null){
                        srch.close();
                    }
                    res.sampleEnd();
                }

            }

        } catch (NamingException ex) {
            //log.warn("DEBUG",ex);
// e.g. javax.naming.SizeLimitExceededException: [LDAP: error code 4 - Sizelimit Exceeded]; remaining name ''
//                                                123456789012345678901
            // TODO: tidy this up
            String returnData = ex.toString();
            final int indexOfLDAPErrCode = returnData.indexOf("LDAP: error code");
            if (indexOfLDAPErrCode >= 0) {
                res.setResponseMessage(returnData.substring(indexOfLDAPErrCode + 21, returnData
                        .indexOf("]"))); // $NON-NLS-1$
                res.setResponseCode(returnData.substring(indexOfLDAPErrCode + 17, indexOfLDAPErrCode + 19));
            } else {
                res.setResponseMessage(returnData);
                res.setResponseCode("800"); // $NON-NLS-1$
            }
            isSuccessful = false;
        } finally {
            xmlBuffer.closeTag("operation"); // $NON-NLS-1$
            xmlBuffer.tag("responsecode",res.getResponseCode()); // $NON-NLS-1$
            xmlBuffer.tag("responsemessage",res.getResponseMessage()); // $NON-NLS-1$
            res.setResponseData(xmlBuffer.toString().getBytes());
            res.setDataType(SampleResult.TEXT);
            res.setSuccessful(isSuccessful);
        }
        return res;
    }
View Full Code Here

TOP

Related Classes of org.apache.jorphan.util.XMLBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.