Unable to read HTTP headers in an API resource - api

I am trying to read HTTP header from inside an API that I defined in the ESB. I have tried various methods (see below) all of them print out "null" in the logs.
<log level="custom">
<property name="LOG-POSITION___________________________" value="...4"/>
<property name="AXIS2___________________________" expression="$axis2:accept"/>
<property name="AXIS2___________________________" expression="$axis2:Accept"/>
<property name="AXIS2___________________________" expression="$axis2:ACCEPT"/>
<property name="CTX___________________________" expression="$ctx:accept"/>
<property name="CTX___________________________" expression="$ctx:Accept"/>
<property name="CTX___________________________" expression="$ctx:ACCEPT"/>
<property name="TRP___________________________" expression="$trp:accept"/>
<property name="TRP___________________________" expression="$trp:Accept"/>
<property name="TRP___________________________" expression="$trp:ACCEPT"/>
</log>
I can't see why it is not working.

Here is the synapse code to read and log the content-type http header. Here $trp stands for the transport header.
<log level="custom">
<property name="Content_Type" expression="$trp:Content-Type"/>
</log>
Ref: https://docs.wso2.com/display/ESB500/Synapse+XPath+Variables
If it doesn't work, enable wire logs and post the logs in the question.

I have found an answer to this by looking through existing code, and doing a bit of trial and error.
The expression "$trp:Accept" works, but it must be used before using either a call or send mediator.
For any others experiencing this issue, move the property mediator for grabbing this to the beginning of your proxy or api and the values should come through.

Related

WSO2 ESB - how to dynamically set value to WSDL Endpoint URI using Property Meditor

I have an endpoint (WSDL) with following settings:
<endpoint>
<wsdl port="portName"
service="serviceName"
uri="http://example.com/services/service1.wsdl"/>
</endpoint>
And I have a separate xml file containing my settings for those 3 attributes: uri, service, and port. I can get their value from the xml.
<property expression="get-property('registry','gov:trunk/services/Config.xml')"
name="gc" scope="default" type="OM"/>
<log level="custom">
<property expression="$ctx:gc//wsdl//uri" name="uri"/>
<property expression="$ctx:gc//wsdl//service" name="service"/>
<property expression="$ctx:gc//wsdl//port" name="port"/>
</log>
Now, my question is: how do I set those 3 values dynamically to my endpoint?
I only need this endpoint once, and there is no need to create template for this purpose, but I can't find any resource to help me do that.
Can anyone share some knowledge and experience?
Thanks

WSO2 API Manager 1.10 issue

We are running into an issue where a call to a WSO2 API REST endpoint fails with a "412 Precondition Failed" when the Content-Length exceeds 1068. Just adding a space to the request (increasing size to 1069) causes this failure. This issue can also happen when content length is less than 1069, if the API is called fast enough (using SOAPUI for testing). We have a theory that the header and body are split between packets and confuses the request. We tried turning off chunking and that didn't affect things. When the back end REST service is called directly it works fine.
You can turn off the chunking as below by using the property mediator if you are calling the SOAP endpoint. But you have to make sure that the SOAP endpoint is also expecting a non-chunked request.
<property name=”DISABLE_CHUNKING” value=”true” scope=”axis2″/>
But if you are using REST endpoint above property may not work sometimes. In that kind of situation, we need to make sure the Content-Length header is appended to the request. We can use below two properties to append the Content-Length header.
<property name="FORCE_HTTP_CONTENT_LENGTH" value="true" scope="axis2"></property>
<property name="COPY_CONTENT_LENGTH_FROM_INCOMING" value="true" scope="axis2"></property>
Sample proxy inSequence
<inSequence>
<log level="custom">
<property name="msg" value="Executing IN sequence"></property>
</log>
<property name="FORCE_HTTP_CONTENT_LENGTH" value="true" scope="axis2"></property>
<property name="COPY_CONTENT_LENGTH_FROM_INCOMING" value="true" scope="axis2"></property>
<send>
<endpoint>
<address uri="https://www.google.com" format="rest"></address>
</endpoint>
</send>
</inSequence>

Apache cxf using XSLTJaxbProvider as a JAXRSDataBinding

(apologies for broken links at stackoverflow limits new users to 2 in one post!)
I've scaffolded a web service server using Spring STS and MyEclipse for spring and was interested in transforming the out going soap message.
First thing I wanted to transform was the namespace prefixing so my spring config looked like this
<jaxws:endpoint xmlns:tns="ttps://etc etc">
<jaxws:dataBinding>
<ref bean="data-binding"/>
</jaxws:dataBinding>
</jaxws:endpoint>
<bean ref="data-binding" class="org.apache.cxf.jaxb.JAXBDataBinding">
<property name="namespaceMap">
<map>
<entry>
<key>
<value>ttp://thing</value>
</key>
<value>BeepBeep</value>
</entry>
</map>
</property>
</bean>
this worked fine and my soap message was outputted completely and correctly.
<as>
<b>
<stuff/>
</b>
<c>
<more stuff/>
</c>
</as>
Second I need to change the soap xml but more than the transform features at http://cxf.apache.org/docs/transformationfeature.html allowed
so I read up about the XSLTJaxbProvider at http://cxf.apache.org/docs/jax-rs-advanced-xml.html and plugging in a rs provider to a ws binding at ttp://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-CXFDataBindingsasJAXRSproviders to create the following config
<jaxws:endpoint xmlns:tns="ttps://etc etc">
<jaxws:dataBinding>
<ref bean="jaxrs-data-binding"/>
</jaxws:dataBinding>
<bean id="jaxrs-data-binding" class="org.apache.cxf.jaxrs.provider.JAXRSDataBinding">
<property name="namespaceMap">
<map>
<entry>
<key>
<value>ttp://thing</value>
</key>
<value>BeepBeep</value>
</entry>
</map>
</property>
<property name="provider" ref="xsltProvider"/>
<bean id="xsltProvider" class="org.apache.cxf.jaxrs.provider.XSLTJaxbProvider">
<property name="outTemplate" value="classpath:/WEB-INF/templates/transform.xsl"/>
</bean>
now I get an JAXB Exception: Class not known to this context for classes b and c and even if I have an empty xslt stylesheet I get the xml
<as/>
I have tinkered with the config to every end and added #XmlSeeAlso all over the place to no avail.
I guess I have to ask is what I've done possible in config? The fact that it all works as expected before I try and wire in the rs provider as a ws databinding might mean it's not?
Any advice greatly appreciated. Maybe there is a better way to use xslt/manipulate the xml?
Thanks

