Skip to content

Commit

Permalink
references #26 -additional http methods -webscript descriptors unique…
Browse files Browse the repository at this point in the history
… per http method
  • Loading branch information
dgradecak committed Jun 13, 2024
1 parent cfbe1d1 commit 50ad2dc
Show file tree
Hide file tree
Showing 17 changed files with 219 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
public @interface AlfrescoDispatcherWebscript {
String name() default "alfresco-mvc.mvc";

RequestMethod[] httpMethods() default { RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE, RequestMethod.PUT };
RequestMethod[] httpMethods() default { RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE,
RequestMethod.PUT, RequestMethod.HEAD, RequestMethod.PATCH, RequestMethod.OPTIONS, RequestMethod.TRACE };

Class<?> servletContext();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@

package com.gradecak.alfresco.mvc.rest.config;

import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;

import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
Expand All @@ -33,11 +40,12 @@
import com.gradecak.alfresco.mvc.rest.annotation.AlfrescoDispatcherWebscript;
import com.gradecak.alfresco.mvc.rest.annotation.EnableAlfrescoMvcRest;
import com.gradecak.alfresco.mvc.webscript.DispatcherWebscript;
import com.gradecak.alfresco.mvc.webscript.DispatcherWebscript.DispatcherWebscriptServlet;
import com.gradecak.alfresco.mvc.webscript.DispatcherWebscript.ServletConfigOptions;

public class AlfrescoRestRegistrar implements ImportBeanDefinitionRegistrar {
import jakarta.servlet.ServletContext;

private AnnotationAttributes attributes;
public class AlfrescoRestRegistrar implements ImportBeanDefinitionRegistrar {

public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {

Expand All @@ -56,12 +64,9 @@ public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanD
.toArray(new AnnotationAttributes[0]));
}

this.attributes = new AnnotationAttributes(annotationAttributes);

} else {
this.attributes = new AnnotationAttributes(annotationAttributes);
}

AnnotationAttributes attributes = new AnnotationAttributes(annotationAttributes);
AnnotationAttributes[] dispatcherWebscripts = (AnnotationAttributes[]) attributes.get("value");

for (AnnotationAttributes dispatcherWebscript : dispatcherWebscripts) {
Expand All @@ -83,20 +88,47 @@ private void processDispatcherWebscript(AnnotationAttributes webscriptAttributes
RequestMethod[] httpRequestMethods = (RequestMethod[]) webscriptAttributes.get("httpMethods");
boolean inheritGlobalProperties = (Boolean) webscriptAttributes.get("inheritGlobalProperties");

GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
beanDefinition.setBeanClass(DispatcherWebscript.class);
GenericBeanDefinition dispatcherWebscriptServletDefinition = new GenericBeanDefinition();
dispatcherWebscriptServletDefinition.setBeanClass(DispatcherWebscriptServlet.class);
ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues();
//constructorArgumentValues.addIndexedArgumentValue(0, new RuntimeBeanReference(WebApplicationContext.class));
constructorArgumentValues.addIndexedArgumentValue(1, new RuntimeBeanReference(ServletContext.class));
constructorArgumentValues.addIndexedArgumentValue(2, webscript);
constructorArgumentValues.addIndexedArgumentValue(3, servletContextClass);
constructorArgumentValues.addIndexedArgumentValue(4, servletContext);
constructorArgumentValues.addIndexedArgumentValue(5, inheritGlobalProperties);
dispatcherWebscriptServletDefinition.setConstructorArgumentValues(constructorArgumentValues);
dispatcherWebscriptServletDefinition.setRole(BeanDefinition.ROLE_APPLICATION);

EnumSet<ServletConfigOptions> servletConfigOptionsList = EnumSet.noneOf(ServletConfigOptions.class);
servletConfigOptionsList.addAll(Arrays.asList(servletConfigOptions));
if (!servletConfigOptionsList.isEmpty()) {
MutablePropertyValues mutablePropertyValues = new MutablePropertyValues(List.of(
new PropertyValue("detectAllHandlerMappings",
!servletConfigOptionsList.contains(ServletConfigOptions.DISABLED_PARENT_HANDLER_MAPPINGS)),
new PropertyValue("detectAllHandlerAdapters",
!servletConfigOptionsList.contains(ServletConfigOptions.DISABLED_PARENT_HANDLER_ADAPTERS)),
new PropertyValue("detectAllViewResolvers",
!servletConfigOptionsList.contains(ServletConfigOptions.DISABLED_PARENT_VIEW_RESOLVERS)),
new PropertyValue("detectAllHandlerExceptionResolvers", !servletConfigOptionsList
.contains(ServletConfigOptions.DISABLED_PARENT_HANDLER_EXCEPTION_RESOLVERS))));
dispatcherWebscriptServletDefinition.setPropertyValues(mutablePropertyValues);
}

registry.registerBeanDefinition("dispatcherWebscriptServlet", dispatcherWebscriptServletDefinition);

DispatcherWebscript ws = new DispatcherWebscript(webscript, inheritGlobalProperties);
ws.setContextClass(servletContextClass);
ws.setContextConfigLocation(servletContext.getName());
ws.addServletConfigOptions(servletConfigOptions);
beanDefinition.setInstanceSupplier(() -> ws);
beanDefinition.setRole(BeanDefinition.ROLE_APPLICATION);
GenericBeanDefinition disaptcherWebscriptDefinition = new GenericBeanDefinition();
disaptcherWebscriptDefinition.setBeanClass(DispatcherWebscript.class);

registry.registerBeanDefinition(webscript, beanDefinition);
ConstructorArgumentValues constructorArgumentValues2 = new ConstructorArgumentValues();
constructorArgumentValues2.addIndexedArgumentValue(0,
new RuntimeBeanReference(DispatcherWebscriptServlet.class));
disaptcherWebscriptDefinition.setConstructorArgumentValues(constructorArgumentValues2);
disaptcherWebscriptDefinition.setRole(BeanDefinition.ROLE_APPLICATION);

for (RequestMethod httpRequestMethod : httpRequestMethods) {
registry.registerAlias(webscript, getWebscriptName(webscript, httpRequestMethod.asHttpMethod()));
registry.registerBeanDefinition(getWebscriptName(webscript, httpRequestMethod.asHttpMethod()),
disaptcherWebscriptDefinition);
}
}

Expand Down
Loading

0 comments on commit 50ad2dc

Please sign in to comment.