Example usage for org.apache.commons.lang StringUtils isNotBlank

List of usage examples for org.apache.commons.lang StringUtils isNotBlank

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils isNotBlank.

Prototype

public static boolean isNotBlank(String str) 

Source Link

Document

Checks if a String is not empty (""), not null and not whitespace only.

Usage

From source file:Main.java

public static void main(String[] args) {
    String var1 = null;
    String var2 = "";
    String var3 = "    \t\t\t";
    String var4 = "Hello World";

    System.out.println("var1 is blank? = " + StringUtils.isBlank(var1));
    System.out.println("var2 is blank? = " + StringUtils.isBlank(var2));
    System.out.println("var3 is blank? = " + StringUtils.isBlank(var3));
    System.out.println("var4 is blank? = " + StringUtils.isBlank(var4));

    System.out.println("var1 is not blank? = " + StringUtils.isNotBlank(var1));
    System.out.println("var2 is not blank? = " + StringUtils.isNotBlank(var2));
    System.out.println("var3 is not blank? = " + StringUtils.isNotBlank(var3));
    System.out.println("var4 is not blank? = " + StringUtils.isNotBlank(var4));

    System.out.println("var1 is empty? = " + StringUtils.isEmpty(var1));
    System.out.println("var2 is empty? = " + StringUtils.isEmpty(var2));
    System.out.println("var3 is empty? = " + StringUtils.isEmpty(var3));
    System.out.println("var4 is empty? = " + StringUtils.isEmpty(var4));

    System.out.println("var1 is not empty? = " + StringUtils.isNotEmpty(var1));
    System.out.println("var2 is not empty? = " + StringUtils.isNotEmpty(var2));
    System.out.println("var3 is not empty? = " + StringUtils.isNotEmpty(var3));
    System.out.println("var4 is not empty? = " + StringUtils.isNotEmpty(var4));
}

From source file:Main.java

public static void main(String[] args) {
    String one = "";
    String two = "\t\r\n";
    String three = "     ";
    String four = null;//from   w  ww .  j ava  2s .c om
    String five = "four four two";

    // We can use StringUtils class for checking if a string is empty or not
    // using StringUtils.isBlank() method. This method will return true if
    // the tested string is empty, contains white space only or null.
    System.out.println("Is one empty? " + StringUtils.isBlank(one));
    System.out.println("Is two empty? " + StringUtils.isBlank(two));
    System.out.println("Is three empty? " + StringUtils.isBlank(three));
    System.out.println("Is four empty? " + StringUtils.isBlank(four));
    System.out.println("Is five empty? " + StringUtils.isBlank(five));

    // On the other side, the StringUtils.isNotBlank() methods complement
    // the previous method. It will check is a tested string is not empty.
    System.out.println("Is one not empty? " + StringUtils.isNotBlank(one));
    System.out.println("Is two not empty? " + StringUtils.isNotBlank(two));
    System.out.println("Is three not empty? " + StringUtils.isNotBlank(three));
    System.out.println("Is four not empty? " + StringUtils.isNotBlank(four));
    System.out.println("Is five not empty? " + StringUtils.isNotBlank(five));
}

From source file:com.metamug.mtg.s3.uploader.S3Uploader.java

public static void main(String[] args) {
    String path = args[0];//from ww w .  ja va 2s.c o  m
    String uri = args[1];
    String url = "";
    if (StringUtils.isNotBlank(path)) {
        byte[] buffer = getBytes(path);
        url = upload(new ByteArrayInputStream(buffer), buffer.length, uri);
    }
    System.out.println("");
}

From source file:com.xx_dev.speed_test.SpeedTestClient.java

