Skip to content

Instantly share code, notes, and snippets.

View sivaprasadreddy's full-sized avatar
:octocat:
Learning and practicing...

K. Siva Prasad Reddy sivaprasadreddy

:octocat:
Learning and practicing...
View GitHub Profile
@sivaprasadreddy
sivaprasadreddy / CleanMoneyTransferService
Last active January 1, 2016 15:59
CleanMoneyTransferService
class FundTransferTxn
{
private Account sourceAccount;
private Account targetAccount;
private BigDecimal amount;
private boolean allowDuplicateTxn;
//setters & getters
}
public class CleanMoneyTransferService
@sivaprasadreddy
sivaprasadreddy / UglyMoneyTransferService
Last active January 1, 2016 15:59
UglyMoneyTransferService
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;
@sivaprasadreddy
sivaprasadreddy / RESTEasyDemo-Custom-ExceptionHandlers.java
Created June 12, 2012 09:59
RESTEasy Demo Custom ExceptionHandlers
/**
* 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;
@sivaprasadreddy
sivaprasadreddy / AES.java
Created November 26, 2012 11:48 — forked from ymnk/AES.java
JSch examples
/* -*-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{
@sivaprasadreddy
sivaprasadreddy / RESTEasyDemo-Custom-ExceptionHandlers-output.xml
Created June 12, 2012 10:03
RESTEasyDemo Custom ExceptionHandlers output
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 :
@sivaprasadreddy
sivaprasadreddy / RESTEasyDemo-Custom-Exceptions.java
Created June 12, 2012 09:58
RESTEasy Demo Custom Exceptions
/**
* ResourceNotFoundException.java
*/
package com.sivalabs.resteasydemo;
public class ResourceNotFoundException extends RuntimeException
{
private static final long serialVersionUID = 1L;
public ResourceNotFoundException(String msg)
@sivaprasadreddy
sivaprasadreddy / RESTEasyDemo-Throwing-Custom-Exceptions.java
Created June 12, 2012 10:00
RESTEasy Demo Throwing Custom Exceptions
@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 ){
@sivaprasadreddy
sivaprasadreddy / RESTEasy+Spring-pom.xml
Created June 12, 2012 07:31
RESTEasy+Spring Maven Configuration
<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>
@sivaprasadreddy
sivaprasadreddy / RESTEasy+Spring-Sample-Code.java
Created June 12, 2012 06:39
RESTEasy + Spring Sample Code
package com.sivalabs.resteasydemo;
import java.util.List;
import org.springframework.stereotype.Service;
import com.sivalabs.resteasydemo.MockUserTable;
@Service
public class UserService
{
@sivaprasadreddy
sivaprasadreddy / XMLUtils.java
Created June 7, 2012 03:37
XMLUtils to print XML Document Object as String
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;