Search in sources :

Example 6 with BaseURLSource

use of org.apache.tapestry5.http.services.BaseURLSource in project tapestry-5 by apache.

the class AppModule method setupCustomBaseURLSource.

@Contribute(ServiceOverride.class)
public void setupCustomBaseURLSource(MappedConfiguration<Class, Object> configuration) {
    BaseURLSource source = new BaseURLSource() {

        public String getBaseURL(boolean secure) {
            String protocol = secure ? "https" : "http";
            // This is all a bit jury-rigged together. This is for running the app
            // interactively; Selenium doesn't seem to handle the transition to https.
            int port = secure ? 8443 : 9090;
            return String.format("%s://localhost:%d", protocol, port);
        }
    };
    configuration.add(BaseURLSource.class, source);
}
Also used : BaseURLSource(org.apache.tapestry5.http.services.BaseURLSource) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 7 with BaseURLSource

use of org.apache.tapestry5.http.services.BaseURLSource in project tapestry-5 by apache.

the class LinkImplTest method force_link_to_secure.

@Test
public void force_link_to_secure() {
    Response response = mockResponse();
    BaseURLSource baseURLSource = mockBaseURLSource();
    train_getBaseURL(baseURLSource, true, SECURE_BASE_URL);
    train_encodeURL(response, SECURE_BASE_URL + BASE_PATH, ENCODED);
    replay();
    Link link = new LinkImpl(BASE_PATH, false, LinkSecurity.INSECURE, response, null, baseURLSource);
    link.setSecurity(LinkSecurity.FORCE_SECURE);
    assertEquals(link.toAbsoluteURI(), ENCODED);
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) BaseURLSource(org.apache.tapestry5.http.services.BaseURLSource) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 8 with BaseURLSource

use of org.apache.tapestry5.http.services.BaseURLSource in project tapestry-5 by apache.

the class ComponentEventLinkEncoderImpl method createPageRenderLink.

public Link createPageRenderLink(PageRenderRequestParameters parameters) {
    StringBuilder builder = new StringBuilder(BUFFER_SIZE);
    // Build up the absolute URI.
    String activePageName = parameters.getLogicalPageName();
    builder.append(contextPath);
    encodeAppFolderAndLocale(builder);
    builder.append(SLASH);
    String encodedPageName = encodePageName(activePageName);
    builder.append(encodedPageName);
    appendContext(encodedPageName.length() > 0, parameters.getActivationContext(), builder);
    Link link = new LinkImpl(builder.toString(), false, requestSecurityManager.checkPageSecurity(activePageName), response, contextPathEncoder, baseURLSource);
    if (parameters.isLoopback()) {
        link.addParameter(TapestryConstants.PAGE_LOOPBACK_PARAMETER_NAME, "t");
    }
    return link;
}
Also used : Link(org.apache.tapestry5.http.Link)

Example 9 with BaseURLSource

use of org.apache.tapestry5.http.services.BaseURLSource in project tapestry-5 by apache.

the class LinkImplTest method absolute_URI_for_default_secure_link.

@Test
public void absolute_URI_for_default_secure_link() {
    Response response = mockResponse();
    BaseURLSource baseURLSource = mockBaseURLSource();
    train_getBaseURL(baseURLSource, true, SECURE_BASE_URL);
    train_encodeURL(response, SECURE_BASE_URL + BASE_PATH, ENCODED);
    replay();
    Link link = new LinkImpl(BASE_PATH, false, LinkSecurity.SECURE, response, null, baseURLSource);
    assertEquals(link.toAbsoluteURI(), ENCODED);
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) BaseURLSource(org.apache.tapestry5.http.services.BaseURLSource) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 10 with BaseURLSource

use of org.apache.tapestry5.http.services.BaseURLSource in project tapestry-5 by apache.

the class LinkImplTest method force_secure_URI_from_insecure_link.

@Test
public void force_secure_URI_from_insecure_link() {
    Response response = mockResponse();
    BaseURLSource baseURLSource = mockBaseURLSource();
    train_getBaseURL(baseURLSource, true, SECURE_BASE_URL);
    train_encodeURL(response, SECURE_BASE_URL + BASE_PATH, ENCODED);
    replay();
    Link link = new LinkImpl(BASE_PATH, false, LinkSecurity.INSECURE, response, null, baseURLSource);
    assertEquals(link.toAbsoluteURI(true), ENCODED);
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) BaseURLSource(org.apache.tapestry5.http.services.BaseURLSource) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Aggregations

BaseURLSource (org.apache.tapestry5.http.services.BaseURLSource)13 Test (org.testng.annotations.Test)12 Link (org.apache.tapestry5.http.Link)7 BaseURLSourceImpl (org.apache.tapestry5.http.internal.services.BaseURLSourceImpl)7 Response (org.apache.tapestry5.http.services.Response)5 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)1