I'm working on a Java EE application hosted in weblogic (10.3.4.0) and connected to an Oracle database. I use UserTransaction to perform database operations. Operations are triggered by webservices call from a C++ client. I have two webservices that I would like to perform as an atomic action, ie rollback to initial state if any exception occurs event during the second webservice call. Note: I can't merge the two webservices into a single one.
I first tried with container-based transaction, but it does not seem to fit as I can't control when the commit will happen (I don't want it to occur between the two webservices).
I'm currently trying with stateful bean but didn't yet find a piece of solution. Currenlty all the webservices are stateless.
Would anyone have some advice on my problem, or any hint showing this is not possible?
Thanks
You may need ws-transaction/ws-coordination modules or service compensation.
Related
I am a novice on webservices front, so please bear with me. I have developed a JavaFX desktop application connecting to database using standard JDBC way. Now that, I want to make this web application, the jdbc had to go out.
I am now implementing with tomee in between and created restful apis (created entity classes for tables and restful apis on top of it) for db access. However, I am not sure how to do this where
a) I need to execute a stored procedure
b) Where the sql query is a join on multiple tables
c) Where I need to insert a sequence in one of the columns.
Any help is appreciated, esp wrt (a) and (b).
If you want a no-frills way of doing it, I'd use Dropwizzard (http://www.dropwizard.io).
If you want more customization, build the stack using JAX-RS, Bean Validation, an EJB as a DAO, and a couple of JPA objects to represent your tables.
See examples here:
http://tomee.apache.org/examples-trunk/simple-rest/README.html
http://tomee.apache.org/examples-trunk/simple-stateless/README.html
http://tomee.apache.org/examples-trunk/injection-of-entitymanager/README.html
I am a newbie in stateful webservices area. Please ignore if any of the below questions do not make sense.
I have mostly dealt with stateless webservices. One question in my mind is that can we pass session id to a web service thru the XML API. Is there already a provision for this(so that it becomes stateful)? Does a Java-XML api to invoke a web service has a provision to make use of cookies?
Are RESTful web services stateful? Is this the reason they are called RESTful?
Let's say I am using a stateful web-service. And I have two different operations where 'Atomicity' of operation has to maintained(take an example of Credit/Debit of card and cruz booking). Both have to be successful or neither.
Can such a thing be achieved using a web service?(because I dont know how transaction control can be applied to web services. It would have been easy if I had to deal with only services(ejb) layer).
If yes-this gives rise to another question-how transaction manager identify client context and does the same transaction context gets applied to these operations which should be part of one meaningful and atomic transaction?
Does this depend on the framework/programming language that we gonna use? For e.g. I want to achive this using JSF/SpringMVC UI and JAX-WS/Axis web service. If no, please let me know what other similar frameworks(from Java) have this and provides the solution. Servers - weblogic/jboss.
Thanks
Prakash
I am just getting started in web services using Lotus Notes. What I would like to be able to do is to create a web service that generates a sequential number. The code to generate the number is based on existing code we have used for some time within our databases (just straight lotus script, no web services). Basically there is a document that stores the next number, the next number is returned and is updated for the next call save conflicts are detected and the number is tried again if there was a issue saving the number.
I thought I might use a web service for to generate the number. So are web services processed sequentially or in parallel? Because if they are serial then I won't need to deal with two people trying to save the number at the same time.
Web services are a way for two systems to communicate with each other where they would not have a common language.
For example LotusScript agent connecting to a .Net server.
When creating a web service provider (server) on Domino you can code it in LotusScript or Java. The server then provides a WSDL file for the consumer (client) to write the code required to talk to that web service.
This tutorial should explain it better for you:
http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Creating_your_first_Web_Service_provider_and_consumer_in_LotusScript_and_Java.
Now as for Domino. Web services run in order they are requested from the server. However there is no control to say "Don't start until Webservice X has finished".
You could also code this into an application but run the serious risk of deadlocks of memory/performance issues for other users unless you counter for that.
The Domino server can also be set to not run web services/agents in parallel. But again you risk the same issues.
If it is a unique ID then you could go by the UNID of the document you create from the web service. Or you can use #UNIQUE via an evaluate, but both only return text.
http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/topic/com.ibm.designer.domino.main.doc/H_UNIQUE.html
From the Lotus Designer Documentation:
To enable concurrent Web services on a server, you must enable concurrent Web Agents on that server. Open the Server document you want to edit. Click the Internet Protocols - Domino Web Engine tab. Enable Run Web Agents concurrently.
The maximum number of concurrent Web service calls is determind by "Max concurrent agents"-setting. From the Lotus Administration Documentation:
Max concurrent agents Specifies the number of agents allowed to run concurrently. Valid values are 1 through 10. Default values are 1 for daytime and 2 for nighttime. Enabling a higher number of concurrent agents can relieve a heavily loaded Agent Manager, but also reduces the resources available to run other server tasks.
Lotus Notes Domino Version 8.5.x
Yes web services Will run in parrallel. But since you wrote that your code deals with save conflict, you should NOT have problem.
As in standard notes calls by 2 users: the 1st get the doc then the 2nd get the doc and save (speedy two) then first will get save conflict.
In conclusion yes it's parallel BUT it's not a problem.
I would have thought that they would by default run sequentially as asynchronous web agents is off unless you switch it on. So although it's a good design pattern to do 'safe' sequentially number if you only allocate a number via the web service and you haven't changed the asynchronous setting then you'll be fine
Let me also add:
Employ document locking to assure number uniqueness in sequential document numbering solution
There is a simple solution that avoids synchronicity considerations.
You should generate a temporary number using #Unique, then use a scheduled agent to assign sequential numbers in order of document creation, selecting only unprocessed documents using a properly constituted view. If you're not concerned about the order in which documents were created and only concerned that all numbers are unique, a view is not necessary, and you can just trigger the agent on unprocessed documents.
The temporary number can be used for reference temporarily until a proper sequential number is assigned.
When the scheduled agent runs, it should send authors confirmation with the correct reference number.
Or, you could export to DXL and get the sequence= attribute of the tag. This only works if you're accessing a single instance of the database, though. And the DXL export/XML import is a huge amount of overhead.
Unfortunately, I can't see a way to easily get the sequence number of the note from LotusScript NotesDocument. If you have an active support contract, you could open a Problem Management Report for a software enhancement request ("APAR", in IBM's parlance, though I do not know what its acronym expands to).
Good luck!
I'm building out a RESTful API for an iPhone app.
When a user "checks-in" [Inserts new row into a table] I want to then take data from that insert and call a web service, which would send push notifications based upon that insert.
The only way I can think of doing this is either doing it through a trigger, or having the actual insert method, upon successful insert, call the web service. That seems like a bad idea to me.
Was wondering if you had any thoughts on this or if there was a better approach that I haven't thought of.
Even if it technically could, it's really not a good idea! A trigger should be very lean, and it should definitely not involve a lengthy operation (which a webservice call definitely is)! Rethink your architecture - there should be a better way to do this!
My recommendation would be to separate the task of "noticing" that you need to call the webservice, in your trigger, from the actual execution of that web service call.
Something like:
in your trigger code, insert a "do call the webservice later" into a table (just the INSERT to keep it lean and fast - that's all)
have an asynchronous service (a SQL job, or preferably a Windows NT Service) that makes those calls separately from the actual trigger execution and stores any data retrieved from that web service into the appropriate tables in your database.
A trigger is a very finicky thing - it should always be very quick, very lean - do an INSERT or two at most - and by all means avoid cursors in triggers, or other lengthy operations (like a web service call)
Brent Ozar has a great webcast (presented at SQL PASS) on The Top 10 Developer Mistakes That Don't Scale and triggers are the first thing he puts his focus on! Highly recommended
It depends on the business needs. Usually I would stay away from using triggers for that, as this is a business logic, and should be handled by the BL.
But the answer is Yes to your question - you can do that, just make sure to call the web service asynchronously, so it does not delay the insert while the web service call finishes.
You may also consider using OneWay web service - i.e. fire and forget.
But, as others pointed out - you are always better off not using trigger.
If properly architectured, there should be only one piece of code, which can communicate with the database, i.e. some abstraction of the DAL in only a single service. Hook there to make whatever is needed after an insert.
I would go with a trigger, if there are many different applications which can write in the database with a direct access to the database, not trough a DAL service. Which again is a disaster waiting to happen.
Another situation, in which I may go with a trigger, if I have to deal with internally hosted third party application, i.e. if I have access to the database server itself, but not to the code which writes in the database.
What about a stored procedure? Instead of setting it up on a trigger, call a stored procedure, which will both insert the data, and possibly do something else.
As far as I know, triggers are pretty limited in their scope of what they can do. A stored procedure may have more scope (or maybe not).
In the worst case, you can always build your own "API" page; instead of directly inserting the data, request the API page, which can both insert the data and do the push notification.
Trigger->Queue->SP->XP_XMDShell->BAT->cURL->3rd party web service
I used a trigger to insert a record in a Queue table,
then a Stored procedure using a cursor to pull Queued entries off.
I had no WSDL or access to the 3rd party API developers and an urgent need to complete a prototype, so the Stored Procedure calls XP_CMDShell calling a .bat file with parameters.
The bat file calls cURL which manages the REST/JSON call and response.
It was free, quick and works reliably. Not architecturally pure but got the prototype off the ground.
A good practice is to have that web page make an entry into another table (i will call message_queue ) when the user hits the page.
Then have a windows service / *nix daemon on a server scan the message_queue table and perform the pushes via a web service to the mobile app. You can leverage the power of transaction processing in SQL to manage the queue processing.
The nice thing about this approach is you can start with everything on 1 stand alone server, and even separate the website, database, service/daemon onto different physical servers or server clusters as you scale up.
I need to call a webservice to validate some data. There is web service task in the control flow but I need to validate during the data flow. Also, the web service supports single or batch validations so it would be nice to batch a 100 items for validation at a time.
Is it best to just code all this up in a script component?
Personally I would code in a script component. The web service stuff is kind of beyond the scope of the traditional purposes of the given SSIS components I think and if you're using SSIS 2008 I'd just write it up in C# and continue on.
Just my opnion.