How to replace uri in Symfony 2.1 before initialize controller - events

I want replace uri before started system.
I have routing collection:
/service-actions/{serviceId}/{actionPath}
Request: http://domain.com/service-actions/1/iframe
I want replace full uri:
http://s{serviceId}.domain.com/{actionPath}
http://s1.domain.com/iframe
I try:
Create a new event listener on kernel request, but in event not replace request.

Related

Forward request to another controller in spring

I want to forward request coming to controller /deeplink to /gateway.
Is there any way to do this using the response object like response.sendRedirect is there for redirects? I don't want to return "forward:/url" from my controller as that would require a lot of code change in our legacy codebase
Will forwarding call all the filters as well?

How to add client_IP to the response header in Kong apigateway

I'm trying to add "client_ip" in to a response header, but I can see the IP address is being printed on the kong apigateway logs but cannot forward it to a response header,
Sample log output:
,"method":"GET"},"client_ip":"49.36.22.209","tries":[{"balancer
I was trying following methods to try it out, but still response header is not printed the ip address.
- name: response-transformer
route: routeName
config:
add:
headers:
- X-Real-IP:${{client_ip}}
Can anyone help me to try enable this header on kong apigateway configs ?
Thanks.
You could use the plugin "serverless-functions"
In your case you would use the "post-function" running on service response at "header-phase".
With this plugin and post-function you can write custom logic with lua and modify the response.
With pre-function you could modify the request.
Kong have a PDK you can use globally.
Either if lb or not you would use
kong.client.get_ip() or kong.client.get_forwarded_ip()
Example Code
local client = kong.client
local response = kong.response
local function set_client_ip_header()
local client_ip = client.get_ip() -- or client.get_forwarded_ip()
response.set_header("X-Real-Ip", client_ip)
end
return set_client_ip_header -- return for memoization

Creating HTTP Handler

can anyone tell me how to create Custom Hander (.ashx) file.
Requirement: When a request come to my application for a .pdf, I want to invoke that .ashx handler. The .ashx handler will have logic to show the file or not.
My incoming path would be "http://www.domainname.com/Content/PDF/ABC.pdf".
This URL should be handled by a "http://www.domainname.com/Handler.ashx" file.
I would like to know how to create, map, and register the handler in my application
Thanks in advance.
Why you need an HTTPHandler if you are working with ASP.NET MVC, Use an Action method to server your file content. You can do most of the things you do with an HttpHandler in an Action method. You can do the routing of the action as you wish like http://domainname.com/content/abc can return the abc.pdf file
You should not directly let the browser to access the resource (PDF). Instead you give access via an action method. Read the file Id /name in the action method from the request and read the file and output it. Assuming that you have an action method like below in your ResourceController
public ActionResult GetFile(string id)
{
string fullFilePath=somefullpathvariable+"//"+id+".pdf";
return File(fullFilePath, "application/pdf", Server.UrlEncode(id+".pdf"));
}
Now users can access this like
http://www.yourdomain.com/Resource/awesomemvc
Now this can return a file called awesomemvc.pdf from a location which is stored in your server and your someFullPathVariable holds the path to that location

Apache CXF Webservice failing on AJAX call

We have developed a webservice based on Apache CXF.
This is working fine when accessed normally that is using APIGEE or by using a JaxWsProxyFactoryBean (A clinet for Apache CXF). But when I tried to access this by providing the SOAP Address through AJAX call it is giving me the following exception:
INFO: Interceptor has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: No such operation: (HTTP GET PATH_INFO: /tata-ws-1.0/TataWeb)
at org.apache.cxf.interceptor.URIMappingInterceptor.handleMessage(URIMappingInterceptor.java:77)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:89)
...
This is my AJAX call code happens on click of a button
<a onclick="sendRequest('GET','http://localhost:8080/tata-ws-1.0/services/TataWeb')"href="#">
Get Data:
function sendRequest(method, url)
{
method == 'POST';
{
http.open(method,url,true);
http.onreadystatechange = handleResponse;
http.send(null);
}
}
The URL for WSDL is correct because when i use
http://localhost:8080/tata-ws-1.0/services/TataWeb?wsdl it shows the WSDL for that webservice.
Please share your inputs.
Thanks.
Your need to send a SOAP request rather than a regular HTTP request.
Best way would be use something like this:
http://archive.plugins.jquery.com/project/jqSOAPClient

URL localization in Lenya

I am trying to localize Lenya publication URLs.
I store URL translation in the Document metadata and rewrite urls with URLRewriter transformator.
e.g. I build
/lenya/default/authoring/en/home
from
/lenya/default/authoring/index.html
But I can't find a simple way to force Lenya to tranlate incoming request URI back to the original path: /lenya/default/authoring/index.html
Really I want to process the request via pipelines using the original URL, not translated.
Is it possible at all? I had tried to add a servlet filter and use dispatcher, but filter can't access documents metadata because Environment object isn't in the processing stack yet at this stage...
(At this moment I see only one way - to update CocoonServlet and Cocoon classes)
Thanks!
I was able to do this via a RequestListener.
In the public void onRequestStart(Environment environment) method I create RequestWrapper with a new real URL and put it into objectModel. Also I change Environment context with a real URL: env.setContext("", realUrl, env.getContext())
This works fine!

Resources