Changeset 829
- Timestamp:
- 2008-11-26 09:35:34 (5 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 1 deleted
- 18 edited
- 1 moved
-
core/kauri-runtime-rapi/src/main/java/org/kauriproject/runtime/rapi/KauriModule.java (modified) (3 diffs)
-
core/kauri-runtime-testfw/src/main/java/org/kauriproject/runtime/testfw/AbstractRuntimeTest.java (modified) (2 diffs)
-
core/kauri-runtime-tests/src/test/java/org/kauriproject/runtime/test/ServiceProtocolToPublicTest.java (modified) (2 diffs)
-
core/kauri-runtime/src/main/java/org/kauriproject/runtime/module/restservice/RestserviceFacet.java (modified) (2 diffs)
-
core/kauri-runtime/src/main/java/org/kauriproject/runtime/module/restservice/RestserviceManager.java (modified) (2 diffs)
-
core/kauri-runtime/src/main/java/org/kauriproject/runtime/rapi_impl/KauriModuleImpl.java (modified) (3 diffs)
-
modules/kauri-representation/kauri-representationbuilder-impl/src/test/java/org/kauriproject/representation/test/BuilderTest.java (modified) (2 diffs)
-
modules/kauri-template/kauri-template-service-api/src/main/java/org/kauriproject/template/service/TemplateService.java (modified) (1 diff)
-
modules/kauri-template/kauri-template-service-impl/pom.xml (modified) (1 diff)
-
modules/kauri-template/kauri-template-service-impl/src/main/java/org/kauriproject/template/service/impl/KauriFunctions.java (modified) (3 diffs)
-
modules/kauri-template/kauri-template-service-impl/src/main/java/org/kauriproject/template/service/impl/KauriHelper.java (deleted)
-
modules/kauri-template/kauri-template-service-impl/src/main/java/org/kauriproject/template/service/impl/TemplateRepresentation.java (modified) (3 diffs)
-
modules/kauri-template/kauri-template-service-impl/src/main/java/org/kauriproject/template/service/impl/TemplateServiceImpl.java (modified) (4 diffs)
-
modules/kauri-template/kauri-template-service-impl/src/test/java/org/kauriproject/template/service/test/TemplateServiceHostIdentifierTest.java (added)
-
modules/kauri-template/kauri-template-service-impl/src/test/java/org/kauriproject/template/service/test/TemplateServiceTest.java (modified) (1 diff)
-
modules/kauri-template/kauri-template-service-impl/src/test/java/org/kauriproject/template/service/test/testmodules/common (moved) (moved from trunk/modules/kauri-template/kauri-template-service-impl/src/test/java/org/kauriproject/template/service/test/testmodules/template1)
-
modules/kauri-template/kauri-template-service-impl/src/test/java/org/kauriproject/template/service/test/testmodules/common/Templates.java (modified) (1 diff)
-
modules/kauri-template/kauri-template-service-impl/src/test/modulesrc/org/kauriproject/template/service/test/testmodules/template1/KAURI-INF/spring/services.xml (modified) (2 diffs)
-
modules/kauri-template/kauri-template-service-impl/src/test/modulesrc/org/kauriproject/template/service/test/testmodules/template3/KAURI-INF/spring/services.xml (modified) (2 diffs)
-
universe/kauri-template/src/main/java/org/kauriproject/template/DefaultTemplateExecutor.java (modified) (1 diff)
-
universe/kauri-template/src/main/java/org/kauriproject/template/ExecutionContext.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/kauri-runtime-rapi/src/main/java/org/kauriproject/runtime/rapi/KauriModule.java
r808 r829 1 1 package org.kauriproject.runtime.rapi; 2 2 3 import org.restlet.data.Reference;4 3 import org.restlet.data.Response; 5 4 import org.restlet.data.Request; … … 14 13 * <p>Other URIs can be passed as well, these will be returned unmodified. 15 14 * 16 * <p>The public URI will be made relative to the specified "host Ref". Usually17 * this host Refshould be the one from the original HTTP request. Note that the15 * <p>The public URI will be made relative to the specified "hostIdentifier". Usually 16 * this hostIdentifier should be the one from the original HTTP request. Note that the 18 17 * relativiziation only applies to dropping the scheme and authority parts, the 19 18 * path part will always stay absolute. 20 19 */ 21 String publicUri(String serviceProtocolUri, Reference hostRef);20 String publicUri(String serviceProtocolUri, String hostIdentifier); 22 21 23 22 ModuleSource getSource(); … … 54 53 */ 55 54 KauriModule getOriginatingModule(String uri); 55 56 Request getCurrentExternalRequest(); 56 57 } -
trunk/core/kauri-runtime-testfw/src/main/java/org/kauriproject/runtime/testfw/AbstractRuntimeTest.java
r671 r829 18 18 import org.kauriproject.runtime.repository.RepoArtifactRef; 19 19 import org.kauriproject.runtime.repository.ResolvedArtifact; 20 import org.apache.log4j.ConsoleAppender; 21 import org.apache.log4j.PatternLayout; 22 import org.apache.log4j.Logger; 23 import org.apache.log4j.Level; 20 24 21 25 public abstract class AbstractRuntimeTest extends TestCase { … … 134 138 } 135 139 140 protected void setUpLogging() { 141 // TODO might be useful to introduce similar options like for the Runtime CLI 142 // to easily enable more logging for certain categories (could be passed 143 // as system properties, via -D) 144 String appenderName = "abstract-runtime-test-console-appender"; 145 Logger logger = Logger.getRootLogger(); 146 if (logger.getAppender(appenderName) == null) { 147 ConsoleAppender consoleAppender = new ConsoleAppender(); 148 consoleAppender.setName(appenderName); 149 consoleAppender.setLayout(new PatternLayout("[%t] %-5p %c - %m%n")); 150 consoleAppender.activateOptions(); 151 152 logger.setLevel(Level.WARN); 153 logger.addAppender(consoleAppender); 154 } 155 } 156 136 157 protected void setUp() throws Exception { 158 setUpLogging(); 159 137 160 KauriRuntimeConfig config = getRuntimeConfig(); 138 161 if (config != null) { -
trunk/core/kauri-runtime-tests/src/test/java/org/kauriproject/runtime/test/ServiceProtocolToPublicTest.java
r748 r829 50 50 RestserviceFacet rsf = runtime.getModuleById("sptopublic1").getRestserviceFacet(); 51 51 52 assertEquals("/public1", rsf.getPublicPath("service:/dummy", hostRef ));53 assertEquals("/public1/boe/bie/ba.txt", rsf.getPublicPath("service:/dummy/boe/bie/ba.txt", hostRef ));54 assertEquals("file:///tmp", rsf.getPublicPath("service:/dummy2", hostRef ));55 assertEquals("file:///tmp/yes/no", rsf.getPublicPath("service:/dummy2/yes/no", hostRef ));56 assertEquals("/public2/yes/no", rsf.getPublicPath("service:/dummy3/yes/no", hostRef ));52 assertEquals("/public1", rsf.getPublicPath("service:/dummy", hostRef.getHostIdentifier())); 53 assertEquals("/public1/boe/bie/ba.txt", rsf.getPublicPath("service:/dummy/boe/bie/ba.txt", hostRef.getHostIdentifier())); 54 assertEquals("file:///tmp", rsf.getPublicPath("service:/dummy2", hostRef.getHostIdentifier())); 55 assertEquals("file:///tmp/yes/no", rsf.getPublicPath("service:/dummy2/yes/no", hostRef.getHostIdentifier())); 56 assertEquals("/public2/yes/no", rsf.getPublicPath("service:/dummy3/yes/no", hostRef.getHostIdentifier())); 57 57 } 58 58 59 59 { 60 60 RestserviceFacet rsf = runtime.getModuleById("sptopublic2").getRestserviceFacet(); 61 assertEquals("/public2", rsf.getPublicPath("service:/dummy", hostRef ));61 assertEquals("/public2", rsf.getPublicPath("service:/dummy", hostRef.getHostIdentifier())); 62 62 } 63 63 … … 91 91 92 92 // host is same as hostref, host should not be part of result 93 assertEquals("/public1", rsf.getPublicPath("service:/dummy", hostRef ));93 assertEquals("/public1", rsf.getPublicPath("service:/dummy", hostRef.getHostIdentifier())); 94 94 95 95 // host is different, host should be part of result 96 assertEquals("http://otherhost:8888/public2/yes/no", rsf.getPublicPath("service:/dummy3/yes/no", hostRef ));96 assertEquals("http://otherhost:8888/public2/yes/no", rsf.getPublicPath("service:/dummy3/yes/no", hostRef.getHostIdentifier())); 97 97 } 98 98 99 99 { 100 100 RestserviceFacet rsf = runtime.getModuleById("sptopublic2").getRestserviceFacet(); 101 assertEquals("http://otherhost:8888/public2", rsf.getPublicPath("service:/dummy", hostRef ));101 assertEquals("http://otherhost:8888/public2", rsf.getPublicPath("service:/dummy", hostRef.getHostIdentifier())); 102 102 } 103 103 -
trunk/core/kauri-runtime/src/main/java/org/kauriproject/runtime/module/restservice/RestserviceFacet.java
r808 r829 137 137 } 138 138 139 public String getPublicPath(String uri, Reference hostRef) {139 public String getPublicPath(String uri, String hostIdentifier) { 140 140 Matcher matcher = Constants.SERVICE_PROTOCOL_URI_PATTERN.matcher(uri); 141 141 if (!matcher.matches()) { … … 190 190 191 191 192 if (!pathIsAbsolute ) {192 if (!pathIsAbsolute && hostIdentifier != null) { 193 193 VirtualHostDefinitions vhds = restserviceManager.getRuntime().getConfig().getVirtualHosts(); 194 194 VirtualHostDefinition vhd = virtualHostName != null ? vhds.get(virtualHostName) : vhds.getDefault(); 195 195 String canonicalUri = vhd.getCanonicalUri(); 196 196 197 if (!canonicalUri.equals(host Ref.getHostIdentifier())) {197 if (!canonicalUri.equals(hostIdentifier)) { 198 198 mountPath = canonicalUri + mountPath; 199 199 } -
trunk/core/kauri-runtime/src/main/java/org/kauriproject/runtime/module/restservice/RestserviceManager.java
r803 r829 4 4 import org.restlet.service.MetadataService; 5 5 import org.restlet.data.Protocol; 6 import org.restlet.data.Request; 7 import org.restlet.data.Response; 6 8 import org.kauriproject.runtime.KauriRTException; 7 9 import org.kauriproject.runtime.KauriRuntime; … … 22 24 public static final Protocol MODULE_PROTOCOL = new Protocol("module", "MODULE", "Kauri module protocol", -1); 23 25 26 /** 27 * Holds the current request that arrived via a connector (if any). This will be different 28 * from the current request, when internal requests are performed. 29 */ 30 public static ThreadLocal<Request> CURRENT_EXTERNAL_REQUEST = new ThreadLocal<Request>(); 31 24 32 public RestserviceManager(KauriRuntime runtime) { 25 component = new Component();33 component = new MyComponent(); 26 34 this.runtime = runtime; 27 35 this.metadataService = new KauriMetadataService(); 36 } 37 38 private static class MyComponent extends Component { 39 @Override 40 public void handle(Request request, Response response) { 41 CURRENT_EXTERNAL_REQUEST.set(request); 42 try { 43 super.handle(request, response); 44 } finally { 45 CURRENT_EXTERNAL_REQUEST.set(null); 46 } 47 } 28 48 } 29 49 -
trunk/core/kauri-runtime/src/main/java/org/kauriproject/runtime/rapi_impl/KauriModuleImpl.java
r808 r829 7 7 import org.kauriproject.runtime.module.Module; 8 8 import org.kauriproject.runtime.module.restservice.RestserviceRegistryEntry; 9 import org.kauriproject.runtime.module.restservice.RestserviceManager; 9 10 import org.kauriproject.runtime.KauriRuntime; 10 11 import org.kauriproject.runtime.Constants; … … 28 29 } 29 30 30 public String publicUri(String serviceProtocolUri, Reference hostRef) {31 return module.getRestserviceFacet().getPublicPath(serviceProtocolUri, host Ref);31 public String publicUri(String serviceProtocolUri, String hostIdentifier) { 32 return module.getRestserviceFacet().getPublicPath(serviceProtocolUri, hostIdentifier); 32 33 } 33 34 … … 94 95 return null; 95 96 } 97 98 public Request getCurrentExternalRequest() { 99 return RestserviceManager.CURRENT_EXTERNAL_REQUEST.get(); 100 } 96 101 } -
trunk/modules/kauri-representation/kauri-representationbuilder-impl/src/test/java/org/kauriproject/representation/test/BuilderTest.java
r808 r829 21 21 // Mocked KauriModule implementation 22 22 KauriModule kauriModule = new KauriModule() { 23 public String publicUri(String serviceProtocolUri, ReferencehostRef) {23 public String publicUri(String serviceProtocolUri, String hostRef) { 24 24 return null; 25 25 } … … 64 64 65 65 public KauriModule getOriginatingModule(String uri) { 66 return null; 67 } 68 69 public Request getCurrentExternalRequest() { 66 70 return null; 67 71 } -
trunk/modules/kauri-template/kauri-template-service-api/src/main/java/org/kauriproject/template/service/TemplateService.java
r651 r829 38 38 OutputStream outputStream, MediaType mediaType, Map<String, Object> parameters) throws Exception; 39 39 40 public void generateTemplate(String templateLocation, Context restletContext, Request request, 41 OutputStream outputStream, MediaType mediaType, Map<String, Object> parameters, 42 Map<String, Object> executionAttributes) throws Exception; 43 40 44 public Representation getTemplateRepresentation(final MediaType mediaType, final Context restletContext, 41 45 Request request, final String templateLocation, final Map<String, Object> parameters); 46 47 public Representation getTemplateRepresentation(final MediaType mediaType, final Context restletContext, 48 Request request, final String templateLocation, final Map<String, Object> parameters, 49 Map<String, Object> executionAttributes); 42 50 } -
trunk/modules/kauri-template/kauri-template-service-impl/pom.xml
r656 r829 49 49 <groupId>org.kauriproject</groupId> 50 50 <artifactId>kauri-runtime-testfw</artifactId> 51 <scope>test</scope> 51 52 </dependency> 52 53 </dependencies> -
trunk/modules/kauri-template/kauri-template-service-impl/src/main/java/org/kauriproject/template/service/impl/KauriFunctions.java
r808 r829 18 18 import org.kauriproject.runtime.rapi.KauriModule; 19 19 import org.kauriproject.template.source.SourceResolver; 20 import org.kauriproject.template.ExecutionContext; 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 20 23 21 24 /** … … 24 27 */ 25 28 public class KauriFunctions { 26 27 29 public static String publicUri(String serviceProtocolUri) { 28 30 String uriString; … … 34 36 35 37 KauriModule kauriModule = sc.getKauriModule(); 36 uriString = kauriModule.publicUri(serviceProtocolUri, KauriHelper.getRequest().getHostRef()); 38 String hostIdentifier = (String)ExecutionContext.CURRENT.get().getAttributes().get("hostIdentifier"); 39 System.out.println("================================================= hostIdentifier = " + hostIdentifier); 40 uriString = kauriModule.publicUri(serviceProtocolUri, hostIdentifier); 37 41 } catch (Exception ex) { 38 // TODO: log error 42 Log log = LogFactory.getLog(KauriFunctions.class); 43 log.error("Could not determine public URI for " + serviceProtocolUri, ex); 39 44 uriString = "NOT_FOUND"; 40 45 } -
trunk/modules/kauri-template/kauri-template-service-impl/src/main/java/org/kauriproject/template/service/impl/TemplateRepresentation.java
r278 r829 36 36 private String templateLocation; 37 37 private Map<String, Object> parameters; 38 39 public TemplateRepresentation(final Context restletContext, final Request request, 40 final TemplateService templateService, final String templateLocation, 41 final Map<String, Object> parameters) { 42 this(MediaType.APPLICATION_XML, restletContext, request, templateService, templateLocation, 43 parameters); 44 } 38 private Map<String, Object> executionAttributes; 45 39 46 40 public TemplateRepresentation(final MediaType mediaType, final Context restletContext, 47 41 final Request request, final TemplateService templateService, final String templateLocation, 48 final Map<String, Object> parameters ) {42 final Map<String, Object> parameters, Map<String, Object> executionAttributes) { 49 43 super(mediaType); 50 44 this.restletContext = restletContext; … … 53 47 this.templateLocation = templateLocation; 54 48 this.parameters = parameters; 49 this.executionAttributes = executionAttributes; 55 50 } 56 51 … … 59 54 try { 60 55 templateService.generateTemplate(templateLocation, restletContext, request, outputStream, 61 getMediaType(), parameters );56 getMediaType(), parameters, executionAttributes); 62 57 } catch (Exception ex) { 63 58 throw new RuntimeException("Template processing error.", ex); -
trunk/modules/kauri-template/kauri-template-service-impl/src/main/java/org/kauriproject/template/service/impl/TemplateServiceImpl.java
r808 r829 19 19 import java.io.OutputStream; 20 20 import java.util.Map; 21 import java.util.HashMap; 21 22 22 23 import org.kauriproject.template.TemplateResultImpl; … … 66 67 public void generateTemplate(String templateLocation, Context restletContext, Request request, 67 68 OutputStream outputStream, MediaType mediaType, Map<String, Object> parameters) throws Exception { 68 // update kaurihelper with request info 69 KauriHelper.init(restletContext, request); 69 generateTemplate(templateLocation, restletContext, request, outputStream, mediaType, parameters, null); 70 } 71 72 public void generateTemplate(String templateLocation, Context restletContext, Request request, 73 OutputStream outputStream, MediaType mediaType, Map<String, Object> parameters, 74 Map<String, Object> executionAttributes) throws Exception { 70 75 // construct executioncontext 71 76 SourceResolver sourceResolver = new KauriSourceResolver((KauriModule)restletContext.getAttributes().get("org.kauriproject.runtime.rapi.KauriModule")); … … 77 82 templateContext.putAll(parameters); 78 83 } 84 79 85 ExecutionContext executionContext = delegate.createContext(sourceResolver, templateContext, 80 86 functionRegistry); 87 88 if (executionAttributes == null) { 89 KauriModule kauriModule = (KauriModule)restletContext.getAttributes().get("org.kauriproject.runtime.rapi.KauriModule"); 90 executionAttributes = getDefaultExecutionAttributes(kauriModule); 91 } 92 93 executionContext.getAttributes().putAll(executionAttributes); 94 81 95 // ask delegate to generate template 82 96 delegate.generateTemplate(templateLocation, executionContext, templateResult); … … 97 111 public Representation getTemplateRepresentation(final MediaType mediaType, final Context restletContext, 98 112 final Request request, final String templateLocation, final Map<String, Object> parameters) { 113 return getTemplateRepresentation(mediaType, restletContext, request, templateLocation, 114 parameters, null); 115 } 116 117 public Representation getTemplateRepresentation(MediaType mediaType, Context restletContext, Request request, String templateLocation, Map<String, Object> parameters, Map<String, Object> executionAttributes) { 118 if (executionAttributes == null) { 119 KauriModule kauriModule = (KauriModule)restletContext.getAttributes().get("org.kauriproject.runtime.rapi.KauriModule"); 120 executionAttributes = getDefaultExecutionAttributes(kauriModule); 121 } 122 99 123 return new TemplateRepresentation(mediaType, restletContext, request, this, templateLocation, 100 parameters); 124 parameters, executionAttributes); 125 } 126 127 public Map<String, Object> getDefaultExecutionAttributes(KauriModule kauriModule) { 128 String hostIdentifier = null; 129 System.out.println("kauriModule.getCurrentExternalRequest() = " + kauriModule.getCurrentExternalRequest() + " thread " + Thread.currentThread()); 130 if (kauriModule.getCurrentExternalRequest() != null) { 131 hostIdentifier = kauriModule.getCurrentExternalRequest().getHostRef().toString(); 132 } 133 134 Map<String, Object> attrs = new HashMap<String, Object>(); 135 attrs.put("hostIdentifier", hostIdentifier); 136 137 return attrs; 101 138 } 102 139 } -
trunk/modules/kauri-template/kauri-template-service-impl/src/test/java/org/kauriproject/template/service/test/TemplateServiceTest.java
r808 r829 47 47 File moduleDir = createModule("org.kauriproject.template.service.test.testmodules.template1"); 48 48 ModuleDefinition module = new ModuleDefinition("template1", moduleDir, ModuleSourceType.EXPANDED_JAR); 49 module.addMount(new MountDefinition(" templates", "/templates", null, true));49 module.addMount(new MountDefinition("executedtemplates", "/templates", null, true)); 50 50 module.addMount(new MountDefinition("A", "/A1", null, true)); 51 51 module.addInject(new RestserviceInjectDefinition("templates2", "template2", "templates")); -
trunk/modules/kauri-template/kauri-template-service-impl/src/test/java/org/kauriproject/template/service/test/testmodules/common/Templates.java
r808 r829 1 package org.kauriproject.template.service.test.testmodules. template1;1 package org.kauriproject.template.service.test.testmodules.common; 2 2 3 3 import org.restlet.Restlet; -
trunk/modules/kauri-template/kauri-template-service-impl/src/test/modulesrc/org/kauriproject/template/service/test/testmodules/template1/KAURI-INF/spring/services.xml
r808 r829 20 20 21 21 <kauri:export-restservice ref="A"/> 22 <kauri:export-restservice ref=" templates"/>22 <kauri:export-restservice ref="executedtemplates"/> 23 23 24 24 <bean id="A" class="org.restlet.Directory"> … … 27 27 </bean> 28 28 29 <bean id=" templates" class="org.kauriproject.template.service.test.testmodules.template1.Templates">29 <bean id="executedtemplates" class="org.kauriproject.template.service.test.testmodules.common.Templates"> 30 30 <constructor-arg ref="templateService"/> 31 31 <constructor-arg ref="restletContext"/> -
trunk/modules/kauri-template/kauri-template-service-impl/src/test/modulesrc/org/kauriproject/template/service/test/testmodules/template3/KAURI-INF/spring/services.xml
r808 r829 19 19 <kauri:export-restservice ref="A"/> 20 20 <kauri:export-restservice ref="templates"/> 21 <kauri:export-restservice ref="executedtemplates"/> 21 22 22 23 <bean id="A" class="org.restlet.Directory"> … … 30 31 </bean> 31 32 33 <bean id="executedtemplates" class="org.kauriproject.template.service.test.testmodules.common.Templates"> 34 <constructor-arg ref="templateService"/> 35 <constructor-arg ref="restletContext"/> 36 </bean> 32 37 </beans> -
trunk/universe/kauri-template/src/main/java/org/kauriproject/template/DefaultTemplateExecutor.java
r816 r829 24 24 25 25 public void execute(Step startStep, Step endStep, ExecutionContext context, TemplateResult result) throws SAXException { 26 if (context.getExecutor() == null) {27 context.setExecutor(this);28 }26 ExecutionContext oldCurrentContext = ExecutionContext.CURRENT.get(); 27 try { 28 ExecutionContext.CURRENT.set(context); 29 29 30 Step currentStep = startStep; 31 while (currentStep != endStep) { 32 currentStep = currentStep.executeAndProceed(context, result); 30 if (context.getExecutor() == null) { 31 context.setExecutor(this); 32 } 33 34 Step currentStep = startStep; 35 while (currentStep != endStep) { 36 currentStep = currentStep.executeAndProceed(context, result); 37 } 38 } finally { 39 ExecutionContext.CURRENT.set(oldCurrentContext); 33 40 } 34 41 } -
trunk/universe/kauri-template/src/main/java/org/kauriproject/template/ExecutionContext.java
r822 r829 29 29 */ 30 30 public class ExecutionContext { 31 public static ThreadLocal<ExecutionContext> CURRENT = new ThreadLocal<ExecutionContext>(); 31 32 32 33 private SourceResolver sourceResolver; … … 36 37 private FunctionRegistry functionRegistry; 37 38 private TemplateExecutor executor; 39 private Map<String, Object> attributes = new HashMap<String, Object>(); 38 40 39 41 private Map<String, MacroBlock> macroRegistry; … … 140 142 } 141 143 144 /** 145 * A free set of attributes. This is intended for template users to make 146 * non-predefined data available for during execution, e.g. for use 147 * by custom expression language functions. This map should not be 148 * modified during template execution. 149 */ 150 public Map<String, Object> getAttributes() { 151 return attributes; 152 } 153 142 154 public List<ExtendBlock> getExtendList() { 143 155 return extendList;
Note: See TracChangeset
for help on using the changeset viewer.