diff --git a/src/gov/nasa/worldwind/avlist/AVKey.java b/src/gov/nasa/worldwind/avlist/AVKey.java index 996ced8451..b126b16a3e 100644 --- a/src/gov/nasa/worldwind/avlist/AVKey.java +++ b/src/gov/nasa/worldwind/avlist/AVKey.java @@ -56,6 +56,8 @@ public interface AVKey // TODO: Eliminate unused constants, if any final String BALLOON = "gov.nasa.worldwind.avkey.Balloon"; final String BALLOON_TEXT = "gov.nasa.worldwind.avkey.BalloonText"; final String BACK = "gov.nasa.worldwind.avkey.Back"; + final String BASIC_AUTH_USERNAME = "gov.nasa.worldwind.avkey.BasicAuthUsername"; + final String BASIC_AUTH_PASSWORD = "gov.nasa.worldwind.avkey.BasicAuthPassword"; final String BEGIN = "gov.nasa.worldwind.avkey.Begin"; final String BIG_ENDIAN = "gov.nasa.worldwind.avkey.BigEndian"; final String BOTTOM = "gov.nasa.worldwind.avkey.Bottom"; diff --git a/src/gov/nasa/worldwind/layers/rpf/RPFRetriever.java b/src/gov/nasa/worldwind/layers/rpf/RPFRetriever.java index c3b39d199e..9059a046e8 100644 --- a/src/gov/nasa/worldwind/layers/rpf/RPFRetriever.java +++ b/src/gov/nasa/worldwind/layers/rpf/RPFRetriever.java @@ -65,6 +65,8 @@ class RPFRetriever extends WWObjectImpl implements Retriever public static final int RESPONSE_CODE_OK = 1; public static final int RESPONSE_CODE_NO_CONTENT = 2; + protected String basicAuthenticationEncodedString; + public RPFRetriever(RPFGenerator.RPFServiceInstance service, URL url, RetrievalPostProcessor postProcessor) { if (service == null) @@ -196,6 +198,11 @@ public void setStaleRequestLimit(int staleRequestLimit) this.staleRequestLimit = staleRequestLimit; } + @Override + public void setBasicAuthentication(String basicAuthorizationString) { + this.basicAuthenticationEncodedString = basicAuthorizationString; + } + public final RPFGenerator.RPFServiceInstance getService() { return this.service; diff --git a/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100Capabilities.java b/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100Capabilities.java index 5c310a21a9..d005d02aaa 100644 --- a/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100Capabilities.java +++ b/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100Capabilities.java @@ -62,13 +62,31 @@ public class WCS100Capabilities extends AbstractXMLEventParser * if an error occurs retrieving the document. */ public static WCS100Capabilities retrieve(URI uri) throws Exception + { + return retrieve(uri, null, null); + } + + /** + * Retrieves the WCS capabilities document from a specified WCS server. + * + * @param uri The URI of the server. + * @param basicAuthUsername Username for Basic Authentication + * @param basicAuthPassword Password for Basic Authentication + * + * @return The WCS capabilities document for the specified server. + * + * @throws IllegalArgumentException if the specified URI is invalid. + * @throws gov.nasa.worldwind.exception.WWRuntimeException + * if an error occurs retrieving the document. + */ + public static WCS100Capabilities retrieve(URI uri, String basicAuthUsername, String basicAuthPassword) throws Exception { try { CapabilitiesRequest request = new CapabilitiesRequest(uri, "WCS"); request.setVersion("1.0.0"); - return new WCS100Capabilities(request.toString()); + return new WCS100Capabilities(request.toString(), basicAuthUsername, basicAuthPassword); } catch (URISyntaxException e) { @@ -79,10 +97,22 @@ public static WCS100Capabilities retrieve(URI uri) throws Exception } public WCS100Capabilities(Object docSource) + { + this(docSource, null, null); + } + + /** + * Constructs WCS100Capabilities with an optional Base64 Encoded String for Basic Authentication + * + * @param docSource + * @param basicAuthUsername Username for Basic Authentication + * @param basicAuthUsername Password for Basic Authentication + */ + public WCS100Capabilities(Object docSource, String basicAuthUsername, String basicAuthPassword) { super(OGCConstants.WCS_1_0_0_NAMESPACE_URI); - this.eventReader = this.createReader(docSource); + this.eventReader = this.createReader(docSource, basicAuthUsername, basicAuthPassword); this.initialize(); } @@ -92,9 +122,9 @@ protected void initialize() this.parserContext = this.createParserContext(this.eventReader); } - protected XMLEventReader createReader(Object docSource) + protected XMLEventReader createReader(Object docSource, String basicAuthUsername, String basicAuthPassword) { - return WWXML.openEventReader(docSource); + return WWXML.openEventReader(docSource, basicAuthUsername, basicAuthPassword); } protected XMLEventParserContext createParserContext(XMLEventReader reader) diff --git a/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100DescribeCoverage.java b/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100DescribeCoverage.java index 1f2ac0ea2f..1d0ff43767 100644 --- a/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100DescribeCoverage.java +++ b/src/gov/nasa/worldwind/ogc/wcs/wcs100/WCS100DescribeCoverage.java @@ -50,7 +50,29 @@ public class WCS100DescribeCoverage extends AbstractXMLEventParser protected XMLEventParserContext parserContext; protected List coverageOfferings = new ArrayList(1); - public static WCS100DescribeCoverage retrieve(URI uri, final String coverageName) throws URISyntaxException + /** + * Retrieve WCS 100 Coverage + * + * @param uri uri + * @param coverageName name of coverage + * @return WCS100DescribeCoverage + * @throws URISyntaxException URI Syntax incorrect + */ + public static WCS100DescribeCoverage retrieve(URI uri, final String coverageName) throws URISyntaxException{ + return retrieve(uri, coverageName, null, null); + } + + /** + * Retrieve WCS 100 Coverage + * + * @param uri uri + * @param coverageName name of coverage + * @param basicAuthUsername Basic Authentication Username + * @param basicAuthPassword Basic Authentication Password + * @return WCS100DescribeCoverage + * @throws URISyntaxException URI Syntax incorrect + */ + public static WCS100DescribeCoverage retrieve(URI uri, final String coverageName, String basicAuthUsername, String basicAuthPassword) throws URISyntaxException { Request request = new Request(uri, "WCS") { @@ -64,14 +86,19 @@ protected void initialize(String service) } }; - return new WCS100DescribeCoverage(request.toString()); + return new WCS100DescribeCoverage(request.toString(), basicAuthUsername, basicAuthPassword); } public WCS100DescribeCoverage(Object docSource) + { + this(docSource, null, null); + } + + public WCS100DescribeCoverage(Object docSource, String basicAuthUsername, String basicAuthPassword) { super(OGCConstants.WCS_1_0_0_NAMESPACE_URI); - this.eventReader = this.createReader(docSource); + this.eventReader = this.createReader(docSource, basicAuthUsername, basicAuthPassword); this.initialize(); } @@ -81,9 +108,9 @@ protected void initialize() this.parserContext = this.createParserContext(this.eventReader); } - protected XMLEventReader createReader(Object docSource) + protected XMLEventReader createReader(Object docSource, String basicAuthUsername, String basicAuthPassword) { - return WWXML.openEventReader(docSource); + return WWXML.openEventReader(docSource, basicAuthUsername, basicAuthPassword); } protected XMLEventParserContext createParserContext(XMLEventReader reader) diff --git a/src/gov/nasa/worldwind/retrieve/LocalRasterServerRetriever.java b/src/gov/nasa/worldwind/retrieve/LocalRasterServerRetriever.java index 5b48fb4f36..03b78f03d2 100644 --- a/src/gov/nasa/worldwind/retrieve/LocalRasterServerRetriever.java +++ b/src/gov/nasa/worldwind/retrieve/LocalRasterServerRetriever.java @@ -56,7 +56,7 @@ public class LocalRasterServerRetriever extends WWObjectImpl implements Retrieve protected long submitTime; protected long beginTime; protected long endTime; - + protected String basicAuthenticationEncodedString; public LocalRasterServerRetriever(AVList params, RasterServer rasterServer, RetrievalPostProcessor postProcessor) { if (null != params) @@ -177,6 +177,11 @@ public void setStaleRequestLimit(int staleRequestLimit) this.staleRequestLimit = staleRequestLimit; } + @Override + public void setBasicAuthentication(String basicAuthorizationString) { + this.basicAuthenticationEncodedString = basicAuthorizationString; + } + public Retriever call() throws Exception { try diff --git a/src/gov/nasa/worldwind/retrieve/Retriever.java b/src/gov/nasa/worldwind/retrieve/Retriever.java index eac9f68d53..c24565eaa2 100644 --- a/src/gov/nasa/worldwind/retrieve/Retriever.java +++ b/src/gov/nasa/worldwind/retrieve/Retriever.java @@ -86,4 +86,6 @@ public interface Retriever extends WWObject, java.util.concurrent.Callable + *
  • {@link URL}
  • {@link InputStream}
  • {@link File}
  • {@link String} containing a valid URL + * description or a file or resource name available on the classpath.
  • + * + * @param docSource the source of the XML document. + * @param basicAuthPassword Username for Basic Authentication + * @param basicAuthUsername Password for Basic Authentication + * + * @return the source document as a {@link javax.xml.stream.XMLEventReader}, or null if the source object is a + * string that does not identify a URL, a file or a resource available on the classpath. + */ + public static XMLEventReader openEventReader(Object docSource, String basicAuthUsername, String basicAuthPassword) + { + return openEventReader(docSource, true, basicAuthUsername, basicAuthPassword); } /** @@ -498,6 +540,24 @@ public static XMLEventReader openEventReader(Object docSource) * string that does not identify a URL, a file or a resource available on the classpath. */ public static XMLEventReader openEventReader(Object docSource, boolean isNamespaceAware) + { + return openEventReader(docSource, isNamespaceAware, null, null); + } + + /** + * Open an XML event stream from a general source. The source type may be one of the following:
    • {@link + * URL}
    • {@link InputStream}
    • {@link File}
    • {@link String} containing a valid URL + * description or a file or resource name available on the classpath.
    + * + * @param docSource the source of the XML document. + * @param isNamespaceAware true to enable namespace-aware processing and false to disable it. + * @param basicAuthUsername Username for Basic Authentication + * @param basicAuthPassword Password for Basic Authentication + * + * @return the source document as a {@link javax.xml.stream.XMLEventReader}, or null if the source object is a + * string that does not identify a URL, a file or a resource available on the classpath. + */ + public static XMLEventReader openEventReader(Object docSource, boolean isNamespaceAware, String basicAuthUsername, String basicAuthPassword) { if (docSource == null || WWUtil.isEmpty(docSource)) { @@ -534,7 +594,7 @@ else if (!(docSource instanceof String)) URL url = WWIO.makeURL(sourceName); if (url != null) - return openEventReaderURL(url, isNamespaceAware); + return openEventReaderURL(url, isNamespaceAware, basicAuthUsername, basicAuthPassword); return openEventReaderFile(sourceName, null, isNamespaceAware); }