Using connection service based by params - eclipse-scout

I have many services extending MsSQLAbstractService class, each for single database. For my application I need to connect to the proper database based on a parameter in the request.
How can I pass such a parameter and make the SQL class use the service I want?
I created my own SQL class, when passing the ID manually everything works, but I need to pass it from the request. How can I pass that param from request to SQL class?

Extracting the parameter
Depends on your requirements:
Service call from front end: Probably you could register a #Replace-Annotated ServiceTunnelServlet-subclass and extract it from the request there.
Alternatively, there also is a thread-local that keeps the request for service tunnel calls: IHttpServletRoundtrip.CURRENT_HTTP_SERVLET_REQUEST. If you can easily extract it from the URL or header: great
REST call to your backend: Extract it in the appropriate Servlet
Storing the parameter
You can wrap method calls in a ServerRunContext, and pass properties along that you can extract at other locations! See the ServerRunContext#withProperty(String,String) method.
You can create a new Context using the ServerRunContexts helper methods.
Using it
This part you already seem to have solved: You can use a single registered Service or appropriate #Order annotation to get the request and then dispatch them to the proper service based on the ID that you stored in the ServerRunContext.

Related

What is the proper way to pass the connection to the DB in a Servicestack message based design

I have problems deciding on how the OrmLiteConnectionFactory should be passed to the different classes. Should it be done by injecting the container into the constructors? It is a message based design if that matters.
Basically you'd just want to pass a "reference" to what connection you'd want your Service to be executed with.
ServiceStack's Multitenancy docs shows different approaches of specifying the DB connection to use per Request DTO message, including using a custom filter, or utilizing the built-in [ConnectionInfo] or [NamedConnection] attributes.
Or if you prefer you can resolve which DB connection you want to use with your Services logic by resolving it from a IDbConnectionFactory dependency.

What is the best way to pass context parameters to a ResourceHandler

I am using CefSharp. I have a RequestHandler which read data from a multiple databases. I would like to pass a context object which will contain a service instance which is bound to a specific database connection. I wonder what is the best way to do that using CefSharp. So far I was using global instance that is shared between the browser and the client code but I dont like that approach. Is there a way to set a "context" object per browser instance and use that context from the ResourceHandler?

Symfony 2 - How can I share data between controllers

I need to be able to make some request data from one controller available in another controller. I can make a service to set the data in one controller, but when the other controller fires and I get the service, a new instance of the service is created. Is there any way I can make this data static and share it between two controllers?
The same basic things you would do whenever you need information to be available in PHP from a new request:
Store it in the session. Symfony2 has a great session component for this. Ideal for fleeting data that needs to be saved only while the user is navigating
Store it in the database. Symfony2 supports Doctrine which makes this very easy. Ideal for permanent storage
Optionally:
Store it on the filesystem. Not recommended unless it's actually a file, but possible as well.
In the end, rather than using the session to store data, I created two separate routes to the same controller action. I added an optional argument in the controller action, with a default value only specified in one of the routes. I can then test for that argument's value when the controller runs. In the Twig template that calls this controller action, the path can be generated using either one of these routes, depending on a variable already available.
Bit of a work around, but problem solved!

Accessing workflowArguments in a hosted workflow

We are mixing workflows, a workflow using receive activity's more at the end. But at the start we want to pass in some arguments (not using a receive activity!)
Our workflows are already being created and resumed using a dynamic endpoint with IWorkflowCreation and a class derived from WorkflowHostingEndpoint. In the OnGetCreationContext the creationgContext is filled with WorkflowArguments and the workflow runs. At a later part the receive activity's are creating a bookmark which can be resumed with a message. All seems nice.
But in a xamlx there are no WorkflowArguments, i understand why, except that i want them anyway. I though about an activity in which i can write some code to get the Arguments myself, but i do need some help here.
Or is there another way to pass along the WorkflowArguments into a xamls without using Messaging?
You can't pass arguments into a starting workflow service except through the SOAP message that starts it. But there is nothing preventing you from reading any properties in your workflow service. So it is perfectly fine to do read settings or something similar instead of passing them in at startup.
We have solved this exact situation by creating another WCF service which sits alongside our xamlx service on a slightly different url (e.g. /WorkflowMetadata) and this is where we implement a service method that returns a dictionary of string, type.
In the implementation of this service we simply read the xamlx and determine the arguments.
This is what we use to interrogate a target workflow in an activity designer when creating something like a launch-workflow activity.
Creating an activity will not work as that activity will need an instance in order to run. All you want is some metadata about the xamlx service. And if you are using a WorkflowCreationEndpoint to construct a creation context then you are probably only allowing a dictionary of string, object as the start parameters. Therefore standard metadata will not work. This left us with the only option being to provide another service beside the workflow which serves metadata.
Background here: http://blog.petegoo.com/index.php/2011/09/02/building-an-enterprise-workflow-system-with-wf4/

Calling a web service using URL with complex parameters

I have web services that work fine using SOAP, but today I received a request to call the web services using the URL.
So, instead of consuming the service, they want to call http://servicename/ProductEnq.asmx/ProductEnqByCodeWithLogin?Code=123456789&Username=user&Password=bubbles
I found that the "basic" calls work 100%, i.e. when the params are all strings, like the call above. This method returns a complex type.
Where I get stuck is that I have another method that expects a List of strings as parameter together with some other params.
No matter how I try to get the list to be populated, the page always returns "System.InvalidOperationException: ProductEnqByMultipleCodesWithLogin Web Service method name is not valid."
Please note that this call works 100% when called from my application or WebService Studio.
Any hints on if this is possible, or should I just convince the client to use SOAP?
Thank you.
Jaco

Resources