public static void main(String[] args) {
    EventLoopGroup group = new NioEventLoopGroup();
    try {//from   www.ja  v a 2 s . com

        URL url = new URL(args[0]);

        boolean isSSL = false;
        String host = url.getHost();
        int port = 80;
        if (StringUtils.equals(url.getProtocol(), "https")) {
            port = 443;
            isSSL = true;
        }

        if (url.getPort() > 0) {
            port = url.getPort();
        }

        String path = url.getPath();
        if (StringUtils.isNotBlank(url.getQuery())) {
            path += "?" + url.getQuery();
        }

        PrintWriter resultPrintWriter = null;
        if (StringUtils.isNotBlank(args[1])) {
            String resultFile = args[1];

            resultPrintWriter = new PrintWriter(
                    new OutputStreamWriter(new FileOutputStream(resultFile, false), "UTF-8"));
        }

        Bootstrap b = new Bootstrap();
        b.group(group).channel(NioSocketChannel.class)
                .handler(new SpeedTestHttpClientChannelInitializer(isSSL, resultPrintWriter));

        // Make the connection attempt.
        Channel ch = b.connect(host, port).sync().channel();

        // Prepare the HTTP request.
        HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, path);
        request.headers().set(HttpHeaders.Names.HOST, host);
        request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
        //request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);

        // Send the HTTP request.
        ch.writeAndFlush(request);

        // Wait for the server to close the connection.
        ch.closeFuture().sync();

        if (resultPrintWriter != null) {
            resultPrintWriter.close();
        }

    } catch (InterruptedException e) {
        logger.error(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        logger.error(e.getMessage(), e);
    } catch (UnsupportedEncodingException e) {
        logger.error(e.getMessage(), e);
    } catch (MalformedURLException e) {
        logger.error(e.getMessage(), e);
    } finally {
        group.shutdownGracefully();
    }
}

From source file:com.mosso.client.cloudfiles.sample.FilesList.java

public static void main(String args[]) {
    //Build the command line options
    Options options = addCommandLineOptions();

    if (args.length <= 0)
        printHelp(options);/*from   w  w  w  . j  a v a2 s  .c om*/

    CommandLineParser parser = new GnuParser();
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("help"))
            printHelp(options);

        if (line.hasOption("containersOnly")) {
            if (line.hasOption("H"))
                printContainers(true);
            else
                printContainers(false);
        } else if (line.hasOption("all")) {
            if (line.hasOption("H"))
                printContainersAll(true);
            else
                printContainersAll(false);
        } //if (line.hasOption("all"))
        else if (line.hasOption("container")) {
            String containerName = line.getOptionValue("container");
            if (StringUtils.isNotBlank(containerName)) {
                if (line.hasOption("H"))
                    printContainer(containerName, true);
                else
                    printContainer(containerName, false);
            }
        } //if (line.hasOption("container"))
        else if (line.hasOption("H")) {
            System.out.println(
                    "This option needs to be used in conjunction with another option that lists objects or container.");
        }
    } catch (ParseException err) {
        System.err.println("Please see the logs for more details. Error Message: " + err.getMessage());
        err.printStackTrace(System.err);
    } //catch( ParseException err )
    catch (FilesException err) {
        System.err.println("Please see the logs for more details. Error Message: " + err.getMessage());
    } //catch (FilesAuthorizationException err)

    catch (IOException err) {
        System.err.println("Please see the logs for more details. Error Message: " + err.getMessage());
    } //catch ( IOException err)
}

From source file:com.rackspacecloud.client.cloudfiles.sample.FilesList.java

public static void main(String args[]) {
    //Build the command line options
    Options options = addCommandLineOptions();

    if (args.length <= 0)
        printHelp(options);/*from   w  w w .  j  a v a 2  s .com*/

    CommandLineParser parser = new GnuParser();
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("help"))
            printHelp(options);

        if (line.hasOption("containersOnly")) {
            if (line.hasOption("H"))
                printContainers(true);
            else
                printContainers(false);
        } else if (line.hasOption("all")) {
            if (line.hasOption("H"))
                printContainersAll(true);
            else
                printContainersAll(false);
        } //if (line.hasOption("all"))
        else if (line.hasOption("container")) {
            String containerName = line.getOptionValue("container");
            if (StringUtils.isNotBlank(containerName)) {
                if (line.hasOption("H"))
                    printContainer(containerName, true);
                else
                    printContainer(containerName, false);
            }
        } //if (line.hasOption("container"))
        else if (line.hasOption("H")) {
            System.out.println(
                    "This option needs to be used in conjunction with another option that lists objects or container.");
        }
    } catch (ParseException err) {
        System.err.println("Please see the logs for more details. Error Message: " + err.getMessage());
        err.printStackTrace(System.err);
    } //catch( ParseException err )
    catch (HttpException err) {
        System.err.println("Please see the logs for more details. Error Message: " + err.getMessage());
        err.printStackTrace(System.err);
    } //catch( ParseException err )

    catch (IOException err) {
        System.err.println("Please see the logs for more details. Error Message: " + err.getMessage());
    } //catch ( IOException err)
}

