Java Code Examples for org.springframework.shell.support.util.OsUtils

The following examples show how to use org.springframework.shell.support.util.OsUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: geoserver-shell   Source File: OWSCommandsTest.java    License: MIT License 6 votes vote down vote up
@Test
public void listWcsSettings() throws Exception {
    String url = "/geoserver/rest/services/wcs/settings.xml";
    whenHttp(server).match(get(url)).then(stringContent(getResourceString("wcs.xml")), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    OWSCommands commands = new OWSCommands();
    commands.setGeoserver(geoserver);
    String actual = commands.wcsList(null);
    String expected = "WCS" + OsUtils.LINE_SEPARATOR +
            "   Enabled: true" + OsUtils.LINE_SEPARATOR +
            "   Cite Compliant: false" + OsUtils.LINE_SEPARATOR +
            "   Schema Base URL: http://schemas.opengis.net" + OsUtils.LINE_SEPARATOR +
            "   Verbose: false" + OsUtils.LINE_SEPARATOR +
            "   GML Prefixing: false" + OsUtils.LINE_SEPARATOR +
            "   LatLon: false" + OsUtils.LINE_SEPARATOR +
            "   Max Input Memory: -1" + OsUtils.LINE_SEPARATOR +
            "   Max Output Memory: -1" + OsUtils.LINE_SEPARATOR +
            "   Subsampling Enabled: false" + OsUtils.LINE_SEPARATOR +
            "   Versions:" + OsUtils.LINE_SEPARATOR +
            "      1.0.0" + OsUtils.LINE_SEPARATOR +
            "      1.1.1" + OsUtils.LINE_SEPARATOR +
            "      2.0.1" + OsUtils.LINE_SEPARATOR;
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.GET), uri(url));
}
 
Example 2
Source Project: Decision   Source File: StreamListRenderer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String render(List<StratioStream> streams) throws ShellException {
    StringBuilder queryTables = new StringBuilder();
    List<Map<String, Object>> data = new ArrayList<>();
    for (StratioStream stratioStream : streams) {
        Map<String, Object> row = new HashMap<>();
        row.put(STREAM_NAME, stratioStream.getStreamName());
        row.put(USER_DEFINED, stratioStream.getUserDefined());
        row.put(QUERIES, stratioStream.getQueries().size());
        row.put(ELEMENTS, stratioStream.getColumns().size());
        row.put(ACTIVE_ACTIONS, stratioStream.getActiveActions().toString());

        queryTables.append(renderQueriesTable(stratioStream.getQueries(), stratioStream.getStreamName()));

        data.add(row);
    }

    StringBuilder result = new StringBuilder();
    result.append(TableRenderer.renderMapDataAsTable(data, columns));
    result.append(OsUtils.LINE_SEPARATOR);
    result.append(queryTables);

    return result.toString();
}
 
Example 3
Source Project: geoserver-shell   Source File: AboutCommandsTest.java    License: MIT License 6 votes vote down vote up
@Test
public void manifestGet() throws Exception {
    whenHttp(server).match(get("/geoserver/rest/about/manifests.xml")).then(stringContent(getResourceString("manifests.xml")), status(HttpStatus.OK_200));

    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    AboutCommands commands = new AboutCommands();
    commands.setGeoserver(geoserver);
    String actual = commands.manifestGet("gt-xsd-ows-9.1");
    String expected = "gt-xsd-ows-9.1" + OsUtils.LINE_SEPARATOR +
            "   Manifest-Version: 1.0" + OsUtils.LINE_SEPARATOR +
            "   Archiver-Version: Plexus Archiver" + OsUtils.LINE_SEPARATOR +
            "   Built-By: jetty" + OsUtils.LINE_SEPARATOR +
            "   Build-Timestamp: 20-Apr-2013 11:03" + OsUtils.LINE_SEPARATOR +
            "   Git-Revision: f25b08094d1bf7e0949994f4971bc21fb117d37b" + OsUtils.LINE_SEPARATOR +
            "   Build-Jdk: 1.6.0_22" + OsUtils.LINE_SEPARATOR +
            "   Project-Version: 9.1" + OsUtils.LINE_SEPARATOR +
            "   Created-By: Apache Maven" + OsUtils.LINE_SEPARATOR;
    assertEquals(expected, actual);

    verifyHttp(server).once(method(Method.GET), uri("/geoserver/rest/about/manifests.xml"));
}
 
