Re: Beginners question with Sling.

2011-07-08 Thread Phil Rice
Thank you all for you help and advice

I have to say that I am struggling with Apache Sling. I am an experienced
developer, and have put the time in: I think I am on day 5 now, and while I
am running launchpad, I am getting nowhere flat with using it from the Java
Code. To be honest am getting quite demoralized over it. I missed the email
about the developer version of CRX, so I will get that and play with it. I
am quite keen to stay in the open source world, although I take your point
that its a very good way to learn about the language.

So I have a specific pain at the moment. The code sample I gave in the first
post is still not working, although the HTML post is (thank you: that gave
me a feel good factor that this project actually works). The advise to use
Firebug was very good and caused me to add a couple of headers.

DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(new AuthScope("localhost",
8080), new UsernamePasswordCredentials("admin", "admin"));

String nodeName = "newNodeb8";
List formParams = Arrays. asList(new
BasicNameValuePair("param1", "value1"), new BasicNameValuePair("param2",
"value2"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams, "UTF-8");
HttpPost action = new HttpPost("http://localhost:8080/"; + nodeName);
action.addHeader("Content-Type", "application/x-www-form-urlencoded");
action.addHeader("enctype", "multipart/form-data");
action.setEntity(entity);
HttpResponse response = client.execute(action);

System.out.println("Status: " + response.getStatusLine().getStatusCode());
System.out.println("Reason: " + response.getStatusLine().getReasonPhrase());
System.out.println("Reason: " + response.getStatusLine());

HttpEntity responseEntity = response.getEntity();
String page = responseEntity == null ? "" :
EntityUtils.toString(responseEntity);
System.out.println("Response");
System.out.println(page);

The result is:

Status: 500
Reason: Internal Server Error
Reason: HTTP/1.1 500 Internal Server Error
Response


Error while processing /newNodeb8


Error while processing /newNodeb8



Status
500


Message
javax.jcr.AccessDeniedException:
/newNodeb8/param2: not allowed to add or modify item


Location
/newNodeb8


Parent Location
/


Path
/newNodeb8


Referer



ChangeLog
created("/newNodeb8");modified("/newNodeb8/param1");modified("/newNodeb8/param2");



Go Back
Modified Resource
Parent of Modified Resource




The response I get indicates that I have a security problem. I suspect that
there is an error in the credentials. Of course as luck would have it the
apache http client API has just had a radical rewrite and all the tutorials
and advise are for the old interface... Do any of you have a code snippet
like this that actually works?

When I get this working, I'll write it up as a tutorial about using it from
Java!


On Thu, Jul 7, 2011 at 2:32 PM, Mark Herman  wrote:

> "You could probably use their tools to create bundles then just deploy the
> bundles to your sling instance."
>
> Just need to say that using their tools in this manor may violate the
> developer edition's license agreement, I don't know.  I'd still suggest
> looking into the product to help learn the language, but make sure you
> carefully read the license agreement before actually deploying bundles to
> sling.
>
> -Original Message-
> From: Mark Herman
> Sent: Thursday, July 07, 2011 9:04 AM
> To: users@sling.apache.org
> Subject: RE: Beginners question with Sling.
>
> In reference to ESP vs JSP:
>
> You may be able to use Day CRX (now Adobe) documentation as a resource.
>
> They have a series of blogs called "CRX Gems." Some are product specific
> but
> most are really just taking advantage of sling.
>
> http://dev.day.com/content/ddc/blog.html?_charset_=ISO-8859-1&query=crx+gems&;
> main_entries_start=15&blog=search&y=0&x=0
> Page back into newer topics as well.
>
> Here are some links that I have stashed away that may be of interest to
> you:
> http://dev.day.com/content/ddc/blog/2010/07/learning_about_espv.html
> https://cwiki.apache.org/SLING/scripting-variables.html
>
> http://www.lucamasini.net/Home/sling-and-cq5/accessing-relational-data-as-sli
> ng-restful-urls
>
> I recently looked into whether to go with ESP or JSP and decided to go with
> JSP for the following reasons:
>  - JSP is more standard, easier for others to jump on a project
>  - As you have found documentation for ESP is scarce.
>  - I wasn't able to find any advantages of using ESP besides that the
> common
> sling objects are pro

Re: Beginners question with Sling.

2011-07-08 Thread Alexander Klimetschek
On 08.07.11 10:39, "Phil Rice"  wrote:
>DefaultHttpClient client = new DefaultHttpClient();
>client.getCredentialsProvider().setCredentials(new AuthScope("localhost",
>8080), new UsernamePasswordCredentials("admin", "admin"));

I guess you need to use preemptive auth:

client.getParams().setAuthenticationPreemptive(true);

http://hc.apache.org/httpclient-3.x/authentication.html


Regards,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel






Re: Beginners question with Sling.

2011-07-08 Thread Julian Sedding
Hi Phil

Check out the integration tests, as Bertrand suggested. In the class
AbstractAuthenticatedTest[0] there is pretty much the same code you're
trying to write. I think that should get you going.

Regards
Julian

[0] 
http://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/AbstractAuthenticatedTest.java




On Fri, Jul 8, 2011 at 11:19 AM, Alexander Klimetschek
 wrote:
> On 08.07.11 10:39, "Phil Rice"  wrote:
>>DefaultHttpClient client = new DefaultHttpClient();
>>client.getCredentialsProvider().setCredentials(new AuthScope("localhost",
>>8080), new UsernamePasswordCredentials("admin", "admin"));
>
> I guess you need to use preemptive auth:
>
> client.getParams().setAuthenticationPreemptive(true);
>
> http://hc.apache.org/httpclient-3.x/authentication.html
>
>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> Developer // Adobe (Day) // Berlin - Basel
>
>
>
>
>


Re: Beginners question with Sling.

2011-07-08 Thread Phil Rice
Thanks for the help Alex. Unfortunately that is one of the things that has
changed in the new API. Its no longer a method available from the
parameters. However the advice to follow the test framework was very good
and the following now works. I can rip this apart and reduce to to the
minimum working, which I will post for the benefit of anyone else trying to
do this.

DefaultHttpClient httpClient = new DefaultHttpClient();
RequestExecutor executor = new RequestExecutor(httpClient);

String nodeName = "slingNode1";

List formParams = Arrays. asList(new
BasicNameValuePair("param1", "value1"), new BasicNameValuePair("param2",
"value2"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams, "UTF-8");
System.out.println(executor.execute(requestBuilder.buildPostRequest(nodeName).withEntity(entity).withCredentials("admin",
"admin")).getContent());
System.out.println(executor.execute(requestBuilder.buildGetRequest(nodeName
+ ".json")).getContent());

Once again thanks for all the help, and I look forward to seeing some of you
in September at Berlin.

Phil

On Fri, Jul 8, 2011 at 10:19 AM, Alexander Klimetschek
wrote:

> On 08.07.11 10:39, "Phil Rice"  wrote:
> >DefaultHttpClient client = new DefaultHttpClient();
> >client.getCredentialsProvider().setCredentials(new AuthScope("localhost",
> >8080), new UsernamePasswordCredentials("admin", "admin"));
>
> I guess you need to use preemptive auth:
>
> client.getParams().setAuthenticationPreemptive(true);
>
> http://hc.apache.org/httpclient-3.x/authentication.html
>
>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> Developer // Adobe (Day) // Berlin - Basel
>
>
>
>
>


Re: Beginners question with Sling.

2011-07-08 Thread Phil Rice
Also thanks Julain/Bertand. I now have about the simplest hello world
program working. I suspect as I get further into the project, I will need to
look at the authentication system a lot more thoroughly, but for now I am
happy with just being able to POST and GET data!

public class PopulateRepository {
public static void main(String[] args) throws Exception {
String nodeName = "newNodea";
String userName = "admin";
String password = "admin";

DefaultHttpClient client = new DefaultHttpClient();
client.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0);
client.getCredentialsProvider().setCredentials(new AuthScope("localhost",
8080), new UsernamePasswordCredentials(userName, password));
UrlEncodedFormEntity entity = new
UrlEncodedFormEntity(Arrays. asList(new
BasicNameValuePair("param1", "value11"), new BasicNameValuePair("param2",
"valueq")), "UTF-8");
HttpPost action = new HttpPost("http://localhost:8080/"; + nodeName);
action.setEntity(entity);
HttpResponse response = client.execute(action);

System.out.println("Status: " + response.getStatusLine().getStatusCode());
}

private static class PreemptiveAuthInterceptor implements
HttpRequestInterceptor {

@Override
public void process(HttpRequest request, HttpContext context) throws
HttpException, IOException {

AuthState authState = (AuthState)
context.getAttribute(ClientContext.TARGET_AUTH_STATE);
CredentialsProvider credsProvider = (CredentialsProvider)
context.getAttribute(ClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost)
context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);

// If not auth scheme has been initialized yet
if (authState.getAuthScheme() == null) {
AuthScope authScope = new AuthScope(targetHost.getHostName(),
targetHost.getPort());

// Obtain credentials matching the target host
Credentials creds = credsProvider.getCredentials(authScope);

// If found, generate BasicScheme preemptively
if (creds != null) {
authState.setAuthScheme(new BasicScheme());
authState.setCredentials(creds);
}
}
}
}
}


