incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1149403 - in /incubator/isis/trunk/framework: ./ core/commons/src/main/java/org/apache/isis/core/commons/lang/ runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/ runtimes/dflt/webserver/src/main/java/org/apache/...
Date Thu, 21 Jul 2011 23:16:37 GMT
Author: danhaywood
Date: Thu Jul 21 23:16:31 2011
New Revision: 1149403

URL: http://svn.apache.org/viewvc?rev=1149403&view=rev
Log:
ISIS-109: started work on the tck tests for json viewer

Added:
    incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/internal/OptionHandlerStartupMode.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/Link.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/Method.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/boot/
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/boot/BootstrapResource.java
      - copied, changed from r1148920, incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/BootstrapResource.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/DomainObjectResource.java
      - copied, changed from r1148920, incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/DomainObjectResource.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/ServicesResource.java
      - copied, changed from r1148920, incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/ServicesResource.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/homepage/
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/homepage/HomePage.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/homepage/HomePageResource.java
      - copied, changed from r1148920, incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/HomePageResource.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/types/
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/types/SpecsResource.java
      - copied, changed from r1148920, incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/SpecsResource.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/user/
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/user/UserResource.java
      - copied, changed from r1148920, incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/UserResource.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/util/
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/util/JsonMapper.java
    incubator/isis/trunk/framework/viewer/json/json-tck/src/test/
    incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/
    incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/HomePageResourceTest.java
    incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/
    incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/
    incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/
    incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/
    incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/
    incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/
Removed:
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/BootstrapResource.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/DomainObjectResource.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/HomePageResource.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/ServicesResource.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/SpecsResource.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/UserResource.java
Modified:
    incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/lang/StringUtils.java
    incubator/isis/trunk/framework/pom.xml
    incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/WebServer.java
    incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/WebServerBootstrapper.java
    incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/WebServerConstants.java
    incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/internal/OptionHandlerPort.java
    incubator/isis/trunk/framework/viewer/json/json-tck/pom.xml
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstract.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/home/HomePageResourceImpl.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/objects/DomainObjectResourceImpl.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/objects/MemberRepType.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/services/ServicesResourceImpl.java

Modified: incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/lang/StringUtils.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/lang/StringUtils.java?rev=1149403&r1=1149402&r2=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/lang/StringUtils.java (original)
+++ incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/lang/StringUtils.java Thu Jul 21 23:16:31 2011
@@ -329,4 +329,13 @@ public final class StringUtils {
         }
     }
 
+    public static String coalesce(String... strings) {
+        for(String str: strings) {
+            if(str != null) {
+                return str;
+            }
+        }
+        return null;
+    }
+
 }

Modified: incubator/isis/trunk/framework/pom.xml
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/pom.xml?rev=1149403&r1=1149402&r2=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/pom.xml (original)
+++ incubator/isis/trunk/framework/pom.xml Thu Jul 21 23:16:31 2011
@@ -194,8 +194,13 @@
             <id>Maven Central Repository (UK Mirror)</id>
             <url>http://uk.maven.org/maven2</url>
         </repository>
+        <repository>
+            <id>JBoss Public Release</id>
+            <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
+        </repository>
     </repositories>
 
+
     <build>
         <extensions>
             <!-- scp and sftp support for deployments. -->
@@ -1085,7 +1090,7 @@ archetype includes this explicit depende
             <dependency>
                 <groupId>org.jboss.resteasy</groupId>
                 <artifactId>resteasy-jaxrs</artifactId>
-                <version>2.2.0.GA</version>
+                <version>2.2.1.GA</version>
                 <exclusions>
                     <!-- instead use org.apache.geronimo.specs:geronimo-servlet_2.5_spec -->
                     <exclusion>
@@ -1104,6 +1109,11 @@ archetype includes this explicit depende
                     </exclusion>
                 </exclusions>
             </dependency>
+            <dependency>
+                <groupId>org.jboss.resteasy</groupId>
+                <artifactId>resteasy-client</artifactId>
+                <version>1.0-beta-8</version>
+            </dependency>
 
 
             <!-- predicate libraries -->

Modified: incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/WebServer.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/WebServer.java?rev=1149403&r1=1149402&r2=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/WebServer.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/WebServer.java Thu Jul 21 23:16:31 2011
@@ -19,17 +19,66 @@
 
 package org.apache.isis.runtimes.dflt.webserver;
 
+import java.net.URI;
+import java.text.MessageFormat;
+import java.util.Formatter;
+
 import org.apache.isis.core.commons.lang.ArrayUtils;
+import org.apache.isis.core.commons.lang.StringUtils;
+import org.apache.isis.runtimes.dflt.runtime.runner.Constants;
 import org.apache.isis.runtimes.dflt.runtime.runner.IsisRunner;
 import org.apache.isis.runtimes.dflt.webserver.internal.OptionHandlerAddress;
 import org.apache.isis.runtimes.dflt.webserver.internal.OptionHandlerDeploymentTypeWebServer;
 import org.apache.isis.runtimes.dflt.webserver.internal.OptionHandlerPort;
 import org.apache.isis.runtimes.dflt.webserver.internal.OptionHandlerResourceBase;
