Revision 1964 org.gvsig.raster.wmts/trunk/org.gvsig.raster.wmts/org.gvsig.raster.wmts.ogc/org.gvsig.raster.wmts.ogc.impl/src/main/java/org/gvsig/raster/wmts/ogc/impl/base/WMTSProtocolHandler.java
WMTSProtocolHandler.java | ||
---|---|---|
33 | 33 |
import java.net.HttpURLConnection; |
34 | 34 |
import java.net.MalformedURLException; |
35 | 35 |
import java.net.URL; |
36 |
import java.nio.ByteBuffer; |
|
37 |
import java.nio.channels.FileChannel; |
|
36 | 38 |
import java.security.KeyManagementException; |
37 | 39 |
import java.security.NoSuchAlgorithmException; |
38 | 40 |
import java.util.ArrayList; |
... | ... | |
58 | 60 |
import org.gvsig.raster.wmts.ogc.impl.request.WMTSGetCapabilitiesRequest; |
59 | 61 |
import org.gvsig.raster.wmts.ogc.impl.request.WMTSGetFeatureInfoRequest; |
60 | 62 |
import org.gvsig.raster.wmts.ogc.impl.request.WMTSGetTileRequest; |
63 |
import org.gvsig.raster.wmts.ogc.struct.WMTSLayer; |
|
61 | 64 |
import org.gvsig.raster.wmts.ogc.struct.WMTSOperationsMetadata; |
65 |
import org.gvsig.raster.wmts.ogc.struct.WMTSStyle; |
|
62 | 66 |
import org.kxml2.io.KXmlParser; |
63 | 67 |
import org.xmlpull.v1.XmlPullParserException; |
64 | 68 |
|
... | ... | |
467 | 471 |
sc.init(null, trustAllCerts, new java.security.SecureRandom()); |
468 | 472 |
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); |
469 | 473 |
} |
470 |
|
|
474 |
|
|
471 | 475 |
/** |
472 |
* <p>It will send a GetFeatureInfo request to the WMTS |
|
476 |
* @return string that represents the url for getting the wms legend |
|
477 |
* If the layer has the object layer-->style-->legendurl that url will be returned |
|
478 |
* otherwise builds the getLegendGraphic according to the OGC WMS Specifications |
|
479 |
* |
|
480 |
*/ |
|
481 |
/*private String buildGetLegendGraphicRequest(WMTSLayer layer, WMTSStyle style) { |
|
482 |
String onlineResource = style.getLegendURL().getHref(); |
|
483 |
String symbol = getSymbol(onlineResource); |
|
484 |
String layerName = layer.getTitle(); |
|
485 |
|
|
486 |
if(onlineResource == null || onlineResource.equals("")) |
|
487 |
return null; |
|
488 |
|
|
489 |
StringBuffer req = new StringBuffer(); |
|
490 |
req.append(onlineResource + symbol + "REQUEST=GetLegendGraphic&SERVICE=WMS&VERSION=").append(getVersion()); |
|
491 |
req.append("&LAYER=" + layerName).append("&TRANSPARENT=TRUE").append("&FORMAT=image/png"); |
|
492 |
String aux = req.toString().replaceAll(" ", "%20"); |
|
493 |
System.out.println("GetLegendGraphic url:" + aux); |
|
494 |
return aux; |
|
495 |
}*/ |
|
496 |
|
|
497 |
public File getLegendGraphic(WMTSLayer layer, WMTSStyle style, ICancellable cancel) |
|
498 |
throws ServerErrorException, WMTSException, DownloadException { |
|
499 |
URL request = null; |
|
500 |
try { |
|
501 |
String requestStr = style.getLegendURL().getHref(); |
|
502 |
if(requestStr == null || requestStr.equals("")) |
|
503 |
return null; |
|
504 |
request = new URL(requestStr); |
|
505 |
System.out.println(requestStr); |
|
506 |
|
|
507 |
File f = downloadFile(request, cancel); |
|
508 |
if (f== null) |
|
509 |
return null; |
|
510 |
if (Utilities.isTextFile(f)) { |
|
511 |
FileInputStream fis = new FileInputStream(f); |
|
512 |
FileChannel fc = fis.getChannel(); |
|
513 |
byte[] data = new byte[(int)fc.size()]; |
|
514 |
ByteBuffer bb = ByteBuffer.wrap(data); |
|
515 |
fc.read(bb); |
|
516 |
|
|
517 |
WMTSException wmsEx = null; |
|
518 |
|
|
519 |
String exceptionMessage = parseException(data); |
|
520 |
if (exceptionMessage == null) { |
|
521 |
String error = new String(data); |
|
522 |
int pos = error.indexOf("<?xml"); |
|
523 |
if (pos!= -1) { |
|
524 |
String xml = error.substring(pos,error.length()); |
|
525 |
exceptionMessage = parseException(xml.getBytes()); |
|
526 |
} |
|
527 |
if (exceptionMessage == null) |
|
528 |
exceptionMessage = new String(data); |
|
529 |
|
|
530 |
} |
|
531 |
wmsEx = new WMTSException(exceptionMessage); |
|
532 |
wmsEx.setWMTSMessage(new String(data)); |
|
533 |
Utilities.removeURL(request); |
|
534 |
fis.close(); |
|
535 |
throw wmsEx; |
|
536 |
} |
|
537 |
return f; |
|
538 |
} catch(IOException e) { |
|
539 |
e.printStackTrace(); |
|
540 |
throw new ServerErrorException(); |
|
541 |
} |
|
542 |
} |
|
543 |
|
|
544 |
/** |
|
545 |
* <p>It will send a GetFeatureInfo request to the WMTS |
|
473 | 546 |
* Parsing the response and redirecting the info to the WMTS client</p> |
474 | 547 |
* TODO: return a stored file instead a String. |
475 | 548 |
*/ |
Also available in: Unified diff