How to consume message from the endpoint in Apache Camel?

I had created a message with a topic name and set some information with key/value pair and sent the message to the MessageBus (i.e, produced the message to an endPoint - in my case endpoint is a messageBus).
How can consume the message from that endPoint? I know the uri, endpoint. what configurations needs to be done for my consumer ( any camel XML changes to done ?).
Please help.
see the camel-jms page for details, but you basically need to do some basic Spring XML to configure the ActiveMQ connection and then establish your route...
from("activemq:queue:inboundQueue").bean(MyConsumerBean.class);
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false&broker.useJmx=false"/>
</bean>
</property>
</bean>
see these unit test for more information...
https://svn.apache.org/repos/asf/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteTest.java
https://svn.apache.org/repos/asf/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsRouteUsingSpring.xml

How do i exclude everything but text/html from a heritrix crawl?

On: Heritrix Usecases there is an Use Case for "Only Store Successful HTML Pages"
My Problem: i dont know how to implement it in my cxml File. Especially:
Adding the ContentTypeRegExpFilter to the ARCWriterProcessor => set its regexp setting to text/html.*. ...
There is no ContentTypeRegExpFilter in the sample cxml Files.
Kris's answer is only half the truth (at least with Heritrix 3.1.x that I'm using). A DecideRule return ACCEPT, REJECT or NONE. If a rule returns NONE, it means that this rule has "no opinion" about that (like ACCESS_ABSTAIN in Spring Security). Now ContentTypeMatchesRegexDecideRule (as all other MatchesRegexDecideRule) can be configured to return a decision if a regex matches (configured by the two properties "decision" and "regex"). The setting means that this rule returns an ACCEPT decision if the regex matches, but returns NONE if it does not match. And as we have seen - NONE is not an opinion so that shouldProcessRule will evaluate to ACCEPT because no decisions have been made.
So to only archive responses with text/html* Content-Type, configure a DecideRuleSequence where everything is REJECTed by default and only selected entries will be ACCEPTed.
This looks like this:
<bean id="warcWriter" class="org.archive.modules.writer.WARCWriterProcessor">
<property name="shouldProcessRule">
<bean class="org.archive.modules.deciderules.DecideRuleSequence">
<property name="rules">
<list>
<!-- Begin by REJECTing all... -->
<bean class="org.archive.modules.deciderules.RejectDecideRule" />
<bean class="org.archive.modules.deciderules.ContentTypeMatchesRegexDecideRule">
<property name="decision" value="ACCEPT" />
<property name="regex" value="^text/html.*" />
</bean>
</list>
</property>
</bean>
</property>
<!-- other properties... -->
</bean>
To avoid that images, movies etc. are downloaded at all, configure the "scope" bean with a MatchesListRegexDecideRule that REJECTs urls with well known file extensions like:
<!-- ...and REJECT those from a configurable (initially empty) set of URI regexes... -->
<bean class="org.archive.modules.deciderules.MatchesListRegexDecideRule">
<property name="decision" value="REJECT"/>
<property name="listLogicalOr" value="true" />
<property name="regexList">
<list>
<value>.*(?i)(\.(avi|wmv|mpe?g|mp3))$</value>
<value>.*(?i)(\.(rar|zip|tar|gz))$</value>
<value>.*(?i)(\.(pdf|doc|xls|odt))$</value>
<value>.*(?i)(\.(xml))$</value>
<value>.*(?i)(\.(txt|conf|pdf))$</value>
<value>.*(?i)(\.(swf))$</value>
<value>.*(?i)(\.(js|css))$</value>
<value>.*(?i)(\.(bmp|gif|jpe?g|png|svg|tiff?))$</value>
</list>
</property>
</bean>
The use cases you cite are somewhat out of date and refer to Heritrix 1.x (filters have been replaced with decide rules, very different configuration framework). Still the basic concept is the same.
The cxml file is basically a Spring configuration file. You need to configure the property shouldProcessRule on the ARCWriter bean to be the ContentTypeMatchesRegexDecideRule
A possible ARCWriter configuration:
<bean id="warcWriter" class="org.archive.modules.writer.ARCWriterProcessor">
<property name="shouldProcessRule">
<bean class="org.archive.modules.deciderules.ContentTypeMatchesRegexDecideRule">
<property name="decision" value="ACCEPT" />
<property name="regex" value="^text/html.*">
</bean>
</property>
<!-- Other properties that need to be set ... -->
</bean>
This will cause the Processor to only process those items that match the DecideRule, which in turn only passes those whose content type (mime type) matches the provided regular expression.
Be careful about the 'decision' setting. Are you ruling things in our out? (My example rules things in, anything not matching is ruled out).
As shouldProcessRule is inherited from Processor, this can be applied to any processor.
More information about configuring Heritrix 3 can be found on the Heritrix 3 Wiki (the user guide on crawler.archive.org is about Heritrix 1)