On Fri, Jul 8, 2011 at 11:43 AM, Phil Rice  wrote:

> Thanks for the help Alex. Unfortunately that is one of the things that has
> changed in the new API. Its no longer a method available from the
> parameters. However the advice to follow the test framework was very good
> and the following now works. I can rip this apart and reduce to to the
> minimum working, which I will post for the benefit of anyone else trying to
> do this.
>
> DefaultHttpClient httpClient = new DefaultHttpClient();
> RequestExecutor executor = new RequestExecutor(httpClient);
>
> String nodeName = "slingNode1";
>
> List formParams = Arrays. asList(new
> BasicNameValuePair("param1", "value1"), new BasicNameValuePair("param2",
> "value2"));
>  UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams,
> "UTF-8");
> System.out.println(executor.execute(requestBuilder.buildPostRequest(nodeName).withEntity(entity).withCredentials("admin",
> "admin")).getContent());
>  System.out.println(executor.execute(requestBuilder.buildGetRequest(nodeName
> + ".json")).getContent());
>
> Once again thanks for all the help, and I look forward to seeing some of
> you in September at Berlin.
>
> Phil
>
> On Fri, Jul 8, 2011 at 10:19 AM, Alexander Klimetschek  > wrote:
>
>> On 08.07.11 10:39, "Phil Rice"  wrote:
>> >DefaultHttpClient client = new DefaultHttpClient();
>> >client.getCredentialsProvider().setCredentials(new AuthScope("localhost",
>> >8080), new UsernamePasswordCredentials("admin", "admin"));
>>
>> I guess you need to use preemptive auth:
>>
>> client.getParams().setAuthenticationPreemptive(true);
>>
>> http://hc.apache.org/httpclient-3.x/authentication.html
>>
>>
>> Regards,
>> Alex
>>
>> --
>> Alexander Klimetschek
>> Developer // Adobe (Day) // Berlin - Basel
>>
>>
>>
>>
>>
>


