📄 httpcommunicationhandler.java
字号:
* resultBuf = new StringBuffer(); String wmsUrl =
* requestParam.getGetMapURL(); StringBuffer url = new StringBuffer(wmsUrl);
* url.append(wmsUrl.indexOf("?") < 0 ? "?" : "&");
* url.append("request=FindPath"); url.append("&service=wms");
* url.append("&styles="); // 7.2.3.4; MUST be present and // may be a null
* value for default // or must one from the list. url.append("&layers=");
* url.append(requestParam.getFindPathLayer());
* url.append("&spoint=").append
* (requestParam.getStartPoint()[0]).append(",")
* .append(requestParam.getStartPoint()[1]);
* url.append("&epoint=").append(requestParam
* .getEndPoint()[0]).append(",").append(requestParam.getEndPoint()[1]);
* url.append("&bbox=").append(new
* Float(requestParam.getBoundingX1()).toString());
* url.append(",").append(new
* Float(requestParam.getBoundingY1()).toString());
* url.append(",").append(new
* Float(requestParam.getBoundingX2()).toString());
* url.append(",").append(new
* Float(requestParam.getBoundingY2()).toString());
* url.append("&SRS=").append(requestParam.getSRS());
* url.append("&width=").append
* (requestParam.getPixelWidth()).append("&height="
* ).append(requestParam.getPixelHeight());
* url.append("&format=").append(requestParam.getXmlFormat());
* url.append("&exceptions=").append(requestParam.getTextFormat());
* url.append("&version=").append(requestParam.getVersion()); wmsUrl =
* url.toString(); // wmsUrl = //
* "http://localhost:8080/geoserver/wms?&request=FindPath&service=wms&styles=&LAYERS=jvn:roads_topo&spoint=105.94586,10.78163&epoint=105.94065,10.79906&bbox=105.93026,10.75845,105.95795,10.80074&SRS=EPSG:4326&width=240&height=367&format=text/xml&version=1.1.1"
* ; try { connection = openGETConnection(wmsUrl); //
* System.out.println("******** Reading stream: "); updateProgress();
* inputStream = openConnectionInputStream(connection); updateProgress();
* int ch; while ((ch = inputStream.read()) != -1) { resultBuf.append((char)
* ch); // System.out.print((char) ch); } } catch (IOException ioe) { // int
* ch; // try { // while ((ch = inputStream.read()) != -1) { //
* System.out.print((char)ch); // } // } catch (IOException e) { //
* e.printStackTrace(); // } System.out.println(); ioe.printStackTrace();
* throw new ApplicationException(ErrorMessageCodes.ERROR_CANNOT_CONNECT); }
* finally { closeConnection(connection, inputStream); } return
* toUTF8(resultBuf.toString()); }
*/
public String searchFeature(SearchFeatureParameter searchParam)
throws ModelException, ApplicationException {
HttpConnection connection = null;
String results;
String webGISURL = searchParam.getWebGISURL();
StringBuffer url = new StringBuffer(webGISURL);
url
.append((webGISURL.lastIndexOf('/') != (webGISURL.length() - 1)) ? "/searchfeatures?"
: "searchfeatures?");
url.append("minx=").append(searchParam.getBoundingBox()[0].toString());
url.append("&miny=").append(searchParam.getBoundingBox()[1].toString());
url.append("&maxx=").append(searchParam.getBoundingBox()[2].toString());
url.append("&maxy=").append(searchParam.getBoundingBox()[3].toString());
url.append("&word=").append(searchParam.getKeyWord());
url.append("&start=").append(searchParam.getStart());
url.append("&SRS=EPSG:4326");
webGISURL = url.toString();
// For testing only
// webGISURL =
// "http://khanhlnq:8080/jvnwebgis/searchfeatures?minx=617420&miny=1144670&maxx=752520&maxy=1238000&word=n&start=0"
// ;
if (internalCache.containsKey(webGISURL)) {
System.out.println("Pull data from cache \n" + webGISURL);
results = (String) internalCache.get(webGISURL);
} else {
try {
connection = openGETConnection(webGISURL);
updateProgress();
results = readStringContent(connection);
internalCache.put(webGISURL, results);
updateProgress();
} catch (IOException ioe) {
System.out.println();
ioe.printStackTrace();
throw new ApplicationException(
MessageCodes.ERROR_CANNOT_CONNECT, ioe.getMessage());
}
}
return results;
}
public String getFeatureInfo(WMSRequestParameter requestParam,
Vector layerList, String infoLayer) throws ModelException,
ApplicationException {
HttpConnection connection = null;
// Try to free-up memory first
System.gc();
updateProgress();
String results;
String wmsUrl = requestParam.getGetMapURL();
StringBuffer url = new StringBuffer(wmsUrl);
url.append(wmsUrl.indexOf("?") < 0 ? "?" : "&");
url.append("request=GetFeatureInfo");
url.append("&service=wms");
url.append("&styles="); // 7.2.3.4; MUST be present and
// may be a null value for default
// or must one from the list.
url.append("&layers=");
for (int i = 0; i < layerList.size(); i++) {
url.append(((LayerInformation) layerList.elementAt(i))
.getField("name"));
url.append(",");
}
// Delete the last comma
url.deleteCharAt(url.length() - 1);
url.append("&bbox=").append(
new Float(requestParam.getBoundingX1()).toString());
url.append(",").append(
new Float(requestParam.getBoundingY1()).toString());
url.append(",").append(
new Float(requestParam.getBoundingX2()).toString());
url.append(",").append(
new Float(requestParam.getBoundingY2()).toString());
url.append("&SRS=").append(requestParam.getSRS());
url.append("&width=").append(requestParam.getPixelWidth()).append(
"&height=").append(requestParam.getPixelHeight());
url.append("&format=").append(requestParam.getImageFormat());
url.append("&query_layers=").append(infoLayer);
url.append("&info_format=").append(requestParam.getTextFormat());
url.append("&x=").append(requestParam.getX());
url.append("&y=").append(requestParam.getY());
url.append("&feature_count=1");
url.append("&exceptions=").append(requestParam.getTextFormat());
url.append("&version=").append(requestParam.getVersion());
wmsUrl = url.toString();
// wmsUrl =
// "http://localhost:8080/geoserver/wms?&request=FindPath&service=wms&styles=&LAYERS=jvn:roads_topo&spoint=105.94586,10.78163&epoint=105.94065,10.79906&bbox=105.93026,10.75845,105.95795,10.80074&SRS=EPSG:4326&width=240&height=367&format=text/xml&version=1.1.1"
// ;
if (internalCache.containsKey(wmsUrl)) {
System.out.println("Pull data from cache \n" + wmsUrl);
results = (String) internalCache.get(wmsUrl);
} else {
try {
connection = openGETConnection(wmsUrl);
results = readStringContent(connection);
internalCache.put(wmsUrl, results);
updateProgress();
} catch (IOException ioe) {
// int ch;
// try {
// while ((ch = inputStream.read()) != -1) {
// System.out.print((char)ch);
// }
// } catch (IOException e) {
// e.printStackTrace();
// }
System.out.println();
ioe.printStackTrace();
throw new ApplicationException(
MessageCodes.ERROR_CANNOT_CONNECT, ioe.getMessage());
}
}
return results;
}
public String checkUpdate(String updateURL) throws ModelException,
ApplicationException {
HttpConnection connection = null;
String results;
try {
connection = openGETConnection(updateURL);
results = readStringContent(connection);
} catch (IOException ioe) {
System.out.println();
ioe.printStackTrace();
throw new ApplicationException(ioe);
}
return results;
}
/*
* public Image viewPathWMS(WMSRequestParameter requestParam) throws
* ModelException, ApplicationException { HttpConnection connection = null;
* InputStream inputStream = null; Image path; // Try to free-up memory
* first System.gc(); updateProgress(); String wmsUrl =
* requestParam.getGetMapURL(); StringBuffer url = new StringBuffer(wmsUrl);
* url.append(wmsUrl.indexOf("?") < 0 ? "?" : "&");
* url.append("request=FindPath"); url.append("&service=wms");
* url.append("&styles="); // 7.2.3.4; MUST be present and // may be a null
* value for default // or must one from the list. url.append("&layers=");
* url.append(requestParam.getFindPathLayer());
* url.append("&spoint=").append
* (requestParam.getStartPoint()[0]).append(",")
* .append(requestParam.getStartPoint()[1]);
* url.append("&epoint=").append(requestParam
* .getEndPoint()[0]).append(",").append(requestParam.getEndPoint()[1]);
* url.append("&bbox=").append(new
* Float(requestParam.getBoundingX1()).toString());
* url.append(",").append(new
* Float(requestParam.getBoundingY1()).toString());
* url.append(",").append(new
* Float(requestParam.getBoundingX2()).toString());
* url.append(",").append(new
* Float(requestParam.getBoundingY2()).toString());
* url.append("&SRS=").append(requestParam.getSRS());
* url.append("&width=").append
* (requestParam.getPixelWidth()).append("&height="
* ).append(requestParam.getPixelHeight());
* url.append("&format=").append(requestParam.getPNGFormat());
* url.append("&exceptions=").append(requestParam.getTextFormat());
* url.append("&version=").append(requestParam.getVersion()); wmsUrl =
* url.toString(); // wmsUrl = //
* "http://localhost:8080/geoserver/wms?&request=FindPath&service=wms&styles=&LAYERS=jvn:roads_topo&spoint=105.94586,10.78163&epoint=105.94065,10.79906&bbox=105.93026,10.75845,105.95795,10.80074&SRS=EPSG:4326&width=240&height=367&format=image/png&version=1.1.1"
* ; try { connection = openGETConnection(wmsUrl); updateProgress();
* inputStream = openConnectionInputStream(connection); updateProgress(); //
* Check for content type String contentType =
* connection.getHeaderField("content-type"); if
* (!contentType.equals(requestParam.getImageFormat())) { StringBuffer
* msgBuf = new StringBuffer(); int ch; while ((ch = inputStream.read()) !=
* -1) { msgBuf.append((char) ch); } throw new
* ApplicationException(msgBuf.toString()); } // Read input stream into
* byte[] ByteArrayOutputStream baos = new ByteArrayOutputStream(); int ch;
* while ((ch = inputStream.read()) != -1) { baos.write(ch); } path =
* Image.createImage(baos.toByteArray(), 0, baos.size()); } catch
* (IOException ioe) { System.out.println(); ioe.printStackTrace(); throw
* new ApplicationException(ioe); } finally { closeConnection(connection,
* inputStream); } return path; }
*/
public String getCapabilitiesWMS(String serviceURL) throws ModelException,
ApplicationException {
HttpConnection connection;
// Try to free-up memory first
System.gc();
updateProgress();
String results;
if (internalCache.containsKey(serviceURL)) {
System.out.println("Pull data from cache \n" + serviceURL);
results = (String) internalCache.get(serviceURL);
} else {
try {
connection = openGETConnection(serviceURL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -