use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class WebPage method validateHeaders.
/**
* Validate that each component which wanted to contribute to the header section actually was
* able to do so.
*/
private void validateHeaders() {
// search for HtmlHeaderContainer in the first level of children or deeper
// if there are transparent resolvers used
HtmlHeaderContainer header = visitChildren(new IVisitor<Component, HtmlHeaderContainer>() {
@Override
public void component(final Component component, final IVisit<HtmlHeaderContainer> visit) {
if (component instanceof HtmlHeaderContainer) {
visit.stop((HtmlHeaderContainer) component);
} else if (component instanceof TransparentWebMarkupContainer == false) {
visit.dontGoDeeper();
}
}
});
if (header == null) {
// the markup must at least contain a <body> tag for wicket to automatically
// create a HtmlHeaderContainer. Log an error if no header container
// was created but any of the components or behaviors want to contribute
// something to the header.
header = new HtmlHeaderContainer(HtmlHeaderSectionHandler.HEADER_ID);
add(header);
RequestCycle requestCycle = getRequestCycle();
Response orgResponse = requestCycle.getResponse();
try {
StringResponse tempResponse = new StringResponse();
requestCycle.setResponse(tempResponse);
// Render all header sections of all components on the page
AbstractHeaderRenderStrategy.get().renderHeader(header, null, getPage());
IHeaderResponse headerResponse = header.getHeaderResponse();
headerResponse.close();
CharSequence collectedHeaderOutput = tempResponse.getBuffer();
if (collectedHeaderOutput.length() > 0) {
reportMissingHead(collectedHeaderOutput);
}
} catch (Exception e) {
// just swallow this exception, there isn't much we can do about.
log.error("header/body check throws exception", e);
} finally {
this.remove(header);
requestCycle.setResponse(orgResponse);
}
}
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class PartialPageUpdate method writeComponents.
/**
* Processes components added to the target. This involves attaching components, rendering
* markup into a client side xml envelope, and detaching them
*
* @param response
* the response to write to
* @param encoding
* the encoding for the response
*/
private void writeComponents(Response response, String encoding) {
componentsFrozen = true;
List<Component> toBeWritten = new ArrayList<>(markupIdToComponent.size());
// delay preparation of feedbacks after all other components
try (FeedbackDelay delay = new FeedbackDelay(RequestCycle.get())) {
for (Component component : markupIdToComponent.values()) {
if (!containsAncestorFor(component)) {
if (prepareComponent(component)) {
toBeWritten.add(component);
}
}
}
// .. now prepare all postponed feedbacks
delay.beforeRender();
}
// write components
for (Component component : toBeWritten) {
writeComponent(response, component.getAjaxRegionMarkupId(), component, encoding);
}
if (header != null) {
RequestCycle cycle = RequestCycle.get();
// some header responses buffer all calls to render*** until close is called.
// when they are closed, they do something (i.e. aggregate all JS resource urls to a
// single url), and then "flush" (by writing to the real response) before closing.
// to support this, we need to allow header contributions to be written in the close
// tag, which we do here:
headerRendering = true;
// save old response, set new
Response oldResponse = cycle.setResponse(headerBuffer);
headerBuffer.reset();
// now, close the response (which may render things)
header.getHeaderResponse().close();
// revert to old response
cycle.setResponse(oldResponse);
// write the XML tags and we're done
writeHeaderContribution(response);
headerRendering = false;
}
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class AbstractRequestLogger method getCurrentRequest.
public RequestData getCurrentRequest() {
RequestCycle requestCycle = RequestCycle.get();
RequestData rd = requestCycle.getMetaData(REQUEST_DATA);
if (rd == null) {
rd = new RequestData();
requestCycle.setMetaData(REQUEST_DATA, rd);
int activeCount = activeRequests.incrementAndGet();
if (activeCount > peakActiveRequests.get()) {
peakActiveRequests.set(activeCount);
}
}
return rd;
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class AbstractTransformerBehavior method afterRender.
@Override
public void afterRender(final Component component) {
final RequestCycle requestCycle = RequestCycle.get();
try {
BufferedWebResponse tempResponse = (BufferedWebResponse) requestCycle.getResponse();
if (component instanceof Page && originalResponse instanceof WebResponse) {
tempResponse.writeMetaData((WebResponse) originalResponse);
}
// Transform the data
CharSequence output = transform(component, tempResponse.getText());
originalResponse.write(output);
} catch (Exception ex) {
throw new WicketRuntimeException("Error while transforming the output of component: " + component, ex);
} finally {
// Restore the original response object
requestCycle.setResponse(originalResponse);
}
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class AbstractTransformerBehavior method beforeRender.
@Override
public void beforeRender(Component component) {
super.beforeRender(component);
final RequestCycle requestCycle = RequestCycle.get();
// Temporarily replace the web response with a String response
originalResponse = requestCycle.getResponse();
WebResponse origResponse = (WebResponse) ((originalResponse instanceof WebResponse) ? originalResponse : null);
BufferedWebResponse tempResponse = newResponse(origResponse);
// temporarily set StringResponse to collect the transformed output
requestCycle.setResponse(tempResponse);
}
Aggregations