How to add tomcat virtual hosts instances programatically - spring

I was working for the last 2 years on building a social network for companies using Grails.
A new requirement appeared which is creating separate virtual host for each company that will have it's own database of users, timelines, etc (I would like to avoid rewriting all the service layer)
So initially the application was running on http://www.my-social-network.com for example
Now using an admin console that we will have to develop, companies should be able to create their own subdomain like this : http://company1.my-social-network.com and so on.
The web server that we are using is Apache 2.2 + tomcat 6
Is there someone who has an idea about how to do it?
Ideally I want to have one instance of the application that receives requests with different host names so it can behave differently in order to save resources because Grails consumes too much memory.
For example :
subdomain1.my-social-network.com --> apache 2 --> my-social-network.com (+ specific headers) --> tomcat
If such thing was possible, is there a way to select a datasource depending on a request parameter or header?
Any help is appreciated

There are a number of different options you can take, but first you need to make a decision on how you are going to implement this at the lowest level:
You can take the requests to subdomain1.my-social-network.com and redirect the user to my-social-network.com.
Same as above but use HTTP 302, HTTP 303 or HTTP 307 instead.
Simply show the contents of the site, responding with HTTP 200 (probably the best approach as these domains are meant to be permanent). Further text assumes this option.
Next, you need to have a servlet filter which intercepts all HTTP traffic and has a map {virtual_path -> real_site}. This filter can simply set relevant request attribute (hint: servletRequest.setAttribute(String, Object)) when it detects that requested virtual path is recognized.
If a user creates/renames/deletes a domain/virtual path, you would populate the map accordingly.
Finally, your render component should check that parameter and render relevant site. It is really hard to elaborate further without knowing more details on how your application works.

Related

How to poll the quality gate execution status?

I would like to poll the quality gate execution status of my SonarQube 6.3 instance using a REST api call. I went through a few api calls, which did not give me the expected results.
I tried to use these urls:
http://localhost:9000/api/resources
http://localhost:9000/api/components
But I always got this response:
{"errors":[{"msg":"Unknown url : /api/resources"}]}
How can I poll the quality gate execution status via REST?
http://localhost:9000/web_api lists the web service endpoints available on your server and provides documentation for each one. In my copy of 6.3, the documentation for "api/resources" says
Removed since 6.3, please use api/components and api/measures instead
You say you've tried http://localhost:9000/api/components and gotten an error. That's because there's not actually a web service there. You'll have to add the qualifier for the service you want, such as /api/components/search, as described in the docs for that set of services: http://localhost:9000/web_api/api/components
In fact there are 5 parts in a correct SonarQube web api url. They can be seen like that domain/api/controller/action?parameters, for example http://localhost:9000/api/components/show?componentKey=blue.
So we have:
domain: which is represented by http://localhost:9000 in the example, it is the address where you can call your SonarQube server
api: which is represented by /api in the example, it is the base path of all web service in SonarQube
controller: which is represented by /components in the example, it represents a pool of web service concerning a given theme (issues, profiles, components, etc.)
action: which is represented by /show in the example, it is a unit action that you can perform through the web service, for example: show, search, list, backup, delete, etc.
parameters: which is represented by ?componentKey=bluein the example, they are not always mandatory but often allow you to specify further information to get more precise results
What you have forgotten here is at means to specify an action.
http://localhost:9000/api/project_analyses/search?project=myProjectname&category=QUALITY_GATE
This query returned the status of my quality gate. Here I have mentioned the project name as myProjectname

4GL and Magento SOAP API. Need a simple example

