-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload observing instead of intercepting #256
Merged
Turini
merged 7 commits into
DownloadObservingInsteadOfIntercepting
from
UploadObservingInsteadOfIntercepting
Nov 14, 2013
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
22c93a7
CommonsUploadMultipart: from interceptor to Observer
Turini ea295c9
NullMultipart: from Interceptor to Observer
Turini 6fcf7b9
fixing and renaming CommonsUploadMultipart tests
Turini 8c158af
fixing weird indent on setup method
Turini 547235b
adding new ControllerMethodDiscovered event
Turini 775a81b
firing and observing ControllerMethodDiscovered
Turini 6aba49b
moving for observer.upload package
Turini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
...e/src/main/java/br/com/caelum/vraptor/interceptor/multipart/NullMultipartInterceptor.java
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
...core/src/main/java/br/com/caelum/vraptor/interceptor/multipart/NullMultipartObserver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/*** | ||
* Copyright (c) 2009 Caelum - www.caelum.com.br/opensource | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package br.com.caelum.vraptor.interceptor.multipart; | ||
|
||
import static com.google.common.base.Strings.nullToEmpty; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import javax.enterprise.context.RequestScoped; | ||
import javax.enterprise.event.Observes; | ||
import javax.inject.Inject; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.slf4j.Logger; | ||
|
||
import br.com.caelum.vraptor.controller.ControllerMethod; | ||
|
||
/** | ||
* A null implementation of {@link MultipartInterceptor}. This interceptor will | ||
* be activated when no commons-fileupload was found in classpath. If application | ||
* try to upload any files, this interceptor will warn a message in console. | ||
* | ||
* @author Otávio Scherer Garcia | ||
* @author Rodrigo Turini | ||
* @since 3.1.3 | ||
*/ | ||
@RequestScoped | ||
public class NullMultipartObserver { | ||
|
||
private static final Logger logger = getLogger(NullMultipartObserver.class); | ||
|
||
private final HttpServletRequest request; | ||
|
||
/** | ||
* @deprecated CDI eyes only | ||
*/ | ||
protected NullMultipartObserver() { | ||
this(null); | ||
} | ||
|
||
@Inject | ||
public NullMultipartObserver(HttpServletRequest request) { | ||
this.request = request; | ||
} | ||
|
||
public void nullUpload(@Observes ControllerMethod controllerMethod) { | ||
if (request.getMethod().toUpperCase().equals("POST") | ||
&& nullToEmpty(request.getContentType()).startsWith("multipart/form-data")) { | ||
logger.warn("There is no file upload handlers registered. If you are willing to " | ||
+ "upload a file, please add the commons-fileupload in your classpath"); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the correct event? wasn't something like
ReadyToExecute
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need run it before
ParameterInstantiatorInterceptor
,ReadyToExecute
is fired afterThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.. where is it being fired? what else is observing this event?
ControllerMethod is not an event, it's a product of one. Maybe we should wrap it in another class...
Just maybe ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fired by ControllerLookupInterceptor,
observed by ControllerMethodFactory, NullMultipart and CommonsUploadMultipart
I think about that before using ControllerMethod directly, do you have a good name for this new event?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like
ControllerMethodDiscovered
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done here 775a81b