How to add a file as attachment in Spring integraion Webservices outbound gateway - attachment

I have a spring integration outbound gateway for Webservices. Till this time, i send the request in xml format to the web services.
Now, I need to send a file as part of the request to the web service.
How will I do that?
Below is the spring integration chain existing configuration:
<!-- Chain to Process requests for XXXXX-->
<int:chain id="psTestChain" input-channel="psTestInputChannel" >
<!-- Set up transformer for input message -->
<int:transformer method="transform" ref="testRequestXformer"/>
<!-- This Spring Integration chain first adds the service name and the
service operation headers to the Spring Integration message using the header
<int:header-enricher>
<int:header name="#{XXXXXXXXX}"
value="TestSearch" />
<int:header
name="#{XXXXXX}"
value="searchByTestIdentifier" />
</int:header-enricher>
<!-- The WS outbound gateway is used to make an outgoing SOAP call. -->
<int-ws:outbound-gateway id="simpleGateway"
destination-provider="testDestinationProvider"
message-sender="testHttpsMessageSender"
interceptor="test_wss4jInterceptor"
header-mapper="testSoapHeaderMapper"/>
<!-- Set up transformer for output message -->
<int:transformer method="transform" ref="testResponseXformer"/>
</int:chain>

Take a look, please, to the MTOM sample for the Spring WS project.
Since Spring Integration WS module is fully based on the Spring WS, I think there won't be so mutch difference to build JaxB object with attachements as Message payload and send it to the <int-ws:outbound-gateway> with marshaller injection.
We have an open issue on the matter, but I don't have enough time to see what we should do there.
I've just raised an ticket for Spring Integration Samples to track the ability of MTOM in Spring Integration.

Related

Spring Cloud Data Flow - Http --> HttpClient (pass headers)

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.

ReactiveBase headers

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.

What is the purpose of API token in REST API Call Plugin Configuration?

What is the purpose of "API token" option in REST API Call Plugin Configuration? Why it is compulsory?
On screenshots below it was set to "rest" but never used afterwards. Any examples?
https://thingsboard.io/docs/reference/plugins/rest/
The purpose of the API token is to reserve certain path in the REST and Websocket API to particular plugin.
So, all requests that match certain URL filter:
http(s)://host:port/api/plugins/$API_TOKEN/
Will be dispatched to the plugin implementation after security check.
Plugin can apply additional checks if required.

CXF post api fails via jmeter

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

ServiceMix + broadcasting message

New to ServiceMix, I'm not sure if it can do what I need:
I've an interface defined by wsdl
I have several endpoints that implement that interface defined by the wsdl
I've a service that can only send the message to one endpoint.
Can service mix do the following:
Producer sends to an endpoint in servicemix (with the wsdl).
ServiceMix broadcasts to the different endpoints the message.
Thanks for the advice and / or pointers!
The simplest would be to use a Camel Recipient List. This would allow you to have either static or dynamic destinations for your broadcast.
It sounds as if your application doesn't require termination of the SOAP message (de/serialize the payload to/from an object) at the ServiceMix consumer. Therefore it can be kept very simple by using a Camel Jetty proxy:
There are further details on the link above on how to configure static (the example above) and dynamic routing.
If your application changes and does require termination of the SOAP message at the ServiceMix consumer in the future, then change out the Camel Jetty consumer endpoint with a Camel CXF endpoint and set bridgeEndpoint to false.
As for ServiceMix you will need to enable the Camel Jetty component. To have it enabled by default you need to edit the etc/org.apache.karaf.features.cfg file and add camel-jetty to the featuresBoot property. This is typically the best practice for features required by your application. You can also install the feature at the ServiceMix console with the command "features:install camel-jetty".
The Recipient List capability is part of the Camel Core API which is installed by default and if not, as a dependency of any other Camel component.
Best Regards,
Scott ES

Resources