Category Archives: apache-commons

Apache common daemon procrun with batch file

i wrote a simple batch file which reads the configuration from a external file. the script looks like this:

@echo off


for /f "delims=" %%x in (test-config.txt) do (
    set "%%x" 
)

prunsrv.exe //IS//%SERVICE_NAME%

and my configuration like this:

SERVICE_NAME=TestService
PR_DESCRIPTION=test description

PR_CLASSPATH=TestService.jar

PR_STARTMODE=Java
PR_STARTCLASS=package.Starter

PR_JVM=auto
PR_STARTUP=auto

for some reason, the configuration are not applied at all while installing the service. this can be seen at the description for example, as it does not get set. does anyone know why the configuration is not applied?

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/beanutils/BeanMap

I am trying to use below code for comparing two object values and print the mismtach:

  BeanMap map = new BeanMap(ep);
  PropertyUtilsBean propUtils = new PropertyUtilsBean();
  for (Object propNameObject : map.keySet()) {
     String propertyName = (String) propNameObject;
     Object expectedValue = propUtils.getProperty(ep, propertyName);
     Object actualValue = propUtils.getProperty(ap, propertyName);
     if (!expectedValue.equals(actualValue)) {
        WorkloadGeneratorLogger.log("> " + propertyName
              + " is different (oldValue=\"" + expectedValue
              + "\", newValue=\"" + actualValue + "\")");
     }
  }

Getting below error while using beanMap:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/beanutils/BeanMap ..................... Caused by: java.lang.ClassNotFoundException:

org.apache.commons.beanutils.BeanMap

Below is my pom.xml entries for the same:

   <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>1.9.3</version>
    </dependency>
    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2.2</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.2</version>
    </dependency>

Not sure what is being missed here,I tried the same combination of jars suggested by below link:

java.lang.NoClassDefFoundError: org/apache/commons/collections/Transformer

http://commons.apache.org/proper/commons-beanutils/dependencies.html

Still unable to sort this out.

commons-beanutils: if set method return is this model, can’t get writeMethod [on hold]

private long payActualMoney; 

public long getPayActualMoney() {
  return this.payActualMoney;
}

public TAllocate setPayActualMoney(long payActualMoney) {
  this.payActualMoney = payActualMoney;
  setPayActualMoneyIsSet(true);
  return this;
}

PropertyUtils.getPropertyDescriptors not return payActualMoney 's writeMethod,and return an property 'setPayActualMoney'

Issues with CloseableHttpClient throwing NullPointerException

I am using the CloseableHttpClient to make an api call. However, I am getting the NullPointerException with the following stack trace:

NullPointerException
org.apache.logging.log4j.core.Logger.isEnabled(Logger.java:156)
org.apache.log4j.Category.isEnabledFor(Category.java:485)
org.apache.log4j.Category.isEnabledFor(Category.java:287)
org.apache.log4j.Category.log(Category.java:443)
org.apache.commons.logging.impl.Log4JLogger.debug(Log4JLogger.java:155)
org.apache.http.client.protocol.RequestAuthCache.process(RequestAuthCache.java:75)
org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:133)
org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:193)
org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)

I have looked for it but haven't found any concrete post regarding it. Any suggestions?

Apache Commons Codec

i missed my class on Apache Commons for java earlier this week and was wondering if someone could just help explain this code for me, can't find any tutorials on line specifically for this :/

Soundex s = new Soundex();
System.out.println("Soundex: " + s.encode(args[0]));


Nysiis n = new Nysiis();
System.out.println("Nysiis: " + n.encode(args[0]));

Caverphone2 c = new Caverphone2();
System.out.println("Caverphone2: " + c.encode(args[0]));

Metaphone m = new Metaphone();
System.out.println("Metaphone: " + m.encode(args[0]));

And also if there is different syntax for them . Thank you!

How to check incoming file transfer status in apache commons io monitor

I have implemented a simple file listener using Apache commons io monitor.I have also implemented a selenium script that simply do is download file into the pre hard coded path folder.That is totally working fine.My listener monitoring downloaded files and collect the necessary information.According to my requirement i should be able to stop the file listener once my selenium script is finished execution.To do that i must know that the incoming file transferring status to handle it better way.because i can not stop listener middle of the file transferring.(sometimes download file can be heavy so it will take some time to download).So how can i know that incoming file status in Apache commons io monitor before stop the file listener.If any one knows please let me know.

Sample code snippet

    public class SimpleTestMonitor {
    // A hardcoded path to a folder you are monitoring .
    public static final String FOLDER =
            "/home/skywalker/Desktop/simple-test-monitor/watchdir";

    public static void main(String[] args) throws Exception {
        // The monitor will perform polling on the folder every 5 seconds
        final long pollingInterval = 5 * 1000;

        File folder = new File(FOLDER);

        if (!folder.exists()) {
            // Test to see if monitored folder exists
            throw new RuntimeException("Directory not found: " + FOLDER);
        }

        FileAlterationObserver observer = new FileAlterationObserver(folder);
        FileAlterationMonitor monitor =
                new FileAlterationMonitor(pollingInterval);
        FileAlterationListener listener = new FileAlterationListenerAdaptor() {
            // Is triggered when a file is created in the monitored folder
            @Override
            public void onFileCreate(File file) {
                try {
                    // "file" is the reference to the newly created file
                    System.out.println("File created: "
                            + file.getCanonicalPath());
                } catch (IOException e) {
                    e.printStackTrace(System.err);
                }
            }

            // Is triggered when a file is deleted from the monitored folder
            @Override
            public void onFileDelete(File file) {
                try {
                    // "file" is the reference to the removed file
                    System.out.println("File removed: "
                            + file.getCanonicalPath());
                    // "file" does not exists anymore in the location
                    System.out.println("File still exists in location: "
                            + file.exists());
                } catch (IOException e) {
                    e.printStackTrace(System.err);
                }
            }
        };

        observer.addListener(listener);
        monitor.addObserver(observer);
        monitor.start();
    }
}

Reference