diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval.wfs/src/com/raytheon/uf/edex/datadelivery/retrieval/wfs/WfsRetrievalGenerator.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval.wfs/src/com/raytheon/uf/edex/datadelivery/retrieval/wfs/WfsRetrievalGenerator.java index e6fdd7662e..6995588a57 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval.wfs/src/com/raytheon/uf/edex/datadelivery/retrieval/wfs/WfsRetrievalGenerator.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval.wfs/src/com/raytheon/uf/edex/datadelivery/retrieval/wfs/WfsRetrievalGenerator.java @@ -1,9 +1,7 @@ package com.raytheon.uf.edex.datadelivery.retrieval.wfs; -import java.text.ParseException; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.List; import com.raytheon.uf.common.datadelivery.registry.Coverage; @@ -19,7 +17,6 @@ import com.raytheon.uf.common.datadelivery.retrieval.xml.Retrieval; import com.raytheon.uf.common.datadelivery.retrieval.xml.RetrievalAttribute; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; -import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.edex.datadelivery.retrieval.RetrievalGenerator; import com.raytheon.uf.edex.datadelivery.retrieval.adapters.RetrievalAdapter; diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/src/com/raytheon/uf/edex/datadelivery/retrieval/util/WfsConnectionUtil.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/src/com/raytheon/uf/edex/datadelivery/retrieval/util/WfsConnectionUtil.java index b078347c8c..db0f7e4086 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/src/com/raytheon/uf/edex/datadelivery/retrieval/util/WfsConnectionUtil.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/src/com/raytheon/uf/edex/datadelivery/retrieval/util/WfsConnectionUtil.java @@ -1,11 +1,14 @@ package com.raytheon.uf.edex.datadelivery.retrieval.util; import java.net.URI; +import java.net.URISyntaxException; import org.apache.http.client.methods.HttpGet; import com.raytheon.uf.common.comm.HttpClient; import com.raytheon.uf.common.comm.HttpClient.HttpClientResponse; +import com.raytheon.uf.common.comm.IHttpsConfiguration; +import com.raytheon.uf.common.comm.IHttpsCredentialsHandler; import com.raytheon.uf.common.datadelivery.registry.Connection; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; @@ -36,17 +39,14 @@ public class WfsConnectionUtil { private static final IUFStatusHandler statusHandler = UFStatus .getHandler(WfsConnectionUtil.class); - + public static String wfsConnect(String url, Connection conn, String providerName) { String xmlResponse = null; HttpClient http = null; try { - // Sets up any proxy info that might be necessary // TODO: consider using HTTP POST instead of GET - ConnectionUtil.getProxyParameters(); - //url = url.replace("https://dev11:8888", "http://dev05:8085"); http = HttpClient.getInstance(); HttpGet get = new HttpGet(); URI uri = new URI(url); @@ -55,6 +55,9 @@ public class WfsConnectionUtil { && conn.getPassword() != null) { statusHandler.handle(Priority.INFO, "Attempting credential request: " + providerName); + http.setHandler(new WfsCredentialsHandler(conn.getUserName(), + conn.getUnencryptedPassword())); + http.setHttpsConfiguration(new WfsHttpsConfiguration(uri)); http.setCredentials(uri.getHost(), uri.getPort(), providerName, conn.getUserName(), conn.getUnencryptedPassword()); } @@ -62,6 +65,7 @@ public class WfsConnectionUtil { get.setURI(uri); HttpClientResponse response = http.executeRequest(get); xmlResponse = new String(response.data); + //System.out.println("Response: "+xmlResponse); } catch (Exception e) { statusHandler.handle(Priority.PROBLEM, @@ -70,5 +74,93 @@ public class WfsConnectionUtil { return xmlResponse; } + + /** + * + * Credentials Holder + * + *
+     *
+     * SOFTWARE HISTORY
+     *
+     * Date         Ticket#    Engineer    Description
+     * ------------ ---------- ----------- --------------------------
+     * Jun 19, 2013  2120       dhladky     Initial creation
+     *
+     * 
+ * + * @author dhladky + * @version 1.0 + */ + private static class WfsCredentialsHandler implements IHttpsCredentialsHandler { + private String username; + + private String password; + + @Override + public String[] getCredentials(String message) { + return new String[] { username, + password }; + } + + public WfsCredentialsHandler(String username, String password) { + this.password = password; + this.username = username; + } + } + + /** + * + * HTTPS Configuration + * + *
+     *
+     * SOFTWARE HISTORY
+     *
+     * Date         Ticket#    Engineer    Description
+     * ------------ ---------- ----------- --------------------------
+     * Jun 19, 2013  2120       dhladky     Initial creation
+     *
+     * 
+ * + * @author dhladky + * @version 1.0 + */ + private static class WfsHttpsConfiguration implements IHttpsConfiguration { + + private int httpsPort = 443; + + private int httpPort = 80; + + public WfsHttpsConfiguration(URI uri) { + + try { + if (uri.getScheme().equals("http")) { + httpPort = uri.getPort(); + } else if (uri.getScheme().equals("https")) { + httpsPort = uri.getPort(); + if (httpsPort == -1) { + httpsPort = 443; // The default https port + } + } else { + throw new URISyntaxException(uri.toString(), + "Invalid server"); + } + } catch (URISyntaxException e) { + statusHandler.handle(Priority.PROBLEM, "Syntax or URI is bad!", e); + } + } + + @Override + public int getHttpsPort() { + return httpsPort; + } + + @Override + public int getHttpPort() { + return httpPort; + } + } + } diff --git a/tests/unit/com/raytheon/uf/common/util/ProxiedJettyServer.java b/tests/unit/com/raytheon/uf/common/util/ProxiedJettyServer.java index 5e94145f7d..6cfbd345e0 100644 --- a/tests/unit/com/raytheon/uf/common/util/ProxiedJettyServer.java +++ b/tests/unit/com/raytheon/uf/common/util/ProxiedJettyServer.java @@ -36,6 +36,8 @@ import org.eclipse.jetty.servlets.ProxyServlet; import org.eclipse.jetty.util.security.Constraint; import org.eclipse.jetty.util.security.Credential; +import com.raytheon.uf.common.comm.HttpProxyTestConstants; + /** * This class sets up a Jetty Server that can serve up Proxied HttpServlets in * either http or https mode. @@ -227,6 +229,6 @@ public class ProxiedJettyServer { // Run this server ProxiedJettyServer server = new ProxiedJettyServer(redirectHost, port, sport, context, realm, user, password); - server.startServer(); + server.startSSLServer(); } } \ No newline at end of file