From source file:com.mosso.client.cloudfiles.sample.FilesCopy.java

public static void main(String args[]) throws NoSuchAlgorithmException, FilesException {
    //Build the command line options
    Options options = addCommandLineOptions();

    if (args.length <= 0)
        printHelp(options);//from w w w .ja  v a 2s. c o  m

    CommandLineParser parser = new GnuParser();
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("help"))
            printHelp(options);

        if (line.hasOption("file") && line.hasOption("folder")) {
            System.err.println("Can not use both -file and -folder on the command line at the same time.");
            System.exit(-1);
        } //if (line.hasOption("file") && line.hasOption("folder"))

        if (line.hasOption("download")) {
            if (line.hasOption("folder")) {
                String localFolder = FilenameUtils.normalize(line.getOptionValue("folder"));
                String containerName = null;
                if (StringUtils.isNotBlank(localFolder)) {
                    File localFolderObj = new File(localFolder);
                    if (localFolderObj.exists() && localFolderObj.isDirectory()) {
                        if (line.hasOption("container")) {
                            containerName = line.getOptionValue("container");
                            if (!StringUtils.isNotBlank(containerName)) {
                                System.err.println(
                                        "You must provide a valid value for the  Container to upload to !");
                                System.exit(-1);
                            } //if (!StringUtils.isNotBlank(ontainerName))                            
                        } else {
                            System.err.println(
                                    "You must provide the -container for a copy operation to work as expected.");
                            System.exit(-1);
                        }

                        System.out.println("Downloading all objects from: " + containerName
                                + " to local folder: " + localFolder);

                        getContainerObjects(localFolderObj, containerName);

                    } else {
                        if (!localFolderObj.exists()) {
                            System.err.println("The local folder: " + localFolder
                                    + " does not exist.  Create it first and then run this command.");
                        }

                        if (!localFolderObj.isDirectory()) {
                            System.err.println(
                                    "The local folder name supplied : " + localFolder + " is not a folder !");
                        }

                        System.exit(-1);
                    }
                }
            }
            System.exit(0);
        } //if (line.hasOption("download"))

        if (line.hasOption("folder")) {
            String containerName = null;
            String folderPath = null;

            if (line.hasOption("container")) {
                containerName = line.getOptionValue("container");
                if (!StringUtils.isNotBlank(containerName)) {
                    System.err.println("You must provide a valid value for the  Container to upload to !");
                    System.exit(-1);
                } //if (!StringUtils.isNotBlank(containerName))

            } else {
                System.err.println("You must provide the -container for a copy operation to work as expected.");
                System.exit(-1);
            }

            folderPath = line.getOptionValue("folder");
            if (StringUtils.isNotBlank(folderPath)) {
                File folder = new File(FilenameUtils.normalize(folderPath));
                if (folder.isDirectory()) {
                    if (line.hasOption("z")) {
                        System.out.println("Zipping: " + folderPath);
                        System.out.println("Nested folders are ignored !");

                        File zipedFolder = zipFolder(folder);
                        String mimeType = FilesConstants.getMimetype(ZIPEXTENSION);
                        copyToCreateContainerIfNeeded(zipedFolder, mimeType, containerName);
                    } else {
                        File[] files = folder.listFiles();
                        for (File f : files) {
                            String mimeType = FilesConstants
                                    .getMimetype(FilenameUtils.getExtension(f.getName()));
                            System.out.println("Uploading :" + f.getName() + " to " + folder.getName());
                            copyToCreateContainerIfNeeded(f, mimeType, containerName);
                            System.out.println(
                                    "Upload :" + f.getName() + " to " + folder.getName() + " completed.");
                        }
                    }
                } else {
                    System.err.println("You must provide a valid folder value for the -folder option !");
                    System.err.println("The value provided is: " + FilenameUtils.normalize(folderPath));
                    System.exit(-1);
                }

            }
        } //if (line.hasOption("folder"))

        if (line.hasOption("file")) {
            String containerName = null;
            String fileNamePath = null;

            if (line.hasOption("container")) {
                containerName = line.getOptionValue("container");
                if (!StringUtils.isNotBlank(containerName) || containerName.indexOf('/') != -1) {
                    System.err.println("You must provide a valid value for the  Container to upload to !");
                    System.exit(-1);
                } //if (!StringUtils.isNotBlank(containerName))
            } else {
                System.err.println("You must provide the -container for a copy operation to work as expected.");
                System.exit(-1);
            }

            fileNamePath = line.getOptionValue("file");
            if (StringUtils.isNotBlank(fileNamePath)) {
                String fileName = FilenameUtils.normalize(fileNamePath);
                String fileExt = FilenameUtils.getExtension(fileNamePath);
                String mimeType = FilesConstants.getMimetype(fileExt);
                File file = new File(fileName);

                if (line.hasOption("z")) {
                    logger.info("Zipping " + fileName);
                    if (!file.isDirectory()) {
                        File zippedFile = zipFile(file);
                        mimeType = FilesConstants.getMimetype(ZIPEXTENSION);
                        copyTo(zippedFile, mimeType, containerName);
                        zippedFile.delete();
                    }

                } //if (line.hasOption("z"))
                else {

                    logger.info("Uploading " + fileName + ".");
                    if (!file.isDirectory())
                        copyTo(file, mimeType, containerName);
                    else {
                        System.err.println(
                                "The path you provided is a folder.  For uploading folders use the -folder option.");
                        System.exit(-1);
                    }
                }
            } //if (StringUtils.isNotBlank(file))
            else {
                System.err.println("You must provide a valid value for the file to upload !");
                System.exit(-1);
            }
        } //if (line.hasOption("file"))
    } //end try        
    catch (ParseException err) {
        System.err.println("Please see the logs for more details. Error Message: " + err.getMessage());
        err.printStackTrace(System.err);
    } //catch( ParseException err )
    catch (FilesAuthorizationException err) {
        logger.fatal("FilesAuthorizationException : Failed to login to your  account !" + err);
        System.err.println("Please see the logs for more details. Error Message: " + err.getMessage());
    } //catch (FilesAuthorizationException err)

    catch (IOException err) {
        logger.fatal("IOException : " + err);
        System.err.println("Please see the logs for more details. Error Message: " + err.getMessage());
    } //catch ( IOException err)
}

