Permalink
Browse files

Updated CORS config, Added _wrml api metadata response to WrmlServlet

  • Loading branch information...
1 parent 4836ea7 commit 8fa65767c04241030e519c11f3d57e7834b2802e @markmasse markmasse committed Sep 15, 2015
View
@@ -147,51 +147,77 @@ The **werminal** command runs Werminal with the following command:
java -DwrmlConfiguration=../config/filesystem-wrml.json -classpath "target/wrml-cli.jar" org.wrml.werminal.Werminal -unix
+Werminal starts by dispaying the splash screen (shown below). From here you may press any key to start interacting with WRML.
+
<p align="center">
<img src="doc/README/Werminal-001.png" width="90%"/>
</p>
For more information about running Werminal, see <a href="./cli/README.md">the Werminal /cli project README.</a>
-For those having problems starting WRML, please confirm that the WRML configuration file is using the correct "slash" leaning direction for the folder/directory paths match the conventions of your OS. In WRML config files, the "/" forward slash should work cross-platform.
+If you have problems starting Werminal, please confirm that the WRML configuration file is using the correct "slash" leaning direction for the folder/directory paths match the conventions of your OS. In WRML config files, the "/" forward slash should work cross-platform.
##A Quick Tour of Werminal##
This section will walk through a simple example of using Werminal to demonstrate WRML's modeling features. Specifically, in this tour we will:
1. Design a new schema
- * Create a new schema, named **Test**
+ * Create a new schema, named **Demo**
* Save our new schema to disk, using the "File" service
* Load our new schema as a java class
2. Create model instances of new schema type
- * Create a new instance of **Test**
+ * Create a new instance of **Demo**
* Save the model instance to disk
* Exit Werminal, then re-launch and re-open the saved demo instance
For more about the Werminal app, please consult the "[Werminal Masters Handbook](https://github.com/wrml/wrml/blob/master/doc/WRML_WerminalMastersHandbook.pdf)"
###Designing a new Schema###
+As you might expect, a WRML schema is a structured data type. For the first part of the Werminal tour, you will create a new schema named **Demo**.
+
+Following the splash screen (after pressing any key), Werminal displays its main menu (shown below).
+
<p align="center">
<img src="doc/README/Werminal-002.png" width="90%"/>
</p>
+The **New** button has input focus (indicated by bold red text) so you can press the enter key to activate it.
+
+The **New Model** dialog will prompt you to enter the URI that identifies the schema of the model that you wish to create. To create a new schema, the URI is [http://schema.api.wrml.org/org/wrml/model/schema/Schema](http://schema.api.wrml.org/org/wrml/model/schema/Schema).
+
+By default, this URI is already entered so you can simply press the tab key until the **OK** button has input focus and then press the enter key to activate it.
+
<p align="center">
<img src="doc/README/Werminal-003.png" width="90%"/>
</p>
+Now you should see Werminal's model editor window with the title **"Werminal - Model - Schema"**, which indicates that you are editing a model of type schema.
+
+The top portion of the model editor window displays a toolbar, which we will make use of in a moment. For now, we will start by editing a few of the **slots** of our new schema model. A WRML model slot is analagous to a property, field, or column in other modeling systems.
+
<p align="center">
<img src="doc/README/Werminal-004.png" width="90%"/>
</p>
+The first slot to edit is named **uri**. Press the tab key until you see the uri slot's value gain input focus, which is indicated by red highlight and cursor location.
+
+With the uri slot focused, edit the value to **http://schema.api.wrml.org/Demo**.
+
<p align="center">
<img src="doc/README/Werminal-005.png" width="90%"/>
</p>
+Next, press the tab key (or down arrow key) to give focus to the **baseSchemaURis** slot. This slot allows schema models to declare that they extend other schemas. The value in this slot is a list of URIs that identify the *base* schemas for this schema.
+
+With the **baseSchemaURis** slot focused, press the enter key to open the list editor window.
+
<p align="center">
<img src="doc/README/Werminal-006.png" width="90%"/>
</p>
+
+
<p align="center">
<img src="doc/README/Werminal-007.png" width="90%"/>
</p>
@@ -77,16 +77,8 @@
* </p>
* <p/>
* <p>
- * WRML, like other model-driven architectures before it, says that data structures are "{@link Model}s", which don't
- * need be "coded". To promote reuse, abstraction, and separation of concerns; WRML says that data structures are
- * *modeled* and algorithms are *coded* (in {@link Service}s).
+ * In WRML data structures are *modeled* and algorithms are *coded* (in {@link Service}s).
* </p>
- * <p/>
- * <p>
- * WRML suggests that there are two unique disciplines within computer science *modelers* and *coders*. WRML modelers
- * can use intuitive design tools. WRML coders can implement services any way they want (Java not required).
- * </p>
- * <p/>
* <p>
* A {@link Model} is the base concept for all WRML "data structures". {@link Model} is the base interface of all Web
* resource {@link Schema} {@link Proxy} instances. In addition to the {@link Map}-like (or JSON-like) get/set slot
View
@@ -17,7 +17,7 @@
<dependencies>
<!-- Root POM should have no dependencies. See <dependencyManagement> instead. -->
</dependencies>
-
+
<build>
<plugins>
<plugin>
@@ -84,6 +84,12 @@
public static final String WRML_CONFIGURATION_RESOURCE_PATH_INIT_PARAM_NAME = "wrml-config-resource-path";
+ public static final String WRML_METADATA_ROOT_PATH = "/_wrml";
+
+ public static final String WRML_METADATA_API_PATH = WRML_METADATA_ROOT_PATH + "/api";
+
+
+
private static final Logger LOGGER = LoggerFactory.getLogger(WrmlServlet.class);
private static final long serialVersionUID = 1L;
@@ -214,6 +220,32 @@ protected void service(final HttpServletRequest request, final HttpServletRespon
LOGGER.debug("Request is associated with REST API: {}.", api.getTitle());
+ final String path = requestUri.getPath();
+ LOGGER.debug("PATH: {}", path);
+ if (WRML_METADATA_API_PATH.equals(path)) {
+ acceptableMediaTypes.clear();
+
+ final URI defaultFormatUri = context.getFormatLoader().getDefaultFormatUri();
+ final Map<String, String> mediaTypeParameters = new LinkedHashMap<>(6);
+
+ mediaTypeParameters.put(SystemMediaType.PARAMETER_NAME_SCHEMA, api.getSchemaUri().toString());
+ mediaTypeParameters.put(SystemMediaType.PARAMETER_NAME_FORMAT, defaultFormatUri.toString());
+
+ final MediaType mediaType = new MediaType(SystemMediaType.TYPE_APPLICATION, SystemMediaType.SUBTYPE_WRML,
+ mediaTypeParameters);
+
+ acceptableMediaTypes.add(mediaType);
+
+ try {
+ writeModelAsResponseEntity(response, api, acceptableMediaTypes, method);
+ }
+ catch (final ModelWriterException | MediaTypeException e) {
+ throw new ServletException("Failed to write model to HTTP response output stream (URI = " + requestUri + ", Model = [" + api + "]).", e);
+ }
+
+ return;
+ }
+
final Resource endpointResource = apiNavigator.getResource(requestUri);
if (endpointResource == null) {
final ResourceNotFoundErrorReport notFoundErrorReport = createNotFoundErrorReport(ResourceNotFoundErrorReport.class, requestUri, api);
@@ -691,7 +723,7 @@ void writeModelAsResponseEntity(final HttpServletResponse response, final Model
}
else {
final Context context = getContext();
- // TODO This isn't great
+
final ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
// Set the format for output
@@ -706,7 +738,6 @@ void writeModelAsResponseEntity(final HttpServletResponse response, final Model
formatUri = getLoadedFormatUri(responseEntityMediaType);
}
- // TODO Unfunkify this
context.writeModel(byteOut, responseModel, formatUri);
final byte[] modelBytes = byteOut.toByteArray();
@@ -2,6 +2,13 @@
<img src="http://www.wrml.org/images/site-logo-2.png"/>
</p>
+
+Getting Started
+================================
+
+After building the WRML project, by running "mvn clean install" at the project root level, you can run the server using the start-wrml-server.sh script. To test the server locally, run the client-request-examples.sh script and see basic WRML client-server interaction.
+
+
Server-WAR
================================
@@ -0,0 +1,149 @@
+#!/bin/bash
+
+##########################################################################################
+# #
+# WRML - Web Resource Modeling Language #
+# __ __ ______ __ __ __ #
+# /\ \ _ \ \ /\ == \ /\ "-./ \ /\ \ #
+# \ \ \/ ".\ \\ \ __< \ \ \-./\ \\ \ \____ #
+# \ \__/".~\_\\ \_\ \_\\ \_\ \ \_\\ \_____\ #
+# \/_/ \/_/ \/_/ /_/ \/_/ \/_/ \/_____/ #
+# #
+# http://www.wrml.org #
+# #
+# Copyright 2015 Mark Masse (OSS project WRML.org) #
+# #
+# Licensed under the Apache License, Version 2.0 (the "License"); #
+# you may not use this file except in compliance with the License. #
+# You may obtain a copy of the License at #
+# #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+# #
+# Unless required by applicable law or agreed to in writing, software #
+# distributed under the License is distributed on an "AS IS" BASIS, #
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
+# See the License for the specific language governing permissions and #
+# limitations under the License. #
+# #
+##########################################################################################
+
+##########################################################################################
+# Tests WRML client-server interaction on localhost. #
+##########################################################################################
+
+echo " "
+echo " "
+echo "#"
+echo "#"
+echo "# Requesting http://schema.api.wrml.org/org/wrml/model/schema/Schema"
+echo "#"
+echo "# The Schema model is interesting because it is a Model which defines the structure"
+echo "# of all models. You will notice that it has the standard model slots and it also "
+echo "# schematically defines these same slots for all models."
+echo "#"
+echo " "
+curl -H "WRML-Host:schema.api.wrml.org" -H "WRML-Port:80" http://localhost:8080/org/wrml/model/schema/Schema
+
+echo " "
+echo " "
+echo "#"
+echo "#"
+echo "# Requesting http://schema.api.wrml.org/org/wrml/model/Model"
+echo "#"
+echo "#"
+echo " "
+curl -H "WRML-Host:schema.api.wrml.org" -H "WRML-Port:80" http://localhost:8080/org/wrml/model/Model
+
+echo " "
+echo " "
+echo "#"
+echo "#"
+echo "# Requesting http://schema.api.wrml.org/_wrml/api"
+echo "#"
+echo "#"
+echo " "
+curl -H "WRML-Host:schema.api.wrml.org" -H "WRML-Port:80" http://localhost:8080/_wrml/api
+
+echo " "
+echo " "
+echo "#"
+echo "#"
+echo "# Requesting http://schema.api.wrml.org/org/wrml/model/format/Format"
+echo "#"
+echo "#"
+echo " "
+curl -H "WRML-Host:schema.api.wrml.org" -H "WRML-Port:80" http://localhost:8080/org/wrml/model/format/Format
+
+echo " "
+echo " "
+echo "#"
+echo "#"
+echo "# Requesting http://format.api.wrml.org/application/json"
+echo "#"
+echo "#"
+echo " "
+curl -H "WRML-Host:format.api.wrml.org" -H "WRML-Port:80" http://localhost:8080/application/json
+
+echo " "
+echo " "
+echo "#"
+echo "#"
+echo "# Requesting http://schema.api.wrml.org/org/wrml/model/rest/LinkRelation"
+echo "#"
+echo "#"
+echo " "
+curl -H "WRML-Host:schema.api.wrml.org" -H "WRML-Port:80" http://localhost:8080/org/wrml/model/rest/LinkRelation
+
+echo " "
+echo " "
+echo "#"
+echo "#"
+echo "# Requesting http://relation.api.wrml.org/org/wrml/relation/self"
+echo "#"
+echo "#"
+echo " "
+curl -H "WRML-Host:relation.api.wrml.org" -H "WRML-Port:80" http://localhost:8080/org/wrml/relation/self
+
+
+
+echo " "
+echo " "
+echo "#"
+echo "#"
+echo "# Requesting http://schema.api.wrml.org/org/wrml/model/schema/Syntax"
+echo "#"
+echo "#"
+echo " "
+curl -H "WRML-Host:schema.api.wrml.org" -H "WRML-Port:80" http://localhost:8080/org/wrml/model/schema/Syntax
+
+echo " "
+echo " "
+echo "#"
+echo "#"
+echo "# Requesting http://syntax.api.wrml.org/org/wrml/syntax/URI"
+echo "#"
+echo "#"
+echo " "
+curl -H "WRML-Host:syntax.api.wrml.org" -H "WRML-Port:80" http://localhost:8080/org/wrml/syntax/URI
+
+echo " "
+echo " "
+echo "#"
+echo "#"
+echo "# Requesting http://schema.api.wrml.org/org/wrml/model/schema/Choices"
+echo "#"
+echo "#"
+echo " "
+curl -H "WRML-Host:schema.api.wrml.org" -H "WRML-Port:80" http://localhost:8080/org/wrml/model/schema/Choices
+
+echo " "
+echo " "
+echo "#"
+echo "#"
+echo "# Requesting http://choices.api.wrml.org/org/wrml/model/schema/ValueType"
+echo "#"
+echo "#"
+echo " "
+curl -H "WRML-Host:choices.api.wrml.org" -H "WRML-Port:80" http://localhost:8080/org/wrml/model/schema/ValueType
+
+
@@ -128,6 +128,29 @@
</configuration>
</plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.3</version>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals><goal>copy</goal></goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-runner</artifactId>
+ <version>7.5.4.v20111024</version>
+ <destFileName>jetty-runner.jar</destFileName>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
Oops, something went wrong.

0 comments on commit 8fa6576

Please sign in to comment.