Author: mladen.turk(a)jboss.com
Date: 2008-05-29 02:50:34 -0400 (Thu, 29 May 2008)
New Revision: 1633
Added:
sandbox/aloha/java/org/jboss/aloha/Connection.java
sandbox/aloha/java/org/jboss/aloha/ConnectionFactory.java
sandbox/aloha/java/org/jboss/aloha/HttpConnection.java
Removed:
sandbox/aloha/java/org/jboss/aloha/HttpMessage.java
sandbox/aloha/java/org/jboss/aloha/MessageFactory.java
Modified:
sandbox/aloha/java/org/jboss/aloha/GenericResource.java
sandbox/aloha/java/org/jboss/aloha/Message.java
sandbox/aloha/java/org/jboss/aloha/ResponseBodyParser.java
Log:
Rename some classes
Added: sandbox/aloha/java/org/jboss/aloha/Connection.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/Connection.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/Connection.java 2008-05-29 06:50:34 UTC (rev 1633)
@@ -0,0 +1,100 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import org.jboss.aloha.util.*;
+
+/**
+ * Represents the Connection to remote Web Server instance
+ * using MCMP protocol
+ *
+ * @author Mladen Turk
+ *
+ */
+public abstract class Connection
+{
+
+ private MessageProtocol protocol;
+
+ private String host;
+ private int port;
+ private String url;
+ protected int connectTimeout;
+ protected int readTimeout;
+ protected String authorization;
+
+ /**
+ * Creates an empty connection to ManagedServer
+ */
+ protected Connection()
+ {
+ }
+
+ public abstract void connect();
+ public abstract void disconnect();
+ public abstract int getResponseCode();
+ public abstract void sendMessage(Message message);
+ public abstract String getResponse();
+
+
+ public void setProtocol(String v)
+ throws IllegalArgumentException
+ {
+ protocol = MessageProtocol.valueOfIgnoreCase(v);
+ }
+
+ public void setProtocol(MessageProtocol v) { protocol = v;}
+
+ public MessageProtocol getProtocol() { return protocol; }
+
+
+ public void setHost(String v) { host = v; }
+ public String getHost() { return host; }
+
+ public void setPort(int v) { port = v; }
+ public int getPort() { return port; }
+
+ public void setManagerUrl(String v) { url = v; }
+ public String getManagerUrl() { return url; }
+
+ public void setConnectTimeout(int v) { connectTimeout = v; }
+ public int getConnectTimeout() { return connectTimeout; }
+
+ public void setReadTimeout(int v) { readTimeout = v; }
+ public int getReadTimeout() { return readTimeout; }
+
+ public String getAuthorization() { return authorization; }
+
+ /**
+ * Sets the Authorization credentials
+ */
+ public void setAuthorization(String authorization)
+ {
+ this.authorization = authorization;
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/Connection.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/ConnectionFactory.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/ConnectionFactory.java (rev
0)
+++ sandbox/aloha/java/org/jboss/aloha/ConnectionFactory.java 2008-05-29 06:50:34 UTC (rev
1633)
@@ -0,0 +1,117 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import org.jboss.aloha.util.*;
+
+/**
+ * ConnectionFactory
+ *
+ * @author Mladen Turk
+ *
+ */
+public class ConnectionFactory
+{
+ private MessageProtocol protocol = MessageProtocol.Http;
+ private String host = "localhost";
+ private int port = 0;
+ private String url = Default.MANAGER_URL;
+ protected int connectTimeout = Default.CONNECT_TIMEOUT;
+ protected int readTimeout = Default.READ_TIMEOUT;
+ protected String authorization = null;
+
+ private Class conClass;
+
+ public void setProtocol(MessageProtocol v) { protocol = v; }
+
+ public void setProtocol(String v)
+ throws IllegalArgumentException
+ {
+ protocol = MessageProtocol.valueOfIgnoreCase(v);
+ }
+
+ public MessageProtocol getProtocol() { return protocol; }
+
+
+ public void setHost(String v) { host = v; }
+ public String getHost() { return host; }
+
+ public void setPort(int v) { port = v; }
+ public int getPort() { return port; }
+
+ public void setManagerUrl(String v) { url = v; }
+ public String getManagerUrl() { return url; }
+
+ public void setConnectTimeout(int v) { connectTimeout = v; }
+ public int getConnectTimeout() { return connectTimeout; }
+
+ public void setReadTimeout(int v) { readTimeout = v; }
+ public int getReadTimeout() { return readTimeout; }
+
+ public String getAuthorization() { return authorization; }
+
+ /**
+ * Sets the Basic Authorization credentials
+ */
+ public void setBasicAuthorization(String username, String password)
+ {
+ if (username != null && password != null)
+ authorization = "Basic " + Base64.encode(username + ":" +
password);
+ }
+
+ /**
+ * Sets the Authorization credentials
+ */
+ public void setAuthorization(String authorization)
+ {
+ this.authorization = authorization;
+ }
+
+ public ConnectionFactory(Class conClass)
+ {
+ this.conClass = conClass;
+ }
+
+ public Connection getConnection()
+ {
+ Connection con;
+ try {
+ con = (Connection)conClass.newInstance();
+ con.setProtocol(protocol);
+ con.setHost(host);
+ con.setPort(port);
+ con.setManagerUrl(url);
+ con.setConnectTimeout(connectTimeout);
+ con.setReadTimeout(readTimeout);
+ con.setAuthorization(authorization);
+
+ } catch (Exception e) {
+ con = null;
+ }
+ return con;
+ }
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/ConnectionFactory.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: sandbox/aloha/java/org/jboss/aloha/GenericResource.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/GenericResource.java 2008-05-28 15:50:29 UTC (rev
1632)
+++ sandbox/aloha/java/org/jboss/aloha/GenericResource.java 2008-05-29 06:50:34 UTC (rev
1633)
@@ -56,7 +56,7 @@
public GenericResource(ManagedServer managedServer)
{
- this(managedServer, ResourceType.Unknown.toString());
+ this(managedServer, ResourceType.Unknown.name());
}
public GenericResource()
Added: sandbox/aloha/java/org/jboss/aloha/HttpConnection.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/HttpConnection.java (rev
0)
+++ sandbox/aloha/java/org/jboss/aloha/HttpConnection.java 2008-05-29 06:50:34 UTC (rev
1633)
@@ -0,0 +1,194 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.io.InputStream;
+
+import java.net.URL;
+import java.net.URLEncoder;
+import java.net.HttpURLConnection;
+
+import java.net.ProtocolException;
+import java.net.MalformedURLException;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Represents the HTTP protocol Message to remote Web Server
+ * instance using MCMP protocol
+ *
+ * @author Mladen Turk
+ *
+ */
+public class HttpConnection extends Connection
+{
+ private static final String GET = "GET";
+ private static final String OK = "OK";
+ private static final String ERR_500 = "?Error: 502; Internal Server
Error";
+ private static final String ERR_502 = "?Error: 502; Bad Gateway";
+ private static final String ERR_505 = "?Error: 505; HTTP Version not
supported";
+ private static final String ERR_400 = "?Error: 400; Bad Request";
+ private static final String ERR_403 = "?Error: 403; Forbidded";
+ private static final String ERR_404 = "?Error: 404; Not Found";
+ private static final String ERR_405 = "?Error: 405; Method Not
Allowed";
+ private int responseCode = 0;
+ private String responseDesc = "";
+ private String responseBody = null;
+
+
+ /**
+ * Creates an empty HttpConnection
+ */
+ protected HttpConnection()
+ {
+ }
+
+ public void connect()
+ {
+ // Nothing
+ }
+
+ public void disconnect()
+ {
+ // Nothing
+ }
+
+ /**
+ * Return HTTP response code
+ */
+ public int getResponseCode()
+ {
+ return responseCode;
+ }
+
+ public void sendMessage(Message message)
+ {
+ responseBody = getResponseBody(message);
+ }
+
+ public String getResponse()
+ {
+ return responseBody;
+ }
+
+ private String getResponseBody(Message message)
+ {
+ HttpURLConnection conn;
+ try {
+ URL url = new URL(getConnectionUrl(message.getCommand().name()));
+ conn = (HttpURLConnection)url.openConnection();
+ conn.setRequestMethod(GET);
+ } catch (MalformedURLException u) {
+ responseCode = HttpURLConnection.HTTP_BAD_REQUEST;
+ return ERR_400;
+ } catch (ProtocolException e) {
+ responseCode = HttpURLConnection.HTTP_BAD_METHOD;
+ return ERR_405;
+ } catch (IOException e) {
+ responseCode = HttpURLConnection.HTTP_FORBIDDEN;
+ return ERR_403;
+ }
+ conn.setAllowUserInteraction(false);
+ conn.setUseCaches(false);
+ conn.setDoInput(true);
+ conn.setDoOutput(false);
+ conn.setRequestProperty(Globals.SERVER_RESOURCE, message.getQuery());
+ if (authorization != null) {
+ // Add Authorization header
+ conn.setRequestProperty("Authorization", authorization);
+ }
+
+ try {
+ conn.setConnectTimeout(connectTimeout);
+ conn.setReadTimeout(readTimeout);
+ conn.connect();
+ } catch (IOException e) {
+ responseCode = HttpURLConnection.HTTP_BAD_GATEWAY;
+ return ERR_502;
+ }
+ try {
+ responseCode = conn.getResponseCode();
+ responseDesc = conn.getResponseMessage();
+ } catch (IOException x) {
+ responseCode = HttpURLConnection.HTTP_VERSION;
+ conn.disconnect();
+ return ERR_505;
+ }
+
+ if (responseCode != HttpURLConnection.HTTP_OK) {
+ StringBuffer eb = new StringBuffer("?Error: ");
+ eb.append(responseCode);
+ eb.append("; ");
+ eb.append(responseDesc);
+ return eb.toString();
+ }
+
+ InputStream is;
+ try {
+ is = conn.getInputStream();
+ } catch (IOException e) {
+ responseCode = HttpURLConnection.HTTP_INTERNAL_ERROR;
+ conn.disconnect();
+ return ERR_500;
+ }
+ StringBuffer s = new StringBuffer();
+ int rd;
+ byte [] bb = new byte[1024];
+ try {
+ while ((rd = is.read(bb)) > 0) {
+ s.append(new String(bb, 0, rd, Default.CHARSET));
+ if (rd < 1024)
+ break;
+ }
+ } catch (Exception e) {
+ // Ignore. Return what we've got so far.
+ }
+ String r = s.toString();
+ if (s.length() == 0)
+ return OK;
+ else
+ return r;
+ }
+
+ private String getConnectionUrl(String path)
+ {
+ StringBuffer sb = new StringBuffer(getProtocol().name().toLowerCase());
+ sb.append("://");
+ sb.append(getHost());
+ if (getPort() > 0) {
+ sb.append(':');
+ sb.append(getPort());
+ }
+ sb.append('/');
+ sb.append(path);
+ sb.append(getManagerUrl());
+ return sb.toString();
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/HttpConnection.java
___________________________________________________________________
Name: svn:eol-style
+ native
Deleted: sandbox/aloha/java/org/jboss/aloha/HttpMessage.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/HttpMessage.java 2008-05-28 15:50:29 UTC (rev
1632)
+++ sandbox/aloha/java/org/jboss/aloha/HttpMessage.java 2008-05-29 06:50:34 UTC (rev
1633)
@@ -1,163 +0,0 @@
-/*
- *
- * Copyright(c) 2008 Red Hat Middleware, LLC,
- * and individual contributors as indicated by the @authors tag.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library in the file COPYING.LIB;
- * if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- */
-
-package org.jboss.aloha;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.io.InputStream;
-
-import java.net.URL;
-import java.net.URLEncoder;
-import java.net.HttpURLConnection;
-
-import java.net.ProtocolException;
-import java.net.MalformedURLException;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Represents the HTTP protocol Message to remote Web Server
- * instance using MCMP protocol
- *
- * @author Mladen Turk
- *
- */
-public class HttpMessage extends Message
-{
-
- private static final String GET = "GET";
- private static final String OK = "OK";
- private static final String ERR_500 = "?Error: 502; Internal Server
Error";
- private static final String ERR_502 = "?Error: 502; Bad Gateway";
- private static final String ERR_505 = "?Error: 505; HTTP Version not
supported";
- private static final String ERR_400 = "?Error: 400; Bad Request";
- private static final String ERR_403 = "?Error: 403; Forbidded";
- private static final String ERR_404 = "?Error: 404; Not Found";
- private static final String ERR_405 = "?Error: 405; Method Not
Allowed";
- private int responseCode = 0;
- private String responseDesc = "";
-
- /**
- * Creates an empty Message
- */
- public HttpMessage()
- {
- }
-
- protected Message getInstance()
- {
- return this;
- }
-
- /**
- * Return HTTP response code
- */
- public int getResponseCode()
- {
- return responseCode;
- }
-
- public String getResponse(String query)
- {
- HttpURLConnection conn;
- try {
- URL url = new URL(getMessageUrl());
- conn = (HttpURLConnection)url.openConnection();
- conn.setRequestMethod(GET);
- } catch (MalformedURLException u) {
- responseCode = HttpURLConnection.HTTP_BAD_REQUEST;
- return ERR_400;
- } catch (ProtocolException e) {
- responseCode = HttpURLConnection.HTTP_BAD_METHOD;
- return ERR_405;
- } catch (IOException e) {
- responseCode = HttpURLConnection.HTTP_FORBIDDEN;
- return ERR_403;
- }
- conn.setAllowUserInteraction(false);
- conn.setUseCaches(false);
- conn.setDoInput(true);
- conn.setDoOutput(false);
- conn.setRequestProperty(Globals.SERVER_RESOURCE, query);
- if (authorization != null) {
- // Add Authorization header
- conn.setRequestProperty("Authorization", authorization);
- }
-
- try {
- conn.setConnectTimeout(connectTimeout);
- conn.setReadTimeout(readTimeout);
- conn.connect();
- } catch (IOException e) {
- responseCode = HttpURLConnection.HTTP_BAD_GATEWAY;
- return ERR_502;
- }
- try {
- responseCode = conn.getResponseCode();
- responseDesc = conn.getResponseMessage();
- } catch (IOException x) {
- responseCode = HttpURLConnection.HTTP_VERSION;
- conn.disconnect();
- return ERR_505;
- }
-
- if (responseCode != HttpURLConnection.HTTP_OK) {
- StringBuffer eb = new StringBuffer("?Error: ");
- eb.append(responseCode);
- eb.append("; ");
- eb.append(responseDesc);
- return eb.toString();
- }
-
- InputStream is;
- try {
- is = conn.getInputStream();
- } catch (IOException e) {
- responseCode = HttpURLConnection.HTTP_INTERNAL_ERROR;
- conn.disconnect();
- return ERR_500;
- }
- StringBuffer s = new StringBuffer();
- int rd;
- byte [] bb = new byte[1024];
- try {
- while ((rd = is.read(bb)) > 0) {
- s.append(new String(bb, 0, rd, Default.CHARSET));
- if (rd < 1024)
- break;
- }
- } catch (Exception e) {
- // Ignore. Return what we've got so far.
- }
- String r = s.toString();
- if (s.length() == 0)
- return OK;
- else
- return r;
- }
-
-}
Modified: sandbox/aloha/java/org/jboss/aloha/Message.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/Message.java 2008-05-28 15:50:29 UTC (rev 1632)
+++ sandbox/aloha/java/org/jboss/aloha/Message.java 2008-05-29 06:50:34 UTC (rev 1633)
@@ -35,91 +35,48 @@
* @author Mladen Turk
*
*/
-public abstract class Message
+public class Message
{
- private MessageProtocol protocol = MessageProtocol.Http;
- private Command cmd = Command.Info;
+ private Command cmd;
+ private String query;
+ private ResponseBodyParser parser = new ResponseBodyParser();
- private String host = "localhost";
- private int port = 0;
- private String url = Default.MANAGER_URL;
- protected int connectTimeout = Default.CONNECT_TIMEOUT;
- protected int readTimeout = Default.READ_TIMEOUT;
- protected String authorization = null;
-
/**
- * Creates an empty connection to ManagedServer
+ * Creates an Message
*/
+ public Message(Command cmd, String query)
+ {
+ this.cmd = cmd;
+ this.query = query;
+ }
+
public Message()
{
+ this(Command.Info, "*");
}
- protected abstract int getResponseCode();
- protected abstract String getResponse(String query);
- protected abstract Message getInstance();
+ public Message(String query)
+ {
+ this(Command.Info, query);
+ }
- public void setProtocol(MessageProtocol v) { protocol = v; }
-
- public void setProtocol(String v)
- throws IllegalArgumentException
- {
- protocol = MessageProtocol.valueOfIgnoreCase(v);
- }
-
- public MessageProtocol getProtocol() { return protocol; }
-
-
public void setCommand(Command v) { cmd = v; }
public Command getCommand() { return cmd; }
- public void setHost(String v) { host = v; }
- public String getHost() { return host; }
+ public void setQuery(String v) { query = v; }
+ public String getQuery() { return query; }
- public void setPort(int v) { port = v; }
- public int getPort() { return port; }
+ public ResponseBodyParser getParser() { return parser; }
- public void setManagerUrl(String v) { url = v; }
- public String getManagerUrl() { return url; }
-
- public void setConnectTimeout(int v) { connectTimeout = v; }
- public int getConnectTimeout() { return connectTimeout; }
-
- public void setReadTimeout(int v) { readTimeout = v; }
- public int getReadTimeout() { return readTimeout; }
-
- public String getAuthorization() { return authorization; }
-
- /**
- * Sets the Basic Authorization credentials
- */
- public void setAuthorization(String username, String password)
+ public String toString()
{
- if (username != null && password != null)
- authorization = "Basic " + Base64.encode(username + ":" +
password);
+ return query;
}
- /**
- * Sets the Authorization credentials
- */
- public void setAuthorization(String authorization)
+ public void parse(String response)
{
- this.authorization = authorization;
+ parser.parse(response);
}
- public String getMessageUrl()
- {
- StringBuffer sb = new StringBuffer(protocol.name().toLowerCase());
- sb.append("://");
- sb.append(host);
- if (port > 0) {
- sb.append(':');
- sb.append(port);
- }
- sb.append(url);
- sb.append('/');
- sb.append(cmd.name());
- return sb.toString();
- }
-
}
Deleted: sandbox/aloha/java/org/jboss/aloha/MessageFactory.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/MessageFactory.java 2008-05-28 15:50:29 UTC (rev
1632)
+++ sandbox/aloha/java/org/jboss/aloha/MessageFactory.java 2008-05-29 06:50:34 UTC (rev
1633)
@@ -1,118 +0,0 @@
-/*
- *
- * Copyright(c) 2008 Red Hat Middleware, LLC,
- * and individual contributors as indicated by the @authors tag.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library in the file COPYING.LIB;
- * if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- */
-
-package org.jboss.aloha;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import org.jboss.aloha.util.*;
-
-/**
- * MessageFactory
- *
- * @author Mladen Turk
- *
- */
-public class MessageFactory
-{
-
- private MessageProtocol protocol = MessageProtocol.Http;
- private ResponseBodyParser parser = new ResponseBodyParser();
- private Message message;
- private String host = "localhost";
- private int port = 0;
- private String url = Default.MANAGER_URL;
- protected int connectTimeout = Default.CONNECT_TIMEOUT;
- protected int readTimeout = Default.READ_TIMEOUT;
- protected String authorization = null;
-
- /**
- * Creates an empty connection to ManagedServer
- */
- public MessageFactory(Message message)
- {
- this.message = message;
- }
-
- public void setProtocol(MessageProtocol v) { protocol = v; }
-
- public void setProtocol(String v)
- throws IllegalArgumentException
- {
- protocol = MessageProtocol.valueOfIgnoreCase(v);
- }
-
- public MessageProtocol getProtocol() { return protocol; }
-
-
- public void setHost(String v) { host = v; }
- public String getHost() { return host; }
-
- public void setPort(int v) { port = v; }
- public int getPort() { return port; }
-
- public void setManagerUrl(String v) { url = v; }
- public String getManagerUrl() { return url; }
-
- public void setConnectTimeout(int v) { connectTimeout = v; }
- public int getConnectTimeout() { return connectTimeout; }
-
- public void setReadTimeout(int v) { readTimeout = v; }
- public int getReadTimeout() { return readTimeout; }
-
- public String getAuthorization() { return authorization; }
-
- /**
- * Sets the Basic Authorization credentials
- */
- public void setAuthorization(String username, String password)
- {
- if (username != null && password != null)
- authorization = "Basic " + Base64.encode(username + ":" +
password);
- }
-
- /**
- * Sets the Authorization credentials
- */
- public void setAuthorization(String authorization)
- {
- this.authorization = authorization;
- }
-
- public Message getMessage()
- {
- Message msg = message.getInstance();
-
- msg.setProtocol(protocol);
- msg.setHost(host);
- msg.setPort(port);
- msg.setManagerUrl(url);
- msg.setConnectTimeout(connectTimeout);
- msg.setReadTimeout(readTimeout);
- msg.setAuthorization(authorization);
-
- return msg;
- }
-
-}
Modified: sandbox/aloha/java/org/jboss/aloha/ResponseBodyParser.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/ResponseBodyParser.java 2008-05-28 15:50:29 UTC
(rev 1632)
+++ sandbox/aloha/java/org/jboss/aloha/ResponseBodyParser.java 2008-05-29 06:50:34 UTC
(rev 1633)
@@ -74,9 +74,9 @@
errorDescription = "No error";
responseType = ResponseType.Empty;
bodyLines.clear();
- grL.clear();
+ grL.clear();
}
-
+
public void parse(String body)
{
clear();
@@ -96,7 +96,7 @@
}
public ResponseBodyParser(String body)
- {
+ {
parse(body);
}