I'm trying to create a route where the endpoint depents on the incoming message. The aim is to write into a mongodb in different databases and collection.
I'm looking for an easy way to get the information from the message header and write it in to the <to uri=""/>
<route>
<from uri="jms:topic:BUS_IN" />
<to uri="mongodb:myDb?database=${header.someValue}&collection=storyTeaser&operation=save" />
</route>
Thanks a lot
You could add a second route that sets the header variables:
<route>
<from uri="jms:topic:BUS_IN" />
<camel:setHeader headerName="CamelMongoDbDatabase">
<camel:simple>testmydb</camel:simple>
</camel:setHeader>
<camel:setHeader headerName="CamelMongoDbCollection">
<camel:simple>mycollection</camel:simple>
</camel:setHeader>
<to uri="jms:queue:mongodb.out"/>
</route>
And then add the parameter "dynamicity" in the uri of your first route:
<route>
<from uri="jms:queue:mongodb.out" />
<to uri="mongodb:myDb?database=new_test&collection=old&dynamicity=true&operation=save"/>
</route>
Using Apache Camels toD function https://camel.apache.org/message-endpoint.html will allow you to dynamically set the URI as messages are passed through. The URI allows for simple language https://camel.apache.org/simple.html where we can for instance use the filename to generate a collection.
Heres an example Route:
from(input).routeId("SampleRoute")
.toD("mongodb3://mongoBean?database=myDB&collection=${file:onlyname.noext}&" +
"operation=insert&createCollection=true")
Related
I am redoing some paths in my app and therefore need to preserve the old ones with Redirect.I want to change these routes:
previous path /bar to now redirect to /foo/bar.
previous path /bar/fizz to now redirect to /foo/bar/fizz.
Here's what I think should work based on the path syntax docs (https://github.com/ReactTraining/react-router/blob/master/docs/guides/RouteMatching.md#path-syntax):
<Route path="/" component={...}>
<Route path="foo" component={...}>
<Route path="bar" component={...}>
<Route path="fizz" component={...}/>
</Route>
</Route>
<Redirect from="bar(/*)" to="foo/bar(/*)"/>
</Route>
<Redirect path="*" to="/"/>
However this makes only the first desired redirect work, from /bar to /foo/bar. Trying to go to /bar/fizz redirects me to just the root /.
If I change the Redirect to <Redirect from="bar/*" to="foo/bar/*"/> then the opposite is true; only the second desired redirect works, from /bar/fizz to /foo/bar/fizz. Trying to go to /bar redirects me to just the root /.
The only way I've gotten it to work is to include two Redirects to cover both scenarios. Is there a more concise way to write this with just one Redirect?:
<Route path="/" component={...}>
<Route path="foo" component={...}>
<Route path="bar" component={...}>
<Route path="fizz" component={...}/>
</Route>
</Route>
<Redirect from="bar" to="foo/bar"/>
<Redirect from="bar/*" to="foo/bar/*"/>
</Route>
<Redirect path="*" to="/"/>
Hi I’m having problem understand why I get different response when I use the (org.xacmlinfo.xacml.pep.agent.PEPAgent.java) and the tryit function in WSO2IS 5.0.0. They are querying the same policy.
<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="OfficeHours" RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:permit-overrides" Version="1.0">
<Description>denyOutsideOfficeHours</Description>
<Target>
<AnyOf>
<AllOf>
<Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">foo.com</AttributeValue>
<AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:environment:environment-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"></AttributeDesignator>
</Match>
</AllOf>
</AnyOf>
</Target>
<Rule Effect="Permit" RuleId="PermitInOfficeHours">
<Condition>
<Apply FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">12:00:00</AttributeValue>
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">17:00:00</AttributeValue>
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
<AttributeDesignator MustBePresent="false" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment" AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time" DataType="http://www.w3.org/2001/XMLSchema#time"></AttributeDesignator>
</Apply>
</Apply>
</Condition>
</Rule>
</Policy>
PEPAgent
<Request xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" CombinedDecision="false" ReturnPolicyIdList="false">
<Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment">
<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:environment:environment-id" IncludeInResult="false"><AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">foo.com</AttributeValue>
</Attribute>
</Attributes>
</Request>
<Response xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17">
<Result>
<Decision>Indeterminate</Decision><Status>
<StatusCode Value="urn:oasis:names:tc:xacml:1.0:status:processing-error"/>
<StatusMessage>urn:oasis:names:tc:xacml:1.0:function:time-one-and-only expects a bag that contains a single element, got a bag with 0 elements</StatusMessage>
</Status>
</Result>
</Response>
Tryit
<Request xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" CombinedDecision="false" ReturnPolicyIdList="false">
<Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment">
<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:environment:environment-id" IncludeInResult="false">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">foo.com</AttributeValue>
</Attribute></Attributes></Request>
<Response xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17">
<Result><Decision>Permit</Decision><Status>
<StatusCode Value="urn:oasis:names:tc:xacml:1.0:status:ok"/>
</Status><PolicyIdentifierList>
<PolicyIdReference>OfficeHours</PolicyIdReference>
</PolicyIdentifierList>
</Result>
</Response>
First of all here are a few comments regarding your policy and rule:
the policy description doesn't match the rule description. In one case you say deny, in the other you say Permit.
you use a Condition where in fact a Target would be enough.
Now, as for the different responses: in one case your code (PEPAgent) doesn't send the current time value and the server (is that the PDP?) doesn't add the time either. In the second case, the Tryit client still doesn't send time but obviously the receiving end (another PDP?) fills in the missing time value.
If you look more closely at your first response, you will notice the following error message:
<StatusMessage>urn:oasis:names:tc:xacml:1.0:function:time-one-and-only expects a bag that contains a single element, got a bag with 0 elements</StatusMessage>
This means that you didn't pass in any value for current-time.
I tested this using the Axiomatics Policy Server and I received the expected behavior.
An example URI for my rest service is as follows:
http://xx.xx.xxx.xx:8080/myservice/service/encode?encrypt=true&payload=11/11/2013%207:59:15%20AM&ttl=10h
The service route I am using on the node with my service on it is as follows. This works fine. The route should bridge whatever we give it through to the service.
<route id="my-server">
<from uri="fabric-camel:myClusterId:jetty:http://xx.xx.xxx.xx:8484/myservice/service?matchOnUriPrefix=true" />
<to uri="jetty:http://xx.xx.xxx.xx:8080/myservice/service?bridgeEndpoint=true&throwExceptionOnFailure=false" />
</route>
My trouble is with the client route. The time component is working fine but my efforts to append anything to the GET have failed. If I can figure out how to do this I can create any number of client examples.
<route id="fabric-client" errorHandlerRef="errorHandler">
<from uri="timer://foo?fixedRate=true&period=1000"/>
<to uri="fabric-camel:myClusterId"/>
</route>
Can someone give me a leg up by converting the URI example above to Sprint DSL? I am hoping you can show me how to do it. From that I can figure out how to pass in variables.
Here is the answer to my syntax question.
<route id="fabric-client" errorHandlerRef="errorHandler">
<from uri="timer://foo?fixedRate=true&period=1000"/>
<setHeader headerName="CamelHttpPath">
<simple>/encode?encrypt=true&payload=11/11/2013%207:59:15%20AM&ttl=10h</simple>
</setHeader>
<to uri="fabric-camel:myClusterId"/>
<log message=">>> ${body}"/>
</route>
This post was the key. http://camel.465427.n5.nabble.com/Setting-url-params-in-REST-call-with-Camel-td2257861.html Took a lot of Googling.
This reference might help other people it helped me; especially the side by side Java and Spring DSL.
http://people.apache.org/~dkulp/camel/http.html I actually can't remember how I figured out how to map Exchange.HTTP_PATH to CamelHttpPath. I think I had to guess - getting late.
I have 2 child wsse:Security in soap:Header and trying to delete one. I tried to do this with Enrich Mediator, but instead of replace soap:Header it deletes. Here is simple example that reproduces it:
<inSequence>
<enrich>
<source type="inline" clone="true">
<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<foo/>
</soapenv:Header>
</source>
<target xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xpath="//soapenv:Header"/>
</enrich>
<log level="full"/>
</inSequence>
Log mediator logs message without Header. If I add to target action="child", everything work just as expected. So i have 2 questions:
1. Why enrich mediator act like that?
2. How can i change header with other way?
You should use header mediator to change SOAP Headers
Have a look there : https://docs.wso2.com/display/ESB481/Header+Mediator
Sample to add a custom header :
<header xmlns:myns="http://com/header" name="myns:MyHeader" value="0"/>
Sample to remove it :
<header xmlns:myns="http://com/header" name="myns:MyHeader" action="remove"/>
You can use this mediator to change http headers : just add a scope attribute with a value equals to 'transport'
I have a problem with the activemq *aggregator*, would be very thankfull if someone would help me out somehow. Marshaling into a xml.
So i have my route configured like this:
<route id="myRoute">
<from uri="timer:someScheduler?period=5000" />
<bean ref="someBean" method="someMethod" />
<marshal>
<jaxb contextPath="some package" />
</marshal>
<split streaming="true">
<tokenize token="#id" group="1000" />
<to uri="activemq:topic:some_topic" />
</split>
</route>
This works and it splits my xml messages composed by 1k rows, tho dunno how to configure the aggregator in order to put together all the messages before proceding with their processing.
This is it(doesn't work):
<route id="myRoute">
<from uri="activemq:topic:some_Topic" />
<aggregate completionSize="5">
<correlationExpression>
<constant>true</constant>
</correlationExpression>
<to uri="mock:aggregated"/>
</aggregate>
<unmarshal>
<jaxb contextPath="some_package" />
</unmarshal>
<bean ref="someBean" method="someMethod" />
</route>
Thanks in advance!
What you need to do is to provide the aggregator with an implementation of an AggregationStrategy - this is a class that tells the pattern how to assemble two objects that match the correllationExpression. See Camel Aggregator for an example as to how to do this.