org.springframework.extensions.webscripts
Class TestWebScriptServer

java.lang.Object
  extended by org.springframework.extensions.webscripts.TestWebScriptServer
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware

public class TestWebScriptServer
extends Object
implements org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.InitializingBean

Stand-alone Web Script Test Server

Author:
davidc

Nested Class Summary
static class TestWebScriptServer.DeleteRequest
          Test DELETE Request
static class TestWebScriptServer.GetRequest
          Test GET Request
static class TestWebScriptServer.MockHttpServletResponseResponse
          Test Response wrapping a MockHttpServletResponse
static class TestWebScriptServer.PatchRequest
          Test PATCH Request
static class TestWebScriptServer.PostRequest
          Test POST Request
static class TestWebScriptServer.PutRequest
          Test PUT Request
static class TestWebScriptServer.Request
          A Web Script Test Request
static interface TestWebScriptServer.Response
          A Web Script Test Response
 
Field Summary
protected  org.springframework.context.ApplicationContext applicationContext
          The application context
protected  ServletAuthenticatorFactory authenticatorFactory
           
protected  ConfigService configService
           
protected  RuntimeContainer container
           
protected  BufferedReader fIn
          The reader for interaction.
protected  Map<String,String> headers
          Current headers
protected  String lastCommand
          Last command issued
protected  org.springframework.context.MessageSource m_messages
          I18N Messages
protected  ServerProperties serverProperties
          Server Configuration
protected  String username
          Current user
 
Constructor Summary
TestWebScriptServer()
           
 
Method Summary
 void afterPropertiesSet()
           
protected  String executeCommand(String line)
          Execute a single command using the BufferedReader passed in for any data needed.
 org.springframework.context.ApplicationContext getApplicationContext()
          Gets the application context
protected  String getDefaultUserName()
          Get default user name
 ServerProperties getServerProperties()
          Gets the server properties
static TestWebScriptServer getTestServer()
          Retrieve an instance of the TestWebScriptServer
protected  String interpretCommand(String line)
          Interpret a single command using the BufferedReader passed in for any data needed.
static void main(String[] args)
          Main entry point.
 void rep()
          A Read-Eval-Print loop.
 void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
          Sets the application context
 void setConfigService(ConfigService configService)
           
 void setContainer(RuntimeContainer container)
          Sets the Web Script Runtime Context
 void setMessages(org.springframework.context.MessageSource messages)
          Sets the Messages resource bundle
 void setServletAuthenticatorFactory(ServletAuthenticatorFactory authenticatorFactory)
           
 TestWebScriptServer.Response submitRequest(String method, String uri, Map<String,String> headers, byte[] body, String encoding, String contentType)
          Submit a Web Script Request.
 TestWebScriptServer.Response submitRequest(TestWebScriptServer.Request req)
          Submit a Web Script Request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

applicationContext

protected org.springframework.context.ApplicationContext applicationContext
The application context


configService

protected ConfigService configService

container

protected RuntimeContainer container

authenticatorFactory

protected ServletAuthenticatorFactory authenticatorFactory

serverProperties

protected ServerProperties serverProperties
Server Configuration


fIn

protected BufferedReader fIn
The reader for interaction.


lastCommand

protected String lastCommand
Last command issued


username

protected String username
Current user


headers

protected Map<String,String> headers
Current headers


m_messages

protected org.springframework.context.MessageSource m_messages
I18N Messages

Constructor Detail

TestWebScriptServer

public TestWebScriptServer()
Method Detail

setConfigService

public void setConfigService(ConfigService configService)
Parameters:
configService -

setContainer

public void setContainer(RuntimeContainer container)
Sets the Web Script Runtime Context

Parameters:
container -

setServletAuthenticatorFactory

public void setServletAuthenticatorFactory(ServletAuthenticatorFactory authenticatorFactory)
Parameters:
authenticatoFactory -

setMessages

public void setMessages(org.springframework.context.MessageSource messages)
                 throws IOException
Sets the Messages resource bundle

Parameters:
messages -
Throws:
IOException

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
                           throws org.springframework.beans.BeansException
Sets the application context

Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware
Parameters:
applicationContext - the application context
Throws:
org.springframework.beans.BeansException

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
Exception

getDefaultUserName

protected String getDefaultUserName()
Get default user name


getServerProperties

public ServerProperties getServerProperties()
Gets the server properties

Returns:
server properties
Throws:
Exception

getApplicationContext

public org.springframework.context.ApplicationContext getApplicationContext()
Gets the application context

Returns:
ApplicationContext the application context

main

public static void main(String[] args)
Main entry point.


getTestServer

public static TestWebScriptServer getTestServer()
Retrieve an instance of the TestWebScriptServer

Returns:
Test Server

submitRequest

public TestWebScriptServer.Response submitRequest(TestWebScriptServer.Request req)
                                           throws IOException
Submit a Web Script Request.

Parameters:
req - request
Returns:
response
Throws:
IOException

submitRequest

public TestWebScriptServer.Response submitRequest(String method,
                                                  String uri,
                                                  Map<String,String> headers,
                                                  byte[] body,
                                                  String encoding,
                                                  String contentType)
                                           throws IOException
Submit a Web Script Request.

Can specifiy content and content type

Parameters:
method - http method
uri - web script (relative to /alfresco/service)
headers - headers
body - body of request content (can be null)
contentType - content type (eg "multipart/form-data") (can be null)
Returns:
response
Throws:
IOException

rep

public void rep()
A Read-Eval-Print loop.


interpretCommand

protected String interpretCommand(String line)
                           throws IOException
Interpret a single command using the BufferedReader passed in for any data needed.

Parameters:
line - The unparsed command
Returns:
The textual output of the command.
Throws:
IOException

executeCommand

protected String executeCommand(String line)
                         throws IOException
Execute a single command using the BufferedReader passed in for any data needed. TODO: Use decent parser!

Parameters:
line - The unparsed command
Returns:
The textual output of the command.
Throws:
IOException


Copyright © 2009 SpringSource, Inc. All Rights Reserved.