Re: Beginners question with Sling.

2011-07-08 Thread sam lee
Out of curiosity, why are you using Java and access Sling through HTTP?

If you really like Java, you can create an OSGi bundle and deploy the bundle
to Sling (felix, /system/console).

You can put Servlets and other useful utilities in the bundle.
And, you can access the repository directly without going through HTTP, but
through JCR or Sling API.




On Fri, Jul 8, 2011 at 6:43 AM, Phil Rice
wrote:

> Thanks for the help Alex. Unfortunately that is one of the things that has
> changed in the new API. Its no longer a method available from the
> parameters. However the advice to follow the test framework was very good
> and the following now works. I can rip this apart and reduce to to the
> minimum working, which I will post for the benefit of anyone else trying to
> do this.
>
> DefaultHttpClient httpClient = new DefaultHttpClient();
> RequestExecutor executor = new RequestExecutor(httpClient);
>
> String nodeName = "slingNode1";
>
> List formParams = Arrays. asList(new
> BasicNameValuePair("param1", "value1"), new BasicNameValuePair("param2",
> "value2"));
> UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams,
> "UTF-8");
>
> System.out.println(executor.execute(requestBuilder.buildPostRequest(nodeName).withEntity(entity).withCredentials("admin",
> "admin")).getContent());
> System.out.println(executor.execute(requestBuilder.buildGetRequest(nodeName
> + ".json")).getContent());
>
> Once again thanks for all the help, and I look forward to seeing some of
> you
> in September at Berlin.
>
> Phil
>
> On Fri, Jul 8, 2011 at 10:19 AM, Alexander Klimetschek
> wrote:
>
> > On 08.07.11 10:39, "Phil Rice"  wrote:
> > >DefaultHttpClient client = new DefaultHttpClient();
> > >client.getCredentialsProvider().setCredentials(new
> AuthScope("localhost",
> > >8080), new UsernamePasswordCredentials("admin", "admin"));
> >
> > I guess you need to use preemptive auth:
> >
> > client.getParams().setAuthenticationPreemptive(true);
> >
> > http://hc.apache.org/httpclient-3.x/authentication.html
> >
> >
> > Regards,
> > Alex
> >
> > --
> > Alexander Klimetschek
> > Developer // Adobe (Day) // Berlin - Basel
> >
> >
> >
> >
> >
>


Re: Beginners question with Sling.

2011-07-08 Thread Julian Sedding
Hi Phil

Typically when working with Sling you don't access it via HTTP a lot.
Rather you work "within" Sling. I.e. you write scripts that run within
an authenticated request (which typically originates from a browser).
I believe that getting "inside" Sling can be a little tricky at the
beginning and that's where CRX with its tooling can certainly help.

Assuming you know roughly what Jackrabbit/JCR is, the first steps I
recommend are:
* understand resource resolution[0]: how does Sling map URL paths to
Sling resources
* understand script resolution[1]: in Sling you address content, the
content knows where to find its rendering script(s) via the
sling:resourceType property
* once you understand these two concepts, you can look at the
FileSystem Provider[2], which allows you to map a filesystem path into
Sling's resource tree. This can be helpful for editing rendering
scripts outside the repository, which is easier without more
sophisticated tooling.

Hope that helps more than it confuses ;)

Regards
Julian


[0] http://sling.apache.org/site/url-decomposition.html
[1] http://dev.day.com/content/ddc/blog/2008/07/cheatsheet.html
[2] http://sling.apache.org/site/downloads.cgi -> download FileSystem
Provider bundle and install in /system/console/bundles




