accessCookies()
+ {
+ return cookies;
+ }
+
+ /**
+ * Do the XSLT transformation
+ */
+ public void transform( InputStream xmlIS,
+ InputStream xslIS,
+ Map params,
+ OutputStream result,
+ String encoding) {
+ try {
+ TransformerFactory trFac =3D TransformerFactory.newInstance();
+ Transformer transformer =3D trFac.newTransformer(new StreamSou=
rce(xslIS));
+ Iterator it =3D params.keySet().iterator();
+ while (it.hasNext()) {
+ String key =3D (String)it.next();
+ transformer.setParameter(key, (String)params.get(key));
+ }
+ transformer.setOutputProperty("encoding", encoding);
+ transformer.transform(new StreamSource(xmlIS), new StreamResul=
t(result));
+ } catch (Exception e) {
+ getLogger().severe("XmlHttpProxy: Exception with xslt " + e);
+ }
+ }
+
+ /**
+ *
+ * CLI to the XmlHttpProxy
+ */
+ /* public static void main(String[] args)
+ throws IOException, MalformedURLException {
+
+ getLogger().info("XmlHttpProxy 1.8");
+ XmlHttpProxy xhp =3D new XmlHttpProxy();
+
+ if (args.length =3D=3D 0) {
+ System.out.println(USAGE);
+ }
+
+ String method =3D XmlHttpProxy.GET;
+ InputStream xslInputStream =3D null;
+ String serviceKey =3D null;
+ String urlString =3D null;
+ String xslURLString =3D null;
+ String format =3D "xml";
+ String callback =3D null;
+ String urlParams =3D null;
+ String configURLString =3D "xhp.json";
+ String resourceBase =3D "file:src/conf/META-INF/resources/xsl/";
+ String username =3D null;
+ String password =3D null;
+
+ // read in the arguments
+ int index =3D 0;
+ while (index < args.length) {
+ if (args[index].toLowerCase().equals("-url") && index + 1 < args.le=
ngth) {
+ urlString =3D args[++index];
+ } else if (args[index].toLowerCase().equals("-key") && index + 1 < =
args.length) {
+ serviceKey =3D args[++index];
+ } else if (args[index].toLowerCase().equals("-id") && index + 1 < a=
rgs.length) {
+ serviceKey =3D args[++index];
+ } else if (args[index].toLowerCase().equals("-callback") && index +=
1 < args.length) {
+ callback =3D args[++index];
+ } else if (args[index].toLowerCase().equals("-xslurl") && index + =
1 < args.length) {
+ xslURLString =3D args[++index];
+ } else if (args[index].toLowerCase().equals("-method") && index + 1=
< args.length) {
+ method =3D args[++index];
+ } else if (args[index].toLowerCase().equals("-username") && index +=
1 < args.length) {
+ username =3D args[++index];
+ } else if (args[index].toLowerCase().equals("-password") && index +=
1 < args.length) {
+ password =3D args[++index];
+ } else if (args[index].toLowerCase().equals("-urlparams") && index =
+ 1 < args.length) {
+ urlParams =3D args[++index];
+ } else if (args[index].toLowerCase().equals("-config") && index + 1=
< args.length) {
+ configURLString =3D args[++index];
+ } else if (args[index].toLowerCase().equals("-resources") && index =
+ 1 < args.length) {
+ resourceBase =3D args[++index];
+ }
+ index++;
+ }
+
+ if (serviceKey !=3D null) {
+ try {
+ InputStream is =3D (new URL(configURLString)).openStream();
+ JSONObject services =3D loadServices(is);
+ JSONObject service =3D services.getJSONObject(serviceKey);
+ // default to the service default if no url parameters are specifi=
ed
+ if (urlParams =3D=3D null && service.has("defaultURLParams")) {
+ urlParams =3D service.getString("defaultURLParams");
+ }
+ String serviceURL =3D service.getString("url");
+ // build the URL properly
+ if (urlParams !=3D null && serviceURL.indexOf("?") =3D=3D -1){
+ serviceURL +=3D "?";
+ } else if (urlParams !=3D null){
+ serviceURL +=3D "&";
+ }
+ String apiKey =3D "";
+ if (service.has("apikey")) apiKey =3D service.getString("apikey");
+ urlString =3D serviceURL + apiKey + "&" + urlParams;
+ if (service.has("xslStyleSheet")) {
+ xslURLString =3D service.getString("xslStyleSheet");
+ // check if the url is correct of if to load from the classpath
+
+ }
+ } catch (Exception ex) {
+ getLogger().severe("XmlHttpProxy Error loading service: " + ex);
+ System.exit(1);
+ }
+ } else if (urlString =3D=3D null) {
+ System.out.println(USAGE);
+ System.exit(1);
+ }
+ // The parameters are feed to the XSL Stylsheet during transformation.
+ // These parameters can provided data or conditional information.
+ Map paramsMap =3D new HashMap();
+ if (format !=3D null) {
+ paramsMap.put("format", format);
+ }
+ if (callback !=3D null) {
+ paramsMap.put("callback", callback);
+ }
+
+ if (xslURLString !=3D null) {
+ URL xslURL =3D new URL(xslURLString);
+ if (xslURL !=3D null) {
+ xslInputStream =3D xslURL.openStream();
+ } else {
+ getLogger().severe("Error: Unable to locate XSL at URL " + xslURL=
String);
+ }
+ }
+ xhp.processRequest(urlString, System.out, xslInputStream, paramsMap, =
null, method, username, password);
+ } */
+
+ public static Logger getLogger() {
+ if (logger =3D=3D null) {
+ logger =3D Logger.getLogger(XmlHttpProxy.class.getName());
+ }
+ return logger;
+ }
+
+ public static ProxyConfig loadServices(InputStream is)
+ {
+ return ProxyConfig.parse(is);
+ }
+
+ public class Cookie
+ {
+ String name;
+ String value;
+ String path;
+ }
+
+
+ public class AuthenticationException extends IOException {
+ int code;
+ String authHeader;
+
+ public AuthenticationException(int code, String authHeader) {
+ this.code =3D code;
+ this.authHeader =3D authHeader;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public String getAuthHeader() {
+ return authHeader;
+ }
+ }
+}
\ No newline at end of file
Added: console/trunk/app/src/main/java/org/jboss/as/console/server/proxy/Xm=
lHttpProxyServlet.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- console/trunk/app/src/main/java/org/jboss/as/console/server/proxy/XmlHt=
tpProxyServlet.java (rev 0)
+++ console/trunk/app/src/main/java/org/jboss/as/console/server/proxy/XmlHt=
tpProxyServlet.java 2012-03-26 21:53:57 UTC (rev 1540)
@@ -0,0 +1,631 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @author tags. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WIT=
HOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNE=
SS 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 Licens=
e,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+package org.jboss.as.console.server.proxy;
+
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.PropertyResourceBundle;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+/**
+ * Used to access services in hosted mode that
+ * deployed to an external container. I.e. JBoss AS.
+ *
+ * Usage (web.xml):
+ *
+ *
+ * <servlet>
+ * <servlet-name>gwtProxy</servlet-name>
+ * <description>GWT Proxy</description>
+ * <servlet-class>org.jboss.as.console.server.proxy.XmlHttpProxyS=
ervlet</servlet-class>
+ * <init-param>
+ * <param-name>config.name</param-name>
+ * <param-value>gwt-proxy.json</param-value>
+ * </init-param>
+ * <load-on-startup>1</load-on-startup>
+ * </servlet>
+ *
+ * <servlet-mapping>
+ * <servlet-name>gwtProxy</servlet-name>
+ * <url-pattern>/app/proxy/*</url-pattern>
+ * </servlet-mapping>
+ *
+ *
+ *
+ *
+ *
+ * gwt-proxy.properties:
+ *
+ * service.id=3Ddomain-api
+ * service.url=3Dhttp://127.0.0.1:9990/domain-api
+ * service.passThrough=3Dtrue
+ *
+ *
+ * @author Greg Murray
+ * @author Heiko Braun
+ */
+public class XmlHttpProxyServlet extends HttpServlet
+{
+
+ public static String REMOTE_USER =3D "REMOTE_USER";
+
+ private static String XHP_LAST_MODIFIED =3D "xhp_last_modified_key";
+ private static String DEFAULT_CONFIG =3D "gwt-proxy.properties";
+
+ private static boolean allowXDomain =3D false;
+ private static boolean requireSession =3D false;
+ private static boolean createSession =3D false;
+ private static String defaultContentType =3D "application/dmr-encoded;=
charset=3DUTF-8";
+ private static boolean rDebug =3D false;
+ private Logger logger =3D null;
+ private XmlHttpProxy xhp =3D null;
+ private ServletContext ctx;
+ private List