Change Camel's basic /camel url - apache-camel

Issue:
I would need to change the basic /camel url which camel uses by default, but when i try to change it in application.yml nothing happens to it.
Would like to keep other systems intact without changing their urls, from what they already have (would require quiet a bit of work in back-end systems)
Current URL: http://localhost:8080/camel/hello
Desired URL: http://localhost:8080/service/hello
Checked links which are NOT working for me:
Link1
Link2
Link3
EG: application.yml
camel:
springboot:
name: CamelRestContext
component:
servlet:
mapping:
enabled: true
context-path: /service

So apparently this way works:
camel:
springboot:
name: RestDSLContext
servlet:
mapping:
context-path: /service/*
rest:
context-path: /service

Related

CloudFormation condition for choosing file from files section

I've got webserver template in CloudFormation. I want to use the same template for http and https.
Idea is that I'll use condition like:
Codition:
Https:
Fn::Equals: [Ref: 05HttpsUsed, Used]
and later I've got section files:
files:
full_path_apache/my_no_ssl.conf:
content: !Sub |
<proper_apache_config>
No SSL config... not important now
</proper_apache_config>
full_path_apache/my_ssl.conf:
content: !Sub |
<proper_apache_config>
SSL config... not important now
</proper_apache_config>
I'm trying to combine this. So depends if I choose to use or not https it will create a correct apache config file.
All this is inside Instace, Metadata, AWS::CloudFormation::Init: and configSets:
Edit:
I've tried also applied solution I used for Security Group:
!If [Https,
{CidrIp: 0.0.0.0/0,
IpProtocol: tcp,
FromPort: '443',
ToPort: '443'}, !Ref "AWS::NoValue"]
But still can't figure it out... Either rollback (timeout) or syntax...
You basically need Fn::If. Something like:
files:
full_path_apache/my.conf:
content: !If
- Https
- !Sub |
<proper_apache_config>
SSL config... not important now
</proper_apache_config>
- !Sub: |
<proper_apache_config>
No SSL config... not important now
</proper_apache_config>
I also think that it might be easier to create two AWS::CloudFormation::Init resources (one for HTTPS, one for non-HTTPS) instead.

Zuul url parameters to Solr Query parameters

I am trying to rewrite request with zuul and forward them to an old solr server.
My application.yml looks like this:
zuul:
prefix: /api/v1
routes:
peoples:
path: path: /peoples/**
url: http://solr/api/select?
So far the /people route is working fine, i get the incoming request, pass the correct parameters to the request via a Zuulfilter and forward to solr. The redirected request looks:
http://sorl/api/select?q=*&wt=json&indent=true&collection=MyCollection&fl=Filter1,Filter2,Filter3,Filter4&rows=10
I don't understand how i can define a new route like : peoples/{id}.
I need to pass the {id} route to another ZuulFilter and append it to com.netflix.zuul.context.RequestContext.getCurrentContext().setRequestQueryParams()
Am i missing something in Zuul or is it just no possible to get a param from the requestcontext, and transform it to a query param ?

Parsing application.yml in angularjs

I have a application.yml file in my application
spring:
profiles:
active: default,dev
app:
properties:
lucene:
indexInfoFile: ${spring.jpa.properties.hibernate.search.default.indexBase}/index.properties
reindex: false
storage:
home: ${user.home}/xxx
basePath: ${app.properties.storage.home}/uploads/
staticFilesPrefix: /files/
appUrl: /app/
spring:
profiles: dev
http:
multipart:
max-file-size: 3MB
max-request-Size: 3MB
Now in my controller, I am trying to get the data from yml file and the code for the same is
$http.get('/resources/application.yml').then(function (response) {
console.log('entire data is ', response.data);
console.log('basePath is ', response.data.basePath);
});
Entire Data is printing perfectly ( the whole yml file is getting printed) but when ever I am trying to print a particular property like basePath, max-file-size etc I am getting "undefined error".
My question is how to get a particular property to be printed on the console.
I would not recommend to access the yml file directly in Angular.
The format is difficult to parse (hence your question) and you sooner or later you may not want to expose all your confguration details.
Instead create a rest controller in spring mapped to something like /config
Let spring inject all the configuration values you need using #Value and return a Map or a simple PoJo with exactly the attributes you need.
Spring will convert this to JSON which you can easily be consumed in Angular.

Symfony2: allow all unmatched routes to be accessed anonymously

I have Symfony2 application separated into 2 bundles: BackendBundle for API and FrontendBundle for AngularJS "client". Everything works under firewall.
BackendBundle has entities, handles API routes; FrontendBundle has Angular views, routing etc. and has only one controller with wildcard:
class AngularController extends Controller {
/**
* #Route("/{route}", name="angular_index_all_unmatched_routes", requirements={"route" = ".*"})
* #Template("FrontendBundle::index.html.twig")
*/
public function angularIndexAction($route) {
return ['route' => $route];
}
}
FrontendBundle routing is defined as last resource in app/config/routing.yml, to be invoked only if any other route was not matched. Thanks to that, it can handle Angular HTML5-mode routes if they're accessed directly (for example copy-paste) - and it works ok.
What I want to do, is define firewall and/or access control in way that all those unmatched routes (handled by AngularController::angularIndexAction()) could be accessible by anonymous user.
Why? I want to open some API routes (via frontend proxy) to be accessible by non-users (for example confirmation URLs sent by email, with some message to user).
I don't want to hardcode access control list for every anonymous "Angular" route, I would like to do it only for API routes. At the end, those unmatched routes should open Angular's index which should know if user is logged in (for displaying full or simplified layout) and should handle Angular routes and display some kind of "Access denied" message if request failed (there is Symfony listener and Angular's $provide interceptor for that).
Any suggestions?
Edit: #Security annotation on AngularController::angularIndexAction() does not work, it still redirects to firewall entry point.
Edit2: Here is fragment of security.yml
firewalls:
unsecured:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
anonymous: true
secured:
pattern: '^.*$'
form_login:
login_path: /our-provider/login
check_path: /our-provider/callback/
anonymous: true
entry_point: our_provider.entry_point
access_control:
- { path: '^/our-provider/(login(/[a-zA-Z]+)?|logout|redirect|callback)', roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: '^/', roles: ROLE_USER }
I know that { path: '^/', roles: ROLE_USER } will redirect all routes to login page if user is not logged in. I assumed it's obvious and did not mentioned it. What I want is force ROLE_USER for matched routes and let IS_AUTHENTICATED_ANONYMOUSLY for those unmatched, without explicitely defining each frontend "proxy-route". In my case there is not 404 Symfony page, because everything goes to angular_index_all_unmatched_routes route and there Angular routing definition decides if there is something to handle or not.
I haven't tried this, and I cannot begin to guess your existing security/route setup in security.yml but I guess you could whitelist the method with IS_AUTHENTICATED_ANONYMOUSLY. From the Symfony docs:
All users (even anonymous ones) have this - this is useful when whitelisting URLs to guarantee access - some details are in How Does the Security access_control Work?.
So, for example, if you were using the #Security annotation you could do something like (not tested):
class AngularController extends Controller {
/**
* #Route("/{route}", name="route", requirements={"route" = ".*"})
* #Template("FrontendBundle::index.html.twig")
* #Security("has_role('IS_AUTHENTICATED_ANONYMOUSLY')")
*/
public function angularIndexAction($route) {
return ['route' => $route];
}
}
More on the #Security annotation here.
Hope this helps :)
Edit
All that said, when you define/restrict your routes under access_control in security.yml, the matching process stops on the first match. I assume that you have some role-restricted paths, which you should define explicitly - and put them first, so if they match the process stops.
Otherwise, you should be able to add a catch-all route, enforced by role IS_AUTHENTICATED_ANONYMOUSLY. Since the path definition of a route is a regex, something like ^/ should catch anything that is not explicitly defined. Just make sure and place it after your restricted route definitions.
You would not need for the #Security annotation in this case.
Edit 2
I tried mocking this out using a clean instance and HTTP BasicAuth but what I was trying to achieve was the following, which I understand as similar to your use case:
Create a backend controller with routes / and /api/ and trigger a HTTP BasicAuth authentication popup
Create a frontend controller with route /{route} that would match everything else and authenticate anonymously.
My firewall and access_control configuration looks like this:
security:
encoders:
# encoder config here
providers:
# provider config here
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
secured:
anonymous: ~
http_basic: ~
access_control:
- { path: ^/$, roles: ROLE_USER }
- { path: ^/api/, roles: ROLE_USER }
- { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
Access control paths are regexes, so ^/$ and ^/ are not the same. The former will only match exactly to route /. The latter will match any route that begins with /; e.g: /home, /products, /contact etc.
Indeed, the latter will match and anonymously authenticate /api, but it will not match /api/, or /api/1 etc. as these are explicitly defined and restricted to ROLE_USER.
So the general idea is to explicitly and (if possible) exactly match the routes you want to restrict, and declare those first. The last declaration ^/ should openly catch any other route that falls through.

How to understand chats.html v.s ('/getchats', ChatsRequestHandler)]