Example 4
Source Project: geoserver-shell   Source File: AboutCommands.java    License: MIT License 6 votes vote down vote up
@CliCommand(value = "version list", help = "Get versions.")
public String versionList() throws Exception {
    String TAB = "   ";
    String xml = HTTPUtils.get(geoserver.getUrl() + "/rest/about/versions.xml", geoserver.getUser(), geoserver.getPassword());
    StringBuilder builder = new StringBuilder();
    Element root = JDOMBuilder.buildElement(xml);

    List<Element> resources = root.getChildren("resource");
    for (Element resource : resources) {
        String name = resource.getAttributeValue("name");
        String buildTime = resource.getChildText("Build-Timestamp");
        String gitRevision = resource.getChildText("Git-Revision");
        String version = resource.getChildText("Version");
        builder.append(name).append(OsUtils.LINE_SEPARATOR);
        builder.append(TAB).append("Version: ").append(version).append(OsUtils.LINE_SEPARATOR);
        builder.append(TAB).append("Build Time: ").append(buildTime).append(OsUtils.LINE_SEPARATOR);
        builder.append(TAB).append("Git Revision: ").append(gitRevision).append(OsUtils.LINE_SEPARATOR);
        builder.append(OsUtils.LINE_SEPARATOR);
    }

    return builder.toString();
}
 
Example 5
Source Project: geoserver-shell   Source File: TemplateCommands.java    License: MIT License 6 votes vote down vote up
@CliCommand(value = "template list", help = "List templates.")
public String list(
        @CliOption(key = "workspace", mandatory = false, help = "The workspace") String workspace,
        @CliOption(key = "datastore", mandatory = false, help = "The datastore") String datastore,
        @CliOption(key = "featuretype", mandatory = false, help = "The featuretype") String featureType,
        @CliOption(key = "coveragestore", mandatory = false, help = "The coveragestore") String coverageStore,
        @CliOption(key = "coverage", mandatory = false, help = "The coverage") String coverage
) throws Exception {
    StringBuilder urlBuilder = buildUrl(geoserver.getUrl(), workspace, datastore, featureType, coverageStore, coverage);
    urlBuilder.append("/templates.xml");
    String xml = HTTPUtils.get(urlBuilder.toString(), geoserver.getUser(), geoserver.getPassword());
    Element rootElement = JDOMBuilder.buildElement(xml);
    List<Element> templateElements = rootElement.getChildren("template");
    List<String> names = new ArrayList<String>();
    Collections.sort(names);
    for (Element templateElement : templateElements) {
        names.add(templateElement.getChildText("name"));
    }
    StringBuilder builder = new StringBuilder();
    for (String name : names) {
        builder.append(name).append(OsUtils.LINE_SEPARATOR);
    }
    return builder.toString();
}
 
Example 6
Source Project: geoserver-shell   Source File: OWSCommandsTest.java    License: MIT License 6 votes vote down vote up
@Test
public void listWcsSettingsForWorkspace() throws Exception {
    String url = "/geoserver/rest/services/wcs/workspaces/topp/settings.xml";
    whenHttp(server).match(get(url)).then(stringContent(getResourceString("wcs.xml")), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    OWSCommands commands = new OWSCommands();
    commands.setGeoserver(geoserver);
    String actual = commands.wcsList("topp");
    String expected = "WCS" + OsUtils.LINE_SEPARATOR +
            "   Enabled: true" + OsUtils.LINE_SEPARATOR +
            "   Cite Compliant: false" + OsUtils.LINE_SEPARATOR +
            "   Schema Base URL: http://schemas.opengis.net" + OsUtils.LINE_SEPARATOR +
            "   Verbose: false" + OsUtils.LINE_SEPARATOR +
            "   GML Prefixing: false" + OsUtils.LINE_SEPARATOR +
            "   LatLon: false" + OsUtils.LINE_SEPARATOR +
            "   Max Input Memory: -1" + OsUtils.LINE_SEPARATOR +
            "   Max Output Memory: -1" + OsUtils.LINE_SEPARATOR +
            "   Subsampling Enabled: false" + OsUtils.LINE_SEPARATOR +
            "   Versions:" + OsUtils.LINE_SEPARATOR +
            "      1.0.0" + OsUtils.LINE_SEPARATOR +
            "      1.1.1" + OsUtils.LINE_SEPARATOR +
            "      2.0.1" + OsUtils.LINE_SEPARATOR;
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.GET), uri(url));
}
 
Example 7
Source Project: geoserver-shell   Source File: ScriptCommands.java    License: MIT License 6 votes vote down vote up
@CliCommand(value = "scripting session list", help = "List scripting sessions.")
public String listSession(
        @CliOption(key = "ext", mandatory = false, help = "The script extension") String ext
) throws Exception {
    String url = geoserver.getUrl() + "/rest/sessions";
    if (ext != null) {
        url += "/" + URLUtil.encode(ext);
    }
    String result = HTTPUtils.get(url, geoserver.getUser(), geoserver.getPassword());
    JSONObject rootJsonObject = new JSONObject(result);
    JSONArray jsonArray = rootJsonObject.getJSONArray("sessions");
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject jsonObject = jsonArray.getJSONObject(i);
        builder.append(jsonObject.getString("id")).append(" ")
                .append(jsonObject.get("engine"))
                .append(OsUtils.LINE_SEPARATOR);
    }
    return builder.toString();
}
 
