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;
ListNameValuePair formParams = Arrays.NameValuePair 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 ? Empty Response :
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
html
head
titleError while processing /newNodeb8/title
/head
body
h1Error while processing /newNodeb8/h1
table
tbody
tr
tdStatus/td
tddiv id=Status500/div/td
/tr
tr
tdMessage/td
tddiv id=Messagejavax.jcr.AccessDeniedException:
/newNodeb8/param2: not allowed to add or modify item/div/td
/tr
tr
tdLocation/td
tda href=/newNodeb8 id=Location/newNodeb8/a/td
/tr
tr
tdParent Location/td
tda href=/ id=ParentLocation//a/td
/tr
tr
tdPath/td
tddiv id=Path/newNodeb8/div/td
/tr
tr
tdReferer/td
tda href= id=Referer/a/td
/tr
tr
tdChangeLog/td
tddiv
id=ChangeLogprecreated(/newNodeb8);br/modified(/newNodeb8/param1);br/modified(/newNodeb8/param2);br//pre/div/td
/tr
/tbody
/table
pa href=Go Back/a/p
pa href=/newNodeb8Modified Resource/a/p
pa href=/Parent of Modified Resource/a/p
/body
/html


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 mher...@nbme.org 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-1query=crx+gems;
 main_entries_start=15blog=searchy=0x=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

Re: Beginners question with Sling.

2011-07-08 Thread Alexander Klimetschek
On 08.07.11 10:39, Phil Rice phil.rice.erud...@googlemail.com 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
aklim...@adobe.com wrote:
 On 08.07.11 10:39, Phil Rice phil.rice.erud...@googlemail.com 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;

ListNameValuePair formParams = Arrays.NameValuePair 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
aklim...@adobe.comwrote:

 On 08.07.11 10:39, Phil Rice phil.rice.erud...@googlemail.com 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.NameValuePair 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 phil.rice.erud...@googlemail.com
 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;

 ListNameValuePair formParams = Arrays.NameValuePair 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 aklim...@adobe.com
  wrote:

 On 08.07.11 10:39, Phil Rice phil.rice.erud...@googlemail.com 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
phil.rice.erud...@googlemail.comwrote:

 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;

 ListNameValuePair formParams = Arrays.NameValuePair 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
 aklim...@adobe.comwrote:

  On 08.07.11 10:39, Phil Rice phil.rice.erud...@googlemail.com 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 jsedd...@gmail.com 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
phil.rice.erud...@googlemail.comwrote:

 @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 jsedd...@gmail.com
 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 skyn...@gmail.com 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
 phil.rice.erud...@googlemail.comwrote:

 @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 jsedd...@gmail.com
 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 jsedd...@gmail.com 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 skyn...@gmail.com 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
 phil.rice.erud...@googlemail.comwrote:

 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;

 ListNameValuePair formParams = Arrays.NameValuePair 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
 aklim...@adobe.comwrote:

  On 08.07.11 10:39, Phil Rice phil.rice.erud...@googlemail.com 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
Hi Phil,

On Fri, Jul 8, 2011 at 4:15 PM, Phil Rice
phil.rice.erud...@googlemail.com 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
phil.rice.erud...@googlemail.com 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-07 Thread sam lee
You can use /system/sling.js

It has Sling.removeContent() and Sling.getContent().
You just need to implement Sling.createContent(), Sling.updateContent(),
Sling.query()  using xhr.

Then you have something like couchdb.

I don't think sling has RESTful API reference. It would be useful.


On Thu, Jul 7, 2011 at 8:57 AM, Eric Norman eric.d.nor...@gmail.com wrote:

 Hi Phil,

 It looks like your form inputs are missing the name attribute.  Try
 something like this:

 html
  headtitleTesting/title/head
  body
