On Jan 29, 2010, at 8:51 AM, Ben Short <[email protected]> wrote:

> Thank you for the response.
>
> I have the following rough class.
>
> package com.daisytechnologies.basket;
>
> import org.apache.sling.api.SlingHttpServletRequest;
> import org.apache.sling.api.servlets.HtmlResponse;
> import org.apache.sling.servlets.post.SlingPostOperation;
> import org.apache.sling.servlets.post.SlingPostProcessor;
>
> import javax.jcr.Node;
> import javax.jcr.RepositoryException;
> import javax.jcr.Session;
> import javax.jcr.SimpleCredentials;
>
> /**
> *
> * @scr.component metatype="no" immediate="true"
> * @scr.service
> interface="org.apache.sling.servlets.post.SlingPostOperation"
> * @scr.property name="sling.post.operation" value="createBasket"
> */
> public class CreateBasketPostOperation implements SlingPostOperation {
>    public void run(SlingHttpServletRequest request, HtmlResponse
> htmlResponse, SlingPostProcessor[] slingPostProcessors) {
>
>        Session session =
> request.getResourceResolver().adaptTo(Session.class);
>
>        try {
>            Session superSession = session.getRepository().login(new
> SimpleCredentials("admin", "admin".toCharArray()));
>
>            final String path = request.getResource().getPath();
>
>            Node basketsNode = (Node)superSession.getItem(path);
>
>            Node basketNode =
> basketsNode.addNode(Long.toString(System.currentTimeMillis()));
>
>            htmlResponse.onCreated(basketNode.getPath());
>
>            superSession.save();
>            superSession.logout();
>        } catch (RepositoryException e) {
>            e.printStackTrace();
>        }
>
>    }
> }
>
> And the following in my pom
>
> <plugin>
>                <groupId>org.apache.felix</groupId>
>                <artifactId>maven-bundle-plugin</artifactId>
>                <extensions>true</extensions>
>                <configuration>
>                    <instructions>
>
> <Sling-Initial-Content>initial-
> content;overwrite:=true;uninstall=true</Sling-Initial-Content>
>                        <Private-Package>>
>                            com.daisytechnologies.basket
>                        </Private-Package>>
>                    </instructions>
>                </configuration>
>            </plugin>
>
> the bundle deploys ok but when I execute the following command
>
> curl -F":operation=addBasket" http://127.0.0.1:8080/mollycupcakes/baskets
>
> I get the following error..
>
> Status
> 500
> Message
> Invalid operation specified for POST request
> Location <http://127.0.0.1:8080/mollycupcakes/baskets>Parent
> Location<http://127.0.0.1:8080/mollycupcakes/baskets>
> Path
> Refererhttp://127.0.0.1:8080/mollycupcakesChangeLog
>
>
> any ideas where im going wrong?
>

Is the SCR XML file being generated? Is the Service registered?

> Also how do i inject the SlingRepository into the post operation?

Take a look at the SCR documentation.

Justin

>
> 2010/1/29 Bertrand Delacretaz <[email protected]>
>
>> On Fri, Jan 29, 2010 at 12:55 PM, Vidar Ramdal <[email protected]>
>> wrote:
>>> ....     Node basketsParent =
>> session.getItem(req.getResource().getPath());
>>>     Node basket = basketsParent.addNode(/* generate a unique name
>>> */);
>>> ...
>>
>> To "unique name" I'd add "impossible to guess" to prevent people from
>> messing up with other people's baskets.
>>
>> -Bertrand
>>

Reply via email to