Example 8
Source Project: geoserver-shell   Source File: CoverageStoreCommands.java    License: MIT License 6 votes vote down vote up
@CliCommand(value = "coverage store get", help = "Get a coverage store.")
public String get(
        @CliOption(key = "workspace", mandatory = true, help = "The workspace") String workspace,
        @CliOption(key = "coveragestore", mandatory = true, help = "The coveragestore") String coveragestore
) throws Exception {
    String url = geoserver.getUrl() + "/rest/workspaces/" + URLUtil.encode(workspace) + "/coveragestores/" + URLUtil.encode(coveragestore) + ".xml";
    String xml = HTTPUtils.get(url, geoserver.getUser(), geoserver.getPassword());
    Element coverageStoreElement = JDOMBuilder.buildElement(xml);
    String name = coverageStoreElement.getChildText("name");
    String type = coverageStoreElement.getChildText("type");
    String enabled = coverageStoreElement.getChildText("enabled");
    String covUrl = coverageStoreElement.getChildText("url");
    // @TODO RESTCoverageStore doesn't have access to type, enabled
    /*GeoServerRESTReader reader = new GeoServerRESTReader(geoserver.getUrl(), geoserver.getUser(), geoserver.getPassword());
    RESTCoverageStore store = reader.getCoverageStore(workspace, coveragestore);*/
    String TAB = "   ";
    StringBuilder builder = new StringBuilder();
    builder.append(name).append(OsUtils.LINE_SEPARATOR);
    builder.append(TAB).append("Type: ").append(type).append(OsUtils.LINE_SEPARATOR);
    builder.append(TAB).append("URL: ").append(covUrl).append(OsUtils.LINE_SEPARATOR);
    builder.append(TAB).append("Enabled: ").append(enabled).append(OsUtils.LINE_SEPARATOR);
    return builder.toString();
}
 
Example 9
Source Project: geoserver-shell   Source File: LayerCommands.java    License: MIT License 6 votes vote down vote up
@CliCommand(value = "layer style list", help = "List the Styles for a layer.")
public String listStyles(
        @CliOption(key = "name", mandatory = true, help = "The name") String name
) throws Exception {
    String url = geoserver.getUrl() + "/rest/layers/" + URLUtil.encode(name) + "/styles.xml";
    String xml = HTTPUtils.get(url, geoserver.getUser(), geoserver.getPassword());
    Element element = JDOMBuilder.buildElement(xml);
    List<Element> styleElements = element.getChildren("style");
    List<String> names = new ArrayList<String>();
    for (Element styleElement : styleElements) {
        names.add(styleElement.getChildText("name"));
    }
    Collections.sort(names);
    StringBuilder builder = new StringBuilder();
    for (String nm : names) {
        builder.append(nm).append(OsUtils.LINE_SEPARATOR);
    }
    return builder.toString();
}
 
Example 10
Source Project: geoserver-shell   Source File: LayerCommandsTest.java    License: MIT License 6 votes vote down vote up
@Test
public void getLayer() throws Exception {
    String url = "/geoserver/rest/layers/streams.xml";
    whenHttp(server).match(get(url)).then(stringContent(getResourceString("layer.xml")), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    LayerCommands commands = new LayerCommands();
    commands.setGeoserver(geoserver);
    String actual = commands.get("streams");
    String expected = "streams" + OsUtils.LINE_SEPARATOR +
            "   Title: null" + OsUtils.LINE_SEPARATOR +
            "   Type: VECTOR" + OsUtils.LINE_SEPARATOR +
            "   Abstract: null" + OsUtils.LINE_SEPARATOR +
            "   Default Style: simple_streams" + OsUtils.LINE_SEPARATOR +
            "   Namespace:    Type String: VECTOR" + OsUtils.LINE_SEPARATOR;
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.GET), uri(url));
}
 
Example 11
Source Project: geoserver-shell   Source File: DataStoreCommandsTest.java    License: MIT License 6 votes vote down vote up
@Test
public void getDataStore() throws Exception {
    String url = "/geoserver/rest/workspaces/topp/datastores/taz_shapes.xml";
    whenHttp(server).match(get(url)).then(stringContent(getResourceString("datastore.xml")), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    DataStoreCommands commands = new DataStoreCommands();
    commands.setGeoserver(geoserver);
    String actual = commands.get("topp", "taz_shapes");
    String expected = "taz_shapes" + OsUtils.LINE_SEPARATOR +
            "   Enabled? true" + OsUtils.LINE_SEPARATOR +
            "   Description: null" + OsUtils.LINE_SEPARATOR +
            "   Store Type: null" + OsUtils.LINE_SEPARATOR +
            "   Type: UNKNOWN" + OsUtils.LINE_SEPARATOR +
            "   Workspace: topp" + OsUtils.LINE_SEPARATOR +
            "   Connection Parameters:" + OsUtils.LINE_SEPARATOR +
            "      namespace: http://www.openplans.org/topp" + OsUtils.LINE_SEPARATOR +
            "      url: file:data/taz_shapes" + OsUtils.LINE_SEPARATOR;
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.GET), uri(url));
}
 
