http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/AddressBookResourceTest.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/AddressBookResourceTest.java b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/AddressBookResourceTest.java deleted file mode 100644 index 99829f7..0000000 --- a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/AddressBookResourceTest.java +++ /dev/null @@ -1,301 +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.examples.rest; - -import static org.apache.juneau.examples.rest.TestUtils.*; -import static org.apache.juneau.xml.XmlSerializerContext.*; -import static org.junit.Assert.*; - -import java.util.*; - -import org.apache.juneau.*; -import org.apache.juneau.examples.addressbook.*; -import org.apache.juneau.html.*; -import org.apache.juneau.json.*; -import org.apache.juneau.rest.client.*; -import org.apache.juneau.transforms.*; -import org.apache.juneau.xml.*; -import org.junit.*; - -@SuppressWarnings({"serial"}) -public class AddressBookResourceTest extends RestTestcase { - - private static boolean debug = false; - - static RestClient[] clients; - - @BeforeClass - public static void beforeClass() throws Exception { - clients = new RestClient[] { - SamplesMicroservice.client() - .pojoSwaps(CalendarSwap.DateMedium.class) - .property(XML_autoDetectNamespaces, true) - .build(), - SamplesMicroservice.client() - .serializer(XmlSerializer.class) - .parser(XmlParser.class) - .pojoSwaps(CalendarSwap.DateMedium.class) - .property(XML_autoDetectNamespaces, true) - .build(), - SamplesMicroservice.client() - .serializer(HtmlSerializer.class) - .parser(HtmlParser.class) - .accept("text/html+stripped") - .pojoSwaps(CalendarSwap.DateMedium.class) - .property(XML_autoDetectNamespaces, true) - .build(), - SamplesMicroservice.client() - .serializer(XmlSerializer.class) - .parser(HtmlParser.class) - .accept("text/html+stripped") - .pojoSwaps(CalendarSwap.DateMedium.class) - .property(XML_autoDetectNamespaces, true) - .build(), - }; - } - - @AfterClass - public static void afterClass() { - for (RestClient c : clients) { - c.closeQuietly(); - } - } - - - //==================================================================================================== - // Get AddressBookResource as JSON - //==================================================================================================== - @Test - public void testBasic() throws Exception { - String in = "" - +"{" - +"\n name: \"Bill Clinton\", " - +"\n age: 66, " - +"\n birthDate: \"Aug 19, 1946\", " - +"\n addresses: [" - +"\n {" - +"\n street: \"a3\", " - +"\n city: \"b3\", " - +"\n state: \"c3\", " - +"\n zip: 3, " - +"\n isCurrent: false" - +"\n }" - +"\n ]" - +"\n}"; - JsonParser p = new JsonParserBuilder().pojoSwaps(CalendarSwap.DateMedium.class).build(); - Person person = p.parse(in, Person.class); - if (debug) System.err.println(person); - } - - // A list of People objects. - public static class PersonList extends LinkedList<Person> {} - - //==================================================================================================== - // PojoRest tests - //==================================================================================================== - @Test - public void testPojoRest() throws Exception { - for (RestClient client : clients) { - int rc; - Person p; - List<Person> people; - - // Reinitialize the resource - rc = client.doGet("/addressBook?method=init").run(); - assertEquals(200, rc); - - // Simple GETs - people = client.doGet("/addressBook/people").getResponse(PersonList.class); - assertEquals("Barack Obama", people.get(0).name); - assertEquals(76638, people.get(1).addresses.get(0).zip); - - // PUT a simple String field - p = people.get(0); - rc = client.doPut(p.uri+"/name", "foo").run(); - assertEquals(200, rc); - String name = client.doGet(p.uri+"/name").getResponse(String.class); - assertEquals("foo", name); - p = client.doGet(p.uri).getResponse(Person.class); - assertEquals("foo", p.name); - - // POST an address as JSON - CreateAddress ca = new CreateAddress("a1","b1","c1",1,false); - Address a = client.doPost(p.uri + "/addresses", new ObjectMap(BeanContext.DEFAULT.createSession().toBeanMap(ca))).getResponse(Address.class); - assertEquals("a1", a.street); - a = client.doGet(a.uri).getResponse(Address.class); - assertEquals("a1", a.street); - assertEquals(1, a.zip); - assertFalse(a.isCurrent); - - // POST an address as a bean - ca = new CreateAddress("a2","b2","c2",2,true); - a = client.doPost(p.uri + "/addresses", ca).getResponse(Address.class); - assertEquals("a2", a.street); - a = client.doGet(a.uri).getResponse(Address.class); - assertEquals("a2", a.street); - assertEquals(2, a.zip); - assertTrue(a.isCurrent); - - // POST a person - CreatePerson billClinton = new CreatePerson("Bill Clinton", AddressBook.toCalendar("Aug 19, 1946"), - new CreateAddress("a3","b3","c3",3,false) - ); - rc = client.doPost("/addressBook/people", billClinton).run(); - assertEquals(200, rc); - people = client.doGet("/addressBook/people").getResponse(PersonList.class); - p = people.get(2); - assertEquals(3, people.size()); - assertEquals("Bill Clinton", p.name); - - // DELETE an address - rc = client.doDelete(p.addresses.get(0).uri).run(); - assertEquals(200, rc); - people = client.doGet("/addressBook/people").getResponse(PersonList.class); - p = people.get(2); - assertEquals(0, p.addresses.size()); - - // DELETE a person - rc = client.doDelete(p.uri).run(); - assertEquals(200, rc); - people = client.doGet("/addressBook/people").getResponse(PersonList.class); - assertEquals(2, people.size()); - - // Reinitialize the resource - rc = client.doGet("/addressBook?method=init").run(); - assertEquals(200, rc); - } - } - - //==================================================================================================== - // PojoQuery tests - //==================================================================================================== - @Test - public void testPojoQuery() throws Exception { - - for (RestClient client : clients) { - RestCall r; - List<Person> people; - - // Reinitialize the resource - int rc = client.doGet("/addressBook?method=init").run(); - assertEquals(200, rc); - - r = client.doGet("/addressBook/people?s=name=B*"); - people = r.getResponse(PersonList.class); - assertEquals(1, people.size()); - assertEquals("Barack Obama", people.get(0).name); - - r = client.doGet("/addressBook/people?s=name='Barack+Obama'"); - people = r.getResponse(PersonList.class); - assertEquals(1, people.size()); - assertEquals("Barack Obama", people.get(0).name); - - r = client.doGet("/addressBook/people?s=name='Barack%20Obama'"); - people = r.getResponse(PersonList.class); - assertEquals(1, people.size()); - assertEquals("Barack Obama", people.get(0).name); - - r = client.doGet("/addressBook/people?v=name,birthDate"); - people = r.getResponse(PersonList.class); - assertEquals("Barack Obama", people.get(0).name); - assertTrue(people.get(0).getAge() > 10); - assertEquals(0, people.get(0).addresses.size()); - - r = client.doGet("/addressBook/people?v=addresses,birthDate"); - people = r.getResponse(PersonList.class); - assertNull(people.get(0).name); - assertTrue(people.get(0).getAge() > 10); - assertEquals(2, people.get(0).addresses.size()); - - r = client.doGet("/addressBook/people?o=age-"); - people = r.getResponse(PersonList.class); - assertTrue(people.get(0).getAge() > 10); - r = client.doGet("/addressBook/people?o=age"); - people = r.getResponse(PersonList.class); - assertTrue(people.get(0).getAge() > 10); - r = client.doGet("/addressBook/people?o=age+"); - people = r.getResponse(PersonList.class); - assertTrue(people.get(0).getAge() > 10); - - r = client.doGet("/addressBook/people?p=1&l=1"); - people = r.getResponse(PersonList.class); - assertEquals(1, people.size()); - assertTrue(people.get(0).getAge() > 10); - } - } - - //==================================================================================================== - // PojoIntrospector tests - //==================================================================================================== - @Test - public void testPojoIntrospector() throws Exception { - - for (RestClient client : clients) { - - List<Person> people; - - // Reinitialize the resource - int rc = client.doGet("/addressBook?method=init").run(); - assertEquals(200, rc); - - // Simple GETs - people = client.doGet("/addressBook/people").getResponse(PersonList.class); - Person p = people.get(0); - int length = client.doGet(p.uri+"/name?invokeMethod=length").getResponse(Integer.class); - assertEquals(12, length); - - String[] tokens = client.doGet(p.uri+"/name?invokeMethod=split(java.lang.String,int)&invokeArgs=['a',3]").getResponse(String[].class); - assertObjectEquals("['B','r','ck Obama']", tokens); - } - } - - //==================================================================================================== - // Interface proxy tests - //==================================================================================================== - @Test - public void testProxyInterface() throws Exception { - - for (RestClient client : clients) { - - List<Person> people; - - IAddressBook ab = client.getRemoteableProxy(IAddressBook.class, "/addressBook/proxy"); - - // Reinitialize the resource - ab.init(); - - // Simple GETs - people = ab.getPeople(); - assertEquals("Barack Obama", people.get(0).name); - assertEquals(76638, people.get(1).addresses.get(0).zip); - - // POST a person - CreatePerson billClinton = new CreatePerson("Bill Clinton", AddressBook.toCalendar("Aug 19, 1946"), - new CreateAddress("a3","b3","c3",3,false) - ); - ab.createPerson(billClinton); - people = ab.getPeople(); - assertEquals(3, people.size()); - Person p = people.get(2); - assertEquals("Bill Clinton", p.name); - - // DELETE a person - ab.removePerson(p.id); - people = ab.getPeople(); - assertEquals(2, people.size()); - - // Reinitialize the resource - ab.init(); - } - } -}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/RestTestcase.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/RestTestcase.java b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/RestTestcase.java deleted file mode 100644 index 8b7471a..0000000 --- a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/RestTestcase.java +++ /dev/null @@ -1,36 +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.examples.rest; - -import org.junit.*; - -/** - * Superclass of REST testcases that start up the REST test microservice before running the tests locally. - * - * @author James Bognar (james.bog...@salesforce.com) - */ -public class RestTestcase { - - private static boolean microserviceStarted; - - @BeforeClass - public static void setUp() { - microserviceStarted = SamplesMicroservice.startMicroservice(); - } - - @AfterClass - public static void tearDown() { - if (microserviceStarted) - SamplesMicroservice.stopMicroservice(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/RootResourcesTest.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/RootResourcesTest.java b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/RootResourcesTest.java deleted file mode 100644 index f743513..0000000 --- a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/RootResourcesTest.java +++ /dev/null @@ -1,115 +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.examples.rest; - -import static org.junit.Assert.*; - -import org.apache.juneau.*; -import org.apache.juneau.dto.swagger.*; -import org.apache.juneau.html.*; -import org.apache.juneau.json.*; -import org.apache.juneau.rest.client.*; -import org.apache.juneau.rest.labels.*; -import org.apache.juneau.xml.*; -import org.junit.*; - -public class RootResourcesTest extends RestTestcase { - - private static boolean debug = false; - - private RestClient jsonClient = SamplesMicroservice.DEFAULT_CLIENT; - - - //==================================================================================================== - // text/json - //==================================================================================================== - @Test - public void testJson() throws Exception { - RestClient client = SamplesMicroservice.DEFAULT_CLIENT; - RestCall r = client.doGet(""); - ResourceDescription[] x = r.getResponse(ResourceDescription[].class); - assertEquals("helloWorld", x[0].getName()); - assertEquals("Hello World", x[0].getDescription()); - - r = jsonClient.doOptions(""); - ObjectMap x2 = r.getResponse(ObjectMap.class); - String s = x2.getObjectMap("info").getString("description"); - if (debug) System.err.println(s); - assertTrue(s, s.startsWith("Example of a router resource page")); - } - - //==================================================================================================== - // text/xml - //==================================================================================================== - @Test - public void testXml() throws Exception { - RestClient client = SamplesMicroservice.client().parser(XmlParser.DEFAULT).build(); - RestCall r = client.doGet(""); - ResourceDescription[] x = r.getResponse(ResourceDescription[].class); - assertEquals("helloWorld", x[0].getName()); - assertEquals("Hello World", x[0].getDescription()); - - r = jsonClient.doOptions(""); - ObjectMap x2 = r.getResponse(ObjectMap.class); - String s = x2.getObjectMap("info").getString("description"); - if (debug) System.err.println(s); - assertTrue(s, s.startsWith("Example of a router resource page")); - - client.closeQuietly(); - } - - //==================================================================================================== - // text/html+stripped - //==================================================================================================== - @Test - public void testHtmlStripped() throws Exception { - RestClient client = SamplesMicroservice.client().parser(HtmlParser.DEFAULT).accept("text/html+stripped").build(); - RestCall r = client.doGet(""); - ResourceDescription[] x = r.getResponse(ResourceDescription[].class); - assertEquals("helloWorld", x[0].getName()); - assertEquals("Hello World", x[0].getDescription()); - - r = jsonClient.doOptions("").accept("text/json"); - ObjectMap x2 = r.getResponse(ObjectMap.class); - String s = x2.getObjectMap("info").getString("description"); - if (debug) System.err.println(s); - assertTrue(s, s.startsWith("Example of a router resource page")); - - client.closeQuietly(); - } - - //==================================================================================================== - // application/json+schema - //==================================================================================================== - @Test - public void testJsonSchema() throws Exception { - RestClient client = SamplesMicroservice.client().parser(JsonParser.DEFAULT).accept("text/json+schema").build(); - RestCall r = client.doGet(""); - ObjectMap m = r.getResponse(ObjectMap.class); - if (debug) System.err.println(m); - assertEquals("org.apache.juneau.rest.labels.ChildResourceDescriptions<org.apache.juneau.rest.labels.ResourceDescription>", m.getString("description")); - assertEquals("org.apache.juneau.rest.labels.ResourceDescription", m.getObjectMap("items").getString("description")); - client.closeQuietly(); - } - - //==================================================================================================== - // OPTIONS page - //==================================================================================================== - @Test - public void testOptionsPage() throws Exception { - RestCall r = jsonClient.doOptions(""); - Swagger o = r.getResponse(Swagger.class); - if (debug) System.err.println(o); - assertEquals("Example of a router resource page.", o.getInfo().getDescription()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/SampleRemoteableServicesResourceTest.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/SampleRemoteableServicesResourceTest.java b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/SampleRemoteableServicesResourceTest.java deleted file mode 100644 index 9fd8d5b..0000000 --- a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/SampleRemoteableServicesResourceTest.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.examples.rest; - -import static org.apache.juneau.xml.XmlSerializerContext.*; -import static org.junit.Assert.*; - -import java.text.*; - -import org.apache.juneau.examples.addressbook.*; -import org.apache.juneau.rest.client.*; -import org.apache.juneau.transforms.*; -import org.apache.juneau.uon.*; -import org.apache.juneau.xml.*; -import org.junit.*; - -public class SampleRemoteableServicesResourceTest extends RestTestcase { - - static RestClient[] clients; - - private static String path = SamplesMicroservice.getURI().getPath() + "/addressBook/proxy"; - - @BeforeClass - public static void beforeClass() throws Exception { - clients = new RestClient[] { - SamplesMicroservice.client() - .pojoSwaps(CalendarSwap.DateMedium.class) - .build(), - SamplesMicroservice.client(XmlSerializer.class, XmlParser.class) - .pojoSwaps(CalendarSwap.DateMedium.class) - .property(XML_autoDetectNamespaces, true) - .build(), - SamplesMicroservice.client(UonSerializer.class, UonParser.class) - .pojoSwaps(CalendarSwap.DateMedium.class) - .build(), - }; - } - - @AfterClass - public static void afterClass() { - for (RestClient c : clients) { - c.closeQuietly(); - } - } - - //==================================================================================================== - // Get AddressBookResource as JSON - //==================================================================================================== - @Test - public void testBasic() throws Exception { - for (RestClient client : clients) { - IAddressBook ab = client.getRemoteableProxy(IAddressBook.class, path); - Person p = ab.createPerson( - new CreatePerson("Test Person", - AddressBook.toCalendar("Aug 1, 1999"), - new CreateAddress("Test street", "Test city", "Test state", 12345, true)) - ); - assertEquals("Test Person", p.name); - assertEquals("Aug 1, 1999", DateFormat.getDateInstance(DateFormat.MEDIUM).format(p.birthDate.getTime())); - assertEquals("Test street", p.addresses.get(0).street); - assertEquals("Test city", p.addresses.get(0).city); - assertEquals("Test state", p.addresses.get(0).state); - assertEquals(12345, p.addresses.get(0).zip); - assertEquals(true, p.addresses.get(0).isCurrent); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/SamplesMicroservice.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/SamplesMicroservice.java b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/SamplesMicroservice.java deleted file mode 100644 index a9af029..0000000 --- a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/SamplesMicroservice.java +++ /dev/null @@ -1,110 +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.examples.rest; - -import java.net.*; -import java.util.*; - -import org.apache.juneau.microservice.*; -import org.apache.juneau.parser.*; -import org.apache.juneau.plaintext.*; -import org.apache.juneau.rest.client.*; -import org.apache.juneau.serializer.*; - -/** - * Utility class for starting up the examples microservice. - * <p> - * This class is NOT thread safe. - */ -public class SamplesMicroservice { - static RestMicroservice microservice; - static URI microserviceURI; - - // Reusable HTTP clients that get created and shut down with the microservice. - public static RestClient DEFAULT_CLIENT; - public static RestClient DEFAULT_CLIENT_PLAINTEXT; - - /** - * Starts the microservice. - * @return <jk>true</jk> if the service started, <jk>false</jk> if it's already started. - * If this returns <jk>false</jk> then don't call stopMicroservice()!. - */ - public static boolean startMicroservice() { - if (microservice != null) - return false; - try { - Locale.setDefault(Locale.US); - microservice = new RestMicroservice().setConfig("examples.cfg", false); - microserviceURI = microservice.start().getURI(); - DEFAULT_CLIENT = client().build(); - DEFAULT_CLIENT_PLAINTEXT = client(PlainTextSerializer.class, PlainTextParser.class).build(); - return true; - } catch (Throwable e) { - // Probably already started. - e.printStackTrace(); - System.err.println(e); // NOT DEBUG - return false; - } - } - - /** - * Returns the URI of the microservice. - * @return The URI of the microservice. - */ - public static URI getURI() { - if (microservice == null) - startMicroservice(); - return microserviceURI; - } - - /** - * Stops the microservice. - */ - public static void stopMicroservice() { - try { - microservice.stop(); - microservice = null; - DEFAULT_CLIENT.closeQuietly(); - DEFAULT_CLIENT_PLAINTEXT.closeQuietly(); - } catch (Exception e) { - System.err.println(e); // NOT DEBUG - } - } - - /** - * Create a new HTTP client. - */ - public static RestClientBuilder client() { - try { - return new RestClientBuilder() - .rootUrl(microserviceURI) - ; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** - * Create a new HTTP client using the specified serializer and parser. - */ - public static RestClientBuilder client(Serializer s, Parser p) { - return client().serializer(s).parser(p); - } - - /** - * Create a new HTTP client using the specified serializer and parser. - */ - public static RestClientBuilder client(Class<? extends Serializer> s, Class<? extends Parser> p) { - return client().serializer(s).parser(p); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/TestMultiPartFormPostsTest.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/TestMultiPartFormPostsTest.java b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/TestMultiPartFormPostsTest.java deleted file mode 100644 index 6c72dde..0000000 --- a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/TestMultiPartFormPostsTest.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.examples.rest; - -import static org.junit.Assert.*; -import static org.apache.juneau.internal.FileUtils.*; - -import java.io.*; - -import org.apache.http.*; -import org.apache.http.entity.mime.*; -import org.apache.juneau.rest.client.*; -import org.apache.juneau.utils.*; -import org.junit.*; - -public class TestMultiPartFormPostsTest extends RestTestcase { - - private static String URL = "/tempDir"; - boolean debug = false; - - //==================================================================================================== - // Test that RestClient can handle multi-part form posts. - //==================================================================================================== - @Test - public void testUpload() throws Exception { - RestClient client = SamplesMicroservice.DEFAULT_CLIENT; - File f = createTempFile("testMultiPartFormPosts.txt"); - IOPipe.create(new StringReader("test!"), new FileWriter(f)).closeOut().run(); - HttpEntity entity = MultipartEntityBuilder.create().addBinaryBody(f.getName(), f).build(); - client.doPost(URL + "/upload", entity); - - String downloaded = client.doGet(URL + '/' + f.getName() + "?method=VIEW").getResponseAsString(); - assertEquals("test!", downloaded); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/TestUtils.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/TestUtils.java b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/TestUtils.java deleted file mode 100644 index a38e4ed..0000000 --- a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/TestUtils.java +++ /dev/null @@ -1,366 +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.examples.rest; - -import static org.junit.Assert.*; -import static org.apache.juneau.internal.StringUtils.*; -import static org.apache.juneau.internal.IOUtils.*; - -import java.io.*; -import java.util.*; -import java.util.regex.*; - -import javax.xml.*; -import javax.xml.parsers.*; -import javax.xml.transform.*; -import javax.xml.transform.dom.*; -import javax.xml.transform.stream.*; -import javax.xml.validation.*; - -import org.apache.juneau.*; -import org.apache.juneau.json.*; -import org.apache.juneau.serializer.*; -import org.apache.juneau.transforms.*; -import org.apache.juneau.xml.*; -import org.junit.*; -import org.w3c.dom.*; -import org.w3c.dom.bootstrap.*; -import org.w3c.dom.ls.*; -import org.xml.sax.*; - -public class TestUtils { - - private static JsonSerializer js = new JsonSerializerBuilder() - .simple() - .trimNullProperties(false) - .build(); - - private static JsonSerializer jsSorted = new JsonSerializerBuilder() - .simple() - .sortCollections(true) - .sortMaps(true) - .trimNullProperties(false) - .build(); - - - private static JsonSerializer js2 = new JsonSerializerBuilder() - .simple() - .pojoSwaps(IteratorSwap.class, EnumerationSwap.class) - .build(); - - private static JsonSerializer js3 = new JsonSerializerBuilder() - .simple() - .pojoSwaps(IteratorSwap.class, EnumerationSwap.class) - .sortProperties(true) - .build(); - - /** - * Verifies that two objects are equivalent. - * Does this by doing a string comparison after converting both to JSON. - */ - public static void assertEqualObjects(Object o1, Object o2) throws SerializeException { - assertEqualObjects(o1, o2, false); - } - - /** - * Verifies that two objects are equivalent. - * Does this by doing a string comparison after converting both to JSON. - * @param sort If <jk>true</jk> sort maps and collections before comparison. - */ - public static void assertEqualObjects(Object o1, Object o2, boolean sort) throws SerializeException { - JsonSerializer s = (sort ? jsSorted : js); - String s1 = s.serialize(o1); - String s2 = s.serialize(o2); - if (s1.equals(s2)) - return; - throw new ComparisonFailure(null, s1, s2); - } - - /** - * Validates that the whitespace is correct in the specified XML. - */ - public static void checkXmlWhitespace(String out) throws SerializeException { - if (out.indexOf('\u0000') != -1) { - for (String s : out.split("\u0000")) - checkXmlWhitespace(s); - return; - } - - int indent = -1; - Pattern startTag = Pattern.compile("^(\\s*)<[^/>]+(\\s+\\S+=['\"]\\S*['\"])*\\s*>$"); - Pattern endTag = Pattern.compile("^(\\s*)</[^>]+>$"); - Pattern combinedTag = Pattern.compile("^(\\s*)<[^>/]+(\\s+\\S+=['\"]\\S*['\"])*\\s*/>$"); - Pattern contentOnly = Pattern.compile("^(\\s*)[^\\s\\<]+$"); - Pattern tagWithContent = Pattern.compile("^(\\s*)<[^>]+>.*</[^>]+>$"); - String[] lines = out.split("\n"); - try { - for (int i = 0; i < lines.length; i++) { - String line = lines[i]; - Matcher m = startTag.matcher(line); - if (m.matches()) { - indent++; - if (m.group(1).length() != indent) - throw new SerializeException("Wrong indentation detected on start tag line ''{0}''", i+1); - continue; - } - m = endTag.matcher(line); - if (m.matches()) { - if (m.group(1).length() != indent) - throw new SerializeException("Wrong indentation detected on end tag line ''{0}''", i+1); - indent--; - continue; - } - m = combinedTag.matcher(line); - if (m.matches()) { - indent++; - if (m.group(1).length() != indent) - throw new SerializeException("Wrong indentation detected on combined tag line ''{0}''", i+1); - indent--; - continue; - } - m = contentOnly.matcher(line); - if (m.matches()) { - indent++; - if (m.group(1).length() != indent) - throw new SerializeException("Wrong indentation detected on content-only line ''{0}''", i+1); - indent--; - continue; - } - m = tagWithContent.matcher(line); - if (m.matches()) { - indent++; - if (m.group(1).length() != indent) - throw new SerializeException("Wrong indentation detected on tag-with-content line ''{0}''", i+1); - indent--; - continue; - } - throw new SerializeException("Unmatched whitespace line at line number ''{0}''", i+1); - } - if (indent != -1) - throw new SerializeException("Possible unmatched tag. indent=''{0}''", indent); - } catch (SerializeException e) { - printLines(lines); - throw e; - } - } - - private static void printLines(String[] lines) { - for (int i = 0; i < lines.length; i++) - System.err.println(String.format("%4s:" + lines[i], i+1)); - } - - /** - * Validates that the specified XML conforms to the specified schema. - */ - private static void validateXml(String xml, String xmlSchema) throws Exception { - // parse an XML document into a DOM tree - DocumentBuilderFactory f = DocumentBuilderFactory.newInstance(); - f.setNamespaceAware(true); - DocumentBuilder documentBuilder = f.newDocumentBuilder(); - Document document = documentBuilder.parse(new InputSource(new StringReader(xml))); - - // create a SchemaFactory capable of understanding WXS schemas - SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - - if (xmlSchema.indexOf('\u0000') != -1) { - - // Break it up into a map of namespaceURI->schema document - final Map<String,String> schemas = new HashMap<String,String>(); - String[] ss = xmlSchema.split("\u0000"); - xmlSchema = ss[0]; - for (String s : ss) { - Matcher m = pTargetNs.matcher(s); - if (m.find()) - schemas.put(m.group(1), s); - } - - // Create a custom resolver - factory.setResourceResolver( - new LSResourceResolver() { - - @Override /* LSResourceResolver */ - public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { - - String schema = schemas.get(namespaceURI); - if (schema == null) - throw new FormattedRuntimeException("No schema found for namespaceURI ''{0}''", namespaceURI); - - try { - DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); - DOMImplementationLS domImplementationLS = (DOMImplementationLS)registry.getDOMImplementation("LS 3.0"); - LSInput in = domImplementationLS.createLSInput(); - in.setCharacterStream(new StringReader(schema)); - in.setSystemId(systemId); - return in; - - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - ); - } - - Schema schema = factory.newSchema(new StreamSource(new StringReader(xmlSchema))); - - // create a Validator instance, which can be used to validate an instance document - Validator validator = schema.newValidator(); - - // validate the DOM tree - validator.validate(new DOMSource(document)); - } - - private static Pattern pTargetNs = Pattern.compile("targetNamespace=['\"]([^'\"]+)['\"]"); - - public static void validateXml(Object o) throws Exception { - validateXml(o, XmlSerializer.DEFAULT_NS_SQ); - } - - /** - * Test whitespace and generated schema. - */ - public static void validateXml(Object o, XmlSerializer s) throws Exception { - s = s.builder().ws().ns().addNamespaceUrisToRoot(true).build(); - String xml = s.serialize(o); - - String xmlSchema = null; - try { - xmlSchema = s.getSchemaSerializer().serialize(o); - TestUtils.checkXmlWhitespace(xml); - TestUtils.checkXmlWhitespace(xmlSchema); - TestUtils.validateXml(xml, xmlSchema); - } catch (Exception e) { - System.err.println("---XML---"); - System.err.println(xml); - System.err.println("---XMLSchema---"); - System.err.println(xmlSchema); - throw e; - } - } - - public static String readFile(String p) throws Exception { - InputStream is = TestUtils.class.getResourceAsStream(p); - if (is == null) { - is = new FileInputStream(p); - } - String e = read(is); - e = e.replaceAll("\r", ""); - return e; - } - - final protected static char[] hexArray = "0123456789ABCDEF".toCharArray(); - public static String toHex(byte b) { - char[] c = new char[2]; - int v = b & 0xFF; - c[0] = hexArray[v >>> 4]; - c[1] = hexArray[v & 0x0F]; - return new String(c); - } - - public static void debugOut(Object o) { - try { - System.err.println(decodeHex(JsonSerializer.DEFAULT_LAX.serialize(o))); - } catch (SerializeException e) { - e.printStackTrace(); - } - } - - /** - * Sort an XML document by element and attribute names. - * This method is primarily meant for debugging purposes. - */ - private static final String sortXml(String xml) throws Exception { - - xml = xml.replaceAll("\\w+\\:", ""); // Strip out all namespaces. - - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setIgnoringElementContentWhitespace(true); - dbf.setNamespaceAware(false); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse(new InputSource(new StringReader(xml))); - - DOMSource s = new DOMSource(doc); - - StringWriter sw = new StringWriter(); - StreamResult sr = new StreamResult(sw); - XML_SORT_TRANSFORMER.transform(s, sr); - return sw.toString().replace('"', '\'').replace("\r", ""); - } - - /** - * Compares two XML documents for equality. - * Namespaces are stripped from each and elements/attributes are ordered in alphabetical order, - * then a simple string comparison is performed. - */ - public static final void assertXmlEquals(String expected, String actual) throws Exception { - assertEquals(sortXml(expected), sortXml(actual)); - } - - private static Transformer XML_SORT_TRANSFORMER; - static { - try { - String xsl = "" - + " <xsl:stylesheet version='1.0'" - + " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>" - + " <xsl:output omit-xml-declaration='yes' indent='yes'/>" - + " <xsl:strip-space elements='*'/>" - + " <xsl:template match='node()|@*'>" - + " <xsl:copy>" - + " <xsl:apply-templates select='@*'>" - + " <xsl:sort select='name()'/>" - + " </xsl:apply-templates>" - + " <xsl:apply-templates select='node()'>" - + " <xsl:sort select='name()'/>" - + " <xsl:sort select='text()'/>" - + " </xsl:apply-templates>" - + " </xsl:copy>" - + " </xsl:template>" - + " </xsl:stylesheet>"; - TransformerFactory tf = TransformerFactory.newInstance(); - StreamSource ss = new StreamSource(new StringReader(xsl)); - XML_SORT_TRANSFORMER = tf.newTransformer(ss); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** - * Assert that the object equals the specified string after running it through JsonSerializer.DEFAULT_LAX.toString(). - */ - public static void assertObjectEquals(String s, Object o) { - assertObjectEquals(s, o, js2); - } - - /** - * Assert that the object equals the specified string after running it through JsonSerializer.DEFAULT_LAX.toString() - * with BEAN_sortProperties set to true. - */ - public static void assertSortedObjectEquals(String s, Object o) { - assertObjectEquals(s, o, js3); - } - - /** - * Assert that the object equals the specified string after running it through ws.toString(). - */ - public static void assertObjectEquals(String s, Object o, WriterSerializer ws) { - Assert.assertEquals(s, ws.toString(o)); - } - - /** - * Replaces all newlines with pipes, then compares the strings. - */ - public static void assertTextEquals(String s, Object o) { - String s2 = o.toString().replaceAll("\\r?\\n", "|"); - Assert.assertEquals(s, s2); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/_TestSuite.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/_TestSuite.java b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/_TestSuite.java deleted file mode 100644 index d902804..0000000 --- a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/_TestSuite.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.examples.rest; - -import org.junit.*; -import org.junit.runner.*; -import org.junit.runners.*; -import org.junit.runners.Suite.*; - -/** - * Runs all the testcases in this project. - * Starts a REST service running org.apache.juneau.examples.rest.RootResources on port 10000. - * Stops the REST service after running the tests. - */ -@RunWith(Suite.class) -@SuiteClasses({ - AddressBookResourceTest.class, - RootResourcesTest.class, - SampleRemoteableServicesResourceTest.class, - TestMultiPartFormPostsTest.class -}) -public class _TestSuite { - - @BeforeClass - public static void setUp() { - SamplesMicroservice.startMicroservice(); - } - - @AfterClass - public static void tearDown() { - SamplesMicroservice.stopMicroservice(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/war/web.xml ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/war/web.xml b/juneau-examples-rest/war/web.xml deleted file mode 100755 index 8387154..0000000 --- a/juneau-examples-rest/war/web.xml +++ /dev/null @@ -1,47 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - *************************************************************************************************************************** - * 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. * - *************************************************************************************************************************** ---> -<web-app - version="2.4" - xmlns="http://java.sun.com/xml/ns/j2ee" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> - - <servlet> - <servlet-name>examples</servlet-name> - <servlet-class>org.apache.juneau.examples.rest.RootResources</servlet-class> - </servlet> - <servlet> - <servlet-name>test</servlet-name> - <servlet-class>org.apache.juneau.examples.rest.test.Root</servlet-class> - </servlet> - <servlet> - <servlet-name>testuris</servlet-name> - <servlet-class>org.apache.juneau.examples.rest.test.TestUris</servlet-class> - </servlet> - - <servlet-mapping> - <servlet-name>sample</servlet-name> - <url-pattern>/*</url-pattern> - </servlet-mapping> - <servlet-mapping> - <servlet-name>test</servlet-name> - <url-pattern>/test/*</url-pattern> - </servlet-mapping> - <servlet-mapping> - <servlet-name>testuris</servlet-name> - <url-pattern>/testuris/*</url-pattern> - </servlet-mapping> -</web-app> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-microservice-template/.classpath ---------------------------------------------------------------------- diff --git a/juneau-microservice-template/.classpath b/juneau-microservice-template/.classpath deleted file mode 100755 index c672327..0000000 --- a/juneau-microservice-template/.classpath +++ /dev/null @@ -1,29 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="/juneau-core"/> - <classpathentry kind="src" path="/juneau-rest"/> - <classpathentry kind="src" path="/juneau-microservice"/> - <classpathentry kind="src" output="target/classes" path="src/main/java"> - <attributes> - <attribute name="optional" value="true"/> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="src" output="target/test-classes" path="src/test/java"> - <attributes> - <attribute name="optional" value="true"/> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="output" path="target/classes"/> -</classpath> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-microservice-template/.gitignore ---------------------------------------------------------------------- diff --git a/juneau-microservice-template/.gitignore b/juneau-microservice-template/.gitignore deleted file mode 100644 index d274d47..0000000 --- a/juneau-microservice-template/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/target/ -/.settings/ -/.DS_Store http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-microservice-template/.project ---------------------------------------------------------------------- diff --git a/juneau-microservice-template/.project b/juneau-microservice-template/.project deleted file mode 100755 index 1be18b1..0000000 --- a/juneau-microservice-template/.project +++ /dev/null @@ -1,37 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - *************************************************************************************************************************** - * 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. * - *************************************************************************************************************************** ---> -<projectDescription> - <name>juneau-microservice-template</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.m2e.core.maven2Builder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.m2e.core.maven2Nature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-microservice-template/META-INF/MANIFEST.MF ---------------------------------------------------------------------- diff --git a/juneau-microservice-template/META-INF/MANIFEST.MF b/juneau-microservice-template/META-INF/MANIFEST.MF deleted file mode 100755 index 22d1630..0000000 --- a/juneau-microservice-template/META-INF/MANIFEST.MF +++ /dev/null @@ -1,29 +0,0 @@ -Copyright: - *************************************************************************************************************************** - * 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. * - *************************************************************************************************************************** -Manifest-Version: 1.0 -Main-Class: org.apache.juneau.microservice.RestMicroservice -Rest-Resources: - org.apache.juneau.microservice.sample.RootResources -Main-ConfigFile: microservice.cfg -Class-Path: - lib/commons-codec-1.9.jar - lib/commons-io-1.2.jar - lib/commons-logging-1.1.1.jar - lib/httpclient-4.5.jar - lib/httpcore-4.4.1.jar - lib/httpmime-4.5.jar - lib/javax.servlet-api-3.0.jar - lib/jetty-all-8.1.0.jar - lib/juneau-all-5.2.jar - lib/org.apache.commons.fileupload_1.3.1.jar \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-microservice-template/build.xml ---------------------------------------------------------------------- diff --git a/juneau-microservice-template/build.xml b/juneau-microservice-template/build.xml deleted file mode 100644 index 814a0a5..0000000 --- a/juneau-microservice-template/build.xml +++ /dev/null @@ -1,55 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - *************************************************************************************************************************** - * 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. * - *************************************************************************************************************************** ---> -<!-- - Provides a VERY basic ANT script for creating a microservice zip file. ---> -<project name='Microservice' default='Microservice.Build'> - - <target name='Microservice.Build'> - <tstamp/> - <loadproperties srcFile='build.properties'/> - - <path id='classpath'> - <fileset dir='lib' includes='*.jar'/> - </path> - - <delete dir='build' quiet='true'/> - - <copy todir='build/bin'> - <fileset dir='src' excludes='**/*.java'/> - </copy> - <copy todir='build/microservice'> - <fileset dir='.' includes='*.cfg,lib/**'/> - </copy> - - <javac srcdir='src' destdir='build/bin' fork='true' source='1.6' target='1.6' debug='true' includeantruntime='false'> - <classpath refid='classpath'/> - </javac> - - <jar jarfile='build/microservice/${jar}' basedir='build/bin' duplicate='fail' level='9' manifest='META-INF/MANIFEST.MF'> - <manifest> - <attribute name='Built-By' value='${user.name}'/> - <attribute name='Build-Date' value='${TODAY}'/> - <attribute name='Bundle-Version' value='${version}'/> - </manifest> - </jar> - - <zip basedir='build/microservice' destfile='build/${zip}'/> - - <delete dir='build/bin' quiet='true'/> - </target> - -</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-microservice-template/jetty.xml ---------------------------------------------------------------------- diff --git a/juneau-microservice-template/jetty.xml b/juneau-microservice-template/jetty.xml deleted file mode 100644 index e5f7543..0000000 --- a/juneau-microservice-template/jetty.xml +++ /dev/null @@ -1,58 +0,0 @@ -<?xml version="1.0"?> -<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"> -<!-- - *************************************************************************************************************************** - * 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. * - *************************************************************************************************************************** ---> - -<Configure id="ExampleServer" class="org.eclipse.jetty.server.Server"> - - <Set name="connectors"> - <Array type="org.eclipse.jetty.server.Connector"> - <Item> - <New class="org.eclipse.jetty.server.ServerConnector"> - <Arg> - <Ref refid="ExampleServer" /> - </Arg> - <Set name="port">10000</Set> - </New> - </Item> - </Array> - </Set> - - <New id="context" class="org.eclipse.jetty.servlet.ServletContextHandler"> - <Set name="contextPath">/</Set> - <Call name="addServlet"> - <Arg>org.apache.juneau.microservice.sample.RootResources</Arg> - <Arg>/*</Arg> - </Call> - <Set name="sessionHandler"> - <New class="org.eclipse.jetty.server.session.SessionHandler" /> - </Set> - </New> - - <Set name="handler"> - <New class="org.eclipse.jetty.server.handler.HandlerCollection"> - <Set name="handlers"> - <Array type="org.eclipse.jetty.server.Handler"> - <Item> - <Ref refid="context" /> - </Item> - <Item> - <New class="org.eclipse.jetty.server.handler.DefaultHandler" /> - </Item> - </Array> - </Set> - </New> - </Set> -</Configure> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-microservice-template/microservice.cfg ---------------------------------------------------------------------- diff --git a/juneau-microservice-template/microservice.cfg b/juneau-microservice-template/microservice.cfg deleted file mode 100755 index e5fdd9a..0000000 --- a/juneau-microservice-template/microservice.cfg +++ /dev/null @@ -1,118 +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. * -# *************************************************************************************************************************** - -#================================================================================ -# Basic configuration file for SaaS microservices -# Subprojects can use this as a starting point. -#================================================================================ - -#================================================================================ -# Services -#================================================================================ -[Services] -REST = org.apache.juneau.microservice.rest.RestApplication - -#================================================================================ -# REST settings -#================================================================================ -[REST] - -jettyXml = jetty.xml - -# Stylesheet to use for HTML views. -# The default options are: -# - servlet:/styles/juneau.css -# - servlet:/styles/devops.css -# Other stylesheets can be referenced relative to the servlet package or working directory. -stylesheet = servlet:/styles/devops.css - -# What to do when the config file is saved. -# Possible values: -# NOTHING - Don't do anything. (default) -# RESTART_SERVER - Restart the Jetty server. -# RESTART_SERVICE - Shutdown and exit with code '3'. -saveConfigAction = RESTART_SERVER - -#================================================================================ -# Logger settings -# See FileHandler Java class for details. -#================================================================================ -[Logging] - -# The directory where to create the log file. -# Default is "." -logDir = logs - -# The name of the log file to create for the main logger. -# The logDir and logFile make up the pattern that's passed to the FileHandler -# constructor. -# If value is not specified, then logging to a file will not be set up. -logFile = microservice.%g.log - -# Whether to append to the existing log file or create a new one. -# Default is false. -append = - -# The SimpleDateFormat format to use for dates. -# Default is "yyyy.MM.dd hh:mm:ss". -dateFormat = - -# The log message format. -# The value can contain any of the following variables: -# {date} - The date, formatted per dateFormat. -# {class} - The class name. -# {method} - The method name. -# {logger} - The logger name. -# {level} - The log level name. -# {msg} - The log message. -# {threadid} - The thread ID. -# {exception} - The localized exception message. -# Default is "[{date} {level}] {msg}%n". -format = - -# The maximum log file size. -# Suffixes available for numbers. -# See ConfigFile.getInt(String,int) for details. -# Default is 1M. -limit = 10M - -# Max number of log files. -# Default is 1. -count = 5 - -# Default log levels. -# Keys are logger names. -# Values are serialized Level POJOs. -levels = { org.apache.juneau:'INFO' } - -# Only print unique stack traces once and then refer to them by a simple 8 character hash identifier. -# Useful for preventing log files from filling up with duplicate stack traces. -# Default is false. -useStackTraceHashes = true - -# The default level for the console logger. -# Default is WARNING. -consoleLevel = - -#================================================================================ -# System properties -#-------------------------------------------------------------------------------- -# These are arbitrary system properties that are set during startup. -#================================================================================ -[SystemProperties] - -# Configure Jetty for StdErrLog Logging -org.eclipse.jetty.util.log.class = org.eclipse.jetty.util.log.StrErrLog - -# Jetty logging level -org.eclipse.jetty.LEVEL = WARN http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-microservice-template/pom.xml ---------------------------------------------------------------------- diff --git a/juneau-microservice-template/pom.xml b/juneau-microservice-template/pom.xml deleted file mode 100644 index 30fe508..0000000 --- a/juneau-microservice-template/pom.xml +++ /dev/null @@ -1,98 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - *************************************************************************************************************************** - * 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. * - *************************************************************************************************************************** ---> -<!-- - This project is meant to be used as a starting point for developers to use in creating their own REST microservices. - It creates a parent REST interface on port 10000 with a single child hello-world resource. - This POM is likewise meant to be used as a starting point for developers. It creates an uber-jar - to run the microserice from the command line. Copy the jar as well as the .cfg file and start it - with java -jar juneau-microservice-template-1.0.0.jar microservice.cfg - The group/artifact/version information is meant to be overwritten by developers to match their own needs. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>juneau-microservice-template</groupId> - <artifactId>juneau-microservice-template</artifactId> - <version>6.3.2</version> - <name>Apache Juneau Microservice Template</name> - <description>A template project developers use to start with to create a microservice.</description> - <properties> - <juneau.version>6.3.2-incubating-SNAPSHOT</juneau.version> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - <dependencies> - <dependency> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau-microservice</artifactId> - <version>${juneau.version}</version> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.6.1</version> - <configuration> - <source>1.6</source> - <target>1.6</target> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>2.4</version> - <configuration> - <archive> - <manifest> - <mainClass>org.apache.juneau.microservice.RestMicroservice - </mainClass> - </manifest> - <manifestEntries> - <Rest-Resources>org.apache.juneau.microservice.sample.RootResources - </Rest-Resources> - <Main-ConfigFile>microservice.cfg</Main-ConfigFile> - </manifestEntries> - </archive> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>3.0.0</version> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <filters> - <filter> - <artifact>*:*</artifact> - <excludes> - <exclude>META-INF/*.SF</exclude> - <exclude>META-INF/*.RSA</exclude> - <exclude>META-INF/*.INF</exclude> <!-- This one may not be required --> - </excludes> - </filter> - </filters> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-microservice-template/src/main/java/org/apache/juneau/microservice/sample/HelloWorldResource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice-template/src/main/java/org/apache/juneau/microservice/sample/HelloWorldResource.java b/juneau-microservice-template/src/main/java/org/apache/juneau/microservice/sample/HelloWorldResource.java deleted file mode 100755 index 04edc2e..0000000 --- a/juneau-microservice-template/src/main/java/org/apache/juneau/microservice/sample/HelloWorldResource.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. * -// *************************************************************************************************************************** -package org.apache.juneau.microservice.sample; - -import org.apache.juneau.microservice.Resource; -import org.apache.juneau.rest.annotation.RestMethod; -import org.apache.juneau.rest.annotation.RestResource; - -/** - * Sample REST resource that prints out a simple "Hello world!" message. - */ -@RestResource( - title="Hello World example", - path="/helloworld", - description="Simplest possible REST resource" -) -public class HelloWorldResource extends Resource { - private static final long serialVersionUID = 1L; - - /** GET request handler */ - @RestMethod(name="GET", path="/*") - public String sayHello() { - return "Hello world!"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-microservice-template/src/main/java/org/apache/juneau/microservice/sample/RootResources.java ---------------------------------------------------------------------- diff --git a/juneau-microservice-template/src/main/java/org/apache/juneau/microservice/sample/RootResources.java b/juneau-microservice-template/src/main/java/org/apache/juneau/microservice/sample/RootResources.java deleted file mode 100755 index 140baaf..0000000 --- a/juneau-microservice-template/src/main/java/org/apache/juneau/microservice/sample/RootResources.java +++ /dev/null @@ -1,41 +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.microservice.sample; - -import static org.apache.juneau.html.HtmlDocSerializerContext.HTMLDOC_links; - -import org.apache.juneau.microservice.ResourceGroup; -import org.apache.juneau.microservice.resources.ConfigResource; -import org.apache.juneau.microservice.resources.LogsResource; -import org.apache.juneau.rest.annotation.Property; -import org.apache.juneau.rest.annotation.RestResource; - -/** - * Root microservice page. - */ -@RestResource( - path="/", - title="Juneau Microservice Template", - description="Template for creating REST microservices", - properties={ - @Property(name=HTMLDOC_links, value="{options:'?method=OPTIONS'}") - }, - children={ - HelloWorldResource.class, - ConfigResource.class, - LogsResource.class - } -) -public class RootResources extends ResourceGroup { - private static final long serialVersionUID = 1L; -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-microservice-template/src/main/java/org/apache/juneau/microservice/sample/nls/Messages.properties ---------------------------------------------------------------------- diff --git a/juneau-microservice-template/src/main/java/org/apache/juneau/microservice/sample/nls/Messages.properties b/juneau-microservice-template/src/main/java/org/apache/juneau/microservice/sample/nls/Messages.properties deleted file mode 100755 index d4a7d06..0000000 --- a/juneau-microservice-template/src/main/java/org/apache/juneau/microservice/sample/nls/Messages.properties +++ /dev/null @@ -1,19 +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. -# * -# *************************************************************************************************************************** - -#-------------------------------------------------------------------------------- -# RootResources -#-------------------------------------------------------------------------------- -RootResources.title = Juneau Microservice Template -RootResources.description = Template for creating REST microservices http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-microservice-template/src/test/java/.gitignore ---------------------------------------------------------------------- diff --git a/juneau-microservice-template/src/test/java/.gitignore b/juneau-microservice-template/src/test/java/.gitignore deleted file mode 100644 index 8a0051a..0000000 --- a/juneau-microservice-template/src/test/java/.gitignore +++ /dev/null @@ -1,12 +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. * - ***************************************************************************************************************************