You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Dominique Jäggi <dj...@day.com> on 2008/10/06 22:29:12 UTC
Re: Half pre-processing a POST
On Mon, Oct 6, 2008 at 8:27 PM, Joshua Oransky <ca...@gmail.com> wrote:
> Is this possible? Kind of like the Servlet Filter concept, where I can
> process some of the request than then pass it along.
why don't you just use filtering then? take a look at the
org.apache.sling.sample.filter.ZipFilter sample.
greetings,
dom.
>
> -Josh
>
Re: Half pre-processing a POST
Posted by Joshua Oransky <ca...@gmail.com>.
How about this for the feature request:
The chain will continue if the response is not committed, and the
Sling servlet is allowed to continue processing the POST. But if I
commit the response, the chain breaks, and processing stops.
Does this make sense? Basically, I want an ability to make changes to
my files before they are stored (and with this paradigm, I could
technically change anything).
Thoughts?
-Josh
On Oct 6, 2008, at 11:56 PM, Joshua Oransky wrote:
> Because I want to keep all of my development inside of Sling.
> Besides, I only want to process this on certain resourceTypes;
> something that is already done by the whole Sling framework. In
> fact, if storing files from a form was as easy as storing text info,
> I wouldn't even need this... feature request?
>
> -Josh
>
> On Oct 6, 2008, at 1:29 PM, Dominique Jäggi wrote:
>
>> On Mon, Oct 6, 2008 at 8:27 PM, Joshua Oransky <ca...@gmail.com>
>> wrote:
>>> Is this possible? Kind of like the Servlet Filter concept, where I
>>> can
>>> process some of the request than then pass it along.
>>
>> why don't you just use filtering then? take a look at the
>> org.apache.sling.sample.filter.ZipFilter sample.
>>
>> greetings,
>> dom.
>>
>>>
>>> -Josh
>>>
>
Re: Half pre-processing a POST
Posted by Michael Marth <mm...@day.com>.
Bertrand, I think we discussed the same request here [1] and there were some
good suggestions, but I do not know if there was anything implemented.
Josh, I would also like to see your request be solved in general. However,
for your particular use case (thumbnail generation) there is an OSGi bundle
that uses JCR EventListeners here [2]
Michael
[1] http://dev.day.com/discussion-groups/content/lists.go/mlxxagiz
[2] https://issues.apache.org/jira/browse/SLING-673
On Wed, Oct 15, 2008 at 9:35 AM, Bertrand Delacretaz <bdelacretaz@apache.org
> wrote:
> Hi Josh,
>
> On Tue, Oct 14, 2008 at 10:07 PM, Joshua Oransky <ca...@gmail.com>
> wrote:
> > ...what I need is a way of processing those files before they are
> written.
> > My use case is that I want users to upload a single large image, and
> process
> > it with an image lib to generate thumbnails, etc. But I don't want to
> have
> > to write all the code to ALSO persist the text data, like image
> description,
> > etc...
>
> Ok - I think I would rather generate thumbnails and the like
> asynchronously, but in general being able to process files before
> storage makes sense.
>
> >... So what I want, is a way to handle storing of the files separately,
> but
> > leave the text data to the Sling servlet. Of course, one could also
> > intercept some of the text data as well. The point is how do I write code
> to
> > only worry about the stuff I need, and let Sling persist anything else
> > normally....
>
> What would be the unit of "stuff I need"? Would you want to process
> some request parameters and let Sling process some others, or is that
> something else?
>
> -Bertrand
>
--
Michael Marth | http://dev.day.com/
Re: Half pre-processing a POST
Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Josh,
On Tue, Oct 14, 2008 at 10:07 PM, Joshua Oransky <ca...@gmail.com> wrote:
> ...what I need is a way of processing those files before they are written.
> My use case is that I want users to upload a single large image, and process
> it with an image lib to generate thumbnails, etc. But I don't want to have
> to write all the code to ALSO persist the text data, like image description,
> etc...
Ok - I think I would rather generate thumbnails and the like
asynchronously, but in general being able to process files before
storage makes sense.
>... So what I want, is a way to handle storing of the files separately, but
> leave the text data to the Sling servlet. Of course, one could also
> intercept some of the text data as well. The point is how do I write code to
> only worry about the stuff I need, and let Sling persist anything else
> normally....
What would be the unit of "stuff I need"? Would you want to process
some request parameters and let Sling process some others, or is that
something else?
-Bertrand
Re: Half pre-processing a POST
Posted by Joshua Oransky <ca...@gmail.com>.
No, what I need is a way of processing those files before they are
written. My use case is that I want users to upload a single large
image, and process it with an image lib to generate thumbnails, etc.
But I don't want to have to write all the code to ALSO persist the
text data, like image description, etc...
So what I want, is a way to handle storing of the files separately,
but leave the text data to the Sling servlet. Of course, one could
also intercept some of the text data as well. The point is how do I
write code to only worry about the stuff I need, and let Sling persist
anything else normally.
-Josh
On Oct 13, 2008, at 1:52 AM, Bertrand Delacretaz wrote:
> On Tue, Oct 7, 2008 at 8:56 AM, Joshua Oransky <ca...@gmail.com>
> wrote:
>> ...In fact, if storing files from a
>> form was as easy as storing text info, I wouldn't even need this...
>> feature
>> request?...
>
> I'm not sure if I understand the problem - if you use a form like
>
> <form action="/content/foo/*" method="POST" enctype="multipart/form-
> data">
> <input type="file" name="attachments/*"/>
> <input type="submit"/>
> </form>
>
> the data is uploaded as a file under an "attachments" child node of
> the created node. Isn't that what you need?
>
> The SLING-673 blog sample uses this.
>
> -Bertrand
Re: Half pre-processing a POST
Posted by Bertrand Delacretaz <bd...@apache.org>.
On Tue, Oct 7, 2008 at 8:56 AM, Joshua Oransky <ca...@gmail.com> wrote:
> ...In fact, if storing files from a
> form was as easy as storing text info, I wouldn't even need this... feature
> request?...
I'm not sure if I understand the problem - if you use a form like
<form action="/content/foo/*" method="POST" enctype="multipart/form-data">
<input type="file" name="attachments/*"/>
<input type="submit"/>
</form>
the data is uploaded as a file under an "attachments" child node of
the created node. Isn't that what you need?
The SLING-673 blog sample uses this.
-Bertrand
Re: Half pre-processing a POST
Posted by Dominique Jäggi <dj...@day.com>.
On Tue, Oct 7, 2008 at 8:56 AM, Joshua Oransky <ca...@gmail.com> wrote:
> Because I want to keep all of my development inside of Sling. Besides, I
> only want to process this on certain resourceTypes; something that is
> already done by the whole Sling framework. In fact, if storing files from a
> form was as easy as storing text info, I wouldn't even need this... feature
> request?
maybe i am completely misunderstanding your use case, but i still
think that a filter does the job. you operate completely within sling
and have a configurable OSGI component as well. i hacked up an
untested sample:
package my.package;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.request.RequestParameter;
import org.apache.sling.api.resource.Resource;
import org.osgi.service.component.ComponentContext;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Dictionary;
import java.util.List;
/**
* @scr.component label="My Filter" description="Filters file uploads."
*/
public class MyPostFilter implements Filter {
/**
* @scr.property values.0="myapp/components/name"
* label="Resource types to observe"
*/
private static final String RESOURCE_TYPES = "workspacename";
private List<String> resourceTypes = new ArrayList<String>();
public void init(FilterConfig filterConfig) {
}
public void doFilter(ServletRequest request, ServletResponse
response, FilterChain chain) throws IOException, ServletException {
final SlingHttpServletRequest slingRequest =
(SlingHttpServletRequest) request;
final Resource resource = slingRequest.getResource();
if (resourceTypes.contains(resource.getResourceType())) {
final Collection<RequestParameter[]> parameters =
slingRequest.getRequestParameterMap().values();
for (RequestParameter[] parameter : parameters) {
for (RequestParameter param : parameter) {
if (param.isFormField() && 0 < param.getSize()) {
// identified file
final InputStream inputStream = param.getInputStream();
// process stream....
}
}
}
}
// continue filtering
chain.doFilter(request, response);
}
public void destroy() {
}
protected void activate(ComponentContext context) {
final Dictionary properties = context.getProperties();
final String[] paths = (String[]) properties.get(RESOURCE_TYPES);
resourceTypes.addAll(Arrays.asList(paths));
}
}
greetings,
dom.
Re: Half pre-processing a POST
Posted by Joshua Oransky <ca...@gmail.com>.
Because I want to keep all of my development inside of Sling. Besides,
I only want to process this on certain resourceTypes; something that
is already done by the whole Sling framework. In fact, if storing
files from a form was as easy as storing text info, I wouldn't even
need this... feature request?
-Josh
On Oct 6, 2008, at 1:29 PM, Dominique Jäggi wrote:
> On Mon, Oct 6, 2008 at 8:27 PM, Joshua Oransky <ca...@gmail.com>
> wrote:
>> Is this possible? Kind of like the Servlet Filter concept, where I
>> can
>> process some of the request than then pass it along.
>
> why don't you just use filtering then? take a look at the
> org.apache.sling.sample.filter.ZipFilter sample.
>
> greetings,
> dom.
>
>>
>> -Josh
>>