Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Commit

Permalink
Added POST query processing to AtomPub server (abdera+jaxrs)
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/incubator/chemistry/trunk@787218 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Florent Guillaume committed Jun 22, 2009
1 parent 75decda commit 8bf5ba8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
Expand Up @@ -20,6 +20,7 @@

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
Expand Down Expand Up @@ -73,8 +74,10 @@ public AbderaResource() throws Exception {
}

/**
* Gets a {@link ServletRequestContext} wrapping the httpRequest but
* pretending that this Resource's path is part of the servlet path.
* Gets a {@link ServletRequestContext} wrapping the httpRequest.
* <p>
* Wrapping is needed to fixup the servlet path to take include this
* Resource's path.
*
* @param segments the number of segments of the method invoking this, used
* to determine the Resource path
Expand Down Expand Up @@ -126,6 +129,12 @@ protected Response getAbderaEntry(int skipSegments) {
return Response.ok(adapter.getEntry(requestContext)).build();
}

protected Response getAbderaPostFeed(int skipSegments) {
RequestContext requestContext = getRequestContext(skipSegments);
CollectionAdapter adapter = getAbderaCollectionAdapter(requestContext);
return Response.ok(adapter.postEntry(requestContext)).build();
}

@GET
@Produces("application/atomsvc+xml")
@Path("repository")
Expand Down Expand Up @@ -169,4 +178,12 @@ public Response doGetFile() {
return Response.ok(responseContext).type(contentType).build();
}

@POST
@Consumes("application/cmisquery+xml")
@Produces("application/atom+xml;type=feed")
@Path("query")
public Response doPostQuery() {
return getAbderaPostFeed(1);
}

}
Expand Up @@ -24,8 +24,11 @@
import org.apache.abdera.model.Element;
import org.apache.abdera.model.Service;
import org.apache.abdera.model.Workspace;
import org.apache.abdera.protocol.EntityProvider;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;
import org.apache.abdera.protocol.util.AbstractEntityProvider;
import org.apache.abdera.writer.StreamWriter;
import org.apache.chemistry.BaseType;
import org.apache.chemistry.Connection;
import org.apache.chemistry.ContentStream;
Expand Down Expand Up @@ -177,8 +180,50 @@ public void testConnect() throws Exception {
assertEquals(HttpStatus.SC_OK, status);
assertEquals("text/plain",
method.getResponseHeader("Content-Type").getValue());
assertEquals(String.valueOf(TEST_FILE_CONTENT.getBytes().length),
method.getResponseHeader("Content-Length").getValue());
byte[] body = method.getResponseBody();
assertEquals(TEST_FILE_CONTENT, new String(body, "UTF-8"));
method.releaseConnection();

EntityProvider provider = new QueryEntityProvider("SELECT * FROM doc");
resp = client.post(base + "/query", provider);
assertEquals(200, resp.getStatus());
Element res = resp.getDocument().getRoot();
assertNotNull(res);
}

public static class QueryEntityProvider extends AbstractEntityProvider {

public String statement;

public QueryEntityProvider(String statement) {
this.statement = statement;
}

@Override
public String getContentType() {
return "application/cmisquery+xml";
}

public boolean isRepeatable() {
return true;
}

public void writeTo(StreamWriter sw) {
sw.startDocument();
sw.startElement("query", CMIS.CMIS_NS, CMIS.CMIS_PREFIX);
sw.startElement("statement", CMIS.CMIS_NS, CMIS.CMIS_PREFIX).writeElementText(
statement).endElement();
sw.startElement("searchAllVersions", CMIS.CMIS_NS, CMIS.CMIS_PREFIX).writeElementText(
"false").endElement();
sw.startElement("pageSize", CMIS.CMIS_NS, CMIS.CMIS_PREFIX).writeElementText(
0).endElement();
sw.startElement("skipCount", CMIS.CMIS_NS, CMIS.CMIS_PREFIX).writeElementText(
0).endElement();
sw.endElement(); // query
sw.endDocument();
}
}

}

0 comments on commit 8bf5ba8

Please sign in to comment.