@Override
public boolean handleConnectorRequest(VaadinRequest request,VaadinResponse response,String path) throws IOException {
final BusyIndicatorWindow busyIndicatorWindow = new BusyIndicatorWindow();
final UI ui = UI.getCurrent();
ui.access(() -> ui.addWindow(busyIndicatorWindow));
try {
//on charge le fichier
getStreamSource().loadondemandFile();
if (getStreamSource().getStream()==null){
return true;
}
getResource().setFilename(getStreamSource().getFileName());
return super.handleConnectorRequest(request,response,path);
}catch(Exception e){
return true;
}
finally {
busyIndicatorWindow.close();
}
}
@Override
public boolean handleConnectorRequest(VaadinRequest request,String path) throws IOException {
final BusyIndicatorWindow busyIndicatorWindow = new BusyIndicatorWindow();
final UI ui = UI.getCurrent();
ui.access(() -> ui.addWindow(busyIndicatorWindow));
try {
getStreamSource().loadondemandFile();
if (getStreamSource().getStream()==null){
return true;
}
getDownloadStreamSource().setMIMEType("application/pdf");
getDownloadStreamSource().getStream().setParameter(
"Content-disposition","attachment; filename="+getStreamSource().getFileName());
return super.handleConnectorRequest(request,path);
}catch(Exception e){
return true;
}finally {
busyIndicatorWindow.close();
}
}
项目:vaadin-jcrop
文件:Jcrop.java
/**
* initalize a unique RequestHandler
*/
private void initRequestHandler() {
if (this.requestHandlerUri == null) {
this.requestHandlerUri = UUID.randomUUID()
.toString();
VaadinSession.getCurrent()
.addRequestHandler(new RequestHandler() {
@Override
public boolean handleRequest(final VaadinSession session,final VaadinRequest request,final VaadinResponse response)
throws IOException {
if (String.format("/%s",Jcrop.this.requestHandlerUri)
.equals(request.getPathInfo())) {
Jcrop.this.resource.getStream()
.writeResponse(request,response);
return true;
} else {
return false;
}
}
});
}
}
@Override
public void onRequestEnd(VaadinRequest request,VaadinSession session) {
try {
if (session != null) {
SecurityContext securityContext = SecurityContextHolder.getContext();
logger.trace("Storing security context {} in VaadinSession {}",securityContext,session);
session.lock();
try {
session.setAttribute(Security_CONTEXT_SESSION_ATTRIBUTE,securityContext);
} finally {
session.unlock();
}
} else {
logger.trace("No VaadinSession available for storing the security context");
}
} finally {
logger.trace("Clearing security context");
SecurityContextHolder.clearContext();
}
}
项目:panifex-platform
文件:PageletAwareUITest.java
@Test
public void testinitNotMatchedPagelet() throws Exception {
// variables
String path = "/test";
// mocks
VaadinPageletTracker pageletTracker = createMock(VaadinPageletTracker.class);
VaadinRequest request = createMock(VaadinRequest.class);
// expect getting url path from request
expect(request.getPathInfo()).andReturn(path);
// expect matching path to pagelet
expect(pageletTracker.matchPathToPagelet(path)).andReturn(null);
// except returning HTTP 404
VaadinResponse response = createMock(VaadinResponse.class);
expect(CurrentInstance.get(VaadinResponse.class)).andReturn(response);
response.sendError(HttpServletResponse.SC_NOT_FOUND,"Not found");
// perform test
replayAll();
PageletAwareUI ui = new PageletAwareUI(pageletTracker);
ui.init(request);
verifyAll();
}
项目:java-pwa
文件:MyUI.java
@Override
protected void servletinitialized() throws servletexception {
super.servletinitialized();
HeaderTagHandler.init(getService());
getService().addSessionInitListener(new SessionInitListener() {
@Override
public void sessionInit(SessionInitEvent event) throws ServiceException {
event.getSession().addRequestHandler(new RequestHandler() {
@Override
public boolean handleRequest(VaadinSession session,VaadinRequest request,VaadinResponse response) throws IOException {
String pathInfo = request.getPathInfo();
InputStream in = null;
if (pathInfo.endsWith("sw.js")) {
response.setContentType("application/javascript");
in = getClass().getResourceAsstream("/sw.js");
}
if (in != null) {
OutputStream out = response.getoutputStream();
IoUtils.copy(in,out);
in.close();
out.close();
return true;
} else {
return false;
}
}
});
}
});
}
项目:hybridbpm
文件:DocumentHistoryLayout.java
@Override
public boolean handleConnectorRequest(VaadinRequest request,String path) throws IOException {
StreamResource resource = new StreamResource(new StreamResource.StreamSource() {
@Override
public InputStream getStream() {
byte[] doc = HybridbpmUI.getDocumentAPI().getDocumentBodyByVersionId(documentVersionId);
return new ByteArrayInputStream(doc);
}
},name);
this.setResource("dl",resource);
return super.handleConnectorRequest(request,path);
}
项目:hybridbpm
文件:DocumentColumnGenerator.java
@Override
public boolean handleConnectorRequest(VaadinRequest request,String path) throws IOException {
StreamResource resource = new StreamResource(() -> {
Document doc = HybridbpmUI.getDocumentAPI().getDocumentById(documentId,true);
return new ByteArrayInputStream(doc.getBody());
},path);
}
项目:trollator
文件:DynamicImage.java
@Override
public boolean handleRequest(VaadinSession session,VaadinResponse response)
throws IOException {
System.out.println("Requesting "+ request.getPathInfo());
if (imageData != null && ("/" + uri).equals(request.getPathInfo())) {
response.setContentType("image/png");
ImageIO.write(imageData,"png",response.getoutputStream());
return true;
}
return false;
}
@Override
public void onRequestStart(VaadinRequest request,VaadinResponse response) {
final WrappedSession wrappedSession = request.getWrappedSession(false);
VaadinSession session = null;
if (wrappedSession != null) {
session = VaadinSession.getForSession(request.getService(),wrappedSession);
}
SecurityContextHolder.clearContext();
if (session != null) {
logger.trace("Loading security context from VaadinSession {}",session);
SecurityContext securityContext;
session.lock();
try {
securityContext = (SecurityContext) session.getAttribute(Security_CONTEXT_SESSION_ATTRIBUTE);
} finally {
session.unlock();
}
if (securityContext == null) {
logger.trace("No security context found in VaadinSession {}",session);
} else {
logger.trace("Setting security context to {}",securityContext);
SecurityContextHolder.setContext(securityContext);
}
} else {
logger.trace("No VaadinSession available for retrieving the security context");
}
}
项目:vaadin4spring
文件:Vaadin4SpringServletService.java
@Override
public void requestStart(VaadinRequest request,VaadinResponse response) {
super.requestStart(request,response);
logger.trace("Invoking VaadinRequestStartListeners");
for (VaadinRequestStartListener listener : applicationContext.getBeansOfType(VaadinRequestStartListener.class).values()) {
try {
listener.onRequestStart(request,response);
} catch (Exception ex) {
logger.error("VaadinRequestStartListener threw an exception,ignoring",ex);
}
}
logger.trace("Finished invoking VaadinRequestStartListeners");
}
项目:vaadin4spring
文件:Vaadin4SpringServletService.java
@Override
public void requestEnd(VaadinRequest request,VaadinSession session) {
logger.trace("Invoking VaadinRequestEndListeners");
for (VaadinRequestEndListener listener : applicationContext.getBeansOfType(VaadinRequestEndListener.class).values()) {
try {
listener.onRequestEnd(request,session);
} catch (Exception ex) {
logger.error("VaadinRequestEndListener threw an exception,ex);
}
}
logger.trace("Finished invoking VaadinRequestEndListener");
super.requestEnd(request,session);
}
项目:dhconvalidator
文件:ExternalResourceRequestHandler.java
@Override
public boolean handleRequest(VaadinSession session,VaadinResponse response)
throws IOException {
// does the request concern us?
if (request.getPathInfo().startsWith("/popup"+imagePath)) { //$NON-NLS-1$
ZipResult zipResult =
(ZipResult) VaadinSession.getCurrent().getAttribute(
SessionStorageKey.ZIPRESULT.name());
// if this is about the example picture we use the example ZipResult
if (request.getPathInfo().endsWith(examplePictureName)) {
zipResult = exampleZipResult;
}
if (zipResult != null) {
byte[] resource = zipResult.getExternalResource(
request.getPathInfo().substring(PATH_PREFIX_LENGTH));
if (resource != null) {
response.getoutputStream().write(resource);
return true;
}
else {
throw new IOException(
Messages.getString(
"ExternalResourceRequestHandler.resourceNotFound",//$NON-NLS-1$
request.getPathInfo().substring(PATH_PREFIX_LENGTH)));
}
}
}
return false;
}
项目:mideaas
文件:OAuthButton.java
/**
* Creates the parameter handler that will be invoked when the user returns
* from the OAuth service.
*
* @return the parameter handler
*/
protected RequestHandler createRequestHandler() {
return new RequestHandler() {
public boolean handleRequest(VaadinSession session,VaadinResponse response)
throws IOException {
if (request.getParameterMap().containsKey(getVerifierName())) {
String v = request.getParameter(getVerifierName());
Verifier verifier = new Verifier(v);
accesstoken = service
.getAccesstoken(requestToken,verifier);
User user = getUser();
VaadinSession.getCurrent().removeRequestHandler(handler);
handler = null;
//String url = getAuthUrl();
//callbackPage.open(url,"Authentificate",400,300,BorderStyle.DEFAULT);
authListener.userAuthenticated(user);
} else if (getFailureParameters() != null) {
for (String key : getFailureParameters()) {
if (request.getParameterMap().containsKey(key)) {
authListener.Failed(request.getParameter(key));
break;
}
}
}
return true;
}
};
}
@Override
public void onRequestStart(final VaadinRequest request,final VaadinResponse response)
{
updateMDC();
}
@Override
public void onRequestEnd(final VaadinRequest request,final VaadinResponse response,final VaadinSession session)
{
destroyMDC();
}
项目:cuba
文件:CubaWebJarsHandler.java
@Override
public boolean handleRequest(VaadinSession session,VaadinResponse response) throws IOException {
String path = request.getPathInfo();
if (StringUtils.isEmpty(path) || StringUtils.isNotEmpty(path) && !path.startsWith(VAADIN_WEBJARS_PREFIX)) {
return false;
}
log.trace("WebJar resource requested: {}",path.replace(VAADIN_WEBJARS_PREFIX,""));
String errorMessage = checkResourcePath(path);
if (StringUtils.isNotEmpty(errorMessage)) {
log.warn(errorMessage);
response.sendError(HttpServletResponse.SC_FORBIDDEN,errorMessage);
return false;
}
URL resourceUrl = getStaticResourceUrl(path);
if (resourceUrl == null) {
resourceUrl = getClassPathResourceUrl(path);
}
if (resourceUrl == null) {
String msg = String.format("Requested WebJar resource is not found: %s",path);
response.sendError(HttpServletResponse.SC_NOT_FOUND,msg);
log.warn(msg);
return false;
}
String resourceName = getResourceName(path);
String mimeType = servletContext.getMimeType(resourceName);
response.setContentType(mimeType != null ? mimeType : FileTypesHelper.DEFAULT_MIME_TYPE);
String cacheControl = "public,max-age=0,must-revalidate";
int resourceCacheTime = getCacheTime(resourceName);
if (resourceCacheTime > 0) {
cacheControl = "max-age=" + String.valueOf(resourceCacheTime);
}
response.setHeader("Cache-Control",cacheControl);
response.setDateHeader("Expires",System.currentTimeMillis() + (resourceCacheTime * 1000));
InputStream inputStream = null;
try {
URLConnection connection = resourceUrl.openConnection();
long lastModifiedTime = connection.getLastModified();
// Remove milliseconds to avoid comparison problems (milliseconds
// are not returned by the browser in the "If-Modified-Since"
// header).
lastModifiedTime = lastModifiedTime - lastModifiedTime % 1000;
response.setDateHeader("Last-Modified",lastModifiedTime);
if (browserHasNewestVersion(request,lastModifiedTime)) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return true;
}
inputStream = connection.getInputStream();
copy(inputStream,response.getoutputStream());
return true;
} finally {
if (inputStream != null) {
inputStream.close();
}
}
}
@Override
public boolean handleConnectorRequest(VaadinRequest request,String path) throws IOException {
this.getResource().setFilename(this.resource.getFilename());
return super.handleConnectorRequest(request,path);
}
@Override
public boolean handleConnectorRequest(VaadinRequest request,path);
}
项目:vaadin-oauthpopup
文件:OAuthCallbackRequestHandler.java
@Override
public boolean handleRequest(VaadinSession session,VaadinResponse response) throws IOException {
if (!data.isCallbackForMe(request)) {
return false;
}
String verifier = request.getParameter(data.getVerifierParameterName());
if (verifier != null) {
// Got verifier!
data.setVerifier(requestToken,new Verifier(verifier));
finish(session,response);
return true;
}
// No verifier in the parameters. That's most likely because the user
// denied the OAuth.
// Todo: current error message reporting (below) is not very useful
String error = null;
for (String errorName : data.getErrorParameterNames()) {
error = request.getParameter(errorName);
if (error != null) {
break;
}
}
String errorMessage;
if (error==null) {
errorMessage = "OAuth Failed.";
}
else {
errorMessage = "OAuth denied: " + error;
}
data.setDenied(errorMessage);
finish(session,response);
return true;
}
项目:vaadin-oauthpopup
文件:OAuthCallbackRequestHandler.java
private void finish(VaadinSession session,VaadinResponse response) throws IOException {
response.setContentType("text/html");
response.getWriter().append(CLOSE_WINDOW_HTML);
cleanUpSession(session);
}
项目:vaadin4spring
文件:VaadinRequestStartListener.java
/**
* Called before Vaadin starts handling a request.
*
* @param request The request
* @param response The response
* @see com.vaadin.server.VaadinService#requestStart(com.vaadin.server.VaadinRequest,com.vaadin.server.VaadinResponse)
*/
void onRequestStart(VaadinRequest request,VaadinResponse response);
项目:vaadin4spring
文件:VaadinRequestEndListener.java
/**
* Called after Vaadin has handled a request and the response has
* been written.
*
* @param request The request object
* @param response The response object
* @param session The session which was used during the request or null if the
* request did not use a session
* @see com.vaadin.server.VaadinService#requestEnd(com.vaadin.server.VaadinRequest,com.vaadin.server.VaadinResponse,com.vaadin.server.VaadinSession)
*/
void onRequestEnd(VaadinRequest request,VaadinSession session);