If you have error gotten back a nice 400 Bad Request from Spring MVC when trying to map a pojo with @RequestBody this will help you find out what is failing.
@ExceptionHandler(MethodArgumentNotValidException.class)
public String handleMethodArgumentNotValidException(
MethodArgumentNotValidException error) {
LOGGER.error(error.getBindingResult().toString());
return "Bad value";
}
@ExceptionHandler(TypeMismatchException.class)
public String handleTypeMismatchException(TypeMismatchException ex,
HttpServletRequest req, HttpServletResponse resp) {
LOGGER.error("Parameter failure: {}"
+ ex.getRootCause().getLocalizedMessage());
LOGGER.error("Invalid value is: {}" + ex.getValue());
LOGGER.error("Required type is: {}"
+ ex.getRequiredType().getSimpleName());
return "Bad value";
}
@ExceptionHandler(HttpMessageNotReadableException.class)
public String handleMessageNotReadableException(
HttpMessageNotReadableException ex, HttpServletRequest req,
HttpServletResponse resp) {
LOGGER.error("Failure: {}" + ex.getRootCause().getLocalizedMessage());
return "Bad value";
}
Friday, March 29, 2013
Wednesday, March 27, 2013
Spring @Transactional boundaries
InvalidDataAccessApiUsageException: detached entity passed to persist:
I experienced the exception above recently and thought it was simply, something like one of the following links:
http://stackoverflow.com/questions/2441598/detached-entity-passed-to-persist-error-with-jpa-ejb-code
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/objectstate.html
Detached - a detached instance is an object that has been persistent, but its
Session has been closed. The reference to the object is still valid, of course, and the detached instance might even be modified in this state. A detached instance can be reattached to a new Session at a later point in time, making it (and all the modifications) persistent again. This feature enables a programming model for long running units of work that require user think-time. We call them application transactions, i.e., a unit of work from the point of view of the user.In fact though it was because I was executing the queries across two different transactions and once I added @Transactional to the service method they were being executed in -- it changed to the same transaction.
http://stackoverflow.com/questions/6363683/spring-transactional-boundaries
http://forum.springsource.org/showthread.php?109091-JpaRepository-save()-gt-detached-entity-passed-to-persist
http://forum.springsource.org/showthread.php?75646-exception-detached-entity-passed-to-persist
Tuesday, March 12, 2013
Browser based security attacks
2 Common Types
- Cross-site scripting uses known vulnerabilities in web-based applications, their servers, or plug-in systems they rely on. Exploiting one of these, they fold malicious content into the content being delivered from the compromised site. When the resulting combined content arrives at the client-side web browser, it has all been delivered from the trusted source, and thus operates under the permissions granted to that system. By finding ways of injecting malicious scripts into web pages, an attacker can gain elevated access-privileges to sensitive page content, session cookies, and a variety of other information maintained by the browser on behalf of the user. Cross-site scripting attacks are therefore a special case of code injection. http://en.wikipedia.org/wiki/Cross-site_scripting
- Cross-site request forgery, also known as a one-click attack or session riding and abbreviated as CSRF (sometimes pronounced sea-surf[1]) or XSRF, is a type of malicious exploit of a website whereby unauthorized commands are transmitted from a user that the website trusts.[2] Unlike cross-site scripting (XSS), which exploits the trust a user has for a particular site, CSRF exploits the trust that a site has in a user's browser. http://en.wikipedia.org/wiki/Cross-site_request_forgery
http://beefproject.com/ The Browser Exploitation Framework (BeEF)
Polymorphism
3 Types:
- Ad-hoc polymorphism
- Parametric polymorphism
- Subtype polymorphism (or inclusion polymorphism)
Parametric polymorphism: Parametric polymorphism allows a function or a data type to be written generically, so that it can handle values identically without depending on their type.[4] Parametric polymorphism is a way to make a language more expressive, while still maintaining full static type-safety.
Parametric polymorphism is ubiquitous in functional programming, where it is often simply referred to as "polymorphism". The following example shows a parametrized list data type and two parametrically polymorphic functions on them:
Look further into Type Theory.
In mathematics, logic, and computer science, type theory generally refers to a class of formal systems, some of which can serve as alternatives to naive set theory as a foundation for all mathematics. In type theory, every "term" has a "type" and operations are restricted to terms of a certain type.
http://en.wikipedia.org/wiki/Type_theory
Douglas Crockford: Monads
http://www.youtube.com/watch?v=dkZFtimgAcM Douglas Crockford: Monads Talk
http://channel9.msdn.com/Shows/Going+Deep/Hewitt-Meijer-and-Szyperski-The-Actor-Model-everything-you-wanted-to-know-but-were-afraid-to-ask
http://en.wikipedia.org/wiki/Monad_(functional_programming)#The_Maybe_monad
http://www.manning.com/bjarnason/ Functional programming in Scala
http://letitcrash.com/ Erlang let it crash model
http://stackoverflow.com/questions/7103864/what-are-practical-uses-of-applicative-style
http://prog21.dadgum.com/16.html Garbage collection in Erlang, very interesting read.
http://channel9.msdn.com/Shows/Going+Deep/Hewitt-Meijer-and-Szyperski-The-Actor-Model-everything-you-wanted-to-know-but-were-afraid-to-ask
http://en.wikipedia.org/wiki/Monad_(functional_programming)#The_Maybe_monad
http://www.manning.com/bjarnason/ Functional programming in Scala
http://letitcrash.com/ Erlang let it crash model
http://stackoverflow.com/questions/7103864/what-are-practical-uses-of-applicative-style
http://prog21.dadgum.com/16.html Garbage collection in Erlang, very interesting read.
Erlang and "Let it Crash" Programming
Although Erlang is designed to encourage/facilitate a massively parallel programming style, its error handling may be even more noteworthy.
- Error handling in Erlang is very different from error handling in conventional programming languages. The key observation here is to note that the error-handling mechanisms were designed for building fault-tolerant systems, and not merely for protecting from program exceptions. You cannot build a fault-tolerant system if you only have one computer. The minimal configuration for a fault tolerant system has two computers. These must be configured so that both observe each other. If one of the computers crashes, then the other computer must take over whatever the first computer was doing. This means that the model for error handling is based on the idea of two computers that observe each other.
- Links in Erlang are provided to control error propagation paths for errors between processes. An Erlang process will die if it evaluates illegal code, so, for example, if a process tries to divide by zero it will die. The basic model of error handling is to assume that some other process in the system will observe the death of the process and take appropriate corrective actions. But which process in the system should do this? If there are several thousand processes in the system then how do we know which process to inform when an error occurs? The answer is the linked process. If some process A evaluates the primitive link(B) then it becomes linked to A . If A dies then B is informed. If B dies then A is informed.Using links, we can create sets of processes that are linked together. If these are normal processes, they will die immediately if they are linked to a process that dies with an error. The idea here is to create sets of processes such that if any process in the set dies, then they will all die. This mechanism provides the invariant that either all the processes in the set are alive or none of them are. This is very useful for programming error-recovery strategies in complex situations. As far as I know, no other programming language has anything remotely like this.
http://blogs.teamb.com/craigstuntz/2008/05/19/37819/
Friday, March 1, 2013
Changing your default python version on OSX
$ man python
$ which python
/usr/bin/python
$ python -V
Python 2.7.1
#
# temporarily change version
#
$ export VERSIONER_PYTHON_VERSION=2.6
$ python -V
Python 2.6.6
$ unset VERSIONER_PYTHON_VERSION
$ python -V
Python 2.7.1
#
# persistently change version
#
$ defaults write com.apple.versioner.python Version 2.6
$ python -V
Python 2.6.6
http://stackoverflow.com/questions/6998545/how-can-i-make-python-2-6-my-default-in-mac-os-x-lion
Subscribe to:
Posts (Atom)