Example 12
Source Project: geoserver-shell   Source File: GeoWebCacheCommandsTest.java    License: MIT License 6 votes vote down vote up
@Test
public void getLayer() throws Exception {
    String url = "/geoserver/gwc/rest/layers/sf:roads.xml";
    whenHttp(server).match(get(url)).then(stringContent(getResourceString("gwc_layer.xml")), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    GeoWebCacheCommands commands = new GeoWebCacheCommands();
    commands.setGeoserver(geoserver);
    String actual = commands.getLayer("sf:roads");
    String expected = "sf:roads" + OsUtils.LINE_SEPARATOR +
            "   Enabled: true" + OsUtils.LINE_SEPARATOR +
            "   Gutter: 0" + OsUtils.LINE_SEPARATOR +
            "   Auto Cache Styles: true" + OsUtils.LINE_SEPARATOR +
            "   Mime Formats:" + OsUtils.LINE_SEPARATOR +
            "      image/png" + OsUtils.LINE_SEPARATOR +
            "      image/jpeg" + OsUtils.LINE_SEPARATOR +
            "   Grid Subsets:" + OsUtils.LINE_SEPARATOR +
            "      EPSG:900913" + OsUtils.LINE_SEPARATOR +
            "      EPSG:4326" + OsUtils.LINE_SEPARATOR +
            "   Meta Dimensions:" + OsUtils.LINE_SEPARATOR +
            "      Width: 4" + OsUtils.LINE_SEPARATOR +
            "      Height: 4" + OsUtils.LINE_SEPARATOR;
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.GET), uri(url));
}
 
Example 13
Source Project: geoserver-shell   Source File: WmsStoreCommandsTest.java    License: MIT License 6 votes vote down vote up
@Test
public void getStore() throws Exception {
    String url = "/geoserver/rest/workspaces/topp/wmsstores/massgis.xml";
    whenHttp(server).match(get(url)).then(stringContent(getResourceString("wmsStore.xml")), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    WmsStoreCommands commands = new WmsStoreCommands();
    commands.setGeoserver(geoserver);
    String actual = commands.getStore("topp", "massgis");
    String expected = "massgis" + OsUtils.LINE_SEPARATOR +
            "   Type: WMS" + OsUtils.LINE_SEPARATOR +
            "   Enabled: true" + OsUtils.LINE_SEPARATOR +
            "   Workspace: topp" + OsUtils.LINE_SEPARATOR +
            "   Capabilities URL: " + OsUtils.LINE_SEPARATOR +
            "		http://giswebservices.massgis.state.ma.us/geoserver/wms?request=GetCapabilities&version=1.1.0&service=wms" + OsUtils.LINE_SEPARATOR +
            "	" + OsUtils.LINE_SEPARATOR +
            "   Max Connections: 6" + OsUtils.LINE_SEPARATOR +
            "   Read Timeout: 60" + OsUtils.LINE_SEPARATOR +
            "   Connect Timeout: 30" + OsUtils.LINE_SEPARATOR +
            "   Metadata: " + OsUtils.LINE_SEPARATOR +
            "      useConnectionPooling: true" + OsUtils.LINE_SEPARATOR;
    assertStringsEquals(expected, actual, true);
    verifyHttp(server).once(method(Method.GET), uri(url));
}
 
Example 14
Source Project: geoserver-shell   Source File: SettingsCommandsTest.java    License: MIT License 6 votes vote down vote up
@Test
public void listContactSettings() throws Exception {
    String url = "/geoserver/rest/settings/contact.xml";
    whenHttp(server).match(get(url)).then(stringContent(getResourceString("contactSettings.xml")), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    SettingsCommands commands = new SettingsCommands();
    commands.setGeoserver(geoserver);
    String actual = commands.listContact();
    String expected = "City: Somewhere" + OsUtils.LINE_SEPARATOR +
            "Country: USA" + OsUtils.LINE_SEPARATOR +
            "Type: Home" + OsUtils.LINE_SEPARATOR +
            "Email: [email protected]" + OsUtils.LINE_SEPARATOR +
            "Organization: Geoserver" + OsUtils.LINE_SEPARATOR +
            "Name: John Doe" + OsUtils.LINE_SEPARATOR +
            "Position: Map Maker" + OsUtils.LINE_SEPARATOR;
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.GET), uri(url));
}
 
