forked from OpenNTF/org.openntf.domino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Callback interfaces and helper methods for doing boilerplating for ex…
…tracting HttpRequest and HttpResponse, processing, and properly terminating the response from an XAgent. One is specifically designed to allow population of a JSON object which will get passed back to the REST request /* * One method call to XspUtils.initialiseAndProcessResponse() does all the boilerplating for extracting the request, response and JsonJavaObject * and properly terminating the response. JsonJavaObject is basically the same as a Java Map. All gotchas are handled for you! * * The bit that could be new to most is that XspUtils.initialiseAndProcessResponseAsJson() takes an anonymous inner class as its method. This is just * a way to pass in a process() method that can interact with the request and response set up by XspUtils.initialiseAndProcessResponseAsJson() * * With Java 8 it becomes more readable with lambdas: * * XspUtils.initialiseAndProcessResponseAsJson((request, response, jsonObj) -> { * // do stuff here * }); */
- Loading branch information
Paul Withers
committed
Jan 4, 2018
1 parent
b2b6660
commit 32ef344
Showing
3 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
domino/xsp/src/main/java/org/openntf/domino/xsp/IXspHttpServletJsonResponseCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.openntf.domino.xsp; | ||
|
||
/* | ||
Copyright 2018 Paul Withers Licensed 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 | ||
*/ | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import com.ibm.commons.util.io.json.JsonJavaObject; | ||
import com.ibm.xsp.webapp.XspHttpServletResponse; | ||
|
||
/** | ||
* This interface allows the developer to pass custom code to be run to process the HttpServletRequest and populate the | ||
* XspHttpServletResponse | ||
* | ||
* @author Paul Withers | ||
* @since ODA 4.3.0 | ||
* | ||
*/ | ||
public interface IXspHttpServletJsonResponseCallback { | ||
|
||
/** | ||
* {@linkplain Utils#initialiseAndProcessResponse(IXspHttpServletJsonResponseCallback)} will extract the HttpServletRequest and | ||
* XspHttpServletResponse, call this process() method, then terminate the response. | ||
* | ||
* By using the callback approach custom code can be generated without needing to remember to code the boilerplate Java code that should | ||
* sit around it. | ||
* | ||
* @param request | ||
* HttpServletRequest | ||
* @param response | ||
* XspHttpServletResponse that will be posted back to the browser, from which the getDelegate() method gives access to the | ||
* HttpServletResponse, if needed | ||
* @param jsonObj | ||
* to store JSON | ||
*/ | ||
public void process(HttpServletRequest request, XspHttpServletResponse response, JsonJavaObject jsonObj) throws IOException; | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
domino/xsp/src/main/java/org/openntf/domino/xsp/IXspHttpServletResponseCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.openntf.domino.xsp; | ||
|
||
/* | ||
Copyright 2018 Paul Withers Licensed 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 | ||
*/ | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import com.ibm.xsp.webapp.XspHttpServletResponse; | ||
|
||
/** | ||
* This interface allows the developer to pass custom code to be run to process the HttpServletRequest and populate the | ||
* XspHttpServletResponse | ||
* | ||
* @author Paul Withers | ||
* @since ODA 4.3.0 | ||
* | ||
*/ | ||
public interface IXspHttpServletResponseCallback { | ||
|
||
/** | ||
* {@linkplain Utils#initialiseAndProcessResponse(IXspHttpServletResponseCallback)} will extract the HttpServletRequest and | ||
* XspHttpServletResponse, call this process() method, then terminate the response. | ||
* | ||
* By using the callback approach custom code can be generated without needing to remember to code the boilerplate Java code that should | ||
* sit around it. | ||
* | ||
* @param request | ||
* HttpServletRequest | ||
* @param response | ||
* XspHttpServletResponse that will be posted back to the browser, from which the getDelegate() method gives access to the | ||
* HttpServletResponse, if needed | ||
*/ | ||
public void process(HttpServletRequest request, XspHttpServletResponse response) throws IOException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters