summaryrefslogtreecommitdiff
path: root/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util')
-rw-r--r--qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java130
-rw-r--r--qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java193
-rw-r--r--qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java155
-rw-r--r--qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/XMLWriter.java100
4 files changed, 0 insertions, 578 deletions
diff --git a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java b/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java
deleted file mode 100644
index d27980be05..0000000000
--- a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.qpid.info.util;
-
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.net.InetAddress;
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.UnknownHostException;
-
-/**
- *
- * An simple Http post class for qpid info service
- */
-public class HttpPoster implements Runnable
-{
- private final String _url;
-
- private final Hashtable<String, String> _header;
-
- private final List<String> _response = new ArrayList<String>();
-
- private final StringBuffer _buf;
-
- /**
- * Constructor
- *
- * @param props Properties containing the URL
- * @param buf Buffer containing the message to be posted
- */
- public HttpPoster(Properties props, StringBuffer buf)
- {
- _buf = buf;
- if (null != props)
- {
- _url = props.getProperty("http.url");
- _header = new Hashtable<String, String>();
- try
- {
- String hostname = InetAddress.getLocalHost().getHostName();
- _header.put("hostname", hostname);
- }
- catch (UnknownHostException e)
- {
- // Silently ignoring the error ;)
- }
- }
- else
- {
- _url = null;
- _header = null;
- }
- }
-
- /** Posts the message from the _buf StringBuffer to the http server */
- public void run()
- {
- if (null == _url)
- {
- return;
- }
- String line;
- URL urlDest;
- URLConnection urlConn;
- try
- {
- urlDest = new URL(_url);
- urlConn = urlDest.openConnection();
- urlConn.setDoOutput(true);
- urlConn.setUseCaches(false);
- for (Iterator<String> it = _header.keySet().iterator(); it.hasNext();)
- {
- String prop = it.next();
- urlConn.setRequestProperty(prop, _header.get(prop));
- }
- OutputStreamWriter wr =
- new OutputStreamWriter(urlConn.getOutputStream());
- wr.write(_buf.toString());
- wr.flush();
- // Get the response
- BufferedReader rd = new BufferedReader(new InputStreamReader(
- urlConn.getInputStream()));
- while ((line = rd.readLine()) != null)
- {
- _response.add(line);
- }
- }
- catch (Exception ex)
- {
- // Silently ignoring the error ;)
- }
- }
-
- /**
- * Retrieves the response from the http server
- *
- * @return List<String> response received from the http server
- */
- public List<String> get_response()
- {
- return _response;
- }
-
-}
diff --git a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java b/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java
deleted file mode 100644
index 60a025d322..0000000000
--- a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.qpid.info.util;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * This class is simple implementation of an ini file reader. It expects a
- * file with the following structure:
- *
- * ; global values, can be overwritten in sections
- * key1=value1
- * key2=value2
- *
- * [Section1]
- * key1=value1_new ; overwriting the global key1
- * key3=value3
- * key4=value4
- *
- * [Section2]
- * key5=value5
- * key6=value6
- * key7=value7
- *
- * Note: Commentaries are preceded by ; or # and are supported throughout
- * A commentary line at the end of section is interpreted as
- * a section end marker
- *
- * A structure <String,Properties> (section name, associated properties)
- * is generated as a result of processing the ini file.
- */
-public class IniFileReader
-{
- private final Map<String, Properties> _sections;
-
- private final String COMMENT_SEMICOLON = ";";
-
- private final String COMMENT_HASH = "#";
-
- enum State
- {
- IN_SECTION, OFF_SECTION, GLOBAL
- }
-
- /*
- * IniFileReader constructor
- */
-
- public IniFileReader()
- {
- _sections = new HashMap<String, Properties>();
- }
-
- /**
- * Cleans up the after comments or the empty spaces/tabs surrounding the given string
- *
- * @param str The String to be cleaned
- *
- * @return String Cleanup Version
- */
- private String cleanUp(String str)
- {
- if (str.contains(COMMENT_SEMICOLON))
- {
- str = str.substring(0, str.indexOf(COMMENT_SEMICOLON));
- }
- if (str.contains(COMMENT_HASH))
- {
- str = str.substring(0, str.indexOf(COMMENT_HASH));
- }
- return str.trim();
- }
-
- /**
- * Loads and parses the ini file with the full path specified in the argument
- *
- * @param fileName Full path to the ini file
- *
- * @throws IllegalArgumentException If the file cannot be processed
- */
- public void load(String fileName) throws IllegalArgumentException
- {
- if (!new File(fileName).isFile())
- {
- throw new IllegalArgumentException("File: " + fileName + " does not exist or cannot be read.");
- }
- State state = State.GLOBAL;
- String line;
- Properties sectionProps = new Properties();
- String sectionName = "";
- try
- {
- BufferedReader in = new BufferedReader(new FileReader(fileName));
- while ((line = in.readLine()) != null)
- {
- String str = cleanUp(line);
-
- // Did we get a section header?
- if (str.startsWith("["))
- {
- if (!str.endsWith("]"))
- {
- // Index of 1 to skip '['
- throw new IllegalArgumentException(str.substring(1)
- + " is not closed");
- }
-
- // We encountered a new section header
- if (state != State.IN_SECTION)
- {
- _sections.put(sectionName, sectionProps);
- sectionProps = new Properties();
- sectionName = str.replace("[", "").replace("]", "")
- .trim();
- state = State.IN_SECTION;
- }
- }
-
- // Any other line tested separately, ignore if out of a section
- // and add if in section
- if (str.length() == 0)
- {
- // We encountered a commented or an empty line, both cases
- // mean we are off the section
- if (state == State.IN_SECTION)
- {
- _sections.put(sectionName, sectionProps);
- state = State.OFF_SECTION;
- }
- }
- else
- {
- // proper line, add it to the props
- if (state != State.OFF_SECTION)
- {
- if (str.contains("="))
- {
- int ix = str.indexOf("=");
- sectionProps.put(str.substring(0, ix).trim(), str
- .substring(ix + 1).trim());
- }
- }
- }
- }
- in.close();
- }
- catch (IOException e)
- {
- _sections.clear();
- return;
- }
- if (state != State.OFF_SECTION)
- {
- _sections.put(sectionName, sectionProps);
- }
- }
-
- /**
- * Getter for the Sections Map
- *
- * @return Map<String,Properties> The parsed content of the ini file in this structure
- */
- public Map<String, Properties> getSections()
- {
- return _sections;
- }
-
-}
diff --git a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java b/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java
deleted file mode 100644
index 0f66085fc3..0000000000
--- a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- *
- */
-/**
- *
- * @author sorin
- *
- * An simple SOAP client for qpid info service
- */
-package org.apache.qpid.info.util;
-
-import java.io.BufferedWriter;
-import java.io.OutputStreamWriter;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.util.HashMap;
-import java.util.Properties;
-
-public class SoapClient
-{
-
- private final StringBuffer _xmlData;
-
- private final Properties _destprops;
-
- private final String _hostname;
-
- private final int _port;
-
- private final String _urlpath;
-
- private final String _soapenvelope;
-
- private final String _soapaction;
-
- private final StringBuffer _soapMessage = new StringBuffer();
-
-
- public SoapClient(HashMap<String, String> map, Properties destprops)
- {
- _destprops = destprops;
- _hostname = (String) _destprops.get("soap.hostname");
- _port = Integer.parseInt((String) _destprops.get("soap.port"));
- _urlpath = (String) destprops.get("soap.path");
- _soapenvelope = (String) destprops.get("soap.envelope");
- _soapaction = (String) destprops.get("soap.action");
- _xmlData = new StringBuffer(_soapenvelope);
- replaceVariables(map);
- }
-
- public StringBuffer getXMLData()
- {
- return _xmlData;
- }
-
- public StringBuffer getSoapMessage() {
- return _soapMessage;
- }
-
- public String getSoapEnvelope() {
- return _soapenvelope;
- }
-
- /**
- * Clears and sets new XML data
- * @param sb the new data to set
- */
- public void setXMLData(StringBuffer sb)
- {
- _xmlData.delete(0, _xmlData.length());
- _xmlData.append(sb);
- }
-
-
- public void replaceVariables(HashMap<String, String> vars)
- {
- int ix = 0;
- for (String var : vars.keySet())
- {
- while ((ix = _xmlData.indexOf("@" + var.toUpperCase())) >= 0)
- {
- _xmlData.replace(ix, ix + 1 + var.length(), vars.get(var));
- }
- }
- }
-
- public void replaceVariables(Properties varProps)
- {
- if (varProps == null)
- {
- return;
- }
- int ix = 0;
- for (Object var : varProps.keySet())
- {
- while ((ix = _xmlData.indexOf("@" + var)) >= 0)
- {
- _xmlData.replace(ix, ix + 1 + var.toString().length(), varProps
- .get(var).toString());
- }
- }
- }
-
-
- public void sendSOAPMessage()
- {
-
- try
- {
- InetAddress addr = InetAddress.getByName(_hostname);
- Socket sock = new Socket(addr, _port);
- StringBuffer sb = new StringBuffer();
- sb.append("POST " + _urlpath + " HTTP/1.1\r\n");
- sb.append("Host: " + _hostname + ":" + _port + "\r\n");
- sb.append("Content-Length: " + _xmlData.length() + "\r\n");
- sb.append("Content-Type: text/xml; charset=\"utf-8\"\r\n");
- sb.append("SOAPAction: \"urn:"+ _soapaction +"\"\r\n");
- sb.append("User-Agent: Axis2\r\n");
- sb.append("\r\n");
- // Send header
- BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock
- .getOutputStream(), "UTF-8"));
- synchronized(_soapMessage) {
- _soapMessage.setLength(0);
- _soapMessage.append(sb);
- _soapMessage.append(_xmlData);
- }
- // Send data
- wr.write(_soapMessage.toString());
- wr.flush();
- wr.close();
-
- } catch (Exception ex)
- {
- // Drop any exception
- }
- }
-}
diff --git a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/XMLWriter.java b/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/XMLWriter.java
deleted file mode 100644
index a266edae00..0000000000
--- a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/XMLWriter.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.qpid.info.util;
-
-import java.util.Map;
-
-/**
- *
- * Naive and rudimentary XML writer
- * It has methods to write the header, a tag with attributes
- * and values. It escapes the XML special characters
- */
-public class XMLWriter
-{
-
- private final StringBuffer _sb;
-
- private final String INDENT = " ";
-
- public XMLWriter(StringBuffer sb)
- {
- _sb = sb;
- }
-
- public StringBuffer getXML()
- {
- return _sb;
- }
-
- public void writeXMLHeader()
- {
- _sb.append("<?xml version=\"1.0\"?>\n");
- }
-
- public void writeTag(String tagName, Map<String, String> attributes,
- String value)
- {
- writeOpenTag(tagName, attributes);
- writeValue(value);
- writeCloseTag(tagName);
- }
-
- public void writeOpenTag(String tagName, Map<String, String> attributes)
- {
- _sb.append("<").append(tagName);
- if (null == attributes)
- {
- _sb.append(">\n");
- return;
- }
- for (String key : attributes.keySet())
- {
- _sb.append(" ").append(key + "=\"" + attributes.get(key) + "\"");
- }
- _sb.append(">\n");
-
- }
-
- private void writeValue(String val)
- {
- _sb.append(INDENT).append(escapeXML(val) + "\n");
- }
-
- public void writeCloseTag(String tagName)
- {
- _sb.append("</" + tagName + ">\n");
- }
-
- private String escapeXML(String xmlStr)
- {
- if (null == xmlStr)
- return null;
- xmlStr = xmlStr.replaceAll("&", "&amp;");
- xmlStr = xmlStr.replace("<", "&lt;");
- xmlStr = xmlStr.replace(">", "&gt;");
- xmlStr = xmlStr.replace("\"", "&quot;");
- xmlStr = xmlStr.replace("'", "&apos;");
- return xmlStr;
- }
-
-}