- 浏览: 292156 次
- 性别:
- 来自: 上海
-
文章分类
- 全部博客 (163)
- ETL (4)
- Oracle (24)
- Win (2)
- Apache (5)
- struts2 (1)
- ArcGIS (21)
- Java (17)
- other (6)
- JavaScript (4)
- Xml (4)
- c# (2)
- webSphere (5)
- Ext (2)
- Flex (35)
- Svn (3)
- tomcat (3)
- MyEclipse (4)
- MySQL (2)
- ibatis (2)
- log4j (4)
- spring (1)
- SqlServer (2)
- android (4)
- ios (3)
- SDE (2)
- mac (1)
- Linux (9)
- Mina2 (1)
最新评论
-
markss:
您好,请问kettle循环处理的内存泄漏问题是否已经解决了?毕 ...
Kettle -
1qqqqqq:
图呢 ???
Myeclipse 9.0集成FLASH BUILDER 4.5 -
hanyi366:
现在MyEclipse 都2014版了,好像MyEclipse ...
Visual Editor 插件 安装 -
cnjmwr:
MyEclipse8.6的Eclipse版本是3.5的 ve1 ...
Visual Editor 插件 安装 -
cloudphoenix:
大神 我特地登陆来回帖,真是帮了我的大忙了。看了一个多月的AS ...
FlexGlobals.topLevelApplication
XmlHttpProxy
XmlHttpProxyServlet
HttpClient
/* Copyright 2007 You may not modify, use, reproduce, or distribute this software except in compliance with the terms of the License at: http://developer.sun.com/berkeley_license.html $Id: XmlHttpProxy.java 2660 2008-10-29 14:40:28Z heiko.braun@jboss.com $ */ package jmaki.xhp; /* Copyright 2007 You may not modify, use, reproduce, or distribute this software except in compliance with the terms of the License at: http://developer.sun.com/berkeley_license.html $Id: XmlHttpProxy.java 2660 2008-10-29 14:40:28Z heiko.braun@jboss.com $ */ import java.io.*; import java.net.MalformedURLException; import java.net.URL; import java.util.*; import java.util.logging.*; import javax.xml.transform.*; import javax.xml.transform.stream.*; import org.json.*; public class XmlHttpProxy { public static String GET = "GET"; public static String POST = "POST"; public static String DELETE = "DELETE"; public static String PUT = "PUT"; private String userName = null; private String password = null; private static Logger logger; private String proxyHost = ""; int proxyPort = -1; private JSONObject config; private static String USAGE = "Usage: -url service_URL -id service_key [-url or -id required] -xslurl xsl_url [optional] -format json|xml [optional] -callback[optional] -config [optional] -resources base_directory_containing XSL stylesheets [optional]"; public XmlHttpProxy() {} public XmlHttpProxy(String proxyHost, int proxyPort) { this.proxyHost = proxyHost; this.proxyPort = proxyPort; } public XmlHttpProxy(String proxyHost, int proxyPort, String userName, String password) { this.proxyHost = proxyHost; this.proxyPort = proxyPort; this.userName = userName; this.password = password; } /** * This method will go out and make the call and it will apply an XSLT Transformation with the * set of parameters provided. * * @param urlString - The URL which you are looking up * @param out - The OutputStream to which the resulting document is written * @param xslInputStream - An input Stream to an XSL style sheet that is provided to the XSLT processor. If set to null there will be no transformation * @param paramsMap - A Map of parameters that are feed to the XSLT Processor. These params may be used when generating content. This may be set to null if no parameters are necessary. * @param method - The HTTP method used. * */ public void processRequest(String urlString, OutputStream out, InputStream xslInputStream, Map paramsMap, Map headers, String method, String userName, String password) throws IOException, MalformedURLException { doProcess(urlString, out, xslInputStream, paramsMap, headers,method, null,null, userName,password); } /** * This method will go out and make the call and it will apply an XSLT Transformation with the * set of parameters provided. * * @param urlString - The URL which you are looking up * @param out - The OutputStream to which the resulting document is written * */ public void doPost(String urlString, OutputStream out, InputStream xslInputStream, Map paramsMap, Map headers, String postData, String postContentType, String userName, String password) throws IOException, MalformedURLException { doProcess(urlString, out, xslInputStream, paramsMap, headers, XmlHttpProxy.POST, postData, postContentType, userName, password); } /** * This method will go out and make the call and it will apply an XSLT Transformation with the * set of parameters provided. * * @param urlString - The URL which you are looking up * @param out - The OutputStream to which the resulting document is written * @param xslInputStream - An input Stream to an XSL style sheet that is provided to the XSLT processor. If set to null there will be no transformation * @param paramsMap - A Map of parameters that are feed to the XSLT Processor. These params may be used when generating content. This may be set to null if no parameters are necessary. * @param method - the HTTP method used. * @param postData - A String of the bodyContent to be posted. A doPost will be used if this is parameter is not null. * @param postContentType - The request contentType used when posting data. Will not be set if this parameter is null. * @param userName - userName used for basic authorization * @param password - password used for basic authorization */ public void doProcess(String urlString, OutputStream out, InputStream xslInputStream, Map paramsMap, Map headers, String method, String postData, String postContentType, String userName, String password) throws IOException, MalformedURLException { if (paramsMap == null) { paramsMap = new HashMap(); } String format = (String)paramsMap.get("format"); if (format == null) { format = "xml"; } InputStream in = null; BufferedOutputStream os = null; HttpClient httpclient = null; if (userName != null && password != null) { httpclient = new HttpClient(proxyHost, proxyPort, urlString, headers, method, userName, password); } else { httpclient = new HttpClient(proxyHost, proxyPort, urlString, headers, method); } // post data determines whether we are going to do a get or a post if (postData == null) { in = httpclient.getInputStream(); } else { in = httpclient.doPost(postData, postContentType); } if(null==in) { throw new IOException("Failed to open input stream"); } // read the encoding from the incoming document and default to UTF-8 // if an encoding is not provided String ce = httpclient.getContentEncoding(); if (ce == null) { String ct = httpclient.getContentType(); if (ct != null) { int idx = ct.lastIndexOf("charset="); if (idx >= 0) { ce = ct.substring(idx+8); } else { ce = "UTF-8"; } } else { ce = "UTF-8"; } } // get the content type String cType = null; // write out the content type //http://www.ietf.org/rfc/rfc4627.txt if (format.equals("json")) { cType = "application/json;charset="+ce; } else { cType = "text/xml;charset="+ce; } try { byte[] buffer = new byte[1024]; int read = 0; if (xslInputStream == null) { while (true) { read = in.read(buffer); if (read <= 0) break; out.write(buffer, 0, read ); } } else { transform(in, xslInputStream, paramsMap, out, ce); } } catch (Exception e) { getLogger().severe("XmlHttpProxy transformation error: " + e); } finally { try { if (in != null) { in.close(); } if (out != null) { out.flush(); out.close(); } } catch (Exception e) { // do nothing } } } /** * Do the XSLT transformation */ public void transform( InputStream xmlIS, InputStream xslIS, Map params, OutputStream result, String encoding) { try { TransformerFactory trFac = TransformerFactory.newInstance(); Transformer transformer = trFac.newTransformer(new StreamSource(xslIS)); Iterator it = params.keySet().iterator(); while (it.hasNext()) { String key = (String)it.next(); transformer.setParameter(key, (String)params.get(key)); } transformer.setOutputProperty("encoding", encoding); transformer.transform(new StreamSource(xmlIS), new StreamResult(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 = new XmlHttpProxy(); if (args.length == 0) { System.out.println(USAGE); } String method = XmlHttpProxy.GET; InputStream xslInputStream = null; String serviceKey = null; String urlString = null; String xslURLString = null; String format = "xml"; String callback = null; String urlParams = null; String configURLString = "xhp.json"; String resourceBase = "file:src/conf/META-INF/resources/xsl/"; String username = null; String password = null; // read in the arguments int index = 0; while (index < args.length) { if (args[index].toLowerCase().equals("-url") && index + 1 < args.length) { urlString = args[++index]; } else if (args[index].toLowerCase().equals("-key") && index + 1 < args.length) { serviceKey = args[++index]; } else if (args[index].toLowerCase().equals("-id") && index + 1 < args.length) { serviceKey = args[++index]; } else if (args[index].toLowerCase().equals("-callback") && index + 1 < args.length) { callback = args[++index]; } else if (args[index].toLowerCase().equals("-xslurl") && index + 1 < args.length) { xslURLString = args[++index]; } else if (args[index].toLowerCase().equals("-method") && index + 1 < args.length) { method = args[++index]; } else if (args[index].toLowerCase().equals("-username") && index + 1 < args.length) { username = args[++index]; } else if (args[index].toLowerCase().equals("-password") && index + 1 < args.length) { password = args[++index]; } else if (args[index].toLowerCase().equals("-urlparams") && index + 1 < args.length) { urlParams = args[++index]; } else if (args[index].toLowerCase().equals("-config") && index + 1 < args.length) { configURLString = args[++index]; } else if (args[index].toLowerCase().equals("-resources") && index + 1 < args.length) { resourceBase = args[++index]; } index++; } if (serviceKey != null) { try { InputStream is = (new URL(configURLString)).openStream(); JSONObject services = loadServices(is); JSONObject service = services.getJSONObject(serviceKey); // default to the service default if no url parameters are specified if (urlParams == null && service.has("defaultURLParams")) { urlParams = service.getString("defaultURLParams"); } String serviceURL = service.getString("url"); // build the URL properly if (urlParams != null && serviceURL.indexOf("?") == -1){ serviceURL += "?"; } else if (urlParams != null){ serviceURL += "&"; } String apiKey = ""; if (service.has("apikey")) apiKey = service.getString("apikey"); urlString = serviceURL + apiKey + "&" + urlParams; if (service.has("xslStyleSheet")) { xslURLString = 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 == 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 = new HashMap(); if (format != null) { paramsMap.put("format", format); } if (callback != null) { paramsMap.put("callback", callback); } if (xslURLString != null) { URL xslURL = new URL(xslURLString); if (xslURL != null) { xslInputStream = xslURL.openStream(); } else { getLogger().severe("Error: Unable to locate XSL at URL " + xslURLString); } } xhp.processRequest(urlString, System.out, xslInputStream, paramsMap, null, method, username, password); } public static Logger getLogger() { if (logger == null) { logger = Logger.getLogger("jmaki.xhp.Log"); } return logger; } public static JSONObject loadServices(InputStream is) { JSONObject config = null; JSONObject services = new JSONObject(); try { config = loadJSONObject(is).getJSONObject("xhp"); JSONArray sA = config.getJSONArray("services"); for (int l=0; l < sA.length(); l++) { JSONObject value = sA.getJSONObject(l); String key = value.getString("id"); services.put(key,value); } } catch (Exception ex) { getLogger().severe("XmlHttpProxy error loading services." + ex); } return services; } public static JSONObject loadJSONObject(InputStream in) { ByteArrayOutputStream out = null; try { byte[] buffer = new byte[1024]; int read = 0; out = new ByteArrayOutputStream(); while (true) { read = in.read(buffer); if (read <= 0) break; out.write(buffer, 0, read ); } return new JSONObject(out.toString()); } catch (Exception e) { getLogger().severe("XmlHttpProxy error reading in json " + e); } finally { try { if (in != null) { in.close(); } if (out != null) { out.flush(); out.close(); } } catch (Exception e) { } } return null; } }
XmlHttpProxyServlet
/* Copyright 2007 You may not modify, use, reproduce, or distribute this software except in compliance with the terms of the License at: http://developer.sun.com/berkeley_license.html $Id: XmlHttpProxyServlet.java 2660 2008-10-29 14:40:28Z heiko.braun@jboss.com $ */ package jmaki.xhp; import java.io.*; import java.util.*; import java.net.URL; import java.net.URLConnection; import java.util.logging.*; import javax.servlet.*; import javax.servlet.http.*; import org.json.*; /** XmlHttpProxyServlet * @author Greg Murray */ public class XmlHttpProxyServlet extends HttpServlet { public static String REMOTE_USER = "REMOTE_USER"; private static String XHP_LAST_MODIFIED = "xhp_last_modified_key"; private static String XHP_CONFIG = "xhp.json"; private static boolean allowXDomain = false; private static boolean requireSession = false; private static boolean createSession = false; private static String responseContentType = "application/json;charset=UTF-8"; private static boolean rDebug = false; private Logger logger = null; private XmlHttpProxy xhp = null; private ServletContext ctx; private JSONObject services = null; private String resourcesDir = "/resources/"; private String classpathResourcesDir = "/META-INF/resources/"; private String headerToken = "jmaki-"; private String testToken = "xtest-"; public XmlHttpProxyServlet() { if (rDebug) { logger = getLogger(); } } public void init(ServletConfig config) throws ServletException { super.init(config); ctx = config.getServletContext(); // set the response content type if (ctx.getInitParameter("responseContentType") != null) { responseContentType = ctx.getInitParameter("responseContentType"); } // allow for resources dir over-ride at the xhp level otherwise allow // for the jmaki level resources if (ctx.getInitParameter("jmaki-xhp-resources") != null) { resourcesDir = ctx.getInitParameter("jmaki-xhp-resources"); } else if (ctx.getInitParameter("jmaki-resources") != null) { resourcesDir = ctx.getInitParameter("jmaki-resources"); } // allow for resources dir over-ride if (ctx.getInitParameter("jmaki-classpath-resources") != null) { classpathResourcesDir = ctx.getInitParameter("jmaki-classpath-resources"); } String requireSessionString = ctx.getInitParameter("requireSession"); if (requireSessionString == null) requireSessionString = ctx.getInitParameter("jmaki-requireSession"); if (requireSessionString != null) { if ("false".equals(requireSessionString)) { requireSession = false; getLogger().severe("XmlHttpProxyServlet: intialization. Session requirement disabled."); } else if ("true".equals(requireSessionString)) { requireSession = true; getLogger().severe("XmlHttpProxyServlet: intialization. Session requirement enabled."); } } String xdomainString = ctx.getInitParameter("allowXDomain"); if (xdomainString == null) xdomainString = ctx.getInitParameter("jmaki-allowXDomain"); if (xdomainString != null) { if ("true".equals(xdomainString)) { allowXDomain = true; getLogger().severe("XmlHttpProxyServlet: intialization. xDomain access is enabled."); } else if ("false".equals(xdomainString)) { allowXDomain = false; getLogger().severe("XmlHttpProxyServlet: intialization. xDomain access is disabled."); } } String createSessionString = ctx.getInitParameter("jmaki-createSession"); if (createSessionString != null) { if ("true".equals(createSessionString)) { createSession = true; getLogger().severe("XmlHttpProxyServlet: intialization. create session is enabled."); } else if ("false".equals(xdomainString)) { createSession = false; getLogger().severe("XmlHttpProxyServlet: intialization. create session is disabled."); } } // if there is a proxyHost and proxyPort specified create an HttpClient with the proxy String proxyHost = ctx.getInitParameter("proxyHost"); String proxyPortString = ctx.getInitParameter("proxyPort"); if (proxyHost != null && proxyPortString != null) { int proxyPort = 8080; try { proxyPort= new Integer(proxyPortString).intValue(); xhp = new XmlHttpProxy(proxyHost, proxyPort); } catch (NumberFormatException nfe) { getLogger().severe("XmlHttpProxyServlet: intialization error. The proxyPort must be a number"); throw new ServletException("XmlHttpProxyServlet: intialization error. The proxyPort must be a number"); } } else { xhp = new XmlHttpProxy(); } } private void getServices(HttpServletResponse res) { InputStream is = null; try { URL url = ctx.getResource(resourcesDir + XHP_CONFIG); // use classpath if not found locally. //if (url == null) url = XmlHttpProxyServlet.class.getResource(classpathResourcesDir + XHP_CONFIG); if (url == null) url = XmlHttpProxyServlet.class.getResource(XHP_CONFIG); // same package is = url.openStream(); } catch (Exception ex) { try { getLogger().severe("XmlHttpProxyServlet error loading xhp.json : " + ex); PrintWriter writer = res.getWriter(); writer.write("XmlHttpProxyServlet Error: Error loading xhp.json. Make sure it is available in the /resources directory of your applicaton."); writer.flush(); } catch (Exception iox) {} } services = xhp.loadServices(is); } public void doDelete(HttpServletRequest req, HttpServletResponse res) { doProcess(req,res, XmlHttpProxy.DELETE); } public void doGet(HttpServletRequest req, HttpServletResponse res) { doProcess(req,res, XmlHttpProxy.GET); } public void doPost(HttpServletRequest req, HttpServletResponse res) { doProcess(req,res, XmlHttpProxy.POST); } public void doPut(HttpServletRequest req, HttpServletResponse res) { doProcess(req,res, XmlHttpProxy.PUT); } public void doProcess(HttpServletRequest req, HttpServletResponse res, String method) { boolean isPost = XmlHttpProxy.POST.equals(method); StringBuffer bodyContent = null; OutputStream out = null; PrintWriter writer = null; String serviceKey = null; try { BufferedReader in = req.getReader(); String line = null; while ((line = in.readLine()) != null) { if (bodyContent == null) bodyContent = new StringBuffer(); bodyContent.append(line); } } catch (Exception e) { } try { HttpSession session = null; // it really does not make sense to use create session with require session as // the create session will always result in a session created and the requireSession // will always succeed. Leaving the logic for now. if (createSession) { session = req.getSession(true); } if (requireSession) { // check to see if there was a session created for this request // if not assume it was from another domain and blow up // Wrap this to prevent Portlet exeptions session = req.getSession(false); if (session == null) { res.setStatus(HttpServletResponse.SC_FORBIDDEN); return; } } serviceKey = req.getParameter("id"); // only to preven regressions - Remove before 1.0 if (serviceKey == null) serviceKey = req.getParameter("key"); // check if the services have been loaded or if they need to be reloaded if (services == null || configUpdated()) { getServices(res); } String urlString = null; String xslURLString = null; String userName = null; String password = null; String format = "json"; String callback = req.getParameter("callback"); String urlParams = req.getParameter("urlparams"); String countString = req.getParameter("count"); boolean passthrough = false; // encode the url to prevent spaces from being passed along if (urlParams != null) { urlParams = urlParams.replace(' ', '+'); } // get the headers to pass through Map headers = null; // Forward all request headers starting with the header token jmaki- // and chop off the jmaki- Enumeration hnum = req.getHeaderNames(); // test hack while (hnum.hasMoreElements()) { String name = (String)hnum.nextElement(); if (name.startsWith(headerToken)) { if (headers == null) headers = new HashMap(); String value = ""; // handle multi-value headers Enumeration vnum = req.getHeaders(name); while (vnum.hasMoreElements()) { value += (String)vnum.nextElement(); if (vnum.hasMoreElements()) value += ";"; } String sname = name.substring(headerToken.length(), name.length()); headers.put(sname,value); } else if(name.startsWith(testToken)) { // hack test capabilities for authentication if("xtest-user".equals(name)) userName = req.getHeader("xtest-user"); if("xtest-pass".equals(name)) password = req.getHeader("xtest-pass"); } } try { String actualServiceKey = serviceKey != null ? serviceKey : "default"; if (services.has(actualServiceKey)) { JSONObject service = services.getJSONObject(actualServiceKey); String serviceURL = service.getString("url"); if(null==serviceURL) throw new IllegalArgumentException("xhp.json: service url is mising"); if (service.has("passthrough")) passthrough = Boolean.valueOf(service.getString("passthrough")); if (service.has("username")) userName = service.getString("username"); if (service.has("password")) password = service.getString("password"); String apikey = ""; if (service.has("apikey")) apikey = service.getString("apikey"); if (service.has("xslStyleSheet")) xslURLString = service.getString("xslStyleSheet"); // default to the service default if no url parameters are specified if(!passthrough) { if (urlParams == null && service.has("defaultURLParams")) { urlParams = service.getString("defaultURLParams"); } // build the URL if (urlParams != null && serviceURL.indexOf("?") == -1){ serviceURL += "?"; } else if (urlParams != null) { serviceURL += "&"; } urlString = serviceURL + apikey; if (urlParams != null) urlString += "&" + urlParams; } if(passthrough) { // override service url and url params String path = req.getPathInfo(); path = path.substring(path.indexOf("xhp/")+3, path.length()); urlString = serviceURL + path + "?" + req.getQueryString(); } } else { writer = res.getWriter(); if (serviceKey == null) writer.write("XmlHttpProxyServlet Error: id parameter specifying serivce required."); else writer.write("XmlHttpProxyServlet Error : service for id '" + serviceKey + "' not found."); writer.flush(); return; } } catch (Exception ex) { getLogger().severe("XmlHttpProxyServlet Error loading service: " + ex); res.setStatus(500); } Map paramsMap = new HashMap(); paramsMap.put("format", format); // do not allow for xdomain unless the context level setting is enabled. if (callback != null && allowXDomain) { paramsMap.put("callback", callback); } if (countString != null) { paramsMap.put("count", countString); } InputStream xslInputStream = null; if (urlString == null) { writer = res.getWriter(); writer.write("XmlHttpProxyServlet parameters: id[Required] urlparams[Optional] format[Optional] callback[Optional]"); writer.flush(); return; } // support for session properties and also authentication name if (urlString.indexOf("${") != -1) { urlString = processURL(urlString, req, res); } // default to JSON res.setContentType(responseContentType); out = res.getOutputStream(); // get the stream for the xsl stylesheet if (xslURLString != null) { // check the web root for the resource URL xslURL = null; xslURL = ctx.getResource(resourcesDir + "xsl/"+ xslURLString); // if not in the web root check the classpath if (xslURL == null) { xslURL = XmlHttpProxyServlet.class.getResource(classpathResourcesDir + "xsl/" + xslURLString); } if (xslURL != null) { xslInputStream = xslURL.openStream(); } else { String message = "Could not locate the XSL stylesheet provided for service id " + serviceKey + ". Please check the XMLHttpProxy configuration."; getLogger().severe(message); res.setStatus(500); try { out.write(message.getBytes()); out.flush(); return; } catch (java.io.IOException iox){ } } } if (!isPost) { xhp.processRequest(urlString, out, xslInputStream, paramsMap, headers, method, userName, password); } else { final String content = bodyContent != null ? bodyContent.toString() : ""; if (bodyContent == null) getLogger().info("XmlHttpProxyServlet attempting to post to url " + urlString + " with no body content"); xhp.doPost(urlString, out, xslInputStream, paramsMap, headers, content, req.getContentType(), userName, password); } } catch (Exception iox) { iox.printStackTrace(); getLogger().severe("XmlHttpProxyServlet: caught " + iox); res.setStatus(500); /*try { writer = res.getWriter(); writer.write("XmlHttpProxyServlet error loading service for " + serviceKey + " . Please notify the administrator."); writer.flush(); } catch (java.io.IOException ix) { ix.printStackTrace(); }*/ return; } finally { try { if (out != null) out.close(); if (writer != null) writer.close(); } catch (java.io.IOException iox){} } } /* Allow for a EL style replacements in the serviceURL * * The constant REMOTE_USER will replace the contents of ${REMOTE_USER} * with the return value of request.getRemoteUserver() if it is not null * otherwise the ${REMOTE_USER} is replaced with a blank. * * If you use ${session.somekey} the ${session.somekey} will be replaced with * the String value of the session varialble somekey or blank if the session key * does not exist. * */ private String processURL(String url, HttpServletRequest req, HttpServletResponse res) { String serviceURL = url; int start = url.indexOf("${"); int end = url.indexOf("}", start); if (end != -1) { String prop = url.substring(start + 2, end).trim(); // no matter what we will remove the ${} // default to blank like the JSP EL String replace = ""; if (REMOTE_USER.equals(prop)) { if (req.getRemoteUser() != null) replace = req.getRemoteUser(); } if (prop.toLowerCase().startsWith("session.")) { String sessionKey = prop.substring("session.".length(), prop.length()); if (req.getSession().getAttribute(sessionKey) != null) { // force to a string replace = req.getSession().getAttribute(sessionKey).toString(); } } serviceURL = serviceURL.substring(0, start) + replace + serviceURL.substring(end + 1, serviceURL.length()); } // call recursively to process more than one instance of a ${ in the serviceURL if (serviceURL.indexOf("${") != -1) serviceURL = processURL(serviceURL, req, res); return serviceURL; } /** * Check to see if the configuration file has been updated so that it may be reloaded. */ private boolean configUpdated() { try { URL url = ctx.getResource(resourcesDir + XHP_CONFIG); URLConnection con; if (url == null) return false ; con = url.openConnection(); long lastModified = con.getLastModified(); long XHP_LAST_MODIFIEDModified = 0; if (ctx.getAttribute(XHP_LAST_MODIFIED) != null) { XHP_LAST_MODIFIEDModified = ((Long)ctx.getAttribute(XHP_LAST_MODIFIED)).longValue(); } else { ctx.setAttribute(XHP_LAST_MODIFIED, new Long(lastModified)); return false; } if (XHP_LAST_MODIFIEDModified < lastModified) { ctx.setAttribute(XHP_LAST_MODIFIED, new Long(lastModified)); return true; } } catch (Exception ex) { getLogger().severe("XmlHttpProxyServlet error checking configuration: " + ex); } return false; } public Logger getLogger() { if (logger == null) { logger = Logger.getLogger("jmaki.services.xhp.Log"); } return logger; } private void logMessage(String message) { if (rDebug) { getLogger().info(message); } } }
HttpClient
/* Copyright 2006-2008 Sun Microsystems, Inc. All rights reserved. You may not modify, use, reproduce, or distribute this software except in compliance with the terms of the License at: http://developer.sun.com/berkeley_license.html $Id: HttpClient.java 2631 2008-10-27 17:25:05Z heiko.braun@jboss.com $ */package jmaki.xhp; import java.io.*; import java.util.Map; import java.util.Iterator; import java.net.*; import java.util.logging.*; import java.security.Security; /** * @author Yutaka Yoshida, Greg Murray * * Minimum set of HTTPclient supporting both http and https. * It's aslo capable of POST, but it doesn't provide doGet because * the caller can just read the inputstream. */ public class HttpClient { private static Logger logger; private String proxyHost = null; private int proxyPort = -1; private boolean isHttps = false; private boolean isProxy = false; private HttpURLConnection urlConnection = null; private Map headers; /** * @param phost PROXY host name * @param pport PROXY port string * @param url URL string * @param headers Map */ public HttpClient( String phost, int pport, String url, Map headers, String method) throws MalformedURLException { if (phost != null && pport != -1) { this.isProxy = true; } this.proxyHost = phost; this.proxyPort = pport; if (url.trim().startsWith("https:")) { isHttps = true; } this.urlConnection = getURLConnection(url); try { this.urlConnection.setRequestMethod(method); } catch (java.net.ProtocolException pe) { HttpClient.getLogger().severe("Unable protocol method to " + method + " : " + pe); } this.headers = headers; // seat headers if (headers != null) { Iterator it = headers.keySet().iterator(); if (it != null) { while (it.hasNext()) { String key = (String)it.next(); String value = (String)headers.get(key); this.urlConnection.setRequestProperty (key, value); } } } } /** * @param phost PROXY host name * @param pport PROXY port string * @param url URL string * @param headers Map * @param userName string * @param password string */ public HttpClient(String phost, int pport, String url, Map headers, String method, String userName, String password) throws MalformedURLException { try { if (phost != null && pport != -1) { this.isProxy = true; } this.proxyHost = phost; this.proxyPort = pport; if (url.trim().startsWith("https:")) { isHttps = true; } this.urlConnection = getURLConnection(url); try { this.urlConnection.setRequestMethod(method); } catch (java.net.ProtocolException pe) { HttpClient.getLogger().severe("Unable protocol method to " + method + " : " + pe); } // set basic authentication information String auth = userName + ":" + password; String encoded = new sun.misc.BASE64Encoder().encode (auth.getBytes()); // set basic authorization this.urlConnection.setRequestProperty ("Authorization", "Basic " + encoded); this.headers = headers; // seat headers if (headers != null) { Iterator it = headers.entrySet().iterator(); if (it != null) { while (it.hasNext()) { String key = (String)it.next(); String value = (String)headers.get(key); this.urlConnection.setRequestProperty (key, value); } } } } catch (Exception ex) { HttpClient.getLogger().severe("Unable to set basic authorization for " + userName + " : " +ex); } } /** * private method to get the URLConnection * @param str URL string */ private HttpURLConnection getURLConnection(String str) throws MalformedURLException { try { if (isHttps) { /* when communicating with the server which has unsigned or invalid * certificate (https), SSLException or IOException is thrown. * the following line is a hack to avoid that */ Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); if (isProxy) { System.setProperty("https.proxyHost", proxyHost); System.setProperty("https.proxyPort", proxyPort + ""); } } else { if (isProxy) { System.setProperty("http.proxyHost", proxyHost); System.setProperty("http.proxyPort", proxyPort + ""); } } URL url = new URL(str); HttpURLConnection uc = (HttpURLConnection)url.openConnection(); // if this header has not been set by a request set the user agent. if (headers == null || (headers != null && headers.get("user-agent") == null)) { // set user agent to mimic a common browser String ua="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"; uc.setRequestProperty("user-agent", ua); } return uc; } catch (MalformedURLException me) { throw new MalformedURLException(str + " is not a valid URL"); } catch (Exception e) { throw new RuntimeException("Unknown error creating UrlConnection: " + e); } } /** * returns the inputstream from URLConnection * @return InputStream */ public InputStream getInputStream() { try { // logger doesnt work, because it writes to stderr, // which causes GwtTest to interpret it as failure System.out.println( this.urlConnection.getRequestMethod()+ " " + this.urlConnection.getURL() +": "+ this.urlConnection.getResponseCode() ); return (this.urlConnection.getInputStream()); } catch (Exception e) { e.printStackTrace(); return null; } } /** * return the OutputStream from URLConnection * @return OutputStream */ public OutputStream getOutputStream() { try { return (this.urlConnection.getOutputStream()); } catch (Exception e) { e.printStackTrace(); return null; } } /** * posts data to the inputstream and returns the InputStream. * @param postData data to be posted. must be url-encoded already. * @param contentType allows you to set the contentType of the request. * @return InputStream input stream from URLConnection */ public InputStream doPost(String postData, String contentType) { this.urlConnection.setDoOutput(true); if (contentType != null) this.urlConnection.setRequestProperty( "Content-type", contentType ); OutputStream os = this.getOutputStream(); PrintStream ps = new PrintStream(os); ps.print(postData); ps.close(); return (this.getInputStream()); } public String getContentEncoding() { if (this.urlConnection == null) return null; return (this.urlConnection.getContentEncoding()); } public int getContentLength() { if (this.urlConnection == null) return -1; return (this.urlConnection.getContentLength()); } public String getContentType() { if (this.urlConnection == null) return null; return (this.urlConnection.getContentType()); } public long getDate() { if (this.urlConnection == null) return -1; return (this.urlConnection.getDate()); } public String getHeader(String name) { if (this.urlConnection == null) return null; return (this.urlConnection.getHeaderField(name)); } public long getIfModifiedSince() { if (this.urlConnection == null) return -1; return (this.urlConnection.getIfModifiedSince()); } public static Logger getLogger() { if (logger == null) { logger = Logger.getLogger("jmaki.xhp.Log"); } return logger; } }
- XmlHttpProxy.rar (10.6 KB)
- 下载次数: 4
发表评论
-
Java中byte与16进制字符串的互相转换
2014-09-07 07:43 754Java中byte用二进制表示占用8位,而我们知道16进制 ... -
SynchronizedMap和ConcurrentHashMap的深入分析
2014-06-19 10:33 628在开始之前,先介绍下Map是什么? javadoc中对M ... -
多线程下使用 SimpleDateFormat 的问题
2014-03-18 12:38 785最近用到多线程写通信服务,发现在解析时间是一直莫名的错误, ... -
java内存限制
2012-07-12 20:38 938回顾一下java内存限制的几个参数的具体含义 -Xm ... -
UTC GMT CST时间
2012-07-05 15:59 2549GMT(Greenwich Mean Time,格林威治 ... -
java 操作 excel 2010
2012-03-14 15:28 1664前段时间,需要进行excel2010数据的解析。先是找组件, ... -
FLEX权限--使用RemoteObject交互结合spring AOP控制项目权限教程
2012-03-04 16:55 855FLEX使用remoteobject交互结合sprin ... -
iBatis中的insert如何返回个类数据库的主键
2012-02-24 11:03 1002<SPAN style="COLOR: #ff ... -
java.util.ConcurrentModificationException异常
2012-01-14 12:59 9701、 今天在写一个带缓 ... -
JAVA中ArrayList 与 Vector 的线程安全问题
2012-01-13 18:45 3666JAVA中ArrayList是否允许两个线程同时进行插入和删除 ... -
java calendar
2011-12-22 16:27 1745import java.text.DateFormat; ... -
Servlet中init-param and content-param
2011-11-08 08:56 838Servlet中init-param and content- ... -
HttpRequestProxy 请求代理 post方法
2011-10-28 15:31 4328* * * * Title: Ht ... -
HttpRequestProxy 请求代理 post方法
2011-10-28 15:30 1394写道 * * * * Title: HttpR ... -
super.init(config)
2011-08-22 11:45 3017servlet的init(ServletConfig conf ... -
URL工具类
2011-08-18 14:45 1017package ssh.util; import ...
相关推荐
DeepSeek与AI幻觉-清华大学团队制作 一、什么是AI幻觉 (定义与基础概念) 二、DeepSeek为什么会产生幻觉 (聚焦特定AI模型的幻觉成因分析) 三、AI幻觉评测 (评估AI幻觉的频率、类型与影响的方法) 四、如何减缓AI幻觉 (解决方案与技术优化方向) 五、AI幻觉的创造力价值 (探讨幻觉在创新场景中的潜在益处,如艺术生成、灵感激发等)
协同过滤算法商品推荐系统(源码+数据库+论文+ppt)java开发springboot框架javaweb,可做计算机毕业设计或课程设计 【功能需求】 前台用户可以实现注册登录、商品浏览,在线客服,加入购物车,加入收藏,下单购买,个人信息管理,收货信息管理,收藏管理,评论功能。 后台管理员可以进行用户管理、商品分类管理、商品信息管理、订单评价管理、系统管理、订单管理。 【环境需要】 1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.数据库:MySql 5.7/8.0等版本均可; 【购买须知】 本源码项目经过严格的调试,项目已确保无误,可直接用于课程实训或毕业设计提交。里面都有配套的运行环境软件,讲解视频,部署视频教程,一应俱全,可以自己按照教程导入运行。附有论文参考,使学习者能够快速掌握系统设计和实现的核心技术。
MES系统数字化工厂解决方案.pptx
MUI调用照片以及裁剪和图库照片上传到服务器
GPT付费体验系统最新版系统是一款基于ThinkPHP框架开发的AI问答小程序, 是基于国外很火的ChatGPT进行开发的Ai智能问答小程序。这是一种基于人工智能技术的问答系统, 可以实现智能回答用户提出的问题。相比传统的问答系统,ChatGPT可以更加准确地理解用户的意图, 提供更加精准的答案。同时系统采用了最新的GPT3.5接口与GPT4模型,同时还支持型,文心一言,腾讯混元, 讯飞星火,通义千问,DeepSeeK,智普等等国内各种大模型,可以更好地适应不同的应用场景,支持站点无限多开, 可以说ChatGPT付费创作系统目前国内相对体验比较好的一款的ChatGPT及多接口软件系统。 新增接入DeepSeek-R1、DeepSeek-V3(Ollama自部署和第三方均支持)、高级通道增加DeepSeek、 支持AI接口输出的reasoning_content字段(新的推理输出格式)、更新模型库、修复导出Excel的bug等功能, 优化了云灵Midjourney接口,出图更快更稳定。小程序端变化不大该系统版本测试下来比较完美, 老版本升级时数据库结构同步下,同时把原来
内容概要:本文档详细介绍了一款基于Java技术的美食点餐管理平台的设计与实现。该平台旨在优化传统餐饮行业的服务流程,通过智能化的点餐系统、高效的订单处理、智能库存管理和数据分析等功能,为用户提供便捷高效的点餐体验,并提升餐厅管理效率和服务质量。系统涵盖了前端设计、后端开发、数据库设计等方面,采用了成熟的Java技术和现代Web开发框架,如Spring Boot、Vue.js或React,确保系统的高效性和稳定性。此外,文档还包括详细的用户界面设计、模块实现以及系统部署指南,帮助开发者理解和搭建该平台。 适合人群:具备一定的Java编程基础和技术经验的研发人员、IT从业者以及有意开发类似系统的企业和个人。 使用场景及目标:①为餐厅提供一个集点餐、订单处理、库存管理于一体的高效平台;②优化传统餐饮服务流程,提升客户服务体验;③利用大数据分析辅助决策,助力餐饮企业精细化运营;④通过集成多种支付方式和其他外部系统,满足多样化的商业需求。 其他说明:本项目不仅提供了完整的技术方案和支持文档,还针对实际应用场景提出了多个扩展方向和技术优化思路,旨在引导用户不断迭代和完善该平台的功能和性能。
相场模拟与激光制造技术:选择性激光烧结、激光融覆中的凝固与枝晶生长研究,相场模拟与激光制造技术:选择性激光烧结、激光融覆及凝固过程中的枝晶生长研究,相场模拟 选择性激光烧结 激光融覆 凝固 枝晶生长 ,相场模拟; 选择性激光烧结; 激光融覆; 凝固; 枝晶生长,相场模拟与激光工艺:枝晶生长的凝固过程研究
项目工程资源经过严格测试运行并且功能上ok,可实现复现复刻,拿到资料包后可实现复现出一样的项目,本人系统开发经验充足(全栈全领域),有任何使用问题欢迎随时与我联系,我会抽时间努力为您解惑,提供帮助 【资源内容】:包含源码+工程文件+说明等。答辩评审平均分达到96分,放心下载使用!可实现复现;设计报告也可借鉴此项目;该资源内项目代码都经过测试运行;功能ok 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 【提供帮助】:有任何使用上的问题欢迎随时与我联系,抽时间努力解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 下载后请首先打开说明文件(如有);整理时不同项目所包含资源内容不同;项目工程可实现复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用
关于加强新能源汽车安全管理涉及的法规标准分析.pptx
项目工程资源经过严格测试运行并且功能上ok,可实现复现复刻,拿到资料包后可实现复现出一样的项目,本人系统开发经验充足(全栈全领域),有任何使用问题欢迎随时与我联系,我会抽时间努力为您解惑,提供帮助 【资源内容】:包含源码+工程文件+说明等。答辩评审平均分达到96分,放心下载使用!可实现复现;设计报告也可借鉴此项目;该资源内项目代码都经过测试运行,功能ok 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 【提供帮助】:有任何使用上的问题欢迎随时与我联系,抽时间努力解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 下载后请首先打开说明文件(如有);整理时不同项目所包含资源内容不同;项目工程可实现复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用
项目工程资源经过严格测试运行并且功能上ok,可实现复现复刻,拿到资料包后可实现复现出一样的项目,本人系统开发经验充足(全栈全领域),有任何使用问题欢迎随时与我联系,我会抽时间努力为您解惑,提供帮助 【资源内容】:包含源码+工程文件+说明等。答辩评审平均分达到96分,放心下载使用!可实现复现;设计报告也可借鉴此项目;该资源内项目代码都经过测试运行;功能ok 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 【提供帮助】:有任何使用上的问题欢迎随时与我联系,抽时间努力解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 下载后请首先打开说明文件(如有);整理时不同项目所包含资源内容不同;项目工程可实现复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用
UI+svg格式
关于乘用车燃料消耗量评价方法及指标强制性国家标准的分析.pptx
1、文件内容:openjpeg-1.5.1-18.el7.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/openjpeg-1.5.1-18.el7.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、更多资源/技术支持:公众号禅静编程坊
FPGA Verilog实现BT656与1120视频协议组帧解帧代码详解:含文档介绍与仿真验证,FPGA Verilog实现BT656与1120视频协议组帧解帧代码详解:含文档介绍与仿真验证,fpga verilog实现视频协议bt656和1120组帧解帧代码 有文档介绍协议,有mod仿真,matlab代码仿真 ,FPGA; Verilog; BT656协议; 1120组帧解帧代码; 文档介绍; Mod仿真; Matlab代码仿真,FPGA Verilog:实现BT656与1120组帧解帧代码的仿真与文档化研究
基于 RAG 与大模型技术的医疗问答系统,利用 DiseaseKG 数据集与 Neo4j 构 建知识图谱,结合 BERT 的命名实体识别和 34b 大模型的意图识别,通过精确的知识检索和问答生成, 提升系统在医疗咨询中的性能,解决大模型在医疗领域应用的可靠性问题。.zip项目工程资源经过严格测试运行并且功能上ok,可实现复现复刻,拿到资料包后可实现复现出一样的项目,本人系统开发经验充足(全栈全领域),有任何使用问题欢迎随时与我联系,我会抽时间努力为您解惑,提供帮助 【资源内容】:包含源码+工程文件+说明等。答辩评审平均分达到96分,放心下载使用!可实现复现;设计报告也可借鉴此项目;该资源内项目代码都经过测试运行,功能ok 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 【提供帮助】:有任何使用上的问题欢迎随时与我联系,抽时间努力解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 下载后请首先打开说明文件(如有);整理时不同项目所包含资源内容不同;项目工程可实现复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用
项目工程资源经过严格测试运行并且功能上ok,可实现复现复刻,拿到资料包后可实现复现出一样的项目,本人系统开发经验充足(全栈全领域),有任何使用问题欢迎随时与我联系,我会抽时间努力为您解惑,提供帮助 【资源内容】:包含源码+工程文件+说明等。答辩评审平均分达到96分,放心下载使用!可实现复现;设计报告也可借鉴此项目;该资源内项目代码都经过测试运行;功能ok 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 【提供帮助】:有任何使用上的问题欢迎随时与我联系,抽时间努力解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 下载后请首先打开说明文件(如有);整理时不同项目所包含资源内容不同;项目工程可实现复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用
抖音视频带货:行业趋势与营销策略.pptx
西门子动态密码程序:学习随机码生成与指针存储数据,Smartline触摸屏操作指南及编程视频教程,西门子动态密码程序:学习随机码生成与存储数据的智能之旅(视频讲解),200smart动态密码程序,触摸屏是smartline,西门子动态密码程序,,随机码的产生,指针用法存储数据,非常适合学习,而且是自己程序,还专门录制了一段视频来讲解编程的思路和画面的操作步骤。 ,200smart动态密码程序; touchscreen: smartline; 西门子动态密码程序; 随机码生成; 指针用法存储数据; 自学编程; 程序录制视频讲解。,西门子动态密码程序:触摸屏Smartline随机码生成与指针存储技术解析