diff --git a/BcnxWebService/src/com/bcnx/web/app/exception/ApplicationExceptionHandler.java b/BcnxWebService/src/com/bcnx/web/app/exception/ApplicationExceptionHandler.java index 5c1a558..52f91e9 100644 --- a/BcnxWebService/src/com/bcnx/web/app/exception/ApplicationExceptionHandler.java +++ b/BcnxWebService/src/com/bcnx/web/app/exception/ApplicationExceptionHandler.java @@ -1,21 +1,27 @@ package com.bcnx.web.app.exception; +import javax.ws.rs.Produces; import javax.ws.rs.core.Response; import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.Provider; -import org.jboss.resteasy.spi.ApplicationException; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; import com.bcnx.web.app.service.entity.ErrMsg; @Provider -public class ApplicationExceptionHandler implements - ExceptionMapper { +@Component +public class ApplicationExceptionHandler implements ExceptionMapper { + private static final Logger logger = Logger.getLogger(ApplicationExceptionHandler.class); + @Produces("application/json") @Override - public Response toResponse(ApplicationException ex) { + public Response toResponse(Exception ex) { + logger.debug("Exception occured while process request",ex); + logger.debug("Exception message :"+ex.getMessage()); ErrMsg errMsg = new ErrMsg(); errMsg.setCode("510"); errMsg.setMessage("Internal Message Error"); - return Response.status(500).entity(errMsg).build(); + return Response.serverError().entity(errMsg).build(); } } diff --git a/BcnxWebService/src/com/bcnx/web/app/exception/SessionTimeOutHandler.java b/BcnxWebService/src/com/bcnx/web/app/exception/SessionTimeOutHandler.java new file mode 100644 index 0000000..af1863b --- /dev/null +++ b/BcnxWebService/src/com/bcnx/web/app/exception/SessionTimeOutHandler.java @@ -0,0 +1,35 @@ +package com.bcnx.web.app.exception; + +import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpSessionEvent; +import javax.servlet.http.HttpSessionListener; + +import org.apache.log4j.Logger; + +import com.bcnx.web.app.service.UserService; +import com.bcnx.web.app.service.entity.User; + +public class SessionTimeOutHandler implements HttpSessionListener { + private static Logger logger = Logger.getLogger(SessionTimeOutHandler.class); + private UserService userService; + public void setUserService(UserService userService){ + this.userService = userService; + } + @Override + public void sessionCreated(HttpSessionEvent event) { + logger.debug("session is created"); + return; + } + + @Override + public void sessionDestroyed(HttpSessionEvent event) { + logger.debug("session is destroyed"); + HttpSession session = event.getSession(); + User user = (User) session.getAttribute("user"); + user = userService.getUser(user); + user.setState(0); + userService.update(user); + return; + } + +} diff --git a/BcnxWebService/src/com/bcnx/web/app/service/UserServiceImp.java b/BcnxWebService/src/com/bcnx/web/app/service/UserServiceImp.java index 54bbe42..9f6df86 100644 --- a/BcnxWebService/src/com/bcnx/web/app/service/UserServiceImp.java +++ b/BcnxWebService/src/com/bcnx/web/app/service/UserServiceImp.java @@ -12,6 +12,7 @@ public class UserServiceImp implements UserService { private static final Logger logger = Logger.getLogger(UserServiceImp.class); + private static final String REGEX = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\\S+$).{8,}$"; private UserDao userDao; public void setUserDao(UserDao userDao){ this.userDao = userDao; @@ -40,11 +41,10 @@ public void updatePasswd(User user) { logger.debug("Exception occured while try to updat user",e); } } - private static final String REGEX = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\\S+$).{8,}$"; private Pattern pattern = Pattern.compile(REGEX); private Matcher matcher; @Override - public boolean checkComplex(String passwd) { + public boolean checkComplex(final String passwd) { matcher = pattern.matcher(passwd); return matcher.find(); } diff --git a/BcnxWebService/src/com/bcnx/web/app/service/admin/MemberController.java b/BcnxWebService/src/com/bcnx/web/app/service/admin/MemberController.java index f4f5d35..a4b7eed 100644 --- a/BcnxWebService/src/com/bcnx/web/app/service/admin/MemberController.java +++ b/BcnxWebService/src/com/bcnx/web/app/service/admin/MemberController.java @@ -22,7 +22,7 @@ public class MemberController { @Path("/save") @Produces("application/json") @Consumes("application/json") - public Response save(Member member){ + public Response save(Member member) throws Exception{ MemberService service = (MemberService) BcnxApplicationContext.getBean("memberService"); service.save(member); return Response.status(200).entity(member).build(); @@ -30,9 +30,11 @@ public Response save(Member member){ @RolesAllowed("ADM") @GET @Path("/get/{first}/{max}") - public Response getMembes(@PathParam("first") String first, @PathParam("max") String max){ - MemberService service = (MemberService) BcnxApplicationContext.getBean("memberService"); - List members = service.getMembers(Integer.parseInt(first), Integer.parseInt(max)); + public Response getMembes(@PathParam("first") int first, + @PathParam("max") int max) throws Exception { + MemberService service = (MemberService) BcnxApplicationContext + .getBean("memberService"); + List members = service.getMembers(first, max); return Response.status(200).entity(members).build(); } } diff --git a/BcnxWebService/src/com/bcnx/web/app/service/admin/RoleController.java b/BcnxWebService/src/com/bcnx/web/app/service/admin/RoleController.java index 9cb5455..93f6f34 100644 --- a/BcnxWebService/src/com/bcnx/web/app/service/admin/RoleController.java +++ b/BcnxWebService/src/com/bcnx/web/app/service/admin/RoleController.java @@ -2,13 +2,11 @@ import java.util.List; -import javax.annotation.security.RolesAllowed; -import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; -import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; import com.bcnx.web.app.context.BcnxApplicationContext; @@ -17,22 +15,26 @@ @Path("/role") public class RoleController { - @RolesAllowed("ADM") @POST @Path("/save") @Produces("application/json") - @Consumes("application/json") - public Response save(Role role){ - RoleService service = (RoleService) BcnxApplicationContext.getBean("roleService"); + public Response save(@QueryParam("roleId") String roleId, + @QueryParam("roleName") String roleName) throws Exception { + RoleService service = (RoleService) BcnxApplicationContext + .getBean("roleService"); + Role role = new Role(); + role.setRoleId(roleId); + role.setRoleName(roleName); service.save(role); return Response.status(200).entity(role).build(); } - @RolesAllowed("ADM") @GET - @Path("/get/{first}/{max}") - public Response getRoles(@PathParam("first")String first, @PathParam("max")String max){ - RoleService service = (RoleService) BcnxApplicationContext.getBean("roleService"); - List roles = service.getRoles(Integer.parseInt(first), Integer.parseInt(max)); + @Path("/get") + public Response getRoles(@QueryParam("first") int first, + @QueryParam("max") int max) throws Exception { + RoleService service = (RoleService) BcnxApplicationContext + .getBean("roleService"); + List roles = service.getRoles(first, max); return Response.status(200).entity(roles).build(); } } diff --git a/BcnxWebService/src/com/bcnx/web/app/service/admin/UserController.java b/BcnxWebService/src/com/bcnx/web/app/service/admin/UserController.java index fb8515b..301f2a5 100644 --- a/BcnxWebService/src/com/bcnx/web/app/service/admin/UserController.java +++ b/BcnxWebService/src/com/bcnx/web/app/service/admin/UserController.java @@ -2,6 +2,8 @@ import java.util.List; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; import javax.ws.rs.FormParam; import javax.ws.rs.GET; import javax.ws.rs.POST; @@ -10,6 +12,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import com.bcnx.web.app.context.BcnxApplicationContext; @@ -29,7 +32,8 @@ public class UserController { @Path("/save") public Response save(@FormParam("userId") String userId, @FormParam("name") String name, @FormParam("email") String email, - @FormParam("memId") String memId, @FormParam("roleId") String roleId) { + @FormParam("memId") String memId, @FormParam("roleId") String roleId) + throws Exception { UserService userService = (UserService) BcnxApplicationContext .getBean("userService"); MemberService memberService = (MemberService) BcnxApplicationContext @@ -50,7 +54,7 @@ public Response save(@FormParam("userId") String userId, role.setRoleId(roleId); role = roleService.getRole(role); String passwd = PasswdGenerator.generate(); - sendMailService.sendMail(user.getEmail(),passwd); + sendMailService.sendMail(user.getEmail(), passwd); user.setPasswd(Encryptography.encrypt(passwd)); user.setMember(member); user.setRole(role); @@ -60,8 +64,10 @@ public Response save(@FormParam("userId") String userId, @GET @Path("/get") @Produces("application/json") - public Response getUser(@QueryParam("userId") String userId){ - UserService service = (UserService) BcnxApplicationContext.getBean("userService"); + public Response getUser(@QueryParam("userId") String userId) + throws Exception { + UserService service = (UserService) BcnxApplicationContext + .getBean("userService"); User user = new User(); user.setUserId(userId); user = service.getUser(user); @@ -71,7 +77,7 @@ public Response getUser(@QueryParam("userId") String userId){ @Path("/get/{first}/{max}") @Produces("application/json") public Response getUsers(@PathParam("first") int first, - @PathParam("max") int max) { + @PathParam("max") int max) throws Exception { UserService service = (UserService) BcnxApplicationContext .getBean("userService"); List users = service.getUsers(first,max); @@ -81,12 +87,14 @@ public Response getUsers(@PathParam("first") int first, @Path("/get/{userId}/{first}/{max}") @Produces("application/json") public Response getUsers(@PathParam("userId") String userId, - @PathParam("first") String first, @PathParam("max") String max) { + @PathParam("first") String first, @PathParam("max") String max) + throws Exception { UserService service = (UserService) BcnxApplicationContext .getBean("userService"); User user = new User(); user.setUserId(userId); - List users = service.getUsers(user, Integer.parseInt(first), Integer.parseInt(max)); + List users = service.getUsers(user, Integer.parseInt(first), + Integer.parseInt(max)); return Response.status(200).entity(users).build(); } @PUT @@ -95,16 +103,19 @@ public Response getUsers(@PathParam("userId") String userId, public Response updatePasswd(@FormParam("userId") String userId, @FormParam("passwd") String passwd, @FormParam("nPasswd") String nPasswd, - @FormParam("cPasswd") String cPasswd) { - UserService userService = (UserService) BcnxApplicationContext.getBean("userService"); + @FormParam("cPasswd") String cPasswd) throws Exception { + UserService userService = (UserService) BcnxApplicationContext + .getBean("userService"); User user = new User(); user.setUserId(userId); user = userService.getUser(user); - int count = user.getCount()+1; + int count = user.getCount() + 1; user.setCount(count); boolean check = Encryptography.checkPasswd(passwd, user.getPasswd()); - if(!check){ - return Response.status(401).entity(new ErrMsg("407","invalid current password")).build(); + if (!check) { + return Response.status(401) + .entity(new ErrMsg("407", "invalid current password")) + .build(); } check = userService.checkComplex(nPasswd); if (!check) @@ -130,8 +141,10 @@ public Response updatePasswd(@FormParam("userId") String userId, @POST @Path("/login") @Produces("application/json") - public Response logon(@FormParam("userId") String userId, @FormParam("passwd") String passwd){ - UserService service = (UserService) BcnxApplicationContext.getBean("userService"); + public Response logon(@FormParam("userId") String userId, + @FormParam("passwd") String passwd, @Context HttpServletRequest request) throws Exception { + UserService service = (UserService) BcnxApplicationContext + .getBean("userService"); User user = new User(); user.setUserId(userId); user = service.getUser(user); @@ -139,42 +152,52 @@ public Response logon(@FormParam("userId") String userId, @FormParam("passwd") S String status = user.getStatus(); int state = user.getState(); int count = user.getCount(); - - if(!check){ - return Response.status(401).entity(new ErrMsg("400","invalid userId/password")).build(); + + if (!check) { + return Response.status(401) + .entity(new ErrMsg("400", "invalid userId/password")) + .build(); } - if(!status.equals("A")) - { - return Response.status(401).entity(new ErrMsg("401","inactive user")).build(); + if (!status.equals("A")) { + return Response.status(401) + .entity(new ErrMsg("401", "inactive user")).build(); } - if(state!=0){ - return Response.status(401).entity(new ErrMsg("402","current user is loggin in")).build(); + if (state != 0) { + return Response.status(401) + .entity(new ErrMsg("402", "current user is loggin in")) + .build(); } - if(count ==0 ||(count%31 == 0)){ - return Response.status(200).entity(new ErrMsg("403","required user change password")).build(); + if (count == 0 || (count % 31 == 0)) { + return Response.status(200) + .entity(new ErrMsg("403", "required user change password")) + .build(); } - count = count+1; + count = count + 1; user.setCount(count); user.setState(1); service.update(user); - return Response.ok(new ErrMsg("200","logging in successful")).build(); + HttpSession session = request.getSession(); + session.setAttribute("user", user); + return Response.ok(new ErrMsg("200", "logging in successful")).build(); } @PUT @Path("/active") @Produces("application/json") - public Response getUpdateStatus(@FormParam("userId")String userId,@FormParam("status")String status){ - UserService service = (UserService) BcnxApplicationContext.getBean("userService"); + public Response getUpdateStatus(@FormParam("userId") String userId, + @FormParam("status") String status) throws Exception { + UserService service = (UserService) BcnxApplicationContext + .getBean("userService"); User user = new User(); user.setUserId(userId); user = service.getUser(user); user.setStatus(status); service.update(user); - return Response.ok(new ErrMsg("200","active user successful")).build(); + return Response.ok(new ErrMsg("200", "active user successful")).build(); } @PUT @Path("/logout") @Produces("application/json") - public Response logout(@FormParam("userId")String userId){ + public Response logout(@FormParam("userId")String userId) throws Exception{ UserService service = (UserService) BcnxApplicationContext.getBean("userService"); User user = new User(); user.setUserId(userId); diff --git a/BcnxWebService/src/com/bcnx/web/app/service/user/AdjustmentController.java b/BcnxWebService/src/com/bcnx/web/app/service/user/AdjustmentController.java index b1c1e29..13e4e14 100644 --- a/BcnxWebService/src/com/bcnx/web/app/service/user/AdjustmentController.java +++ b/BcnxWebService/src/com/bcnx/web/app/service/user/AdjustmentController.java @@ -6,8 +6,6 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.Response; -import org.jboss.resteasy.spi.ApplicationException; - import com.bcnx.web.app.context.BcnxApplicationContext; import com.bcnx.web.app.service.AdjustmentService; import com.bcnx.web.app.service.entity.BcnxSettle; @@ -28,8 +26,7 @@ public Response save(@FormParam("mti") String mti, @FormParam("rea") String rea, @FormParam("remark") String remark, @FormParam("part") String part, @FormParam("amount") double amount, @FormParam("fee") double fee, @FormParam("iss") String iss, - @FormParam("acq") String acq, @FormParam("usrId") String userId) - throws ApplicationException { + @FormParam("acq") String acq, @FormParam("usrId") String userId) throws Exception { DisputeTxn disputeTxn = new DisputeTxn(); disputeTxn.setProcc(proc); disputeTxn.setRemark(remark); diff --git a/BcnxWebService/src/com/bcnx/web/app/service/user/BcnxSettleController.java b/BcnxWebService/src/com/bcnx/web/app/service/user/BcnxSettleController.java index 18d5f34..838719f 100644 --- a/BcnxWebService/src/com/bcnx/web/app/service/user/BcnxSettleController.java +++ b/BcnxWebService/src/com/bcnx/web/app/service/user/BcnxSettleController.java @@ -8,8 +8,6 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; -import org.jboss.resteasy.spi.ApplicationException; - import com.bcnx.web.app.context.BcnxApplicationContext; import com.bcnx.web.app.service.BcnxSettleService; import com.bcnx.web.app.service.entity.BcnxSettle; @@ -25,7 +23,7 @@ public Response getBcnxSettles(@QueryParam("card") String card, @QueryParam("rrn") String rrn, @QueryParam("stan") String stan, @QueryParam("from") String from, @QueryParam("to") String to, @QueryParam("page") int page, @QueryParam("rows") int rows) - throws ApplicationException { + throws Exception { BcnxSettle bs = new BcnxSettle(); bs.setCard(card); bs.setRrn(rrn); diff --git a/BcnxWebService/src/com/bcnx/web/app/service/user/BulletinController.java b/BcnxWebService/src/com/bcnx/web/app/service/user/BulletinController.java index 7f54d82..d3d2b77 100644 --- a/BcnxWebService/src/com/bcnx/web/app/service/user/BulletinController.java +++ b/BcnxWebService/src/com/bcnx/web/app/service/user/BulletinController.java @@ -17,7 +17,6 @@ import javax.ws.rs.core.Response; import org.jboss.resteasy.annotations.providers.multipart.MultipartForm; -import org.jboss.resteasy.spi.ApplicationException; import com.bcnx.web.app.context.BcnxApplicationContext; import com.bcnx.web.app.service.BulletinService; @@ -27,7 +26,7 @@ public class BulletinController { @POST @Path("/upload") @Consumes("multipart/form-data") - public Response upload(@MultipartForm Bulletin bulletin) throws ApplicationException { + public Response upload(@MultipartForm Bulletin bulletin) throws Exception { String title = bulletin.getTitle() == null ? "Unknown" : bulletin.getTitle(); String completeFilePath = "D:/Server/Storage/" + title+"."+bulletin.getType(); try @@ -49,14 +48,14 @@ public Response upload(@MultipartForm Bulletin bulletin) throws ApplicationExcep @POST @Path("/save") @Produces("application/json") - public Response save(Bulletin bulletin) throws ApplicationException { + public Response save(Bulletin bulletin) throws Exception { BulletinService service = (BulletinService) BcnxApplicationContext.getBean("bulletinService"); service.save(bulletin); return Response.status(200).entity(bulletin).build(); } @GET @Path("/get/{first}/{max}") - public Response getBulletns(@PathParam("first")int first, @PathParam("max")int max) throws ApplicationException { + public Response getBulletns(@PathParam("first")int first, @PathParam("max")int max) throws Exception { BulletinService service = (BulletinService) BcnxApplicationContext.getBean("bulletinService"); List bulletins = service.getBulletin(first, max); return Response.status(200).entity(bulletins).build(); @@ -64,7 +63,7 @@ public Response getBulletns(@PathParam("first")int first, @PathParam("max")int m @GET @Path("/get/{date}/{first}/{max}") public Response getBulletins(@PathParam("date") String date, - @PathParam("first") int first, @PathParam("max") int max) throws ApplicationException { + @PathParam("first") int first, @PathParam("max") int max) throws Exception { BulletinService service = (BulletinService) BcnxApplicationContext .getBean("bulletinService"); Timestamp start = toTimestamp(date.replaceAll("-", "") + "000000"); diff --git a/BcnxWebService/src/com/bcnx/web/app/service/user/ChargebackController.java b/BcnxWebService/src/com/bcnx/web/app/service/user/ChargebackController.java index 57b6259..891717b 100644 --- a/BcnxWebService/src/com/bcnx/web/app/service/user/ChargebackController.java +++ b/BcnxWebService/src/com/bcnx/web/app/service/user/ChargebackController.java @@ -6,8 +6,6 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.Response; -import org.jboss.resteasy.spi.ApplicationException; - import com.bcnx.web.app.context.BcnxApplicationContext; import com.bcnx.web.app.service.ChargebackService; import com.bcnx.web.app.service.entity.BcnxSettle; @@ -28,7 +26,7 @@ public Response save(@FormParam("mti") String mti, @FormParam("rea") String rea, @FormParam("remark") String remark, @FormParam("part") String part, @FormParam("amount") double amount, @FormParam("fee") double fee, @FormParam("iss") String iss, - @FormParam("acq") String acq, @FormParam("usrId") String userId) throws ApplicationException { + @FormParam("acq") String acq, @FormParam("usrId") String userId) throws Exception { DisputeTxn disputeTxn = new DisputeTxn(); disputeTxn.setProcc(proc); disputeTxn.setRemark(remark); diff --git a/BcnxWebService/src/com/bcnx/web/app/service/user/CopyRequestController.java b/BcnxWebService/src/com/bcnx/web/app/service/user/CopyRequestController.java index 9853c88..45a9abc 100644 --- a/BcnxWebService/src/com/bcnx/web/app/service/user/CopyRequestController.java +++ b/BcnxWebService/src/com/bcnx/web/app/service/user/CopyRequestController.java @@ -19,7 +19,6 @@ import org.jboss.resteasy.plugins.providers.multipart.InputPart; import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; -import org.jboss.resteasy.spi.ApplicationException; import com.bcnx.web.app.context.BcnxApplicationContext; import com.bcnx.web.app.service.CopyRequestService; @@ -28,9 +27,12 @@ import com.bcnx.web.app.service.entity.ErrMsg; import com.bcnx.web.app.service.entity.ReasonCode; import com.bcnx.web.app.service.entity.User; + @Path("/copyrequest") -public class CopyRequestController extends DisputeTemplate{ - private static CopyRequestService copyRequestService = (CopyRequestService) BcnxApplicationContext.getBean("copyRequestService"); +public class CopyRequestController extends DisputeTemplate { + private static CopyRequestService copyRequestService = (CopyRequestService) BcnxApplicationContext + .getBean("copyRequestService"); + @POST @Path("/save") @Produces("application/json") @@ -39,7 +41,8 @@ public Response save(@FormParam("mti") String mti, @FormParam("stan") String stan, @FormParam("proc") String proc, @FormParam("rea") String rea, @FormParam("remark") String remark, @FormParam("part") String part, @FormParam("amount") double amount, - @FormParam("fee") double fee, @FormParam("usrId") String userId) throws ApplicationException { + @FormParam("fee") double fee, @FormParam("usrId") String userId) + throws Exception { DisputeTxn disputeTxn = new DisputeTxn(); disputeTxn.setProcc(proc); disputeTxn.setRemark(remark); @@ -59,7 +62,7 @@ public Response save(@FormParam("mti") String mti, settle.setStan(stan); settle.setMti(mti); settle = bcnxSettleService.getBcnxSettle(settle); - if(settle==null) + if (settle == null) return Response.status(500) .entity(new ErrMsg("412", "invalid transactions")).build(); disputeTxn.setBcnxSettle(settle); @@ -69,10 +72,11 @@ public Response save(@FormParam("mti") String mti, .status(500) .entity(new ErrMsg("410", "User is not allowed to perform function")).build(); - boolean valid = checkValidDate(settle.getDate(),proc); - if(!valid) + boolean valid = checkValidDate(settle.getDate(), proc); + if (!valid) return Response.status(500) - .entity(new ErrMsg("414", "Exceed valid date request")).build(); + .entity(new ErrMsg("414", "Exceed valid date request")) + .build(); DisputeTxn txn = disputeTxnService.getDisputeTxn(disputeTxn); if (txn != null) return Response.status(500) @@ -83,14 +87,16 @@ public Response save(@FormParam("mti") String mti, .entity(new ErrMsg("200", "Copy request has sent successfully")) .build(); } + @PUT @Path("/response") @Produces("application/json") @Consumes("multipart/form-data") - public Response resCpRq(MultipartFormDataInput input, @Context ServletContext context) throws ApplicationException { + public Response resCpRq(MultipartFormDataInput input, + @Context ServletContext context) throws Exception { String path = context.getInitParameter("uploadFolder"); Map> uploadForm = input.getFormDataMap(); - String fileName = getFileData(uploadForm.get("file"),path); + String fileName = getFileData(uploadForm.get("file"), path); String rrn = getDataForm(uploadForm.get("rrn")); String slot = getDataForm(uploadForm.get("slot")); String stan = getDataForm(uploadForm.get("stan")); @@ -98,18 +104,18 @@ public Response resCpRq(MultipartFormDataInput input, @Context ServletContext co String proc = getDataForm(uploadForm.get("procc")); String rea = getDataForm(uploadForm.get("rea")); String userId = getDataForm(uploadForm.get("usrId")); - - DisputeTxn disputeTxn = new DisputeTxn(); + + DisputeTxn disputeTxn = new DisputeTxn(); disputeTxn.setDate(getDate()); disputeTxn.setTime(getTime()); disputeTxn.setProcc(proc); - + User user = new User(); user.setUserId(userId); user = userService.getUser(user); disputeTxn.setUser(user); // check file name - boolean chkName = checkName(fileName, user,rrn, stan); + boolean chkName = checkName(fileName, user, rrn, stan); if (!chkName) return Response.status(500) .entity(new ErrMsg("409", "Invalid Attachment Name")) @@ -121,13 +127,13 @@ public Response resCpRq(MultipartFormDataInput input, @Context ServletContext co settle.setSlot(slot); settle.setStan(stan); settle.setMti(mti); - + settle = bcnxSettleService.getBcnxSettle(settle); - if(settle==null) + if (settle == null) return Response.status(500) .entity(new ErrMsg("412", "Invalid transactions")).build(); disputeTxn.setBcnxSettle(settle); - + DisputeTxn txn = disputeTxnService.getDisputeTxn(disputeTxn); if (txn != null) return Response.status(500) @@ -142,33 +148,33 @@ public Response resCpRq(MultipartFormDataInput input, @Context ServletContext co disp.setProcc("500001"); disp.setBcnxSettle(settle); disp = disputeTxnService.getDisputeTxn(disp); - if(disp==null) - return Response - .status(500) - .entity(new ErrMsg("413", - "Invalid copy request")).build(); - boolean valid = checkValidDate(disp.getDate(),proc); - if(valid) - return Response - .status(500) - .entity(new ErrMsg("414", - "Exceed valid date request")).build(); + if (disp == null) + return Response.status(500) + .entity(new ErrMsg("413", "Invalid copy request")).build(); + boolean valid = checkValidDate(disp.getDate(), proc); + if (valid) + return Response.status(500) + .entity(new ErrMsg("414", "Exceed valid date request")) + .build(); disp.setStatus("Y"); copyRequestService.update(disp); disputeTxn.setAmount(disp.getAmount()); disputeTxn.setFee(disp.getFee()); disputeTxn.setFileName(fileName); - copyRequestService.save(disputeTxn); - return Response.ok(new ErrMsg("200","update successful")).build(); + copyRequestService.save(disputeTxn); + return Response.ok(new ErrMsg("200", "update successful")).build(); } + @Path("download/{fileName}") @Produces(MediaType.APPLICATION_OCTET_STREAM) - public Response download(@PathParam("fileName")String fileName, @Context ServletContext context) throws ApplicationException { + public Response download(@PathParam("fileName") String fileName, + @Context ServletContext context) throws Exception { String path = context.getInitParameter("uploadFolder"); - String target = path+"/"+fileName; + String target = path + "/" + fileName; File file = new File(target); - ResponseBuilder response = Response.ok((Object) file); - response.header("Content-Disposition","attachment; filename="+fileName); - return response.build(); + ResponseBuilder response = Response.ok((Object) file); + response.header("Content-Disposition", "attachment; filename=" + + fileName); + return response.build(); } } diff --git a/BcnxWebService/src/com/bcnx/web/app/service/user/DisputeController.java b/BcnxWebService/src/com/bcnx/web/app/service/user/DisputeController.java index d7b2eca..7398f94 100644 --- a/BcnxWebService/src/com/bcnx/web/app/service/user/DisputeController.java +++ b/BcnxWebService/src/com/bcnx/web/app/service/user/DisputeController.java @@ -8,8 +8,6 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; -import org.jboss.resteasy.spi.ApplicationException; - import com.bcnx.web.app.service.entity.BcnxSettle; import com.bcnx.web.app.service.entity.DisputeTxn; import com.bcnx.web.app.service.entity.Wrapper; @@ -21,7 +19,7 @@ public class DisputeController extends DisputeTemplate { @Produces("application/json") public Response getRelated(@QueryParam("rrn") String rrn, @QueryParam("slot") String slot, @QueryParam("stan") String stan, - @QueryParam("page") int page, @QueryParam("rows") int rows) throws ApplicationException { + @QueryParam("page") int page, @QueryParam("rows") int rows) throws Exception { BcnxSettle settle = new BcnxSettle(); settle.setRrn(rrn); settle.setSlot(slot); @@ -43,7 +41,7 @@ public Response getRelated(@QueryParam("rrn") String rrn, @Path("/get/txn") @Produces("application/json") public Response getDisputeTxn(@QueryParam("rrn") String rrn, @QueryParam("proc") String proc, - @QueryParam("slot") String slot, @QueryParam("stan") String stan) throws ApplicationException { + @QueryParam("slot") String slot, @QueryParam("stan") String stan) throws Exception { BcnxSettle settle = new BcnxSettle(); settle.setRrn(rrn); settle.setSlot(slot); diff --git a/BcnxWebService/src/com/bcnx/web/app/service/user/IncomingController.java b/BcnxWebService/src/com/bcnx/web/app/service/user/IncomingController.java index ae13857..91a4df1 100644 --- a/BcnxWebService/src/com/bcnx/web/app/service/user/IncomingController.java +++ b/BcnxWebService/src/com/bcnx/web/app/service/user/IncomingController.java @@ -9,8 +9,6 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; -import org.jboss.resteasy.spi.ApplicationException; - import com.bcnx.web.app.service.entity.DisputeTxn; import com.bcnx.web.app.service.entity.User; import com.bcnx.web.app.service.entity.Wrapper; @@ -21,7 +19,7 @@ public class IncomingController extends DisputeTemplate { @Path("/get") @Produces("application/json") public Response getIncoming(@QueryParam("usrId") String usrId, - @QueryParam("page") int page, @QueryParam("rows") int rows) throws ApplicationException { + @QueryParam("page") int page, @QueryParam("rows") int rows) throws Exception { User usr = new User(); usr.setUserId(usrId); usr = userService.getUser(usr); @@ -44,7 +42,7 @@ public Response getIncoming(@QueryParam("usrId") String usrId, @QueryParam("card") String card, @QueryParam("rrn") String rrn, @QueryParam("stan") String stan, @QueryParam("proc") String proc, @QueryParam("start") String start, @QueryParam("end") String end, - @QueryParam("page") int page, @QueryParam("rows") int rows) throws ApplicationException { + @QueryParam("page") int page, @QueryParam("rows") int rows) throws Exception { User usr = new User(); usr.setUserId(usrId); usr = userService.getUser(usr); diff --git a/BcnxWebService/src/com/bcnx/web/app/service/user/OutgoingController.java b/BcnxWebService/src/com/bcnx/web/app/service/user/OutgoingController.java index 2841c00..39c259c 100644 --- a/BcnxWebService/src/com/bcnx/web/app/service/user/OutgoingController.java +++ b/BcnxWebService/src/com/bcnx/web/app/service/user/OutgoingController.java @@ -9,8 +9,6 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; -import org.jboss.resteasy.spi.ApplicationException; - import com.bcnx.web.app.service.entity.DisputeTxn; import com.bcnx.web.app.service.entity.User; import com.bcnx.web.app.service.entity.Wrapper; @@ -21,7 +19,7 @@ public class OutgoingController extends DisputeTemplate { @Path("/get") @Produces("application/json") public Response getOutgoing(@QueryParam("usrId") String usrId, - @QueryParam("page") int page, @QueryParam("rows") int rows) throws ApplicationException { + @QueryParam("page") int page, @QueryParam("rows") int rows) throws Exception { User usr = new User(); usr.setUserId(usrId); usr = userService.getUser(usr); @@ -44,7 +42,7 @@ public Response getOutgoing(@QueryParam("usrId") String usrId, @QueryParam("card") String card, @QueryParam("rrn") String rrn, @QueryParam("stan") String stan, @QueryParam("proc") String proc, @QueryParam("start") String start, @QueryParam("end") String end, - @QueryParam("page") int page, @QueryParam("rows") int rows) throws ApplicationException { + @QueryParam("page") int page, @QueryParam("rows") int rows) throws Exception { User usr = new User(); usr.setUserId(usrId); usr = userService.getUser(usr); diff --git a/BcnxWebService/src/com/bcnx/web/app/service/user/ReasonCodeController.java b/BcnxWebService/src/com/bcnx/web/app/service/user/ReasonCodeController.java index bf6fe61..b53fb3e 100644 --- a/BcnxWebService/src/com/bcnx/web/app/service/user/ReasonCodeController.java +++ b/BcnxWebService/src/com/bcnx/web/app/service/user/ReasonCodeController.java @@ -8,8 +8,6 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.Response; -import org.jboss.resteasy.spi.ApplicationException; - import com.bcnx.web.app.context.BcnxApplicationContext; import com.bcnx.web.app.service.ReasonCodeService; import com.bcnx.web.app.service.entity.ReasonCode; @@ -19,7 +17,7 @@ public class ReasonCodeController { @GET @Path("/get/{proc}") @Produces("application/json") - public Response getReasonCode(@PathParam("proc") String proc) throws ApplicationException { + public Response getReasonCode(@PathParam("proc") String proc) throws Exception { List list = reasonCodeService.getReasonCodes(proc); return Response.ok(list).build(); } diff --git a/BcnxWebService/src/com/bcnx/web/app/service/user/RepresentController.java b/BcnxWebService/src/com/bcnx/web/app/service/user/RepresentController.java index ca67f8c..30c5310 100644 --- a/BcnxWebService/src/com/bcnx/web/app/service/user/RepresentController.java +++ b/BcnxWebService/src/com/bcnx/web/app/service/user/RepresentController.java @@ -17,7 +17,6 @@ import org.jboss.resteasy.plugins.providers.multipart.InputPart; import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; -import org.jboss.resteasy.spi.ApplicationException; import com.bcnx.web.app.context.BcnxApplicationContext; import com.bcnx.web.app.service.RepresentService; @@ -34,7 +33,7 @@ public class RepresentController extends DisputeTemplate{ @Path("/save") @Produces("application/json") @Consumes("multipart/form-data") - public Response save(MultipartFormDataInput input, @Context ServletContext context) throws ApplicationException { + public Response save(MultipartFormDataInput input, @Context ServletContext context) throws Exception { String path = context.getInitParameter("uploadFolder"); Map> uploadForm = input.getFormDataMap(); String fileName = getFileData(uploadForm.get("file"),path); @@ -103,7 +102,7 @@ public Response save(MultipartFormDataInput input, @Context ServletContext conte } @Path("download/{fileName}") @Produces(MediaType.APPLICATION_OCTET_STREAM) - public Response download(@PathParam("fileName")String fileName, @Context ServletContext context) throws ApplicationException { + public Response download(@PathParam("fileName")String fileName, @Context ServletContext context) throws Exception { String path = context.getInitParameter("uploadFolder"); String target = path+"/"+fileName; File file = new File(target); diff --git a/BcnxWebService/src/com/bcnx/web/app/service/user/SettleBcnxController.java b/BcnxWebService/src/com/bcnx/web/app/service/user/SettleBcnxController.java index a4e66e9..b2299cc 100644 --- a/BcnxWebService/src/com/bcnx/web/app/service/user/SettleBcnxController.java +++ b/BcnxWebService/src/com/bcnx/web/app/service/user/SettleBcnxController.java @@ -12,8 +12,6 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; -import org.jboss.resteasy.spi.ApplicationException; - import com.bcnx.web.app.context.BcnxApplicationContext; import com.bcnx.web.app.service.SettleBcnxService; import com.bcnx.web.app.service.UserService; @@ -27,7 +25,7 @@ public class SettleBcnxController { @Path("/get") @Produces("application/json") public Response getSettleBcnx(@QueryParam("date") String date, - @QueryParam("id") String id) throws ApplicationException { + @QueryParam("id") String id) throws Exception { SettleBcnxService settleBean = (SettleBcnxService) BcnxApplicationContext.getBean("settleBcnxService"); UserService userBean = (UserService) BcnxApplicationContext.getBean("userService"); User user = new User(); @@ -43,7 +41,7 @@ public Response getSettleBcnx(@QueryParam("date") String date, @Produces("text/plain") public Response download(@QueryParam("usrId") String usrId, @QueryParam("date") String date, @QueryParam("file") String file, - @Context ServletContext servletContext) throws ApplicationException { + @Context ServletContext servletContext) throws Exception { String path = servletContext.getInitParameter("reportPath"); UserService service = (UserService) BcnxApplicationContext.getBean("userService"); User user = new User(); diff --git a/BcnxWebService/src/com/bcnx/web/app/utility/UtilityService.java b/BcnxWebService/src/com/bcnx/web/app/utility/UtilityService.java index f6c012f..236c06f 100644 --- a/BcnxWebService/src/com/bcnx/web/app/utility/UtilityService.java +++ b/BcnxWebService/src/com/bcnx/web/app/utility/UtilityService.java @@ -7,14 +7,17 @@ import java.util.Calendar; import java.util.List; +import org.apache.log4j.Logger; + public class UtilityService { + public static final Logger logger = Logger.getLogger(UtilityService.class); public static Date str2Date(String str){ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); try { java.util.Date date = formatter.parse(str); return new Date(date.getTime()); } catch (ParseException e) { - e.printStackTrace(); + logger.debug("Exception occured while try to convert string to date",e); return null; } } @@ -24,7 +27,7 @@ public static Date str2Date2(String str){ java.util.Date date = formatter.parse(str); return new Date(date.getTime()); } catch (ParseException e) { - e.printStackTrace(); + logger.debug("Exception occured while try to convert string to date",e); return null; } } diff --git a/BcnxWebService/webapp/WEB-INF/bulletin_context.xml b/BcnxWebService/webapp/WEB-INF/bulletin_context.xml index 91d0b52..adb1f62 100644 --- a/BcnxWebService/webapp/WEB-INF/bulletin_context.xml +++ b/BcnxWebService/webapp/WEB-INF/bulletin_context.xml @@ -9,6 +9,6 @@ - + diff --git a/BcnxWebService/webapp/WEB-INF/exception_context.xml b/BcnxWebService/webapp/WEB-INF/exception_context.xml index 74bdca2..7d55484 100644 --- a/BcnxWebService/webapp/WEB-INF/exception_context.xml +++ b/BcnxWebService/webapp/WEB-INF/exception_context.xml @@ -4,7 +4,11 @@ xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd"> + + + + diff --git a/BcnxWebService/webapp/WEB-INF/user_context.xml b/BcnxWebService/webapp/WEB-INF/user_context.xml index 2f10506..6077145 100644 --- a/BcnxWebService/webapp/WEB-INF/user_context.xml +++ b/BcnxWebService/webapp/WEB-INF/user_context.xml @@ -9,6 +9,6 @@ - + diff --git a/BcnxWebService/webapp/WEB-INF/web.xml b/BcnxWebService/webapp/WEB-INF/web.xml index 7c50c8a..70ebbe9 100644 --- a/BcnxWebService/webapp/WEB-INF/web.xml +++ b/BcnxWebService/webapp/WEB-INF/web.xml @@ -9,6 +9,10 @@ uploadFolder D:\Share\tik\Work + + resteasy.providers + com.bcnx.web.app.exception.ApplicationExceptionHandler + resteasy.resources @@ -28,7 +32,9 @@ com.bcnx.web.app.service.user.SettleBcnxController - + + com.bcnx.web.app.exception.SessionTimeOutHandler + org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap