Mule Schema validation when wsdl has embedded xsd - xsd

In Mule ESB I want to validate incoming SOAP/XML, using a standard Mule "schema-validation filter".
Something like:
<mulexml:schema-validation-filter schemaLocations="xxx.xsd" name="xxxValidationFilter"/>
However this kind of definition seem to assume that the schema is located in a separate xsd-file, whereas in a lot of cases the schema definition is embedded in the "wsdl:types" element of a wsdl-file.
Is there any way to use the Mule schema-validation-filter to validate against schema's which are embedded in the wsdl (except for copying the schema element definitions out of the
wsdl and into a separate xsd-file).

Mule service element tags which expose the service haave an attribute that can enable validation on the incoming request.
validationEnabled="true"
<cxf:simple-service validationEnabled="true"/>
<cxf:jaxws-service validationEnabled="true"/>
<cxf:proxy-service validationEnabled="true"/>
For more information refer to the following Mule documentation link.
http://www.mulesoft.org/documentation/display/current/Building+Web+Services+with+CXF
Hope this helps.

Related

Generate openApi DTO's with NestJS without a Controller

I am writing a NestJS service that provides a REST API and it publishes some messages to NATS. We are using the NestJS support to generate OpenAPI docs, and from the OpenAPI docs we generate an SDK that we import into our clients. This all works great, but only the REST API of our code is in the SDK.
What we'd like to also do is to have NestJS include the DTO's for the content for the messages we publish to NATS. Then our SDK will also include interfaces for these DTO's, and then our clients can cast the message content to the correct interface (based on the message subject). This way, the publisher of an event defines the content of the event, and users of it don't have to replicate the interface, yet they get strongly-typed code.
I've tried adding the #Api decorators to the DTO, but it appears that unless the DTO is used in the definition of an #Controller, it is not included in the resultant openApi docs.
I was hoping for a way to decorate a "random" DTO in my code so it will then be included in the swagger docs, and in-turn included in a generated SDK. Is something like that possible?
you can also pass extraModels array as a part of SwaggerDocumentOptions
SwaggerModule.createDocument(app, config, {
extraModels: [.......]
});
https://github.com/nestjs/swagger/issues/241

How to create Index with custom analyzers from json file in Azure Search .NET SDK?

I had read that the Azure Search .NET SDK uses NewtonSoft.Json to convert it's models to/from json in it's underlying REST API calls so I've been doing the same in my own app.
I have a simple app which creates a new Index using the .NET SDK. To do this, I was defining my Index in a json file, using the format outlined here https://learn.microsoft.com/en-us/rest/api/searchservice/create-index and then I was converting this to a Microsoft.Azure.Search.Models.Index object using Newtonsoft.
var index = JsonConvert.DeserializeObject<Microsoft.Azure.Search.Models.Index>(System.IO.File.ReadAllText("config.json");
This was working fine before I configured custom Analyzers, but now that I have custom Analyzers in my config, the Analyzers, Tokenizers, and TokenFilters are not being resolved into the correct types. ie. my custom Analyzer is being deserialized as a Microsoft.Azure.Search.Models.Analyzer, instead of Microsoft.Azure.Search.Models.CustomAnalyzer, same goes for the Tokenizers and TokenFilters, they are being deserialized into the base types.
Is there an easy way I can create an Index like this in the .NET SDK from a json file?
Unfortunately this is not an officially supported scenario. While it works for simple index definitions, we're working to understand what we need to do to be able to support all cases.
Please post your feature request on our User Voice page to help us prioritize: https://feedback.azure.com/forums/263029-azure-search
In the meantime, you might be able to get it working yourself by adapting the JsonSerializerSettings initialization code at the bottom of this file.

Spring Integration REST service consuming both XML and JSON

I would like to implement the following simple use case with Spring Integration v4.2+:
A REST endpoint is provided to clients, for example (/api/person).
The clients can POST data to this endpoint. The data can be submitted in JSON, XML or Google Protocol Buffers format.
The application accepts the data and saves it to a database table.
I have the following Spring Integration configuration that allows the endpoint to accept JSON data:
<int:channel id="receiveChannel"/>
<http:inbound-channel-adapter id="restInputAdapter"
channel="receiveChannel"
path="/api/person"
request-payload-type="java.util.Map"
supported-methods="POST"/>
<jdbc:outbound-channel-adapter id="jdbcOutputAdapter"
channel="receiveChannel"
data-source="dataSource"
query='INSERT INTO "person" ("first_name", "last_name", "email_address") VALUES (:payload[firstName], :payload[lastName], :payload[email])'/>
This is in a Maven project with Jackson2 on the classpath, which is why no special configuration is required for reading JSON from the request.
However, attempting to post XML data results in the following exception:
org.springframework.messaging.MessagingException: Could not convert request: no suitable HttpMessageConverter found for expected type [java.util.Map] and content type [application/xml]]
I have tried using the message-converters attribute with http:inbound-channel-adapter, specifying Jackson, JAXB and Protocol Buffers converters explicitly but that does not help either.
I know how to do this in a bespoke Spring MVC application with #RestControllers so I am not looking for solutions outside of Spring Integration.
How can the Spring Integration configuration above be tweaked so that the REST endpoint can be made to accept JSON, XML and Google Protocol Buffers at the same time?
It seems that although JSON converts to java.util.Map, XML does not. This is why the seen error.
I created a class:
#XmlRootElement class Person { ... }
and then modified the configuration as follows (only changes shown):
<http:inbound-channel-adapter ...
request-payload-type="Person"
.../>
<jdbc:outbound-channel-adapter ...
query='INSERT INTO "person" ("first_name", "last_name", "email_address") VALUES (:payload.firstName, :payload.lastName, :payload.email)'
.../>
I can now post both XML and JSON data to the endpoint.
Google Protocol Buffers support can now be added using the Protostuff library.

Spring WS and CXF Binding

I want to implement a webservice client using Spring WS JAXB and CXF.
I use CXF to generate my Stubs from a WSDL file.
This WSDL contains the following schema :
For this schema the only thing that cxf generates is an ObjectFactory and no stub.
I want to use Spring Ws marshalSendAndReceive method to send a request to my service but I don't know how to construct my request object from what was generated with CXF.
Someone can help ?
thx
You don't really need CXF to generate the JAXB types from the WSDL file, JDK comes with a tool called xjc which can do this for you - http://docs.oracle.com/javase/6/docs/technotes/tools/share/xjc.html
Can you try using this and see if the artifacts created with this tool suffice.

XJC fails generating *.java classes

I am trying to generate java classes that describe the web service offered here which belongs to this page. Please mind that I am not convinced that the XML is the one needed to run the following steps!
I save the XML of the API to a file: getcapabilities.xml
I run the following trang command to generate an XSD: java -jar trang.jar getcapabilities.xml getcapabilities.xsd
I get the following files: getcapabilities.xsd, ogc.xsd, wfs.xsd, xlink.xsd, xsi.xsd
I run the following command to generate java classes: xjc getcapabilities.xsd
The following error message is prompted
parsing a schema... [ERROR] no-xsi: The {target namespace} of an attribute declaration must not match 'http://www.w3.org/2001/XMLSchema-instance'.
line 7 of file:xsi.xsd
Failed to parse a schema.
Questions:
Do you get the same error message?
What can I do about it?
Is my approach meant to be successful at all?
You're dealing with an OGC Web Feature Service. There's a couple of peculiarities with that.
Don't generate you schemas with trang, you can get them from OGC: http://schemas.opengis.net/wfs/1.1.0/
You don't really have to compile these schemas on your own, you can get them precompiled from the OGC Schemas and Tools project (JARs are here).
WFS schemas only describe WFS operations - they are kind of container schemas. You'll also have an application profile which describes your features. You can obtain it via the DescribeFeatureType operation: http://data.wien.gv.at/daten/wfs?service=WFS&request=DescribeFeatureType&version=1.1.0
Consider using someting like GeoTools.

Resources