@Test public void testServiceError() throws Exception { PowerMockito.whenNew(HttpClient.class) .withNoArguments() .thenReturn(clientMock) .thenReturn(clientMock); PowerMockito.whenNew(GetMethod.class) .withNoArguments() .thenReturn(getMock) .thenReturn(getMock); when(clientMock.executeMethod(getMock)) .thenReturn(HttpStatus.SC_OK) .thenReturn(HttpStatus.SC_OK); when(getMock.getResponseBodyAsStream()) .thenReturn( ArcGISRestDataStoreFactoryTest.readJSONAsStream("test-data/catalog.json")) .thenReturn( ArcGISRestDataStoreFactoryTest.readJSONAsStream("test-data/error.json")); try { this.dataStore = (ArcGISRestDataStore) ArcGISRestDataStoreFactoryTest.createDefaultOpenDataTestDataStore(); List<Name> names = this.dataStore.createTypeNames(); } catch (IOException e) { assertTrue(e.getMessage().contains("Cannot perform query")); } }
@Override protected List<Name> createTypeNames() { if (this.entries.isEmpty() == false) { return new ArrayList<Name>(this.entries.keySet()); } final List<Dataset> datasetList = this.getCatalog().getDataset(); List<Name> typeNames = new ArrayList<Name>(); ExecutorService executor = Executors.newFixedThreadPool(REQUEST_THREADS); final class WsCallResult { public Dataset dataset; public Webservice webservice; public WsCallResult(Dataset ds, Webservice ws) { this.dataset = ds; this.webservice = ws; }; } final class WsCall implements Callable<WsCallResult> { public final Dataset dataset; public final String webserviceUrl; public WsCall(Dataset dsIn, String wsUrl) { this.dataset = dsIn; this.webserviceUrl = wsUrl; } public WsCallResult call() throws Exception { Webservice ws = null; String responseWSString = null; try { responseWSString = ArcGISRestDataStore.InputStreamToString( retrieveJSON( "GET", new URL(this.webserviceUrl), ArcGISRestDataStore.DEFAULT_PARAMS)); } catch (IOException e) { LOGGER.log( Level.SEVERE, String.format( "Error during retrieval of dataset '%s' %s", this.webserviceUrl, e.getMessage()), e); return null; } try { ws = (new Gson()).fromJson(responseWSString, Webservice.class); if (ws == null || ws.getCurrentVersion() == null) { throw (new JsonSyntaxException("Malformed JSON")); } } catch (JsonSyntaxException e) { Error_ errWS = (new Gson()).fromJson(responseWSString, Error_.class); LOGGER.log( Level.SEVERE, String.format( "Error during retrieval of dataset '%s' %s %s ", this.webserviceUrl, errWS.getCode(), errWS.getMessage()), e); return null; } if (ws.getCurrentVersion() < MINIMUM_API_VERSION || ws.getSupportedQueryFormats() .toString() .toLowerCase() .contains(FORMAT_JSON.toLowerCase()) == false) { LOGGER.log( Level.SEVERE, String.format( "Dataset %s does not support either the API version supported ,or the GeoJSON format", this.webserviceUrl)); return null; } return new WsCallResult(this.dataset, ws); } } Collection<WsCall> calls = new ArrayList<WsCall>(); datasetList .stream() .forEach( (ds) -> { String ws = ArcGISRestDataStore.getWebServiceEndpoint(ds); if (ws != null) { calls.add(new WsCall(ds, ws)); } }); try { List<Future<WsCallResult>> futures = executor.invokeAll( calls, (REQUEST_TIMEOUT * calls.size()) / REQUEST_THREADS, TimeUnit.SECONDS); for (Future<WsCallResult> future : futures) { try { WsCallResult result = future.get(); if (result != null && result.webservice.getType() != null && result.webservice .getType() .equalsIgnoreCase(DATASETTYPE_FEATURELAYER) && result.webservice .getSupportedQueryFormats() .toLowerCase() .contains(FORMAT_JSON.toLowerCase()) && result.webservice.getCurrentVersion() >= MINIMUM_API_VERSION && result.webservice.getName().length() > 0 && result.webservice .getCapabilities() .toLowerCase() .contains(CAPABILITIES_QUERY.toLowerCase())) { Name dsName = new NameImpl( namespace.toExternalForm(), result.webservice.getName()); ContentEntry entry = new ContentEntry(this, dsName); this.datasets.put(dsName, result.dataset); this.entries.put(dsName, entry); } } catch (Exception e) { LOGGER.log( Level.SEVERE, String.format("Dataset call returned %s", e.getMessage())); } } } catch (Exception e) { LOGGER.log( Level.SEVERE, String.format( "Error during webservice calls %s", e.getMessage(), e.getStackTrace())); return new ArrayList<Name>(); } executor.shutdown(); return new ArrayList<Name>(this.entries.keySet()); }
ArcGISRestDataStore extends ContentDataStore { @Override protected List<Name> createTypeNames() { if (this.entries.isEmpty() == false) { return new ArrayList<Name>(this.entries.keySet()); } final List<Dataset> datasetList = this.getCatalog().getDataset(); List<Name> typeNames = new ArrayList<Name>(); ExecutorService executor = Executors.newFixedThreadPool(REQUEST_THREADS); final class WsCallResult { public Dataset dataset; public Webservice webservice; public WsCallResult(Dataset ds, Webservice ws) { this.dataset = ds; this.webservice = ws; }; } final class WsCall implements Callable<WsCallResult> { public final Dataset dataset; public final String webserviceUrl; public WsCall(Dataset dsIn, String wsUrl) { this.dataset = dsIn; this.webserviceUrl = wsUrl; } public WsCallResult call() throws Exception { Webservice ws = null; String responseWSString = null; try { responseWSString = ArcGISRestDataStore.InputStreamToString( retrieveJSON( "GET", new URL(this.webserviceUrl), ArcGISRestDataStore.DEFAULT_PARAMS)); } catch (IOException e) { LOGGER.log( Level.SEVERE, String.format( "Error during retrieval of dataset '%s' %s", this.webserviceUrl, e.getMessage()), e); return null; } try { ws = (new Gson()).fromJson(responseWSString, Webservice.class); if (ws == null || ws.getCurrentVersion() == null) { throw (new JsonSyntaxException("Malformed JSON")); } } catch (JsonSyntaxException e) { Error_ errWS = (new Gson()).fromJson(responseWSString, Error_.class); LOGGER.log( Level.SEVERE, String.format( "Error during retrieval of dataset '%s' %s %s ", this.webserviceUrl, errWS.getCode(), errWS.getMessage()), e); return null; } if (ws.getCurrentVersion() < MINIMUM_API_VERSION || ws.getSupportedQueryFormats() .toString() .toLowerCase() .contains(FORMAT_JSON.toLowerCase()) == false) { LOGGER.log( Level.SEVERE, String.format( "Dataset %s does not support either the API version supported ,or the GeoJSON format", this.webserviceUrl)); return null; } return new WsCallResult(this.dataset, ws); } } Collection<WsCall> calls = new ArrayList<WsCall>(); datasetList .stream() .forEach( (ds) -> { String ws = ArcGISRestDataStore.getWebServiceEndpoint(ds); if (ws != null) { calls.add(new WsCall(ds, ws)); } }); try { List<Future<WsCallResult>> futures = executor.invokeAll( calls, (REQUEST_TIMEOUT * calls.size()) / REQUEST_THREADS, TimeUnit.SECONDS); for (Future<WsCallResult> future : futures) { try { WsCallResult result = future.get(); if (result != null && result.webservice.getType() != null && result.webservice .getType() .equalsIgnoreCase(DATASETTYPE_FEATURELAYER) && result.webservice .getSupportedQueryFormats() .toLowerCase() .contains(FORMAT_JSON.toLowerCase()) && result.webservice.getCurrentVersion() >= MINIMUM_API_VERSION && result.webservice.getName().length() > 0 && result.webservice .getCapabilities() .toLowerCase() .contains(CAPABILITIES_QUERY.toLowerCase())) { Name dsName = new NameImpl( namespace.toExternalForm(), result.webservice.getName()); ContentEntry entry = new ContentEntry(this, dsName); this.datasets.put(dsName, result.dataset); this.entries.put(dsName, entry); } } catch (Exception e) { LOGGER.log( Level.SEVERE, String.format("Dataset call returned %s", e.getMessage())); } } } catch (Exception e) { LOGGER.log( Level.SEVERE, String.format( "Error during webservice calls %s", e.getMessage(), e.getStackTrace())); return new ArrayList<Name>(); } executor.shutdown(); return new ArrayList<Name>(this.entries.keySet()); } }
ArcGISRestDataStore extends ContentDataStore { @Override protected List<Name> createTypeNames() { if (this.entries.isEmpty() == false) { return new ArrayList<Name>(this.entries.keySet()); } final List<Dataset> datasetList = this.getCatalog().getDataset(); List<Name> typeNames = new ArrayList<Name>(); ExecutorService executor = Executors.newFixedThreadPool(REQUEST_THREADS); final class WsCallResult { public Dataset dataset; public Webservice webservice; public WsCallResult(Dataset ds, Webservice ws) { this.dataset = ds; this.webservice = ws; }; } final class WsCall implements Callable<WsCallResult> { public final Dataset dataset; public final String webserviceUrl; public WsCall(Dataset dsIn, String wsUrl) { this.dataset = dsIn; this.webserviceUrl = wsUrl; } public WsCallResult call() throws Exception { Webservice ws = null; String responseWSString = null; try { responseWSString = ArcGISRestDataStore.InputStreamToString( retrieveJSON( "GET", new URL(this.webserviceUrl), ArcGISRestDataStore.DEFAULT_PARAMS)); } catch (IOException e) { LOGGER.log( Level.SEVERE, String.format( "Error during retrieval of dataset '%s' %s", this.webserviceUrl, e.getMessage()), e); return null; } try { ws = (new Gson()).fromJson(responseWSString, Webservice.class); if (ws == null || ws.getCurrentVersion() == null) { throw (new JsonSyntaxException("Malformed JSON")); } } catch (JsonSyntaxException e) { Error_ errWS = (new Gson()).fromJson(responseWSString, Error_.class); LOGGER.log( Level.SEVERE, String.format( "Error during retrieval of dataset '%s' %s %s ", this.webserviceUrl, errWS.getCode(), errWS.getMessage()), e); return null; } if (ws.getCurrentVersion() < MINIMUM_API_VERSION || ws.getSupportedQueryFormats() .toString() .toLowerCase() .contains(FORMAT_JSON.toLowerCase()) == false) { LOGGER.log( Level.SEVERE, String.format( "Dataset %s does not support either the API version supported ,or the GeoJSON format", this.webserviceUrl)); return null; } return new WsCallResult(this.dataset, ws); } } Collection<WsCall> calls = new ArrayList<WsCall>(); datasetList .stream() .forEach( (ds) -> { String ws = ArcGISRestDataStore.getWebServiceEndpoint(ds); if (ws != null) { calls.add(new WsCall(ds, ws)); } }); try { List<Future<WsCallResult>> futures = executor.invokeAll( calls, (REQUEST_TIMEOUT * calls.size()) / REQUEST_THREADS, TimeUnit.SECONDS); for (Future<WsCallResult> future : futures) { try { WsCallResult result = future.get(); if (result != null && result.webservice.getType() != null && result.webservice .getType() .equalsIgnoreCase(DATASETTYPE_FEATURELAYER) && result.webservice .getSupportedQueryFormats() .toLowerCase() .contains(FORMAT_JSON.toLowerCase()) && result.webservice.getCurrentVersion() >= MINIMUM_API_VERSION && result.webservice.getName().length() > 0 && result.webservice .getCapabilities() .toLowerCase() .contains(CAPABILITIES_QUERY.toLowerCase())) { Name dsName = new NameImpl( namespace.toExternalForm(), result.webservice.getName()); ContentEntry entry = new ContentEntry(this, dsName); this.datasets.put(dsName, result.dataset); this.entries.put(dsName, entry); } } catch (Exception e) { LOGGER.log( Level.SEVERE, String.format("Dataset call returned %s", e.getMessage())); } } } catch (Exception e) { LOGGER.log( Level.SEVERE, String.format( "Error during webservice calls %s", e.getMessage(), e.getStackTrace())); return new ArrayList<Name>(); } executor.shutdown(); return new ArrayList<Name>(this.entries.keySet()); } ArcGISRestDataStore(
            String namespaceIn,
            String apiEndpoint,
            boolean opendataFlagIn,
            String user,
            String password); }