+import org.apache.isis.runtimes.dflt.webserver.internal.OptionHandlerStartupMode;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Handler;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.webapp.WebAppContext;
+import org.mortbay.util.URIUtil;
 
 public class WebServer {
 
+    public static enum StartupMode {
+        FOREGROUND,
+        BACKGROUND;
+
+        public static StartupMode lookup(String value) {
+            if(value == null) {
+                return null;
+            }
+            try {
+                return valueOf(value.toUpperCase());
+            } catch (Exception e) {
+                return null;
+            }
+        }
+
+        public boolean isForeground() {
+            return this == FOREGROUND;
+        }
+
+        public boolean isBackground() {
+            return this == BACKGROUND;
+        }
+
+    }
+
+    private Server jettyServer;
+
     public static void main(final String[] args) {
-        new WebServer().run(ArrayUtils.append(args, "--nosplash"));
+        new WebServer().run(ArrayUtils.append(args, "--" + Constants.NO_SPLASH_LONG_OPT));
+    }
+
+    /**
+     * Originally introduced to allow the WebServer to be used by tests.
+     */
+    public void run(int port) {
+        String[] args = new String[0];
+        args = OptionHandlerStartupMode.appendArg(args,StartupMode.BACKGROUND);
+        args = OptionHandlerPort.appendArg(args,port);
+        run(args);
     }
 
     public void run(final String[] args) {
@@ -39,12 +88,51 @@ public class WebServer {
         runner.addOptionHandler(new OptionHandlerPort());
         runner.addOptionHandler(new OptionHandlerAddress());
         runner.addOptionHandler(new OptionHandlerResourceBase());
+        runner.addOptionHandler(new OptionHandlerStartupMode());
 
         if (!runner.parseAndValidate()) {
             return;
         }
 
-        runner.bootstrap(new WebServerBootstrapper(runner));
+        WebServerBootstrapper bootstrapper = new WebServerBootstrapper(runner);
+        runner.bootstrap(bootstrapper);
+        jettyServer = bootstrapper.getJettyServer();
     }
 
+    public void stop() {
+        if(jettyServer == null) {
+            return;
+        }
+        try {
+            jettyServer.stop();
+        } catch (Exception e) {
+            e.printStackTrace(System.err);
+        }
+    }
+
+    public URI getBase() {
+        return URI.create(baseFor(jettyServer));
+    }
+
+    private String baseFor(Server jettyServer) {
+        Connector connector = jettyServer.getConnectors()[0];
+        String scheme = "http";
+        String host = StringUtils.coalesce(connector.getHost(), "localhost");
+        int port = connector.getPort();
+
+        WebAppContext handler = (WebAppContext) jettyServer.getHandler();
+        String contextPath = handler.getContextPath();
+
+        StringBuilder buf = new StringBuilder();
+        Formatter formatter = new Formatter(buf);
+        formatter.format("%s://%s:%d/%s", scheme, host, port, contextPath);
+        return appendSlashIfRequired(buf).toString();
+    }
+
+    private static StringBuilder appendSlashIfRequired(StringBuilder buf) {
+        if(buf.charAt(buf.length()-1) != '/') {
+            buf.append('/');
+        }
+        return buf;
+    }
 }

Modified: incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/WebServerBootstrapper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/WebServerBootstrapper.java?rev=1149403&r1=1149402&r2=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/WebServerBootstrapper.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/WebServerBootstrapper.java Thu Jul 21 23:16:31 2011
@@ -23,6 +23,8 @@ import static org.apache.isis.runtimes.d
 import static org.apache.isis.runtimes.dflt.webserver.WebServerConstants.EMBEDDED_WEB_SERVER_PORT_KEY;
 import static org.apache.isis.runtimes.dflt.webserver.WebServerConstants.EMBEDDED_WEB_SERVER_RESOURCE_BASE_DEFAULT;
 import static org.apache.isis.runtimes.dflt.webserver.WebServerConstants.EMBEDDED_WEB_SERVER_RESOURCE_BASE_KEY;
+import static org.apache.isis.runtimes.dflt.webserver.WebServerConstants.EMBEDDED_WEB_SERVER_STARTUP_MODE_KEY;
+import static org.apache.isis.runtimes.dflt.webserver.WebServerConstants.EMBEDDED_WEB_SERVER_STARTUP_MODE_DEFAULT;
 
 import java.util.HashMap;
 import java.util.List;
@@ -36,14 +38,20 @@ import org.apache.isis.core.commons.lang
 import org.apache.isis.runtimes.dflt.runtime.runner.IsisBootstrapper;
 import org.apache.isis.runtimes.dflt.runtime.runner.IsisRunner;
 import org.apache.isis.runtimes.dflt.webapp.WebAppConstants;
+import org.apache.isis.runtimes.dflt.webserver.WebServer.StartupMode;
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.webapp.WebAppContext;
 
 import com.google.inject.Injector;
 
 final class WebServerBootstrapper implements IsisBootstrapper {
+    
     private static final String SRC_MAIN_WEBAPP = "src/main/webapp";
+    
     private final IsisRunner runner;
+    
+    private Server jettyServer;
+
 
     WebServerBootstrapper(final IsisRunner runner) {
         this.runner = runner;
@@ -63,20 +71,28 @@ final class WebServerBootstrapper implem
         final int port = configuration.getInteger(EMBEDDED_WEB_SERVER_PORT_KEY, EMBEDDED_WEB_SERVER_PORT_DEFAULT);
         final String webappContextPath =
             configuration.getString(EMBEDDED_WEB_SERVER_RESOURCE_BASE_KEY, EMBEDDED_WEB_SERVER_RESOURCE_BASE_DEFAULT);
+        StartupMode startupMode = StartupMode.lookup(
+                configuration.getString(EMBEDDED_WEB_SERVER_STARTUP_MODE_KEY, EMBEDDED_WEB_SERVER_STARTUP_MODE_DEFAULT));
 
-        final Server server = new Server(port);
+        jettyServer = new Server(port);
         final WebAppContext context = new WebAppContext(SRC_MAIN_WEBAPP, webappContextPath);
 
         copyConfigurationPrimersIntoServletContext(context);
 
-        server.setHandler(context);
+        jettyServer.setHandler(context);
         try {
-            server.start();
-            server.join();
+            jettyServer.start();
+            if(startupMode.isForeground()) {
+                jettyServer.join();
+            }
         } catch (final Exception ex) {
             throw new IsisException("Unable to start Jetty server", ex);
         }
     }
+    
+    public Server getJettyServer() {
+        return jettyServer;
+    }
 
     /**
      * Bound to the {@link WebAppContext} so that they can be used when bootstrapping.

Modified: incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/WebServerConstants.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/WebServerConstants.java?rev=1149403&r1=1149402&r2=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/WebServerConstants.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/WebServerConstants.java Thu Jul 21 23:16:31 2011
@@ -21,6 +21,7 @@ package org.apache.isis.runtimes.dflt.we
 
 import org.apache.isis.core.commons.config.ConfigurationConstants;
 import org.apache.isis.runtimes.dflt.runtime.installerregistry.installerapi.EmbeddedWebServerInstaller;
+import org.apache.isis.runtimes.dflt.webserver.WebServer.StartupMode;
 
 public final class WebServerConstants {
 
@@ -35,6 +36,9 @@ public final class WebServerConstants {
     public static final String EMBEDDED_WEB_SERVER_RESOURCE_BASE_KEY = ROOT + "webapp";
     public static final String EMBEDDED_WEB_SERVER_RESOURCE_BASE_DEFAULT = ""; // or "webapp" ??
 
+    public static final String EMBEDDED_WEB_SERVER_STARTUP_MODE_KEY = ROOT + "startupMode";
+    public static final String EMBEDDED_WEB_SERVER_STARTUP_MODE_DEFAULT = StartupMode.FOREGROUND.name(); 
+
     private WebServerConstants() {
     }
 

Modified: incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/internal/OptionHandlerPort.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/internal/OptionHandlerPort.java?rev=1149403&r1=1149402&r2=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/internal/OptionHandlerPort.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/internal/OptionHandlerPort.java Thu Jul 21 23:16:31 2011
@@ -27,6 +27,7 @@ import org.apache.commons.cli.Option;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 import org.apache.isis.core.commons.config.IsisConfigurationBuilder;
+import org.apache.isis.core.commons.lang.ArrayUtils;
 import org.apache.isis.core.runtime.optionhandler.BootPrinter;
 import org.apache.isis.core.runtime.optionhandler.OptionHandler;
 import org.apache.isis.runtimes.dflt.webserver.WebServerConstants;
@@ -36,6 +37,10 @@ public final class OptionHandlerPort imp
     static final String PORT_LONG_OPT = "port";
     static final String PORT_OPT = "p";
 
+    public static String[] appendArg(String[] args, int port) {
+        return ArrayUtils.append(args, "--" + PORT_LONG_OPT, "" + port);
+    }
+
     @Override
     @SuppressWarnings("static-access")
     public void addOption(final Options options) {

Added: incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/internal/OptionHandlerStartupMode.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/internal/OptionHandlerStartupMode.java?rev=1149403&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/internal/OptionHandlerStartupMode.java (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/internal/OptionHandlerStartupMode.java Thu Jul 21 23:16:31 2011
@@ -0,0 +1,67 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+
+package org.apache.isis.runtimes.dflt.webserver.internal;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.isis.core.commons.config.IsisConfigurationBuilder;
+import org.apache.isis.core.commons.lang.ArrayUtils;
+import org.apache.isis.core.runtime.optionhandler.BootPrinter;
+import org.apache.isis.core.runtime.optionhandler.OptionHandler;
+import org.apache.isis.runtimes.dflt.webserver.WebServer.StartupMode;
+import org.apache.isis.runtimes.dflt.webserver.WebServerConstants;
+
+public final class OptionHandlerStartupMode implements OptionHandler {
+    
+    static final String STARTUP_MODE_LONG_OPT = "startup";
+    static final String STARTUP_MODE_BASE_OPT = "a";
+
+    public static String[] appendArg(String[] args, StartupMode startupMode) {
+        return ArrayUtils.append(args, "--" + STARTUP_MODE_LONG_OPT, "" + startupMode.name());
+    }
+
+    private StartupMode startupMode;
+
+    @Override
+    @SuppressWarnings("static-access")
+    public void addOption(final Options options) {
+        final Option option =
+            OptionBuilder.withArgName("startup mode").hasArg()
+                .withLongOpt(OptionHandlerStartupMode.STARTUP_MODE_LONG_OPT)
+                .withDescription("start in foreground (sync) or background (async)").create(OptionHandlerStartupMode.STARTUP_MODE_BASE_OPT);
+        options.addOption(option);
+    }
+
+    @Override
+    public boolean handle(final CommandLine commandLine, final BootPrinter bootPrinter, final Options options) {
+        startupMode = StartupMode.lookup(commandLine.getOptionValue(OptionHandlerStartupMode.STARTUP_MODE_BASE_OPT));
+        return true;
+    }
+
+    @Override
+    public void primeConfigurationBuilder(final IsisConfigurationBuilder isisConfigurationBuilder) {
+        if(startupMode != null) {
+            isisConfigurationBuilder.add(WebServerConstants.EMBEDDED_WEB_SERVER_STARTUP_MODE_KEY, startupMode.name());
+        }
+    }
+
+}
\ No newline at end of file

Added: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/Link.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/Link.java?rev=1149403&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/Link.java (added)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/Link.java Thu Jul 21 23:16:31 2011
@@ -0,0 +1,33 @@
+package org.apache.isis.viewer.json.applib.blocks;
+
+public class Link {
+    
+    private String rel;
+    private String href;
+    private Method method;
+    
+    public String getRel() {
+        return rel;
+    }
+    public void setRel(String rel) {
+        this.rel = rel;
+    }
+    public String getHref() {
+        return href;
+    }
+    public void setHref(String href) {
+        this.href = href;
+    }
+    public Method getMethod() {
+        return method;
+    }
+    public void setMethod(Method method) {
+        this.method = method;
+    }
+    @Override
+    public String toString() {
+        return "Link [rel=" + rel + ", href=" + href + ", method=" + method + "]";
+    }
+
+    
+}

Added: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/Method.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/Method.java?rev=1149403&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/Method.java (added)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/Method.java Thu Jul 21 23:16:31 2011
@@ -0,0 +1,8 @@
+package org.apache.isis.viewer.json.applib.blocks;
+
+public enum Method {
+    GET,
+    PUT,
+    POST,
+    DELETE
+}

Copied: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/boot/BootstrapResource.java (from r1148920, incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/BootstrapResource.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/boot/BootstrapResource.java?p2=incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/boot/BootstrapResource.java&p1=incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/BootstrapResource.java&r1=1148920&r2=1149403&rev=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/BootstrapResource.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/boot/BootstrapResource.java Thu Jul 21 23:16:31 2011
@@ -16,7 +16,7 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package org.apache.isis.viewer.json.applib.resources;
+package org.apache.isis.viewer.json.applib.boot;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Produces;

Copied: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/DomainObjectResource.java (from r1148920, incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/DomainObjectResource.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/DomainObjectResource.java?p2=incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/DomainObjectResource.java&p1=incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/DomainObjectResource.java&r1=1148920&r2=1149403&rev=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/DomainObjectResource.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/DomainObjectResource.java Thu Jul 21 23:16:31 2011
@@ -16,11 +16,12 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package org.apache.isis.viewer.json.applib.resources;
+package org.apache.isis.viewer.json.applib.domain;
 
 import java.io.InputStream;
 import java.util.List;
 
+import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
@@ -32,39 +33,46 @@ import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
+import org.jboss.resteasy.annotations.ClientResponseType;
+
 // under /objects
 public interface DomainObjectResource {
 
     @GET
     @Path("/{oid}")
     @Produces({ MediaType.APPLICATION_JSON })
-    public String object(@PathParam("oid") final String oidStr);
+    @ClientResponseType(entityType=String.class)
+    public Response object(@PathParam("oid") final String oidStr);
 
     @GET
     @Path("/{oid}/properties{propertyId}")
     @Produces({ MediaType.APPLICATION_JSON })
-    public String propertyDetails(
+    @ClientResponseType(entityType=String.class)
+    public Response propertyDetails(
         @PathParam("oid") final String oidStr,
         @PathParam("propertyId") final String propertyId);
 
     @GET
     @Path("/{oid}/collections/{collectionId}")
     @Produces({ MediaType.APPLICATION_JSON })
-    public String accessCollection(
+    @ClientResponseType(entityType=String.class)
+    public Response accessCollection(
         @PathParam("oid") final String oidStr,
         @PathParam("collectionId") final String collectionId);
 
     @GET
     @Path("/{oid}/actions/{actionId}")
     @Produces({ MediaType.APPLICATION_JSON })
-    public String actionPrompt(
+    @ClientResponseType(entityType=String.class)
+    public Response actionPrompt(
         @PathParam("oid") final String oidStr, 
         @PathParam("actionId") final String actionId);
 
     @GET
     @Path("/{oid}/actions/{actionId}/invoke")
     @Produces({ MediaType.APPLICATION_JSON })
-    public Object invokeActionIdempotent(
+    @ClientResponseType(entityType=String.class)
+    public Response invokeActionIdempotent(
         @PathParam("oid") final String oidStr, 
         @PathParam("actionId") final String actionId,
         @QueryParam("arg") final List<String> arguments);
@@ -72,6 +80,8 @@ public interface DomainObjectResource {
     @PUT
     @Path("/{oid}/properties{propertyId}")
     @Produces({ MediaType.APPLICATION_JSON })
+    @Consumes({ MediaType.APPLICATION_JSON })
+    @ClientResponseType(entityType=String.class)
     public Response modifyProperty(
         @PathParam("oid") final String oidStr,
         @PathParam("propertyId") final String propertyId, 
@@ -79,6 +89,7 @@ public interface DomainObjectResource {
 
     @PUT
     @Path("/{oid}/collections/{collectionId}")
+    @Consumes({ MediaType.APPLICATION_JSON })
     @Produces({ MediaType.APPLICATION_JSON })
     public Response addToSet(
         @PathParam("oid") final String oidStr,
@@ -88,6 +99,7 @@ public interface DomainObjectResource {
     @DELETE
     @Path("/{oid}/properties/{propertyId}")
     @Produces({ MediaType.APPLICATION_JSON })
+    @ClientResponseType(entityType=String.class)
     public Response clearProperty(
         @PathParam("oid") final String oidStr, 
         @PathParam("propertyId") final String propertyId);
@@ -95,6 +107,8 @@ public interface DomainObjectResource {
     @DELETE
     @Path("/{oid}/collections/{collectionId}")
     @Produces({ MediaType.APPLICATION_JSON })
+    @Consumes({ MediaType.APPLICATION_JSON })
+    @ClientResponseType(entityType=String.class)
     public Response removeFromCollection(
         @PathParam("oid") final String oidStr,
         @PathParam("collectionId") final String collectionId,
@@ -103,6 +117,8 @@ public interface DomainObjectResource {
     @POST
     @Path("/{oid}/collections/{collectionId}")
     @Produces({ MediaType.APPLICATION_JSON })
+    @Consumes({ MediaType.APPLICATION_JSON })
+    @ClientResponseType(entityType=String.class)
     public Response addToList(
         @PathParam("oid") final String oidStr,
         @PathParam("collectionId") final String collectionId,
@@ -111,7 +127,9 @@ public interface DomainObjectResource {
     @POST
     @Path("/{oid}/actions/{actionId}/invoke")
     @Produces({ MediaType.APPLICATION_JSON })
-    public Object invokeAction(
+    @Consumes({ MediaType.APPLICATION_JSON })
+    @ClientResponseType(entityType=String.class)
+    public Response invokeAction(
         @PathParam("oid") final String oidStr, 
         @PathParam("actionId") final String actionId,
         final InputStream body);

Copied: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/ServicesResource.java (from r1148920, incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/ServicesResource.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/ServicesResource.java?p2=incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/ServicesResource.java&p1=incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/ServicesResource.java&r1=1148920&r2=1149403&rev=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/ServicesResource.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/ServicesResource.java Thu Jul 21 23:16:31 2011
@@ -16,18 +16,22 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package org.apache.isis.viewer.json.applib.resources;
+package org.apache.isis.viewer.json.applib.domain;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.jboss.resteasy.annotations.ClientResponseType;
 
 public interface ServicesResource {
 
     @GET
-    @Produces({ MediaType.APPLICATION_JSON })
     @Path("/")
-    public String services();
+    @Produces({ MediaType.APPLICATION_JSON })
+    @ClientResponseType(entityType=String.class)
+    public Response services();
 
 }
\ No newline at end of file

Added: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/homepage/HomePage.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/homepage/HomePage.java?rev=1149403&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/homepage/HomePage.java (added)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/homepage/HomePage.java Thu Jul 21 23:16:31 2011
@@ -0,0 +1,28 @@
+package org.apache.isis.viewer.json.applib.homepage;
+
+import org.apache.isis.viewer.json.applib.blocks.Link;
+
+public class HomePage {
+
+    private Link user;
+    private Link services;
+    public Link getUser() {
+        return user;
+    }
+    public void setUser(Link user) {
+        this.user = user;
+    }
+    public Link getServices() {
+        return services;
+    }
+    public void setServices(Link services) {
+        this.services = services;
+    }
+    
+    @Override
+    public String toString() {
+        return "HomePage [user=" + user + ", services=" + services + "]";
+    }
+    
+    
+}

Copied: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/homepage/HomePageResource.java (from r1148920, incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/HomePageResource.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/homepage/HomePageResource.java?p2=incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/homepage/HomePageResource.java&p1=incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/HomePageResource.java&r1=1148920&r2=1149403&rev=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/HomePageResource.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/homepage/HomePageResource.java Thu Jul 21 23:16:31 2011
@@ -16,16 +16,20 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package org.apache.isis.viewer.json.applib.resources;
+package org.apache.isis.viewer.json.applib.homepage;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.jboss.resteasy.annotations.ClientResponseType;
 
 public interface HomePageResource {
 
     @GET
     @Produces({ MediaType.APPLICATION_JSON })
-    public String resources();
+    @ClientResponseType(entityType=String.class)
+    public Response resources();
 
 }
\ No newline at end of file

Copied: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/types/SpecsResource.java (from r1148920, incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/SpecsResource.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/types/SpecsResource.java?p2=incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/types/SpecsResource.java&p1=incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/SpecsResource.java&r1=1148920&r2=1149403&rev=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/SpecsResource.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/types/SpecsResource.java Thu Jul 21 23:16:31 2011
@@ -16,66 +16,79 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package org.apache.isis.viewer.json.applib.resources;
+package org.apache.isis.viewer.json.applib.types;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
 
+import org.jboss.resteasy.annotations.ClientResponseType;
+
+@Path("/types")
 public interface SpecsResource {
 
     @GET
     @Path("/")
     @Produces({ MediaType.APPLICATION_JSON })
-    public abstract String specs();
+    @ClientResponseType(entityType=String.class)
+    public abstract Response specs();
 
     @GET
     @Path("/{specFullName}")
     @Produces({ MediaType.APPLICATION_JSON })
-    public abstract String spec(@PathParam("specFullName") final String specFullName);
+    @ClientResponseType(entityType=String.class)
+    public abstract Response spec(@PathParam("specFullName") final String specFullName);
 
     @GET
     @Path("/{specFullName}/facet/{facetType}")
     @Produces({ MediaType.APPLICATION_JSON })
-    public abstract String specFacet(@PathParam("specFullName") final String specFullName,
+    @ClientResponseType(entityType=String.class)
+    public abstract Response specFacet(@PathParam("specFullName") final String specFullName,
         @PathParam("facetType") final String facetTypeName);
 
     @GET
     @Path("/{specFullName}/property/{propertyName}")
     @Produces({ MediaType.APPLICATION_JSON })
-    public abstract String specProperty(@PathParam("specFullName") final String specFullName,
+    @ClientResponseType(entityType=String.class)
+    public abstract Response specProperty(@PathParam("specFullName") final String specFullName,
         @PathParam("propertyName") final String propertyName);
 
     @GET
     @Path("/{specFullName}/collection/{collectionName}")
     @Produces({ MediaType.APPLICATION_JSON })
-    public abstract String specCollection(@PathParam("specFullName") final String specFullName,
+    @ClientResponseType(entityType=String.class)
+    public abstract Response specCollection(@PathParam("specFullName") final String specFullName,
         @PathParam("collectionName") final String collectionName);
 
     @GET
     @Path("/{specFullName}/action/{actionId}")
     @Produces({ MediaType.APPLICATION_JSON })
-    public abstract String specAction(@PathParam("specFullName") final String specFullName,
+    @ClientResponseType(entityType=String.class)
+    public abstract Response specAction(@PathParam("specFullName") final String specFullName,
         @PathParam("actionId") final String actionId);
 
     @GET
     @Path("/{specFullName}/property/{propertyName}/facet/{facetType}")
     @Produces({ MediaType.APPLICATION_JSON })
-    public abstract String specPropertyFacet(@PathParam("specFullName") final String specFullName,
+    @ClientResponseType(entityType=String.class)
+    public abstract Response specPropertyFacet(@PathParam("specFullName") final String specFullName,
         @PathParam("propertyName") final String propertyName, @PathParam("facetType") final String facetTypeName);
 
     @GET
     @Path("/{specFullName}/collection/{collectionName}/facet/{facetType}")
     @Produces({ MediaType.APPLICATION_JSON })
-    public abstract String specCollectionFacet(@PathParam("specFullName") final String specFullName,
+    @ClientResponseType(entityType=String.class)
+    public abstract Response specCollectionFacet(@PathParam("specFullName") final String specFullName,
         @PathParam("collectionName") final String collectionName, @PathParam("facetType") final String facetTypeName);
 
     @GET
     @Path("/{specFullName}/action/{actionId}/facet/{facetType}")
     @Produces({ MediaType.APPLICATION_JSON })
-    public abstract String specActionFacet(@PathParam("specFullName") final String specFullName,
+    @ClientResponseType(entityType=String.class)
+    public abstract Response specActionFacet(@PathParam("specFullName") final String specFullName,
         @PathParam("actionId") final String actionId, @PathParam("facetType") final String facetTypeName);
 
 }
\ No newline at end of file

Copied: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/user/UserResource.java (from r1148920, incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/UserResource.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/user/UserResource.java?p2=incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/user/UserResource.java&p1=incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/UserResource.java&r1=1148920&r2=1149403&rev=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/resources/UserResource.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/user/UserResource.java Thu Jul 21 23:16:31 2011
@@ -16,16 +16,22 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package org.apache.isis.viewer.json.applib.resources;
+package org.apache.isis.viewer.json.applib.user;
 
 import javax.ws.rs.GET;
+import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
 
+import org.jboss.resteasy.annotations.ClientResponseType;
+
+@Path("/user")
 public interface UserResource {
 
     @GET
     @Produces({ MediaType.APPLICATION_JSON })
-    public String user();
+    @ClientResponseType(entityType=String.class)
+    public Response user();
 
 }
\ No newline at end of file

Added: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/util/JsonMapper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/util/JsonMapper.java?rev=1149403&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/util/JsonMapper.java (added)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/util/JsonMapper.java Thu Jul 21 23:16:31 2011
@@ -0,0 +1,52 @@
+package org.apache.isis.viewer.json.applib.util;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.isis.viewer.json.applib.homepage.HomePage;
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.DeserializationConfig;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+
+
+public class JsonMapper {
+    private ObjectMapper objectMapper = new ObjectMapper();
+
+    public JsonMapper() {
+        objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+        objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+    }
+
+    @SuppressWarnings("unchecked")
+    public Map<String, Object> readAsMap(String json) {
+        return objectMapper.convertValue(json, LinkedHashMap.class);
+    }
+
+    public List<?> readAsList(String json) {
+        return objectMapper.convertValue(json, ArrayList.class);
+    }
+
+    public <T> T read(String json, Class<T> expectedType) throws JsonParseException, JsonMappingException, IOException {
+        return (T) objectMapper.readValue(json, expectedType);        
+    }
+
+    public String write(Object object) throws JsonGenerationException, JsonMappingException, IOException {
+        return objectMapper.writeValueAsString(object);
+    }
+    
+
+    /**
+     * @deprecated
+     * @return
+     */
+    @Deprecated
+    public ObjectMapper getObjectMapper() {
+        return objectMapper;
+    }
+
+}
\ No newline at end of file

Modified: incubator/isis/trunk/framework/viewer/json/json-tck/pom.xml
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-tck/pom.xml?rev=1149403&r1=1149402&r2=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-tck/pom.xml (original)
+++ incubator/isis/trunk/framework/viewer/json/json-tck/pom.xml Thu Jul 21 23:16:31 2011
@@ -41,6 +41,13 @@
 		</plugins>
 	</build>
 
+    <repositories>
+        <repository>
+            <id>JBoss Public Release</id>
+            <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
+        </repository>
+    </repositories>
+
 	<dependencies>
 	
         <!-- other modules in this project -->
@@ -57,6 +64,12 @@
         </dependency>
 
 
+        <dependency>
+            <groupId>org.jboss.resteasy</groupId>
+            <artifactId>resteasy-client</artifactId>
+            <version>1.0-beta-8</version>
+        </dependency>
+
         <!-- isis viewer -->
 		<dependency>
 	        <groupId>org.apache.isis.viewer</groupId>
@@ -105,6 +118,13 @@
             <optional>true</optional>
         </dependency>
 
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.8.2</version>
+            <scope>test</scope>
+        </dependency>
+        
 	</dependencies>
 
 </project>

Added: incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/HomePageResourceTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/HomePageResourceTest.java?rev=1149403&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/HomePageResourceTest.java (added)
+++ incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/HomePageResourceTest.java Thu Jul 21 23:16:31 2011
@@ -0,0 +1,79 @@
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.assertThat;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Map;
+
+import javax.ws.rs.core.Response;
+
+import org.apache.isis.runtimes.dflt.webserver.WebServer;
+import org.apache.isis.viewer.json.applib.blocks.Method;
+import org.apache.isis.viewer.json.applib.domain.DomainObjectResource;
+import org.apache.isis.viewer.json.applib.domain.ServicesResource;
+import org.apache.isis.viewer.json.applib.homepage.HomePage;
+import org.apache.isis.viewer.json.applib.homepage.HomePageResource;
+import org.apache.isis.viewer.json.applib.user.UserResource;
+import org.apache.isis.viewer.json.applib.util.JsonMapper;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.jboss.resteasy.client.ClientRequestFactory;
+import org.jboss.resteasy.client.ProxyFactory;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+public class HomePageResourceTest {
+
+    @BeforeClass
+    public static void setUpClass() throws Exception {
+        webServer = new WebServer();
+        webServer.run(8080);
+    }
+
+    @AfterClass
+    public static void tearDownClass() throws Exception {
+        webServer.stop();
+    }
+
+    private static WebServer webServer;
+    
+    private final static JsonMapper jsonMapper = new JsonMapper();
+    
+    private HomePageResource homePageResource;
+    private DomainObjectResource domainObjectResource;
+    private ServicesResource servicesResource;
+    private UserResource userResource;
+
+    @Before
+    public void setUp() throws Exception {
+        URI base = webServer.getBase();
+        ClientRequestFactory clientRequestFactory = new ClientRequestFactory(base);
+        
+        homePageResource = clientRequestFactory.createProxy(HomePageResource.class);
+        domainObjectResource = clientRequestFactory.createProxy(DomainObjectResource.class);
+        servicesResource = clientRequestFactory.createProxy(ServicesResource.class);
+        userResource = clientRequestFactory.createProxy(UserResource.class);
+    }
+    
+    @Test
+    public void homePageResources() throws JsonParseException, JsonMappingException, IOException {
+        Response resources = homePageResource.resources();
+        assertThat(resources.getStatus(), is(200));
+        Object entity = resources.getEntity();
+        assertThat(entity, is(not(nullValue())));
+
+        // not yet working...
+        
+        //HomePage homePage = jsonMapper.read(entity, HomePage.class);
+        //assertThat(homePage.getUser().getMethod(), is(Method.GET));
+        
+//        Map<String, Object> readAsMap = jsonMapper.readAsMap((String) entity);
+//        assertThat(((Map<?,?>)readAsMap.get("user")).get("method"), is((Object)Method.GET));
+        
+        
+    }
+
+}

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstract.java?rev=1149403&r1=1149402&r2=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstract.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstract.java Thu Jul 21 23:16:31 2011
@@ -45,6 +45,7 @@ import org.apache.isis.runtimes.dflt.run
 import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
 import org.apache.isis.runtimes.dflt.runtime.system.persistence.OidGenerator;
 import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.viewer.json.applib.util.JsonMapper;
 import org.apache.isis.viewer.json.viewer.RepContext;
 import org.apache.isis.viewer.json.viewer.ResourceContext;
 import org.apache.isis.viewer.json.viewer.representations.Representation;
@@ -68,10 +69,7 @@ public abstract class ResourceAbstract {
     private static final String HEADER_X_RESTFUL_OBJECTS_REASON = "X-RestfulObjects-Reason";
 
 
-	protected final static ObjectMapper objectMapper = new ObjectMapper();
-    static {
-        objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
-    }
+	protected final static JsonMapper jsonMapper = new JsonMapper();
 
 	public final static ActionType[] ACTION_TYPES = { ActionType.USER, ActionType.DEBUG, ActionType.EXPLORATION,
     // SET is excluded; we simply flatten contributed actions.
@@ -132,7 +130,7 @@ public abstract class ResourceAbstract {
 
     protected String asJson(final Object object) {
         try {
-            return objectMapper.writeValueAsString(object);
+            return jsonMapper.write(object);
         } catch (JsonGenerationException e) {
             throw new RuntimeException(e);
         } catch (JsonMappingException e) {
@@ -239,6 +237,10 @@ public abstract class ResourceAbstract {
         return Response.ok().build();
     }
 
+    protected static Response responseOfOk(String entity) {
+        return Response.ok().entity(entity).build();
+    }
+
     protected static Response responseOfGone(final String reason) {
         return Response.status(Status.GONE).header(HEADER_X_RESTFUL_OBJECTS_REASON, reason).build();
     }

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/home/HomePageResourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/home/HomePageResourceImpl.java?rev=1149403&r1=1149402&r2=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/home/HomePageResourceImpl.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/home/HomePageResourceImpl.java Thu Jul 21 23:16:31 2011
@@ -21,11 +21,13 @@ package org.apache.isis.viewer.json.view
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
 
-import org.apache.isis.viewer.json.applib.resources.HomePageResource;
+import org.apache.isis.viewer.json.applib.homepage.HomePageResource;
 import org.apache.isis.viewer.json.viewer.representations.LinkRepBuilder;
 import org.apache.isis.viewer.json.viewer.representations.Representation;
 import org.apache.isis.viewer.json.viewer.resources.ResourceAbstract;
+import org.jboss.resteasy.annotations.ClientResponseType;
 
 /**
  * Implementation note: it seems to be necessary to annotate the implementation with {@link Path} rather than the
@@ -37,14 +39,14 @@ public class HomePageResourceImpl extend
 
     @Override
     @Produces(MediaType.APPLICATION_JSON)
-    public String resources() {
+    public Response resources() {
         init();
         
         Representation representation = new Representation();
         representation.put("user", linkTo("user"));
         representation.put("services", linkTo("services"));
         
-        return asJson(representation);
+        return responseOfOk(asJson(representation));
     }
 
     protected Representation linkTo(String url) {

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/objects/DomainObjectResourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/objects/DomainObjectResourceImpl.java?rev=1149403&r1=1149402&r2=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/objects/DomainObjectResourceImpl.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/objects/DomainObjectResourceImpl.java Thu Jul 21 23:16:31 2011
@@ -49,7 +49,7 @@ import org.apache.isis.core.metamodel.sp
 import org.apache.isis.core.metamodel.spec.feature.ObjectMember;
 import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
 import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
-import org.apache.isis.viewer.json.applib.resources.DomainObjectResource;
+import org.apache.isis.viewer.json.applib.domain.DomainObjectResource;
 import org.apache.isis.viewer.json.viewer.resources.ResourceAbstract;
 import org.apache.isis.viewer.json.viewer.util.UrlDecoderUtils;
 import org.codehaus.jackson.JsonParseException;
@@ -66,18 +66,18 @@ public class DomainObjectResourceImpl ex
     @GET
     @Path("/{oid}")
     @Produces({ MediaType.APPLICATION_JSON })
-    public String object(@PathParam("oid") final String oidStr) {
+    public Response object(@PathParam("oid") final String oidStr) {
 
         final ObjectAdapter objectAdapter = getObjectAdapter(oidStr);
         final DomainObjectRepBuilder builder = DomainObjectRepBuilder
                 .newBuilder(getResourceContext().repContext(), objectAdapter);
-        return jsonRepresentionFrom(builder);
+        return responseOfOk(jsonRepresentionFrom(builder));
     }
 
     @GET
     @Path("/{oid}/properties/{propertyId}")
     @Produces({ MediaType.APPLICATION_JSON })
-    public String propertyDetails(
+    public Response propertyDetails(
         @PathParam("oid") final String oidStr,
         @PathParam("propertyId") final String propertyId) {
 
@@ -87,13 +87,13 @@ public class DomainObjectResourceImpl ex
 
         final PropertyRepBuilder builder = PropertyRepBuilder.newBuilder(
                 getResourceContext().repContext(), objectAdapter, property);
-        return jsonRepresentionFrom(builder);
+        return responseOfOk(jsonRepresentionFrom(builder));
     }
 
     @GET
     @Path("/{oid}/collections/{collectionId}")
     @Produces({ MediaType.APPLICATION_JSON })
-    public String accessCollection(
+    public Response accessCollection(
         @PathParam("oid") final String oidStr,
         @PathParam("collectionId") final String collectionId) {
 
@@ -103,13 +103,13 @@ public class DomainObjectResourceImpl ex
 
         final CollectionRepBuilder builder = CollectionRepBuilder.newBuilder(
                 getResourceContext().repContext(), objectAdapter, collection);
-        return jsonRepresentionFrom(builder);
+        return responseOfOk(jsonRepresentionFrom(builder));
     }
 
     @GET
     @Path("/{oid}/actions/{actionId}")
     @Produces({ MediaType.APPLICATION_JSON })
-    public String actionPrompt(
+    public Response actionPrompt(
         @PathParam("oid") final String oidStr,
         @PathParam("actionId") final String actionId) {
 
@@ -119,13 +119,13 @@ public class DomainObjectResourceImpl ex
 
         ActionRepBuilder builder = ActionRepBuilder.newBuilder(
                 getResourceContext().repContext(), objectAdapter, action);
-        return jsonRepresentionFrom(builder);
+        return responseOfOk(jsonRepresentionFrom(builder));
     }
 
     @GET
     @Path("/{oid}/actions/{actionId}/invoke")
     @Produces({ MediaType.APPLICATION_JSON })
-    public Object invokeActionIdempotent(
+    public Response invokeActionIdempotent(
         @PathParam("oid") final String oidStr,
         @PathParam("actionId") final String actionId,
         @QueryParam("arg") final List<String> arguments) {
@@ -178,15 +178,13 @@ public class DomainObjectResourceImpl ex
      * (rather than having already been parsed into a List/Map representation).
      */
     private ObjectAdapter objectAdapterFor(ObjectSpecification spec,
-        String urlEncodedJson) {
+        String urlEncodedJson)  {
         final String json = UrlDecoderUtils.urlDecode(urlEncodedJson);
         if (spec.containsFacet(EncodableFacet.class)) {
             EncodableFacet encodableFacet = spec.getFacet(EncodableFacet.class);
             return encodableFacet.fromEncodedString(json);
         } else {
-            @SuppressWarnings("unchecked")
-            Map<String, Object> representation = objectMapper.convertValue(
-                    json, LinkedHashMap.class);
+            Map<String, Object> representation = jsonMapper.readAsMap(json);
             return objectAdapterFor(spec, representation);
         }
     }
@@ -337,7 +335,7 @@ public class DomainObjectResourceImpl ex
     @POST
     @Path("/{oid}/actions/{actionId}/invoke")
     @Produces({ MediaType.APPLICATION_JSON })
-    public Object invokeAction(
+    public Response invokeAction(
         @PathParam("oid") final String oidStr,
         @PathParam("actionId") final String actionId,
         final InputStream body) {
@@ -412,7 +410,7 @@ public class DomainObjectResourceImpl ex
     // helpers
     // ///////////////////////////////////////////////////////////////////
 
-    private Object invokeActionUsingAdapters(final ObjectAction action,
+    private Response invokeActionUsingAdapters(final ObjectAction action,
         final ObjectAdapter objectAdapter,
         final List<ObjectAdapter> argAdapters) {
 
@@ -447,9 +445,9 @@ public class DomainObjectResourceImpl ex
         if (facet != null) {
             final Collection<ObjectAdapter> collectionAdapters = facet
                     .collection(returnedAdapter);
-            return jsonRepresentationOf(collectionAdapters);
+            return responseOfOk(jsonRepresentationOf(collectionAdapters));
         } else {
-            return jsonRepresentationOf(returnedAdapter);
+            return responseOfOk(jsonRepresentationOf(returnedAdapter));
         }
     }
 
@@ -470,7 +468,7 @@ public class DomainObjectResourceImpl ex
             byte[] byteArray = ByteStreams.toByteArray(body);
             String bodyAsString = new String(byteArray, Charsets.UTF_8);
 
-            List<?> arguments = objectMapper.readValue(bodyAsString, ArrayList.class);
+            List<?> arguments = jsonMapper.readAsList(bodyAsString);
             return arguments;
         } catch (JsonParseException e) {
             throw new WebApplicationException(e,

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/objects/MemberRepType.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/objects/MemberRepType.java?rev=1149403&r1=1149402&r2=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/objects/MemberRepType.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/objects/MemberRepType.java Thu Jul 21 23:16:31 2011
@@ -17,7 +17,7 @@
 package org.apache.isis.viewer.json.viewer.resources.objects;
 
 import org.apache.isis.core.metamodel.spec.feature.ObjectMember;
-import org.apache.isis.viewer.json.applib.resources.DomainObjectResource;
+import org.apache.isis.viewer.json.applib.domain.DomainObjectResource;
 
 /**
  * Whether the representation of an {@link ObjectMember} (as generated by

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/services/ServicesResourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/services/ServicesResourceImpl.java?rev=1149403&r1=1149402&r2=1149403&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/services/ServicesResourceImpl.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/services/ServicesResourceImpl.java Thu Jul 21 23:16:31 2011
@@ -23,18 +23,11 @@ import java.util.List;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
 
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.viewer.json.applib.resources.ServicesResource;
-import org.apache.isis.viewer.json.viewer.RepContext;
-import org.apache.isis.viewer.json.viewer.representations.Representation;
+import org.apache.isis.viewer.json.applib.domain.ServicesResource;
 import org.apache.isis.viewer.json.viewer.resources.ResourceAbstract;
-import org.apache.isis.viewer.json.viewer.resources.objects.DomainObjectRepBuilder;
-
-import com.google.common.base.Function;
-import com.google.common.base.Functions;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Lists;
 
 /**
  * Implementation note: it seems to be necessary to annotate the implementation with {@link Path} rather than the
@@ -45,12 +38,11 @@ public class ServicesResourceImpl extend
 
     @Override
     @Produces({ MediaType.APPLICATION_JSON })
-    public String services() {
+    public Response services() {
         init();
 
         final List<ObjectAdapter> serviceAdapters = getPersistenceSession().getServices();
-		return jsonRepresentationOf(serviceAdapters);
+		return responseOfOk(jsonRepresentationOf(serviceAdapters));
     }
 
-
 }



Mime
View raw message