Search in sources :

Example 1 with BaseURLSource

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

the class BaseURLSourceImplTest method contributed_hostname.

@Test
public void contributed_hostname() {
    expect(request.getServerPort()).andReturn(80).once();
    expect(request.isSecure()).andReturn(false);
    replay();
    BaseURLSource baseURLSource = new BaseURLSourceImpl(request, "my.server.com", 0, 0);
    assertEquals(baseURLSource.getBaseURL(false), "http://my.server.com");
    verify();
}
Also used : BaseURLSourceImpl(org.apache.tapestry5.http.internal.services.BaseURLSourceImpl) BaseURLSource(org.apache.tapestry5.http.services.BaseURLSource) Test(org.testng.annotations.Test)

Example 2 with BaseURLSource

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

the class BaseURLSourceImplTest method hostname_from_environment_variable.

@Test
public void hostname_from_environment_variable() {
    expect(request.getServerPort()).andReturn(80).once();
    expect(request.isSecure()).andReturn(false);
    replay();
    BaseURLSource baseURLSource = new BaseURLSourceImpl(request, "$HOSTNAME", 0, 0);
    assertEquals(baseURLSource.getBaseURL(false), "http://" + System.getenv("HOSTNAME"));
    verify();
}
Also used : BaseURLSourceImpl(org.apache.tapestry5.http.internal.services.BaseURLSourceImpl) BaseURLSource(org.apache.tapestry5.http.services.BaseURLSource) Test(org.testng.annotations.Test)

Example 3 with BaseURLSource

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

the class BaseURLSourceImplTest method secure_url_using_default_port.

@Test
public void secure_url_using_default_port() {
    replay();
    BaseURLSource baseURLSource = new BaseURLSourceImpl(request, "localhost", 80, 443);
    assertEquals(baseURLSource.getBaseURL(true), "https://localhost");
    verify();
}
Also used : BaseURLSourceImpl(org.apache.tapestry5.http.internal.services.BaseURLSourceImpl) BaseURLSource(org.apache.tapestry5.http.services.BaseURLSource) Test(org.testng.annotations.Test)

Example 4 with BaseURLSource

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

the class BaseURLSourceImplTest method insecure_url_using_default_port.

@Test
public void insecure_url_using_default_port() {
    replay();
    BaseURLSource baseURLSource = new BaseURLSourceImpl(request, "localhost", 80, 443);
    assertEquals(baseURLSource.getBaseURL(false), "http://localhost");
    verify();
}
Also used : BaseURLSourceImpl(org.apache.tapestry5.http.internal.services.BaseURLSourceImpl) BaseURLSource(org.apache.tapestry5.http.services.BaseURLSource) Test(org.testng.annotations.Test)

Example 5 with BaseURLSource

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

the class ComponentEventLinkEncoderImpl method createComponentEventLink.

public Link createComponentEventLink(ComponentEventRequestParameters parameters, boolean forForm) {
    StringBuilder builder = new StringBuilder(BUFFER_SIZE);
    // Build up the absolute URI.
    String activePageName = parameters.getActivePageName();
    String containingPageName = parameters.getContainingPageName();
    String eventType = parameters.getEventType();
    String nestedComponentId = parameters.getNestedComponentId();
    boolean hasComponentId = InternalUtils.isNonBlank(nestedComponentId);
    builder.append(contextPath);
    encodeAppFolderAndLocale(builder);
    builder.append(SLASH);
    builder.append(activePageName.toLowerCase());
    if (hasComponentId) {
        builder.append('.');
        builder.append(nestedComponentId);
    }
    if (!hasComponentId || !eventType.equals(EventConstants.ACTION)) {
        builder.append(':');
        builder.append(encodePageName(eventType));
    }
    appendContext(true, parameters.getEventContext(), builder);
    Link result = new LinkImpl(builder.toString(), forForm, requestSecurityManager.checkPageSecurity(activePageName), response, contextPathEncoder, baseURLSource);
    EventContext pageActivationContext = parameters.getPageActivationContext();
    if (pageActivationContext.getCount() != 0) {
        // Reuse the builder
        builder.setLength(0);
        appendContext(true, pageActivationContext, builder);
        // Omit that first slash
        result.addParameter(InternalConstants.PAGE_CONTEXT_NAME, builder.substring(1));
    }
    if (!containingPageName.equalsIgnoreCase(activePageName))
        result.addParameter(InternalConstants.CONTAINER_PAGE_NAME, encodePageName(containingPageName));
    return result;
}
Also used : Link(org.apache.tapestry5.http.Link)

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