【问题标题】:WFS-T xmlhttp post length limits?WFS-T xmlhttp 帖子长度限制?
【发布时间】:2012-03-06 13:14:41
【问题描述】:

经过长时间的搜索和尝试,我现在寻求帮助:

我的情况:

  • 我有一个 jquery/openlayers-app,它允许用户创建简单的 具有 WFS-T 属性的 geoemtries...
  • 我在 debian6 上运行 tomcat6(:80-iptables) 和 geoserver 2.1.3(码头:8181)。 tomcat 和 geoserver 之间的所有跨域问题都可以通过一个简单的 jsp-proxy 解决
  • 用户可以毫无问题地查看我所有的 wfs 层,并且能够 创建简单的几何图形

我的问题:

  • 创建更复杂几何图形的用户无法保存它 wfs-t。更复杂的意思是生成的 XML-POST 内容长度 超过约。 2100 个字符。 POST 与例如2000 个字符是 插入成功。
  • 我已经深入研究了 tomcat-server 设置并禁用了所有限制 (maxHTTPHeaderSize,maxSavePostSize,...) 并且还提升了 geoserver-jetty 网络服务器中的 maxpostsize --> 无效
  • 当用户创建更复杂的响应错误消息时 几何形状:

org.xml.sax.SAXParseException:在文档的元素内容中发现了一个无效的 XML 字符(Unicode:0x0)。在文档的元素内容中发现了一个无效的 XML 字符 (Unicode: 0x0)。


  • 我不知道为什么每次我向之前成功插入的几何图形添加一个顶点时,我的 XML POST 请求都会导致 Unicode 错误。
  • 我的请求和响应代码:

successful POST request

successful response

successful POST request headers

not successful POST request

not successful response

not successful POST request headers

my jsp-proxy

我很高兴任何提示如何解决我的问题!

提前致谢,

休伯特干杯

【问题讨论】:

  • 我解决了这个问题...我的 jsp-proxy 工作不正常。我将openlayers应用程序转移到geoserver webapps文件夹(码头)->不需要代理,所有WFS-Transactions(尤其是大的)都在工作......但将来我想在tomcat中托管应用程序,因此我需要一个工作解决方案...我去看看tomcat代理解决方案

标签: tomcat openlayers geoserver


【解决方案1】:

迟到总比没有好:) 下面的代码适用于大型几何体(至少对我而言)

哦,是的,这是简单 jsp 代理的代码

<%@page session="false"%>
<%@page import="java.net.*,java.io.*" %>
<%@page trimDirectiveWhitespaces="true"%> 
<%

/**
 * This is a white list proxy that could be used the prevent an error due to 
 * JavaScript Same Origin Policy.
 * 
 * CAUTION: It might break some sites and it's a security risk because
 * people can use this proxy to browse the web and possibly do bad and/or illegal stuff
 * with it. 
 * It can load any content type.
 * This proxy implementation was inspired by the proxy.cgi script of OpenLayers
 * {@link http://openlayers.org}
 * To use this in OpenLayers you have to set OpenLayers.ProxyHost = "Url/To/This/Proxyfile/proxy.jsp?";
 * within your JavaScript code <br>
 * The base code of the proxy has been provided by SNIPPLR
 * {@link http://snipplr.com/view/17987/jsp-proxy-for-javascript-applications/}
 * 
 * @author terrestris GmbH & Co. KG
 * @author Christian Mayer
 * @author Marc Jansen
 * 
 * @license BSD see license.txt
 * 
 */
String[] allowedHosts = {
    "www.openlayers.org", "openlayers.org", 
    "labs.metacarta.com", "world.freemap.in", 
    "prototype.openmnnd.org", "geo.openplans.org",
    "sigma.openplans.org", "demo.opengeo.org",
    "www.openstreetmap.org", "sample.azavea.com",
    "v-swe.uni-muenster.de:8080", 
    "vmap0.tiles.osgeo.org",
    "192.168.197.95:8080"
};
HttpURLConnection con = null;
try {
    String reqUrl = request.getQueryString();
    String decodedUrl = "";
    if (reqUrl != null) {
        reqUrl = URLDecoder.decode(reqUrl, "UTF-8");
    }
    else {
        response.setStatus(400);
        out.println("ERROR 400: No target specified for proxy.");
    }

    // extract the host
    String host = "";
    host = reqUrl.split("\\/")[2];
    boolean allowed = false;

    // check if host (with port) is in white list
    for (String surl : allowedHosts) {
        if (host.equalsIgnoreCase(surl)) {
            allowed = true;
            break;
        }
    }

    // do the proxy action (load requested ressource and transport it to client)
    // if host is in white list
    if(allowed) {
        // replace the white spaces with plus in URL
        reqUrl = reqUrl.replaceAll(" ", "+"); 

        // call the requested ressource     
        URL url = new URL(reqUrl);
        con = (HttpURLConnection)url.openConnection();
        con.setDoOutput(true);
        con.setRequestMethod(request.getMethod());
        String reqContenType = request.getContentType();
        if(reqContenType != null) {
            con.setRequestProperty("Content-Type", reqContenType);
        }
        else {
            con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        }

        int clength = request.getContentLength();
        if(clength > 0) {
            /* NOT WORKING FOR LARGE POST BODY
            con.setDoInput(true);
            byte[] idata = new byte[clength];
            request.getInputStream().read(idata, 0, clength);
            con.getOutputStream().write(idata, 0, clength); 
            */
            con.setDoInput(true);
            InputStream istream = request.getInputStream();
            OutputStream os = con.getOutputStream();
            final int length = 5000;
            byte[] bytes = new byte[length];
            int bytesRead = 0;
            while ((bytesRead = istream.read(bytes, 0, length)) > 0) {
                os.write(bytes, 0, bytesRead);
            }
        }

        // respond to client
        response.setContentType(con.getContentType());

        BufferedReader rd = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String line;
        int i = 0;
        while ((line = rd.readLine()) != null) {
            out.println(line);  
        }
        rd.close();
    }
    else {
        // deny access via HTTP status code 502
        response.setStatus(502);
        out.println("ERROR 502: This proxy does not allow you to access that location.");
    }

} catch(Exception e) {

    // resond an internal server error with the stacktrace
    // on exception
    response.setStatus(500);
    byte[] idata = new byte[5000];

    if(con.getErrorStream() != null) {
        con.getErrorStream().read(idata, 0, 5000);
    }

    out.println("ERROR 500: An internal server error occured. " + e.getMessage() + " " + new String(idata));    
}
%>

【讨论】:

  • 非常感谢!我忘了提到“我的”jsp 代理是你的一个子集......干杯
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-05-21
  • 2012-11-17
  • 2015-03-01
  • 2011-07-06
  • 1970-01-01
  • 2019-04-08
  • 2013-10-25
相关资源
最近更新 更多