From source file:com.rackspacecloud.client.cloudfiles.sample.FilesCopy.java

public static void main(String args[]) throws NoSuchAlgorithmException, FilesException {
    //Build the command line options
    Options options = addCommandLineOptions();

    if (args.length <= 0)
        printHelp(options);//from   www  .jav  a  2  s . c o  m

    CommandLineParser parser = new GnuParser();
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("help"))
            printHelp(options);

        if (line.hasOption("file") && line.hasOption("folder")) {
            System.err.println("Can not use both -file and -folder on the command line at the same time.");
            System.exit(-1);
        } //if (line.hasOption("file") && line.hasOption("folder"))

        if (line.hasOption("download")) {
            if (line.hasOption("folder")) {
                String localFolder = FilenameUtils.normalize(line.getOptionValue("folder"));
                String containerName = null;
                if (StringUtils.isNotBlank(localFolder)) {
                    File localFolderObj = new File(localFolder);
                    if (localFolderObj.exists() && localFolderObj.isDirectory()) {
                        if (line.hasOption("container")) {
                            containerName = line.getOptionValue("container");
                            if (!StringUtils.isNotBlank(containerName)) {
                                System.err.println(
                                        "You must provide a valid value for the  Container to upload to !");
                                System.exit(-1);
                            } //if (!StringUtils.isNotBlank(ontainerName))                            
                        } else {
                            System.err.println(
                                    "You must provide the -container for a copy operation to work as expected.");
                            System.exit(-1);
                        }

                        System.out.println("Downloading all objects from: " + containerName
                                + " to local folder: " + localFolder);

                        getContainerObjects(localFolderObj, containerName);

                    } else {
                        if (!localFolderObj.exists()) {
                            System.err.println("The local folder: " + localFolder
                                    + " does not exist.  Create it first and then run this command.");
                        }

                        if (!localFolderObj.isDirectory()) {
                            System.err.println(
                                    "The local folder name supplied : " + localFolder + " is not a folder !");
                        }

                        System.exit(-1);
                    }
                }
            }
            System.exit(0);
        } //if (line.hasOption("download"))

        if (line.hasOption("folder")) {
            String containerName = null;
            String folderPath = null;

            if (line.hasOption("container")) {
                containerName = line.getOptionValue("container");
                if (!StringUtils.isNotBlank(containerName)) {
                    System.err.println("You must provide a valid value for the  Container to upload to !");
                    System.exit(-1);
                } //if (!StringUtils.isNotBlank(containerName))

            } else {
                System.err.println("You must provide the -container for a copy operation to work as expected.");
                System.exit(-1);
            }

            folderPath = line.getOptionValue("folder");
            if (StringUtils.isNotBlank(folderPath)) {
                File folder = new File(FilenameUtils.normalize(folderPath));
                if (folder.isDirectory()) {
                    if (line.hasOption("z")) {
                        System.out.println("Zipping: " + folderPath);
                        System.out.println("Nested folders are ignored !");

                        File zipedFolder = zipFolder(folder);
                        String mimeType = FilesConstants.getMimetype(ZIPEXTENSION);
                        copyToCreateContainerIfNeeded(zipedFolder, mimeType, containerName);
                    } else {
                        File[] files = folder.listFiles();
                        for (File f : files) {
                            String mimeType = FilesConstants
                                    .getMimetype(FilenameUtils.getExtension(f.getName()));
                            System.out.println("Uploading :" + f.getName() + " to " + folder.getName());
                            copyToCreateContainerIfNeeded(f, mimeType, containerName);
                            System.out.println(
                                    "Upload :" + f.getName() + " to " + folder.getName() + " completed.");
                        }
                    }
                } else {
                    System.err.println("You must provide a valid folder value for the -folder option !");
                    System.err.println("The value provided is: " + FilenameUtils.normalize(folderPath));
                    System.exit(-1);
                }

            }
        } //if (line.hasOption("folder"))

        if (line.hasOption("file")) {
            String containerName = null;
            String fileNamePath = null;

            if (line.hasOption("container")) {
                containerName = line.getOptionValue("container");
                if (!StringUtils.isNotBlank(containerName) || containerName.indexOf('/') != -1) {
                    System.err.println("You must provide a valid value for the  Container to upload to !");
                    System.exit(-1);
                } //if (!StringUtils.isNotBlank(containerName))
            } else {
                System.err.println("You must provide the -container for a copy operation to work as expected.");
                System.exit(-1);
            }

            fileNamePath = line.getOptionValue("file");
            if (StringUtils.isNotBlank(fileNamePath)) {
                String fileName = FilenameUtils.normalize(fileNamePath);
                String fileExt = FilenameUtils.getExtension(fileNamePath);
                String mimeType = FilesConstants.getMimetype(fileExt);
                File file = new File(fileName);

                if (line.hasOption("z")) {
                    logger.info("Zipping " + fileName);
                    if (!file.isDirectory()) {
                        File zippedFile = zipFile(file);
                        mimeType = FilesConstants.getMimetype(ZIPEXTENSION);
                        copyTo(zippedFile, mimeType, containerName);
                        zippedFile.delete();
                    }

                } //if (line.hasOption("z"))
                else {

                    logger.info("Uploading " + fileName + ".");
                    if (!file.isDirectory())
                        copyTo(file, mimeType, containerName);
                    else {
                        System.err.println(
                                "The path you provided is a folder.  For uploading folders use the -folder option.");
                        System.exit(-1);
                    }
                }
            } //if (StringUtils.isNotBlank(file))
            else {
                System.err.println("You must provide a valid value for the file to upload !");
                System.exit(-1);
            }
        } //if (line.hasOption("file"))
    } //end try        
    catch (ParseException err) {
        System.err.println("Please see the logs for more details. Error Message: " + err.getMessage());
        err.printStackTrace(System.err);
    } //catch( ParseException err )
    catch (FilesAuthorizationException err) {
        logger.fatal("FilesAuthorizationException : Failed to login to your  account !" + err);
        System.err.println("Please see the logs for more details. Error Message: " + err.getMessage());
    } //catch (FilesAuthorizationException err)

    catch (Exception err) {
        logger.fatal("IOException : " + err);
        System.err.println("Please see the logs for more details. Error Message: " + err.getMessage());
    } //catch ( IOException err)
}

