Can I enable Spring Integration message history inside a chain? - spring

If I add this to my context:
<integration:message-history/>
I get a message header populated with the names (ids) of all the named components through which the message has passed.
But if I have a chain:
<integration:chain id="inboundChain" input-channel="inboundChannel">
<integration:transformer ref="myTransformer"/>
<integration:filter ref="myFilter"/>
<integration:router ref="myRouter"/>
</integration:chain>
I only get "inboundChain" in the list of components, as I can not add an id to the components nested in the chain.
Any way to get myTransformer etc into the message history?

Answer is no.
See spring forum post here

Related

Send additional data to Workday

I am working on sending some additional data for a workday using this endpoint Edit_Worker_Additional_Data. However, it lacks the documentation as what type of data they are expecting, hence, I am getting validation errors. I have tried various combinations but all in vain.
I took some guidance from this question but getting cus namespace error as I don't know where and how he initialized that namespace. Data for the custom field that I want to send:
Custom List
T-Shirt Sizes
Custom Field Type Name
T-Shirt Sizes
Web Service Alias
tShirtSize
List Value Name
Web Service Alias
M - Xs
mXs
M - S
Ms
Given below is the XML request body that I am sending
<soapenv:Body>
<bsvc:Edit_Worker_Additional_Data_Request
xmlns:bsvc="urn:com.workday/bsvc" bsvc:version="v38.1">
<!-- Optional: -->
<bsvc:Business_Process_Parameters>
<!-- Optional: -->
<bsvc:Auto_Complete>true</bsvc:Auto_Complete>
<!-- Optional: -->
<bsvc:Run_Now>true</bsvc:Run_Now>
</bsvc:Business_Process_Parameters>
<bsvc:Worker_Custom_Object_Data>
<bsvc:Effective_Date>2022-11-18</bsvc:Effective_Date>
<bsvc:Worker_Reference bsvc:Descriptor="string">
<!-- Zero or more repetitions: -->
<bsvc:ID bsvc:type="Employee_ID">3671</bsvc:ID>
</bsvc:Worker_Reference>
<bsvc:Business_Object_Additional_Data>
<!-- You may enter ANY elements at this point -->
<bsvc:tShirtSizes>
<bsvc:tShirtSizesField>mXs</bsvc:tShirtSizesField>
</bsvc:tShirtSizes>
</bsvc:Business_Object_Additional_Data>
</bsvc:Worker_Custom_Object_Data>
</bsvc:Edit_Worker_Additional_Data_Request>
</soapenv:Body>
Following are the validation errors that I am getting with different combinations
Invalid Subelement tShirtSizes-urn:com.workday/bsvc for element Effective_Dated_Web_Service_Additional_Data
Invalid Subelement T-Shirt_Sizes-urn:com.workday/bsvc for element Effective_Dated_Web_Service_Additional_Data
I'm not sure if you've already got an answer. It looks like you need the Custom Object name Web Service Alias and the Custom Field Web Service Alias for T Shirt and T Shirt Sizes. Assuming T Shirt is a custom object for the Worker Object Extended. This can be found by someone with appropriate security access in the Workday environment you are trying to make this for. Looks like this is just a custom list which doesn't really provide the context we are looking for.
In Workday search for Custom Object Definitions
Search By Business Process Type
Select Edit Worker Additional Data Event
At this point you may have one or more results (most likely one), but based on context it should be appended by (Effective Dated)
From here one should find what you are looking for.
Here is an example of what this looks like for another custom object
Workday Custom Object Picture
Once you get this information it could be something like this:
<bsvc:Custom Object's Web Service Alias>
<bsvc:Custom Field's Web Service Alias>Whatever Type of Value</bsvc:Custom Field's Web Service Alias>
</bsvc:Custom Object's Web Service Alias>
Keep in mind that the Custom Fields may be of type boolean so it could also look like this:
<bsvc:tShirtSize>
<!--If field is required send else don't-->
<bsvc:mXs>true</bsvc:mXs>
<!--If field is required send else don't-->
<bsvc:Ms>false</bsvc:Ms>
</bsvc:tShirtSize>
Hope this helps!

Overriding Spring cloud sleuth Trace Id format