Example 15
Source Project: geoserver-shell   Source File: SettingsCommandsTest.java    License: MIT License 6 votes vote down vote up
@Test
public void listLocalSettings() throws Exception {
    String url = "/geoserver/rest/workspaces/topp/settings.xml";
    whenHttp(server).match(get(url)).then(stringContent(getResourceString("localSettings.xml")), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    SettingsCommands commands = new SettingsCommands();
    commands.setGeoserver(geoserver);
    String actual = commands.listLocal("topp");
    String expected = "Settings" + OsUtils.LINE_SEPARATOR +
            "   Charset: UTF-8" + OsUtils.LINE_SEPARATOR +
            "   Number of Decimals: 4" + OsUtils.LINE_SEPARATOR +
            "   Online Resource: null" + OsUtils.LINE_SEPARATOR +
            "   Verbose: false" + OsUtils.LINE_SEPARATOR +
            "   Verbose Exceptions: false" + OsUtils.LINE_SEPARATOR +
            "" + OsUtils.LINE_SEPARATOR +
            "Contact" + OsUtils.LINE_SEPARATOR +
            "   City: null" + OsUtils.LINE_SEPARATOR +
            "   Country: null" + OsUtils.LINE_SEPARATOR +
            "   Type: work" + OsUtils.LINE_SEPARATOR +
            "   Email: null" + OsUtils.LINE_SEPARATOR +
            "   Organization: Work" + OsUtils.LINE_SEPARATOR +
            "   Name: John Doe" + OsUtils.LINE_SEPARATOR +
            "   Position: null" + OsUtils.LINE_SEPARATOR;
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.GET), uri(url));
}
 
Example 16
Source Project: spring-cloud-dashboard   Source File: HttpCommands.java    License: Apache License 2.0 5 votes vote down vote up
private void outputRequest(String method, URI requestUri, MediaType mediaType, String requestData,
		StringBuilder buffer) {
	buffer.append("> ").append(method).append(' ');
	if (mediaType != null) {
		buffer.append("(").append(mediaType.toString()).append(") ");
	}
	buffer.append(requestUri.toString()).append(" ").append(requestData).append(OsUtils.LINE_SEPARATOR);
}
 
Example 17
Source Project: spring-cloud-dashboard   Source File: HttpCommands.java    License: Apache License 2.0 5 votes vote down vote up
private void outputResponse(ResponseEntity<String> response, StringBuilder buffer) {
	buffer.append("> ").append(response.getStatusCode().value()).append(" ").append(response.getStatusCode().name()).append(
			OsUtils.LINE_SEPARATOR);
	String maybeJson = response.getBody();
	if (maybeJson != null) {
		buffer.append(prettyPrintIfJson(maybeJson));
	}
}
 
Example 18
Source Project: pdf-smart-crop   Source File: SmartCropBannerProvider.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("StringBufferReplaceableByString")
@Override
public String getBanner() {
    StringBuilder buf = new StringBuilder();
    buf.append(" _____                      _     _____                 ").append(OsUtils.LINE_SEPARATOR);
    buf.append("/  ___|                    | |   /  __ \\                ").append(OsUtils.LINE_SEPARATOR);
    buf.append("\\ `--. _ __ ___   __ _ _ __| |_  | /  \\/_ __ ___  _ __  ").append(OsUtils.LINE_SEPARATOR);
    buf.append(" `--. \\ '_ ` _ \\ / _` | '__| __| | |   | '__/ _ \\| '_ \\ ").append(OsUtils.LINE_SEPARATOR);
    buf.append("/\\__/ / | | | | | (_| | |  | |_  | \\__/\\ | | (_) | |_) |").append(OsUtils.LINE_SEPARATOR);
    buf.append("\\____/|_| |_| |_|\\__,_|_|   \\__|  \\____/_|  \\___/| .__/ ").append(OsUtils.LINE_SEPARATOR);
    buf.append("                                                 | |    ").append(OsUtils.LINE_SEPARATOR);
    buf.append("                                                 |_|    ").append(OsUtils.LINE_SEPARATOR);
    buf.append("Version: ").append(this.getVersion());
    return buf.toString();
}
 
Example 19
Source Project: spring-cloud-dataflow   Source File: HttpCommands.java    License: Apache License 2.0 5 votes vote down vote up
private void outputRequest(String method, URI requestUri, MediaType mediaType, String requestData,
		StringBuilder buffer) {
	buffer.append("> ").append(method).append(' ');
	if (mediaType != null) {
		buffer.append("(").append(mediaType.toString()).append(") ");
	}
	buffer.append(requestUri.toString()).append(" ").append(requestData).append(OsUtils.LINE_SEPARATOR);
}
 
Example 20
Source Project: spring-cloud-dataflow   Source File: HttpCommands.java    License: Apache License 2.0 5 votes vote down vote up
private void outputResponse(ResponseEntity<String> response, StringBuilder buffer) {
	buffer.append("> ").append(response.getStatusCode().value()).append(" ").append(response.getStatusCode().name())
			.append(OsUtils.LINE_SEPARATOR);
	String maybeJson = response.getBody();
	if (maybeJson != null) {
		buffer.append(ShellUtils.prettyPrintIfJson(maybeJson));
	}
}
 
Example 21
Source Project: geoserver-shell   Source File: StyleCommandsTest.java    License: MIT License 5 votes vote down vote up
@Test
public void getStyle() throws Exception {
    String url = "/geoserver/rest/styles/polygon.xml";
    whenHttp(server).match(get(url)).then(stringContent(getResourceString("style.xml")), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    StyleCommands commands = new StyleCommands();
    commands.setGeoserver(geoserver);
    String actual = commands.getStyle("polygon", null);
    String expected = "polygon" + OsUtils.LINE_SEPARATOR +
            "   SLD Version: 1.0.0" + OsUtils.LINE_SEPARATOR +
            "   File Name: default_polygon.sld" + OsUtils.LINE_SEPARATOR;
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.GET), uri(url));
}
 
