On Fri, Jan 29, 2010 at 2:51 PM, 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?
Check the Felix web console (http://localhost:8080/system/console/bundles) and see that your bundle is listed there, and is "active". If it is not, click to expand it and check if any of the imports are listed in red. You can also tail your sling.log, and see what is output when you start your bundle. > Also how do i inject the SlingRepository into the post operation? You just declare it with a /** @scr.reference */ annotation: /** @scr.reference */ private SlingRepository repository; -- Vidar S. Ramdal <[email protected]> - http://www.idium.no Sommerrogata 13-15, N-0255 Oslo, Norway + 47 22 00 84 00 / +47 21 531941, ext 2070