From source file:at.tuwien.ifs.somtoolbox.apps.helper.VectorSimilarityWriter.java

public static void main(String[] args) throws ClassNotFoundException, InstantiationException,
        IllegalAccessException, IOException, SOMToolboxException {
    JSAPResult config = OptionFactory.parseResults(args, OptionFactory.OPTIONS_INPUT_SIMILARITY_COMPUTER);
    String inputVectorDistanceMatrix = config.getString("inputVectorDistanceMatrix");
    String inputVectorFileName = config.getString("inputVectorFile");
    int numNeighbours = config.getInt("numberNeighbours");
    String outputFormat = config.getString("outputFormat");

    InputVectorDistanceMatrix matrix = null;
    InputData data = new SOMLibSparseInputData(inputVectorFileName);

    if (StringUtils.isNotBlank(inputVectorDistanceMatrix)) {
        matrix = InputVectorDistanceMatrix.initFromFile(inputVectorDistanceMatrix);
    } else {/*from  w  w w  .j  a v a2s  . co m*/
        String metricName = config.getString("metric");
        DistanceMetric metric = AbstractMetric.instantiate(metricName);
        matrix = new LeightWeightMemoryInputVectorDistanceMatrix(data, metric);
    }

    String outputFileName = config.getString("output");
    PrintWriter w = FileUtils.openFileForWriting("Similarity File", outputFileName);

    if (outputFormat.equals("SAT-DB")) {
        // find feature type
        String type = "";
        if (inputVectorFileName.endsWith(".rh") || inputVectorFileName.endsWith(".rp")
                || inputVectorFileName.endsWith(".ssd")) {
            type = "_" + inputVectorFileName.substring(inputVectorFileName.lastIndexOf(".") + 1);
        }
        w.println("INSERT INTO `sat_track_similarity_ifs" + type
                + "` (`TRACKID`, `SIMILARITYCOUNT`, `SIMILARITYIDS`) VALUES ");
    }

    int numVectors = matrix.numVectors();
    // numVectors = 10; // for testing
    StdErrProgressWriter progress = new StdErrProgressWriter(numVectors, "Writing similarities for vector ", 1);
    for (int i = 0; i < numVectors; i++) {
        int[] nearest = matrix.getNNearest(i, numNeighbours);
        if (outputFormat.equals("SAT-DB")) {
            w.print("  (" + i + " , NULL, '");
            for (int j = 0; j < nearest.length; j++) {
                String label = data.getLabel(nearest[j]);
                w.print(label.replace(".mp3", "")); // strip ending
                if (j + 1 < nearest.length) {
                    w.print(",");
                } else {
                    w.print("')");
                }
            }
            if (i + 1 < numVectors) {
                w.print(",");
            }
        } else {
            w.print(data.getLabel(i) + ",");
            for (int j = 0; j < nearest.length; j++) {
                w.print(data.getLabel(nearest[j]));
                if (j + 1 < nearest.length) {
                    w.print(",");
                }
            }
        }
        w.println();
        w.flush();
        progress.progress();
    }
    if (outputFormat.equals("SAT-DB")) {
        w.print(";");
    }
    w.flush();
    w.close();
}

