[exo-jcr-commits] exo-jcr SVN: r1892 - in ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext: service and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Feb 18 07:58:07 EST 2010
Author: max_shaposhnik
Date: 2010-02-18 07:58:07 -0500 (Thu, 18 Feb 2010)
New Revision: 1892
Added:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/service/
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/service/RestServicesList.java
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/service/RestServicesListApplication.java
Log:
EXOJCR-525 Get all bindig path of REST services on server tests
Added: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/service/RestServicesList.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/service/RestServicesList.java (rev 0)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/service/RestServicesList.java 2010-02-18 12:58:07 UTC (rev 1892)
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.rest.ext.service;
+
+import org.exoplatform.services.rest.ObjectFactory;
+import org.exoplatform.services.rest.impl.ResourceBinder;
+import org.exoplatform.services.rest.resource.AbstractResourceDescriptor;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * @author <a href="mailto:andrey.parfonov at exoplatform.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+ at Path("/")
+// NOTE : Class do not implement org.exoplatform.services.rest.resource.ResourceContainer
+// and must never be binded to RESTful framework by using eXoContainer.
+// This service must works as per-request resource.
+public class RestServicesList
+{
+
+ //
+ public static class RootResource
+ {
+ private String fqn;
+
+ private String path;
+
+ private String regex;
+
+ public RootResource(String fqn, String path, String regex)
+ {
+ this.fqn = fqn;
+ this.path = path;
+ this.regex = regex;
+ }
+
+ public String getFqn()
+ {
+ return fqn;
+ }
+
+ public String getPath()
+ {
+ return path;
+ }
+
+ public String getRegex()
+ {
+ return regex;
+ }
+ }
+
+ //
+
+ public static class RootResourcesList
+ {
+ private List<RootResource> rootResources;
+
+ public RootResourcesList(List<RootResource> rootResources)
+ {
+ this.rootResources = rootResources;
+ }
+
+ public List<RootResource> getRootResources()
+ {
+ return rootResources;
+ }
+ }
+
+ //
+
+ private final ResourceBinder binder;
+
+ public RestServicesList(ResourceBinder resources)
+ {
+ this.binder = resources;
+ }
+
+ @GET
+ @Produces({MediaType.TEXT_HTML})
+ public byte[] listHTML()
+ {
+ XMLOutputFactory factory = XMLOutputFactory.newInstance();
+ factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ try
+ {
+ XMLStreamWriter xsw = factory.createXMLStreamWriter(output, "UTF-8");
+ xsw.writeStartDocument("UTF-8", "1.0");
+ xsw.writeDTD("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
+ + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
+ xsw.writeCharacters("\n");
+ xsw.writeStartElement("html");
+ xsw.writeDefaultNamespace("http://www.w3.org/1999/xhtml");
+ xsw.writeStartElement("head");
+ xsw.writeStartElement("title");
+ xsw.writeCharacters("eXo JAXRS Implementation");
+ xsw.writeEndElement(); // </title>
+ xsw.writeEndElement(); // </head>
+ xsw.writeStartElement("body");
+ //
+ xsw.writeStartElement("h3");
+ xsw.writeAttribute("style", "text-align:center;");
+ xsw.writeCharacters("Root resources");
+ xsw.writeEndElement();
+ // table
+ xsw.writeStartElement("table");
+ xsw.writeAttribute("width", "90%");
+ xsw.writeAttribute("style", "table-layout:fixed;");
+ // table header
+ xsw.writeStartElement("tr");
+ xsw.writeStartElement("th");
+ xsw.writeCharacters("Path");
+ xsw.writeEndElement(); // </th>
+ xsw.writeStartElement("th");
+ xsw.writeCharacters("Regex");
+ xsw.writeEndElement(); // </th>
+ xsw.writeStartElement("th");
+ xsw.writeCharacters("FQN");
+ xsw.writeEndElement(); // </th>
+ xsw.writeEndElement(); // </tr>
+ // end table header
+ for (RootResource r : rootResources().getRootResources())
+ {
+ xsw.writeStartElement("tr");
+ xsw.writeStartElement("td");
+ xsw.writeCharacters(r.getPath());
+ xsw.writeEndElement(); // </td>
+ xsw.writeStartElement("td");
+ xsw.writeCharacters(r.getRegex());
+ xsw.writeEndElement(); // </td>
+ xsw.writeStartElement("td");
+ xsw.writeCharacters(r.getFqn());
+ xsw.writeEndElement(); // </td>
+ xsw.writeEndElement(); // </tr>
+ }
+ xsw.writeEndElement(); // </table>
+ xsw.writeEndElement(); // </body>
+ xsw.writeEndDocument();
+ }
+ catch (XMLStreamException xmle)
+ {
+ throw new WebApplicationException(xmle, //
+ Response.status(500) //
+ .entity("Unable write to output stream. " + xmle.getMessage()) //
+ .type(MediaType.TEXT_PLAIN) //
+ .build());
+ }
+ return output.toByteArray();
+ }
+
+ @GET
+ @Produces({MediaType.APPLICATION_JSON})
+ public RootResourcesList listJSON()
+ {
+ return rootResources();
+ }
+
+ protected RootResourcesList rootResources()
+ {
+ List<RootResource> resources = new ArrayList<RootResource>();
+ for (ObjectFactory<AbstractResourceDescriptor> om : binder.getResources())
+ {
+ AbstractResourceDescriptor descriptor = om.getObjectModel();
+ resources.add(new RootResource(descriptor.getObjectClass().getName(), //
+ descriptor.getPathValue().getPath(), //
+ descriptor.getUriPattern().getRegex()));
+ }
+ return new RootResourcesList(resources);
+ }
+
+}
Property changes on: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/service/RestServicesList.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/service/RestServicesListApplication.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/service/RestServicesListApplication.java (rev 0)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/service/RestServicesListApplication.java 2010-02-18 12:58:07 UTC (rev 1892)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.rest.ext.service;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+/**
+ * @author <a href="mailto:andrey.parfonov at exoplatform.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class RestServicesListApplication extends Application
+{
+
+ @Override
+ public Set<Class<?>> getClasses()
+ {
+ Set<Class<?>> cls = new HashSet<Class<?>>();
+ cls.add(RestServicesList.class);
+ return cls;
+ }
+
+}
Property changes on: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/service/RestServicesListApplication.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the exo-jcr-commits
mailing list