On Fri, Jul 8, 2011 at 1:09 PM, sam lee  wrote:
> Out of curiosity, why are you using Java and access Sling through HTTP?
>
> If you really like Java, you can create an OSGi bundle and deploy the bundle
> to Sling (felix, /system/console).
>
> You can put Servlets and other useful utilities in the bundle.
> And, you can access the repository directly without going through HTTP, but
> through JCR or Sling API.
>
>
>
>
> On Fri, Jul 8, 2011 at 6:43 AM, Phil Rice
> wrote:
>
>> Thanks for the help Alex. Unfortunately that is one of the things that has
>> changed in the new API. Its no longer a method available from the
>> parameters. However the advice to follow the test framework was very good
>> and the following now works. I can rip this apart and reduce to to the
>> minimum working, which I will post for the benefit of anyone else trying to
>> do this.
>>
>> DefaultHttpClient httpClient = new DefaultHttpClient();
>> RequestExecutor executor = new RequestExecutor(httpClient);
>>
>> String nodeName = "slingNode1";
>>
>> List formParams = Arrays. asList(new
>> BasicNameValuePair("param1", "value1"), new BasicNameValuePair("param2",
>> "value2"));
>> UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams,
>> "UTF-8");
>>
>> System.out.println(executor.execute(requestBuilder.buildPostRequest(nodeName).withEntity(entity).withCredentials("admin",
>> "admin")).getContent());
>> System.out.println(executor.execute(requestBuilder.buildGetRequest(nodeName
>> + ".json")).getContent());
>>
>> Once again thanks for all the help, and I look forward to seeing some of
>> you
>> in September at Berlin.
>>
>> Phil
>>
>> On Fri, Jul 8, 2011 at 10:19 AM, Alexander Klimetschek
>> wrote:
>>
>> > On 08.07.11 10:39, "Phil Rice"  wrote:
>> > >DefaultHttpClient client = new DefaultHttpClient();
>> > >client.getCredentialsProvider().setCredentials(new
>> AuthScope("localhost",
>> > >8080), new UsernamePasswordCredentials("admin", "admin"));
>> >
>> > I guess you need to use preemptive auth:
>> >
>> > client.getParams().setAuthenticationPreemptive(true);
>> >
>> > http://hc.apache.org/httpclient-3.x/authentication.html
>> >
>> >
>> > Regards,
>> > Alex
>> >
>> > --
>> > Alexander Klimetschek
>> > Developer // Adobe (Day) // Berlin - Basel
>> >
>> >
>> >
>> >
>> >
>>
>


Re: Beginners question with Sling.

2011-07-08 Thread Bertrand Delacretaz
On Fri, Jul 8, 2011 at 1:31 PM, Julian Sedding  wrote:
> ...Typically when working with Sling you don't access it via HTTP a lot.
> Rather you work "within" Sling. I.e. you write scripts that run within
> an authenticated request (which typically originates from a browser).
> I believe that getting "inside" Sling can be a little tricky at the
> beginning and that's where CRX with its tooling can certainly help

Though our samples, like the Slingbucks one, [1] will show you how to
combine java and scripting code to create applications with Sling.

-Bertrand

[1] http://svn.apache.org/repos/asf/sling/trunk/samples/slingbucks


Re: Beginners question with Sling.

2011-07-08 Thread Phil Rice
@Sam Lee
"Why do you want to access through Java" My client is going to be an Eclipse
Plugin. In practice I will probably use Scala or Clojure, but I didn't want
to pollute my pitiful request for help with language issues. I think Sling
looks like an excellent remote repository for a mixture of structured and
unstructured data.

