package com.testclient.controller;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import com.testclient.utils.HttpServletRequestUtils;

@Controller
public class RabbitmqController {
private static final Logger logger = Logger.getLogger(RabbitmqController.class);
	
	@RequestMapping(value="/sendrbmq" )
	@ResponseBody
	public void sendrbmq(HttpServletRequest request, HttpServletResponse response){
		
        String host=request.getParameter("host");
		String port=request.getParameter("port");
		String authname=request.getParameter("authname");
		String password=request.getParameter("password");
		String queue=request.getParameter("queue");
		String message=request.getParameter("message");
		String body="";
		try {
			body = HttpServletRequestUtils.getHttpServletRequestBody(request);
			body = body.trim().replace("\n", "");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			logger.error(e.getMessage());
		}
		if(null==host){
			host=HttpServletRequestUtils.getValueFromRequestInput(body,"host");
		}
		if(null==port){
			port=HttpServletRequestUtils.getValueFromRequestInput(body,"port");
		}
		if(null==authname){
			authname=HttpServletRequestUtils.getValueFromRequestInput(body,"authname");
		}
		if(null==password){
			password=HttpServletRequestUtils.getValueFromRequestInput(body,"password");
		}
		if(null==queue){
			queue=HttpServletRequestUtils.getValueFromRequestInput(body,"queue");
		}
		if(null==message){
			message=HttpServletRequestUtils.getValueFromRequestInput(body,"message");
		}
		if(host.isEmpty() || port.isEmpty() || authname.isEmpty() || password.isEmpty() || queue.isEmpty() || message.isEmpty()){
			try {
				response.getWriter().println("request parameter error!");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				logger.error(e.getMessage());
			}
		}else{
			Connection connection=null;
			Channel channel=null;
			try{
				ConnectionFactory factory = new ConnectionFactory();
				factory.setHost(host);
				factory.setPort(Integer.parseInt(port));
				factory.setUsername(authname);
				factory.setPassword(password);
		        connection = factory.newConnection();
		        channel = connection.createChannel();
		    	channel.basicPublish("", queue, null, message.getBytes());
		    	response.getWriter().println(" [x] Sent '" + message + "'");
			}catch(Exception e){
				logger.error(e.getMessage());
			}finally{
				/*关闭连接*/
		        try {
					channel.close();
					connection.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					logger.error(e.getMessage());
				} catch (TimeoutException e) {
					// TODO Auto-generated catch block
					logger.error(e.getMessage());
				}
			}
		}
	}
}

@@ -20,3148 +20,72 @@
 ent.
-controller;%0A%0Aimport java.io.IOException;%0Aimport java.util.concurrent.TimeoutException;%0A%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A%0Aimport org.apache.log4j.Logger;%0Aimport org.springframework.stereotype.Controller;%0Aimport org.springframework.web.bind.annotation.RequestMapping;%0Aimport org.springframework.web.bind.annotation.ResponseBody;%0A%0Aimport com.rabbitmq.client.Channel;%0Aimport com.rabbitmq.client.Connection;%0Aimport com.rabbitmq.client.ConnectionFactory;%0A%0Aimport com.testclient.utils.HttpServletRequestUtils;%0A%0A@Controller%0Apublic class RabbitmqController %7B%0Aprivate static final Logger logger = Logger.getLogger(RabbitmqController.class);%0A%09%0A%09@RequestMapping(value=%22/sendrbmq%22 )%0A%09@ResponseBody%0A%09public void sendrbmq(HttpServletRequest request, HttpServletResponse response)%7B%0A%09%09%0A        String host=request.getParameter(%22host%22);%0A%09%09String port=request.getParameter(%22port%22);%0A%09%09String authname=request.getParameter(%22authname%22);%0A%09%09String password=request.getParameter(%22password%22);%0A%09%09String queue=request.getParameter(%22queue%22);%0A%09%09String message=request.getParameter(%22message%22);%0A%09%09String body=%22%22;%0A%09%09try %7B%0A%09%09%09body = HttpServletRequestUtils.getHttpServletRequestBody(request);%0A%09%09%09body = body.trim().replace(%22%5Cn%22, %22%22);%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09logger.error(e.getMessage());%0A%09%09%7D%0A%09%09if(null==host)%7B%0A%09%09%09host=HttpServletRequestUtils.getValueFromRequestInput(body,%22host%22);%0A%09%09%7D%0A%09%09if(null==port)%7B%0A%09%09%09port=HttpServletRequestUtils.getValueFromRequestInput(body,%22port%22);%0A%09%09%7D%0A%09%09if(null==authname)%7B%0A%09%09%09authname=HttpServletRequestUtils.getValueFromRequestInput(body,%22authname%22);%0A%09%09%7D%0A%09%09if(null==password)%7B%0A%09%09%09password=HttpServletRequestUtils.getValueFromRequestInput(body,%22password%22);%0A%09%09%7D%0A%09%09if(null==queue)%7B%0A%09%09%09queue=HttpServletRequestUtils.getValueFromRequestInput(body,%22queue%22);%0A%09%09%7D%0A%09%09if(null==message)%7B%0A%09%09%09message=HttpServletRequestUtils.getValueFromRequestInput(body,%22message%22);%0A%09%09%7D%0A%09%09if(host.isEmpty() %7C%7C port.isEmpty() %7C%7C authname.isEmpty() %7C%7C password.isEmpty() %7C%7C queue.isEmpty() %7C%7C message.isEmpty())%7B%0A%09%09%09try %7B%0A%09%09%09%09response.getWriter().println(%22request parameter error!%22);%0A%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%09// TODO Auto-generated catch block%0A%09%09%09%09logger.error(e.getMessage());%0A%09%09%09%7D%0A%09%09%7Delse%7B%0A%09%09%09Connection connection=null;%0A%09%09%09Channel channel=null;%0A%09%09%09try%7B%0A%09%09%09%09ConnectionFactory factory = new ConnectionFactory();%0A%09%09%09%09factory.setHost(host);%0A%09%09%09%09factory.setPort(Integer.parseInt(port));%0A%09%09%09%09factory.setUsername(authname);%0A%09%09%09%09factory.setPassword(password);%0A%09%09        connection = factory.newConnection();%0A%09%09        channel = connection.createChannel();%0A%09%09    %09channel.basicPublish(%22%22, queue, null, message.getBytes());%0A%09%09    %09response.getWriter().println(%22 %5Bx%5D Sent '%22 + message + %22'%22);%0A%09%09%09%7Dcatch(Exception e)%7B%0A%09%09%09%09logger.error(e.getMessage());%0A%09%09%09%7Dfinally%7B%0A%09%09%09%09/*%E5%85%B3%E9%97%AD%E8%BF%9E%E6%8E%A5*/%0A%09%09        try %7B%0A%09%09%09%09%09channel.close();%0A%09%09%09%09%09connection.close();%0A%09%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%09%09// TODO Auto-generated catch block%0A%09%09%09%09%09logger.error(e.getMessage());%0A%09%09%09%09%7D catch (TimeoutException e) %7B%0A%09%09%09%09%09// TODO Auto-generated catch block%0A%09%09%09%09%09logger.error(e.getMessage());%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D
+enums;%0A%0Apublic interface PreReqPara %7B%0A%09String keyword=%22__PREAPI%22;
 %0A%7D%0A

Update PreReqPara.java