Source Code Cross Referenced for QSAdminAPI.java in  » Net » QuickServer » org » quickserver » net » qsadmin » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » QuickServer » org.quickserver.net.qsadmin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of the QuickServer library 
003:         * Copyright (C) 2003-2005 QuickServer.org
004:         *
005:         * Use, modification, copying and distribution of this software is subject to
006:         * the terms and conditions of the GNU Lesser General Public License. 
007:         * You should have received a copy of the GNU LGP License along with this 
008:         * library; if not, you can download a copy from <http://www.quickserver.org/>.
009:         *
010:         * For questions, suggestions, bug-reports, enhancement-requests etc.
011:         * visit http://www.quickserver.org
012:         *
013:         */
014:
015:        package org.quickserver.net.qsadmin;
016:
017:        import java.io.*;
018:        import java.net.*;
019:        import java.util.logging.*;
020:
021:        /**
022:         * QSAdminAPI class to communicate to QsAdmin from java applications.
023:         * <p>
024:         *  Eg:
025:         * <code><BLOCKQUOTE><pre>
026:         QSAdminAPI qsAdminApi = new QSAdminAPI("127.0.0.1", 9080);
027:         if(qsAdminApi.logon()) {
028:         System.out.println("Logged in");
029:         String info = qsAdminApi.sendCommand("info server");
030:         System.out.println("Info on Server :\n"+info);
031:         qsAdminApi.logoff();
032:         } else {
033:         System.out.println("Bad Login");
034:         qsAdminApi.close();
035:         }
036:         </pre></BLOCKQUOTE></code></p>
037:         * @see QSAdminServer
038:         * @since 1.4
039:         * @author Akshathkumar Shetty
040:         */
041:        public class QSAdminAPI {
042:            private static Logger logger = Logger.getLogger(QSAdminAPI.class
043:                    .getName());
044:
045:            private String username = "Admin";
046:            private String password = "QsAdm1n";
047:
048:            private String host = "localhost";
049:            private int port = 9877;
050:
051:            private Socket socket;
052:            private InputStream in;
053:            private OutputStream out;
054:            private BufferedReader br;
055:            private BufferedWriter bw;
056:
057:            /**
058:             * Creates QSAdminAPI object that will communicate with the 
059:             * passed host and port.
060:             */
061:            public QSAdminAPI(String host, int port) {
062:                this .host = host;
063:                this .port = port;
064:            }
065:
066:            /**
067:             * Will attempt to connect and logon to the remote QsAdminServer.
068:             */
069:            public boolean logon() throws IOException {
070:                return logon(username, password);
071:            }
072:
073:            /**
074:             * Will attempt to connect and logon to the remote QsAdminServer.
075:             */
076:            public boolean logon(String username, String password)
077:                    throws IOException {
078:                this .username = username;
079:                this .password = password;
080:
081:                logger.fine("Connecting to " + host + ":" + port);
082:                socket = new Socket(host, port);
083:                in = socket.getInputStream();
084:                out = socket.getOutputStream();
085:                br = new BufferedReader(new InputStreamReader(in));
086:                bw = new BufferedWriter(new OutputStreamWriter(out));
087:                logger.fine("Got : " + br.readLine());
088:                logger.fine("Got : " + br.readLine());
089:                logger.fine("Got : " + br.readLine());
090:
091:                logger.fine("Got : " + br.readLine());
092:                logger.fine("Sending username");
093:                bw.write(username + "\r\n");
094:                bw.flush();
095:                logger.fine("Got : " + br.readLine());
096:
097:                logger.fine("Sending password");
098:                bw.write(password + "\r\n");
099:                bw.flush();
100:
101:                String temp = br.readLine();
102:                logger.fine("Got : " + temp);
103:                return temp.startsWith("+OK ");
104:            }
105:
106:            /**
107:             * Sends the given command to QSAdmin and gives the response back.
108:             */
109:            public String sendCommand(String data) throws IOException {
110:                logger.fine("Sending command : " + data);
111:                bw.write(data + "\r\n");
112:                bw.flush();
113:                String temp = readResponse();
114:                logger.fine("Got : " + temp);
115:                return temp;
116:            }
117:
118:            private String readResponse() throws IOException {
119:                StringBuffer command = new StringBuffer();
120:                String res = br.readLine();
121:                if (res != null && res.equals("+OK info follows") == false)
122:                    return res;
123:                while (res != null && res.equals(".") == false) {
124:                    command.append(res + "\r\n");
125:                    res = br.readLine();
126:                }
127:                return command.toString();
128:            }
129:
130:            /**
131:             * Logoff the QSAdminServer and closed the socket associated.
132:             */
133:            public void logoff() throws IOException {
134:                logger.fine("Logging off");
135:                logger.fine("Sending command : quit");
136:                bw.write("quit" + "\r\n");
137:                bw.flush();
138:                logger.fine("Got : " + br.readLine());
139:                close();
140:            }
141:
142:            /**
143:             * Closes the socket associated.
144:             */
145:            public void close() throws IOException {
146:                logger.fine("Closing");
147:                socket.close();
148:                socket = null;
149:            }
150:
151:            public static void main(String[] args) throws Exception {
152:                QSAdminAPI qsAdminApi = new QSAdminAPI("127.0.0.1", 9080);
153:                if (qsAdminApi.logon()) {
154:                    logger.info("Logged in");
155:                    String info = qsAdminApi.sendCommand("info server");
156:                    logger.info("Info on Server :\n" + info);
157:                    qsAdminApi.logoff();
158:                } else {
159:                    logger.warning("Bad Login!");
160:                    qsAdminApi.close();
161:                }
162:            }
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.