Search in sources :

Example 56 with Path

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

the class DefaultOpenApiDescriptionGenerator method processMethod.

private void processMethod(Method method, final Class<?> pageClass, JSONObject paths, final String tagName) {
    final String uri = getPath(method, pageClass);
    final JSONObject path;
    if (paths.containsKey(uri)) {
        path = paths.getJSONObject(uri);
    } else {
        path = new JSONObject();
        paths.put(uri, path);
    }
    final String httpMethod = getHttpMethod(method);
    if (path.containsKey(httpMethod)) {
        throw new RuntimeException(String.format("There are at least two different REST endpoints for path %s and HTTP method %s in class %s", uri, httpMethod.toUpperCase(), pageClass.getName()));
    } else {
        final JSONObject methodDescription = new JSONObject();
        putIfNotEmpty(methodDescription, "summary", getValue(method, uri, httpMethod, "summary"));
        putIfNotEmpty(methodDescription, "description", getValue(method, uri, httpMethod, "description"));
        JSONArray methodTags = new JSONArray();
        methodTags.add(tagName);
        methodDescription.put("tags", methodTags);
        processResponses(method, uri, httpMethod, methodDescription);
        processParameters(method, uri, httpMethod, methodDescription);
        path.put(httpMethod, methodDescription);
    }
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) JSONArray(org.apache.tapestry5.json.JSONArray)

Example 57 with Path

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

the class StackAssetRequestHandler method streamStackResource.

private boolean streamStackResource(String extraPath) throws IOException {
    Matcher matcher = pathPattern.matcher(extraPath);
    if (!matcher.matches()) {
        logger.warn("Unable to parse '{}' as an asset stack path", extraPath);
        return false;
    }
    String checksum = matcher.group(1);
    String localeName = matcher.group(2);
    final String stackName = matcher.group(3);
    final boolean compressed = checksum.startsWith("z");
    if (compressed) {
        checksum = checksum.substring(1);
    }
    final JavaScriptStack stack = stackSource.findStack(stackName);
    if (stack == null) {
        logger.warn("JavaScript stack '{}' not found.", stackName);
        return false;
    }
    // Yes, I have a big regret that the JavaScript stack stuff relies on this global, rather than
    // having it passed around properly.
    localizationSetter.setNonPersistentLocaleFromLocaleName(localeName);
    StreamableResource resource = tracker.perform(String.format("Assembling JavaScript asset stack '%s' (%s)", stackName, localeName), new IOOperation<StreamableResource>() {

        public StreamableResource perform() throws IOException {
            return javaScriptStackAssembler.assembleJavaScriptResourceForStack(stackName, compressed, stack.getJavaScriptAggregationStrategy());
        }
    });
    if (resource == null) {
        return false;
    }
    return resourceStreamer.streamResource(resource, checksum, ResourceStreamer.DEFAULT_OPTIONS);
}
Also used : StreamableResource(org.apache.tapestry5.services.assets.StreamableResource) Matcher(java.util.regex.Matcher) JavaScriptStack(org.apache.tapestry5.services.javascript.JavaScriptStack) IOException(java.io.IOException)

Aggregations

Test (org.testng.annotations.Test)22 Request (org.apache.tapestry5.http.services.Request)14 Context (org.apache.tapestry5.http.services.Context)9 Resource (org.apache.tapestry5.commons.Resource)8 Path (io.fabric8.annotations.Path)6 IOException (java.io.IOException)6 URL (java.net.URL)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 RequestFilter (org.apache.tapestry5.http.services.RequestFilter)5 RequestHandler (org.apache.tapestry5.http.services.RequestHandler)5 Response (org.apache.tapestry5.http.services.Response)5 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)5 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)5 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)5 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)5 Configuration (io.fabric8.annotations.Configuration)4 Endpoint (io.fabric8.annotations.Endpoint)4 External (io.fabric8.annotations.External)4 PortName (io.fabric8.annotations.PortName)4 Protocol (io.fabric8.annotations.Protocol)4