@Julian
I take your point. I think all I really needed was the hello world program
to post data in, and get data out. One of the things I really like about
Sling (although I haven't got it working yet) is that I can effectively ask
for an object graph with one query.

Example: I am making a project data repository. My data structure holds data
such as "software projects", "releases", "classes", "methods". Some "fields"
are mandatory, but many will be freeform. The relationship between these
entities is complex. As an example the method setXXX may exist across
multiple versions, but perhaps change what it does, so displaying comments
and documentation about that method requires business knowledge. As I
understand it, in a single query about a method, I can return data about the
method, but I can walk the repository tree (I don't have the sling language
yet...give me time) and return data about the method, the class that holds
it, the releases that the class is in, and the project that the holds the
data about the class.

Your checklist looks like a training plan. My first plan was to make a plug
in that was very chatty: I make a query for each entity, perhaps 20 queries
for a screen full of data. This would allow me to gain experience with
sling, eclipse plugins etc, and give me something "shiny" to discuss with
potential users. Once I have that working, I will be doing a lot more work
to reduce it to (hopefull) one request, at which point I will be using a lot
more of the sling tools

@Bertrand
Thanks for the slingbucks example, I'll start with that and if I get stuck
move onto CRX.

@All
Once again thank you for the assistance


On Fri, Jul 8, 2011 at 12:41 PM, Bertrand Delacretaz  wrote:

> On Fri, Jul 8, 2011 at 1:31 PM, Julian Sedding  wrote:
> > ...Typically when working with Sling you don't access it via HTTP a lot.
> > Rather you work "within" Sling. I.e. you write scripts that run within
> > an authenticated request (which typically originates from a browser).
> > I believe that getting "inside" Sling can be a little tricky at the
> > beginning and that's where CRX with its tooling can certainly help
>
> Though our samples, like the Slingbucks one, [1] will show you how to
> combine java and scripting code to create applications with Sling.
>
> -Bertrand
>
> [1] http://svn.apache.org/repos/asf/sling/trunk/samples/slingbucks
>


Re: Beginners question with Sling.

2011-07-08 Thread sam lee
Why don't  you use Jackrabbit via DavEx or RMI?
http://wiki.apache.org/jackrabbit/RemoteAccess

I don't think Sling is a remote repository.

I'm not sure what you meant by "a mixture of structured and unstructured
data".
Have you looked at other databases such as CouchDB or MongoDB?



On Fri, Jul 8, 2011 at 8:05 AM, Phil Rice
wrote:

> @Sam Lee
> "Why do you want to access through Java" My client is going to be an
> Eclipse
> Plugin. In practice I will probably use Scala or Clojure, but I didn't want
> to pollute my pitiful request for help with language issues. I think Sling
> looks like an excellent remote repository for a mixture of structured and
> unstructured data.
>
> @Julian
> I take your point. I think all I really needed was the hello world program
> to post data in, and get data out. One of the things I really like about
> Sling (although I haven't got it working yet) is that I can effectively ask
> for an object graph with one query.
>
> Example: I am making a project data repository. My data structure holds
> data
> such as "software projects", "releases", "classes", "methods". Some
> "fields"
> are mandatory, but many will be freeform. The relationship between these
> entities is complex. As an example the method setXXX may exist across
> multiple versions, but perhaps change what it does, so displaying comments
> and documentation about that method requires business knowledge. As I
> understand it, in a single query about a method, I can return data about
> the
> method, but I can walk the repository tree (I don't have the sling language
> yet...give me time) and return data about the method, the class that holds
> it, the releases that the class is in, and the project that the holds the
> data about the class.
>
> Your checklist looks like a training plan. My first plan was to make a plug
> in that was very chatty: I make a query for each entity, perhaps 20 queries
> for a screen full of data. This would allow me to gain experience with
> sling, eclipse plugins etc, and give me something "shiny" to discuss with
> potential users. Once I have that working, I will be doing a lot more work
> to reduce it to (hopefull) one request, at which point I will be using a
> lot
> more of the sling tools
>
> @Bertrand
> Thanks for the slingbucks example, I'll start with that and if I get stuck
> move onto CRX.
>
> @All
> Once again thank you for the assistance
>
>
> On Fri, Jul 8, 2011 at 12:41 PM, Bertrand Delacretaz <
> bdelacre...@apache.org
> > wrote:
>
> > On Fri, Jul 8, 2011 at 1:31 PM, Julian Sedding 
> wrote:
> > > ...Typically when working with Sling you don't access it via HTTP a
> lot.
> > > Rather you work "within" Sling. I.e. you write scripts that run within
> > > an authenticated request (which typically originates from a browser).
> > > I believe that getting "inside" Sling can be a little tricky at the
> > > beginning and that's where CRX with its tooling can certainly help
> >
> > Though our samples, like the Slingbucks one, [1] will show you how to
> > combine java and scripting code to create applications with Sling.
> >
> > -Bertrand
> >
> > [1] http://svn.apache.org/repos/asf/sling/trunk/samples/slingbucks
> >
>


Re: Beginners question with Sling.

2011-07-08 Thread Justin Edelson
On Fri, Jul 8, 2011 at 8:51 AM, sam lee  wrote:
> Why don't  you use Jackrabbit via DavEx or RMI?
> http://wiki.apache.org/jackrabbit/RemoteAccess

DavEX and RMI are both fairly heavyweight. IIUC, the use case is
similar to remote logging where simple data is posted from lots of
clients to a central repository in a stateless fashion. Sling is well
suited to this use case.

>
> I don't think Sling is a remote repository.

That's true to some extent (in that Sling isn't a repository), but
Sling is a good toolset for building HTTP services to access a
repository remotely. The default GET and POST servlets provide most of
what one might need and additional servlets or scripts can be created
as neeeded.

>
> I'm not sure what you meant by "a mixture of structured and unstructured
> data".
> Have you looked at other databases such as CouchDB or MongoDB?

IIUC, neither CouchDB nor MongoDB provide anything approaching the
security requirements something like this would require. And, like
DavEX or RMI to Jackrabbit, you're accessing the datastore using a
fairly low-level API. Sling enables you to easily create higher level
HTTP-based APIs (and provides its own in the form of the default
servlets).

Justin

>
>
>
> On Fri, Jul 8, 2011 at 8:05 AM, Phil Rice
> wrote:
>
>> @Sam Lee
>> "Why do you want to access through Java" My client is going to be an
>> Eclipse
>> Plugin. In practice I will probably use Scala or Clojure, but I didn't want
>> to pollute my pitiful request for help with language issues. I think Sling
>> looks like an excellent remote repository for a mixture of structured and
>> unstructured data.
>>
>> @Julian
>> I take your point. I think all I really needed was the hello world program
>> to post data in, and get data out. One of the things I really like about
>> Sling (although I haven't got it working yet) is that I can effectively ask
>> for an object graph with one query.
>>
>> Example: I am making a project data repository. My data structure holds
>> data
>> such as "software projects", "releases", "classes", "methods". Some
>> "fields"
>> are mandatory, but many will be freeform. The relationship between these
>> entities is complex. As an example the method setXXX may exist across
>> multiple versions, but perhaps change what it does, so displaying comments
>> and documentation about that method requires business knowledge. As I
>> understand it, in a single query about a method, I can return data about
>> the
>> method, but I can walk the repository tree (I don't have the sling language
>> yet...give me time) and return data about the method, the class that holds
>> it, the releases that the class is in, and the project that the holds the
>> data about the class.
>>
>> Your checklist looks like a training plan. My first plan was to make a plug
>> in that was very chatty: I make a query for each entity, perhaps 20 queries
>> for a screen full of data. This would allow me to gain experience with
>> sling, eclipse plugins etc, and give me something "shiny" to discuss with
>> potential users. Once I have that working, I will be doing a lot more work
>> to reduce it to (hopefull) one request, at which point I will be using a
>> lot
>> more of the sling tools
>>
>> @Bertrand
>> Thanks for the slingbucks example, I'll start with that and if I get stuck
>> move onto CRX.
>>
>> @All
>> Once again thank you for the assistance
>>
>>
>> On Fri, Jul 8, 2011 at 12:41 PM, Bertrand Delacretaz <
>> bdelacre...@apache.org
>> > wrote:
>>
>> > On Fri, Jul 8, 2011 at 1:31 PM, Julian Sedding 
>> wrote:
>> > > ...Typically when working with Sling you don't access it via HTTP a
>> lot.
>> > > Rather you work "within" Sling. I.e. you write scripts that run within
>> > > an authenticated request (which typically originates from a browser).
>> > > I believe that getting "inside" Sling can be a little tricky at the
>> > > beginning and that's where CRX with its tooling can certainly help
>> >
>> > Though our samples, like the Slingbucks one, [1] will show you how to
>> > combine java and scripting code to create applications with Sling.
>> >
>> > -Bertrand
>> >
>> > [1] http://svn.apache.org/repos/asf/sling/trunk/samples/slingbucks
>> >
>>
>


Re: Beginners question with Sling.

2011-07-08 Thread Justin Edelson
On Fri, Jul 8, 2011 at 7:31 AM, Julian Sedding  wrote:
> Hi Phil
>
> Typically when working with Sling you don't access it via HTTP a lot.

How do you figure? Seem to me that Sling applications are almost
always accessed via HTTP.

Justin


> Rather you work "within" Sling. I.e. you write scripts that run within
> an authenticated request (which typically originates from a browser).
> I believe that getting "inside" Sling can be a little tricky at the
> beginning and that's where CRX with its tooling can certainly help.
>
> Assuming you know roughly what Jackrabbit/JCR is, the first steps I
> recommend are:
> * understand resource resolution[0]: how does Sling map URL paths to
> Sling resources
> * understand script resolution[1]: in Sling you address content, the
> content knows where to find its rendering script(s) via the
> sling:resourceType property
> * once you understand these two concepts, you can look at the
> FileSystem Provider[2], which allows you to map a filesystem path into
> Sling's resource tree. This can be helpful for editing rendering
> scripts outside the repository, which is easier without more
> sophisticated tooling.
>
> Hope that helps more than it confuses ;)
>
> Regards
> Julian
>
>
> [0] http://sling.apache.org/site/url-decomposition.html
> [1] http://dev.day.com/content/ddc/blog/2008/07/cheatsheet.html
> [2] http://sling.apache.org/site/downloads.cgi -> download FileSystem
> Provider bundle and install in /system/console/bundles
>
>
>
>
> On Fri, Jul 8, 2011 at 1:09 PM, sam lee  wrote:
>> Out of curiosity, why are you using Java and access Sling through HTTP?
>>
>> If you really like Java, you can create an OSGi bundle and deploy the bundle
>> to Sling (felix, /system/console).
>>
>> You can put Servlets and other useful utilities in the bundle.
>> And, you can access the repository directly without going through HTTP, but
>> through JCR or Sling API.
>>
>>
>>
>>
>> On Fri, Jul 8, 2011 at 6:43 AM, Phil Rice
>> wrote:
>>
>>> Thanks for the help Alex. Unfortunately that is one of the things that has
>>> changed in the new API. Its no longer a method available from the
>>> parameters. However the advice to follow the test framework was very good
>>> and the following now works. I can rip this apart and reduce to to the
>>> minimum working, which I will post for the benefit of anyone else trying to
>>> do this.
>>>
>>> DefaultHttpClient httpClient = new DefaultHttpClient();
>>> RequestExecutor executor = new RequestExecutor(httpClient);
>>>
>>> String nodeName = "slingNode1";
>>>
>>> List formParams = Arrays. asList(new
>>> BasicNameValuePair("param1", "value1"), new BasicNameValuePair("param2",
>>> "value2"));
>>> UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams,
>>> "UTF-8");
>>>
>>> System.out.println(executor.execute(requestBuilder.buildPostRequest(nodeName).withEntity(entity).withCredentials("admin",
>>> "admin")).getContent());
>>> System.out.println(executor.execute(requestBuilder.buildGetRequest(nodeName
>>> + ".json")).getContent());
>>>
>>> Once again thanks for all the help, and I look forward to seeing some of
>>> you
>>> in September at Berlin.
>>>
>>> Phil
>>>
>>> On Fri, Jul 8, 2011 at 10:19 AM, Alexander Klimetschek
>>> wrote:
>>>
>>> > On 08.07.11 10:39, "Phil Rice"  wrote:
>>> > >DefaultHttpClient client = new DefaultHttpClient();
>>> > >client.getCredentialsProvider().setCredentials(new
>>> AuthScope("localhost",
>>> > >8080), new UsernamePasswordCredentials("admin", "admin"));
>>> >
>>> > I guess you need to use preemptive auth:
>>> >
>>> > client.getParams().setAuthenticationPreemptive(true);
>>> >
>>> > http://hc.apache.org/httpclient-3.x/authentication.html
>>> >
>>> >
>>> > Regards,
>>> > Alex
>>> >
>>> > --
>>> > Alexander Klimetschek
>>> > Developer // Adobe (Day) // Berlin - Basel
>>> >
>>> >
>>> >
>>> >
>>> >
>>>
>>
>