form action=http://localhost:8080/newNode1; method=post
label for=name1Name1/label input type=text id=name1 *
 name=name1*
 value=Value1 /br /
   label for=name2Name3/label input type=text id=name2 *
 name=name2*
 value=Value2 /br /
   label for=name3Name4/label input type=text id=name3 *
 name=name3*
 value=Value3 /br /
   label for=name4Name5/label input type=text id=name4 *
 name=name4*
 value=Value4 /br /
 buttonSubmit/button
  /form
  /body
 /html


 Also, take a look at the documentation of the sling post servlet bundle @

 http://sling.apache.org/site/manipulating-content-the-slingpostservlet-servletspost.html
 for
 some examples of content manipulation.

 Regards,
 Eric


 On Thu, Jul 7, 2011 at 12:56 AM, Phil Rice 
 phil.rice.erud...@googlemail.com
  wrote:

  Thanks for the swift reply
 
- I'll raise a bug about Sling in 15 minutes as soon as I can make a
unit test to capture it.
- I'm hoping someone can point me to a tutorial or reference materials
for ESP. Playing with javascript through reflection is hard work!
- Thanks for the idea of running Sling in the same OSGI container. I
suspect that won't work for crowd sourcing (you want one central
repository), but I think it would be an excellent way to learn how
everything ties together
- I was puzzled that PUT was the wrong method. As I understand it PUT
 is
the mechanism to create or replace in REST. However I replaced the
 call
  to
a post, and I just get internal server error 500s with nothing
 appearing
  in
the logs. I will chase that down when I have sorted out the next point:
- Assuming that there is a problem in my understanding in what is going
on, I reduced to the simplest thing that could wrong and produced the
following HTML page
 
  html
   headtitleTesting/title/head
   body
  form action=http://localhost:8080/newNode1; method=post
 label for=name1Name1/label input type=text id=name1
  value=Value1 /br /
 label for=name2Name3/label input type=text id=name2
  value=Value2 /br /
 label for=name3Name4/label input type=text id=name3
  value=Value3 /br /
 label for=name4Name5/label input type=text id=name4
  value=Value4 /br /
  buttonSubmit/button
   /form
/body
  /html
  My hope is that when I click the button this would create newNode1 with
  attributes name1 = Value1 etc. And indeed (after logging in) it created
  newNode1. However when I examine the node created using the url
  http://localhost:8080/newNode1.json I find the following page:
 
 {jcr:primaryType:nt:unstructured}
 
  However if I use
 
  curl -u admin:admin -Fname1=value1 -Fname2=value2
  http://localhost:8080/newNodeQ1
 
  And surf to http://localhost:8080/newNodeQ1.json I find
 
  {name2:value2,jcr:primaryType:nt:unstructured,name1:value1}
 
  I would appreciate some advice on how to get the HTML to work similar to
  curl
 
  Thanks again for the help
  ---
 
   My software stack is:
 
- Windows 7 64 bit
- JDK1.6.0_24
- Eclipse Indigo Release build 20110615-0604
- I am using jar org.apache.sling.launchpad.base.jar, which I
downloaded earlier this week.
- I am running the jar using Eclipse using only defaults (no VM
arguments, no program arguments). The main method is from
class org.apache.sling.launchpad.app.Main
 
  The console output from sling is
 
  07.07.2011 07:54:18.570 *INFO* [main] Setting sling.home=sling (default)
  07.07.2011 07:54:18.572 *INFO* [main] Starting Sling in sling
  (C:\Users\Phil\workspace\Sling\sling)
  07.07.2011 07:54:18.620 *INFO* [main] Checking launcher JAR in folder
 sling
  07.07.2011 07:54:18.640 *INFO* [main] Existing launcher is up to date,
  using
  it: 2.3.0 (org.apache.sling.launchpad.base.jar)
  07.07.2011 07:54:18.642 *INFO* [main] Loading launcher class
  org.apache.sling.launchpad.base.app.MainDelegate from
  org.apache.sling.launchpad.base.jar
  07.07.2011 07:54:18.662 *INFO* [main] Starting launcher ...
  07.07.2011 07:54:18.666 *INFO* [main] HTTP server port: 8080
  07.07.2011 07:54:20.736 *INFO* [main] Startup completed
 
 
 
 
  On Wed, Jul 6, 2011 at 11:02 PM, Justin Edelson 
 jus...@justinedelson.com
  wrote:
 
  
  
   On Jul 6, 2011, at 5:16 PM, Phil Rice 
 phil.rice.erud...@googlemail.com
   wrote:
  
