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
class FundTransferTxn | |
{ | |
private Account sourceAccount; | |
private Account targetAccount; | |
private BigDecimal amount; | |
private boolean allowDuplicateTxn; | |
//setters & getters | |
} | |
public class CleanMoneyTransferService |
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
public class UglyMoneyTransferService | |
{ | |
public void transferFunds(Account source, Account target, BigDecimal amount, boolean allowDuplicateTxn) throws IllegalArgumentException, RuntimeException { | |
Connection conn = null; | |
try { | |
conn = DBUtils.getConnection(); | |
PreparedStatement pstmt = conn.prepareStatement("Select * from accounts where acno = ?"); | |
pstmt.setString(1, source.getAcno()); | |
ResultSet rs = pstmt.executeQuery(); | |
Account sourceAccount = null; |
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
/** | |
* ResourceNotFoundExceptionHandler.java | |
*/ | |
package com.sivalabs.resteasydemo; | |
import javax.ws.rs.core.Response; | |
import javax.ws.rs.ext.ExceptionMapper; | |
import javax.ws.rs.ext.Provider; | |
import org.springframework.stereotype.Component; |
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
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | |
/** | |
* This program will demonstrate how to use "aes128-cbc". | |
* | |
*/ | |
import com.jcraft.jsch.*; | |
import java.awt.*; | |
import javax.swing.*; | |
public class AES{ |
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
case 1 : GET http://localhost:8080/resteasy-demo/rest/users/0 | |
Response : | |
<response> | |
<status>failed</status> | |
<message>User Id[0] should not be less than 1.</message> | |
<internalError>null</internalError> | |
</response> | |
case 2: GET http://localhost:8080/resteasy-demo/rest/users/100 | |
Response : |
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
/** | |
* ResourceNotFoundException.java | |
*/ | |
package com.sivalabs.resteasydemo; | |
public class ResourceNotFoundException extends RuntimeException | |
{ | |
private static final long serialVersionUID = 1L; | |
public ResourceNotFoundException(String msg) |
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
@Path("/{id}") | |
@GET | |
public Response getUserXMLById(@PathParam("id") Integer id) | |
{ | |
if(id==null || id < 1 ){ | |
throw new ApplicationException("User Id["+id+"] should not be less than 1."); | |
} | |
User user = userService.getById(id); | |
if(user==null ){ |
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
<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/POM/4.0.0 | |
http://maven.apache.org/maven-v4_0_0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.sivalabs</groupId> | |
<artifactId>resteasy-demo</artifactId> | |
<version>0.1</version> | |
<packaging>war</packaging> |
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
package com.sivalabs.resteasydemo; | |
import java.util.List; | |
import org.springframework.stereotype.Service; | |
import com.sivalabs.resteasydemo.MockUserTable; | |
@Service | |
public class UserService | |
{ |
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
import java.io.StringReader; | |
import java.io.StringWriter; | |
import javax.xml.parsers.DocumentBuilder; | |
import javax.xml.parsers.DocumentBuilderFactory; | |
import javax.xml.transform.OutputKeys; | |
import javax.xml.transform.Transformer; | |
import javax.xml.transform.TransformerFactory; | |
import javax.xml.transform.dom.DOMSource; | |
import javax.xml.transform.stream.StreamResult; |