Example 22
Source Project: Decision   Source File: StratioStreamingBannerProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String getBanner() {
    StringBuilder sb = new StringBuilder();
    sb.append(FileUtils.readBanner(Main.class, "/banner.txt"));
    sb.append(OsUtils.LINE_SEPARATOR);
    sb.append("Connection urls: " + OsUtils.LINE_SEPARATOR);
    sb.append("    - Kafka: " + kafkaBrokers);
    sb.append("    - Zookeeper: " + zkQuorum);
    sb.append(OsUtils.LINE_SEPARATOR);
    return sb.toString();
}
 
Example 23
Source Project: tutorials   Source File: SimpleBannerProvider.java    License: MIT License 5 votes vote down vote up
public String getBanner() {
    StringBuffer buf = new StringBuffer();
    buf.append("=======================================").append(OsUtils.LINE_SEPARATOR);
    buf.append("*          Baeldung Shell             *").append(OsUtils.LINE_SEPARATOR);
    buf.append("=======================================").append(OsUtils.LINE_SEPARATOR);
    buf.append("Version:").append(this.getVersion());
    return buf.toString();
}
 
Example 24
Source Project: geoserver-shell   Source File: WmsStoreCommands.java    License: MIT License 5 votes vote down vote up
@CliCommand(value = "wmsstore get", help = "Get a WMS Stores.")
public String getStore(
        @CliOption(key = "workspace", mandatory = true, help = "The workspace") String workspace,
        @CliOption(key = "store", mandatory = true, help = "The WMSStore") String store
) throws Exception {
    String url = geoserver.getUrl() + "/rest/workspaces/" + URLUtil.encode(workspace) + "/wmsstores/" + URLUtil.encode(store) + ".xml";
    String xml = HTTPUtils.get(url, geoserver.getUser(), geoserver.getPassword());
    StringBuilder builder = new StringBuilder();
    String TAB = "   ";
    Element element = JDOMBuilder.buildElement(xml);
    builder.append(element.getChildText("name")).append(OsUtils.LINE_SEPARATOR);
    builder.append(TAB).append("Type: ").append(element.getChildText("type")).append(OsUtils.LINE_SEPARATOR);
    builder.append(TAB).append("Enabled: ").append(element.getChildText("enabled")).append(OsUtils.LINE_SEPARATOR);
    Element wsElement = element.getChild("workspace");
    if (wsElement != null) {
        builder.append(TAB).append("Workspace: ").append(wsElement.getChildText("name")).append(OsUtils.LINE_SEPARATOR);
    }
    builder.append(TAB).append("Capabilities URL: ").append(element.getChildText("capabilitiesURL")).append(OsUtils.LINE_SEPARATOR);
    builder.append(TAB).append("Max Connections: ").append(element.getChildText("maxConnections")).append(OsUtils.LINE_SEPARATOR);
    builder.append(TAB).append("Read Timeout: ").append(element.getChildText("readTimeout")).append(OsUtils.LINE_SEPARATOR);
    builder.append(TAB).append("Connect Timeout: ").append(element.getChildText("connectTimeout")).append(OsUtils.LINE_SEPARATOR);
    Element metadataElement = element.getChild("metadata");
    if (metadataElement != null) {
        List<Element> entryElements = metadataElement.getChildren("entry");
        if (entryElements.size() > 0) {
            builder.append(TAB).append("Metadata: ").append(OsUtils.LINE_SEPARATOR);
            for (Element entryElement : entryElements) {
                builder.append(TAB).append(TAB).append(entryElement.getAttributeValue("key")).append(": ").append(entryElement.getTextTrim()).append(OsUtils.LINE_SEPARATOR);
            }
        }
    }
    return builder.toString();
}
 
Example 25
Source Project: geoserver-shell   Source File: SettingsCommands.java    License: MIT License 5 votes vote down vote up
@CliCommand(value = "settings contact list", help = "List contact settings.")
public String listContact() throws Exception {
    String TAB = "   ";
    String xml = HTTPUtils.get(geoserver.getUrl() + "/rest/settings/contact.xml", geoserver.getUser(), geoserver.getPassword());
    StringBuilder builder = new StringBuilder();
    Element element = JDOMBuilder.buildElement(xml);
    builder.append("City: ").append(element.getChildText("addressCity")).append(OsUtils.LINE_SEPARATOR);
    builder.append("Country: ").append(element.getChildText("addressCountry")).append(OsUtils.LINE_SEPARATOR);
    builder.append("Type: ").append(element.getChildText("addressType")).append(OsUtils.LINE_SEPARATOR);
    builder.append("Email: ").append(element.getChildText("contactEmail")).append(OsUtils.LINE_SEPARATOR);
    builder.append("Organization: ").append(element.getChildText("contactOrganization")).append(OsUtils.LINE_SEPARATOR);
    builder.append("Name: ").append(element.getChildText("contactPerson")).append(OsUtils.LINE_SEPARATOR);
    builder.append("Position: ").append(element.getChildText("contactPosition")).append(OsUtils.LINE_SEPARATOR);
    return builder.toString();
}
 
