Spring Integration: JDBC single query to web service - spring-mvc

I would like to know the way for resolving this integration scenario:
Execute different queries to select X elements from a database. I am
looking for an inbound adapter without pooling because it is just
necessary to execute the query once. Although, results of the queries
will be generate only one output.
Work with this data to build a SOAP request (generic web service)
Send this SOAP request to a web service and wait for an asynchronous response.
But also, it is necessary to deploy all this scenario in a WAR file on Tomcat server. I am deploying the application from a spring MVC + spring integration skeleton but I will not have any controller. Is it possible to execute the application when context was loaded on Tomcat?
I am working with the next technologies:
Spring integration
Spring MVC for a WAR deployment
Scheduling (Quartz or #Scheduled)
Spring WS
Regards

Since you say that you'd prefer to select on the application start up and only once, you can use:
<int-event:inbound-channel-adapter channel="jdbcChannel"
event-types="org.springframework.context.event.ContextRefreshedEvent"
payload-expression="''"/>
and <int-jdbc:outbound-gateway query="SELECT * FROM ..."/>
And so on to the WebService.
UPDATE
Since you say that you are around Anotation configuration, consider to use Spring Integration Java DSL.
To configure <int-event:inbound-channel-adapter> from #Configuration you should do this:
#Bean
#SuppressWarnings("unchecked")
public MessageProducer ApplicationEventListeningMessageProducer() {
ApplicationEventListeningMessageProducer producer = new ApplicationEventListeningMessageProducer();
producer.setEventTypes(ContextRefreshedEvent.class);
producer.setPayloadExpression("''");
producer.setOutputChannel(jdbcChannel());
return producer;
}
ContextRefreshedEvent info you can get from its JavaDocs or from Spring Framework Manual.

Related

Spring boot issue when deployed on to Mesos dcos having multiple microservices

I am new to spring boot and have recently encountered a weird issue. My application which already has a context path runs smoothly on the localhost with a URL like "localhost:port/contextpath/dashboard". But when I try to deploy it on Mesosphere DCOS, it produces an error. Since the mesos server has multiple microservices, each service is separated by a service name,so the service got deployed onto a path like "server.com/servicename/contextpath/dashboard". However, internally the relative mapping is such that any internal reference, be it a navigation like or request mapping of controller ends up something like "server.com/contextpath/dashboard" which misses out on the service name and hence doesn't work.

Using Serilog with .Net core and App Insights

I have used App insights directly for application logging before and I have seen that .Net core platform also creates trace events that goes to App insights.
In a new .Net core API application, I'd like to use Serilog for application logging and App Insight for storing and visualizing the log events. I'd like to know:
How to continue to get the .Net core .created trace events to App insights?
How can I pass correlation Id from my application to .Net core created trace events?
Will end to end transaction feature in App insight portal show all the events together? It is important for me to know and keep an eye on the latency of SQL calls.
Simply using Serilog.Sinks.ApplicationInsights is not enough, as it will not correlate Serilog events with the rest of your telemetry on Application Insights.
To correlate the events, so they are shown as one "End-to-End transaction" - you have to do the following things:
Create a Serilog enricher that would record the current Activity id as a ScalarValue in a LogEventProperty - see OperationIdEnricher
[Optional] Create an extension for this enricher - see LoggingExtensions
Register the enricher / add it to the pipeline via code or config - see logging.json
Create a custom TelemetryConverter (subclass from TraceTelemetryConverter or EventTelemetryConverter) for ApplicationInsights that would set telemetry.Context.Operation.Id from value set in 1) - see OperationTelemetryConverter
Check out my blog post "Serilog with ApplicationInsights" that explains the points above with more details, and links
Also, be sure to take a look at Telemetry correlation in Application Insights on MSDN
If you are using ILogger in .Net core for logging purposes, those message can be directed to Application Insights with the following modification of startup.cs:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
/*...existing code..*/
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Warning);
}
If you employ your own correlation ID, you can modify Application Insights correlation IDs accordingly in Context.Operation field of telemetry item with your own Telemetry Initializer or pass those values in the respective headers (Request-ID (global ID) and Correlation-Context (name-value pairs)) in the requests to this app - AI will pick up correlation IDs from those.
The end to end transaction is supposed to be displayed together (Requests/Dependencies and Exceptions) on a timeline in the details view of Application Insights telemetry. With you own correlation IDs it should work as well if they are in there from the very beginning of transaction (e.g. in the first component) - otherwise injecting them in the middle will break the chain.

