项目作者: taymyr

项目描述 :
Lagom SOAP client
高级语言: Kotlin
项目地址: git://github.com/taymyr/lagom-soap-client.git
创建时间: 2018-09-07T16:38:54Z
项目社区:https://github.com/taymyr/lagom-soap-client

开源协议:Apache License 2.0

下载


Gitter
Gitter_RU
Build Status
codecov
Javadocs
Maven Central

Lagom SOAP client

Lagom SOAP allows a Lagom application to make calls on a remote web service using SOAP.
It provides a reactive interface to doing so, making HTTP requests asynchronously and returning futures of the result.
Lagom SOAP use Play SAOP library and
Circuit Breaker feature of Lagom.

Versions compatibility

Lagom Soap Client Lagom Scala
1.+ 1.4.+
1.5.+
1.6.+
2.11
2.12
2.13

How to use

1. Generate async client for external SOAP service

  • Use Play SAOP for generate async client.
  • Add generated client to dependencies of Lagom service. For example:
    ```scala
    val externalSoapClient = “foo.bar” %% “external-async-client” % “X.Y.Z”

    .settings(
    libraryDependencies ++= Seq(
    externalSoapClient
    )
    )
  1. ### 2. Add the dependency
  2. See [Adding the dependency](#adding-the-dependency)
  3. ### 3. Register async client
  4. Extend your Guice module by [ServiceGuiceSupport](java/src/main/kotlin/org/taymyr/lagom/soap/ServiceGuiceSupport.kt)
  5. and use `bindSoapClient` method for registration client. Also you can register SOAP message handler for this service.
  6. For example:
  7. ```java
  8. import org.taymyr.lagom.soap.ServiceGuiceSupport;
  9. public class MyServiceModule extends AbstractModule implements ServiceGuiceSupport {
  10. @Override
  11. protected void configure() {
  12. bindSoapClient(Service.class, ServicePort.class, new DisableJaxbValidationHandler());
  13. }
  14. }

4. Inject SOAP client

4.1 Inject SOAP client directly

  1. public class MyServiceImpl implements MyService {
  2. private final ServicePort soapService;
  3. @Inject
  4. public MyServiceImpl(ServicePort soapService) {
  5. this.soapService = soapService;
  6. }
  7. }

4.2 Inject provider of SOAP client

You can inject provider of SOAP client for using custom handling every SOAP message.

  1. public class MyServiceImpl implements MyService {
  2. private final ServiceProvider<ServicePort> serviceProvider;
  3. @Inject
  4. public MyServiceImpl(ServiceProvider<ServicePort> serviceProvider) {
  5. this.serviceProvider = serviceProvider;
  6. }
  7. }

5. Invoke method of SOAP client

You can get SOAP client from the provider, passing it a list message handlers, that will be used in addition to the list passed during registration.
Within these handlers, you can implement the query logic that depends on the current context. For example, put the header User-Agent in the outgoing SOAP request
depending on the headers of the current request.

  1. import static org.taymyr.lagom.soap.WebFaultException.processWebFault;
  2. import static org.taymyr.lagom.soap.handler.SetUserAgentHandler.userAgent;
  3. public class MyServiceImpl implements MyService {
  4. @Override
  5. public HeaderServiceCall<NotUsed, String> myMethod() {
  6. return (headers, request) -> {
  7. ServicePort service = serviceProvider.get(userAgent("Agent"));
  8. return service.foo(new Bar())
  9. .thenApplyAsync(result -> ok("Foo: " + result))
  10. .exceptionally(throwable -> processWebFault(throwable, e -> {
  11. if (e instanceof ServiceLogicException) {
  12. // do something
  13. } else {
  14. throw new TransportException(InternalServerError, new ExceptionMessage("", ""));
  15. }
  16. }));
  17. };
  18. }
  19. }

6. Configuration

  • Add org.taymyr.lagom.soap.WebFaultException to Circuit Breakers whitelist (lagom.circuit-breaker.default.exception-whitelist),
    because all checked SOAP exceptions boxing to WebFaultException. Otherwise Circuit Breaker will be opened for all SOAP exceptions.

  • Configure Circuit Breaker for SOAP client lagom.circuit-breaker.<SERVICE_CLASS>.
    To configure methods use lagom.circuit-breaker.<SERVICE_CLASS>.methods.<METHOD_NAME>
    Highly recommended configuring Circuit Breaker (see all available settings in Lagom docs)
    in play.soap.services block and use reference to this configuration in lagom.circuit-breaker block.

  • Configure address external SOAP service play.soap.services.<SERVICE_CLASS>.address. See details in Play SOAP docs.

  • Configure value of User-Agent header play.soap.services.<SERVICE_CLASS>.browser-type. (Default value lagom).

  • Configure SOAP client play.soap.services.<SERVICE_CLASS>.singleton as Singleton for better performance. Warning: It can be NOT thread-safe. More details see on CXF docs (Default value false)

  • Configure max log size of you soap-client play.soap.services.<SERVICE_CLASS>.log-size (Default value 48 kB). When you use log-size more than 128 kbytes CXF creates temporary files that contains messages, and CXF deletes files by itself.

  1. lagom.circuit-breaker {
  2. default.exception-whitelist = [
  3. org.taymyr.lagom.soap.WebFaultException
  4. ]
  5. com.foo.bar.service.Service = ${play.soap.services.com.foo.bar.service.Service.breaker}
  6. com.foo.bar.service.Service.methods.method1 = ${play.soap.services.com.foo.bar.service.Service.methods.method1.breaker}
  7. com.foo.bar.service.Service.methods.method2 = ${play.soap.services.com.foo.bar.service.Service.methods.method2.breaker}
  8. }
  9. play.soap.services {
  10. com.foo.bar.service.Service {
  11. address = "http://domain:PORT/service"
  12. browser-type = "Lagom MyService"
  13. singleton: false
  14. log-size : 1MB
  15. breaker = {
  16. call-timeout = 10s
  17. }
  18. methods {
  19. method1 {
  20. breaker {
  21. call-timeout = 20s
  22. }
  23. }
  24. method2 {
  25. breaker {
  26. call-timeout = 30s
  27. }
  28. }
  29. }
  30. }
  31. }

Adding the dependency

All released artifacts are available in the Maven central repository.
Just add a lagom-soap-client to your service dependencies:

  • SBT
  1. libraryDependencies += "org.taymyr.lagom" %% "lagom-soap-client-java" % "X.Y.Z"
  • Maven
  1. <dependency>
  2. <groupId>org.taymyr.lagom</groupId>
  3. <artifactId>lagom-soap-client-java_${scala.binary.version}</artifactId>
  4. <version>X.Y.Z</version>
  5. </dependency>

All snapshot artifacts are available in the Sonatype snapshots repository.
This repository must be added in your build system.

  • SBT
  1. resolvers ++= Resolver.sonatypeRepo("snapshots")
  • Maven
    1. <repositories>
    2. <repository>
    3. <id>snapshots-repo</id>
    4. <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    5. <releases><enabled>false</enabled></releases>
    6. <snapshots><enabled>true</enabled></snapshots>
    7. </repository>
    8. </repositories>

Contributions

Contributions are very welcome.

License

Copyright © 2019 Digital Economy League (https://www.digitalleague.ru/).

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.