@@ -0,0 +1,2816 @@
+/*%0A * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.%0A *%0A * WSO2 Inc. licenses this file to you under the Apache License,%0A * Version 2.0 (the %22License%22); you may not use this file except%0A * in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *   http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing,%0A * software distributed under the License is distributed on an%0A * %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY%0A * KIND, either express or implied.  See the License for the%0A * specific language governing permissions and limitations%0A * under the License.%0A */%0A%0Apackage org.wso2.carbon.uis.internal.http;%0A%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0Aimport org.wso2.carbon.uis.api.App;%0Aimport org.wso2.carbon.uis.api.exception.HttpErrorException;%0Aimport org.wso2.carbon.uis.api.exception.PageRedirectException;%0Aimport org.wso2.carbon.uis.api.exception.UISRuntimeException;%0Aimport org.wso2.carbon.uis.api.http.HttpRequest;%0Aimport org.wso2.carbon.uis.api.http.HttpResponse;%0A%0Aimport static org.wso2.carbon.uis.api.http.HttpResponse.CONTENT_TYPE_TEXT_HTML;%0Aimport static org.wso2.carbon.uis.api.http.HttpResponse.CONTENT_TYPE_TEXT_PLAIN;%0Aimport static org.wso2.carbon.uis.api.http.HttpResponse.HEADER_LOCATION;%0Aimport static org.wso2.carbon.uis.api.http.HttpResponse.STATUS_INTERNAL_SERVER_ERROR;%0A%0Apublic class PageRequestDispatcher %7B%0A%0A    private static final Logger LOGGER = LoggerFactory.getLogger(PageRequestDispatcher.class);%0A%0A    private final App app;%0A%0A    public PageRequestDispatcher(App app) %7B%0A        this.app = app;%0A    %7D%0A%0A    public HttpResponse server(HttpRequest request) %7B%0A        try %7B%0A            String html = app.renderPage(request);%0A            return ResponseBuilder.ok(html, CONTENT_TYPE_TEXT_HTML)%0A                    .headers(app.getConfiguration().getResponseHeaders().forPages())%0A                    .build();%0A        %7D catch (PageRedirectException e) %7B%0A            return ResponseBuilder.status(e.getHttpStatusCode())%0A                    .header(HEADER_LOCATION, e.getRedirectUrl())%0A                    .build();%0A        %7D catch (HttpErrorException e) %7B%0A            return serveDefaultErrorPage(e.getHttpStatusCode(), e.getMessage());%0A        %7D catch (UISRuntimeException e) %7B%0A            LOGGER.error(%22Cannot serve request %7B%7D due to a runtime exception in the server.%22, request, e);%0A            return serveDefaultErrorPage(STATUS_INTERNAL_SERVER_ERROR, %22Internal server error.%22);%0A        %7D%0A    %7D%0A%0A    private static HttpResponse serveDefaultErrorPage(int httpStatusCode, String content) %7B%0A        return ResponseBuilder.status(httpStatusCode)%0A                .content(content)%0A                .contentType(CONTENT_TYPE_TEXT_PLAIN)%0A                .build();%0A    %7D%0A%7D%0A

add PageRequestDispatcher class