Hello everyone.
  
   Hi
  
   
I have just downloaded Sling, and am very impressed with it. I am
   planning
on using it in conjunction with an Eclipse plugin to 

Re: Beginners question with Sling.

2011-07-07 Thread Bertrand Delacretaz
On Thu, Jul 7, 2011 at 3:03 PM, sam lee skyn...@gmail.com wrote:
 ...I don't think sling has RESTful API reference. It would be useful

you're right, OTOH Sling has an extensive integration test suite which
uses its HTTP interfaces, so you can learn a lot by looking at the
code under [1].

If someone feels like contributing to this, it would be cool to adapt
and extend what I started to do in Stanbol [2] to generate RESTful API
documentation based on annotated integration tests.

-Bertrand

[1] http://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests

[2] See https://issues.apache.org/jira/browse/STANBOL-15 and
generateDocumentation in
http://svn.apache.org/repos/asf/incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/enhancer/it/StatelessEngineTest.java


RE: Beginners question with Sling.

2011-07-07 Thread Mark Herman
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-1query=crx+gems;
main_entries_start=15blog=searchy=0x=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 provided for you. In JSP you just have to include a taglib
and call the call sling:define objects.
 - It seems the people who write/use the product tend to use JSP more and are
starting to shy away from ESP.
 - IDE support should be a bit better with JSP

I don't think there is anything wrong with ESP, but it just seems like it
doesn't have any major advantage make it a must have.

A couple of discussions I have found:
http://www.mail-archive.com/users@sling.apache.org/msg01105.html
http://tech.groups.yahoo.com/group/Day-Communique/message/2464


Sorry I can't help with your issues. As you probably have guessed most my
experience is with Day/Adobe's product, so I suggest you may want to get a
license for a developer edition of CRX. It's free (last i checked), and is
basically a jackrabbit repository with sling on top plus their tools.  They
have an Eclipse ide with debugging, a node browser, and a web based ide.
It's very easy to install, although you will need to register for a free
license. Also note, eclipse ide is a separate download. You could probably
use their tools to create bundles then just deploy the bundles to your sling
instance.

Good luck.
 
-Original Message-
From: Phil Rice [mailto:phil.rice.erud...@googlemail.com]
Sent: Thu 7/7/2011 3:56 AM
To: users@sling.apache.org
Subject: Re: Beginners question with Sling.
 
Thanks for the swift reply

   - I'll raise a bug about Sling in 15 minutes as soon as I can make a
   unit test to capture it.
   - I'm hoping someone can point me to a tutorial or reference materials
   for ESP. Playing with javascript through reflection is hard work!
   - Thanks for the idea of running Sling in the same OSGI container. I
   suspect that won't work for crowd sourcing (you want one central
   repository), but I think it would be an excellent way to learn how
   everything ties together
   - I was puzzled that PUT was the wrong method. As I understand it PUT is
   the mechanism to create or replace in REST. However I replaced the call
to
   a post, and I just get internal server error 500s with nothing appearing
in
   the logs. I will chase that down when I have sorted out the next point:
   - Assuming that there is a problem in my understanding in what is going
   on, I reduced to the simplest thing that could wrong and produced the
   following HTML page

html
  headtitleTesting/title/head
  body
 form action=http://localhost:8080/newNode1; method=post
label for=name1Name1/label input type=text id=name1
value=Value1 /br /
label for=name2Name3/label input type=text id=name2
value=Value2 /br /
label for=name3Name4/label input type=text id=name3
value=Value3 /br /
label for=name4Name5/label input type=text id=name4
value=Value4 /br /
buttonSubmit/button
 /form
   /body