Example 26
Source Project: geoserver-shell   Source File: SettingsCommands.java    License: MIT License 5 votes vote down vote up
@CliCommand(value = "settings local list", help = "List settings.")
public String listLocal(
        @CliOption(key = "workspace", mandatory = true, help = "The workspace") String workspace
) throws Exception {
    String url = geoserver.getUrl() + "/rest/workspaces/" + URLUtil.encode(workspace) + "/settings.xml";
    String TAB = "   ";
    String xml = HTTPUtils.get(url, geoserver.getUser(), geoserver.getPassword());
    StringBuilder builder = new StringBuilder();
    Element settings = JDOMBuilder.buildElement(xml);
    if (settings.getChild("workspace") != null) {
        // Settings
        builder.append("Settings").append(OsUtils.LINE_SEPARATOR);
        builder.append(TAB).append("Charset: ").append(settings.getChildText("charset")).append(OsUtils.LINE_SEPARATOR);
        builder.append(TAB).append("Number of Decimals: ").append(settings.getChildText("numDecimals")).append(OsUtils.LINE_SEPARATOR);
        builder.append(TAB).append("Online Resource: ").append(settings.getChildText("onlineResource")).append(OsUtils.LINE_SEPARATOR);
        builder.append(TAB).append("Verbose: ").append(settings.getChildText("verbose")).append(OsUtils.LINE_SEPARATOR);
        builder.append(TAB).append("Verbose Exceptions: ").append(settings.getChildText("verboseExceptions")).append(OsUtils.LINE_SEPARATOR);
        // Contact
        Element contact = settings.getChild("contact");
        if (contact != null) {
            builder.append(OsUtils.LINE_SEPARATOR);
            builder.append("Contact").append(OsUtils.LINE_SEPARATOR);
            builder.append(TAB).append("City: ").append(contact.getChildText("addressCity")).append(OsUtils.LINE_SEPARATOR);
            builder.append(TAB).append("Country: ").append(contact.getChildText("addressCountry")).append(OsUtils.LINE_SEPARATOR);
            builder.append(TAB).append("Type: ").append(contact.getChildText("addressType")).append(OsUtils.LINE_SEPARATOR);
            builder.append(TAB).append("Email: ").append(contact.getChildText("contactEmail")).append(OsUtils.LINE_SEPARATOR);
            builder.append(TAB).append("Organization: ").append(contact.getChildText("contactOrganization")).append(OsUtils.LINE_SEPARATOR);
            builder.append(TAB).append("Name: ").append(contact.getChildText("contactPerson")).append(OsUtils.LINE_SEPARATOR);
            builder.append(TAB).append("Position: ").append(contact.getChildText("contactPosition")).append(OsUtils.LINE_SEPARATOR);
        }
    }
    return builder.toString();
}
 
Example 27
Source Project: geoserver-shell   Source File: DataStoreCommands.java    License: MIT License 5 votes vote down vote up
@CliCommand(value = "datastore get", help = "Get a data store.")
public String get(
        @CliOption(key = "workspace", mandatory = true, help = "The workspace") String workspace,
        @CliOption(key = "name", mandatory = true, help = "The name") String name
) throws Exception {
    GeoServerRESTReader reader = new GeoServerRESTReader(geoserver.getUrl(), geoserver.getUser(), geoserver.getPassword());
    RESTDataStore dataStore = reader.getDatastore(workspace, name);
    final String TAB = "   ";
    StringBuilder builder = new StringBuilder();
    builder.append(dataStore.getName()).append(OsUtils.LINE_SEPARATOR);
    builder.append(TAB).append("Enabled? ").append(dataStore.isEnabled()).append(OsUtils.LINE_SEPARATOR);
    builder.append(TAB).append("Description: ").append(dataStore.getDescription()).append(OsUtils.LINE_SEPARATOR);
    builder.append(TAB).append("Store Type: ").append(dataStore.getStoreType()).append(OsUtils.LINE_SEPARATOR);
    builder.append(TAB).append("Type: ").append(dataStore.getType()).append(OsUtils.LINE_SEPARATOR);
    builder.append(TAB).append("Workspace: ").append(dataStore.getWorkspaceName()).append(OsUtils.LINE_SEPARATOR);
    builder.append(TAB).append("Connection Parameters:").append(OsUtils.LINE_SEPARATOR);
    Map<String, String> params = dataStore.getConnectionParameters();
    List<Map.Entry<String, String>> connectionParamList = new LinkedList<Map.Entry<String, String>>(params.entrySet());
    Collections.sort(connectionParamList, new Comparator<Map.Entry<String,String>>() {
        @Override
        public int compare( Map.Entry<String,String> o1, Map.Entry<String,String> o2 )
        {
            return (o1.getKey()).compareTo( o2.getKey());
        }
    });
    for (Map.Entry<String, String> param : connectionParamList) {
        builder.append(TAB).append(TAB).append(param.getKey()).append(": ").append(param.getValue()).append(OsUtils.LINE_SEPARATOR);
    }
    return builder.toString();
}
 
