I use thymeleaf
template engine to build request to SOAP service. The class that perform sending looks like this:
import java.io.StringReader;
import java.util.*;
import javax.xml.transform.stream.*;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.thymeleaf.*;
import org.thymeleaf.context.*;
import org.thymeleaf.templateresolver.*;
public class SomeService
{
private final TemplateEngine templateEngine;
private final WebServiceTemplate webServiceTemplate;
public RetrieveServiceThymeleafBased() {
webServiceTemplate = new WebServiceTemplate();
webServiceTemplate.setDefaultUri("http://some.path/to/soap/service");
ITemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateEngine = new TemplateEngine();
templateEngine.addTemplateResolver(templateResolver);
}
public void sendMessage(String orderNumber) {
Context params = new Context();
params.setVariable("CreateDateTime", new Date());
params.setVariable("GUID", UUID.randomUUID());
String xmlContent = templateEngine.process("template.xml", params);
StreamSource source = new StreamSource(new StringReader(xmlContent));
StreamResult result = new StreamResult(System.out);
webServiceTemplate.sendSourceAndReceiveToResult(source, result);
}
}
I know that webServiceTemplate.sendSourceAndReceiveToResult
- is thread-safe operation, But I can't find this kind of information about templateEngine.process
Question : Is templateEngine.process
a thread-safe operation or not
Yes, it is. TemplateEngine
objects are designed to be used in highly-concurrent environments without issues (I hope! ;)).
Disclaimer, per StackOverflow rules: I'm Thymeleaf's author.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With