/html
My hope is that when I click the button this would create newNode1 with
attributes name1 = Value1 etc. And indeed (after logging in) it created
newNode1. However when I examine the node created using the url
http://localhost:8080/newNode1.json I find the following page:

{jcr:primaryType:nt:unstructured}

However if I use

curl -u admin:admin -Fname1=value1 -Fname2=value2
http://localhost:8080/newNodeQ1

And surf to http://localhost:8080/newNodeQ1.json I find

{name2:value2,jcr:primaryType:nt:unstructured,name1:value1}

I would appreciate some advice on how to get the HTML to work similar to
curl

Thanks again for the help

Re: Beginners question with Sling.

2011-07-06 Thread Justin Edelson


On Jul 6, 2011, at 5:16 PM, Phil Rice phil.rice.erud...@googlemail.com wrote:

 Hello everyone.

Hi

 
 I have just downloaded Sling, and am very impressed with it. I am planning
 on using it in conjunction with an Eclipse plugin to crowd source
 information about open source projects.

Sounds interesting. Are you able to reuse code between the server side and 
client side as both Sling and Eclipse are OSGi based?

 
 I am having the usual teething problems that I get whenever I use an open
 source product, and I am hoping to get some assistance. I have spent three
 days getting going, so I have tried quite a few combinations.
 
 Some general information for you getting going with sling in 15 minutes
 was very helpful. I have a version of Sling built from the source code using
 Maven, and a second which is the standalone Jar. On both of them the
 following curl command didn't work:
 
 curl -u admin:admin -Fsling:resourceType=foo/bar -Ftitle=some
 title http://localhost:8080/content/mynode
 
 
 I had to replace it with:
 
 
 curl -u admin:admin -Fsling:resourceType=foo/bar -Ftitle=some
 title http://localhost:8080/mynode

This should have worked. Can you file a bug report?

 
 
 At the moment my Sling-fu is weak and I am not sure if this is some
 configuration problem.
 ---
 
 I am now at the point at which I feel the master of Sling (pride comes
 before a fall) using Curl, so I have moved to Java. I have tried a number of
 Java libraries include the Apache HttpClient, http-unit and Rest-assured. I
 am now at the point at which I can get information out of Sling that I put
 in with Curl, but I am unable to programatically add it. Specifically I can
 create the node, but the attributes do not appear. Fairly obviously I am
 missing some critical configuration
 
 So I have the following questions:
 
   - ESP looks very nice. Where can I find information on how to use it. I
   have found some samples using it, but have not been very successful in
   finding tutorials / reference material.
   - What is the Java side client software that you recommend for use with
   Sling, and do you have any example code?

The majority of the Sling integration test suite is written with Apache 
HttpClient 3.x. That's a good point if reference. 

   - Can you advise why the following code does not set param1=value1,
   param2=value2?
 

You're doing a PUT. I'm assuming you are using the default servlets and the 
functionality which accepts form parameters and sets node properties from them 
is in the default POST servlet. Of course, you're free to write your own 
servlet which accepts PUTs.

HTH,
Justin
 
 import org.apache.http.*;
 public class PopulateRepository {
 public static void main(String[] args) throws Exception {
 BasicCredentialsProvider credentialsProvider = new
 BasicCredentialsProvider();
 credentialsProvider.setCredentials(AuthScope.ANY, new
 UsernamePasswordCredentials(admin, admin));
 DefaultHttpClient client = new DefaultHttpClient();
 client.setCredentialsProvider(credentialsProvider);
 
 String nodeName = newNodeName;
 ListNameValuePair formParams = Arrays.NameValuePair asList(new
 BasicNameValuePair(param1, value1), new BasicNameValuePair(param2,
 value2));
 UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams, UTF-8);
 HttpPut action = new HttpPut(http://localhost:8080/; + nodeName);
 HttpResponse response = client.execute(action);
   }}
 
 Thanks for making such an interesting product