/** @deprecated use {@link #AbstractOpenWebService(OWSConfig, Capabilities)} */ public AbstractOpenWebService(C capabilties, URL serverURL) throws ServiceException, IOException { this(serverURL, new SimpleHttpClient(), capabilties); }
/** * Set up the specifications used and retrieve the Capabilities document given by serverURL. * * @param serverURL a URL that points to the capabilities document of a server * @throws IOException if there is an error communicating with the server * @throws ServiceException if the server responds with an error */ public AbstractOpenWebService(final URL serverURL) throws IOException, ServiceException { this(serverURL, new SimpleHttpClient(), null); }
private HTTPClient getHTTPClient(HTTPStoreInfo info) { String capabilitiesURL = info.getCapabilitiesURL(); // check for mock bindings. Since we are going to run this code in production as well, // guard it so that it only triggers if the MockHttpClientProvider has any active binding if (TestHttpClientProvider.testModeEnabled() && capabilitiesURL.startsWith(TestHttpClientProvider.MOCKSERVER)) { HTTPClient client = TestHttpClientProvider.get(capabilitiesURL); return client; } HTTPClient client; if (info.isUseConnectionPooling()) { client = new MultithreadedHttpClient(); if (info.getMaxConnections() > 0) { int maxConnections = info.getMaxConnections(); MultithreadedHttpClient mtClient = (MultithreadedHttpClient) client; mtClient.setMaxConnections(maxConnections); } } else { client = new SimpleHttpClient(); } String username = info.getUsername(); String password = info.getPassword(); int connectTimeout = info.getConnectTimeout(); int readTimeout = info.getReadTimeout(); client.setUser(username); client.setPassword(password); client.setConnectTimeout(connectTimeout); client.setReadTimeout(readTimeout); return client; }
/** @deprecated use {@link #AbstractOpenWebService(OWSConfig)} */ public AbstractOpenWebService(final URL serverURL, int requestTimeout) throws IOException, ServiceException { this(serverURL, new SimpleHttpClient(), null); this.httpClient.setConnectTimeout(requestTimeout); this.httpClient.setReadTimeout(requestTimeout); }
/** * Creates the HttpClient instance used to connect to the WFS service, compatible with the given * parameters. * * @param params wfs service connection parameters * @return the HttpClient instance * @throws IOException */ public HTTPClient getHttpClient(final Map<String, Serializable> params) throws IOException { final URL capabilitiesURL = (URL) URL.lookUp(params); final WFSConfig config = WFSConfig.fromParams(params); return config.isUseHttpConnectionPooling() && isHttp(capabilitiesURL) ? new MultithreadedHttpClient() : new SimpleHttpClient(); }
/** * @deprecated use {@link #AbstractOpenWebService(OWSConfig, Capabilities)} */ public AbstractOpenWebService(C capabilties, URL serverURL) throws ServiceException, IOException { this(serverURL, new SimpleHttpClient(), capabilties); }
/** * Set up the specifications used and retrieve the Capabilities document * given by serverURL. * * @param serverURL a URL that points to the capabilities document of a server * @throws IOException if there is an error communicating with the server * @throws ServiceException if the server responds with an error */ public AbstractOpenWebService(final URL serverURL) throws IOException, ServiceException { this(serverURL, new SimpleHttpClient(), null); }
final HTTPClient http = new SimpleHttpClient(); // new
WebMapServer getWMS() throws IOException, ServiceException { Map<String, Object> hints = new HashMap<>(); hints.put(XMLHandlerHints.ENTITY_RESOLVER, PreventLocalEntityResolver.INSTANCE); return new WebMapServer(new URL(url), new SimpleHttpClient(), hints); }
@Test public void testBasicHeader() throws IOException { stubFor( get(urlEqualTo("/test")) .willReturn( aResponse() .withStatus(200) .withHeader("Content-Type", "text/xml") .withBody("<response>Some content</response>"))); String longPassword = String.join("", Collections.nCopies(10, "0123456789")); String userName = "user"; SimpleHttpClient client = new SimpleHttpClient(); client.setUser(userName); client.setPassword(longPassword); client.get(new URL("http://localhost:" + wireMockRule.port() + "/test")); String encodedCredentials = "dXNlcjowMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5"; verify( getRequestedFor(urlEqualTo("/test")) .withHeader("Authorization", equalTo("Basic " + encodedCredentials))); } }
/** * @deprecated use {@link #AbstractOpenWebService(OWSConfig)} */ public AbstractOpenWebService(final URL serverURL, int requestTimeout) throws IOException, ServiceException { this(serverURL, new SimpleHttpClient(), null); this.httpClient.setConnectTimeout(requestTimeout); this.httpClient.setReadTimeout(requestTimeout); }
@Override public List<RasterCapabilitiesInfo> getRasterCapabilities(Map<String, String> connectionProperties) throws Exception { URL url = new URL(connectionProperties.get(GetWmsCapabilitiesRequest.GET_CAPABILITIES_URL)); SimpleHttpClient httpClient = new SimpleHttpClient(); if (connectionProperties.containsKey(WmsLayerBeanFactory.WMS_USERNAME)) { httpClient.setUser(connectionProperties.get(WmsLayerBeanFactory.WMS_USERNAME)); httpClient.setPassword(connectionProperties.get(WmsLayerBeanFactory.WMS_PASSWORD)); } WebMapServer wms = new WebMapServer(url, httpClient); WMSCapabilities capabilities = wms.getCapabilities(); List<RasterCapabilitiesInfo> layers = new ArrayList<RasterCapabilitiesInfo>(); List<RasterCapabilitiesInfo> nonNativeLayers = new ArrayList<RasterCapabilitiesInfo>(); for (org.geotools.data.ows.Layer owsLayer : WMSUtils.getNamedLayers(capabilities)) { if (owsLayer.getSrs().contains(defaultGeodesk.getMaps().get(0).getCrs())) { // Only add default crs layers.add(dtoFactoryService.buildRasterCapabilitesInfoFromWms(wms, owsLayer, defaultGeodesk.getMaps().get(0).getCrs())); } else { // Add all available crs-es for (String srs : owsLayer.getSrs()) { try { nonNativeLayers.add(dtoFactoryService.buildRasterCapabilitesInfoFromWms(wms, owsLayer, srs)); } catch (LayerException e) { log.warn("Got unknown crs from wms server, ignoring: {}", srs); } } } } layers.addAll(nonNativeLayers); return layers; }
@Override public List<RasterCapabilitiesInfo> getRasterCapabilities(Map<String, String> connectionProperties) throws Exception { URL url = new URL(connectionProperties.get(GetWmsCapabilitiesRequest.GET_CAPABILITIES_URL)); SimpleHttpClient httpClient = new SimpleHttpClient(); if (connectionProperties.containsKey(WmsLayerBeanFactory.WMS_USERNAME)) { httpClient.setUser(connectionProperties.get(WmsLayerBeanFactory.WMS_USERNAME)); httpClient.setPassword(connectionProperties.get(WmsLayerBeanFactory.WMS_PASSWORD)); } WebMapServer wms = new WebMapServer(url, httpClient); WMSCapabilities capabilities = wms.getCapabilities(); List<RasterCapabilitiesInfo> layers = new ArrayList<RasterCapabilitiesInfo>(); List<RasterCapabilitiesInfo> nonNativeLayers = new ArrayList<RasterCapabilitiesInfo>(); for (org.geotools.data.ows.Layer owsLayer : WMSUtils.getNamedLayers(capabilities)) { if (owsLayer.getSrs().contains(defaultGeodesk.getMaps().get(0).getCrs())) { // Only add default crs layers.add(dtoFactoryService.buildRasterCapabilitesInfoFromWms(wms, owsLayer, defaultGeodesk.getMaps().get(0).getCrs())); } else { // Add all available crs-es for (String srs : owsLayer.getSrs()) { try { nonNativeLayers.add(dtoFactoryService.buildRasterCapabilitesInfoFromWms(wms, owsLayer, srs)); } catch (LayerException e) { LOG.warn("Got unknown crs from wms server, ignoring: {}", srs); } } } } layers.addAll(nonNativeLayers); return layers; }
@Override protected void onValidate(IValidatable validatable) { String url = (String) validatable.getValue(); try { HTTPClient client = new SimpleHttpClient(); usernamePanel.getFormComponent().processInput(); String user = usernamePanel.getFormComponent().getInput(); password.getFormComponent().processInput(); String pwd = password.getFormComponent().getInput(); if (user != null && user.length() > 0 && pwd != null && pwd.length() > 0) { client.setUser(user); client.setPassword(pwd); } WebMapServer server = new WebMapServer(new URL(url), client); server.getCapabilities(); } catch(Exception e) { error(validatable, "WMSCapabilitiesValidator.connectionFailure", Collections.singletonMap("error", e.getMessage())); } }
/** * Creates the HttpClient instance used to connect to the WFS service, compatible with the given * parameters. * * @param params wfs service connection parameters * @return the HttpClient instance * @throws IOException */ public HTTPClient getHttpClient(final Map<String, Serializable> params) throws IOException { final URL capabilitiesURL = (URL) URL.lookUp(params); final WFSConfig config = WFSConfig.fromParams(params); return config.isUseHttpConnectionPooling() && isHttp(capabilitiesURL) ? new MultithreadedHttpClient() : new SimpleHttpClient(); }
String url = (String) validatable.getValue(); try { HTTPClient client = new SimpleHttpClient(); usernamePanel.getFormComponent().processInput(); String user = usernamePanel.getFormComponent().getInput();
String url = (String) validatable.getValue(); try { HTTPClient client = new SimpleHttpClient(); usernamePanel.getFormComponent().processInput(); String user = usernamePanel.getFormComponent().getInput();
final HTTPClient http = new SimpleHttpClient(); // new