Re: Beginners question with Sling.

2011-07-08 Thread Phil Rice
> "Why don't  you use Jackrabbit via DavEx or RMI?"
Good question. I was looking for a REST interface to Jackrabbit. I
don't like RMI. I don't like it a lot. IMHO Remote Procedure Calls
come into the category of a Very Bad Idea (TM), but that discussion
has been done to death. I'm not actually familiar with DavEx. If there
is a simpler REST Interface than slide that would be very interesting.
One of the things that attracted me to Sling was the presentation
http://www.slideshare.net/lars3loff/the-zero-bullshit-architecture. I
found that I shared a lot of prejudices with the author, and shared
prejudices are what makes the world go round. As I understand it Day
were the main contributor to Sling, and the Sling architecture is what
he was describing.

> "I'm not sure what you meant by "a mixture of structured and 
> unstructureddata".
By a "mixture of structured and unstructured data", I mean that some
data will have schemas and some won't. I also am quite likely to
change the schema across time. As I have been involved in a large
number of database migration problems: all of which were painful, I
hope to avoid all those problems. It looks to me that Jackrabbit will
deal with many of these issues.

> "Have you looked at other databases such as CouchDB or MongoDB?"
I haven't looked at CouchDb/MongoDb, although I have worked with Neo4J
and Cassandra which have some similar properties. I really like
Cassandra, and keep trying to make the project I am writing use it,
but the amount of work I would have to do is quite high.