ArcGISRestDataStore extends ContentDataStore { @Override protected List<Name> createTypeNames() { if (this.entries.isEmpty() == false) { return new ArrayList<Name>(this.entries.keySet()); } final List<Dataset> datasetList = this.getCatalog().getDataset(); List<Name> typeNames = new ArrayList<Name>(); ExecutorService executor = Executors.newFixedThreadPool(REQUEST_THREADS); final class WsCallResult { public Dataset dataset; public Webservice webservice; public WsCallResult(Dataset ds, Webservice ws) { this.dataset = ds; this.webservice = ws; }; } final class WsCall implements Callable<WsCallResult> { public final Dataset dataset; public final String webserviceUrl; public WsCall(Dataset dsIn, String wsUrl) { this.dataset = dsIn; this.webserviceUrl = wsUrl; } public WsCallResult call() throws Exception { Webservice ws = null; String responseWSString = null; try { responseWSString = ArcGISRestDataStore.InputStreamToString( retrieveJSON( "GET", new URL(this.webserviceUrl), ArcGISRestDataStore.DEFAULT_PARAMS)); } catch (IOException e) { LOGGER.log( Level.SEVERE, String.format( "Error during retrieval of dataset '%s' %s", this.webserviceUrl, e.getMessage()), e); return null; } try { ws = (new Gson()).fromJson(responseWSString, Webservice.class); if (ws == null || ws.getCurrentVersion() == null) { throw (new JsonSyntaxException("Malformed JSON")); } } catch (JsonSyntaxException e) { Error_ errWS = (new Gson()).fromJson(responseWSString, Error_.class); LOGGER.log( Level.SEVERE, String.format( "Error during retrieval of dataset '%s' %s %s ", this.webserviceUrl, errWS.getCode(), errWS.getMessage()), e); return null; } if (ws.getCurrentVersion() < MINIMUM_API_VERSION || ws.getSupportedQueryFormats() .toString() .toLowerCase() .contains(FORMAT_JSON.toLowerCase()) == false) { LOGGER.log( Level.SEVERE, String.format( "Dataset %s does not support either the API version supported ,or the GeoJSON format", this.webserviceUrl)); return null; } return new WsCallResult(this.dataset, ws); } } Collection<WsCall> calls = new ArrayList<WsCall>(); datasetList .stream() .forEach( (ds) -> { String ws = ArcGISRestDataStore.getWebServiceEndpoint(ds); if (ws != null) { calls.add(new WsCall(ds, ws)); } }); try { List<Future<WsCallResult>> futures = executor.invokeAll( calls, (REQUEST_TIMEOUT * calls.size()) / REQUEST_THREADS, TimeUnit.SECONDS); for (Future<WsCallResult> future : futures) { try { WsCallResult result = future.get(); if (result != null && result.webservice.getType() != null && result.webservice .getType() .equalsIgnoreCase(DATASETTYPE_FEATURELAYER) && result.webservice .getSupportedQueryFormats() .toLowerCase() .contains(FORMAT_JSON.toLowerCase()) && result.webservice.getCurrentVersion() >= MINIMUM_API_VERSION && result.webservice.getName().length() > 0 && result.webservice .getCapabilities() .toLowerCase() .contains(CAPABILITIES_QUERY.toLowerCase())) { Name dsName = new NameImpl( namespace.toExternalForm(), result.webservice.getName()); ContentEntry entry = new ContentEntry(this, dsName); this.datasets.put(dsName, result.dataset); this.entries.put(dsName, entry); } } catch (Exception e) { LOGGER.log( Level.SEVERE, String.format("Dataset call returned %s", e.getMessage())); } } } catch (Exception e) { LOGGER.log( Level.SEVERE, String.format( "Error during webservice calls %s", e.getMessage(), e.getStackTrace())); return new ArrayList<Name>(); } executor.shutdown(); return new ArrayList<Name>(this.entries.keySet()); } ArcGISRestDataStore(
            String namespaceIn,
            String apiEndpoint,
            boolean opendataFlagIn,
            String user,
            String password); Catalog getCatalog(); Dataset getDataset(Name name); URL getNamespace(); @Override void dispose(); InputStream retrieveJSON(String methType, URL url, Map<String, Object> params); static String getWebServiceEndpoint(Dataset ds); static String InputStreamToString(InputStream istream); }
