Note that there are some explanatory texts on larger screens.

plurals
  1. POA facade to hide authentication details from Java web service
    primarykey
    data
    text
    <p>I'm building an UI client that uses a service API that behind the scene uses Web services. One of the API services looks like this:</p> <pre><code>interface UserService { List&lt;User&gt; findUsers(User loggedInUser, UserSearchParameters searchParameters, PagingParameters pagingParameters) throws AuthenticationFault, InvalidIndexFault; void removeUser(User loggedInUser, User userToRemove) throws AutheticationFault; void addUser(User loggedInUser, User newUser) throws AuthenticationFault; } </code></pre> <p>The loggedInUser is the user on who's behalf the method is called. AuthenticationFault is a checked exception. There's like 20 of these service interfaces. What I would like to do is implement a facade that hides the loggedInUser parameters and AuthenticationFault exceptions. The facade implementation would call these methods with the user that is currently logged in the client.</p> <p>I would also like to do some cleaning with the other checked exceptions too. As you can see there is a InvalidIndexFault exception that is thrown when client tries to retrieve page -1 but that is a programmer error and I don't want to have it as a checked exception.</p> <p>Currently what I've done is always rethrow a RuntimeException for exceptions that I don't like, but if I later change my mind it's a lot of work changing that later. This also feels like code duplication. Other programmers have just swallowed exceptions and logged them which is totally horrible. Most of the time if there is an exception I want to bubble it up to error handler in the ui that displays an error.</p> <p>There's been a few solutions that have come to my mind:</p> <ol> <li>Java dynamic proxy</li> <li>Code generation</li> </ol> <p>I haven't gotten around to try out those solutions and figured I might as well ask here first. How do you suggest I would implement this? The environment is Java 6 and build tool is Maven 3 if that helps.</p> <p>PS. If you answer this, please say more than "pick number 2" :) Any tips and other implementation details are welcome.</p> <p><strong>As a clarification retrieving the currently logged in user is not an issue so you don't have to help me with it. I currently hide it behind an interface and use IoC to inject it around. Behind the scenes it uses ThreadLocals</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload