use of org.apache.wicket.Application in project wicket by apache.
the class WicketFilterTest method notModifiedResponseIncludesExpiresHeader.
/**
* @throws IOException
* @throws ServletException
* @throws ParseException
*/
@Test
public void notModifiedResponseIncludesExpiresHeader() throws IOException, ServletException, ParseException {
try {
application = new MockApplication();
WicketFilter filter = new WicketFilter();
filter.init(new FilterTestingConfig());
ThreadContext.setApplication(application);
DynamicImageResource resource = new DynamicImageResource() {
private static final long serialVersionUID = 1L;
@Override
protected byte[] getImageData(Attributes attributes) {
throw new UnsupportedOperationException("Not implemented");
}
@Override
protected ResourceResponse newResourceResponse(Attributes attributes) {
ResourceResponse response = super.newResourceResponse(attributes);
response.setCacheDurationToMaximum();
return response;
}
};
application.getSharedResources().add("foo.gif", resource);
MockHttpServletRequest request = new MockHttpServletRequest(application, null, null);
request.setURL(request.getContextPath() + request.getServletPath() + "/wicket/resource/" + Application.class.getName() + "/foo.gif");
setIfModifiedSinceToNextWeek(request);
MockHttpServletResponse response = new MockHttpServletResponse(request);
filter.doFilter(request, response, new FilterChain() {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
}
});
assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getStatus());
String responseExpiresHeader = response.getHeader("Expires");
assertNotNull("Expires header must be set on not modified response", responseExpiresHeader);
Date responseExpires = headerDateFormat.parse(responseExpiresHeader);
assertTrue("Expected later than current date but was " + responseExpires, responseExpires.after(new Date()));
} finally {
ThreadContext.detach();
}
}
use of org.apache.wicket.Application in project wicket by apache.
the class WicketMetrics method getSettings.
/**
* Gets the wicket metrics settings
*
* @return the wicket metrics settings
*/
public static synchronized WicketMetricsSettings getSettings() {
Application application = Application.get(getFilterName());
if (application == null) {
throw new WicketRuntimeException(APPLICATION_ERROR);
}
WicketMetricsSettings wicketMetricsSettings = application.getMetaData(METRIC_SETTINGS);
if (wicketMetricsSettings == null) {
wicketMetricsSettings = new WicketMetricsSettings();
wicketMetricsSettings.setPrefix(getFilterName());
application.setMetaData(METRIC_SETTINGS, wicketMetricsSettings);
}
return wicketMetricsSettings;
}
use of org.apache.wicket.Application in project wicket by apache.
the class WicketMetrics method getMetricRegistry.
/**
* Gets the metric registry
*
* @return the metric registry
*/
public static synchronized MetricRegistry getMetricRegistry() {
Application application = Application.get(getFilterName());
if (application == null) {
throw new WicketRuntimeException(APPLICATION_ERROR);
}
MetricRegistry metricRegistry = application.getMetaData(METRIC_REGISTRY);
if (metricRegistry == null) {
metricRegistry = new MetricRegistry();
application.setMetaData(METRIC_REGISTRY, metricRegistry);
}
return metricRegistry;
}
use of org.apache.wicket.Application in project wicket by apache.
the class ComponentRenderer method renderPage.
/**
* Collects the Html generated by the rendering a page.
* <p>
* Important note: Must be called on a thread bound to an application's {@link ThreadContext}!
*
* @param pageProvider
* the provider of the page class/instance and its parameters
* @return the html rendered by a page
*
* @see ThreadContext
*/
public static CharSequence renderPage(final PageProvider pageProvider) {
Application application = Application.get();
RequestCycle originalRequestCycle = RequestCycle.get();
BufferedWebResponse tempResponse = new BufferedWebResponse(null);
RequestCycle tempRequestCycle = application.createRequestCycle(originalRequestCycle.getRequest(), tempResponse);
try {
ThreadContext.setRequestCycle(tempRequestCycle);
pageProvider.getPageInstance().renderPage();
} finally {
ThreadContext.setRequestCycle(originalRequestCycle);
}
return tempResponse.getText();
}
use of org.apache.wicket.Application in project wicket by apache.
the class LocalizedImageResource method newImage.
/**
* Generates an image resource based on the attribute values on tag
*
* @param value
* The value to parse
*/
private void newImage(final CharSequence value) {
// Parse value
final ImageValueParser valueParser = new ImageValueParser(value);
// Does value match parser?
if (valueParser.matches()) {
final String imageReferenceName = valueParser.getImageReferenceName();
final String specification = Strings.replaceHtmlEscapeNumber(valueParser.getSpecification());
final String factoryName = valueParser.getFactoryName();
final Application application = component.getApplication();
// Do we have a reference?
if (!Strings.isEmpty(imageReferenceName)) {
// Is resource already available via the application?
if (application.getResourceReferenceRegistry().getResourceReference(Application.class, imageReferenceName, locale, style, variation, true, false) == null) {
// Resource not available yet, so create it with factory and
// share via Application
final IResource imageResource = getResourceFactory(application, factoryName).newResource(specification, locale, style, variation);
ResourceReference ref = new SimpleStaticResourceReference(Application.class, imageReferenceName, locale, style, variation, imageResource);
application.getResourceReferenceRegistry().registerResourceReference(ref);
}
// Create resource reference
resourceReference = new PackageResourceReference(Application.class, imageReferenceName, locale, style, variation);
} else {
resource = getResourceFactory(application, factoryName).newResource(specification, locale, style, variation);
}
} else {
throw new WicketRuntimeException("Could not generate image for value attribute '" + value + "'. Was expecting a value attribute of the form \"[resourceFactoryName]:[resourceReferenceName]?:[factorySpecification]\".");
}
}
Aggregations