How can one prevent passing exceptions over an EJB-Webservice?

Hello,
I would appreciate if someone could give me some advice on the following. I tried to google it/use the search function, however, it was quite hard finding a precise search term.
Let me try to explain the setting conceptionally without much code first.
Three stateless session beans - let's call them BeanA, BeanB and BeanC - perform some specific tasks. Especially, they are using JPA to create and manipulate persistent entities. Clients like graphical user interfaces access these beans. I call them internal clients because they belong the same company like BeanA, BeanB and BeanC. Internal clients can know how to handle exceptions which are thrown in the beans.
However, the functionality of these beans is also relevant to external clients, for example another company. A webservice (WebserviceBean) combines the functionality of the three beans and communicates with the external client. The latter one must not receive any exceptions thrown in my EJB application as this could leak implementation details but they must be informed, that the task could not be performed (some kind of "Please try again later"). As far as I understood (also tested it), JAX-WS takes exceptions and turns them into SOAP-Faults.
My first (naive) approach was to do something like this
Webmethod of the WebserviceBean (
public ReturnType doWebserviceFunctionality(ParameterType parameter) {
   try {
      beanAinstance.doWork();
      beanBinstance.doMoreWork();
      beanCinstance.doFinalWork();
   catch(SpecificException se) {
   // Map specific exception to ReturnType.specificError
   } catch(Exception e) {  // Bad practice, I know
   // Map general exception to ReturnType.encounteredInternalError
}In every bean's method as well as in the webservice, I am using Container Managed Transactions (default setting REQUIRED).
The problem is, that doMoreWork() uses an entity with a versioning attribute (@version) in order to support optimistic locking. This works quite well, however, whenever an OptimisticLockException is thrown, it does not get caught in WebserviceBean and is passed on to the client. I think this is because the complete transaction is commited at the end of doWebserviceFunctionality. I am aware that I could use EntityManager's flush method in bean B in order to catch the OptimisticLockException. However, I am trying not to interfere with transaction commiting as far as possible and furthermore, I am not quite sure, if there could be other exceptions (for example JPA exceptions) which could get thrown in a similar way and are passed on to the client.
Does anybody know a possibility to solve this problem? Do I have to use bean managed transactions? Or mark doWebserviceFunctionality as not part of an transaction and put the bean method calls in a seperate method which commits at the end and allows me to handle exceptions? Or is there a completely different approach necessary?
Any help is appreciated, thanks in advance,
BKelso

Hello to all,
thanks again for your suggestions which proved to be valueable hints!
I'll tell you so far the lessons I've learned.
1) Using interceptors (suggested by malrawi)
This would have been a very nice solution, however, it turns out that the problem remains - the exception thrown by the container after the commit is not caught. Here is the code I used
    @AroundInvoke
    public Object convertException(InvocationContext ctx) throws InternalErrorException {
      try {
         return ctx.proceed();
      } catch(Exception e) {
         // just tried to throw another exception here in order to see if it works
         throw new InternalErrorException("Internal Error occured. Please try again later.");
    }2) Using bean managed transcations (suggested by zsom)
This worked out as I thought it would. The webservice starts and commits the transactions, beanA, B and C can still keep the default CMT Attribute. However, when ut.rollback() is called, an IllegalStateException is always thrown. Don't know why so far, the transaction seems to be set back anyways.
@Resource SessionContext ctx;
public ReturnType doWebserviceFunctionality(ParameterType parameter) {
UserTransaction ut = null;
      ut = ctx.getUserTransaction();
      try {
         ut.begin();
         ut.commit();
     } catch (Exception e) {
         try {
            ut.rollback();
            // map exception...
         } catch (Exception rollbackException) {
            // also map exception to return type
}3) Upon the suggestion by malrawi using NotSupported transaction attribute in order to force a commit, I came up with the following: The webservice method uses this transaction attribute while simply calling another local stateless session bean (beanZ), which does the actual work (calling beans A, B, C). It uses the default transaction attribute (Required). This works out perfectly at the cost of an additional bean. But maybe you see some other downsides? Essentially it's the same as the idea with the internalMethod made public and using another transaction attribute.
// web service class
public ReturnType doWebserviceFunctionality(ParameterType parameter) {
   try {
        beanZinstance.doActualWork();
   catch(Exception e) {  // Map exceptions here
// bean Z class
public ReturnType doActualWork(ParameterType parameter) {
       beanAinstance.doWork();
      beanBinstance.doMoreWork();
      beanCinstance.doFinalWork();
}4) Using soaphandler (suggested by zsom)
This seems like a good idea but it is also the most complicated and a bit more low-level. But I will check it out in more detail, I think.
Thanks again for your efforts and I still appreciate any feedback!
BobKelso

Similar Messages

  • How can one prevent iTunes overwriting personalised tagging on iTunes purchases?

    How does one prevent iTunes 11 overwriting custom tags on iTunes purchases? I have a very specific tagging scheme and I do not appreciate my tags being ovewritten by iTunes 11 back to those embedded at purchase causing disorganisation of my iTunes library and iPods
    (For example, I have different genre and sort artist fields that are more suited to my filing system.)

    Are my purchased songs automatically being added? How do I prevent them from being added?
    5502,
    You can do that from the iPad itself. 
    Go into your iPad and touch the Settings icon.  Then, from the left-hand list, choose "iTunes & App Store." 
    This will give you a section about "Automatic Downloads."  There you can enable or disable Music, Apps, and Updates. 

  • HT5517 In multiple Apple TV's installation how can one prevent one iOS device from taking over the connection of another iOS device?

    I am working on a system design where I would like to install 5 Apple TV's so when clients walk in with their iPhones they can connect to the network and be able to stream their audio to facility zone speakers where they will be working. But I am looking to prevent others from taking over that connection. I have never installed multiple Apple TV's in one site but I assume one would name them differently (Apple TV 1 - 5) when setting them up. I am also assuming when I walk in with my iphone and use the airplay I would see all 5 Apple TV's listed. Once I choose Apple TV 1 for instance, I do not want others to walk in and see Apple TV 1 on the list any longer so they do not have the oportunity to select it inadvertantly. Is this doable?

    You can't remove them from the list, but you can set a password for airplay to each Apple TV

  • How can i prevent my pro from over heating?

    How can i prevent my pro from over heating?

    Don't use the computer in your lap, or on a blanket or pillow. The case bottom is part of the heat dissipation system so it needs air underneath. If you must use the computer in your lap, get a lapboard. There are cheap, even more so if you make one yourself.
    If the computer is a older MBP with silver keys, avoid "clamshell" mode when using an external monitor. Those models let a lot of heat escape through the keyboard. The black-key Unibody versions don't seem to rely so much on the keyboard as a vent.
    Like eww said, what feels hot to you may not threaten the computer's well-being. Get a temperature monitoring utility. I like this one:
    http://bresink.com/osx/TemperatureMonitor.html
    It runs politely in the background and puts the readout in the menubar:
    so you don't have to invoke Dashboard like some other temp monitors require. As Dashboard loads all its widgets as soon as it's invoked, the extra widget processes can run up the temps and you don't get a true average use temp.
    If you use Dashboard a lot, those processes stay active after the first launch and can eat processor cycles as well as increase temps. I use DashQuit, a widget that shuts down Dashboard when I'm done without requiring a computer restart. It's here:
    http://www.apple.com/downloads/dashboard/status/dashquit_berenguierduncan.html

  • My neighbour's Mac Book Pro shows up as discoverable when Bluetooth is turned on in my iPad Air.  How can I block her device?  How can I prevent her pairing with my iPad Air. I need Bluetooth on to play music over my system.

    My neighbour's Mac Book Pro shows up as discoverable in my Bluetooth list on my iPad Air.  How can I block her Bluetooth device? How can I prevent her pairing with my device?  I need Bluetooth to stream music on my Bose system.  Thanks!

    If your device is discoverable, the other BT device would try (I am not sure if that would be successful). If it was, it would appear in your system preferences>Bluetooth.
    Take a look at this re: security:
    http://support.apple.com/kb/PH10786
    This is from another Apple article:
    Use Bluetooth
    You can wirelessly transfer files between computers—even Mac to PC—using the Bluetooth File Exchange utility. You can even browse selected devices and retrieve files remotely. For extra security, you can stipulate that only trusted devices be allowed to connect to your Mac, and 128-bit over-the-air encryption is also available
    Barry
    P.S. Since I have not had the issue, I have not researched this before. Thank you for making me look into BT security
    Message was edited by: Barry Hemphill

  • If I have multiple email accounts, how can I prevent one of them from sending email?

    If set up multiple email accounts in Thunderbird, how can I prevent one of them from sending email, while allowing others to send?

    Simple answer:
    do not use the email address when sending or replying or forwarding emails. Sending is not automatic, you have to generate the email and click on a Send button.
    You could use an smtp server that will not allow sending using the incorrect server for the email address, so that it cannot send, but if you accidentally use the email address you may get an error message, but at least the email will not be sent. Do this here:
    Tools > Account Settings for the mail account.
    bottom right Outgoing Server - select one that will not accept sending using wrong email address
    OR
    in Outgoing Server(SMTP) select the server you are using for that account
    click on 'Edit'
    deliberately make an error in the server name - remove the port details etc.
    So the details are wrong and cannot send.

  • How can I prevent two different profiles from interfering with one another?

    I have a serious profiles problem. I created a new profile with Profile Manager and then copied a well-established profile's contents into its directory before starting the new profile. Now, when I start either profile, it contains whatever tabs I had in the previously opened profile. I deleted a bunch of tabs and a window from the new profile but when I opened it after having opened and closed the old profile, the tabs and window reappeared. If I open some tabs in the new profile and then close it and open the old profile, the tabs appear in it, and vice versa.
    I open the original profile through a shell script:
    <pre>/Applications/Firefox.app/Contents/MacOS/firefox -P "profile 1"</pre>
    I open the second one the same way but with the <i>-no-remote</i> parameter:
    <pre>/Applications/Firefox.app/Contents/MacOS/firefox -P "profile 1 clone" -no-remote</pre>
    Why do the two profiles collide like that and how can I prevent this from happening?

    Are you using Sync then ?
    Or are you setting a bunch of tabs as the homepage ?
    If you cloned a profile they will start off the same and that will include the set of open tabs from the file ''sessionstore.js'' however profiles are independent and so should have there own sessionstore and History once they have been used.

  • I am on a plan with a basic phone that is breaking. I was given a smartphone that belonged to a relative that is now deceased, (they used the phone since they have passed it is deactivated.) how can I switch my phone over and is there anyway to avoid a da

    I am on a plan with a basic phone that is breaking. I was given a smartphone that belonged to a relative that is now deceased, (they used the phone since they have passed it is deactivated.) how can I switch my phone over and is there anyway to avoid a data package/plan?

    What is your current plan?  In some cases it can be cheaper to move to a More Everything plan with an out of contract line. With More Everything, you will get a $15 per month reduction in line fee with a minimal data. 

  • My IPAD (original version) is deleting everything over 30 days from my calendar.  How can I prevent this and how can I get the deleted events back?

    My IPAD (original version) is deleting everything over 30 days from my calendar.  How can I prevent this and how can I get back the deleted events? 

    You are most welcome

  • I open safari and one site takes me to their app in the store automatically.  How can I prevent this?

    I open safari and one site takes me to their app in the store automatically.  How can I prevent this?

    some sites that use flash (or other issues) dont want you trying to view the site in your browser on an ios device, because they know it will not be a good experience - they detect your device, and if it is an ios device  they want you to use their app instead of your browser.

  • I'm using "window.open()" to show one Calendar in a popup window. I can see that the popup is re-sizable. How can I prevent the user from re-sizing the popup?

    I'm using "window.open()" to show one Calendar in a popup window. I can see that the popup is re-sizable. How can I prevent the user from re-sizing the popup? I have tried "resizable=yes|no|1|0" and that seems to be not working.

    You can't prevent users from resizing a pop-up.
    *https://developer.mozilla.org/en-US/docs/Web/API/window.open

  • How can I prevent Bridge from altering my photos?

    HELP!!!
    Within the past few days my Bridge CS4 program has been making my life miserable. I had been utilizing the program to batch photos from my extensive photo library, rename them, sort them (i.e., change sort/ordinal number), and the like without any difficulty and then suddenly, after executing such processes my thumbnails turned completely white and would not open in Bridge, Photoshop CS4 Extended - much less anything else. I tried reopening them as .jpg's, .psd's, .tiff's to no avail. I went into properties on each photo and checked the "open with" tab, and it noted that the photo was not recognized. I had some moderate success opening them with Quicktime Picture Viewer, but converting them back to a Bridge readable format (i.e., their original state) proved impossible. Having noticed that Quicktime had hijacked nearly my entire photo opening process, I uninstalled it in the hope that it would solve the problem. It didn't. I then went into Bridge and Photoshop CS4 preferences to try and modify how photos were opened, and couldn't seem to find anything applicable. I did, however, increase the memory and cache allocated to each program substantially.
    Last night I ran into more problems with Bridge. While scanning both photo negatives and prints into Bridge and saving them into various files, I encountered the same problem indicated in paragraph one. I tried scanning several of them a second time and succeeded; however, I had to save them to a different file and give them dissimilar names in .tiff format. In the process I found more than a dozen ways to spell "Mexico," "Tokyo," and "Ukraine"! They would not save as .jpg's or .psd's.
    I use Windows Vista Home Premium SP1, have a Pentium 4 Dual Core (2.8) processor, 4 GB Memory, Nvidia GE Force 7600 video card (yes, the drivers are up to date), and Hewlett Packard Photosmart C7180 and C7280 printers for scanning. All of the photos involved are stored on a Maxtor One Touch 1TB Turbo auxillary hard drive.
    Also, could anyone suggest how I can get the  SD/MMC card reader on my PC to work?
    Thanks to any and all for assisting me with my problem.
    Wolfgang Holst
    Big Bear Lake, CA

    Thank you curt y for your quick response. I have seen your recommendations on the adobe forums link in the past and many of your solutions
    seem to have helped other people with Bridge problems. I took your suggestion and gave it a whirl - all preferences were restored to defaults - and the problem continues. I get the feeling the problems lies with the program's interaction with Windows.
    Having tried a few more things, I've found that I can move the photo shell (the inscription underneath the thumbnail states, "Window Shell Common") to my desktop and open it there with Photoshop (i.e., going through the song and dance of "open with" and clicking on the CS4 icon, where it opens up in RAW). I must then move it over to Photoshop CS4 and save it as a .jpg or a .psd. Unfortunately, after all this it still won't open in Bridge. By all appearances, Bridge somehow has become corrupted and I'm probably going to have to do a complete Photoshop CS4 uninstall and reinstall.
    I've spent hundreds - if not thousands - of hours scanning into my system some 10,000 photographs of my travels (yes, they are backed up on discs), and Bridge should not be negatively impacting my ability to organize and manipulation them as is happening now. If the uninstall/reinstall does not resolve the problem, I'll be back on this forum for more suggestions.
    As for the card reader issue, I'm well aware of the 2GB/over 2GB issue. I typically use a 4GB or more card in my camera. I can download fine through my HP 7180 and 7280 card readers, but my HP 1518n card reader is a different story. I'll work a little more on it, too.
    Thanks again.
    Wolfgang Holst
    Big Bear Lake, CA    
    Date: Thu, 18 Jun 2009 08:49:46 -0600
    From: [email protected]
    To: [email protected]
    Subject: How can I prevent Bridge from altering my photos?
    Have you tried resetting your preferences by holding down the Ctrl key and starting Bridge?  You will get a reset window, choose all 3 options.
    The only thing I know about card readers is that there are 2 versions.  One for cards of 2 gigs or less, and one for HD cards over 2 gigs.  Make sure card and reader match.
    >

  • How can I prevent the settings on iMessage from changing each time I sync the devices with iTunes on our iMac?

    Each time I sync an apple device (iPad, iPad mini, iPhone) with iTunes on our iMac the settings on iMessage and phone settings change. We use the same Apple ID and have different e-mail addresses and phone numbers; however, each time a device is sync'd on iTunes on our iMac, the iMessage settings and phone settings are changed so that we all each get each other's text messages and phone calls. After the device is sync'd/charged, I have to go into each device (all of them somehow update when only one is sync'ing) and re-set the settings to what we want. How can I prevent settings from being changed each time?

    Okay I've tried safe mode.  Let it run down to 98%, plugged it in, locked the screen, and waited.  A few minutes later, the screen came on showing the 100% icon at the top right, full battery icon just to the left of the time, 100% text to the left of that.
    I'm not going to do a hard reset until I have confirmation that this is not normal behavior for the phone because that's going to take hours of my time and gigabytes of data transfer to get all of my media and apps back on the phone and configured.
    After all my griping, I do have to give credit where it's due.  This phone is much more efficient than my Galaxy Nexus.  I left the S5 running in WiFi hotspot mode while on battery last night.  It still had over 50% left on the battery.  The Galaxy Nexus would be stone dead after about 4 hours.  I can live with that if I have to but I'd really rather be able to leave it on the charger at night.

  • How can I prevent videos from automatically starting when I load a web site?

    Recently web sites have begun not only showing me the first shot of a video, but starting the video automatically when the page loads (or when I scroll down to the part of the page where the video is located). This happens on various news sites (nytimes.com), facebook, and other places. How can I prevent the autostart from happening?
    I've got AdBlockPlus and NoScript enabled, although I whitelist many sites in NoScript. Videos used to wait for me to click an arrow in the middle (like a "play" button) to start; some still do, but most don't. (I believe an add-on is responsible for the play button, but I don't recall which one.)
    Any suggestions?
    Thanks.

    The chosen answer is not an answer at all.
    The question remains unanswered: How does one prevent unwanted video content from playing automatically on web websites? The problem is most notable on news sites such as ABC News.
    It is really, really, really really really, really, really, really really really, really, really, really really really irritating. More irritating, in fact, than when people cut and paste a word a dozen times to emphasize it.
    MORE IRRITATING THAN WHJEN PEOPLE USE ALL CAPS OUT OF FRUSTRATION BECAUSE NO ONE SEEMS TO LISTEN OR TO CARE THAT I AM SLOWLY LOSING MY MIND BECAUSE EVERY FLIPPING WEB PAGE IN EXISTENCE PLAYS VIDEAS THAT I DON'T WANT TO WATCH.
    More irritating than repeatedly stating the same thing over and over and over and over... wait. I already illustrated that tautology. Never mind.
    Does anyone have an answer? If there is no answer, and the powers that be at Firefox have decided that we have no choice, then state so. If those who decide what HTML "is" have decided that individuals have no power to opt out of video content on any given web page, then say so.
    If Obama is to blame, then say so. If Bush is to blame, then say so.
    But don't say, "the web [page may be using HTML 5 to play video" because THAT is a NON-ANSWER, let alone the "best" answer.

  • How can I prevent the flushing of the buffer until the playing is finished in AS3?

    How can I prevent the flushing of the buffer until the playing is finished in AS3?
    Is it possible?
    The buffer is emptied and flushed 10-11 seconds before the real end of the flv file.
    The file is locally saved and I stream it though crtmp server.
    I cannot seek the last 10 seconds because of empty buffer. How can I stop flash from flushing the buffer at end?

    i used the same code and i got it working correctly...
    thanx a lot fot it...
    now i have one more problem with it.
    Actually i created a new class 'ErrorDialog' and the function showErrorDialog() inside it.
    now i want the option YES_NO_OPTION and the function sayshowMsgDialog() returning int value indicating the option selected from the dialog box.
    I tried it with following code
    public
    static
    int
    confirmDialog( String message_in, Component parent_in, String title_in,
    int messageType_in )
    try
    JOptionPane pane = new JOptionPane( message_in, messageType_in,
    JOptionPane.YES_NO_OPTION );
    JDialog dialog = pane.createDialog( parent_in, title_in );
    dialog.setResizable( false );
    dialog.show();
    int optionType = -1;
    try
    optionType = ( ( Integer )( pane.getValue() ) ).intValue();
    catch( Exception ee )
    optionType = -1;
    dialog.dispose();
    return optionType;
    catch( Exception e )
    e.printStackTrace();
    but, since return is after dispose() it is throwing an error 'missing return value'
    can i get some kind of solution for this?
    waiting eagerly...........
    -Soni

Maybe you are looking for

  • Currency Translation for Key Figures with Value More Than One Currency

    Hi... I have query which display key figure GL Account Balance. The currency that used for this key figure is USD and IDR. How we want display value based on selection screen? So if we input currency USD, all value that use currency IDR translated to

  • SAP DB Reorganisation in SAP 4.6C Kernel 46D Patch 2500 and Oracle 9.2.0.8

    Hi Gurus, I have to delete the clients and then perform DB-Reorg. Through SCC5, I am deleting the clients. 1) Is it possible to select all the clients and delte altogether, as there are 12 clients to be deleted. For Reorg, I went through the below no

  • How to recover TNSNAMES.ORA file

    Hi, im using Oracle 8i 8.16 database running on win2k server. Im getting a an error whenever i try to connect to the databese using the DBA Studio program - the error was "ORA-12154:TNS:Could Not resolve service name". I noticed that the TNSNAMES.ORA

  • Installing 10g on Windows XP

    I have downloaded the 10g standard Release 2 zip file, moved it to a new directory c:\install\database and unziped the files into that directory. When I click on the autorun.exe and then select Install/Deinstall products I get "Unable to Start Pracle

  • Why can't I see my Itunes library when I connect to the computer?

    I want to see what songs are in my Ipod with my new nano and with my mini, when plugged in to my computer I had the option to see every song in my device. I can't see any of my songs when I click on the Music tab. I need to change some of the file na