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();
}
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();
}
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();
}
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();
}
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;
}
Aggregations