http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/SourceResource.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/SourceResource.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/SourceResource.java deleted file mode 100644 index c09d809..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/SourceResource.java +++ /dev/null @@ -1,112 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - -import java.io.*; -import java.util.*; - -import org.apache.juneau.html.annotation.*; -import org.apache.juneau.internal.*; -import org.apache.juneau.microservice.*; -import org.apache.juneau.rest.annotation.*; - -/** - * Servlet for viewing source code on classes whose Java files are present on the classpath. - * <p> - * This class is by no means perfect but is pretty much the best you can get using only regular expression matching. - */ -@SuppressWarnings("serial") -@RestResource( - path="/source", - messages="nls/SourceResource", - properties={ - @Property(name=HTMLDOC_title, value="Source code viewer"), - @Property(name=HTMLDOC_cssImports, value="$R{servletURI}/htdocs/code-highlighting.css"), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.SourceResource)'}"), - } -) -public class SourceResource extends Resource { - - /** View source on the specified classes. */ - @RestMethod(name="GET", path="/") - public Object getSource(@Query("classes") String[] classes) throws Exception { - if (classes == null) - return "Specify classes using ?classes=(class1,class2,....) attribute"; - List<Object> l = new LinkedList<Object>(); - for (String c : classes) { - try { - l.add(new Source(Class.forName(c))); - } catch (ClassNotFoundException e) { - l.add("Class " + c + " not found"); - } catch (Exception e) { - l.add(e.getLocalizedMessage()); - } - } - return l; - } - - /** - * POJO that allows us to serialize HTML directly to the output. - */ - @Html(asPlainText=true) - public static class Source { - private Class<?> c; - private Source(Class<?> c) { - this.c = c; - } - @Override /* Object */ - public String toString() { - String filename = c.getSimpleName() + ".java"; - InputStream is = c.getResourceAsStream('/' + c.getPackage().getName().replace('.','/') + '/' + filename); - if (is == null) - return "Source for class " + c.getName() + " not found"; - StringBuilder sb = new StringBuilder(); - try { - sb.append("<h3>").append(c.getSimpleName()).append(".java").append("</h3>"); - sb.append("<p class='bcode'>"); - sb.append(highlight(IOUtils.read(is), "java")); - sb.append("</p>"); - } catch (Exception e) { - return e.getLocalizedMessage(); - } - return sb.toString(); - } - } - - public static String highlight(String code, String lang) throws Exception { - if (lang.equalsIgnoreCase("xml")) { - code = code.replaceAll("&", "&"); - code = code.replaceAll("<", "<"); - code = code.replaceAll(">", ">"); - code = code.replaceAll("(<[^\\s&]+>)", "<xt>$1</xt>"); - code = code.replaceAll("(<[^\\s&]+)(\\s)", "<xt>$1</xt>$2"); - code = code.replaceAll("(['\"])(/?>)", "$1<xt>$2</xt>"); - code = code.replaceAll("([\\S]+)=", "<xa>$1</xa>="); - code = code.replaceAll("=(['\"][^'\"]+['\"])", "=<xs>$1</xs>"); - } else if (lang.equalsIgnoreCase("java")) { - code = code.replaceAll("&", "&"); - code = code.replaceAll("<", "<"); - code = code.replaceAll(">", ">"); - code = code.replaceAll("(?s)(\\/\\*\\*.*?\\*\\/)", "<jd>$1</jd>"); // javadoc comments - code = code.replaceAll("(@\\w+)", "<ja>$1</ja>"); // annotations - code = code.replaceAll("(?s)(?!\\/)(\\/\\*.*?\\*\\/)", "<jc>$1</jc>"); // C style comments - code = code.replaceAll("(?m)(\\/\\/.*)", "<jc>$1</jc>"); // C++ style comments - code = code.replaceAll("(?m)('[^'\n]*'|\"[^\"\n]*\")", "<js>$1</js>"); // quotes - code = code.replaceAll("(?<!@)(import|package|boolean|byte|char|double|float|final|static|transient|synchronized|private|protected|public|int|long|short|abstract|class|interface|extends|implements|null|true|false|void|break|case|catch|continue|default|do|else|finally|for|goto|if|instanceof|native|new|return|super|switch|this|threadsafe|throws|throw|try|while)(?=\\W)", "<jk>$1</jk>"); // quotes - code = code.replaceAll("<\\/jk>(\\s+)<jk>", "$1"); // quotes - } - return code; - } -}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/SqlQueryResource.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/SqlQueryResource.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/SqlQueryResource.java deleted file mode 100644 index 5273340..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/SqlQueryResource.java +++ /dev/null @@ -1,128 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import static javax.servlet.http.HttpServletResponse.*; -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - -import java.io.*; -import java.sql.*; -import java.util.*; - -import org.apache.juneau.dto.*; -import org.apache.juneau.ini.*; -import org.apache.juneau.internal.*; -import org.apache.juneau.microservice.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; - -/** - * Sample resource that shows how Juneau can serialize ResultSets. - */ -@RestResource( - path="/sqlQuery", - messages="nls/SqlQueryResource", - properties={ - @Property(name=HTMLDOC_title, value="SQL query service"), - @Property(name=HTMLDOC_description, value="Executes queries against the local derby '$C{SqlQueryResource/connectionUrl}' database"), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.SqlQueryResource)'}"), - } -) -public class SqlQueryResource extends Resource { - private static final long serialVersionUID = 1L; - - private ConfigFile cf = getConfig(); - - private String driver = cf.getString("SqlQueryResource/driver"); - private String connectionUrl = cf.getString("SqlQueryResource/connectionUrl"); - private boolean - allowUpdates = cf.getBoolean("SqlQueryResource/allowUpdates", false), - allowTempUpdates = cf.getBoolean("SqlQueryResource/allowTempUpdates", false), - includeRowNums = cf.getBoolean("SqlQueryResource/includeRowNums", false); - - @Override /* Servlet */ - public void init() { - try { - Class.forName(driver).newInstance(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** GET request handler - Display the query entry page. */ - @RestMethod(name="GET", path="/") - public ReaderResource doGet(RestRequest req) throws IOException { - return req.getReaderResource("SqlQueryResource.html", true); - } - - /** POST request handler - Execute the query. */ - @RestMethod(name="POST", path="/") - public List<Object> doPost(@Body PostInput in) throws Exception { - - List<Object> results = new LinkedList<Object>(); - - // Don't try to submit empty input. - if (StringUtils.isEmpty(in.sql)) - return results; - - if (in.pos < 1 || in.pos > 10000) - throw new RestException(SC_BAD_REQUEST, "Invalid value for position. Must be between 1-10000"); - if (in.limit < 1 || in.limit > 10000) - throw new RestException(SC_BAD_REQUEST, "Invalid value for limit. Must be between 1-10000"); - - // Create a connection and statement. - // If these fais, let the exception filter up as a 500 error. - Connection c = DriverManager.getConnection(connectionUrl); - c.setAutoCommit(false); - Statement st = c.createStatement(); - String sql = null; - - try { - for (String s : in.sql.split(";")) { - sql = s.trim(); - if (! sql.isEmpty()) { - Object o = null; - if (allowUpdates || (allowTempUpdates && ! sql.matches("(?:i)commit.*"))) { - if (st.execute(sql)) { - ResultSet rs = st.getResultSet(); - o = new ResultSetList(rs, in.pos, in.limit, includeRowNums); - } else { - o = st.getUpdateCount(); - } - } else { - ResultSet rs = st.executeQuery(sql); - o = new ResultSetList(rs, in.pos, in.limit, includeRowNums); - } - results.add(o); - } - } - if (allowUpdates) - c.commit(); - else if (allowTempUpdates) - c.rollback(); - } catch (SQLException e) { - c.rollback(); - throw new RestException(SC_BAD_REQUEST, "Invalid query: {0}", sql).initCause(e); - } finally { - c.close(); - } - - return results; - } - - /** The parsed form post */ - public static class PostInput { - public String sql; - public int pos = 1, limit = 100; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/SystemPropertiesResource.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/SystemPropertiesResource.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/SystemPropertiesResource.java deleted file mode 100644 index 9a6764d..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/SystemPropertiesResource.java +++ /dev/null @@ -1,153 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - -import java.util.*; - -import org.apache.juneau.dto.swagger.*; -import org.apache.juneau.encoders.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; - -@RestResource( - path="/systemProperties", - title="System properties resource", - description="REST interface for performing CRUD operations on system properties.", - properties={ - @Property(name=SERIALIZER_quoteChar, value="'"), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS'}"), - }, - stylesheet="styles/devops.css", - encoders=GzipEncoder.class, - contact="{name:'John Smith',email:'[email protected]'}", - license="{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'}", - version="2.0", - termsOfService="You're on your own.", - tags="[{name:'Java',description:'Java utility',externalDocs:{description:'Home page',url:'http://juneau.apache.org'}}]", - externalDocs="{description:'Home page',url:'http://juneau.apache.org'}" -) -public class SystemPropertiesResource extends RestServletDefault { - private static final long serialVersionUID = 1L; - - @RestMethod( - name="GET", path="/", - summary="Show all system properties", - description="Returns all system properties defined in the JVM.", - parameters={ - @Parameter(in="query", name="sort", description="Sort results alphabetically.", _default="false") - }, - responses={ - @Response(value=200, description="Returns a map of key/value pairs.") - } - ) - @SuppressWarnings({"rawtypes", "unchecked"}) - public Map getSystemProperties(@Query("sort") boolean sort) throws Throwable { - if (sort) - return new TreeMap(System.getProperties()); - return System.getProperties(); - } - - @RestMethod( - name="GET", path="/{propertyName}", - summary="Get system property", - description="Returns the value of the specified system property.", - parameters={ - @Parameter(in="path", name="propertyName", description="The system property name.") - }, - responses={ - @Response(value=200, description="The system property value, or null if not found.") - } - ) - public String getSystemProperty(@Path String propertyName) throws Throwable { - return System.getProperty(propertyName); - } - - @RestMethod( - name="PUT", path="/{propertyName}", - summary="Replace system property", - description="Sets a new value for the specified system property.", - guards=AdminGuard.class, - parameters={ - @Parameter(in="path", name="propertyName", description="The system property name."), - @Parameter(in="body", description="The new system property value."), - }, - responses={ - @Response(value=302, - headers={ - @Parameter(name="Location", description="The root URL of this resource.") - } - ), - @Response(value=403, description="User is not an admin.") - } - ) - public Redirect setSystemProperty(@Path String propertyName, @Body String value) { - System.setProperty(propertyName, value); - return new Redirect(); - } - - @RestMethod( - name="POST", path="/", - summary="Add an entire set of system properties", - description="Takes in a map of key/value pairs and creates a set of new system properties.", - guards=AdminGuard.class, - parameters={ - @Parameter(in="path", name="propertyName", description="The system property key."), - @Parameter(in="body", description="The new system property values.", schema="{example:{key1:'val1',key2:123}}"), - }, - responses={ - @Response(value=302, - headers={ - @Parameter(name="Location", description="The root URL of this resource.") - } - ), - @Response(value=403, description="Unauthorized: User is not an admin.") - } - ) - public Redirect setSystemProperties(@Body java.util.Properties newProperties) { - System.setProperties(newProperties); - return new Redirect(); - } - - @RestMethod( - name="DELETE", path="/{propertyName}", - summary="Delete system property", - description="Deletes the specified system property.", - guards=AdminGuard.class, - parameters={ - @Parameter(in="path", name="propertyName", description="The system property name."), - }, - responses={ - @Response(value=302, - headers={ - @Parameter(name="Location", description="The root URL of this resource.") - } - ), - @Response(value=403, description="Unauthorized: User is not an admin") - } - ) - public Redirect deleteSystemProperty(@Path String propertyName) { - System.clearProperty(propertyName); - return new Redirect(); - } - - @RestMethod( - name="OPTIONS", path="/*", - summary="Show resource options", - description="Show resource options as a Swagger doc" - ) - public Swagger getOptions(RestRequest req) { - return req.getSwagger(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/TempDirResource.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/TempDirResource.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/TempDirResource.java deleted file mode 100644 index 48c6237..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/TempDirResource.java +++ /dev/null @@ -1,77 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - -import java.io.*; - -import org.apache.commons.fileupload.*; -import org.apache.commons.fileupload.servlet.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.utils.*; - -/** - * Sample resource that extends {@link DirectoryResource} to open up the temp directory as a REST resource. - */ -@RestResource( - path="/tempDir", - messages="nls/TempDirResource", - properties={ - @Property(name="rootDir", value="$S{java.io.tmpdir}"), - @Property(name="allowViews", value="true"), - @Property(name="allowDeletes", value="true"), - @Property(name="allowPuts", value="false"), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS',upload:'upload',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.TempDirResource,org.apache.juneau.rest.samples.DirectoryResource)'}"), - }, - stylesheet="styles/devops.css" -) -public class TempDirResource extends DirectoryResource { - private static final long serialVersionUID = 1L; - - /** - * [GET /upload] - Display the form entry page for uploading a file to the temp directory. - */ - @RestMethod(name="GET", path="/upload") - public ReaderResource getUploadPage(RestRequest req) throws IOException { - return req.getReaderResource("TempDirUploadPage.html", true); - } - - /** - * [POST /upload] - Upload a file as a multipart form post. - * Shows how to use the Apache Commons ServletFileUpload class for handling multi-part form posts. - */ - @RestMethod(name="POST", path="/upload", matchers=TempDirResource.MultipartFormDataMatcher.class) - public Redirect uploadFile(RestRequest req) throws Exception { - ServletFileUpload upload = new ServletFileUpload(); - FileItemIterator iter = upload.getItemIterator(req); - while (iter.hasNext()) { - FileItemStream item = iter.next(); - if (item.getFieldName().equals("contents")) { //$NON-NLS-1$ - File f = new File(getRootDir(), item.getName()); - IOPipe.create(item.openStream(), new FileOutputStream(f)).closeOut().run(); - } - } - return new Redirect(); // Redirect to the servlet root. - } - - /** Causes a 404 if POST isn't multipart/form-data */ - public static class MultipartFormDataMatcher extends RestMatcher { - @Override /* RestMatcher */ - public boolean matches(RestRequest req) { - String contentType = req.getContentType(); - return contentType != null && contentType.startsWith("multipart/form-data"); //$NON-NLS-1$ - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/TumblrParserResource.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/TumblrParserResource.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/TumblrParserResource.java deleted file mode 100644 index 9414065..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/TumblrParserResource.java +++ /dev/null @@ -1,87 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - -import java.lang.Object; - -import org.apache.juneau.*; -import org.apache.juneau.dto.Link; -import org.apache.juneau.dto.html5.*; -import org.apache.juneau.json.*; -import org.apache.juneau.microservice.*; -import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.rest.client.*; - -@RestResource( - path="/tumblrParser", - messages="nls/TumblrParserResource", - properties={ - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.TumblrParserResource)'}"), - @Property(name=HTMLDOC_title, value="Tumblr parser service"), - @Property(name=HTMLDOC_description, value="Specify a URL to a Tumblr blog and parse the results.") - } -) -public class TumblrParserResource extends Resource { - private static final long serialVersionUID = 1L; - - @RestMethod(name="GET", path="/") - public String getInstructions() throws Exception { - return "Append the Tumblr blog name to the URL above (e.g. /juneau/sample/tumblrParser/mytumblrblog)"; - } - - @RestMethod(name="GET", path="/{blogName}") - public ObjectList parseBlog(@Path String blogName) throws Exception { - ObjectList l = new ObjectList(); - RestClient rc = new RestClient(JsonSerializer.class, JsonParser.class); - try { - String site = "http://" + blogName + ".tumblr.com/api/read/json"; - ObjectMap m = rc.doGet(site).getResponse(ObjectMap.class); - int postsTotal = m.getInt("posts-total"); - for (int i = 0; i < postsTotal; i += 20) { - m = rc.doGet(site + "?start=" + i + "&num=20&filter=text").getResponse(ObjectMap.class); - ObjectList ol = m.getObjectList("posts"); - for (int j = 0; j < ol.size(); j++) { - ObjectMap om = ol.getObjectMap(j); - String type = om.getString("type"); - Entry e = new Entry(); - e.date = om.getString("date"); - if (type.equals("link")) - e.entry = new Link(om.getString("link-text"), om.getString("link-url")); - else if (type.equals("audio")) - e.entry = new ObjectMap().append("type","audio").append("audio-caption", om.getString("audio-caption")); - else if (type.equals("video")) - e.entry = new ObjectMap().append("type","video").append("video-caption", om.getString("video-caption")); - else if (type.equals("quote")) - e.entry = new ObjectMap().append("type","quote").append("quote-source", om.getString("quote-source")).append("quote-text", om.getString("quote-text")); - else if (type.equals("regular")) - e.entry = om.getString("regular-body"); - else if (type.equals("photo")) - e.entry = new Img().src(om.getString("photo-url-250")); - else - e.entry = new ObjectMap().append("type", type); - l.add(e); - } - } - } finally { - rc.closeQuietly(); - } - return l; - } - - public static class Entry { - public String date; - public Object entry; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/UrlEncodedFormResource.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/UrlEncodedFormResource.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/UrlEncodedFormResource.java deleted file mode 100644 index 1c33e87..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/UrlEncodedFormResource.java +++ /dev/null @@ -1,53 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import java.io.*; -import java.util.*; - -import org.apache.juneau.annotation.*; -import org.apache.juneau.microservice.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.transforms.*; - -/** - * Sample REST resource for loading URL-Encoded form posts into POJOs. - */ -@RestResource( - path="/urlEncodedForm", - messages="nls/UrlEncodedFormResource" -) -public class UrlEncodedFormResource extends Resource { - private static final long serialVersionUID = 1L; - - /** GET request handler */ - @RestMethod(name="GET", path="/") - public ReaderResource doGet(RestRequest req) throws IOException { - return req.getReaderResource("UrlEncodedForm.html", true); - } - - /** POST request handler */ - @RestMethod(name="POST", path="/") - public Object doPost(@Body FormInputBean input) throws Exception { - // Just mirror back the request - return input; - } - - public static class FormInputBean { - public String aString; - public int aNumber; - @BeanProperty(swap=CalendarSwap.ISO8601DT.class) - public Calendar aDate; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/addressbook/AddressBookResource.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/addressbook/AddressBookResource.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/addressbook/AddressBookResource.java deleted file mode 100644 index 03b57a6..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/addressbook/AddressBookResource.java +++ /dev/null @@ -1,320 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples.addressbook; - -import static javax.servlet.http.HttpServletResponse.*; -import static org.apache.juneau.html.HtmlDocSerializerContext.*; -import static org.apache.juneau.jena.RdfCommonContext.*; -import static org.apache.juneau.jena.RdfSerializerContext.*; -import static org.apache.juneau.rest.RestServletContext.*; -import static org.apache.juneau.samples.addressbook.AddressBook.*; - -import java.util.*; - -import org.apache.juneau.*; -import org.apache.juneau.dto.*; -import org.apache.juneau.dto.cognos.*; -import org.apache.juneau.dto.swagger.*; -import org.apache.juneau.encoders.*; -import org.apache.juneau.microservice.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.rest.converters.*; -import org.apache.juneau.rest.samples.*; -import org.apache.juneau.samples.addressbook.*; -import org.apache.juneau.transform.*; -import org.apache.juneau.utils.*; - -/** - * Proof-of-concept resource that shows off the capabilities of working with POJO resources. - * Consists of an in-memory address book repository. - */ -@RestResource( - path="/addressBook", - messages="nls/AddressBookResource", - properties={ - @Property(name=REST_allowMethodParam, value="*"), - @Property(name=HTML_uriAnchorText, value=TO_STRING), - @Property(name=SERIALIZER_quoteChar, value="'"), - @Property(name=RDF_rdfxml_tab, value="5"), - @Property(name=RDF_addRootProperty, value="true"), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.addressbook.AddressBookResource,org.apache.juneau.samples.addressbook.Address,org.apache.juneau.samples.addressbook.AddressBook,org.apache.juneau.samples.addressbook.CreateAddress,org.apache.juneau.samples.addressbook.CreatePerson,org.apache.juneau.samples.addressbook.IAddressBook,org.apache.juneau.samples.addressbook.Person)'}"), - // Resolve all relative URIs so that they're relative to this servlet! - @Property(name=SERIALIZER_relativeUriBase, value="$R{servletURI}"), - }, - stylesheet="styles/devops.css", - encoders=GzipEncoder.class, - contact="{name:'John Smith',email:'[email protected]'}", - license="{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'}", - version="2.0", - termsOfService="You're on your own.", - tags="[{name:'Java',description:'Java utility',externalDocs:{description:'Home page',url:'http://juneau.apache.org'}}]", - externalDocs="{description:'Home page',url:'http://juneau.apache.org'}" -) -public class AddressBookResource extends ResourceJena { - private static final long serialVersionUID = 1L; - - // The in-memory address book - private AddressBook addressBook; - - @Override /* Servlet */ - public void init() { - - try { - // Create the address book - addressBook = new AddressBook(java.net.URI.create("")); - - // Add some people to our address book by default - addressBook.createPerson( - new CreatePerson( - "Barack Obama", - toCalendar("Aug 4, 1961"), - new CreateAddress("1600 Pennsylvania Ave", "Washington", "DC", 20500, true), - new CreateAddress("5046 S Greenwood Ave", "Chicago", "IL", 60615, false) - ) - ); - addressBook.createPerson( - new CreatePerson( - "George Walker Bush", - toCalendar("Jul 6, 1946"), - new CreateAddress("43 Prairie Chapel Rd", "Crawford", "TX", 76638, true), - new CreateAddress("1600 Pennsylvania Ave", "Washington", "DC", 20500, false) - ) - ); - - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** - * [GET /] - * Get root page. - */ - @RestMethod(name="GET", path="/", - converters=Queryable.class - ) - public Link[] getRoot() throws Exception { - return new Link[] { - new Link("people", "people"), - new Link("addresses", "addresses") - }; - } - - /** - * [GET /people/*] - * Get all people in the address book. - * Traversable filtering enabled to allow nodes in returned POJO tree to be addressed. - * Introspectable filtering enabled to allow public methods on the returned object to be invoked. - */ - @RestMethod(name="GET", path="/people/*", - converters={Traversable.class,Queryable.class,Introspectable.class} - ) - public AddressBook getAllPeople() throws Exception { - return addressBook; - } - - /** - * [GET /people/{id}/*] - * Get a single person by ID. - * Traversable filtering enabled to allow nodes in returned POJO tree to be addressed. - * Introspectable filtering enabled to allow public methods on the returned object to be invoked. - */ - @RestMethod(name="GET", path="/people/{id}/*", - converters={Traversable.class,Queryable.class,Introspectable.class} - ) - public Person getPerson(@Path int id) throws Exception { - return findPerson(id); - } - - /** - * [GET /addresses/*] - * Get all addresses in the address book. - */ - @RestMethod(name="GET", path="/addresses/*", - converters={Traversable.class,Queryable.class} - ) - public List<Address> getAllAddresses() throws Exception { - return addressBook.getAddresses(); - } - - /** - * [GET /addresses/{id}/*] - * Get a single address by ID. - */ - @RestMethod(name="GET", path="/addresses/{id}/*", - converters={Traversable.class,Queryable.class} - ) - public Address getAddress(@Path int id) throws Exception { - return findAddress(id); - } - - /** - * [POST /people] - * Create a new Person bean. - */ - @RestMethod(name="POST", path="/people", - guards=AdminGuard.class - ) - public Redirect createPerson(@Body CreatePerson cp) throws Exception { - Person p = addressBook.createPerson(cp); - return new Redirect("people/{0}", p.id); - } - - /** - * [POST /people/{id}/addresses] - * Create a new Address bean. - */ - @RestMethod(name="POST", path="/people/{id}/addresses", - guards=AdminGuard.class - ) - public Redirect createAddress(@Path int id, @Body CreateAddress ca) throws Exception { - Person p = findPerson(id); - Address a = p.createAddress(ca); - return new Redirect("addresses/{0}", a.id); - } - - /** - * [DELETE /people/{id}] - * Delete a Person bean. - */ - @RestMethod(name="DELETE", path="/people/{id}", - guards=AdminGuard.class - ) - public String deletePerson(@Path int id) throws Exception { - addressBook.removePerson(id); - return "DELETE successful"; - } - - /** - * [DELETE /addresses/{id}] - * Delete an Address bean. - */ - @RestMethod(name="DELETE", path="/addresses/{id}", - guards=AdminGuard.class - ) - public String deleteAddress(@Path int addressId) throws Exception { - Person p = addressBook.findPersonWithAddress(addressId); - if (p == null) - throw new RestException(SC_NOT_FOUND, "Person not found"); - Address a = findAddress(addressId); - p.addresses.remove(a); - return "DELETE successful"; - } - - /** - * [PUT /people/{id}/*] - * Change property on Person bean. - */ - @RestMethod(name="PUT", path="/people/{id}/*", - guards=AdminGuard.class - ) - public String updatePerson(RestRequest req, @Path int id) throws Exception { - try { - Person p = findPerson(id); - String pathRemainder = req.getPathRemainder(); - PojoRest r = new PojoRest(p); - ClassMeta<?> cm = r.getClassMeta(pathRemainder); - Object in = req.getBody(cm); - r.put(pathRemainder, in); - return "PUT successful"; - } catch (Exception e) { - throw new RestException(SC_BAD_REQUEST, "PUT unsuccessful").initCause(e); - } - } - - /** - * [PUT /addresses/{id}/*] - * Change property on Address bean. - */ - @RestMethod(name="PUT", path="/addresses/{id}/*", - guards=AdminGuard.class - ) - public String updateAddress(RestRequest req, @Path int id) throws Exception { - try { - Address a = findAddress(id); - String pathInfo = req.getPathInfo(); - PojoRest r = new PojoRest(a); - ClassMeta<?> cm = r.getClassMeta(pathInfo); - Object in = req.getBody(cm); - r.put(pathInfo, in); - return "PUT successful"; - } catch (Exception e) { - throw new RestException(SC_BAD_REQUEST, "PUT unsuccessful").initCause(e); - } - } - - /** - * [INIT /] - * Reinitialize this resource. - */ - @RestMethod(name="INIT", path="/", - guards=AdminGuard.class - ) - public String doInit() throws Exception { - init(); - return "OK"; - } - - /** - * [GET /cognos] - * Get data in Cognos/XML format - */ - @RestMethod(name="GET", path="/cognos") - public DataSet getCognosData() throws Exception { - - // The Cognos metadata - Column[] items = { - new Column("name", "xs:String", 255), - new Column("age", "xs:int"), - new Column("numAddresses", "xs:int") - .addPojoSwap( - new PojoSwap<Person,Integer>() { - @Override /* PojoSwap */ - public Integer swap(BeanSession session, Person p) { - return p.addresses.size(); - } - } - ) - }; - - return new DataSet(items, addressBook, this.getBeanContext().createSession()); - } - - /** - * [OPTIONS /*] - * View resource options - */ - @Override /* RestServletJenaDefault */ - @RestMethod(name="OPTIONS", path="/*") - public Swagger getOptions(RestRequest req) { - return req.getSwagger(); - } - - /** Convenience method - Find a person by ID */ - private Person findPerson(int id) throws RestException { - Person p = addressBook.findPerson(id); - if (p == null) - throw new RestException(SC_NOT_FOUND, "Person not found"); - return p; - } - - /** Convenience method - Find an address by ID */ - private Address findAddress(int id) throws RestException { - Address a = addressBook.findAddress(id); - if (a == null) - throw new RestException(SC_NOT_FOUND, "Address not found"); - return a; - } -} - http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/addressbook/ClientTest.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/addressbook/ClientTest.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/addressbook/ClientTest.java deleted file mode 100644 index 3e4b59c..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/addressbook/ClientTest.java +++ /dev/null @@ -1,107 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples.addressbook; - -import java.text.*; -import java.util.*; - -import org.apache.juneau.json.*; -import org.apache.juneau.rest.client.*; -import org.apache.juneau.samples.addressbook.*; -import org.apache.juneau.xml.*; - -/** - * Sample client code for interacting with AddressBookResource - */ -public class ClientTest { - - public static void main(String[] args) { - - try { - System.out.println("Running client test..."); - - // Create a client to handle XML requests and responses. - RestClient client = new RestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT); - RestClient xmlClient = new RestClient(XmlSerializer.DEFAULT_NS, XmlParser.DEFAULT); - try { - String root = "http://localhost:10000/addressBook"; - - // Get the current contents of the address book - AddressBook ab = client.doGet(root + "/people").getResponse(AddressBook.class); - System.out.println("Number of entries = " + ab.getPeople().size()); - - // Same, but use XML as the protocol both ways - ab = xmlClient.doGet(root + "/people").getResponse(AddressBook.class); - System.out.println("Number of entries = " + ab.getPeople().size()); - - - // Delete the existing entries - for (Person p : ab.getPeople()) { - String r = client.doDelete(p.uri).getResponse(String.class); - System.out.println("Deleted person " + p.name + ", response = " + r); - } - - // Make sure they're gone - ab = client.doGet(root + "/people").getResponse(AddressBook.class); - System.out.println("Number of entries = " + ab.getPeople().size()); - - // Add 1st person again - CreatePerson cp = new CreatePerson( - "Barack Obama", - toCalendar("Aug 4, 1961"), - new CreateAddress("1600 Pennsylvania Ave", "Washington", "DC", 20500, true), - new CreateAddress("5046 S Greenwood Ave", "Chicago", "IL", 60615, false) - ); - Person p = client.doPost(root + "/people", cp).getResponse(Person.class); - System.out.println("Created person " + p.name + ", uri = " + p.uri); - - // Add 2nd person again, but add addresses separately - cp = new CreatePerson( - "George Walker Bush", - toCalendar("Jul 6, 1946") - ); - p = client.doPost(root + "/people", cp).getResponse(Person.class); - System.out.println("Created person " + p.name + ", uri = " + p.uri); - - // Add addresses to 2nd person - CreateAddress ca = new CreateAddress("43 Prairie Chapel Rd", "Crawford", "TX", 76638, true); - Address a = client.doPost(p.uri + "/addresses", ca).getResponse(Address.class); - System.out.println("Created address " + a.uri); - - ca = new CreateAddress("1600 Pennsylvania Ave", "Washington", "DC", 20500, false); - a = client.doPost(p.uri + "/addresses", ca).getResponse(Address.class); - System.out.println("Created address " + a.uri); - - // Find 1st person, and change name - Person[] pp = client.doGet(root + "/people?q=(name='Barack+Obama')").getResponse(Person[].class); - String r = client.doPut(pp[0].uri + "/name", "Barack Hussein Obama").getResponse(String.class); - System.out.println("Changed name, response = " + r); - p = client.doGet(pp[0].uri).getResponse(Person.class); - System.out.println("New name = " + p.name); - } finally { - client.closeQuietly(); - xmlClient.closeQuietly(); - } - - } catch (Exception e) { - e.printStackTrace(); - } - } - - // Utility method - public static Calendar toCalendar(String birthDate) throws Exception { - Calendar c = new GregorianCalendar(); - c.setTime(DateFormat.getDateInstance(DateFormat.MEDIUM).parse(birthDate)); - return c; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/Address.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/Address.java b/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/Address.java deleted file mode 100755 index b41698c..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/Address.java +++ /dev/null @@ -1,54 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.samples.addressbook; - -import java.net.URI; - -import org.apache.juneau.annotation.*; -import org.apache.juneau.jena.annotation.*; -import org.apache.juneau.xml.annotation.*; - -/** - * Address bean - */ -@Xml(prefix="addr") -@Rdf(prefix="addr") -@Bean(typeName="address") -public class Address { - - private static int nextAddressId = 1; - - // Bean properties - @Rdf(beanUri=true) public URI uri; - public URI personUri; - public int id; - @Xml(prefix="mail") @Rdf(prefix="mail") public String street, city, state; - @Xml(prefix="mail") @Rdf(prefix="mail") public int zip; - public boolean isCurrent; - - /** Bean constructor - Needed for instantiating on client side */ - public Address() {} - - /** Normal constructor - Needed for instantiating on server side */ - public Address(URI addressBookUri, URI personUri, CreateAddress ca) throws Exception { - this.id = nextAddressId++; - if (addressBookUri != null) - this.uri = addressBookUri.resolve("addresses/" + id); - this.personUri = personUri; - this.street = ca.street; - this.city = ca.city; - this.state = ca.state; - this.zip = ca.zip; - this.isCurrent = ca.isCurrent; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/AddressBook.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/AddressBook.java b/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/AddressBook.java deleted file mode 100755 index f220f53..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/AddressBook.java +++ /dev/null @@ -1,102 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.samples.addressbook; - -import java.net.URI; -import java.text.*; -import java.util.*; - -import org.apache.juneau.annotation.*; - -/** - * Address book bean - */ -@Bean(typeName="addressBook") -public class AddressBook extends LinkedList<Person> implements IAddressBook { - private static final long serialVersionUID = 1L; - - // The URL of this resource - private URI uri; - - /** Bean constructor - Needed for instantiating on server side */ - public AddressBook() {} - - /** Bean constructor - Needed for instantiating on client side */ - public AddressBook(URI uri) throws Exception { - this.uri = uri; - } - - @Override /* IAddressBook */ - public List<Person> getPeople() { - return this; - } - - @Override /* IAddressBook */ - public Person createPerson(CreatePerson cp) throws Exception { - Person p = new Person(uri, cp); - add(p); - return p; - } - - @Override /* IAddressBook */ - public Person findPerson(int id) { - for (Person p : this) - if (p.id == id) - return p; - return null; - } - - @Override /* IAddressBook */ - public Address findAddress(int id) { - for (Person p : this) - for (Address a : p.addresses) - if (a.id == id) - return a; - return null; - } - - @Override /* IAddressBook */ - public Person findPersonWithAddress(int id) { - for (Person p : this) - for (Address a : p.addresses) - if (a.id == id) - return p; - return null; - } - - @Override /* IAddressBook */ - public List<Address> getAddresses() { - Set<Address> s = new LinkedHashSet<Address>(); - for (Person p : this) - for (Address a : p.addresses) - s.add(a); - return new ArrayList<Address>(s); - } - - @Override /* IAddressBook */ - public Person removePerson(int id) { - Person p = findPerson(id); - if (p != null) - this.remove(p); - return p; - } - - /** Utility method */ - public static Calendar toCalendar(String birthDate) throws Exception { - Calendar c = new GregorianCalendar(); - c.setTime(DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US).parse(birthDate)); - return c; - } -} - - http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/CreateAddress.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/CreateAddress.java b/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/CreateAddress.java deleted file mode 100755 index 123f29f..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/CreateAddress.java +++ /dev/null @@ -1,43 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.samples.addressbook; - -import org.apache.juneau.annotation.*; -import org.apache.juneau.jena.annotation.*; -import org.apache.juneau.xml.annotation.*; - -/** - * POJO for creating a new address - */ -@Xml(prefix="addr") -@Rdf(prefix="addr") -@Bean(typeName="address") -public class CreateAddress { - - // Bean properties - @Xml(prefix="mail") @Rdf(prefix="mail") public String street, city, state; - @Xml(prefix="mail") @Rdf(prefix="mail") public int zip; - public boolean isCurrent; - - /** Bean constructor - Needed for instantiating on server side */ - public CreateAddress() {} - - /** Normal constructor - Needed for instantiating on client side */ - public CreateAddress(String street, String city, String state, int zip, boolean isCurrent) { - this.street = street; - this.city = city; - this.state = state; - this.zip = zip; - this.isCurrent = isCurrent; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/CreatePerson.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/CreatePerson.java b/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/CreatePerson.java deleted file mode 100755 index 65a2b54..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/CreatePerson.java +++ /dev/null @@ -1,45 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.samples.addressbook; - -import java.util.*; - -import org.apache.juneau.annotation.*; -import org.apache.juneau.jena.annotation.*; -import org.apache.juneau.transforms.*; -import org.apache.juneau.xml.annotation.*; - -/** - * POJO for creating a new person - */ -@Xml(prefix="per") -@Rdf(prefix="per") -@Bean(typeName="person") -public class CreatePerson { - - // Bean properties - public String name; - @BeanProperty(swap=CalendarSwap.DateMedium.class) public Calendar birthDate; - public LinkedList<CreateAddress> addresses = new LinkedList<CreateAddress>(); - - /** Bean constructor - Needed for instantiating on server side */ - public CreatePerson() {} - - /** Normal constructor - Needed for instantiating on client side */ - public CreatePerson(String name, Calendar birthDate, CreateAddress...addresses) { - this.name = name; - this.birthDate = birthDate; - this.addresses.addAll(Arrays.asList(addresses)); - } -} - http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/IAddressBook.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/IAddressBook.java b/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/IAddressBook.java deleted file mode 100755 index 21e2426..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/IAddressBook.java +++ /dev/null @@ -1,45 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.samples.addressbook; - -import java.util.*; - -import org.apache.juneau.rest.samples.*; - -/** - * Interface used to help illustrate proxy interfaces. - * See {@link SampleRemoteableServlet}. - */ -public interface IAddressBook { - - /** Return all people in the address book */ - List<Person> getPeople(); - - /** Return all addresses in the address book */ - List<Address> getAddresses(); - - /** Create a person in this address book */ - Person createPerson(CreatePerson cp) throws Exception; - - /** Find a person by id */ - Person findPerson(int id); - - /** Find an address by id */ - Address findAddress(int id); - - /** Find a person by address id */ - Person findPersonWithAddress(int id); - - /** Remove a person by id */ - Person removePerson(int id); -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/Person.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/Person.java b/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/Person.java deleted file mode 100755 index e3fadb0..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/Person.java +++ /dev/null @@ -1,73 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.samples.addressbook; - -import java.net.URI; -import java.util.*; - -import org.apache.juneau.annotation.*; -import org.apache.juneau.jena.annotation.*; -import org.apache.juneau.transforms.*; -import org.apache.juneau.xml.annotation.*; - -/** - * Person POJO - */ -@Xml(prefix="per") -@Rdf(prefix="per") -@Bean(typeName="person") -public class Person { - - private static int nextPersonId = 1; - - // Bean properties - @Rdf(beanUri=true) public URI uri; - public URI addressBookUri; - public int id; - public String name; - @BeanProperty(swap=CalendarSwap.DateMedium.class) public Calendar birthDate; - public LinkedList<Address> addresses = new LinkedList<Address>(); - - /** Bean constructor - Needed for instantiating on server side */ - public Person() {} - - /** Normal constructor - Needed for instantiating on client side */ - public Person(URI addressBookUri, CreatePerson cp) throws Exception { - this.id = nextPersonId++; - this.addressBookUri = addressBookUri; - if (addressBookUri != null) - this.uri = addressBookUri.resolve("people/" + id); - this.name = cp.name; - this.birthDate = cp.birthDate; - for (CreateAddress ca : cp.addresses) - this.addresses.add(new Address(addressBookUri, uri, ca)); - } - - /** Extra read-only bean property */ - public int getAge() { - return new GregorianCalendar().get(Calendar.YEAR) - birthDate.get(Calendar.YEAR); - } - - /** Convenience method - Add an address for this person */ - public Address createAddress(CreateAddress ca) throws Exception { - Address a = new Address(addressBookUri, uri, ca); - addresses.add(a); - return a; - } - - /** Extra method (for method invocation example) */ - public String sayHello(String toPerson, int age) { - return name + " says hello to " + toPerson + " who is " + age + " years old"; - } -} - http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/package-info.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/package-info.java b/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/package-info.java deleted file mode 100755 index b84ad3a..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/package-info.java +++ /dev/null @@ -1,35 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -// XML namespaces used in this package -@XmlSchema( - prefix="ab", - xmlNs={ - @XmlNs(prefix="ab", namespaceURI="http://www.apache.org/addressBook/"), - @XmlNs(prefix="per", namespaceURI="http://www.apache.org/person/"), - @XmlNs(prefix="addr", namespaceURI="http://www.apache.org/address/"), - @XmlNs(prefix="mail", namespaceURI="http://www.apache.org/mail/") - } -) -@RdfSchema( - prefix="ab", - rdfNs={ - @RdfNs(prefix="ab", namespaceURI="http://www.apache.org/addressBook/"), - @RdfNs(prefix="per", namespaceURI="http://www.apache.org/person/"), - @RdfNs(prefix="addr", namespaceURI="http://www.apache.org/address/"), - @RdfNs(prefix="mail", namespaceURI="http://www.apache.org/mail/") - } -) -package org.apache.juneau.samples.addressbook; -import org.apache.juneau.jena.annotation.*; -import org.apache.juneau.xml.annotation.*; - http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/package.html ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/package.html b/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/package.html deleted file mode 100755 index 21caee9..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/samples/addressbook/package.html +++ /dev/null @@ -1,42 +0,0 @@ -<!-- -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - ***************************************************************************************************************************/ - --> -<html> -<head> - <style type="text/css"> - /* For viewing in Page Designer */ - @IMPORT url("../../../../../../org.apache.juneau/javadoc.css"); - - /* For viewing in REST interface */ - @IMPORT url("../htdocs/javadoc.css"); - body { - margin: 20px; - } - </style> - <script> - /* Replace all @code and @link tags. */ - window.onload = function() { - document.body.innerHTML = document.body.innerHTML.replace(/\{\@code ([^\}]+)\}/g, '<code>$1</code>'); - document.body.innerHTML = document.body.innerHTML.replace(/\{\@link (([^\}]+)\.)?([^\.\}]+)\}/g, '<code>$3</code>'); - } - </script> -</head> -<body> -<p>Javadocs for Address Book Resource Example</p> -<p> - Pretend there is documentation here. -</p> -</body> -</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/resources/org/apache/juneau/rest/samples/CodeFormatterResource.html ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/resources/org/apache/juneau/rest/samples/CodeFormatterResource.html b/juneau-samples/src/main/resources/org/apache/juneau/rest/samples/CodeFormatterResource.html deleted file mode 100644 index 90441cf..0000000 --- a/juneau-samples/src/main/resources/org/apache/juneau/rest/samples/CodeFormatterResource.html +++ /dev/null @@ -1,68 +0,0 @@ -<!DOCTYPE HTML> -<!-- -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - ***************************************************************************************************************************/ - --> -<html> -<head> - <style type='text/css'> - @import '$R{servletURI}/style.css'; - </style> - <script> - // Quick and dirty function to allow tabs in textarea. - function checkTab(e) { - if (e.keyCode == 9) { - var t = e.target; - var ss = t.selectionStart, se = t.selectionEnd; - t.value = t.value.slice(0,ss).concat('\t').concat(t.value.slice(ss,t.value.length)); - e.preventDefault(); - } - } - // Load results from IFrame into this document. - function loadResults(buff) { - var doc = buff.contentDocument || buff.contentWindow.document; - var buffBody = doc.getElementById('data'); - if (buffBody != null) { - document.getElementById('results').innerHTML = buffBody.innerHTML; - } - } - </script> -</head> -<body> - <h3 class='title'>Code Formatter</h3> - <div class='data'> - <form id='form' action='codeFormatter' method='POST' target='buff'> - <table> - <tr> - <th>Language: </th> - <td> - <select name='lang'> - <option value='java'>Java</option> - <option value='xml'>XML</option> - </select> - </td> - <td><button type='submit'>Submit</button><button type='reset'>Reset</button></td> - </tr> - <tr> - <td colspan='3'><textarea name='code' style='min-width:800px;min-height:400px;font-family:Courier;font-size:9pt;' onkeydown='checkTab(event)'></textarea></td> - </tr> - </table> - </form> - <div id='results' class='monospace'> - </div> - </div> - <iframe name='buff' style='display:none' onload="parent.loadResults(this)"></iframe> -</body> -</html> - http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/resources/org/apache/juneau/rest/samples/SqlQueryResource.html ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/resources/org/apache/juneau/rest/samples/SqlQueryResource.html b/juneau-samples/src/main/resources/org/apache/juneau/rest/samples/SqlQueryResource.html deleted file mode 100644 index 1119400..0000000 --- a/juneau-samples/src/main/resources/org/apache/juneau/rest/samples/SqlQueryResource.html +++ /dev/null @@ -1,66 +0,0 @@ -<!DOCTYPE HTML> -<!-- -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - ***************************************************************************************************************************/ - --> -<html> -<head> - <style type='text/css'> - @import '$R{servletURI}/style.css'; - </style> - <script> - // Quick and dirty function to allow tabs in textarea. - function checkTab(e) { - if (e.keyCode == 9) { - var t = e.target; - var ss = t.selectionStart, se = t.selectionEnd; - t.value = t.value.slice(0,ss).concat('\t').concat(t.value.slice(ss,t.value.length)); - e.preventDefault(); - } - } - // Load results from IFrame into this document. - function loadResults(b) { - var doc = b.contentDocument || b.contentWindow.document; - var data = doc.getElementById('data') || doc.getElementsByTagName('body')[0]; - document.getElementById('results').innerHTML = data.innerHTML; - } - </script> -</head> -<body> - <h3 class='title'>SQL Query API</h3> - <div class='data'> - <form action='sqlQuery' method='POST' target='buf'> - <table> - <tr> - <th>Position (1-10000):</th> - <td><input name='pos' type='number' value='1'></td> - <th>Limit (1-10000):</th> - <td><input name='limit' type='number' value='100'></td> - <td><button type='submit'>Submit</button><button type='reset'>Reset</button></td> - </tr> - <tr> - <td colspan="5"> - <textarea name='sql' style='width:100%;height:200px;font-family:Courier;font-size:9pt;' onkeydown='checkTab(event)'></textarea> - </td> - </tr> - </table> - </form> - <br> - <div id='results'> - </div> - </div> - <iframe name='buf' style='display:none' onload="parent.loadResults(this)"></iframe> -</body> -</html> - http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/resources/org/apache/juneau/rest/samples/TempDirUploadPage.html ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/resources/org/apache/juneau/rest/samples/TempDirUploadPage.html b/juneau-samples/src/main/resources/org/apache/juneau/rest/samples/TempDirUploadPage.html deleted file mode 100644 index 947f8bf..0000000 --- a/juneau-samples/src/main/resources/org/apache/juneau/rest/samples/TempDirUploadPage.html +++ /dev/null @@ -1,34 +0,0 @@ -<!DOCTYPE HTML> -<!-- -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - ***************************************************************************************************************************/ - --> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> - <style type='text/css'> - @import '$R{servletURI}/style.css'; - </style> -</head> -<body> - <h3 class='title'>$R{servletTitle}</h3> - <h5 class="description">$R{servletDescription}</h5> - <div class='data'> - <form id='form' action='$R{servletURI}/upload' method='POST' target='buff' enctype="multipart/form-data"> - <input name="contents" type="file"><button type="submit">Submit</button> - </form> - </div> -</body> -</html> - http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/resources/org/apache/juneau/rest/samples/UrlEncodedForm.html ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/resources/org/apache/juneau/rest/samples/UrlEncodedForm.html b/juneau-samples/src/main/resources/org/apache/juneau/rest/samples/UrlEncodedForm.html deleted file mode 100644 index 0c2d039..0000000 --- a/juneau-samples/src/main/resources/org/apache/juneau/rest/samples/UrlEncodedForm.html +++ /dev/null @@ -1,62 +0,0 @@ -<!DOCTYPE HTML> -<!-- -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - ***************************************************************************************************************************/ - --> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> - <style type='text/css'> - @import '$R{servletURI}/style.css'; - </style> - <script type="text/javascript"> - // Load results from IFrame into this document. - function loadResults(buff) { - var doc = buff.contentDocument || buff.contentWindow.document; - var buffBody = doc.getElementById('data'); - document.getElementById('results').innerHTML = buffBody.innerHTML; - } - </script> -</head> -<body> - <h3 class='title'>$R{servletTitle}</h3> - <h5 class="description">$R{servletDescription}</h5> - <div class='data'> - <form id='form' action='$R{servletURI}' method='POST' target='buff'> - <table> - <tr> - <th>$L{aString}</th> - <td><input name="aString" type="text"></td> - </tr> - <tr> - <th>$L{aNumber}</th> - <td><input name="aNumber" type="number"></td> - </tr> - <tr> - <th>$L{aDate}</th> - <td><input name="aDate" type="datetime"> (ISO8601, e.g. "<code>2001-07-04T15:30:45Z</code>")</td> - </tr> - <tr> - <td colspan='2' align='right'><button type="submit">$L{submit}</button></td> - </tr> - </table> - </form> - <br> - <div id='results'> - </div> - </div> - <iframe name='buff' style='display:none' onload="parent.loadResults(this)"></iframe> -</body> -</html> -