> "I don't think Sling is a remote repository."
You might be right. I have come to it thinking its mainly a Restful
front end to Jackrabbit, but it is quite a lot more than that.
The features of Jackrabbit I like are
1: WebDAV interface...There are loads of tools available for
troubleshooting and exploring
2: The versioning

Although I came to Sling for the Restful interface, there are a few of
features that Sling adds to Jackrabbit that I like:
1: It looks as though Sling would deal with the schema changing across
time issue: The support for multiple renderers, and for those
renderers to be quite sophisticated looks as though I can ask for
resource.oldVersion0, resource.oldVersion1 or resource.json, and have
the correct values presented to me.
2: I hope to be able to use the Sling rendering to reduce the chatter
between client and server

If there is a more suited Restful interface to Jackrabbit I would be
very interested.




On Fri, Jul 8, 2011 at 1:51 PM, sam lee  wrote:
>
> Why don't  you use Jackrabbit via DavEx or RMI?
> http://wiki.apache.org/jackrabbit/RemoteAccess
>
> I don't think Sling is a remote repository.
>
> I'm not sure what you meant by "a mixture of structured and unstructured
> data".
> Have you looked at other databases such as CouchDB or MongoDB?
>
>
>
> On Fri, Jul 8, 2011 at 8:05 AM, Phil Rice
> wrote:
>
> > @Sam Lee
> > "Why do you want to access through Java" My client is going to be an
> > Eclipse
> > Plugin. In practice I will probably use Scala or Clojure, but I didn't want
> > to pollute my pitiful request for help with language issues. I think Sling
> > looks like an excellent remote repository for a mixture of structured and
> > unstructured data.
> >
> > @Julian
> > I take your point. I think all I really needed was the hello world program
> > to post data in, and get data out. One of the things I really like about
> > Sling (although I haven't got it working yet) is that I can effectively ask
> > for an object graph with one query.
> >
> > Example: I am making a project data repository. My data structure holds
> > data
> > such as "software projects", "releases", "classes", "methods". Some
> > "fields"
> > are mandatory, but many will be freeform. The relationship between these
> > entities is complex. As an example the method setXXX may exist across
> > multiple versions, but perhaps change what it does, so displaying comments
> > and documentation about that method requires business knowledge. As I
> > understand it, in a single query about a method, I can return data about
> > the
> > method, but I can walk the repository tree (I don't have the sling language
> > yet...give me time) and return data about the method, the class that holds
> > it, the releases that the class is in, and the project that the holds the
> > data about the class.
> >
> > Your checklist looks like a training plan. My first plan was to make a plug
> > in that was very chatty: I make a query for each entity, perhaps 20 queries
> > for a screen full of data. This would allow me to gain experience with
> > sling, eclipse plugins etc, and give me something "shiny" to discuss with
> > potential users. Once I have that working, I will be doing a lot more work
> > to reduce it to (hopefull) one request, at which point I will be using a
> > lot
> > more of the sling tools
> >
> > @Bertrand
> > Thanks for the slingbucks example, I'll start with that and if I get stuck
> > move onto CRX.
> >

Re: Beginners question with Sling.

2011-07-08 Thread Bertrand Delacretaz
Hi Phil,

On Fri, Jul 8, 2011 at 4:15 PM, Phil Rice
 wrote:
> ...Although I came to Sling for the Restful interface, there are a few of
> features that Sling adds to Jackrabbit that I like:
> 1: It looks as though Sling would deal with the schema changing across
> time issue: The support for multiple renderers, and for those
> renderers to be quite sophisticated looks as though I can ask for
> resource.oldVersion0, resource.oldVersion1 or resource.json, and have
> the correct values presented to me.
> 2: I hope to be able to use the Sling rendering to reduce the chatter
> between client and server...

IMO this matches the general philosophy of Sling very well, so it
looks like it's worth for you to hang in there!

-Bertrand


RE: Beginners question with Sling.

2011-07-08 Thread Mark Herman
I agree, it sounds like Sling will work for what you need.  Personally I
first was interested in using the JCR, and after learning that, Sling was
very easy to pick up.  I would definitely recommend getting some sort of JCR
explorer so you can get a feel of how a jcr repository works, looks and
feels. There are open source projects or you can use Day's developer product.
I've never tried it, but from what I've ready by default you should be able
to connect to a sling repo via jcr explorer using
rmi://localhost:1099/jackrabbit.

For your use, keep in mind that in sling you don't have to use the default
post handler. You can create a custom POST.jsp that will handle the post
request however you want. All you need to do is set the parent's resource
type.

-Original Message-
From: Bertrand Delacretaz [mailto:bdelacre...@apache.org] 
Sent: Friday, July 08, 2011 10:35 AM
To: users@sling.apache.org
Subject: Re: Beginners question with Sling.

Hi Phil,

On Fri, Jul 8, 2011 at 4:15 PM, Phil Rice
 wrote:
> ...Although I came to Sling for the Restful interface, there are a few of
> features that Sling adds to Jackrabbit that I like:
> 1: It looks as though Sling would deal with the schema changing across
> time issue: The support for multiple renderers, and for those
> renderers to be quite sophisticated looks as though I can ask for
> resource.oldVersion0, resource.oldVersion1 or resource.json, and have
> the correct values presented to me.
> 2: I hope to be able to use the Sling rendering to reduce the chatter
> between client and server...

IMO this matches the general philosophy of Sling very well, so it
looks like it's worth for you to hang in there!

-Bertrand


Re: Beginners question with Sling.

2011-07-08 Thread Bertrand Delacretaz
On Fri, Jul 8, 2011 at 4:51 PM, Mark Herman  wrote:
> I agree, it sounds like Sling will work for what you need.  Personally I
> first was interested in using the JCR, and after learning that, Sling was
> very easy to pick up.  I would definitely recommend getting some sort of JCR
> explorer so you can get a feel of how a jcr repository works, looks and
> feels. There are open source projects or you can use Day's developer 
> product

There's even an explorer in Sling,
http://localhost:8080/.explorer.html if you have the
org.apache.sling.extensions.explorer bundle.

It's not perfect, but improving it would be a great way of learning Sling ;-)

-Bertrand


Re: Beginners question with Sling.

2011-07-08 Thread Phil Rice
I appreciate the feedback on suitability, as I don't know this area of
programming very well. I suspect I will be two or three years on this
project, so any mistakes will be biting me for quite some time. The
built in sling explorer works well and gives me quite a lot of
confidence that the programmatic side is working (tests are all very
well but its nice to see stuff).


On Fri, Jul 8, 2011 at 4:03 PM, Bertrand Delacretaz
 wrote:
> On Fri, Jul 8, 2011 at 4:51 PM, Mark Herman  wrote:
>> I agree, it sounds like Sling will work for what you need.  Personally I
>> first was interested in using the JCR, and after learning that, Sling was
>> very easy to pick up.  I would definitely recommend getting some sort of JCR
>> explorer so you can get a feel of how a jcr repository works, looks and
>> feels. There are open source projects or you can use Day's developer 
>> product
>
> There's even an explorer in Sling,
> http://localhost:8080/.explorer.html if you have the
> org.apache.sling.extensions.explorer bundle.
>
> It's not perfect, but improving it would be a great way of learning Sling ;-)
>
> -Bertrand
>