From do-not-reply at jboss.org Thu Feb 18 08:23:36 2010 Content-Type: multipart/mixed; boundary="===============3936388739679748976==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: exo-jcr-commits at lists.jboss.org Subject: [exo-jcr-commits] exo-jcr SVN: r1897 - in ws/branches/2.2.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext: service and 1 other directory. Date: Thu, 18 Feb 2010 08:23:36 -0500 Message-ID: <201002181323.o1IDNasm022370@svn01.web.mwc.hst.phx2.redhat.com> --===============3936388739679748976== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: max_shaposhnik Date: 2010-02-18 08:23:36 -0500 (Thu, 18 Feb 2010) New Revision: 1897 Added: ws/branches/2.2.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services= /rest/ext/service/ ws/branches/2.2.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services= /rest/ext/service/RestServicesList.java ws/branches/2.2.x/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 Added: ws/branches/2.2.x/exo.ws.rest.ext/src/main/java/org/exoplatform/serv= ices/rest/ext/service/RestServicesList.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- ws/branches/2.2.x/exo.ws.rest.ext/src/main/java/org/exoplatform/service= s/rest/ext/service/RestServicesList.java (rev 0) +++ ws/branches/2.2.x/exo.ws.rest.ext/src/main/java/org/exoplatform/service= s/rest/ext/service/RestServicesList.java 2010-02-18 13:23:36 UTC (rev 1897) @@ -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 Andrey Par= fonov + * @version $Id$ + */ +(a)Path("/") +// NOTE : Class do not implement org.exoplatform.services.rest.resource.Re= sourceContainer +// 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 =3D fqn; + this.path =3D path; + this.regex =3D regex; + } + + public String getFqn() + { + return fqn; + } + + public String getPath() + { + return path; + } + + public String getRegex() + { + return regex; + } + } + + // = + + public static class RootResourcesList + { + private List rootResources; + + public RootResourcesList(List rootResources) + { + this.rootResources =3D rootResources; + } + + public List getRootResources() + { + return rootResources; + } + } + + // + + private final ResourceBinder binder; + + public RestServicesList(ResourceBinder resources) + { + this.binder =3D resources; + } + + @GET + @Produces({MediaType.TEXT_HTML}) + public byte[] listHTML() + { + XMLOutputFactory factory =3D XMLOutputFactory.newInstance(); + factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolea= n.TRUE); + ByteArrayOutputStream output =3D new ByteArrayOutputStream(); + try + { + XMLStreamWriter xsw =3D factory.createXMLStreamWriter(output, "UT= F-8"); + xsw.writeStartDocument("UTF-8", "1.0"); + xsw.writeDTD(""); + 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(); // + xsw.writeEndElement(); // + 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(); // + xsw.writeStartElement("th"); + xsw.writeCharacters("Regex"); + xsw.writeEndElement(); // + xsw.writeStartElement("th"); + xsw.writeCharacters("FQN"); + xsw.writeEndElement(); // + xsw.writeEndElement(); // + // end table header + for (RootResource r : rootResources().getRootResources()) + { + xsw.writeStartElement("tr"); + xsw.writeStartElement("td"); + xsw.writeCharacters(r.getPath()); + xsw.writeEndElement(); // + xsw.writeStartElement("td"); + xsw.writeCharacters(r.getRegex()); + xsw.writeEndElement(); // + xsw.writeStartElement("td"); + xsw.writeCharacters(r.getFqn()); + xsw.writeEndElement(); // + xsw.writeEndElement(); // + } + xsw.writeEndElement(); // + xsw.writeEndElement(); // + 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 resources =3D new ArrayList(); + for (ObjectFactory om : binder.getResour= ces()) + { + AbstractResourceDescriptor descriptor =3D om.getObjectModel(); + resources.add(new RootResource(descriptor.getObjectClass().getNam= e(), // + descriptor.getPathValue().getPath(), // + descriptor.getUriPattern().getRegex())); + } + return new RootResourcesList(resources); + } + +} Property changes on: ws/branches/2.2.x/exo.ws.rest.ext/src/main/java/org/ex= oplatform/services/rest/ext/service/RestServicesList.java ___________________________________________________________________ Name: svn:keywords + Id Name: svn:eol-style + native Added: ws/branches/2.2.x/exo.ws.rest.ext/src/main/java/org/exoplatform/serv= ices/rest/ext/service/RestServicesListApplication.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- ws/branches/2.2.x/exo.ws.rest.ext/src/main/java/org/exoplatform/service= s/rest/ext/service/RestServicesListApplication.java = (rev 0) +++ ws/branches/2.2.x/exo.ws.rest.ext/src/main/java/org/exoplatform/service= s/rest/ext/service/RestServicesListApplication.java 2010-02-18 13:23:36 UTC= (rev 1897) @@ -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 Andrey Par= fonov + * @version $Id$ + */ +public class RestServicesListApplication extends Application +{ + + @Override + public Set> getClasses() + { + Set> cls =3D new HashSet>(); + cls.add(RestServicesList.class); + return cls; + } + +} Property changes on: ws/branches/2.2.x/exo.ws.rest.ext/src/main/java/org/ex= oplatform/services/rest/ext/service/RestServicesListApplication.java ___________________________________________________________________ Name: svn:keywords + Id Name: svn:eol-style + native --===============3936388739679748976==--