-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature - Added support for HTTP DELETE method (#12)
- Loading branch information
1 parent
42b90f6
commit 095cd66
Showing
24 changed files
with
592 additions
and
226 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -51,3 +51,6 @@ nbdist/ | |
.DS_Store | ||
**.swap | ||
~ | ||
|
||
# Eclipse # | ||
/bin/ |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,44 @@ | ||
package parrot.rest.common; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.web.servlet.HandlerMapping; | ||
|
||
/** | ||
* | ||
* @author Isuru Weerasooriya | ||
* | ||
*/ | ||
public class PhraseUtility { | ||
|
||
private PhraseUtility() { | ||
} | ||
|
||
public static String getFullUrl(HttpServletRequest request, Pattern urlPattern) { | ||
StringBuilder builder = new StringBuilder(); | ||
String fullUrl = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); | ||
String url = getAppContextUrl(fullUrl, urlPattern); | ||
if (url == null) { | ||
return null; | ||
} | ||
builder.append(url); | ||
if (StringUtils.isNotEmpty(request.getQueryString())) { | ||
builder.append("?"); | ||
builder.append(request.getQueryString()); | ||
} | ||
return builder.toString(); | ||
} | ||
|
||
public static String getAppContextUrl(String fullUrl, Pattern urlPattern) { | ||
Matcher matcher = urlPattern.matcher(fullUrl); | ||
if (matcher.matches() && matcher.groupCount() > 0) { | ||
return matcher.group(1); | ||
} | ||
return null; | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/parrot/rest/controller/ForgetController.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 parrot.rest.controller; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
|
||
import parrot.rest.common.PhraseUtility; | ||
import parrot.rest.exception.UrlNotFoundException; | ||
import parrot.rest.service.PhraseService; | ||
|
||
/** | ||
* | ||
* @author Isuru Weerasooriya | ||
* | ||
*/ | ||
@Controller(ForgetController.PATH) | ||
public class ForgetController { | ||
|
||
public static final String PATH = "forget"; | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ForgetController.class); | ||
private static final Pattern URL_PATTERN = Pattern.compile("\\/{0,1}forget\\/(.*)"); | ||
|
||
@Autowired | ||
private PhraseService phraseService; | ||
|
||
@DeleteMapping("forget/**") | ||
public ResponseEntity<String> forget(HttpServletRequest request) { | ||
ResponseEntity<String> result = null; | ||
String url = PhraseUtility.getFullUrl(request, URL_PATTERN); | ||
|
||
logger.debug("Forgetting URL: {}", url); | ||
try { | ||
phraseService.remove(url); | ||
result = new ResponseEntity<>("OK", HttpStatus.OK); | ||
} catch (UrlNotFoundException e) { | ||
result = new ResponseEntity<>("NO_CONTENT", HttpStatus.NO_CONTENT); | ||
} | ||
return result; | ||
} | ||
|
||
} |
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
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 |
---|---|---|
@@ -1,6 +1,3 @@ | ||
/** | ||
* | ||
*/ | ||
package parrot.rest.controller; | ||
|
||
import org.slf4j.Logger; | ||
|
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
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
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
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
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
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
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
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
Oops, something went wrong.