Example 28
Source Project: geoserver-shell   Source File: StyleCommands.java    License: MIT License 5 votes vote down vote up
@CliCommand(value = "style list", help = "List style.")
public String list(
        @CliOption(key = "workspace", mandatory = false, help = "The workspace") String workspace
) throws Exception {
    GeoServerRESTReader reader = new GeoServerRESTReader(geoserver.getUrl(), geoserver.getUser(), geoserver.getPassword());
    RESTStyleList styleList = workspace != null ? this.getStyles(workspace) : reader.getStyles();
    List<String> names = styleList.getNames();
    Collections.sort(names);
    StringBuilder builder = new StringBuilder();
    for (String name : names) {
        builder.append(name + OsUtils.LINE_SEPARATOR);
    }
    return builder.toString();
}
 
Example 29
Source Project: geoserver-shell   Source File: OWSCommands.java    License: MIT License 5 votes vote down vote up
@CliCommand(value = "ows wcs list", help = "List Global or Local OWS WCS Settings.")
public String wcsList(
        @CliOption(key = "workspace", mandatory = false, help = "The workspace") String workspace
) throws Exception {
    // @TODO http://docs.geoserver.org/stable/en/user/rest/api/services.html is incorrect, it is missing /workspaces/<ws>
    String url = geoserver.getUrl() + "/rest/services/wcs/" + (workspace != null ? "workspaces/" + workspace + "/" : "") + "settings.xml";
    String xml = HTTPUtils.get(url, geoserver.getUser(), geoserver.getPassword());
    StringBuilder builder = new StringBuilder();
    if (xml != null) {
        Element element = JDOMBuilder.buildElement(xml);
        String TAB = "   ";
        builder.append(element.getChildText("name")).append(OsUtils.LINE_SEPARATOR);
        builder.append(TAB).append("Enabled: ").append(element.getChildText("enabled")).append(OsUtils.LINE_SEPARATOR);
        builder.append(TAB).append("Cite Compliant: ").append(element.getChildText("citeCompliant")).append(OsUtils.LINE_SEPARATOR);
        builder.append(TAB).append("Schema Base URL: ").append(element.getChildText("schemaBaseURL")).append(OsUtils.LINE_SEPARATOR);
        builder.append(TAB).append("Verbose: ").append(element.getChildText("verbose")).append(OsUtils.LINE_SEPARATOR);
        builder.append(TAB).append("GML Prefixing: ").append(element.getChildText("gmlPrefixing")).append(OsUtils.LINE_SEPARATOR);
        builder.append(TAB).append("LatLon: ").append(element.getChildText("latLon")).append(OsUtils.LINE_SEPARATOR);
        builder.append(TAB).append("Max Input Memory: ").append(element.getChildText("maxInputMemory")).append(OsUtils.LINE_SEPARATOR);
        builder.append(TAB).append("Max Output Memory: ").append(element.getChildText("maxOutputMemory")).append(OsUtils.LINE_SEPARATOR);
        builder.append(TAB).append("Subsampling Enabled: ").append(element.getChildText("subsamplingEnabled")).append(OsUtils.LINE_SEPARATOR);
        Element vElement = element.getChild("versions");
        if (vElement != null) {
            List<Element> versionElements = vElement.getChildren("org.geotools.util.Version");
            builder.append(TAB).append("Versions:").append(OsUtils.LINE_SEPARATOR);
            for (Element versionElement : versionElements) {
                builder.append(TAB).append(TAB).append(versionElement.getChildText("version")).append(OsUtils.LINE_SEPARATOR);
            }
        }
    }
    return builder.toString();
}
 
Example 30
Source Project: geoserver-shell   Source File: AboutCommandsTest.java    License: MIT License 5 votes vote down vote up
@Test
public void manifestList() throws Exception {
    whenHttp(server).match(get("/geoserver/rest/about/manifests.xml")).then(stringContent(getResourceString("manifests.xml")), status(HttpStatus.OK_200));

    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    AboutCommands commands = new AboutCommands();
    commands.setGeoserver(geoserver);
    String actual = commands.manifestList();
    String expected = "gt-xsd-gml3-9.1" + OsUtils.LINE_SEPARATOR + "gt-xsd-ows-9.1" + OsUtils.LINE_SEPARATOR + "gt-xsd-sld-9.1" + OsUtils.LINE_SEPARATOR;
    assertEquals(expected, actual);

    verifyHttp(server).once(method(Method.GET), uri("/geoserver/rest/about/manifests.xml"));
}