We are looking at leveraging spring cloud sleuth for distributed tracing and we've worked on a POC. It seems like a great solution, works out of the box.
Had a follow up question though:
We use random UUID vs 64 bit ids as trace id. We understand that custom headers (A new trace Id for example) can be added along with sleuth headers but would it be possible to override the default trace id format for slueth? We have looked through the documentation and perhaps Propagation is
the way to go. Can someone who has done this point us in the right direction and to some examples if possible. The help would be much appreciated.
We are using the latest release 2.0.1 which uses the brave library.
Any help/pointers would be greatly appreciated.
Thanks,
GK
Spring-sleuth doesn't provide a way to override the default ID's. According to OpenZipkin, 'Trace identifiers are 64 or 128-bit, but all span identifiers within a trace are 64-bit. All identifiers are opaque'
Refer this:
https://github.com/openzipkin/b3-propagation#identifiers
So, You can either put the generated request ID as Tag ('tag':'requestID') or You can place generate UID in a different field and use propagation technique. Refer ExtraFieldPropagationTest for reference.
https://github.com/openzipkin/brave/blob/master/brave/src/test/java/brave/propagation/ExtraFieldPropagationTest.java
Even though this is not possible (afaik), if your use case is to use custom headers for log correlation, all that's needed is setting these properties (Related SO Answer):
# To add request-id (to MDC?) via sleuth
spring.sleuth.baggage.correlation-fields=x-request-id
spring.sleuth.baggage.remote-fields=x-request-id
And then this can be used in your logging pattern:
%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%X{traceId:-},%X{spanId:-},%X{x-request-id:-}] [%thread] %logger{40} : %msg%n
Now along with the built-in traceId & spanId, the value of the header x-request-id will also be logged:
2022-06-28 19:55:40.071 WARN [8add19deba73c0f3,cda65c8122e5e025,some-request-id] [reactor-http-epoll-8] c.i.p.g.s.MyService : My warn log
To make this more concise, you can skip traceId & spanId if not required. A better way could have been to use them as a fallback when your own custom correlation header is not available, but logback currently does not (and probably will not) support nesting default values for MDC.
What you can do is to generate the id in a different field and propagate it further on. Check this part of the documentation https://cloud.spring.io/spring-cloud-static/Finchley.SR1/single/spring-cloud.html#_propagating_extra_fields
52.1 Propagating extra fields Sometimes you need to propagate extra fields, such as a request ID or an alternate trace context. For
example, if you are in a Cloud Foundry environment, you might want to
pass the request ID, as shown in the following example:
// when you initialize the builder, define the extra field you want to
propagate Tracing.newBuilder().propagationFactory(
ExtraFieldPropagation.newFactory(B3Propagation.FACTORY,
"x-vcap-request-id") );
// later, you can tag that request ID or use it in log correlation
requestId = ExtraFieldPropagation.get("x-vcap-request-id"); You may
also need to propagate a trace context that you are not using. For
example, you may be in an Amazon Web Services environment but not be
reporting data to X-Ray. To ensure X-Ray can co-exist correctly,
pass-through its tracing header, as shown in the following example:
tracingBuilder.propagationFactory(
ExtraFieldPropagation.newFactory(B3Propagation.FACTORY,
"x-amzn-trace-id") ); [Tip] In Spring Cloud Sleuth all elements of the
tracing builder Tracing.newBuilder() are defined as beans. So if you
want to pass a custom PropagationFactory, it’s enough for you to
create a bean of that type and we will set it in the Tracing bean.

Spring JPA With mongo Supporting Contains and LessThan

I am using Spring JPA with mongo.I have a requirement to use contains query on one of the fields.If end users(UI/Service) hits the GET Request and looks for information in EMAIL Field,I need to search based on text.Pretty much it is like.
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/
This link explains that We can Use Contains to get the Data.
List<ScheduledNotification> findByMobileNumberContaining(String mobileNumber);
List<ScheduledNotification> findByEmailIdIgnoreCaseContaining(String emailId);
But when I am using this API,I am not able to get the data.So ,has any one done something like using Contains.
well ,I was not sending content type in header attribute in GET request.So yes it works,alright.There was no issue with method signature.

How to validate request against XSD and return an error object?

My task is to implement a webservice that:
consumes an XML file on a POST endpoint
in happy flow, it returns a DTO as JSON + HTTP 2xx
the incoming XML file is validated against a XSD; if the validation fails, a JSON with a list of all validation errors is returned (including the line, column, error) with HTTP Bad request
the application exposes two endpoints, only one of them should be validated
I have started the implementation with Spring Boot + web, using regular #PostMapping which has "consumes" and "produces" set to application/xml and application/json, respectively. The usual flow works perfectly fine. Now, I stumbled upon the issue of validating the incoming payload. What I figured out:
1) I have to validate the payload before it is converted (marshalled) to an object.
2) Once validated, I have to either:
allow further processing
stop any further processing, write the error object to the response and set the status code to 400 Bad request
My approaches were:
1) using a RequestBodyAdvice, more specifically the beforeBodyRead method implementation. I had the following issue here: I don't know how to write anything to the output in case the validation fails.
2) using a Filter (I've extended OncePerRequestFilter) - fortunately, I can read the request (request.getInputStream()) and write to the response (response.getOutputStream()).
However, how can I do the selective filtering (as mentioned, I only want to validate one single endpoint)?
Are there any other alternatives for placing the incoming request XSD validation? Is spring-web the appropriate choice here? Would you recommend some other library / framework?
To validate xml against xsd schema, my preference is XML Beans. It is very easy to use. Other options are JABX, Castor. Take a look at Java to XML conversions?.
You will need to jar using xsd schmema and will need to put it in the classpath of your application so that it's classes are available for you for validation. Please take a look at this blog.
You can use validation API as mentioned here.
I would prefer to write validation code in the aspect so that it can be reused with other APIs.
If validation fails, throw valid exception from the aspect itself.
If validation is passed, process your input string that you receive.
Please let us know if you need any more information.

How to return output to client side (rest call) from Microsoft.Xrm.Sdk.IPlugin?

I have created a custom entity and a matching plugin.
The plug-in registers on the Create message of the entity, pre-operation, and synchronous.
Via a rest call the plugin execution is triggered. The input is correct. But I can not get the data out to the client side.
Should I set OutputParameters, change the InputParameter, change plugin registration, ...?
Or should I retrieve the entity afterwards?
This pattern is described at
http://crm.davidyack.com/journal/2012/6/26/crm-client-extension-data-access-strategies.html under the command pattern segment
To update some values in record in Pre-Create you can use something like this:
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
Entity yourEntityName= (Entity)context.InputParameters["Target"]
if(yourEntityName.Attributes.Contains("SomeAttribute"))
yourEntityName.Attributes["SomeAttribute"] = "SomeValues"
}
Is that what you are looking for?
Change "SomeAttribute" for attribute name that you want to change and "SomeValues" for value that you want to pass into record.
On PreCreate event populate Text area with your results. At the end of Create, your entity will have this field populated with results. In rest call retrieve the entity after it is created and retrieve the results from Text area.
If you are using CRM 2013, instead of using custom entity and Plugin, you can use Actions to carry out server side execution and Actions can be called from REST calls. Actions is like any SDK Message where you can provide inputs and it will have Output.
hth
Thanks
Mak

Resources