[OpenLayers-Users] error using proxy file and WMS getfeatureinfo request

Spivey, Brett brett.spivey at nc.gov
Fri Feb 10 15:51:44 EST 2012


I'm writing an application that accesses wms services on a variety of servers requiring the use of a proxy file.  The application is running within Tomcat (v 6.0.18) and uses the jsp code at the bottom as the proxy. Everything works fine for getcapabilities and getmap requests but when attempting a getfeatureinfo request  I receive a java "no protocol" error. Can anyone provide a suggestion on correcting this? Thanks.

GetFeatureInfo Code snippet:
info = new OpenLayers.Control.WMSGetFeatureInfo({
    title: 'Identify features by clicking',
    //drillDown: true,
    queryVisible: true,
    infoFormat: 'application/vnd.ogc.wms_xml',
    eventListeners: {
      getfeatureinfo: function (event) {
        map.addPopup(new OpenLayers.Popup.FramedCloud(
                        "chicken",
                        map.getLonLatFromPixel(event.xy),
                        null,
                        event.text,
                        null,
                        true
                    ));
      }
    }
  });
  map.addControl(info);
  info.activate();


Error Received:
java.net.MalformedURLException: no protocol: http://149.168.87.13/arcgis/services/NC1Map_Boundaries/MapServer/WMSServer?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&LAYERS=0,1,2,3&QUERY_LAYERS=0,1,2,3&STYLES=,,,&BBOX=-10624233.224628%2C3771371.436984%2C-7128920.79569%2C4585884.410277&FEATURE_COUNT=10&HEIGHT=333&WIDTH=1429&FORMAT=png&INFO_FORMAT=text%2Fhtml&SRS=EPSG%3A3857&X=758&Y=129 at java.net.URL.(Unknown Source) at java.net.URL.(Unknown Source) at java.net.URL.(Unknown Source) at org.apache.jsp.ncomOL.proxy_jsp._jspService(proxy_jsp.java:100) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Unknown Source)


JSP Proxy
<%@page session="false"%>
<%@page import="java.net.*,java.io.*" %>
<%!
String[] serverUrls = {
  //"<url>[,<token>]"
  "http://sampleserver1.arcgisonline.com/arcgis/rest/services",
  "http://sampleserver2.arcgisonline.com/arcgis/rest/services",
  "http://data.nconemap.com",
  "http://149.168.87.16",
  "http://149.168.87.16:8080",
  "http://149.168.87.13",
  "http://http://imagery.nconemap.com/ArcGIS/rest/services/",
  "http://wms.jpl.nasa.gov/wms.cgi",
  "http://demo.mapserver.org/cgi-bin/wms"
};
%>
<%
try {
  String reqUrl = request.getQueryString();
  boolean allowed = true;
  String token = null;

      for(String surl : serverUrls) {
    String[] stokens = surl.split("\\s*,\\s*");
            System.out.println( "Evaluating date now" );
    if(reqUrl.toLowerCase().contains(stokens[0].toLowerCase())) {
      allowed = true;
      if(stokens.length >= 2 && stokens[1].length() > 0)
        token = stokens[1];
      break;
    }
  }

  if(!allowed) {
    response.setStatus(403);
    return;
  }
  if(token != null) {
    reqUrl = reqUrl + (reqUrl.indexOf("?") > -1 ? "&" : "?") + "token=" + token;
  }
  URL url = new URL(reqUrl);
      HttpURLConnection con = (HttpURLConnection)url.openConnection();
      con.setDoOutput(true);
      con.setRequestMethod(request.getMethod());
      if(request.getContentType() != null) {
        con.setRequestProperty("Content-Type", request.getContentType());
      }
  con.setRequestProperty("Referer", request.getHeader("Referer"));
      int clength = request.getContentLength();
      if(clength > 0) {
            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);
        }
      }
  else {
    con.setRequestMethod("GET");
  }
      out.clear();
  out = pageContext.pushBody();
      OutputStream ostream = response.getOutputStream();
      response.setContentType(con.getContentType());
      InputStream in = con.getInputStream();
      final int length = 5000;
  byte[] bytes = new byte[length];
  int bytesRead = 0;
  while ((bytesRead = in.read(bytes, 0, length)) > 0) {
    ostream.write(bytes, 0, bytesRead);
  }
} catch(Exception e) {
      response.setStatus(500);
      // e.printStackTrace(response.getWriter());
}
%>






Brett Spivey
NC OneMap Programmer
Center for Geographic Information & Analysis
Office of the State Chief Information Officer
919.754.6591
brett.spivey at its.nc.gov
http://www.cgia.state.nc.us

Email correspondence to and from this address may be subject to the North Carolina Public Records Law and may be disclosed to third parties by an authorized state official.


________________________________

E-mail correspondence to and from this address may be subject to the North Carolina Public Records Law and may be disclosed to third parties by an authorized state official.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120210/13f1931c/attachment-0001.html


More information about the Users mailing list