com.estafeta.flujos.DemoMain.java Source code

Java tutorial

Introduction

Here is the source code for com.estafeta.flujos.DemoMain.java

Source

/**
* Copyright 2016 Nuuptech
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package com.estafeta.flujos;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import javax.jms.Queue;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class DemoMain {

    private static final String APPLOCATION_CONTEXT_FILE = "app-context.xml";
    private static final String JMS_MESSAGE_SENDER_BEAN_NAME = "jmsMessageSender";
    private static final String JMS_DESTINATION_NAME = "MQ.INPUT_SOAP";
    private static final String MOCK_INPUT_FILE = "RI_SOAP.xml";
    private static final String UTF_8_CHARSET = "UTF-8";

    /**
     * Clase principal del proyecto
     * @param args argumentos de linea de comandos
     */
    public static void main(String[] args) {
        // init spring context
        ApplicationContext ctx = new ClassPathXmlApplicationContext(APPLOCATION_CONTEXT_FILE);
        // get bean from context
        JmsMessageSender jmsMessageSender = (JmsMessageSender) ctx.getBean(JMS_MESSAGE_SENDER_BEAN_NAME);
        // send to a code specified destination
        Queue queue = new ActiveMQQueue(JMS_DESTINATION_NAME);
        try {
            ClassLoader classLoader = DemoMain.class.getClassLoader();
            FileInputStream fileInputStream = new FileInputStream(
                    classLoader.getResource(MOCK_INPUT_FILE).getFile());
            BufferedReader bufferedReader = new BufferedReader(
                    new InputStreamReader(fileInputStream, Charset.forName(UTF_8_CHARSET)));
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                jmsMessageSender.send(queue, line);
            }
            fileInputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // close spring application context
        ((ClassPathXmlApplicationContext) ctx).close();
    }
}