I try to understand the different between:
The class ChatsRequestHandler generate a template with the name chats.html
template = self.generate('chats.html', template_values)
In the application view its is named getchats:
application = webapp.WSGIApplication(
[('/', MainRequestHandler),
('/getchats', ChatsRequestHandler)],
The same occurs to me at edit_user.html v.s ('/edituser', EditUserProfileHandler)
How is it that the application knows that the getchats is connected to the chats.html aldo they have not the same name? I would expect that it should be the same name chats.html and ('/chats', ChatsRequestHandler).
The flow of your request goes something like this.
App Engine looks up your app.yaml file. It should contain an entry that says /getchats should be handled by application in somefile.py.
It then goes to this "application view" and matches it to a Webapp Route. In this case, that route is ('/getchats', ChatsRequestHandler).
Then it calls get or post on ChatRequestHandler, passing it the request and response objects.
The output of that is sent back to the user's browser.
You are free to implement ChatRequestHandler as you'd like. In this case you're doing so by reading in a template named chats.html, populating it with some values, and then outputting it.
So the application knows that getchats is connected to ChatRequestHandler. The name of chats.html is pretty arbitrary - the ChatReqeustHandler has to know it, but that is all. You could rename it.
Thanks for helping me:
The example a came up with comes from codenvy.com as a examples app.
1 App Engine looks up your app.yaml file. It should contain an entry that says /getchats should be handled by application in somefile.py.
Here is the app.yaml file of this application
application: 3kus-apps
version: 1
runtime: python
api_version: 1
handlers:
- url: /css
static_dir: css
- url: /js
static_dir: js
- url: /.*
script: devchat.py
So as you can see it contain's no entry that says /getchats should be handled by application in somefile.py.
What i found there is a util.js file witch has a function updateChat(). function updateChat() {downloadUrl(getRandomUrl("/getchats"), "GET", null, onChatsReturned);}.
However, I would like to know - under (1) how this should be handled by a somefile.py.

Resources