diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..f97ee26 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,20 @@ +name: build + +on: + push: + branches: [master] + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '17' + cache: maven + - name: Build and test + run: mvn -B verify diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9bcf999..0000000 --- a/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: java -jdk: - - oraclejdk8 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f4c39e9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2015 Ashwanth Fernando + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 9696265..1d34436 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/crazysoftwarecoder/bigpipe.svg?branch=master)](https://travis-ci.org/crazysoftwarecoder/bigpipe) +[![build](https://github.com/crazysoftwarecoder/bigpipe/actions/workflows/build.yml/badge.svg)](https://github.com/crazysoftwarecoder/bigpipe/actions/workflows/build.yml) ## A BigPipe implementation for Java @@ -73,7 +73,7 @@ public ClassA { } ``` -###Step 2 +### Step 2 Define the return ViewObject for each @PageletTaskMethod @@ -90,12 +90,12 @@ class LeftNavBarDataVO implements ViewObject { // ViewObject is just a marker in } public void setCategoryName(String categoryName) { - + this.categoryName = categoryName; } } ``` -###Step 3 +### Step 3 In your JSP @@ -123,7 +123,7 @@ In your JSP ``` -###Step 4 +### Step 4 Then finally in your web.xml ```xml @@ -146,11 +146,11 @@ Then finally in your web.xml ``` -###Step 5 +### Step 5 You are all set! Go to **http://localhost:8080/app-context/url-that-you-want-serve/** and see the results. ## Example For an example, look [here](https://github.com/crazysoftwarecoder/bigpipe/tree/master/bigpipe-java-web-example) -###License -[MIT](https://github.com/strongloop/express/blob/master/LICENSE) +## License +[MIT](LICENSE) diff --git a/bigpipe-java-web/src/main/java/com/myseriousorganization/bigpipe/core/executor/PageletTaskExecutor.java b/bigpipe-java-web/src/main/java/com/myseriousorganization/bigpipe/core/executor/PageletTaskExecutor.java index 63b96b6..eb55271 100644 --- a/bigpipe-java-web/src/main/java/com/myseriousorganization/bigpipe/core/executor/PageletTaskExecutor.java +++ b/bigpipe-java-web/src/main/java/com/myseriousorganization/bigpipe/core/executor/PageletTaskExecutor.java @@ -46,7 +46,7 @@ public void execute(final Object pageletTask, final HttpServletRequest servletRe Preconditions.checkArgument(pageletTask!=null); // Validate if this is a pagelet task. - if (isPageletTask(pageletTask)) { + if (isNotPageletTask(pageletTask)) { throw new TaskExecutionException("passed in object is not a PageletTask. " + "Please annotate your pagelet task class with @" + PageletTask.class.getCanonicalName()); } @@ -75,7 +75,7 @@ public void run() { }); } - private boolean isPageletTask(Object obj) { + private boolean isNotPageletTask(Object obj) { return (obj.getClass().getAnnotation(PageletTask.class)==null); } diff --git a/bigpipe-java-web/src/main/java/com/myseriousorganization/bigpipe/core/tag/BigPipeStartTag.java b/bigpipe-java-web/src/main/java/com/myseriousorganization/bigpipe/core/tag/BigPipeStartTag.java index d94f5d1..2cf8a15 100644 --- a/bigpipe-java-web/src/main/java/com/myseriousorganization/bigpipe/core/tag/BigPipeStartTag.java +++ b/bigpipe-java-web/src/main/java/com/myseriousorganization/bigpipe/core/tag/BigPipeStartTag.java @@ -42,8 +42,4 @@ public void doTag() throws JspException, IOException { out.println(SETTER_JS_FUNCTION); } - public static void main(String[] args) { - new BigPipeStartTag(); - } - } diff --git a/bigpipe-java-web/src/main/java/com/myseriousorganization/bigpipe/core/tag/PageletBodyTag.java b/bigpipe-java-web/src/main/java/com/myseriousorganization/bigpipe/core/tag/PageletBodyTag.java index 01b6714..11a5977 100644 --- a/bigpipe-java-web/src/main/java/com/myseriousorganization/bigpipe/core/tag/PageletBodyTag.java +++ b/bigpipe-java-web/src/main/java/com/myseriousorganization/bigpipe/core/tag/PageletBodyTag.java @@ -2,11 +2,11 @@ import java.io.IOException; import java.io.StringWriter; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; +import java.util.Base64; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.SimpleTagSupport; -import javax.xml.bind.DatatypeConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,16 +49,8 @@ private void emitDivPlaceholder(String pageletName) throws IOException { } protected String getBase64String(String input) { - try { - byte[] inputBytes = input.getBytes("UTF-8"); - String encodedString = DatatypeConverter.printBase64Binary(inputBytes); - return encodedString; - } - catch (UnsupportedEncodingException e) { - String message = "Could not transform String to UTF-8 bytes"; - logger.error(e.getMessage()); - throw new IllegalArgumentException(message); - } + byte[] inputBytes = input.getBytes(StandardCharsets.UTF_8); + return Base64.getEncoder().encodeToString(inputBytes); } @Override diff --git a/bigpipe-java-web/src/test/java/com/myseriousorganization/bigpipe/core/executor/PageletTaskExecutorTest.java b/bigpipe-java-web/src/test/java/com/myseriousorganization/bigpipe/core/executor/PageletTaskExecutorTest.java new file mode 100644 index 0000000..54302e5 --- /dev/null +++ b/bigpipe-java-web/src/test/java/com/myseriousorganization/bigpipe/core/executor/PageletTaskExecutorTest.java @@ -0,0 +1,26 @@ +package com.myseriousorganization.bigpipe.core.executor; + +import org.junit.Test; + +import com.myseriousorganization.bigpipe.core.annotations.PageletTask; +import com.myseriousorganization.bigpipe.core.exception.TaskExecutionException; + +public class PageletTaskExecutorTest { + + @PageletTask(name = "annotated") + static class AnnotatedTask { + } + + static class PlainObject { + } + + @Test(expected = TaskExecutionException.class) + public void rejectsObjectWithoutPageletTaskAnnotation() throws Exception { + new PageletTaskExecutor(1).execute(new PlainObject(), null); + } + + @Test(expected = IllegalArgumentException.class) + public void rejectsNullTask() throws Exception { + new PageletTaskExecutor(1).execute(null, null); + } +} diff --git a/bigpipe-java-web/src/test/java/com/myseriousorganization/bigpipe/core/executor/PageletTaskOutputHolderTest.java b/bigpipe-java-web/src/test/java/com/myseriousorganization/bigpipe/core/executor/PageletTaskOutputHolderTest.java new file mode 100644 index 0000000..3008973 --- /dev/null +++ b/bigpipe-java-web/src/test/java/com/myseriousorganization/bigpipe/core/executor/PageletTaskOutputHolderTest.java @@ -0,0 +1,59 @@ +package com.myseriousorganization.bigpipe.core.executor; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; + +import com.myseriousorganization.bigpipe.core.marker.ViewObject; + +public class PageletTaskOutputHolderTest { + + private PageletTaskOutputHolder holder; + + @Before + public void setUp() { + holder = new PageletTaskOutputHolder(); + } + + @Test + public void roundTripsTheViewObject() { + ViewObject vo = new ViewObject() {}; + holder.addPageletTask("left"); + holder.putViewObject("left", vo); + + assertSame(vo, holder.getViewObject("left")); + } + + @Test + public void tracksWhichPageletsExist() { + assertFalse(holder.doesPageletExist("left")); + holder.addPageletTask("left"); + assertTrue(holder.doesPageletExist("left")); + } + + @Test(expected = IllegalArgumentException.class) + public void rejectsDuplicatePageletRegistration() { + holder.addPageletTask("left"); + holder.addPageletTask("left"); + } + + @Test(expected = IllegalArgumentException.class) + public void rejectsSecondViewObjectForSamePagelet() { + holder.addPageletTask("left"); + holder.putViewObject("left", new ViewObject() {}); + holder.putViewObject("left", new ViewObject() {}); + } + + @Test(expected = IllegalArgumentException.class) + public void putForUnknownPageletFails() { + holder.putViewObject("missing", new ViewObject() {}); + } + + @Test(expected = IllegalArgumentException.class) + public void getForUnknownPageletFails() { + holder.getViewObject("missing"); + } +} diff --git a/pom.xml b/pom.xml index 844cb06..40e4d24 100644 --- a/pom.xml +++ b/pom.xml @@ -11,20 +11,27 @@ The java implementation of big-pipe. - bigpipe-java-web - bigpipe-java-web-example + bigpipe-java-web + bigpipe-java-web-example + + 11 + UTF-8 + + org.apache.maven.plugins maven-compiler-plugin - - 1.7 - 1.7 - + 3.13.0 + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 @@ -34,7 +41,7 @@ junit junit - 3.8.1 + 4.13.2 test