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 java.lang.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  org.springframework.extensions.webscripts.servlet.ServletAuthenticatorFactory authenticatorFactory
           
protected  org.springframework.extensions.config.ConfigService configService
           
protected  org.springframework.extensions.webscripts.RuntimeContainer container
           
protected  java.io.BufferedReader fIn
          The reader for interaction.
protected  java.util.Map<java.lang.String,java.lang.String> headers
          Current headers
protected  java.lang.String lastCommand
          Last command issued
protected  org.springframework.context.MessageSource m_messages
          I18N Messages
protected  org.springframework.extensions.config.ServerProperties serverProperties
          Server Configuration
protected  java.lang.String username
          Current user
 
Constructor Summary
TestWebScriptServer()
           
 
Method Summary
 void afterPropertiesSet()
           
protected  java.lang.String executeCommand(java.lang.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  java.lang.String getDefaultUserName()
          Get default user name
 org.springframework.extensions.config.ServerProperties getServerProperties()
          Gets the server properties
static TestWebScriptServer getTestServer()
          Retrieve an instance of the TestWebScriptServer
protected  java.lang.String interpretCommand(java.lang.String line)
          Interpret a single command using the BufferedReader passed in for any data needed.
static void main(java.lang.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(org.springframework.extensions.config.ConfigService configService)
           
 void setContainer(org.springframework.extensions.webscripts.RuntimeContainer container)
          Sets the Web Script Runtime Context
 void setMessages(org.springframework.context.MessageSource messages)
          Sets the Messages resource bundle
 void setServletAuthenticatorFactory(org.springframework.extensions.webscripts.servlet.ServletAuthenticatorFactory authenticatorFactory)
           
 TestWebScriptServer.Response submitRequest(java.lang.String method, java.lang.String uri, java.util.Map<java.lang.String,java.lang.String> headers, byte[] body, java.lang.String encoding, java.lang.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 org.springframework.extensions.config.ConfigService configService

container

protected org.springframework.extensions.webscripts.RuntimeContainer container

authenticatorFactory

protected org.springframework.extensions.webscripts.servlet.ServletAuthenticatorFactory authenticatorFactory

serverProperties

protected org.springframework.extensions.config.ServerProperties serverProperties
Server Configuration


fIn

protected java.io.BufferedReader fIn
The reader for interaction.


lastCommand

protected java.lang.String lastCommand
Last command issued


username

protected java.lang.String username
Current user


headers

protected java.util.Map<java.lang.String,java.lang.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(org.springframework.extensions.config.ConfigService configService)
Parameters:
configService -

setContainer

public void setContainer(org.springframework.extensions.webscripts.RuntimeContainer container)
Sets the Web Script Runtime Context

Parameters:
container -

setServletAuthenticatorFactory

public void setServletAuthenticatorFactory(org.springframework.extensions.webscripts.servlet.ServletAuthenticatorFactory authenticatorFactory)
Parameters:
authenticatoFactory -

setMessages

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

Parameters:
messages -
Throws:
java.io.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 java.lang.Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.lang.Exception

getDefaultUserName

protected java.lang.String getDefaultUserName()
Get default user name


getServerProperties

public org.springframework.extensions.config.ServerProperties getServerProperties()
Gets the server properties

Returns:
server properties
Throws:
java.lang.Exception

getApplicationContext

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

Returns:
ApplicationContext the application context

main

public static void main(java.lang.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 java.io.IOException
Submit a Web Script Request.

Parameters:
req - request
Returns:
response
Throws:
java.io.IOException

submitRequest

public TestWebScriptServer.Response submitRequest(java.lang.String method,
                                                  java.lang.String uri,
                                                  java.util.Map<java.lang.String,java.lang.String> headers,
                                                  byte[] body,
                                                  java.lang.String encoding,
                                                  java.lang.String contentType)
                                           throws java.io.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:
java.io.IOException

rep

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


interpretCommand

protected java.lang.String interpretCommand(java.lang.String line)
                                     throws java.io.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:
java.io.IOException

executeCommand

protected java.lang.String executeCommand(java.lang.String line)
                                   throws java.io.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:
java.io.IOException


Copyright © 2009-2011 SpringSource, Inc. All Rights Reserved.