![JAR search and dependency download from the Maven repository](/logo.png)
com.amazon.ask.mvc.MvcSdkModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ask-sdk-mvc Show documentation
Show all versions of ask-sdk-mvc Show documentation
The Alexa Skills Kit MVC Framework extends the existing ASK SDK, adding features for mapping requests to methods
and rendering responses via view scripts and templates such as Nashorn Javascript and Freemarker. It also
integrates with the ASK SDK Interaction Model Mapper framework to create a single environment where both the
interaction model and business logic of skills can be managed as code packages.
The newest version!
/*
Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file
except in compliance with the License. A copy of the License is located at
http://aws.amazon.com/apache2.0/
or in the "license" file accompanying this file. This file 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 com.amazon.ask.mvc;
import com.amazon.ask.dispatcher.request.handler.impl.DefaultHandlerAdapter;
import com.amazon.ask.interaction.definition.Model;
import com.amazon.ask.interaction.mapper.IntentMapper;
import com.amazon.ask.module.SdkModule;
import com.amazon.ask.module.SdkModuleContext;
import com.amazon.ask.mvc.annotation.plugin.*;
import com.amazon.ask.mvc.annotation.mapping.IntentMapping;
import com.amazon.ask.mvc.argument.*;
import com.amazon.ask.mvc.mapper.ControllerRequestMapper;
import com.amazon.ask.mvc.annotation.mapping.RequestMapping;
import com.amazon.ask.mvc.plugin.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.*;
import static com.amazon.ask.util.ValidationUtils.assertNotNull;
/**
* {@link SdkModule} adding support for MVC mapping annotations, slot argument resolvers and view resolvers.
*
* @see IntentMapping
* @see RequestMapping
* @see com.amazon.ask.mvc.annotation.mapping.ExceptionHandler
* @see com.amazon.ask.mvc.annotation.mapping.RequestInterceptor
* @see com.amazon.ask.mvc.annotation.mapping.ResponseInterceptor
* @see ArgumentResolver
* @see ViewResolver
* @see SkillContext
*/
public class MvcSdkModule implements SdkModule {
/**
* Default set of {@link ArgumentResolver}s
*/
protected static final Collection DEFAULT_ARGUMENT_RESOLVERS =
Collections.unmodifiableList(Arrays.asList(
new SlotValuesArgumentResolver(),
new SlotValueArgumentResolver(),
new SlotArgumentResolver(),
new RequestArgumentResolver(),
new IntentArgumentResolver(),
new RequestEnvelopeArgumentResolver(),
new SessionArgumentResolver(),
new SessionAttributesMapArgumentResolver(),
new AttributesManagerArgumentResolver(),
new ResponseBuilderArgumentResolver(),
new ServiceClientFactoryArgumentResolver(),
new LocaleArgumentResolver()));
protected static final String MVC_USER_AGENT = "ask-mvc/1.0-beta";
protected static final String MODELS_USER_AGENT = "ask-models/1.0-beta";
protected final SkillContext skillContext;
public MvcSdkModule(SkillContext skillContext) {
this.skillContext = assertNotNull(skillContext, "context");
}
/**
* Scans all controllers for methods, set up handlers and interceptors, and append user agent.
*
* @param moduleContext sdk module context
*/
@Override
public void setupModule(SdkModuleContext moduleContext) {
moduleContext.addHandlerAdapter(new DefaultHandlerAdapter());
moduleContext.appendCustomUserAgent(MVC_USER_AGENT);
if (!skillContext.getModel().equals(Model.empty())) {
moduleContext.appendCustomUserAgent(MODELS_USER_AGENT);
}
for (Object controller : skillContext.getControllers()) {
moduleContext.addRequestMapper(new ControllerRequestMapper(skillContext, controller));
}
}
/**
* @return a builder with default features enabled
*/
public static Builder builder() {
return emptyBuilder()
.addArgumentResolvers(DEFAULT_ARGUMENT_RESOLVERS)
.addArgumentResolver(new AutoArgumentResolver.Scanner())
.addRequestHandlerResolver(new AutoRequestHandler.Scanner())
.addResponseInterceptorResolver(new AutoResponseInterceptor.Scanner())
.addRequestInterceptorResolver(new AutoRequestInterceptor.Scanner())
.addPredicateResolver(new AutoPredicate.Scanner())
.addExceptionHandlerResolver(new AutoExceptionHandler.Scanner());
}
/**
* @return a builder with no features enabled
*/
public static Builder emptyBuilder() {
return new Builder();
}
public static class Builder {
protected Set argumentResolvers;
protected Set exceptionHandlerResolvers;
protected Set requestHandlerResolvers;
protected Set requestInterceptorResolvers;
protected Set responseInterceptorResolvers;
protected Set predicateResolvers;
protected Set viewResolvers;
protected Set
© 2015 - 2025 Weber Informatics LLC | Privacy Policy