Assume a Spring Cloud Dataflow (SCDF) stream like
http|httpclient|custom-app|log
Given I invoke the stream from postman with headers: Content-Type and Custom header (e.g 'fileName')
What would be the approach to pass all the headers from 'http' app to 'custom-app' in above scenario in SCDF.
Issue fix: to configure mapped-request-headers and headers-expression as shown here
I think you need to use mapped-request-headers option in the http application as defined here.
Related
I wrote this robot framework test to post a https request to a webservice. The request body is in xml format and not in Json. I have used request library for this, but i am receiving error when i post using the code listed below.
With postman, i had send the body as raw data and got response as 200 ok, but when i try to do the same in robot framework its throwing error 404.
Please help me on this:
Is requests library relevant for post of https xml data soap request
to a web service?
Can any modification be made to below code for posting a https request
to a web service?
Is there any other library through which we could achieve calling
soap web service?
The Robot Framework Script
***Library***
Library String
Library Collections
Library RequestsLibrary
***Variables***
${user} = username
${passwd} = pwd
&{headers} Content-Type=application/soap+xml or text/xml Authorization=Basic encrypted details
${body_request} = <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://example.com/schemas</a:Action><a:MessageID>msgid</a:MessageID><a:ReplyTo><a:Address>url</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">serviceurl</a:To></s:Header><s:Body xmlns:xsi=body"></s:Body></s:Envelope>
*** Test Cases ***
${auth}= Create List ${user} ${passwd}
Create Session alias=proc url=url headers=${headers} auth=${auth}
Sleep 5
${resp2} Post Request alias=proc uri=url data=${body_request} json=None params=None
headers=${headers} files=None allow_redirects=True timeout=None
Should Be Equal As Strings ${resp2.status_code} 200
Log To Console ${resp2.status_code}
Answers to your question mentioned below,
Is requests library relevant for post of https xml data soap request to a web service? - yes, it can be used. however, there are better ways to achieve the same, see the solution below.
Can any modification be made to below code for posting a https request to a web service? - I think it is nothing to do with https, since 400 is bad request, you need to look at the body.
Is there any other library through which we could achieve calling soap web service? - SudsLibrary.
Although, you can make use of requests module to achieve your solution,
My philosophy when making use of robotframework is "SIMPLY MAKE USE OF EXISTING LIBRARIES" which is already verified. Please do not spend time to solve the problem keeping the thought process of "using a language".
Solution
Please make use of "SudsLibrary" library for SOAP requests, look at Keyword Documentation for your reference.
SudsLibrary is a library for functional testing of SOAP-based web services. SudsLibrary is based on Suds, a dynamic SOAP 1.1 client.
pip install robotframework-sudslibrary3
When you use the above library your code would be something similar to the one seen below,
*** Settings ***
Library SudsLibrary
Library Collections
*** Test Cases ***
Sample Testcase On SOAP
${BASE_URL} Set Variable http://www.someservice.com
${SERVICE} Create Dictionary
... name=someservice
... wsdl=someservice.asmx?WSDL
${PORT} Set variable SERVICE_PORT
${METHOD} Set variable CALLSOMEACTION
Set Binding SOAP-ENV http://www.w3.org/2003/05/soap-envelope
Create Soap Client ${BASE_URL}/${SERVICE.name}/${SERVICE.wsdl}
Set Port ${PORT}
Set Headers Content-Type application/soap+xml
Set Headers Authorization Basic encrypted details
Set Headers Soapaction ${EMPTY}
Set Headers Action "${BASE_URL}/${SERVICE.name}/${METHOD}"
${result} Call Soap Method ${METHOD}
When I send the data to PHP, the browser responds with an error:
Failed to load http://localhost/api/notification/create.php: Response for preflight does not have HTTP ok status.
Here is my code to send the data
This looks like a problem with your CORS implementation. Specifically, you seem to be missing the Http method "options".
You can resolve this by either by:
Implementing CORS correctly in your PHP code. You should prefer this way if your production setup requires you to have the PHP code running on a different domain
or by using the Angular CLI Proxy. You should prefer this way if you only need the different domains (e.g. localhost:4200 for angular and localhost(:80) for PHP)
I'm experimenting with ReactiveSearch and so far have tried the DataSearch and ResultList components. I'm looking over the required component to look at all the props and I see this
<ReactiveBase
app="appname"
credentials="abcdef123:abcdef12-ab12-ab12-ab12-abcdef123456"
headers={{
secret: 'reactivesearch-is-awesome'
}}
>
<Component1 .. />
<Component2 .. />
</ReactiveBase>
If the app is already secured using Appbaseio and the credentials gives my React app access to my ES cluster hosted there... what exactly could headers be used for? At first I thought username and password but you wouldn't do that.
What would be some of the scenarios where I SHOULD/COULD use the headers prop?
The headers are added to each request sent to the url. Normally you wouldn't need these. But in production you might want to add a layer of proxy server between your elasticsearch cluster and the client side ReactiveSearch code, this is where headers can be helpful.
You could add authentication in the flow. For example, you could restrict the elasticsearch calls to authenticated users by sending an access token via the headers prop and then verifying it at the proxy server (example of proxy server).
You could also implement some custom logic by adding custom headers and a logic to handle them at the proxy server.
Trying to automate my test cases using jmeter. I have used cxf for rest apis on my web server. I have an api which actually takes a java object as parameter. On jmeter I have selected the POST method under HTTP-request and sending json data in Body data. The api gets called fine. However the parameter comes null and hence by api fails. I did try changing the parameter to String object, however I get this string as null.
Is this the right way to call apis via jmeter. Or is this failing because I have used cxf on my server.
Any help is appreciated.
Thanks
Most likely you need to add a HTTP Header Manager and configure it to send Content-Type header with the value of application/json
See Testing SOAP/REST Web Services Using JMeter for detailed explanation on JMeter configuration for REST API testing.
Other thing you could try out is using SoapUI tool to send the request to your CXF endpoint and if it succeeds - inspect the request and configure JMeter accordingly. By the way, SoapUI has some limited load testing capabilities, may be it will be enough for your scenario
I have two separate services communicating using AmqpProxyFactoryBean (the "client") and AmqpInvokerServiceExporter (the "server"). Now, I'd like to include some custom headers on every request made through the AMQP proxy and be able to access them on the "server". Is there any easy way I can achieve this?
Since AmqpClientInterceptor uses AmqpTemplate to send and receive AMQP messages, you can provide for that RabbitTemplate any custom MessageConverter. And populate any additional headers from your toMessage() implementation.
However I'm not sure that you will be able to access to those custom header on the server side. We end up there just with RemoteInvocation.invoke().
So, seems for me you finally come up to the solution with an additional RPC param.
From other side that custom header may be useful for other AQMP routing scenarios when you can route that RPC message not only to the RPC queue.
Consider using Spring Integration AMQP Gateways instead of remoting over rabbitmq; that way you have complete control over the headers passed back and forth.
If you don't want to use Spring Integration, you can use the RabbitTemplate sendAndReceive methods on the client and either the receiveAndSend or a listener container on the server.
Again, this gives you full control over the headers.