Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

aquent/dotcms.plugins.posttool

Repository files navigation

Post Viewtool

A plugin for dotCMS that adds a viewtool that allows the front-end developer to make simple post requests like curl.

The plugin now supports The following HTTP Method Types:

  • POST
  • PUT
  • GET
  • HEAD
  • DELETE

You can also pass a content-type to the methods to control what content type is used for the request. Added some new methods that allow you to POST or PUT xml or json data Now supports https requests (you might need to add javax.net to your exported packages for this to work)

Installation

  • Navigate to the dotCMS Dynamic plugins page: "System" > "Dynamic Plugins"
  • Click on "Upload plugin" and select the .jar file located in the "build/jar/" folder

Compatibility

DotCMS 5.0.3+

See previous releases for older versions.

Extra Exported Packages

The following need added to the Exported Packages list if they are not already ...

org.apache.logging.log4j,
org.apache.logging.log4j.core,
org.apache.logging.log4j.spi

Usage

#set($url       = "http://${request.getServerName()}/test/viewtools/posttool2.htm")
#set($params    = "postdata=hello 褩䤩矩い覦")
#set($paramsMap = $contents.getEmptyMap())
#set($_dummy    = $paramsMap.put("postdata","hello 褩䤩矩い覦"))

<h3>Test GET:</h3>
#set($resp      = $post.sendGet("${url}?${params}"))
<p>Status:  $resp.getResponseCode() <br />
You got: <textarea>$resp.getResponse()</textarea> </p>

<h3>Test POST:</h3>
#set($resp2     = $post.send($url, $params, "POST"))
<p>Status:  $resp2.getResponseCode() <br />
You got: <textarea>$resp2.getResponse()</textarea> </p>

<h3>Test PUT with a Map and Content Type:</h3>
#set($resp3     = $post.sendPut($url, $paramsMap, "application/octet-stream"))
<p>Status:  $resp3.getResponseCode() <br />
You got: <textarea>$resp3.getResponse()</textarea> </p>

<h3>Test POST with JSON Data:</h3>
#set($jsonData  = '{"title":"foo","body":"bar","userId":1}')
#set($resp4     = $post.postStringData("http://jsonplaceholder.typicode.com/posts", $jsonData, "application/json"))
<p>Status:  $resp4.getResponseCode() <br />
You got: <textarea>$resp4.getResponse()</textarea> </p>

<h3>Test GET with Basic Auth:</h3>
#set($authUrl   = "http://something.com/api/something")
#set($creds     = $post.createCreds("username", 'password'))
#set($resp5     = $post.send($authUrl))
#set($resp6     = $post.send($authUrl, $creds))
<p>Without Creds - Status:  $resp5.getResponseCode() <br />
Without Creds - You got: <textarea>$resp5.getResponse()</textarea> </p>
<p>With Creds - Status:  $resp6.getResponseCode() <br />
With Creds - You got: <textarea>$resp6.getResponse()</textarea> </p>

Building

  • Run: ./gradlew jar