From source file:com.hiperium.commons.client.soap.AthenticationDispatcherTest.java

/**
 * This class authenticates with the Hiperium Platform using JAXBContext and the selects user's home and
 * profile to access the system functions, and finally end the session. For all this lasts functions
 * we use SOAP messages with dispatchers and not JAXBContext.
 * //from w  w w.j ava  2  s.  c  om
 * We need to recall, that for JAXBContext we could not add a handler to add header security parameters that need
 * to be verified in every service call in the Hiperium Platform, and for that reason, we only use JAXBContext in
 * the authentication process that do not need this header validation in the SOAP message header.
 * 
 * @param args
 */
public static void main(String[] args) {
    try {
        URL authURL = new URL(AUTH_SERVICE_URL);
        // The NAMESPACE must be http://authentication.soap.web.hiperium.com/ and must not begin
        // with http://SEI.authentication.soap.web.hiperium.com. Furthermore, the service name
        // and service port name must end WSService and WSPort respectively in order to call the service.
        QName authServiceQName = new QName(AUTH_NAMESPACE, "UserAuthenticationWSService");
        QName authPortQName = new QName(AUTH_NAMESPACE, "UserAuthenticationWSPort");
        // The parameter class must be annotated with @XmlRootElement in order to function
        JAXBContext jaxbContext = JAXBContext.newInstance(UserAuthentication.class,
                UserAuthenticationResponse.class);
        Service authService = Service.create(authURL, authServiceQName);
        // When we use JAXBContext the dispatcher mode must be PAYLOAD and NOT MESSAGE mode
        Dispatch<Object> dispatch = authService.createDispatch(authPortQName, jaxbContext,
                Service.Mode.PAYLOAD);
        UserCredentialDTO credentialsDTO = new UserCredentialDTO("andres_solorzano85@hotmail.com", "andres123");
        UserAuthentication authenticateRequest = new UserAuthentication();
        authenticateRequest.setArg0(credentialsDTO);
        UserAuthenticationResponse authenticateResponse = (UserAuthenticationResponse) dispatch
                .invoke(authenticateRequest);
        String sessionId = authenticateResponse.getReturn();
        LOGGER.debug("SESSION ID: " + sessionId);

        // Verify if session ID exists
        if (StringUtils.isNotBlank(sessionId)) {
            // Select home and profile
            URL selectHomeURL = new URL(HOME_SELECTION_SERVICE_URL);
            Service selectHomeService = Service.create(selectHomeURL,
                    new QName(AUTH_NAMESPACE, "HomeSelectionWSService"));
            selectHomeService.setHandlerResolver(new ClientHandlerResolver(credentialsDTO.getEmail(),
                    CLIENT_APPLICATION_TOKEN, AuthenticationObjectFactory._SelectHome_QNAME));
            Dispatch<SOAPMessage> selectHomeDispatch = selectHomeService.createDispatch(
                    new QName(AUTH_NAMESPACE, "HomeSelectionWSPort"), SOAPMessage.class, Service.Mode.MESSAGE);
            CommonsUtil.addSessionHeaderParms(selectHomeDispatch, sessionId);
            HomeSelectionDTO homeSelectionDTO = new HomeSelectionDTO(1L, 1L);
            SOAPMessage response = selectHomeDispatch.invoke(createSelectHomeSOAPMessage(homeSelectionDTO));
            readSOAPMessageResponse(response);

            // End Session
            URL endSessionURL = new URL(END_SESSION_SERVICE_URL);
            QName endSessionServiceQName = new QName(GENERAL_NAMESPACE, "MenuWSService");
            QName endSessionPortQName = new QName(GENERAL_NAMESPACE, "MenuWSPort");
            Service endSessionService = Service.create(endSessionURL, endSessionServiceQName);
            endSessionService.setHandlerResolver(new ClientHandlerResolver(credentialsDTO.getEmail(),
                    CLIENT_APPLICATION_TOKEN, GeneralObjectFactory._EndSession_QNAME));
            Dispatch<SOAPMessage> endSessionDispatch = endSessionService.createDispatch(endSessionPortQName,
                    SOAPMessage.class, Service.Mode.MESSAGE);
            CommonsUtil.addSessionHeaderParms(endSessionDispatch, sessionId);
            response = endSessionDispatch.invoke(createEndSessionSOAPMessage());
            readSOAPMessageResponse(response);
        }
    } catch (MalformedURLException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (JAXBException e) {
        LOGGER.error(e.getMessage(), e);
    }
}