ArcGISRestDataStore extends ContentDataStore { @Override protected List<Name> createTypeNames() { if (this.entries.isEmpty() == false) { return new ArrayList<Name>(this.entries.keySet()); } final List<Dataset> datasetList = this.getCatalog().getDataset(); List<Name> typeNames = new ArrayList<Name>(); ExecutorService executor = Executors.newFixedThreadPool(REQUEST_THREADS); final class WsCallResult { public Dataset dataset; public Webservice webservice; public WsCallResult(Dataset ds, Webservice ws) { this.dataset = ds; this.webservice = ws; }; } final class WsCall implements Callable<WsCallResult> { public final Dataset dataset; public final String webserviceUrl; public WsCall(Dataset dsIn, String wsUrl) { this.dataset = dsIn; this.webserviceUrl = wsUrl; } public WsCallResult call() throws Exception { Webservice ws = null; String responseWSString = null; try { responseWSString = ArcGISRestDataStore.InputStreamToString( retrieveJSON( "GET", new URL(this.webserviceUrl), ArcGISRestDataStore.DEFAULT_PARAMS)); } catch (IOException e) { LOGGER.log( Level.SEVERE, String.format( "Error during retrieval of dataset '%s' %s", this.webserviceUrl, e.getMessage()), e); return null; } try { ws = (new Gson()).fromJson(responseWSString, Webservice.class); if (ws == null || ws.getCurrentVersion() == null) { throw (new JsonSyntaxException("Malformed JSON")); } } catch (JsonSyntaxException e) { Error_ errWS = (new Gson()).fromJson(responseWSString, Error_.class); LOGGER.log( Level.SEVERE, String.format( "Error during retrieval of dataset '%s' %s %s ", this.webserviceUrl, errWS.getCode(), errWS.getMessage()), e); return null; } if (ws.getCurrentVersion() < MINIMUM_API_VERSION || ws.getSupportedQueryFormats() .toString() .toLowerCase() .contains(FORMAT_JSON.toLowerCase()) == false) { LOGGER.log( Level.SEVERE, String.format( "Dataset %s does not support either the API version supported ,or the GeoJSON format", this.webserviceUrl)); return null; } return new WsCallResult(this.dataset, ws); } } Collection<WsCall> calls = new ArrayList<WsCall>(); datasetList .stream() .forEach( (ds) -> { String ws = ArcGISRestDataStore.getWebServiceEndpoint(ds); if (ws != null) { calls.add(new WsCall(ds, ws)); } }); try { List<Future<WsCallResult>> futures = executor.invokeAll( calls, (REQUEST_TIMEOUT * calls.size()) / REQUEST_THREADS, TimeUnit.SECONDS); for (Future<WsCallResult> future : futures) { try { WsCallResult result = future.get(); if (result != null && result.webservice.getType() != null && result.webservice .getType() .equalsIgnoreCase(DATASETTYPE_FEATURELAYER) && result.webservice .getSupportedQueryFormats() .toLowerCase() .contains(FORMAT_JSON.toLowerCase()) && result.webservice.getCurrentVersion() >= MINIMUM_API_VERSION && result.webservice.getName().length() > 0 && result.webservice .getCapabilities() .toLowerCase() .contains(CAPABILITIES_QUERY.toLowerCase())) { Name dsName = new NameImpl( namespace.toExternalForm(), result.webservice.getName()); ContentEntry entry = new ContentEntry(this, dsName); this.datasets.put(dsName, result.dataset); this.entries.put(dsName, entry); } } catch (Exception e) { LOGGER.log( Level.SEVERE, String.format("Dataset call returned %s", e.getMessage())); } } } catch (Exception e) { LOGGER.log( Level.SEVERE, String.format( "Error during webservice calls %s", e.getMessage(), e.getStackTrace())); return new ArrayList<Name>(); } executor.shutdown(); return new ArrayList<Name>(this.entries.keySet()); } ArcGISRestDataStore(
            String namespaceIn,
            String apiEndpoint,
            boolean opendataFlagIn,
            String user,
            String password); Catalog getCatalog(); Dataset getDataset(Name name); URL getNamespace(); @Override void dispose(); InputStream retrieveJSON(String methType, URL url, Map<String, Object> params); static String getWebServiceEndpoint(Dataset ds); static String InputStreamToString(InputStream istream); static final double MINIMUM_API_VERSION; static final String GEOMETRYTYPE_PARAM; static final String GEOMETRY_PARAM; static final String COUNT_PARAM; static final String FORMAT_PARAM; static final String GEOMETRYSRS_PARAM; static final String ATTRIBUTES_PARAM; static final String WITHGEOMETRY_PARAM; static final String DATASETTYPE_FEATURELAYER; static final String FORMAT_JSON; static final String FORMAT_GEOJSON; static final String FORMAT_ESRIREST; static final String CAPABILITIES_QUERY; static Map<String, Object> DEFAULT_PARAMS; static String FEATURESERVER_SERVICE; static final String GEOMETRY_ATTR; }