Search in sources :

Example 1 with StaticActivationContextValue

use of org.apache.tapestry5.annotations.StaticActivationContextValue in project tapestry-5 by apache.

the class BaseRestDemoPage method superclassEndpoint.

@OnEvent(EventConstants.HTTP_GET)
public Object superclassEndpoint(@StaticActivationContextValue("superclassEndpoint") String pathParameter) {
    final JSONArray jsonArray = new JSONArray();
    jsonArray.add(pathParameter);
    return jsonArray;
}
Also used : JSONArray(org.apache.tapestry5.json.JSONArray) OnEvent(org.apache.tapestry5.annotations.OnEvent)

Example 2 with StaticActivationContextValue

use of org.apache.tapestry5.annotations.StaticActivationContextValue in project tapestry-5 by apache.

the class DefaultOpenApiDescriptionGenerator method getPath.

private String getPath(Method method, Class<?> pageClass) {
    final StringBuilder builder = new StringBuilder();
    builder.append(pageRenderLinkSource.createPageRenderLink(pageClass).toString());
    for (Parameter parameter : method.getParameters()) {
        if (!isIgnored(parameter)) {
            builder.append("/");
            final StaticActivationContextValue staticValue = parameter.getAnnotation(StaticActivationContextValue.class);
            if (staticValue != null) {
                builder.append(staticValue.value());
            } else {
                builder.append("{");
                builder.append(getParameterName(parameter));
                builder.append("}");
            }
        }
    }
    String path = builder.toString();
    if (!path.startsWith(basePath)) {
        throw new RuntimeException(String.format("Method %s has path %s, which " + "doesn't start with base path %s. It's likely you need to adjust the " + "base path and/or the endpoint paths", method, path, basePath));
    } else {
        // keep the slash
        path = path.substring(basePath.length() - 1);
        // remove possible double slashes
        path = path.replace("//", "/");
    }
    return path;
}
Also used : StaticActivationContextValue(org.apache.tapestry5.annotations.StaticActivationContextValue) ActivationContextParameter(org.apache.tapestry5.annotations.ActivationContextParameter) RequestParameter(org.apache.tapestry5.annotations.RequestParameter) Parameter(java.lang.reflect.Parameter)

Example 3 with StaticActivationContextValue

use of org.apache.tapestry5.annotations.StaticActivationContextValue in project tapestry-5 by apache.

the class Index method getExample.

@RestInfo(returnType = User.class, produces = "application/json")
@OnEvent(EventConstants.HTTP_GET)
public User getExample(@StaticActivationContextValue("example") String example) {
    User user = new User();
    user.setEmail("fulano@fulano.com");
    user.setName("Fulano da Silva");
    user.getAttributes().add(new Attribute("favoriteColor", "blue"));
    return user;
}
Also used : User(org.apache.tapestry5.rest.jackson.test.rest.entities.User) Attribute(org.apache.tapestry5.rest.jackson.test.rest.entities.Attribute) RestInfo(org.apache.tapestry5.annotations.RestInfo) OnEvent(org.apache.tapestry5.annotations.OnEvent)

Aggregations

OnEvent (org.apache.tapestry5.annotations.OnEvent)2 Parameter (java.lang.reflect.Parameter)1 ActivationContextParameter (org.apache.tapestry5.annotations.ActivationContextParameter)1 RequestParameter (org.apache.tapestry5.annotations.RequestParameter)1 RestInfo (org.apache.tapestry5.annotations.RestInfo)1 StaticActivationContextValue (org.apache.tapestry5.annotations.StaticActivationContextValue)1 JSONArray (org.apache.tapestry5.json.JSONArray)1 Attribute (org.apache.tapestry5.rest.jackson.test.rest.entities.Attribute)1 User (org.apache.tapestry5.rest.jackson.test.rest.entities.User)1