websphere liberty 8.5.5.9 remote ejb lookup fails

I have created two liberty instances on my local machine. I deployed a war module which contains a remote ejb in server X and deployed another war in server Y which has to remote lookup the ejb from server X.
Below is the code to lookup the ejb from a restful webservice.
Properties p = new Properties();
p.setProperty("java.naming.provider.url", "corbaname:iiop:localhost:2809");
InitialContext context = new InitialContext (p);
context.lookup("corbaname:rir:#ejb/global/caching/CachingServiceBean!com%5c.ejb%5c.CachingService");
When I try to call the web service I get below exception
DII operation not supported by local object
P.S.
I have enabled ejbRemote feature on both the servers with different port numbers.
I changed my lookup string to "corbaloc:iiop:localhost:2809/NameService#ejb/global/caching/CachingServiceBean!com%5c.ejb%5c.CachingService" and then I get the below error
Then I changed my lookup string to "corbaname:iiop:localhost:2809/NameService#ejb/global/caching/CachingServiceBean!com%5c.ejb%5c.CachingService" and then I got the below error
After checking apache geronimo-yoko implementation on GitHub, I understood that I have to use corbaloc:iiop:localhost:2809. But still I am getting exceptions caused by
org.omg.CORBA.OBJECT_NOT_EXIST: unable to dispatch - servant or POA not found
I used the following urls with no luck:
corbaloc:iiop:localhost:2809/global/caching/CachingServiceBean!com.ejb.CachingService
corbaloc:iiop:localhost:2809/#ejb/global/caching/CachingServiceBean!com.ejb.CachingService
3.corbaloc:iiop:localhost:2809/caching/CachingServiceBean!com.ejb.CachingService
4.corbaloc:iiop:localhost:2809/ejb/global/caching/CachingServiceBean!com.ejb.CachingService
I think the problem is with the packaging. I packed my ejb in a war module.
I followed the steps described in the PDF mentioned in this page http://www.redbooks.ibm.com/redpieces/abstracts/sg248076.html and everything is working now.
I used corbaname::host:port syntax to lookup the remote ejb instead of corbaloc:iiop:host:port
After packing my ejb in an ear then it started working.

Unable to access Data Transfer object in WCF Service

I have created a web application in .Net which will be used to consume multiple wcf service. The end points will be specified at runtime using below code:
ServiceWCFTest3.Service1Client client1 = new Service1Client();
client1.Endpoint.Address = new EndpointAddress("http://localhost:55473/Service1.svc");
Also please refer below one of the web methods exposed by the service:
EmployeeDetails empDtl= new EmployeeDetails("John");
ResultObject result = channel.ADMSAccess_Entry("Test",empDtl );
These classes are marked as DataContract in the specific wcf service.
Now, when the application is executed to access multiple wcf services by changing end point at runtime, it points to correct service and correct web methods. But the value of object EmployeeDetails and ResultObject is passed and received as null. I need to use these class objects to communicate. Can anybody please suggest how can I pass the values using these objects?

LCDS / Spring integration for Assemblers

I have a Flex / Spring / LCDS project, and I'm trying to use the Spring/Flex integration module.
It works fine for exposing simple destinations & messaging end-points, however I'm unsure how to configure to use Assemblers.
The vanilla, no-Spring-integration-way involves declaring a destination such as:
<destination id="book.service">
<properties>
<source>flex.data.assemblers.HibernateAnnotationsAssembler</source>
<item-class>com.library.Book</item-class>
</properties>
</destination>
However, when I try to integrate this approach with Spring, I come unstuck.
This destination needs an adapter. Running as-is, allowing the Spring/Flex integration to install the default remoting adapter doesn't work, as I get the following error at rumtime:
Caused by: flex.messaging.config.ConfigurationException: Destination 'book.service' must specify at least one adapter.
How do I connect this destination to the adapter?
Also, will the HibernateAnnotationsAssember detect and integrate with the Spring managed Hibernate sessions, or does this require additional config as well?
From what I know Spring is fully integrated only with BlazeDS..you cannot expose Spring beans (assemblers) as destinations.

Resources