My company runs a 4GL application internally. It's very old and no one really knows how to improve/develop for it since the developers are long gone.
I need to make a simple SOAP call to my Magento web store. There are tons of examples online in a multitude of languages, but I can't find a single 4GL (OpenEdege ABL) example.
I'm trying to set SKU's to Out of stock status.
Does anyone have a simple example that I can look at, or at least a starting point since there seems to be so little information on 4GL on the web.
Example of the call I need in PHP:
<?php
$proxy = new SoapClient('http://www.domain.com/api/soap/?wsdl');
$sessionId = $proxy->login('admin', 'password');
$proxy->call($sessionId, 'product_stock.update', array('sku123', array('qty'=>50, 'is_in_stock'=>1)));
For version 10.2B there's built in support for consuming web services in Progress ABL.
This is a basic tutorial of how to create a client for a SOAP-based web service in ABL. It's not best practices or in any way complete. Just a quick guide to get started.
1. Analyse the WSDL
There's a built in tool available via command line that lets you analyse a WSDL and create documentation about available services, datatypes, syntax etc. Invoke it on your wsdl like this:
proenv> bprowsdldoc yourwsdl-file c:\temp\docs
The wsdl can be local or remote. If its remote you specify the URL, if it's local you can specify just the local complete path. Documentation in html format will end up in c:\temp\docs. Open up index.html in that folder.
2. Create a basic client
In the index.html document there's a number of headings. Click the link under "Port types". In the Port Type document you will find some useful data.
Copy-and-paste the example in "Connection Details" into your Progress Editor. It should look something like this (names of services and procedures will be different - they are defined in the wsdl):
DEFINE VARIABLE hWebService AS HANDLE NO-UNDO.
DEFINE VARIABLE hYYY AS HANDLE NO-UNDO.
CREATE SERVER hWebService.
hWebService:CONNECT("-WSDL 'file_or_url_to_wsdl.wsdl'").
RUN XXX SET hYYY ON hWebService.
If you run this code your client is connected to the web service but it's still not doing anything.
Further down the same document there's a heading called "Operation (internal procedure) details". This is where the actual web service is invoked. It will look something like the code below. It actually show two ways of making the same call, one functional call and one procedural so choose whatever you prefer and insert it into your editor (I'm usually using the procedural for no real reason other than old habits):
DEFINE VARIABLE strXMLRequest AS CHARACTER NO-UNDO.
DEFINE VARIABLE ProcessXMLResult AS CHARACTER NO-UNDO.
FUNCTION ProcessXML RETURNS CHARACTER
(INPUT strXMLRequest AS CHARACTER)
IN hYYY.
/* Function invocation of ProcessXML operation. */
ProcessXMLResult = ProcessXML(strXMLRequest).
/* Procedure invocation of ProcessXML operation. */
RUN ProcessXML IN hYYY (INPUT strXMLRequest, OUTPUT ProcessXMLResult).
Now all you need to end your program is disconnecting and cleaning up. So insert:
hWebService:DISCONNECT().
DELETE OBJECT hWebService.
If you've followed all steps you should have a skeleton for invoking a web service. The only problem is that you need to handle the in- and out-data.
3. Handle the answer and the request
Depending on how the web service is built this can be easy (if you only input and output simple data like strings and numbers) or quite complicated (if you input and output entire xml-documents). The documentation you created in step one lists all datatypes (in the index.html document) but it doesn't offer any support in how you create any needed xml documents. There's specific Progress documentation available on how to work with xml...
The better approach is to take a look at the official documentation. There you will find everything above and more - how to handle errors etc.
Here is an overview of all 10.2B documentation and here is the PDF named Web Services.
Here is a link to a complete (but actually not so good) example in the Progress KnowledgeBase where a client and corresponding request/response xml is created and handled.
Look at these chapters:
6 - Creating an ABL Client from WSDL
7 - Connecting to Web Services from ABL
8 - Invoking Web Service Operations from ABL
That will basically take you through the entire process from start to beginning.

ProtocolViolationException Load testing web service (GET action with content-body)

I created an ASP.NET MVC4 Web API service (REST) with a single GET action. The action currently needs 11 input values, so rather than passing all of those values in the URL, I opted to encapsulate those values into a single class type and have it passed as Content-Body. When I test in Fiddler, I specify the verb as GET, and enter the JSON text in the "Request Body" input box. This works great!
The problem is when I attempt to perform Load Testing in Visual Studio 2010 Ultimate. I am able to specify the GET action and the JSON Content-Body just fine. But when I run the Load test, VS reports exceptions of type ProtocolViolationException (Cannot send a content-body with this verb-type) in the test results. The test executes in 1ms so I suspect the exceptions are causing the test to immediately abort. What can I do to avoid those exceptions? I'd prefer to not change my API to use URL arguments just to work-around the test tooling. If I should change the API for other reasons, let me know. Thanks!
I found it easier to put this answer rather than carry on the discussions.
Sending content with GET is not defined in RFC 2616 yet it has not been prohibited. So as far as the spec is concerned we are in a territory that we have to make our judgement.
GET is canonically used to get a resource. So you are retrieving this resource using this verb with the parameters you are sending. Since GET is both safe and idempotent, it is ideal for caching. Caching usually takes place based on the resource URI - and sometimes based on various headers. The point is cache implementations - AFAIK - would not use the GET content (and to be honest I have not seen any GET with content in real world). And it would not make sense to include the content in the key generation since it reduces the scalability of the caches.
If you have parameters to send, they must be in the URI since this is part of what defines that URI. As such, I strongly believe sending content with GET is wrong.
Even when you look at implementations such as OData, they put the criteria in the URI. I cannot imagine your (or any) applications requirements is beyond OData query requirements.

mod_rewrite and server environment variables

The setup I have is as follows:
I have one Apache server acting as a URL rewriting engine (SERVER1).
I have a second server (Apache too) which runs a web application (SERVER2). First tries to authenticate users. Part of the authentication protocol involves a lot of redirection between that application server and the authentication server.
My problem is that once the authencation is successfull, the authentication server needs to redirect the user back to the application server, which is only visible from SERVER1. Effectively, SERVER2 needs to be able to reconstruct a URL based on SERVER1's parameters.
Most of the environement variable are helpful i.e. I know the host name, script name, page called etcc but I can 't figure out wether the call was made through HTTP or HTTPS: that information is wiped in the rewrite process by SERVER1...
Anybody knows if/how I can get that information through environement variables? I am limited in that I can't use query string parameters...
Thanks all !
This may sound strange, but I have found part of the answer to my question.
The rewrite engine (at least in Apache 2, I haven't looked anywhere else) allows for writting extra request header.
The rule should look something like that.
RewriteRule .* -
[E=INFO_PATH_INFO:%{PATH_INFO},NE]
Put simple, it creates a new header called INFO_PATH_INFO and sets the value to PATH_INFO.
( For more info check out http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html )
Then it can be retrieved in any languages.
For info I am using Oracle's OWA which adds an extra layer of complication due to the fact that the default environment variables are limited to a few and additional variables need to be specified in thr dads.conf
Hope this will help anyone !

How to setup suffix proxy server

Can anyone guide me for setting up suffix proxy server , so that user can access some specific sites cached in our campus server without doing any configuration in their browsers.
by suffix proxy i mean that if user wants to open http: //en.wikipedia.org/wiki/Proxy_server page then he should enter link:
http ://en.wikipedia.org.CAMPUSPROXY.NET/wiki/Proxy_server (where campusproxy.net is our proxy server) and this requested page can be retrived from our proxy server in place of wikipedia.org
It's a redirect really - your server needs to have a url check that will catch the prefix portion of the url and for this you obviously need unlimited prefix's available from the registered domain URI then it just reforms the uri of the prefix makes the request for the page and then presents it as content to the user - normally you'll also inject a banner at the top of the page also.
so it goes
User - http-get en.wikipedia.org.CAMPUSPROXY.NET/wiki/Proxy_server
your server takes this and creates "en.wikipedia.org/wiki/Proxy_server" via a script or what have you.
CAMPUSPROXY.NET http-get en.wikipedia.org/wiki/Proxy_server
inject the banner code into the webpage via a script or what have you.
probably also modify the html tags and headers to include your prefix proxy info
some knowledge of python - perl or whatever is all you need together with apache or similar server, their are of course scripts out there already but if you do that you'll learn nothing.

Resources