├── .github ├── mergify.yml ├── dependabot.yml ├── scala-steward.conf ├── workflows │ ├── publish.yml │ ├── release-drafter.yml │ ├── dependency-graph.yml │ └── build-test.yml └── release-drafts │ └── increasing-patch-version.yml ├── .gitignore ├── plugin └── src │ ├── main │ ├── resources │ │ ├── META-INF │ │ │ ├── services │ │ │ │ └── com.sun.tools.xjc.Plugin │ │ │ └── tools-plugin.xml │ │ └── play │ │ │ └── soap │ │ │ └── plugin │ │ │ ├── client.vm │ │ │ └── sei.vm │ └── java │ │ └── play │ │ └── soap │ │ └── plugin │ │ ├── PlayPortMethodNameGenerator.java │ │ ├── PlayGenerator.java │ │ ├── FutureApi.java │ │ ├── Configuration.java │ │ ├── FutureGenerator.java │ │ ├── PlaySEIGenerator.java │ │ ├── PlayXjcPlugin.java │ │ └── PlayClientGenerator.java │ └── sbt-test │ └── play-soap │ ├── simple-client-play-java-future │ ├── test │ ├── project │ │ └── plugins.sbt │ ├── app │ │ └── play │ │ │ └── soap │ │ │ └── testservice │ │ │ ├── HelloException.java │ │ │ ├── Hello.java │ │ │ ├── User.java │ │ │ ├── HelloWorld.java │ │ │ ├── Primitives.java │ │ │ ├── HelloWorldImpl.java │ │ │ └── PrimitivesImpl.java │ ├── build.sbt │ ├── tests │ │ └── play │ │ │ └── soap │ │ │ └── sbtplugin │ │ │ └── tester │ │ │ ├── HelloWorldTest.java │ │ │ └── PrimitivesTest.java │ └── conf │ │ └── wsdls │ │ └── helloWorld.wsdl │ ├── simple-client-scala-future │ ├── test │ ├── project │ │ └── plugins.sbt │ ├── app │ │ └── play │ │ │ └── soap │ │ │ └── testservice │ │ │ ├── HelloException.java │ │ │ ├── Hello.java │ │ │ ├── User.java │ │ │ ├── HelloWorld.java │ │ │ ├── Primitives.java │ │ │ ├── HelloWorldImpl.java │ │ │ └── PrimitivesImpl.java │ ├── build.sbt │ ├── tests │ │ └── play │ │ │ └── soap │ │ │ └── sbtplugin │ │ │ └── tester │ │ │ ├── ServiceSpec.scala │ │ │ ├── HelloWorldSpec.scala │ │ │ └── PrimitivesSpec.scala │ └── conf │ │ └── wsdls │ │ └── helloWorld.wsdl │ ├── multiple-ports │ ├── test │ ├── project │ │ └── plugins.sbt │ ├── build.sbt │ └── src │ │ └── main │ │ └── wsdl │ │ └── stockquote.wsdl │ └── incremental-compilation │ ├── project │ ├── plugins.sbt │ └── Constants.scala │ ├── build.sbt │ ├── test │ ├── helloWorld2.wsdl │ └── src │ └── main │ └── wsdl │ └── helloWorld.wsdl ├── docs ├── antora.yml ├── modules │ └── ROOT │ │ ├── pages │ │ ├── plugin │ │ │ ├── cli.adoc │ │ │ ├── gradle.adoc │ │ │ ├── sbt.adoc │ │ │ ├── how-to-use.adoc │ │ │ └── maven.adoc │ │ ├── highlights.adoc │ │ ├── index.adoc │ │ └── client │ │ │ ├── security.adoc │ │ │ ├── handlers.adoc │ │ │ └── play-soap-client.adoc │ │ └── nav.adoc └── local-antora-playbook.yml ├── project ├── build.properties ├── plugins.sbt ├── Common.scala └── Dependencies.scala ├── .git-blame-ignore-revs ├── client └── src │ ├── main │ ├── resources │ │ └── reference.conf │ └── scala │ │ └── play │ │ └── soap │ │ ├── PlayJaxwsClientCallback.scala │ │ ├── PlayJaxWsServiceFactoryBean.scala │ │ ├── PlayServiceConfiguration.scala │ │ ├── PlaySoapPlugin.scala │ │ └── PlayJaxWsProxyFactoryBean.scala │ └── test │ ├── java │ └── play │ │ └── soap │ │ └── mockservice │ │ ├── SomeException.java │ │ ├── MockService.java │ │ ├── MockServiceJava.java │ │ ├── MockServiceScala.java │ │ ├── MockServiceImpl.java │ │ ├── Foo.java │ │ └── Bar.java │ ├── resources │ └── logback.xml │ └── scala │ └── play │ └── soap │ └── PlayJaxWsClientProxySpec.scala ├── .scalafmt.conf ├── common.sbt ├── test ├── server │ └── src │ │ └── main │ │ ├── java │ │ └── play │ │ │ └── soap │ │ │ └── test │ │ │ └── primitives │ │ │ └── PrimitivesImpl.java │ │ └── resources │ │ └── wsdl │ │ └── helloworld.wsdl ├── scala │ └── src │ │ └── test │ │ └── scala │ │ └── play │ │ └── soap │ │ └── test │ │ └── PrimitivesSpec.scala └── java │ └── src │ └── test │ └── java │ └── play │ └── soap │ └── test │ └── PrimitivesTest.java ├── README.md └── LICENSE /.github/mergify.yml: -------------------------------------------------------------------------------- 1 | extends: .github 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | target 3 | .bsp/ 4 | node_modules/ 5 | /docs/build/ 6 | /docs/package*.json 7 | -------------------------------------------------------------------------------- /plugin/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin: -------------------------------------------------------------------------------- 1 | play.soap.plugin.PlayXjcPlugin 2 | -------------------------------------------------------------------------------- /docs/antora.yml: -------------------------------------------------------------------------------- 1 | name: play-soap 2 | title: Play SOAP 3 | version: 2.x 4 | nav: 5 | - modules/ROOT/nav.adoc 6 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | # 4 | sbt.version=1.11.7 5 | -------------------------------------------------------------------------------- /.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | # Scala Steward: Reformat with sbt-java-formatter 0.8.0 2 | 29e7806bcfe0a8e2572239ffc0012592666580df 3 | 4 | # Scala Steward: Reformat with scalafmt 3.9.7 5 | 9b8aa53a95a9d43ea37a2bf5b16816f82751e0ff 6 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-play-java-future/test: -------------------------------------------------------------------------------- 1 | # Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 2 | 3 | > +test 4 | -------------------------------------------------------------------------------- /.github/scala-steward.conf: -------------------------------------------------------------------------------- 1 | commits.message = "${artifactName} ${nextVersion} (was ${currentVersion})" 2 | 3 | pullRequests.grouping = [ 4 | { name = "patches", "title" = "Patch updates", "filter" = [{"version" = "patch"}] } 5 | ] 6 | -------------------------------------------------------------------------------- /client/src/main/resources/reference.conf: -------------------------------------------------------------------------------- 1 | # Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 2 | play { 3 | soap { 4 | debugLog = false 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-scala-future/test: -------------------------------------------------------------------------------- 1 | # Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 2 | 3 | > +test 4 | > checkServiceClients 5 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/multiple-ports/test: -------------------------------------------------------------------------------- 1 | # Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 2 | 3 | > +compile 4 | $ exists target/wsdl/main/sources/net/webservicex/StockQuote.scala 5 | -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/plugin/cli.adoc: -------------------------------------------------------------------------------- 1 | = Сommand Line Interface 2 | 3 | Use https://cxf.apache.org/docs/wsdl-to-java.html[wsdl2java] with options: 4 | [,cmd] 5 | ---- 6 | export CLASSPATH=../../play-soap-plugin.jar 7 | wsdl2java -fe play '-xjc-Xplay:lang java' '-xjc-Xplay:target play' helloWorld.wsdl 8 | ---- -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/multiple-ports/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | addSbtPlugin("org.playframework" % "sbt-play-soap" % sys.props("project.version")) 5 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/incremental-compilation/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | addSbtPlugin("org.playframework" % "sbt-play-soap" % sys.props("project.version")) 5 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | push: 5 | branches: # Snapshots 6 | - main 7 | tags: ["**"] # Releases 8 | 9 | jobs: 10 | publish-artifacts: 11 | name: Publish / Artifacts 12 | uses: playframework/.github/.github/workflows/publish.yml@v3 13 | secrets: inherit 14 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-scala-future/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | addSbtPlugin("org.playframework" % "sbt-play-soap" % sys.props("project.version")) 5 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-play-java-future/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | addSbtPlugin("org.playframework" % "sbt-play-soap" % sys.props("project.version")) 5 | -------------------------------------------------------------------------------- /docs/local-antora-playbook.yml: -------------------------------------------------------------------------------- 1 | site: 2 | title: Play SOAP 3 | start_page: index.adoc 4 | content: 5 | sources: 6 | - url: ../ 7 | branches: HEAD 8 | start_paths: docs 9 | ui: 10 | bundle: 11 | url: https://github.com/playframework/play-antora-ui/releases/latest/download/ui-bundle.zip 12 | snapshot: true 13 | 14 | antora: 15 | extensions: 16 | - require: '@antora/lunr-extension' 17 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/multiple-ports/build.sbt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | scalaVersion := sys.props("scala.version") 5 | crossScalaVersions := sys.props("scala.crossVersions").split(",").toSeq 6 | 7 | libraryDependencies += "org.playframework" %% "play" % play.core.PlayVersion.current 8 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/incremental-compilation/project/Constants.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | object Constants { 5 | // scripted swallows double quotes, so can't use them in a set command, so need to refer to a constant if you want 6 | // to set a string 7 | val comExample = "com.example" 8 | } 9 | -------------------------------------------------------------------------------- /docs/modules/ROOT/nav.adoc: -------------------------------------------------------------------------------- 1 | * xref:index.adoc[About] 2 | 3 | * xref:highlights.adoc[What's new?] 4 | 5 | .Plugin 6 | * xref:plugin/how-to-use.adoc[How To Use] 7 | ** xref:plugin/maven.adoc[Maven] 8 | ** xref:plugin/gradle.adoc[Gradle] 9 | ** xref:plugin/sbt.adoc[SBT] 10 | ** xref:plugin/cli.adoc[CLI] 11 | 12 | .Client 13 | * xref:client/play-soap-client.adoc[Using a Play SOAP client] 14 | * xref:client/handlers.adoc[Using JAX WS Handlers] 15 | * xref:client/security.adoc[Security] 16 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-play-java-future/app/play/soap/testservice/HelloException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.testservice; 5 | 6 | public class HelloException extends Exception { 7 | 8 | public HelloException() { 9 | } 10 | 11 | public HelloException(String msg) { 12 | super(msg); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-scala-future/app/play/soap/testservice/HelloException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.testservice; 5 | 6 | public class HelloException extends Exception { 7 | 8 | public HelloException() { 9 | } 10 | 11 | public HelloException(String msg) { 12 | super(msg); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-scala-future/app/play/soap/testservice/Hello.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.testservice; 5 | 6 | public class Hello { 7 | private User user; 8 | 9 | public User getUser() { 10 | return user; 11 | } 12 | 13 | public void setUser(User user) { 14 | this.user = user; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-play-java-future/app/play/soap/testservice/Hello.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.testservice; 5 | 6 | public class Hello { 7 | private User user; 8 | 9 | public User getUser() { 10 | return user; 11 | } 12 | 13 | public void setUser(User user) { 14 | this.user = user; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-scala-future/app/play/soap/testservice/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.testservice; 5 | 6 | public class User { 7 | private String name; 8 | 9 | public String getName() { 10 | return name; 11 | } 12 | 13 | public void setName(String name) { 14 | this.name = name; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-play-java-future/app/play/soap/testservice/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.testservice; 5 | 6 | public class User { 7 | private String name; 8 | 9 | public String getName() { 10 | return name; 11 | } 12 | 13 | public void setName(String name) { 14 | this.name = name; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /plugin/src/main/java/play/soap/plugin/PlayPortMethodNameGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.plugin; 5 | 6 | import org.apache.cxf.tools.common.model.JavaPort; 7 | 8 | public class PlayPortMethodNameGenerator { 9 | public String transform(JavaPort port) { 10 | return port.getName().substring(0, 1).toLowerCase() + port.getName().substring(1); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.github/workflows/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name: Release Drafter 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | update_release_draft: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: release-drafter/release-drafter@v6 13 | with: 14 | name: "Play SOAP $RESOLVED_VERSION" 15 | config-name: release-drafts/increasing-patch-version.yml # located in .github/ in the default branch within this or the .github repo 16 | commitish: ${{ github.ref_name }} 17 | env: 18 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 19 | -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/highlights.adoc: -------------------------------------------------------------------------------- 1 | = What's new in Play SOAP 2.x 2 | 3 | == CXF 4.0 4 | We have upgraded CXF to the next major version, `4.0`. Because CXF `4.0` is based on https://jakarta.ee/specifications/platform/9.1/[JakartaEE 9.1], all references to the `javax.\*` classpath needed to be migrated to `jakarta.*`. For more details, see the https://cxf.apache.org/docs/40-migration-guide.html[CXF 4.0 release notes] 5 | 6 | == Java 11 7 | In order to support CXF `4.0`, Play SOAP 2.x now requires Java 11. https://cxf.apache.org/docs/35-migration-guide.html[CXF 3.5] is the last major release of CXF that supported Java 8. 8 | -------------------------------------------------------------------------------- /client/src/test/java/play/soap/mockservice/SomeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.mockservice; 5 | 6 | public class SomeException extends Exception { 7 | public SomeException() {} 8 | 9 | public SomeException(String message) { 10 | super(message); 11 | } 12 | 13 | public SomeException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | 17 | public SomeException(Throwable cause) { 18 | super(cause); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /.scalafmt.conf: -------------------------------------------------------------------------------- 1 | runner.dialect = scala213 2 | align.preset = true 3 | assumeStandardLibraryStripMargin = true 4 | danglingParentheses.preset = true 5 | docstrings.style = Asterisk 6 | docstrings.removeEmpty = true 7 | maxColumn = 120 8 | project.git = true 9 | rewrite.rules = [ AvoidInfix, ExpandImportSelectors, RedundantParens, SortModifiers, PreferCurlyFors ] 10 | rewrite.sortModifiers.order = [ "private", "protected", "final", "sealed", "abstract", "implicit", "override", "lazy" ] 11 | spaces.inImportCurlyBraces = true # more idiomatic to include whitepsace in import x.{ yyy } 12 | trailingCommas = preserve 13 | version = 3.10.2 14 | -------------------------------------------------------------------------------- /.github/release-drafts/increasing-patch-version.yml: -------------------------------------------------------------------------------- 1 | _extends: .github:.github/release-drafts/increasing-patch-version.yml 2 | categories: 3 | - title: ':rocket: Features' 4 | labels: 5 | - 'enhancement' 6 | - title: ':bug: Bug Fixes' 7 | labels: 8 | - 'bug' 9 | - title: ':toolbox: Maintenance' 10 | labels: 11 | - 'maintenance' 12 | - title: ':dart: Dependencies' 13 | labels: 14 | - 'dependencies' 15 | 16 | header: | 17 | # :mega: Play SOAP $NEXT_PATCH_VERSION released! 18 | 19 | We are pleased to announce the release of SOAP module for [Play](https://playframework.org/) framework. 20 | 21 | template: | 22 | ## :green_book: What’s Changed 23 | 24 | $CHANGES 25 | -------------------------------------------------------------------------------- /client/src/test/java/play/soap/mockservice/MockService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.mockservice; 5 | 6 | import jakarta.jws.WebService; 7 | import jakarta.xml.ws.Holder; 8 | 9 | @WebService 10 | public interface MockService { 11 | 12 | public Bar getBar(Foo foo); 13 | 14 | public int add(int a, int b); 15 | 16 | public String multiReturn(Holder part, String toSplit, int index); 17 | 18 | public void noReturn(String nothing); 19 | 20 | public String declaredException() throws SomeException; 21 | 22 | public String runtimeException(); 23 | } 24 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | 5 | addSbtPlugin("com.github.sbt" % "sbt-header" % "5.11.0") 6 | addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.6") 7 | addSbtPlugin("com.github.sbt" % "sbt-java-formatter" % "0.10.0") 8 | addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.11.2") 9 | addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.11.4") 10 | addSbtPlugin("io.paymenthighway.sbt" % "sbt-cxf" % "1.7") 11 | addSbtPlugin("net.aichler" % "sbt-jupiter-interface" % "0.11.1") 12 | -------------------------------------------------------------------------------- /.github/workflows/dependency-graph.yml: -------------------------------------------------------------------------------- 1 | name: Dependency Graph 2 | on: 3 | push: 4 | branches: 5 | - main 6 | 7 | concurrency: 8 | # Only run once for latest commit per ref and cancel other (previous) runs. 9 | group: dependency-graph-${{ github.ref }} 10 | cancel-in-progress: true 11 | 12 | permissions: 13 | contents: write # this permission is needed to submit the dependency graph 14 | 15 | jobs: 16 | dependency-graph: 17 | name: Submit dependencies to GitHub 18 | runs-on: ubuntu-latest 19 | steps: 20 | - uses: actions/checkout@v5 21 | with: 22 | fetch-depth: 0 23 | ref: ${{ inputs.ref }} 24 | - uses: sbt/setup-sbt@v1 25 | - uses: scalacenter/sbt-dependency-submission@v3 26 | -------------------------------------------------------------------------------- /client/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | %date{"yyyy-MM-dd'T'HH:mm:ss.SSSZ"} %level %logger [%mdc] - %msg%n 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/plugin/gradle.adoc: -------------------------------------------------------------------------------- 1 | = Gradle 2 | 3 | Example using `play-soap-plugin` with https://plugins.gradle.org/plugin/no.nils.wsdl2java[wsdl2java] gradle plugin: 4 | 5 | Add the following dependencies and plugin configuration to your `build.gradle` file. Additional arguments needed to generate java classes for our web-service WSDLs should be added to the `wsdl2java` block. 6 | 7 | [,groovy] 8 | ---- 9 | plugins { 10 | id "no.nils.wsdl2java" version "0.12" 11 | } 12 | 13 | dependencies { 14 | wsdl2java( 15 | [group: 'org.playframework', name: 'play-soap-plugin', version: '2.0.0'] 16 | ) 17 | } 18 | 19 | wsdl2java { 20 | wsdlsToGenerate = [ 21 | ['-fe', 'play', '-xjc-Xplay:lang java', '-xjc-Xplay:target play', "${projectDir}/src/main/resources/helloWorld.wsdl"] 22 | ] 23 | } 24 | ---- 25 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-play-java-future/app/play/soap/testservice/HelloWorld.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.testservice; 5 | 6 | import javax.jws.WebParam; 7 | import javax.jws.WebService; 8 | import java.util.List; 9 | 10 | @WebService 11 | public interface HelloWorld { 12 | public String sayHello(@WebParam(name = "name") String name); 13 | 14 | public List sayHelloToMany(@WebParam(name = "names") List names); 15 | 16 | public Hello sayHelloToUser(@WebParam(name = "user") User user); 17 | 18 | public String sayHelloException(@WebParam(name = "name") String name) throws HelloException; 19 | 20 | public void dontSayHello(); 21 | } 22 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-scala-future/app/play/soap/testservice/HelloWorld.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.testservice; 5 | 6 | import javax.jws.WebParam; 7 | import javax.jws.WebService; 8 | import java.util.List; 9 | 10 | @WebService 11 | public interface HelloWorld { 12 | public String sayHello(@WebParam(name = "name") String name); 13 | 14 | public List sayHelloToMany(@WebParam(name = "names") List names); 15 | 16 | public Hello sayHelloToUser(@WebParam(name = "user") User user); 17 | 18 | public String sayHelloException(@WebParam(name = "name") String name) throws HelloException; 19 | 20 | public void dontSayHello(); 21 | } 22 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-play-java-future/build.sbt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | scalaVersion := sys.props("scala.version") 5 | crossScalaVersions := sys.props("scala.crossVersions").split(",").toSeq 6 | 7 | lazy val root = (project in file(".")).enablePlugins(PlayJava) 8 | 9 | javacOptions ++= Seq("--release", "11") 10 | 11 | WsdlKeys.futureApi := WsdlKeys.PlayJavaFutureApi 12 | 13 | WsdlKeys.packageName := Some("play.soap.testservice.client") 14 | 15 | libraryDependencies ++= Seq( 16 | "org.apache.cxf" % "cxf-rt-transports-http" % sys.props("cxf.version") % "test", 17 | "org.apache.cxf" % "cxf-rt-transports-http-jetty" % sys.props("cxf.version") % "test" 18 | ) 19 | 20 | Test / scalaSource := baseDirectory.value / "tests" 21 | -------------------------------------------------------------------------------- /plugin/src/main/java/play/soap/plugin/PlayGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.plugin; 5 | 6 | /** Adds common attributes for all source generation templates */ 7 | public interface PlayGenerator { 8 | 9 | /** The name of the plugin */ 10 | String NAME = "Play SOAP"; 11 | 12 | default String version() { 13 | return PlayGenerator.class.getPackage().getImplementationVersion(); 14 | } 15 | 16 | /** Set the Play attributes */ 17 | default void setPlayAttributes() { 18 | setAttribute("version", version()); 19 | setAttribute("fullversion", NAME + " " + version()); 20 | setAttribute("name", NAME); 21 | setAttribute("generatorclass", "PlayGenerator"); 22 | } 23 | 24 | /** Set an attribute */ 25 | void setAttribute(String name, Object value); 26 | } 27 | -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/plugin/sbt.adoc: -------------------------------------------------------------------------------- 1 | = SBT 2 | 3 | Example using `play-soap-plugin` with https://github.com/PaymentHighway/sbt-cxf[sbt-cxf plugin] 4 | 5 | Add dependency and plugin into your project in `project/plugins.sbt`: 6 | 7 | [,scala] 8 | ---- 9 | libraryDependencies ++= Seq("org.playframework" % "play-soap-plugin" % "2.0.0") 10 | 11 | addSbtPlugin("io.paymenthighway.sbt" % "sbt-cxf" % "1.7") 12 | ---- 13 | 14 | Add the plugin configuration to the `build.sbt` file. Additional arguments needed to generate java classes for our web-service WSDLs should be added as parameters to the `cxfWSDLs` setting: 15 | 16 | [,scala] 17 | ---- 18 | enablePlugins(CxfPlugin) 19 | 20 | val CxfVersion = "4.0.8" 21 | 22 | CXF / version := CxfVersion 23 | 24 | cxfWSDLs := Seq( 25 | Wsdl( 26 | "HelloWorld", 27 | (Compile / resourceDirectory).value / "helloWorld.wsdl", 28 | Seq("-fe", "play", "-xjc-Xplay:lang scala", "-xjc-Xplay:target play") 29 | ) 30 | ) 31 | ---- 32 | -------------------------------------------------------------------------------- /client/src/test/java/play/soap/mockservice/MockServiceJava.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.mockservice; 5 | 6 | import jakarta.jws.WebService; 7 | import jakarta.xml.ws.Action; 8 | import jakarta.xml.ws.FaultAction; 9 | import jakarta.xml.ws.Holder; 10 | import java.util.concurrent.CompletionStage; 11 | 12 | @WebService(name = "MockService") 13 | public interface MockServiceJava { 14 | 15 | CompletionStage getBar(Foo foo); 16 | 17 | CompletionStage add(int a, int b); 18 | 19 | CompletionStage multiReturn(Holder part, String toSplit, int index); 20 | 21 | CompletionStage noReturn(String nothing); 22 | 23 | @Action(fault = {@FaultAction(className = SomeException.class)}) 24 | CompletionStage declaredException() throws SomeException; 25 | 26 | CompletionStage runtimeException(); 27 | } 28 | -------------------------------------------------------------------------------- /client/src/test/java/play/soap/mockservice/MockServiceScala.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.mockservice; 5 | 6 | import jakarta.jws.WebService; 7 | import jakarta.xml.ws.Action; 8 | import jakarta.xml.ws.FaultAction; 9 | import jakarta.xml.ws.Holder; 10 | import scala.Unit; 11 | import scala.concurrent.Future; 12 | 13 | @WebService(name = "MockService") 14 | public interface MockServiceScala { 15 | 16 | public Future getBar(Foo foo); 17 | 18 | public Future add(int a, int b); 19 | 20 | public Future multiReturn(Holder part, String toSplit, int index); 21 | 22 | public Future noReturn(String nothing); 23 | 24 | @Action(fault = {@FaultAction(className = SomeException.class)}) 25 | public Future declaredException() throws SomeException; 26 | 27 | public Future runtimeException(); 28 | } 29 | -------------------------------------------------------------------------------- /.github/workflows/build-test.yml: -------------------------------------------------------------------------------- 1 | name: Check 2 | 3 | on: 4 | pull_request: 5 | 6 | push: 7 | branches: 8 | - main # Check branch after merge 9 | 10 | concurrency: 11 | # Only run once for latest commit per ref and cancel other (previous) runs. 12 | group: ci-${{ github.ref }} 13 | cancel-in-progress: true 14 | 15 | jobs: 16 | check-code-style: 17 | name: Code Style 18 | uses: playframework/.github/.github/workflows/cmd.yml@v3 19 | with: 20 | cmd: sbt validateCode 21 | 22 | check-docs: 23 | name: Docs 24 | uses: playframework/.github/.github/workflows/antora.yml@v3 25 | with: 26 | path: "./docs" 27 | 28 | tests: 29 | name: Tests 30 | needs: 31 | - "check-code-style" 32 | - "check-docs" 33 | uses: playframework/.github/.github/workflows/cmd.yml@v3 34 | with: 35 | cmd: sbt +test 36 | 37 | finish: 38 | name: Finish 39 | if: github.event_name == 'pull_request' 40 | needs: # Should be last 41 | - "tests" 42 | uses: playframework/.github/.github/workflows/rtm.yml@v3 43 | -------------------------------------------------------------------------------- /plugin/src/main/resources/META-INF/tools-plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /client/src/main/scala/play/soap/PlayJaxwsClientCallback.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap 5 | 6 | import java.util 7 | 8 | import org.apache.cxf.endpoint.ClientCallback 9 | 10 | import scala.concurrent.Promise 11 | 12 | /** 13 | * A client callback based on a promise 14 | * 15 | * @param promise 16 | * The promise 17 | * @param noResponseValue 18 | * If no response comes back, redeem the future with this value 19 | */ 20 | private[soap] class PlayJaxwsClientCallback(promise: Promise[Any], noResponseValue: Any = null) extends ClientCallback { 21 | override def handleResponse(ctx: util.Map[String, AnyRef], response: Array[AnyRef]) = { 22 | // If there's no return value, the response will be null 23 | if (response != null) { 24 | promise.trySuccess(response(0)) 25 | } else { 26 | promise.trySuccess(noResponseValue) 27 | } 28 | } 29 | 30 | override def handleException(ctx: util.Map[String, AnyRef], ex: Throwable) = { 31 | promise.tryFailure(ex) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /client/src/test/java/play/soap/mockservice/MockServiceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.mockservice; 5 | 6 | import jakarta.jws.WebService; 7 | import jakarta.xml.ws.Holder; 8 | 9 | @WebService(endpointInterface = "play.soap.mockservice.MockService") 10 | public class MockServiceImpl implements MockService { 11 | public Bar getBar(Foo foo) { 12 | return new Bar(foo, "bar"); 13 | } 14 | 15 | public int add(int a, int b) { 16 | return a + b; 17 | } 18 | 19 | public String multiReturn(Holder part, String toSplit, int index) { 20 | String first = toSplit.substring(0, index); 21 | String second = toSplit.substring(index); 22 | part.value = second; 23 | return first; 24 | } 25 | 26 | public void noReturn(String nothing) { 27 | System.out.println("Received " + nothing); 28 | } 29 | 30 | public String declaredException() throws SomeException { 31 | throw new SomeException("an error occurred"); 32 | } 33 | 34 | public String runtimeException() { 35 | throw new RuntimeException("an error occurred"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /plugin/src/main/java/play/soap/plugin/FutureApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.plugin; 5 | 6 | /** The future API */ 7 | public interface FutureApi { 8 | 9 | /** 10 | * The fully qualify class name of the future API 11 | * 12 | * @return {@link String} 13 | */ 14 | String fqn(); 15 | 16 | /** 17 | * The type that the future returns if the method returns void 18 | * 19 | * @return {@link String} 20 | */ 21 | String voidType(); 22 | 23 | /** The Play Java Promise API */ 24 | class JavaFuture implements FutureApi { 25 | 26 | @Override 27 | public String fqn() { 28 | return "java.util.concurrent.CompletionStage"; 29 | } 30 | 31 | @Override 32 | public String voidType() { 33 | return "Void"; 34 | } 35 | } 36 | 37 | /** The Play Scala Promise API */ 38 | class ScalaFuture implements FutureApi { 39 | 40 | @Override 41 | public String fqn() { 42 | return "scala.concurrent.Future"; 43 | } 44 | 45 | @Override 46 | public String voidType() { 47 | return "scala.Unit"; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/plugin/how-to-use.adoc: -------------------------------------------------------------------------------- 1 | = How To Use 2 | 3 | Play SOAP Plugin is a plugin module to JAXB that converts WSDLs into SOAP client interfaces for work with asynchronous requests. 4 | 5 | Start by adding the dependency `play-soap-plugin` to the project and set required WSDL options: 6 | 7 | 8 | [cols="4*^",options=header] 9 | |=== 10 | |Option |Accepted values |Required |Interpretation 11 | 12 | |-fe |play |true |Specifies the frontend to enable `play-soap-plugin` 13 | 14 | |-xjc-Xplay:lang 15 | |scala, java |true |Generate the future type to wrap an original type. 16 | 17 | `scala` - `scala.concurrent.Future` for Scala projects. 18 | 19 | `java` - `java.util.concurrent.CompletionStage` for Java projects. 20 | |-xjc-Xplay:target 21 | |play |false |Generates SOAP client classes for the specified framework. 22 | 23 | `play` - Play Framework 24 | |=== 25 | 26 | Additional documentation on WSDL2JAVA options can be found 27 | https://cxf.apache.org/docs/wsdl-to-java.html[here]. 28 | 29 | For better workflow integration, consider integrating the module into one of these supported build tools (https://maven.apache.org/[maven], https://gradle.org/[gradle] and https://www.scala-sbt.org/[sbt]). A direct command line interface is also available. 30 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/incremental-compilation/build.sbt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | scalaVersion := sys.props("scala.version") 5 | crossScalaVersions := sys.props("scala.crossVersions").split(",").toSeq 6 | 7 | libraryDependencies += "org.playframework" %% "play" % play.core.PlayVersion.current 8 | 9 | InputKey[Unit]("contains") := { 10 | val args = Def.spaceDelimited(" ").parsed 11 | val base: File = baseDirectory.value 12 | val file = args(0) 13 | val check = args.tail.mkString(" ") 14 | val contents = IO.read(base / file) 15 | if (!contents.contains(check)) { 16 | throw new RuntimeException(s"Could not find '$check' in '$contents'") with FeedbackProvidedException 17 | } 18 | } 19 | 20 | InputKey[Unit]("replace") := { 21 | val args = Def.spaceDelimited(" ").parsed 22 | val base: File = baseDirectory.value 23 | val file = args(0) 24 | val word = args(1) 25 | val replacement = args(2) 26 | val contents = IO.read(base / file) 27 | IO.write(base / file, contents.replaceAll(word, replacement)) 28 | } 29 | -------------------------------------------------------------------------------- /client/src/test/java/play/soap/mockservice/Foo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.mockservice; 5 | 6 | public class Foo { 7 | private long id; 8 | private String name; 9 | 10 | public Foo() {} 11 | 12 | public Foo(long id, String name) { 13 | this.id = id; 14 | this.name = name; 15 | } 16 | 17 | public long getId() { 18 | return id; 19 | } 20 | 21 | public void setId(long id) { 22 | this.id = id; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public void setName(String name) { 30 | this.name = name; 31 | } 32 | 33 | @Override 34 | public boolean equals(Object o) { 35 | if (this == o) return true; 36 | if (o == null || getClass() != o.getClass()) return false; 37 | 38 | Foo foo = (Foo) o; 39 | 40 | if (id != foo.id) return false; 41 | if (name != null ? !name.equals(foo.name) : foo.name != null) return false; 42 | 43 | return true; 44 | } 45 | 46 | @Override 47 | public int hashCode() { 48 | int result = (int) (id ^ (id >>> 32)); 49 | result = 31 * result + (name != null ? name.hashCode() : 0); 50 | return result; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /client/src/test/java/play/soap/mockservice/Bar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.mockservice; 5 | 6 | public class Bar { 7 | 8 | private Foo foo; 9 | private String name; 10 | 11 | public Bar() {} 12 | 13 | public Bar(Foo foo, String name) { 14 | this.foo = foo; 15 | this.name = name; 16 | } 17 | 18 | public Foo getFoo() { 19 | return foo; 20 | } 21 | 22 | public void setFoo(Foo foo) { 23 | this.foo = foo; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | @Override 35 | public boolean equals(Object o) { 36 | if (this == o) return true; 37 | if (o == null || getClass() != o.getClass()) return false; 38 | 39 | Bar bar = (Bar) o; 40 | 41 | if (foo != null ? !foo.equals(bar.foo) : bar.foo != null) return false; 42 | if (name != null ? !name.equals(bar.name) : bar.name != null) return false; 43 | 44 | return true; 45 | } 46 | 47 | @Override 48 | public int hashCode() { 49 | int result = foo != null ? foo.hashCode() : 0; 50 | result = 31 * result + (name != null ? name.hashCode() : 0); 51 | return result; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /client/src/main/scala/play/soap/PlayJaxWsServiceFactoryBean.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap 5 | 6 | import java.lang.reflect.Method 7 | 8 | import org.apache.cxf.jaxws.support.JaxWsImplementorInfo 9 | import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean 10 | import org.apache.cxf.service.model.OperationInfo 11 | 12 | private[soap] class PlayJaxWsServiceFactoryBean extends JaxWsServiceFactoryBean { 13 | 14 | /** 15 | * Massive hack here. We want to register Future as a holder type, to do this we add a custom 16 | * AbstractServiceConfiguration. However, JaxWsServiceFactorBean, whenever setJaxWsImplementorInfo is invoked, injects 17 | * its own configuration in the first place, and its isHolder method only returns true for javax.xml.ws.Holder, and 18 | * does not return null for other types (null is used to indicate to move to the next configuration in the chain). 19 | * Consequently, we must inject our configuration after setJaxWsImplementorInfo is invoked, otherwise it will take no 20 | * effect. 21 | */ 22 | override def setJaxWsImplementorInfo(jaxWsImplementorInfo: JaxWsImplementorInfo) = { 23 | super.setJaxWsImplementorInfo(jaxWsImplementorInfo) 24 | 25 | getConfigurations.add(0, new PlayServiceConfiguration) 26 | } 27 | 28 | override def bindOperation(op: OperationInfo, method: Method) = super.bindOperation(op, method) 29 | } 30 | -------------------------------------------------------------------------------- /common.sbt: -------------------------------------------------------------------------------- 1 | // Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 2 | 3 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// 4 | // NOTE: !!! THIS IS A COPY !!! // 5 | // To edit this file use the main version in https://github.com/playframework/.github/blob/main/sbt/common.sbt // 6 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// 7 | 8 | /** 9 | * If you need extra commands to format source code or other documents, add following line to your `build.sbt` 10 | * {{{ 11 | * val _ = sys.props += ("sbt_formatCode" -> List("", "",...).mkString(";")) 12 | * }}} 13 | */ 14 | addCommandAlias( 15 | "formatCode", 16 | List( 17 | "headerCreateAll", 18 | "scalafmtSbt", 19 | "scalafmtAll", 20 | "javafmtAll" 21 | ).mkString(";") + sys.props.get("sbt_formatCode").map(";" + _).getOrElse("") 22 | ) 23 | 24 | /** 25 | * If you need extra commands to validate source code or other documents, add following line to your `build.sbt` 26 | * {{{ 27 | * val _ = sys.props += ("sbt_validateCode" -> List("", "",...).mkString(";")) 28 | * }}} 29 | */ 30 | addCommandAlias( 31 | "validateCode", 32 | List( 33 | "headerCheckAll", 34 | "scalafmtSbtCheck", 35 | "scalafmtCheckAll", 36 | "javafmtCheckAll" 37 | ).mkString(";") + sys.props.get("sbt_validateCode").map(";" + _).getOrElse("") 38 | ) 39 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-scala-future/build.sbt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | scalaVersion := sys.props("scala.version") 5 | crossScalaVersions := sys.props("scala.crossVersions").split(",").toSeq 6 | 7 | lazy val root = (project in file(".")).enablePlugins(PlayScala) 8 | 9 | javacOptions ++= Seq("--release", "11") 10 | 11 | WsdlKeys.packageName := Some("play.soap.testservice.client") 12 | 13 | libraryDependencies ++= Seq( 14 | specs2, 15 | "org.apache.cxf" % "cxf-rt-transports-http" % sys.props("cxf.version") % "test", 16 | "org.apache.cxf" % "cxf-rt-transports-http-jetty" % sys.props("cxf.version") % "test" 17 | ) 18 | 19 | Test / scalaSource := baseDirectory.value / "tests" 20 | 21 | TaskKey[Unit]("checkServiceClients") := { 22 | val path = target.value / "wsdl" / "main" / "sources" / "play" / "soap" / "testservice" / "client" 23 | val tests: Seq[(String, String)] = Seq( 24 | ( 25 | "HelloWorldService.scala", 26 | "createPort[HelloWorld](new QName(\"http://testservice.soap.play/\"), \"HelloWorld\", \"http://localhost:53915/helloWorld\")" 27 | ), 28 | ( 29 | "PrimitivesService.scala", 30 | "createPort[Primitives](new QName(\"http://testservice.soap.play/primitives\"), \"Primitives\", \"http://localhost:53916/primitives\")" 31 | ) 32 | ) 33 | for ((filename, expectedString) <- tests) { 34 | val f = path / filename 35 | println(s"Checking $f for $expectedString") 36 | val contents = IO.read(f) 37 | if (!contents.contains(expectedString)) sys.error(s"File $f didn't contain: $expectedString") 38 | } 39 | () 40 | } 41 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-scala-future/app/play/soap/testservice/Primitives.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.testservice; 5 | 6 | import javax.jws.WebParam; 7 | import javax.jws.WebService; 8 | import java.util.List; 9 | 10 | /* 11 | * THIS FILE IS AUTO GENERATED. DO NOT EDIT THIS FILE MANUALLY. 12 | * 13 | * Run 'generate-primitives.py' to regenerate it. 14 | */ 15 | 16 | @WebService(targetNamespace = "http://testservice.soap.play/primitives") 17 | public interface Primitives { 18 | public boolean booleanOp(@WebParam(name = "x") boolean x); 19 | public java.util.List booleanSequence(@WebParam(name = "xs") boolean xs); 20 | 21 | public byte byteOp(@WebParam(name = "x") byte x); 22 | public java.util.List byteSequence(@WebParam(name = "xs") byte xs); 23 | 24 | public double doubleOp(@WebParam(name = "x") double x); 25 | public java.util.List doubleSequence(@WebParam(name = "xs") double xs); 26 | 27 | public float floatOp(@WebParam(name = "x") float x); 28 | public java.util.List floatSequence(@WebParam(name = "xs") float xs); 29 | 30 | public int intOp(@WebParam(name = "x") int x); 31 | public java.util.List intSequence(@WebParam(name = "xs") int xs); 32 | 33 | public long longOp(@WebParam(name = "x") long x); 34 | public java.util.List longSequence(@WebParam(name = "xs") long xs); 35 | 36 | public short shortOp(@WebParam(name = "x") short x); 37 | public java.util.List shortSequence(@WebParam(name = "xs") short xs); 38 | 39 | } -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-play-java-future/app/play/soap/testservice/Primitives.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.testservice; 5 | 6 | import javax.jws.WebParam; 7 | import javax.jws.WebService; 8 | import java.util.List; 9 | 10 | /* 11 | * THIS FILE IS AUTO GENERATED. DO NOT EDIT THIS FILE MANUALLY. 12 | * 13 | * Run 'generate-primitives.py' to regenerate it. 14 | */ 15 | 16 | @WebService(targetNamespace = "http://testservice.soap.play/primitives") 17 | public interface Primitives { 18 | public boolean booleanOp(@WebParam(name = "x") boolean x); 19 | public java.util.List booleanSequence(@WebParam(name = "xs") boolean xs); 20 | 21 | public byte byteOp(@WebParam(name = "x") byte x); 22 | public java.util.List byteSequence(@WebParam(name = "xs") byte xs); 23 | 24 | public double doubleOp(@WebParam(name = "x") double x); 25 | public java.util.List doubleSequence(@WebParam(name = "xs") double xs); 26 | 27 | public float floatOp(@WebParam(name = "x") float x); 28 | public java.util.List floatSequence(@WebParam(name = "xs") float xs); 29 | 30 | public int intOp(@WebParam(name = "x") int x); 31 | public java.util.List intSequence(@WebParam(name = "xs") int xs); 32 | 33 | public long longOp(@WebParam(name = "x") long x); 34 | public java.util.List longSequence(@WebParam(name = "xs") long xs); 35 | 36 | public short shortOp(@WebParam(name = "x") short x); 37 | public java.util.List shortSequence(@WebParam(name = "xs") short xs); 38 | 39 | } -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-scala-future/app/play/soap/testservice/HelloWorldImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.testservice; 5 | 6 | import javax.jws.WebParam; 7 | import javax.jws.WebService; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | @WebService(endpointInterface = "play.soap.testservice.HelloWorld", 12 | serviceName = "HelloWorldService", portName = "HelloWorld") 13 | public class HelloWorldImpl implements HelloWorld { 14 | @Override 15 | public String sayHello(@WebParam(name = "name") String name) { 16 | System.out.println("Say hello invoked with " + name); 17 | return "Hello " + name; 18 | } 19 | 20 | @Override 21 | public List sayHelloToMany(@WebParam(name = "names") List names) { 22 | System.out.println("Say hello to many invoked with " + names); 23 | List hellos = new ArrayList(names.size()); 24 | for (String name: names) { 25 | hellos.add("Hello " + name); 26 | } 27 | return hellos; 28 | } 29 | 30 | @Override 31 | public Hello sayHelloToUser(@WebParam(name = "user") User user) { 32 | System.out.println("Say hello to user invoked with " + user.getName()); 33 | Hello hello = new Hello(); 34 | hello.setUser(user); 35 | return hello; 36 | } 37 | 38 | @Override 39 | public String sayHelloException(@WebParam(name = "name") String name) throws HelloException { 40 | throw new HelloException("Hello " + name); 41 | } 42 | 43 | @Override 44 | public void dontSayHello() { 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-play-java-future/app/play/soap/testservice/HelloWorldImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.testservice; 5 | 6 | import javax.jws.WebParam; 7 | import javax.jws.WebService; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | @WebService(endpointInterface = "play.soap.testservice.HelloWorld", 12 | serviceName = "HelloWorldService", portName = "HelloWorld") 13 | public class HelloWorldImpl implements HelloWorld { 14 | @Override 15 | public String sayHello(@WebParam(name = "name") String name) { 16 | System.out.println("Say hello invoked with " + name); 17 | return "Hello " + name; 18 | } 19 | 20 | @Override 21 | public List sayHelloToMany(@WebParam(name = "names") List names) { 22 | System.out.println("Say hello to many invoked with " + names); 23 | List hellos = new ArrayList(names.size()); 24 | for (String name: names) { 25 | hellos.add("Hello " + name); 26 | } 27 | return hellos; 28 | } 29 | 30 | @Override 31 | public Hello sayHelloToUser(@WebParam(name = "user") User user) { 32 | System.out.println("Say hello to user invoked with " + user.getName()); 33 | Hello hello = new Hello(); 34 | hello.setUser(user); 35 | return hello; 36 | } 37 | 38 | @Override 39 | public String sayHelloException(@WebParam(name = "name") String name) throws HelloException { 40 | throw new HelloException("Hello " + name); 41 | } 42 | 43 | @Override 44 | public void dontSayHello() { 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/server/src/main/java/play/soap/test/primitives/PrimitivesImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.test.primitives; 5 | 6 | import jakarta.jws.WebService; 7 | import java.util.List; 8 | 9 | @WebService( 10 | serviceName = "PrimitivesService", 11 | portName = "Primitives", 12 | targetNamespace = "http://testservice.soap.play/primitives", 13 | wsdlLocation = "wsdl/primitives.wsdl", 14 | endpointInterface = "play.soap.test.primitives.Primitives") 15 | public class PrimitivesImpl implements Primitives { 16 | public byte byteOp(byte x) { 17 | return x; 18 | } 19 | 20 | public double doubleOp(double x) { 21 | return x; 22 | } 23 | 24 | public List intSequence(List xs) { 25 | return xs; 26 | } 27 | 28 | public boolean booleanOp(boolean x) { 29 | return x; 30 | } 31 | 32 | public List booleanSequence(List xs) { 33 | return xs; 34 | } 35 | 36 | public List byteSequence(List xs) { 37 | return xs; 38 | } 39 | 40 | public List longSequence(List xs) { 41 | return xs; 42 | } 43 | 44 | public List doubleSequence(List xs) { 45 | return xs; 46 | } 47 | 48 | public long longOp(long x) { 49 | return x; 50 | } 51 | 52 | public int intOp(int x) { 53 | return x; 54 | } 55 | 56 | public short shortOp(short x) { 57 | return x; 58 | } 59 | 60 | public List shortSequence(List xs) { 61 | return xs; 62 | } 63 | 64 | public List floatSequence(List xs) { 65 | return xs; 66 | } 67 | 68 | public float floatOp(float x) { 69 | return x; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/incremental-compilation/test: -------------------------------------------------------------------------------- 1 | # Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 2 | 3 | # Run with one WSDL. We run products to ensure that the resources are generated 4 | 5 | > products 6 | $ exists target/wsdl/main/sources/play/soap/testservice/HelloWorldService.scala 7 | 8 | # Test that a recompile doesn't trigger the wsdl to be changed 9 | $ touch target/change1 10 | $ sleep 1100 11 | > products 12 | $ newer target/change1 target/wsdl/main/sources/play/soap/testservice/HelloWorldService.scala 13 | 14 | # Try changing the file, and make sure it's recompiled 15 | > replace src/main/wsdl/helloWorld.wsdl HelloWorldService MyHelloWorldService 16 | > products 17 | $ exists target/wsdl/main/sources/play/soap/testservice/MyHelloWorldService.scala 18 | -$ exists target/wsdl/main/sources/play/soap/testservice/HelloWorldService.scala 19 | 20 | # Add a new file make sure it gets compiled, but that the old one doesn't get recompiled 21 | $ copy-file helloWorld2.wsdl src/main/wsdl/helloWorld2.wsdl 22 | $ touch target/change2 23 | $ sleep 1100 24 | > products 25 | $ exists target/wsdl/main/sources/play/soap/testservice2/HelloWorldService.scala 26 | $ newer target/change2 target/wsdl/main/sources/play/soap/testservice/MyHelloWorldService.scala 27 | 28 | # Remove it, make sure it gets removed 29 | $ delete src/main/wsdl/helloWorld2.wsdl 30 | > products 31 | -$ exists target/wsdl/main/sources/play/soap/testservice2/HelloWorldService.scala 32 | 33 | # Change some configuration, make sure it gets recompiled 34 | > set WsdlKeys.packageName := Some(Constants.comExample) 35 | > products 36 | $ exists target/wsdl/main/sources/com/example/MyHelloWorldService.scala 37 | -$ exists target/wsdl/main/sources/play/soap/testservice/MyHelloWorldService.scala 38 | -------------------------------------------------------------------------------- /client/src/main/scala/play/soap/PlayServiceConfiguration.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap 5 | 6 | import java.lang.reflect.Method 7 | import java.lang.reflect.ParameterizedType 8 | import java.lang.reflect.Type 9 | 10 | import org.apache.cxf.wsdl.service.factory.AbstractServiceConfiguration 11 | import java.util.concurrent.CompletionStage 12 | 13 | import scala.concurrent.Future 14 | 15 | import java.lang.Boolean.FALSE 16 | 17 | private[soap] class PlayServiceConfiguration extends AbstractServiceConfiguration { 18 | 19 | /** 20 | * We say future/promise is a holder type so that JAXB will create bindings for the inner type, not the outer. 21 | */ 22 | override def isHolder(cls: Class[_], `type`: Type) = 23 | if (classOf[Future[_]] == cls || classOf[CompletionStage[_]] == cls) java.lang.Boolean.TRUE else null 24 | 25 | override def getHolderType(cls: Class[_], `type`: Type) = { 26 | if (classOf[Future[_]] == cls || classOf[CompletionStage[_]] == cls) { 27 | `type` match { 28 | case p: ParameterizedType => p.getActualTypeArguments()(0) 29 | } 30 | } else null 31 | } 32 | 33 | /** 34 | * Neither scala.Unit or java.lang.Void are output types 35 | */ 36 | override def hasOutMessage(m: Method) = { 37 | m.getGenericReturnType match { 38 | case future: ParameterizedType 39 | if future.getRawType == classOf[Future[_]] || 40 | future.getRawType == classOf[CompletionStage[_]] => 41 | future.getActualTypeArguments.headOption match { 42 | case Some(unit) if unit == classOf[Unit] || unit == classOf[Void] => FALSE 43 | case _ => null 44 | } 45 | case _ => null 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /plugin/src/main/java/play/soap/plugin/Configuration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.plugin; 5 | 6 | import java.util.Arrays; 7 | import play.soap.plugin.FutureApi.JavaFuture; 8 | import play.soap.plugin.FutureApi.ScalaFuture; 9 | 10 | public class Configuration { 11 | 12 | public static String XJC = "xjc"; 13 | public static String OPTION_PREFIX = "Xplay"; 14 | 15 | public enum Option { 16 | LANG("lang"), 17 | TARGET("target"); 18 | 19 | final String name; 20 | 21 | Option(String name) { 22 | this.name = String.format("-%s:%s", OPTION_PREFIX, name); 23 | } 24 | } 25 | 26 | public enum Lang { 27 | JAVA("java", new JavaFuture()), 28 | SCALA("scala", new ScalaFuture()); 29 | 30 | final String name; 31 | 32 | final FutureApi futureApi; 33 | 34 | Lang(String name, FutureApi futureApi) { 35 | this.name = name; 36 | this.futureApi = futureApi; 37 | } 38 | 39 | public static Lang findByName(String name) { 40 | return Arrays.stream(values()) 41 | .filter(lang -> lang.name.equals(name)) 42 | .findFirst() 43 | .orElse(null); 44 | } 45 | 46 | public static boolean exists(String name) { 47 | return findByName(name) != null; 48 | } 49 | } 50 | 51 | public enum Target { 52 | PLAY("play"); 53 | 54 | final String name; 55 | 56 | Target(String name) { 57 | this.name = name; 58 | } 59 | 60 | public static Target findByName(String name) { 61 | return Arrays.stream(values()) 62 | .filter(target -> target.name.equalsIgnoreCase(name)) 63 | .findFirst() 64 | .orElse(null); 65 | } 66 | 67 | public static boolean exists(String name) { 68 | return findByName(name) != null; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /plugin/src/main/java/play/soap/plugin/FutureGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.plugin; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * A helper used by {@link PlaySEIGenerator} to generate the correct future type to wrap a Java 11 | * type. 12 | */ 13 | public class FutureGenerator { 14 | 15 | private final FutureApi futureApi; 16 | 17 | private final Map mapping; 18 | 19 | public FutureGenerator(FutureApi futureApi) { 20 | this.futureApi = futureApi; 21 | this.mapping = 22 | new HashMap() { 23 | { 24 | put("void", futureApi.voidType()); 25 | put("boolean", "java.lang.Boolean"); 26 | put("byte", "java.lang.Byte"); 27 | put("char", "java.lang.Character"); 28 | put("double", "java.lang.Double"); 29 | put("float", "java.lang.Float"); 30 | put("int", "java.lang.Integer"); 31 | put("long", "java.lang.Long"); 32 | put("short", "java.lang.Short"); 33 | } 34 | }; 35 | } 36 | 37 | /** 38 | * Generate the correct future type that holds the given Java type. E.g. for a Java type of "void" 39 | * this could be "scala.concurrent.Future {@literal <}scala.Unit{@literal >}" or 40 | * "java.util.concurrent.CompletionStage{@literal <}Void{@literal >}". For a Java type of "int" it 41 | * could be "scala.concurrent.Future{@literal <}java.lang.Integer{@literal >}" or 42 | * "java.util.concurrent.CompletionStage{@literal <}java.lang.Integer{@literal >}" 43 | * 44 | * @param javaType The Java type to wrap. 45 | */ 46 | public String futureType(String javaType) { 47 | String type = mapping.get(javaType); 48 | String elementType = type != null ? type : javaType; 49 | return futureApi.fqn() + "<" + elementType + ">"; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/plugin/maven.adoc: -------------------------------------------------------------------------------- 1 | = Maven 2 | 3 | Example using `play-soap-plugin` with https://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html[cxf-codegen-plugin] maven plugin: 4 | 5 | Add the following dependencies and plugin configuration to your `pom.xml` file. Additional arguments needed to generate java classes for our web-service WSDLs should be added to the `` block. 6 | 7 | [,xml] 8 | ---- 9 | 10 | 11 | org.playframework 12 | play-soap-plugin 13 | ${play.soap.plugin.version} 14 | 15 | 16 | 17 | 18 | 19 | 20 | org.apache.cxf 21 | cxf-codegen-plugin 22 | ${cxf.version} 23 | 24 | 25 | generate-sources 26 | generate-sources 27 | 28 | 29 | play 30 | 31 | 32 | 33 | ${basedir}/src/main/resources/helloWorld.wsdl 34 | 35 | -xjc-Xplay:lang java 36 | -xjc-Xplay:target play 37 | 38 | 39 | 40 | 41 | 42 | wsdl2java 43 | 44 | 45 | 46 | 47 | 48 | 49 | ---- 50 | -------------------------------------------------------------------------------- /project/Common.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | import sbt.Keys._ 5 | import sbt._ 6 | import sbt.plugins.JvmPlugin 7 | import Dependencies.ScalaVersions._ 8 | import sbtheader.FileType 9 | import sbtheader.HeaderPlugin 10 | 11 | object Common extends AutoPlugin { 12 | 13 | import HeaderPlugin.autoImport._ 14 | 15 | override def trigger = allRequirements 16 | 17 | override def requires = JvmPlugin && HeaderPlugin 18 | 19 | val repoName = "play-soap" 20 | 21 | override def globalSettings = 22 | Seq( 23 | // organization 24 | organization := "org.playframework", 25 | organizationName := "The Play Framework Project", 26 | organizationHomepage := Some(url("https://playframework.com/")), 27 | // scala settings 28 | scalaVersion := scala213, 29 | scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked", "-encoding", "utf8"), 30 | javacOptions ++= Seq("-encoding", "UTF-8", "-Xlint:-options"), 31 | doc / javacOptions := Seq("-encoding", "UTF-8"), 32 | // legal 33 | licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0.html")), 34 | // on the web 35 | homepage := Some(url(s"https://github.com/playframework/${repoName}")), 36 | developers += Developer( 37 | "playframework", 38 | "The Play Framework Contributors", 39 | "contact@playframework.com", 40 | url("https://github.com/playframework") 41 | ) 42 | ) 43 | 44 | override def projectSettings = 45 | Seq( 46 | headerEmptyLine := false, 47 | headerLicense := Some( 48 | HeaderLicense.Custom( 49 | "Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. " 50 | ) 51 | ), 52 | headerMappings ++= Map( 53 | FileType("wsdl", FileType.xml.firstLinePattern) -> HeaderCommentStyle.xmlStyleBlockComment 54 | ) 55 | ) 56 | } 57 | -------------------------------------------------------------------------------- /plugin/src/main/resources/play/soap/plugin/client.vm: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | ## 4 | package $service.packageName 5 | 6 | import javax.xml.namespace.QName 7 | import jakarta.xml.ws.handler.{MessageContext, Handler} 8 | #if ($markGenerated == "true") 9 | import javax.annotation.Generated 10 | #end 11 | 12 | #foreach ($import in $service.imports) 13 | import ${import} 14 | #end 15 | /** 16 | * This class was generated by $fullversion 17 | * $currentdate 18 | * Generated source version: $version 19 | * 20 | */ 21 | #if ($markGenerated == "true") 22 | @Generated(value = "$generatorclass", date = "$currentdate", comments = "$fullversion") 23 | #end 24 | @javax.inject.Singleton 25 | class ${service.name} @javax.inject.Inject() (apacheCxfBus: play.soap.ApacheCxfBus, configuration: play.api.Configuration) extends play.soap.PlaySoapClient(apacheCxfBus, configuration) { 26 | #foreach ($port in $service.ports) 27 | 28 | #set($portClassName = ${port.interfaceClass}) 29 | #if ($portClassName == ${service.name}) 30 | #set($portClassName = ${port.fullClassName}) 31 | #end 32 | #set($portMethodName = $portMethod.transform($port)) 33 | 34 | #if ($markGenerated == "true") 35 | @Generated(value = "$generatorclass", date = "$currentdate") 36 | #end 37 | lazy val $portMethod.transform($port): $portClassName = { 38 | createPort[$portClassName](new QName("$service.namespace"), "$port.portName", "$port.bindingAdress") 39 | } 40 | 41 | #if ($markGenerated == "true") 42 | @Generated(value = "$generatorclass", date = "$currentdate") 43 | #end 44 | def $portMethod.transform($port)(handlers: Handler[_ <: MessageContext]*): $portClassName = { 45 | createPort[$portClassName](new QName("$service.namespace"), "$port.portName", "$port.bindingAdress", handlers: _*) 46 | } 47 | 48 | #if ($markGenerated == "true") 49 | @Generated(value = "$generatorclass", date = "$currentdate") 50 | #end 51 | @annotation.varargs 52 | def ${port.methodName}(handlers: Handler[_ <: MessageContext]*): $portClassName = ${portMethodName}(handlers: _*) 53 | #end 54 | } 55 | -------------------------------------------------------------------------------- /plugin/src/main/java/play/soap/plugin/PlaySEIGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.plugin; 5 | 6 | import static play.soap.plugin.Configuration.Lang.SCALA; 7 | import static play.soap.plugin.Configuration.Option.LANG; 8 | import static play.soap.plugin.Configuration.XJC; 9 | 10 | import java.io.Writer; 11 | import java.util.Arrays; 12 | import org.apache.cxf.tools.common.ToolException; 13 | import org.apache.cxf.tools.wsdlto.frontend.jaxws.generators.SEIGenerator; 14 | import play.soap.plugin.Configuration.Lang; 15 | 16 | /** Generates the Service Endpoint Interface, ie the actual thing that gets called. */ 17 | public class PlaySEIGenerator extends SEIGenerator implements PlayGenerator { 18 | 19 | @Override 20 | protected void setCommonAttributes() { 21 | super.setCommonAttributes(); 22 | setPlayAttributes(); 23 | } 24 | 25 | @Override 26 | public void setAttribute(String name, Object value) { 27 | setAttributes(name, value); 28 | } 29 | 30 | @Override 31 | protected void doWrite(String templateName, Writer outputs) throws ToolException { 32 | // Override the template... it should only ever be sei.vm, but in case it's not. 33 | String newTemplate = templateName; 34 | if (templateName.endsWith("/sei.vm")) { 35 | newTemplate = "play/soap/plugin/sei.vm"; 36 | } 37 | // Add the future API to the velocity context. The reason this must be done here is that the 38 | // method that invokes 39 | // doWrite() first clears the context before invoking this. 40 | setAttributes("future", new FutureGenerator(findLang().futureApi)); 41 | super.doWrite(newTemplate, outputs); 42 | } 43 | 44 | public Lang findLang() { 45 | String[] xjcValues = (String[]) env.get(XJC); 46 | Lang result = SCALA; 47 | if (xjcValues != null) { 48 | result = 49 | Arrays.stream(xjcValues) 50 | .filter(s -> s.startsWith(LANG.name)) 51 | .map(s -> s.substring(LANG.name.length()).trim()) 52 | .map(Lang::findByName) 53 | .findFirst() 54 | .orElse(result); 55 | } 56 | return result; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /plugin/src/main/java/play/soap/plugin/PlayXjcPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.plugin; 5 | 6 | import static play.soap.plugin.Configuration.OPTION_PREFIX; 7 | import static play.soap.plugin.Configuration.Option.LANG; 8 | import static play.soap.plugin.Configuration.Option.TARGET; 9 | 10 | import com.sun.tools.xjc.BadCommandLineException; 11 | import com.sun.tools.xjc.Options; 12 | import com.sun.tools.xjc.Plugin; 13 | import com.sun.tools.xjc.outline.Outline; 14 | import org.xml.sax.ErrorHandler; 15 | import org.xml.sax.SAXException; 16 | import play.soap.plugin.Configuration.Lang; 17 | import play.soap.plugin.Configuration.Target; 18 | 19 | /** Generate the future type to wrap an original type. */ 20 | public class PlayXjcPlugin extends Plugin { 21 | 22 | @Override 23 | public String getOptionName() { 24 | return OPTION_PREFIX; 25 | } 26 | 27 | @Override 28 | public String getUsage() { 29 | return " -Xplay : Generate the future type to wrap an original type."; 30 | } 31 | 32 | @Override 33 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException { 34 | return false; 35 | } 36 | 37 | @Override 38 | public int parseArgument(Options opt, String[] args, int i) throws BadCommandLineException { 39 | int recognized = this.parseArgument(args[i]); 40 | if (recognized == 0) { 41 | throw new BadCommandLineException("Invalid argument \"" + args[i] + "\""); 42 | } 43 | return recognized; 44 | } 45 | 46 | private int parseArgument(String arg) { 47 | int recognized = 0; 48 | if (arg.startsWith(LANG.name)) { 49 | ++recognized; 50 | String value = arg.substring(LANG.name.length()).trim(); 51 | if (!Lang.exists(value)) { 52 | throw new IllegalArgumentException("Unknown lang: \"" + value + "\""); 53 | } 54 | } 55 | if (arg.startsWith(TARGET.name)) { 56 | ++recognized; 57 | String value = arg.substring(TARGET.name.length()).trim(); 58 | if (!Target.exists(value)) { 59 | throw new IllegalArgumentException("Unknown target: \"" + value + "\""); 60 | } 61 | } 62 | return recognized; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /project/Dependencies.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | import net.aichler.jupiter.sbt.Import.JupiterKeys.jupiterVersion 5 | import sbt.Keys.libraryDependencies 6 | import sbt._ 7 | 8 | object Dependencies { 9 | 10 | object ScalaVersions { 11 | val scala213 = "2.13.18" 12 | val scala3 = "3.3.7" 13 | } 14 | 15 | object Versions { 16 | val CXF = "4.0.10" 17 | val Play = "3.0.9" 18 | } 19 | 20 | val `play-client` = libraryDependencies ++= Seq( 21 | "org.playframework" %% "play" % Versions.Play % Provided, 22 | "org.apache.cxf" % "cxf-rt-frontend-jaxws" % Versions.CXF % Provided, 23 | "org.apache.cxf" % "cxf-rt-transports-http-hc" % Versions.CXF % Provided, 24 | "org.apache.cxf" % "cxf-rt-transports-http" % Versions.CXF % Test, 25 | "org.apache.cxf" % "cxf-rt-transports-http-jetty" % Versions.CXF % Test, 26 | "org.playframework" %% "play-specs2" % Versions.Play % Test 27 | ) 28 | 29 | val plugin = libraryDependencies ++= Seq( 30 | "org.apache.cxf" % "cxf-tools-wsdlto-frontend-jaxws" % Versions.CXF % Provided, 31 | "org.apache.cxf" % "cxf-tools-wsdlto-databinding-jaxb" % Versions.CXF % Provided 32 | ) 33 | 34 | val `mock-server` = libraryDependencies ++= Seq( 35 | "org.apache.cxf" % "cxf-rt-frontend-jaxws" % Versions.CXF, 36 | "org.apache.cxf" % "cxf-rt-transports-http-jetty" % Versions.CXF, 37 | ) 38 | 39 | val `test-java` = libraryDependencies ++= Seq( 40 | "org.apache.cxf" % "cxf-rt-frontend-jaxws" % Versions.CXF % Test, 41 | "org.apache.cxf" % "cxf-rt-transports-http-hc5" % Versions.CXF % Test, 42 | "net.aichler" % "jupiter-interface" % jupiterVersion.value % Test, 43 | "org.testcontainers" % "junit-jupiter" % "1.21.4" % Test, 44 | "org.assertj" % "assertj-core" % "3.27.6" % Test 45 | ) 46 | 47 | val `test-scala` = libraryDependencies ++= Seq( 48 | "org.apache.cxf" % "cxf-rt-frontend-jaxws" % Versions.CXF % Test, 49 | "org.apache.cxf" % "cxf-rt-transports-http-hc5" % Versions.CXF % Test, 50 | "com.dimafeng" %% "testcontainers-scala" % "0.43.0" % Test, 51 | "org.scalatest" %% "scalatest" % "3.2.19" % Test, 52 | ) 53 | } 54 | -------------------------------------------------------------------------------- /plugin/src/main/java/play/soap/plugin/PlayClientGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.plugin; 5 | 6 | import static play.soap.plugin.Configuration.Option.TARGET; 7 | import static play.soap.plugin.Configuration.Target.PLAY; 8 | import static play.soap.plugin.Configuration.XJC; 9 | 10 | import java.io.Writer; 11 | import java.util.Arrays; 12 | import org.apache.cxf.tools.common.ToolException; 13 | import org.apache.cxf.tools.util.ClassCollector; 14 | import org.apache.cxf.tools.wsdlto.frontend.jaxws.generators.ServiceGenerator; 15 | import play.soap.plugin.Configuration.Target; 16 | 17 | /** Generator for the Play plugin */ 18 | public class PlayClientGenerator extends ServiceGenerator implements PlayGenerator { 19 | 20 | @Override 21 | protected void setCommonAttributes() { 22 | super.setCommonAttributes(); 23 | setPlayAttributes(); 24 | } 25 | 26 | @Override 27 | public void setAttribute(String name, Object value) { 28 | setAttributes(name, value); 29 | } 30 | 31 | @Override 32 | protected void doWrite(String templateName, Writer outputs) throws ToolException { 33 | if (PLAY.equals(findTarget())) { 34 | String newTemplate = templateName; 35 | if (templateName.endsWith("/service.vm")) { 36 | newTemplate = "play/soap/plugin/client.vm"; 37 | } 38 | setAttribute("portMethod", new PlayPortMethodNameGenerator()); 39 | super.doWrite(newTemplate, outputs); 40 | } else { 41 | super.doWrite(templateName, outputs); 42 | } 43 | } 44 | 45 | /** Overridden to make the output name Scala instead of Java. */ 46 | @Override 47 | protected Writer parseOutputName(String packageName, String filename) throws ToolException { 48 | Writer writer; 49 | if (PLAY.equals(findTarget())) { 50 | register(env.get(ClassCollector.class), packageName, filename); 51 | writer = parseOutputName(packageName, filename, ".scala"); 52 | } else { 53 | writer = super.parseOutputName(packageName, filename); 54 | } 55 | return writer; 56 | } 57 | 58 | private Target findTarget() { 59 | String[] xjcValues = (String[]) env.get(XJC); 60 | Target result = null; 61 | if (xjcValues != null) { 62 | result = 63 | Arrays.stream(xjcValues) 64 | .filter(s -> s.startsWith(TARGET.name)) 65 | .map(s -> s.substring(TARGET.name.length()).trim()) 66 | .map(Target::findByName) 67 | .findFirst() 68 | .orElse(null); 69 | } 70 | return result; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /plugin/src/main/resources/play/soap/plugin/sei.vm: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright © 2015 Lightbend Inc. 3 | ## 4 | ## 5 | ## Licensed to the Apache Software Foundation (ASF) under one 6 | ## or more contributor license agreements. See the NOTICE file 7 | ## distributed with this work for additional information 8 | ## regarding copyright ownership. The ASF licenses this file 9 | ## to you under the Apache License, Version 2.0 (the 10 | ## "License"); you may not use this file except in compliance 11 | ## with the License. You may obtain a copy of the License at 12 | ## 13 | ## http://www.apache.org/licenses/LICENSE-2.0 14 | ## 15 | ## Unless required by applicable law or agreed to in writing, 16 | ## software distributed under the License is distributed on an 17 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 | ## KIND, either express or implied. See the License for the 19 | ## specific language governing permissions and limitations 20 | ## under the License. 21 | ## 22 | ## This source file has been copied from 23 | ## org/apache/cxf/tools/wsdlto/frontend/jaxws/template/sei.vm 24 | ## and modified according to Play SOAP purposes. 25 | ## 26 | 27 | #if ($intf.packageJavaDoc != "") 28 | /** 29 | $intf.packageJavaDoc 30 | */ 31 | #end 32 | package $intf.PackageName; 33 | 34 | #if ($markGenerated == "true") 35 | import javax.annotation.Generated; 36 | #end 37 | #foreach ($import in $intf.Imports) 38 | import ${import}; 39 | #end 40 | 41 | /** 42 | #if ($intf.classJavaDoc != "") 43 | $intf.classJavaDoc 44 | * 45 | #end 46 | * This class was generated by $fullversion 47 | * $currentdate 48 | * Generated source version: $version 49 | * 50 | */ 51 | #foreach ($annotation in $intf.Annotations) 52 | $annotation 53 | #end 54 | #if ($markGenerated == "true") 55 | @Generated(value = "$generatorclass", date = "$currentdate", comments = "$fullversion") 56 | #end 57 | public interface $intf.Name { 58 | #foreach ($method in $intf.Methods) 59 | 60 | #if ($method.JavaDoc != "") 61 | /** 62 | ${method.JavaDoc} 63 | */ 64 | #end 65 | #foreach ($annotation in $method.Annotations) 66 | $annotation 67 | #end 68 | #if ($markGenerated == "true") 69 | @Generated(value = "$generatorclass", date = "$currentdate") 70 | #end 71 | public $future.futureType($method.returnValue) ${method.Name}(#if($method.ParameterList.size() == 0))#end 72 | #if($method.ParameterList.size() != 0) 73 | 74 | #foreach ($param in ${method.ParameterList}) 75 | $param 76 | #end 77 | )#end#if($method.Exceptions.size() > 0) throws#foreach($exception in $method.Exceptions) $exception.ClassName#if($method.Exceptions.size() != $foreach.count),#end#end#end; 78 | #end 79 | } 80 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-scala-future/tests/play/soap/sbtplugin/tester/ServiceSpec.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.plugin.tester 5 | 6 | import java.net.ServerSocket 7 | import java.util.concurrent.atomic.AtomicBoolean 8 | import javax.xml.ws.Endpoint 9 | import javax.xml.ws.handler.soap._ 10 | import javax.xml.ws.handler.MessageContext 11 | 12 | import org.apache.cxf.jaxws.EndpointImpl 13 | import play.soap.testservice.client._ 14 | import scala.collection.JavaConverters._ 15 | import scala.concurrent.Await 16 | import scala.concurrent.Future 17 | import scala.concurrent.duration._ 18 | import scala.reflect.ClassTag 19 | 20 | import play.api.test._ 21 | import play.api.Application 22 | import play.api.inject.guice.GuiceApplicationBuilder 23 | 24 | abstract class ServiceSpec extends PlaySpecification { 25 | 26 | /** 27 | * The type of the client class that's used to connect to the service. 28 | */ 29 | type ServiceClient 30 | 31 | /** 32 | * The type of service. 33 | */ 34 | type Service 35 | 36 | /** 37 | * The runtime type of the service client. 38 | */ 39 | implicit val serviceClientClass: ClassTag[ServiceClient] 40 | 41 | /** 42 | * Get the service from the client. 43 | */ 44 | def getServiceFromClient(c: ServiceClient): Service 45 | 46 | /** 47 | * Create an implementation of the service to run on the server. 48 | */ 49 | def createServiceImpl(): Any 50 | 51 | /** 52 | * The path of the service. Omit the leading '/'. 53 | */ 54 | val servicePath: String 55 | 56 | def await[T](future: Future[T]): T = Await.result(future, 10.seconds) 57 | 58 | def withClient[T](block: Service => T): T = withApp { app => 59 | val client = app.injector.instanceOf[ServiceClient] 60 | val service = getServiceFromClient(client) 61 | block(service) 62 | } 63 | 64 | def withApp[T](block: Application => T): T = withService { port => 65 | implicit val app = new GuiceApplicationBuilder() 66 | .configure("play.soap.address" -> s"http://localhost:$port/$servicePath") 67 | .build 68 | Helpers.running(app) { 69 | block(app) 70 | } 71 | } 72 | 73 | def withService[T](block: Int => T): T = { 74 | val port = findAvailablePort() 75 | val impl = createServiceImpl() 76 | val endpoint = Endpoint.publish(s"http://localhost:$port/$servicePath", impl) 77 | try { 78 | block(port) 79 | } finally { 80 | endpoint.stop() 81 | // Need to shutdown whole engine. Note, Jetty's shutdown doesn't seem to happen synchronously, have to wait 82 | // a few seconds for the port to be released. This is why we use a different port each time. 83 | endpoint.asInstanceOf[EndpointImpl].getBus.shutdown(true) 84 | } 85 | } 86 | 87 | def findAvailablePort() = { 88 | val socket = new ServerSocket(0) 89 | try { 90 | socket.getLocalPort 91 | } finally { 92 | socket.close() 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-scala-future/app/play/soap/testservice/PrimitivesImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.testservice; 5 | 6 | import javax.jws.WebParam; 7 | import javax.jws.WebService; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /* 12 | * THIS FILE IS AUTO GENERATED. DO NOT EDIT THIS FILE MANUALLY. 13 | * 14 | * Run 'generate-primitives.py' to regenerate it. 15 | */ 16 | 17 | @WebService( 18 | targetNamespace = "http://testservice.soap.play/primitives", 19 | endpointInterface = "play.soap.testservice.Primitives", 20 | serviceName = "PrimitivesService", portName = "Primitives") 21 | public class PrimitivesImpl implements Primitives { 22 | @Override 23 | public boolean booleanOp(@WebParam(name = "x") boolean x) { 24 | return x; 25 | } 26 | @Override 27 | public java.util.List booleanSequence(@WebParam(name = "xs") boolean xs) { 28 | return java.util.Arrays.asList(true, true, true); 29 | } 30 | 31 | @Override 32 | public byte byteOp(@WebParam(name = "x") byte x) { 33 | return x; 34 | } 35 | @Override 36 | public java.util.List byteSequence(@WebParam(name = "xs") byte xs) { 37 | return java.util.Arrays.asList((byte) 1, (byte) 1, (byte) 1); 38 | } 39 | 40 | @Override 41 | public double doubleOp(@WebParam(name = "x") double x) { 42 | return x; 43 | } 44 | @Override 45 | public java.util.List doubleSequence(@WebParam(name = "xs") double xs) { 46 | return java.util.Arrays.asList(1.0d, 1.0d, 1.0d); 47 | } 48 | 49 | @Override 50 | public float floatOp(@WebParam(name = "x") float x) { 51 | return x; 52 | } 53 | @Override 54 | public java.util.List floatSequence(@WebParam(name = "xs") float xs) { 55 | return java.util.Arrays.asList(1.0f, 1.0f, 1.0f); 56 | } 57 | 58 | @Override 59 | public int intOp(@WebParam(name = "x") int x) { 60 | return x; 61 | } 62 | @Override 63 | public java.util.List intSequence(@WebParam(name = "xs") int xs) { 64 | return java.util.Arrays.asList(1, 1, 1); 65 | } 66 | 67 | @Override 68 | public long longOp(@WebParam(name = "x") long x) { 69 | return x; 70 | } 71 | @Override 72 | public java.util.List longSequence(@WebParam(name = "xs") long xs) { 73 | return java.util.Arrays.asList(1L, 1L, 1L); 74 | } 75 | 76 | @Override 77 | public short shortOp(@WebParam(name = "x") short x) { 78 | return x; 79 | } 80 | @Override 81 | public java.util.List shortSequence(@WebParam(name = "xs") short xs) { 82 | return java.util.Arrays.asList((short) 1, (short) 1, (short) 1); 83 | } 84 | 85 | } -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-play-java-future/app/play/soap/testservice/PrimitivesImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.testservice; 5 | 6 | import javax.jws.WebParam; 7 | import javax.jws.WebService; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /* 12 | * THIS FILE IS AUTO GENERATED. DO NOT EDIT THIS FILE MANUALLY. 13 | * 14 | * Run 'generate-primitives.py' to regenerate it. 15 | */ 16 | 17 | @WebService( 18 | targetNamespace = "http://testservice.soap.play/primitives", 19 | endpointInterface = "play.soap.testservice.Primitives", 20 | serviceName = "PrimitivesService", portName = "Primitives") 21 | public class PrimitivesImpl implements Primitives { 22 | @Override 23 | public boolean booleanOp(@WebParam(name = "x") boolean x) { 24 | return x; 25 | } 26 | @Override 27 | public java.util.List booleanSequence(@WebParam(name = "xs") boolean xs) { 28 | return java.util.Arrays.asList(true, true, true); 29 | } 30 | 31 | @Override 32 | public byte byteOp(@WebParam(name = "x") byte x) { 33 | return x; 34 | } 35 | @Override 36 | public java.util.List byteSequence(@WebParam(name = "xs") byte xs) { 37 | return java.util.Arrays.asList((byte) 1, (byte) 1, (byte) 1); 38 | } 39 | 40 | @Override 41 | public double doubleOp(@WebParam(name = "x") double x) { 42 | return x; 43 | } 44 | @Override 45 | public java.util.List doubleSequence(@WebParam(name = "xs") double xs) { 46 | return java.util.Arrays.asList(1.0d, 1.0d, 1.0d); 47 | } 48 | 49 | @Override 50 | public float floatOp(@WebParam(name = "x") float x) { 51 | return x; 52 | } 53 | @Override 54 | public java.util.List floatSequence(@WebParam(name = "xs") float xs) { 55 | return java.util.Arrays.asList(1.0f, 1.0f, 1.0f); 56 | } 57 | 58 | @Override 59 | public int intOp(@WebParam(name = "x") int x) { 60 | return x; 61 | } 62 | @Override 63 | public java.util.List intSequence(@WebParam(name = "xs") int xs) { 64 | return java.util.Arrays.asList(1, 1, 1); 65 | } 66 | 67 | @Override 68 | public long longOp(@WebParam(name = "x") long x) { 69 | return x; 70 | } 71 | @Override 72 | public java.util.List longSequence(@WebParam(name = "xs") long xs) { 73 | return java.util.Arrays.asList(1L, 1L, 1L); 74 | } 75 | 76 | @Override 77 | public short shortOp(@WebParam(name = "x") short x) { 78 | return x; 79 | } 80 | @Override 81 | public java.util.List shortSequence(@WebParam(name = "xs") short xs) { 82 | return java.util.Arrays.asList((short) 1, (short) 1, (short) 1); 83 | } 84 | 85 | } -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-scala-future/tests/play/soap/sbtplugin/tester/HelloWorldSpec.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.plugin.tester 5 | 6 | import java.net.ServerSocket 7 | import java.util.concurrent.atomic.AtomicBoolean 8 | import javax.xml.ws.Endpoint 9 | import javax.xml.ws.handler.soap._ 10 | import javax.xml.ws.handler.MessageContext 11 | 12 | import org.apache.cxf.jaxws.EndpointImpl 13 | import play.soap.testservice.client._ 14 | import scala.collection.JavaConverters._ 15 | import scala.concurrent.Await 16 | import scala.concurrent.Future 17 | import scala.concurrent.duration._ 18 | import scala.reflect.ClassTag 19 | 20 | import play.api.test._ 21 | import play.api.Application 22 | import play.api.inject.guice.GuiceApplicationBuilder 23 | import play.soap.testservice.HelloWorldImpl 24 | 25 | class HelloWorldSpec extends ServiceSpec { 26 | 27 | sequential 28 | 29 | "HelloWorld" should { 30 | "say hello" in withClient { client => 31 | await(client.sayHello("world")) must_== "Hello world" 32 | } 33 | 34 | "say hello to many people" in withClient { client => 35 | await(client.sayHelloToMany(java.util.Arrays.asList("foo", "bar"))).asScala must_== List("Hello foo", "Hello bar") 36 | } 37 | 38 | "say hello to one user" in withClient { client => 39 | val user = new User 40 | user.setName("world") 41 | await(client.sayHelloToUser(user)).getUser.getName must_== "world" 42 | } 43 | 44 | "say hello with an exception" in withClient { client => 45 | await(client.sayHelloException("world")) must throwA[HelloException_Exception].like { case e => 46 | e.getMessage must_== "Hello world" 47 | } 48 | } 49 | 50 | "dont say hello" in withClient { client => 51 | await(client.dontSayHello()) must_== ((): Unit) 52 | } 53 | 54 | "allow adding custom handlers" in { 55 | val invoked = new AtomicBoolean() 56 | withApp { app => 57 | val client = app.injector 58 | .instanceOf[HelloWorldService] 59 | .helloWorld(new SOAPHandler[SOAPMessageContext] { 60 | def getHeaders = null 61 | def handleMessage(context: SOAPMessageContext) = { 62 | invoked.set(true) 63 | true 64 | } 65 | def close(context: MessageContext) = () 66 | def handleFault(context: SOAPMessageContext) = true 67 | }) 68 | 69 | await(client.sayHello("world")) must_== "Hello world" 70 | invoked.get() must_== true 71 | } 72 | } 73 | } 74 | 75 | override type ServiceClient = HelloWorldService 76 | 77 | override type Service = HelloWorld 78 | 79 | implicit override val serviceClientClass: ClassTag[HelloWorldService] = ClassTag(classOf[HelloWorldService]) 80 | 81 | override def getServiceFromClient(c: ServiceClient): Service = c.helloWorld 82 | 83 | override def createServiceImpl(): Any = new HelloWorldImpl 84 | 85 | val servicePath: String = "helloWorld" 86 | 87 | } 88 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-scala-future/tests/play/soap/sbtplugin/tester/PrimitivesSpec.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.plugin.tester 5 | 6 | import java.util.Arrays 7 | 8 | import play.soap.testservice.PrimitivesImpl 9 | import play.soap.testservice.client._ 10 | 11 | import scala.collection.JavaConverters._ 12 | import scala.reflect.ClassTag 13 | 14 | /* 15 | * THIS FILE IS AUTO GENERATED. DO NOT EDIT THIS FILE MANUALLY. 16 | * 17 | * Run 'generate-primitives.py' to regenerate it. 18 | */ 19 | 20 | class PrimitivesSpec extends ServiceSpec { 21 | 22 | sequential 23 | "Primitives" should { 24 | 25 | "handle boolean ops" in withClient { client => 26 | await(client.booleanOp(true)) must_== true 27 | } 28 | 29 | "handle boolean sequences" in withClient { client => 30 | await(client.booleanSequence(Arrays.asList(true, true))).asScala must_== List(true, true, true) 31 | } 32 | "handle byte ops" in withClient { client => 33 | await(client.byteOp(1.toByte)) must_== 1.toByte 34 | } 35 | 36 | "handle byte sequences" in withClient { client => 37 | await(client.byteSequence(Arrays.asList(1.toByte, 1.toByte))).asScala must_== List(1.toByte, 1.toByte, 1.toByte) 38 | } 39 | "handle double ops" in withClient { client => 40 | await(client.doubleOp(1.0d)) must_== 1.0d 41 | } 42 | 43 | "handle double sequences" in withClient { client => 44 | await(client.doubleSequence(Arrays.asList(1.0d, 1.0d))).asScala must_== List(1.0d, 1.0d, 1.0d) 45 | } 46 | "handle float ops" in withClient { client => 47 | await(client.floatOp(1.0f)) must_== 1.0f 48 | } 49 | 50 | "handle float sequences" in withClient { client => 51 | await(client.floatSequence(Arrays.asList(1.0f, 1.0f))).asScala must_== List(1.0f, 1.0f, 1.0f) 52 | } 53 | "handle int ops" in withClient { client => 54 | await(client.intOp(1)) must_== 1 55 | } 56 | 57 | "handle int sequences" in withClient { client => 58 | await(client.intSequence(Arrays.asList(1, 1))).asScala must_== List(1, 1, 1) 59 | } 60 | "handle long ops" in withClient { client => 61 | await(client.longOp(1L)) must_== 1L 62 | } 63 | 64 | "handle long sequences" in withClient { client => 65 | await(client.longSequence(Arrays.asList(1L, 1L))).asScala must_== List(1L, 1L, 1L) 66 | } 67 | "handle short ops" in withClient { client => 68 | await(client.shortOp(1.toShort)) must_== 1.toShort 69 | } 70 | 71 | "handle short sequences" in withClient { client => 72 | await(client.shortSequence(Arrays.asList(1.toShort, 1.toShort))).asScala must_== List( 73 | 1.toShort, 74 | 1.toShort, 75 | 1.toShort 76 | ) 77 | } 78 | } 79 | 80 | override type ServiceClient = PrimitivesService 81 | 82 | override type Service = Primitives 83 | 84 | implicit override val serviceClientClass: ClassTag[PrimitivesService] = ClassTag(classOf[PrimitivesService]) 85 | 86 | override def getServiceFromClient(c: ServiceClient): Service = c.primitives 87 | 88 | override def createServiceImpl(): Any = new PrimitivesImpl 89 | 90 | val servicePath: String = "primitives" 91 | 92 | } 93 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Reactive SOAP 2 | 3 | [![Twitter Follow](https://img.shields.io/twitter/follow/playframework?label=follow&style=flat&logo=twitter&color=brightgreen)](https://twitter.com/playframework) 4 | [![Discord](https://img.shields.io/discord/931647755942776882?logo=discord&logoColor=white)](https://discord.gg/g5s2vtZ4Fa) 5 | [![GitHub Discussions](https://img.shields.io/github/discussions/playframework/playframework?&logo=github&color=brightgreen)](https://github.com/playframework/playframework/discussions) 6 | [![StackOverflow](https://img.shields.io/static/v1?label=stackoverflow&logo=stackoverflow&logoColor=fe7a16&color=brightgreen&message=playframework)](https://stackoverflow.com/tags/playframework) 7 | [![YouTube](https://img.shields.io/youtube/channel/views/UCRp6QDm5SDjbIuisUpxV9cg?label=watch&logo=youtube&style=flat&color=brightgreen&logoColor=ff0000)](https://www.youtube.com/channel/UCRp6QDm5SDjbIuisUpxV9cg) 8 | [![Twitch Status](https://img.shields.io/twitch/status/playframework?logo=twitch&logoColor=white&color=brightgreen&label=live%20stream)](https://www.twitch.tv/playframework) 9 | [![OpenCollective](https://img.shields.io/opencollective/all/playframework?label=financial%20contributors&logo=open-collective)](https://opencollective.com/playframework) 10 | 11 | [![Build Status](https://github.com/playframework/play-soap/actions/workflows/build-test.yml/badge.svg)](https://github.com/playframework/play-soap/actions/workflows/build-test.yml) 12 | [![Maven](https://img.shields.io/maven-central/v/org.playframework/play-soap-client_2.13.svg?logo=apache-maven)](https://mvnrepository.com/artifact/org.playframework/play-soap-client_2.13) 13 | [![Repository size](https://img.shields.io/github/repo-size/playframework/play-soap.svg?logo=git)](https://github.com/playframework/play-soap) 14 | [![Scala Steward badge](https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=)](https://scala-steward.org) 15 | [![Mergify Status](https://img.shields.io/endpoint.svg?url=https://api.mergify.com/v1/badges/playframework/play-soap&style=flat)](https://mergify.com) 16 | 17 | Play SOAP allows an 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 promises/futures of the result. 18 | 19 | The detail description of how to use the library is described in the [Docs](https://playframework.github.io/play-soap/2.x/) point. 20 | 21 | ## Docs 22 | 23 | For testing documentation locally use a few next commands (for more details see [Antora workflow](https://github.com/playframework/.github/blob/main/.github/workflows/antora.yml)): 24 | 25 | ```bash 26 | cd docs 27 | npm i -D -E @antora/cli @antora/site-generator @antora/lunr-extension 28 | npx antora local-antora-playbook.yml 29 | ``` 30 | 31 | Then open in browser generated documentation from `/docs/build/site`. 32 | 33 | ## Releasing a new version 34 | 35 | See https://github.com/playframework/.github/blob/main/RELEASING.md 36 | -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/index.adoc: -------------------------------------------------------------------------------- 1 | = Play SOAP 2 | 3 | Play SOAP allows an 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 promises/futures of the result. 4 | 5 | == JAX WS support 6 | 7 | Play SOAP builds on the JAX WS spec, but doesn't implement it exactly. JAX WS does have support for making asynchronous calls, but this support is somewhat clumsy. It requires all asynchronous methods to have an `Async` suffix, and requires the passing of an `AsyncHandler` argument to handle the response. This makes it awkward to integrate into an asynchronous framework, since `AsyncHandler` s do not compose well with other asynchronous constructs. This support could be described as a second class citizen, bolted on to the spec as an afterthought. 8 | 9 | In contrast, Play SOAP provides asynchronous invocation of SOAP services as a first class citizen. Play SOAP methods all return promises, making them easy to compose with promises from other libraries, and allowing application code to be focussed on business logic, not on wiring asynchronous callbacks together. 10 | 11 | == Client proxy 12 | 13 | === Proxy interceptor 14 | 15 | To implement the proxy, we have to implement our own version of JaxWsClientProxy. This is the CXF JDK proxy interceptor that implements JAX WS interfaces. It's here that asynchronous requests are handled, and the logic here is hard coded - it implements the JAX WS requirements, if a method ends in Async and returns something that implements Future then dispatch an asynchronous call. Hence why we have to implement our own to make every method asynchronous regardless of name, and to allow scala Future and Java CompletionStage return types. 16 | 17 | This class has a lot of logic copied from JaxWsClientProxy, the actual part that has been customised is quite simple, it just creates a promise, and sends an asynchronous callback that redeems the promise. 18 | 19 | === Return type binding 20 | 21 | When the SOAP bindings are generated, JAXB bindings are generated from the return type. Since this type is a future, we need to tell CXF to use the type it contains. 22 | 23 | JAX WS provides a Holder type, this is used to allow methods return multiple values, something that is not possible otherwise in Java. It does this by having the first value returned as the return value of the method, and passing additional Holder objects as arguments to the method, whose values are set when the method returns. Although this wasn't designed with returning futures in mind, the implementation of it in Apache CXF makes it quite simple to reuse this mechanism to extract the return type, hence this is what we're doing. This allows us to completely reuse all the reflection code from Apache CXF that generates the bindings from the interface. 24 | 25 | In future, we may decide to implement our own reflection code for generating bindings, but for now using the Holder mechanism is good enough. A small amount of hacking is necessary to use it, due to some odd behaviour by the CXF JAX WS support - when the bindings are created, the JAX WS support automatically inserts its own configuration, and implements it in such a way that any configuration that we've added for holders gets overridden. We work around this by overriding a method that eventually injects this configuration but is invoked before the binding is actually done, and after invoking the super for the method, we inject our own configuration to override the default behaviour. -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/client/security.adoc: -------------------------------------------------------------------------------- 1 | = Security 2 | 3 | Most security protocols can be implemented in Play SOAP using handlers. For general documentation on handlers, see xref:client/handlers.adoc[here]. 4 | 5 | == Adding an authentication token to requests 6 | 7 | Let's say you wanted to make authenticated requests on a web service that expected an authentication token in the request header. To implement this, you can get the request headers from the message context, and add the authentication token there. The HTTP request headers can be loaded by reading the `javax.xml.ws.handler.MessageContext.HTTP_REQUEST_HEADERS` property. Of course, this should only be done when the message is an outbound message, so the implementation needs to check that as well. 8 | 9 | === Adding an authentication token in Java 10 | 11 | [,java] 12 | ---- 13 | import javax.xml.namespace.QName; 14 | import javax.xml.ws.handler.MessageContext; 15 | import javax.xml.ws.handler.soap.SOAPHandler; 16 | import javax.xml.ws.handler.soap.SOAPMessageContext; 17 | import java.util.*; 18 | 19 | public class AuthenticationHandler implements SOAPHandler { 20 | 21 | public Set getHeaders() { 22 | return null; 23 | } 24 | 25 | public boolean handleMessage(SOAPMessageContext context) { 26 | Boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); 27 | 28 | if (outbound) { 29 | // Get headers, create if null 30 | Map> headers = (Map) context.get(MessageContext.HTTP_REQUEST_HEADERS); 31 | if (headers == null) { 32 | headers = new HashMap<>(); 33 | } 34 | 35 | // Add authentication header 36 | headers.put("Authentication-Token", Arrays.asList("somesecret")); 37 | context.put(MessageContext.HTTP_REQUEST_HEADERS, headers); 38 | } 39 | return true; 40 | } 41 | 42 | public boolean handleFault(SOAPMessageContext context) { 43 | return true; 44 | } 45 | 46 | public void close(MessageContext context) { 47 | } 48 | } 49 | ---- 50 | 51 | === Adding an authentication token in Scala 52 | 53 | Note that in the collection types used by the JAX WS API are Java collection types, so care needs to be taken to ensure that these types are used in the Scala code, rather than the Scala collection types. A common way to address this in Scala is to use aliased imports, prepending the letter `J` to each type, for example, `import java.util.{Map => JMap}`. 54 | 55 | [,scala] 56 | ---- 57 | import javax.xml.ws.handler.MessageContext 58 | import javax.xml.ws.handler.soap.{SOAPMessageContext, SOAPHandler} 59 | 60 | import java.util.{Map => JMap, List => JList, HashMap => JHashMap} 61 | import scala.collection.JavaConverters._ 62 | 63 | class AuthenticationHandler extends SOAPHandler[SOAPMessageContext] { 64 | def getHeaders = null 65 | 66 | def handleMessage(context: SOAPMessageContext) = { 67 | // If this is an outbound message 68 | if (context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY) 69 | .asInstanceOf[java.lang.Boolean]) { 70 | 71 | // Get the request headers, which may be null, in which case create them 72 | val headers = Option(context.get(MessageContext.HTTP_REQUEST_HEADERS) 73 | .asInstanceOf[JMap[String, JList[String]]] 74 | ).getOrElse(new JHashMap[String, JList[String]]) 75 | 76 | // Add the authentication token to the headers 77 | headers += ("Authentication-Token" -> List("somesecret")) 78 | 79 | // Attach the headers to the context 80 | context += (MessageContext.HTTP_REQUEST_HEADERS -> headers) 81 | 82 | } 83 | true 84 | } 85 | 86 | def close(context: MessageContext) = () 87 | 88 | def handleFault(context: SOAPMessageContext) = true 89 | } 90 | ---- 91 | -------------------------------------------------------------------------------- /test/scala/src/test/scala/play/soap/test/PrimitivesSpec.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.test 5 | 6 | import com.dimafeng.testcontainers.ForAllTestContainer 7 | import com.dimafeng.testcontainers.GenericContainer 8 | import org.scalatest.BeforeAndAfterAll 9 | import org.scalatest.concurrent.AsyncTimeLimitedTests 10 | import org.scalatest.matchers.should.Matchers._ 11 | import org.scalatest.time.Span 12 | import org.scalatest.time.SpanSugar._ 13 | import org.scalatest.wordspec.AsyncWordSpec 14 | import play.soap.PlayJaxWsProxyFactoryBean 15 | import play.soap.test.primitives.Primitives 16 | 17 | import java.util.{ List => JList } 18 | 19 | class PrimitivesSpec extends AsyncWordSpec with BeforeAndAfterAll with AsyncTimeLimitedTests with ForAllTestContainer { 20 | 21 | private val MOCK_SERVER_IMAGE = "play/soap-test-server" 22 | 23 | override def timeLimit: Span = 5.seconds 24 | 25 | override val container: GenericContainer = GenericContainer( 26 | dockerImage = s"$MOCK_SERVER_IMAGE", 27 | exposedPorts = Seq(8080) 28 | ).configure { container => 29 | container.withCreateContainerCmdModifier(it => it.withEntrypoint("bin/primitives_primitives_server")) 30 | } 31 | container.start() 32 | 33 | private var client: Primitives = _ 34 | 35 | protected override def beforeAll(): Unit = { 36 | container.container.isRunning shouldBe true 37 | val factory = new PlayJaxWsProxyFactoryBean 38 | factory.setServiceClass(classOf[Primitives]) 39 | // noinspection HttpUrlsUsage 40 | factory.setAddress(s"http://${container.containerIpAddress}:${container.mappedPort(8080)}/primitives") 41 | client = factory.create().asInstanceOf[Primitives] 42 | } 43 | 44 | "SOAP service that uses primitives" should { 45 | 46 | "work with boolean" in { 47 | client.booleanOp(true).map { _ shouldBe true } 48 | } 49 | 50 | "work with boolean sequence" in { 51 | client.booleanSequence(JList.of(true, false, true)).map { seq => 52 | seq should contain theSameElementsAs Seq(true, false, true) 53 | } 54 | } 55 | 56 | "work with empty boolean sequence" in { 57 | client.booleanSequence(JList.of()).map { _ shouldBe empty } 58 | } 59 | 60 | "work with byte" in { 61 | client.byteOp(1).map { _ shouldBe 1 } 62 | } 63 | 64 | "work with byte sequence" in { 65 | client.byteSequence(JList.of(1.toByte, 2.toByte, 3.toByte)).map { seq => 66 | seq should contain theSameElementsAs Seq(1, 2, 3) 67 | } 68 | } 69 | 70 | "work with empty byte sequence" in { 71 | client.byteSequence(JList.of()).map { _ shouldBe empty } 72 | } 73 | 74 | "work with double" in { 75 | client.doubleOp(1.0d).map { _ shouldBe 1.0d } 76 | } 77 | 78 | "work with double sequence" in { 79 | client.doubleSequence(JList.of(1.0d, 2.0d, 3.0d)).map { seq => 80 | seq should contain theSameElementsAs Seq(1.0d, 2.0d, 3.0d) 81 | } 82 | } 83 | 84 | "work with empty double sequence" in { 85 | client.doubleSequence(JList.of()).map { _ shouldBe empty } 86 | } 87 | 88 | "work with float" in { 89 | client.floatOp(1.5f).map { _ shouldBe 1.5f } 90 | } 91 | 92 | "work with float sequence" in { 93 | client.floatSequence(JList.of(1.5f, 2.5f, 3.5f)).map { seq => 94 | seq should contain theSameElementsAs Seq(1.5f, 2.5f, 3.5f) 95 | } 96 | } 97 | 98 | "work with empty float sequence" in { 99 | client.floatSequence(JList.of()).map { _ shouldBe empty } 100 | } 101 | 102 | "work with int" in { 103 | client.intOp(100).map { _ shouldBe 100 } 104 | } 105 | 106 | "work with int sequence" in { 107 | client.intSequence(JList.of(100, 200, 300)).map { seq => 108 | seq should contain theSameElementsAs Seq(100, 200, 300) 109 | } 110 | } 111 | 112 | "work with empty int sequence" in { 113 | client.intSequence(JList.of()).map { _ shouldBe empty } 114 | } 115 | 116 | "work with long" in { 117 | client.longOp(1000).map { _ shouldBe 1000 } 118 | } 119 | 120 | "work with long sequence" in { 121 | client.longSequence(JList.of(1000L, 2000L, 3000L)).map { seq => 122 | (seq should contain).theSameElementsInOrderAs(Seq(1000L, 2000L, 3000L)) 123 | } 124 | } 125 | 126 | "work with empty long sequence" in { 127 | client.longSequence(JList.of()).map { _ shouldBe empty } 128 | } 129 | 130 | "work with short" in { 131 | client.shortOp(10).map { _ shouldBe 10 } 132 | } 133 | 134 | "work with short sequence" in { 135 | client.shortSequence(JList.of(10.toShort, 20.toShort, 30.toShort)).map { seq => 136 | (seq should contain).theSameElementsInOrderAs(Seq(10, 20, 30)) 137 | } 138 | } 139 | 140 | "work with empty short sequence" in { 141 | client.shortSequence(JList.of()).map { _ shouldBe empty } 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /client/src/test/scala/play/soap/PlayJaxWsClientProxySpec.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap 5 | 6 | import jakarta.xml.ws.Endpoint 7 | import jakarta.xml.ws.Holder 8 | import org.apache.cxf.binding.soap.SoapFault 9 | import org.apache.cxf.jaxws.EndpointImpl 10 | import org.specs2.mutable.Specification 11 | import play.soap.mockservice._ 12 | 13 | import java.net.ServerSocket 14 | import java.util.concurrent.CompletionStage 15 | import scala.concurrent.Await 16 | import scala.concurrent.Future 17 | import scala.concurrent.duration._ 18 | import scala.jdk.FutureConverters 19 | import scala.reflect.ClassTag 20 | 21 | class PlayJaxWsClientProxySpec extends Specification { 22 | sequential 23 | 24 | "The client proxy" should { 25 | "work with a scala client" in { 26 | "allow calling a simple method" in withScalaClient { client => await(client.add(3, 4)) must_== 7 } 27 | 28 | "allow calling a method with complex types" in withScalaClient { client => 29 | val foo = new Foo(10, "foo") 30 | val bar = await(client.getBar(foo)) 31 | bar.getFoo must_== foo 32 | bar.getName must_== "bar" 33 | } 34 | 35 | "allow calling a method with multiple return types" in withScalaClient { client => 36 | val second = new Holder[String] 37 | val first = await(client.multiReturn(second, "hello", 2)) 38 | first must_== "he" 39 | second.value must_== "llo" 40 | } 41 | 42 | "allow calling a method with no return value" in withScalaClient { client => 43 | await(client.noReturn("nothing")) must_== ((): Unit) 44 | } 45 | 46 | "allow calling a method that throws a declared exception" in withScalaClient { client => 47 | val result = client.declaredException() 48 | await(result) must throwA[SomeException].like { case e: SomeException => 49 | e.getMessage must_== "an error occurred" 50 | } 51 | } 52 | 53 | "allow calling a method that throws an undeclared exception" in withScalaClient { client => 54 | val result = client.runtimeException() 55 | await(result) must throwA[SoapFault].like { case e: SoapFault => 56 | e.getMessage must_== "an error occurred" 57 | } 58 | } 59 | } 60 | 61 | "work with a java client" in { 62 | "allow calling a simple method" in withJavaClient { client => await(client.add(3, 4)) must_== 7 } 63 | 64 | "allow calling a method with complex types" in withJavaClient { client => 65 | val foo = new Foo(10, "foo") 66 | val bar = await(client.getBar(foo)) 67 | bar.getFoo must_== foo 68 | bar.getName must_== "bar" 69 | } 70 | 71 | "allow calling a method with multiple return types" in withJavaClient { client => 72 | val second = new Holder[String] 73 | val first = await(client.multiReturn(second, "hello", 2)) 74 | first must_== "he" 75 | second.value must_== "llo" 76 | } 77 | 78 | "allow calling a method with no return value" in withJavaClient { client => 79 | await(client.noReturn("nothing")) must_== null 80 | } 81 | 82 | "allow calling a method that throws a declared exception" in withJavaClient { client => 83 | val result = client.declaredException() 84 | await(result) must throwA[SomeException].like { case e: SomeException => 85 | e.getMessage must_== "an error occurred" 86 | } 87 | } 88 | 89 | "allow calling a method that throws an undeclared exception" in withJavaClient { client => 90 | val result = client.runtimeException() 91 | await(result) must throwA[SoapFault].like { case e: SoapFault => 92 | e.getMessage must_== "an error occurred" 93 | } 94 | } 95 | } 96 | } 97 | 98 | def await[T](future: Future[T]): T = Await.result(future, 10.seconds) 99 | 100 | def await[T](completionStage: CompletionStage[T]): T = await( 101 | FutureConverters.CompletionStageOps(completionStage).asScala 102 | ) 103 | 104 | def withScalaClient[T](block: MockServiceScala => T): T = withClient(block) 105 | 106 | def withJavaClient[T](block: MockServiceJava => T): T = withClient(block) 107 | 108 | def withClient[T, S](block: S => T)(implicit serviceClass: ClassTag[S]): T = 109 | withService { port => 110 | val factory = new PlayJaxWsProxyFactoryBean 111 | factory.setServiceClass(serviceClass.runtimeClass) 112 | factory.setAddress(s"http://localhost:$port/mockService") 113 | val client = factory.create().asInstanceOf[S] 114 | block(client) 115 | } 116 | 117 | def withService[T](block: Int => T): T = { 118 | val port = findAvailablePort() 119 | val endpoint = Endpoint.publish(s"http://localhost:$port/mockService", new MockServiceImpl) 120 | try { 121 | block(port) 122 | } finally { 123 | endpoint.stop() 124 | // Need to shutdown whole engine. Note, Jetty's shutdown doesn't seem to happen synchronously, have to wait 125 | // a few seconds for the port to be released. This is why we use a different port each time. 126 | endpoint.asInstanceOf[EndpointImpl].getBus.shutdown(true) 127 | } 128 | } 129 | 130 | def findAvailablePort(): Int = { 131 | val socket = new ServerSocket(0) 132 | try { 133 | socket.getLocalPort 134 | } finally { 135 | socket.close() 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /client/src/main/scala/play/soap/PlaySoapPlugin.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap 5 | 6 | import javax.inject.Inject 7 | import javax.inject.Singleton 8 | import javax.xml.namespace.QName 9 | import jakarta.xml.ws.handler.MessageContext 10 | import jakarta.xml.ws.handler.Handler 11 | import jakarta.xml.ws.soap.SOAPBinding 12 | 13 | import org.apache.cxf.BusFactory 14 | import org.apache.cxf.interceptor.LoggingOutInterceptor 15 | import org.apache.cxf.interceptor.LoggingInInterceptor 16 | import org.apache.cxf.transport.ConduitInitiatorManager 17 | import org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduitFactory 18 | import org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit 19 | import org.apache.cxf.transport.http.asyncclient.AsyncHttpTransportFactory 20 | import play.api._ 21 | import play.api.inject.ApplicationLifecycle 22 | 23 | import scala.jdk.CollectionConverters._ 24 | import scala.concurrent.Future 25 | import scala.reflect.ClassTag 26 | 27 | /** 28 | * Abstract plugin extended by all generated SOAP clients. 29 | */ 30 | abstract class PlaySoapClient @Inject() (apacheCxfBus: ApacheCxfBus, configuration: Configuration) { 31 | private lazy val config = Configuration(configuration.underlying.getConfig("play.soap")) 32 | private lazy val serviceConfig = config.getOptional[Configuration]("services." + this.getClass.getName) 33 | private def portConfig(portName: String) = serviceConfig.flatMap(_.getOptional[Configuration]("ports." + portName)) 34 | private def readConfig[T](portName: String, read: Configuration => Option[T], default: T): T = { 35 | portConfig(portName) 36 | .flatMap(read) 37 | .orElse(serviceConfig.flatMap(read)) 38 | .orElse(read(config)) 39 | .getOrElse(default) 40 | } 41 | 42 | /** 43 | * Create a port for the given class 44 | * 45 | * @param qname 46 | * The qname of the class 47 | * @param portName 48 | * The name of the port 49 | * @param defaultAddress 50 | * The default address to use if none configured 51 | * @param handlers 52 | * The handlers to use 53 | * @return 54 | * The port 55 | */ 56 | protected def createPort[T]( 57 | qname: QName, 58 | portName: String, 59 | defaultAddress: String, 60 | handlers: Handler[_ <: MessageContext]* 61 | )(implicit ct: ClassTag[T]): T = { 62 | val factory: PlayJaxWsProxyFactoryBean = createFactory 63 | 64 | if (readConfig(portName, _.getOptional[Boolean]("debugLog"), false)) { 65 | factory.getInInterceptors.add(new LoggingInInterceptor) 66 | factory.getOutInterceptors.add(new LoggingOutInterceptor) 67 | } 68 | factory.setServiceClass(ct.runtimeClass) 69 | val address = readConfig(portName, _.getOptional[String]("address"), defaultAddress) 70 | factory.setAddress(address) 71 | 72 | val bindingId = readConfig(portName, _.getOptional[String]("bindingId"), SOAPBinding.SOAP11HTTP_BINDING) 73 | factory.setBindingId(bindingId) 74 | 75 | factory.setHandlers(handlers.asJava) 76 | 77 | val port = factory.create() 78 | 79 | port.asInstanceOf[T] 80 | } 81 | 82 | private def createFactory: PlayJaxWsProxyFactoryBean = { 83 | val factory = new PlayJaxWsProxyFactoryBean 84 | factory.setBus(apacheCxfBus.bus) 85 | factory 86 | } 87 | } 88 | 89 | /** 90 | * Configures and manages the lifecycle of an Apache CXF bus 91 | */ 92 | @Singleton 93 | class ApacheCxfBus @Inject() (lifecycle: ApplicationLifecycle) extends Logging { 94 | private lazy val asyncTransport = new AsyncHttpTransportFactory 95 | private[soap] lazy val bus = { 96 | val bus = BusFactory.newInstance.createBus 97 | 98 | // Although Apache CXF will automatically select the async http transport conduit, we want to ensure that it will 99 | // use ours no matter what, so we do that here. Note - in future we could replace this with one based on WS. 100 | val cim = bus.getExtension(classOf[ConduitInitiatorManager]) 101 | cim.registerConduitInitiator("http://cxf.apache.org/transports/http", asyncTransport) 102 | cim.registerConduitInitiator("http://cxf.apache.org/transports/https", asyncTransport) 103 | cim.registerConduitInitiator("http://cxf.apache.org/transports/http/configuration", asyncTransport) 104 | cim.registerConduitInitiator("http://cxf.apache.org/transports/https/configuration", asyncTransport) 105 | 106 | bus.setProperty(AsyncHTTPConduit.USE_ASYNC, java.lang.Boolean.TRUE) 107 | 108 | bus 109 | } 110 | 111 | lifecycle.addStopHook { () => 112 | bus.shutdown(true) 113 | 114 | // The AsyncHttpTransportFactory holds an AsyncHTTPConduitFactory, which holds a client which holds threads. There 115 | // is no way to shut this down without using reflection to get the conduit factory. 116 | try { 117 | val factoryField = classOf[AsyncHttpTransportFactory].getDeclaredField("factory") 118 | factoryField.setAccessible(true) 119 | val factory = factoryField.get(asyncTransport).asInstanceOf[AsyncHTTPConduitFactory] 120 | factory.shutdown() 121 | } catch { 122 | // Ignore, just print the stack trace so we know something has gone wrong 123 | case e: Exception => 124 | logger.warn("Error shutting down CXF bus", e) 125 | } 126 | 127 | Future.successful(()) 128 | } 129 | } 130 | 131 | private case class PortConfig(namespace: QName, address: Option[String], debugLog: Boolean) 132 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-play-java-future/tests/play/soap/sbtplugin/tester/HelloWorldTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.plugin.tester; 5 | 6 | import java.lang.RuntimeException; 7 | import java.io.IOException; 8 | import java.net.ServerSocket; 9 | import java.util.function.*; 10 | import java.util.*; 11 | import java.util.concurrent.atomic.AtomicBoolean; 12 | import javax.xml.namespace.QName; 13 | import javax.xml.ws.Endpoint; 14 | import javax.xml.ws.handler.MessageContext; 15 | import javax.xml.ws.handler.soap.*; 16 | import org.apache.cxf.jaxws.EndpointImpl; 17 | import org.junit.*; 18 | import play.soap.testservice.client.*; 19 | import play.Application; 20 | import play.inject.guice.GuiceApplicationBuilder; 21 | 22 | import java.util.concurrent.TimeUnit; 23 | import java.util.concurrent.CompletionStage; 24 | 25 | import static org.junit.Assert.*; 26 | import static play.test.Helpers.*; 27 | 28 | public class HelloWorldTest { 29 | 30 | @Test 31 | public void sayHello() { 32 | withClient(client -> 33 | assertEquals("Hello world", await(client.sayHello("world"))) 34 | ); 35 | } 36 | 37 | @Test 38 | public void sayHelloToManyPeople() { 39 | withClient(client -> { 40 | List names = Arrays.asList("foo", "bar"); 41 | List hellos = Arrays.asList("Hello foo", "Hello bar"); 42 | assertEquals(hellos, await(client.sayHelloToMany(names))); 43 | }); 44 | } 45 | 46 | @Test 47 | public void sayHelloToOneUser() { 48 | withClient(client -> { 49 | User user = new User(); 50 | user.setName("world"); 51 | assertEquals("world", await(client.sayHelloToUser(user)).getUser().getName()); 52 | }); 53 | } 54 | 55 | @Test 56 | public void sayHelloException() { 57 | withClient(client -> { 58 | try { 59 | await(client.sayHelloException("world")); 60 | fail(); 61 | } catch (Exception ex) { 62 | assertEquals( 63 | "play.soap.testservice.client.HelloException_Exception: Hello world", 64 | ex.getCause().getMessage() 65 | ); 66 | } 67 | }); 68 | } 69 | 70 | @Test 71 | public void dontSayHello() { 72 | withClient(client -> { 73 | assertNull(await(client.dontSayHello())); 74 | }); 75 | } 76 | 77 | @Test 78 | public void workWithCustomHandlers() { 79 | withApp(app -> { 80 | final AtomicBoolean invoked = new AtomicBoolean(); 81 | HelloWorld client = app.injector().instanceOf(HelloWorldService.class).getHelloWorld(new SOAPHandler() { 82 | public Set getHeaders() { 83 | return null; 84 | } 85 | 86 | public boolean handleMessage(SOAPMessageContext context) { 87 | invoked.set(true); 88 | return true; 89 | } 90 | 91 | public boolean handleFault(SOAPMessageContext context) { 92 | return true; 93 | } 94 | 95 | public void close(MessageContext context) { 96 | } 97 | }); 98 | 99 | assertEquals("Hello world", await(client.sayHello("world"))); 100 | assertTrue(invoked.get()); 101 | }); 102 | } 103 | 104 | private static T await(CompletionStage promise) { 105 | try { 106 | return promise.toCompletableFuture().get(10, TimeUnit.SECONDS); 107 | } catch (Exception ex) { 108 | throw new RuntimeException(ex); 109 | } 110 | } 111 | 112 | private static void withClient(Consumer block) { 113 | withApp(app -> { 114 | HelloWorld client = app.injector().instanceOf(HelloWorldService.class).getHelloWorld(); 115 | block.accept(client); 116 | }); 117 | } 118 | 119 | private static void withApp(Consumer block) { 120 | withService(port -> { 121 | GuiceApplicationBuilder builder = new GuiceApplicationBuilder() 122 | .configure("play.soap.address", "http://localhost:"+port+"/helloWorld") 123 | .configure("play.soap.debugLog", true); 124 | Application app = builder.build(); 125 | running(app, () -> block.accept(app)); 126 | }); 127 | } 128 | 129 | private static void withService(Consumer block) { 130 | final int port = findAvailablePort(); 131 | final Endpoint endpoint = Endpoint.publish( 132 | "http://localhost:"+port+"/helloWorld", 133 | new play.soap.testservice.HelloWorldImpl()); 134 | try { 135 | block.accept(port); 136 | } finally { 137 | endpoint.stop(); 138 | // Need to shutdown whole engine. Note, Jetty's shutdown doesn't seem to happen synchronously, have to wait 139 | // a few seconds for the port to be released. This is why we use a different port each time. 140 | ((EndpointImpl) endpoint).getBus().shutdown(true); 141 | } 142 | } 143 | 144 | private static int findAvailablePort() { 145 | try { 146 | final ServerSocket socket = new ServerSocket(0); 147 | try { 148 | return socket.getLocalPort(); 149 | } finally { 150 | socket.close(); 151 | } 152 | } catch (IOException ioe) { 153 | throw new RuntimeException(ioe); 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/multiple-ports/src/main/wsdl/stockquote.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | Get Stock quote for a company Symbol 43 | 44 | 45 | 46 | 47 | 48 | 49 | Get Stock quote for a company Symbol 50 | 51 | 52 | 53 | 54 | 55 | 56 | Get Stock quote for a company Symbol 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/incremental-compilation/helloWorld2.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/incremental-compilation/src/main/wsdl/helloWorld.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-play-java-future/tests/play/soap/sbtplugin/tester/PrimitivesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.plugin.tester; 5 | 6 | import java.lang.RuntimeException; 7 | import java.io.IOException; 8 | import java.net.ServerSocket; 9 | import java.util.function.*; 10 | import java.util.*; 11 | import java.util.concurrent.TimeUnit; 12 | import java.util.concurrent.atomic.AtomicBoolean; 13 | import javax.xml.namespace.QName; 14 | import javax.xml.ws.Endpoint; 15 | import javax.xml.ws.handler.MessageContext; 16 | import javax.xml.ws.handler.soap.*; 17 | import org.apache.cxf.jaxws.EndpointImpl; 18 | import org.junit.*; 19 | import play.soap.testservice.client.*; 20 | import play.Application; 21 | import play.inject.guice.GuiceApplicationBuilder; 22 | 23 | import java.util.concurrent.CompletionStage; 24 | 25 | import static org.junit.Assert.*; 26 | import static play.test.Helpers.*; 27 | 28 | /* 29 | * THIS FILE IS AUTO GENERATED. DO NOT EDIT THIS FILE MANUALLY. 30 | * 31 | * Run 'generate-primitives.py' to regenerate it. 32 | */ 33 | 34 | public class PrimitivesTest { 35 | 36 | 37 | @Test 38 | public void booleanOp() { 39 | withClient(client -> 40 | assertEquals((java.lang.Boolean) true, await(client.booleanOp(true))) 41 | ); 42 | } 43 | @Test 44 | public void booleanSequence() { 45 | withClient(client -> 46 | assertEquals(Arrays.asList(true, true, true), await(client.booleanSequence(Arrays.asList(true, true)))) 47 | ); 48 | } 49 | @Test 50 | public void byteOp() { 51 | withClient(client -> 52 | assertEquals((java.lang.Byte) (byte) 1, await(client.byteOp((byte) 1))) 53 | ); 54 | } 55 | @Test 56 | public void byteSequence() { 57 | withClient(client -> 58 | assertEquals(Arrays.asList((byte) 1, (byte) 1, (byte) 1), await(client.byteSequence(Arrays.asList((byte) 1, (byte) 1)))) 59 | ); 60 | } 61 | @Test 62 | public void doubleOp() { 63 | withClient(client -> 64 | assertEquals((java.lang.Double) 1.0d, await(client.doubleOp(1.0d))) 65 | ); 66 | } 67 | @Test 68 | public void doubleSequence() { 69 | withClient(client -> 70 | assertEquals(Arrays.asList(1.0d, 1.0d, 1.0d), await(client.doubleSequence(Arrays.asList(1.0d, 1.0d)))) 71 | ); 72 | } 73 | @Test 74 | public void floatOp() { 75 | withClient(client -> 76 | assertEquals((java.lang.Float) 1.0f, await(client.floatOp(1.0f))) 77 | ); 78 | } 79 | @Test 80 | public void floatSequence() { 81 | withClient(client -> 82 | assertEquals(Arrays.asList(1.0f, 1.0f, 1.0f), await(client.floatSequence(Arrays.asList(1.0f, 1.0f)))) 83 | ); 84 | } 85 | @Test 86 | public void intOp() { 87 | withClient(client -> 88 | assertEquals((java.lang.Integer) 1, await(client.intOp(1))) 89 | ); 90 | } 91 | @Test 92 | public void intSequence() { 93 | withClient(client -> 94 | assertEquals(Arrays.asList(1, 1, 1), await(client.intSequence(Arrays.asList(1, 1)))) 95 | ); 96 | } 97 | @Test 98 | public void longOp() { 99 | withClient(client -> 100 | assertEquals((java.lang.Long) 1L, await(client.longOp(1L))) 101 | ); 102 | } 103 | @Test 104 | public void longSequence() { 105 | withClient(client -> 106 | assertEquals(Arrays.asList(1L, 1L, 1L), await(client.longSequence(Arrays.asList(1L, 1L)))) 107 | ); 108 | } 109 | @Test 110 | public void shortOp() { 111 | withClient(client -> 112 | assertEquals((java.lang.Short) (short) 1, await(client.shortOp((short) 1))) 113 | ); 114 | } 115 | @Test 116 | public void shortSequence() { 117 | withClient(client -> 118 | assertEquals(Arrays.asList((short) 1, (short) 1, (short) 1), await(client.shortSequence(Arrays.asList((short) 1, (short) 1)))) 119 | ); 120 | } 121 | private static T await(CompletionStage promise) { 122 | try { 123 | return promise.toCompletableFuture().get(10, TimeUnit.SECONDS); 124 | } catch (Exception ex) { 125 | throw new RuntimeException(ex); 126 | } 127 | } 128 | 129 | private static void withClient(Consumer block) { 130 | withApp(app -> { 131 | Primitives client = app.injector().instanceOf(PrimitivesService.class).getPrimitives(); 132 | block.accept(client); 133 | }); 134 | } 135 | 136 | private static void withApp(Consumer block) { 137 | withService(port -> { 138 | GuiceApplicationBuilder builder = new GuiceApplicationBuilder() 139 | .configure("play.soap.address", "http://localhost:"+port+"/primitives") 140 | .configure("play.soap.debugLog", true); 141 | Application app = builder.build(); 142 | running(app, () -> block.accept(app)); 143 | }); 144 | } 145 | 146 | private static void withService(Consumer block) { 147 | final int port = findAvailablePort(); 148 | final Endpoint endpoint = Endpoint.publish( 149 | "http://localhost:"+port+"/primitives", 150 | new play.soap.testservice.PrimitivesImpl()); 151 | try { 152 | block.accept(port); 153 | } finally { 154 | endpoint.stop(); 155 | // Need to shutdown whole engine. Note, Jetty's shutdown doesn't seem to happen synchronously, have to wait 156 | // a few seconds for the port to be released. This is why we use a different port each time. 157 | ((EndpointImpl) endpoint).getBus().shutdown(true); 158 | } 159 | } 160 | 161 | private static int findAvailablePort() { 162 | try { 163 | final ServerSocket socket = new ServerSocket(0); 164 | try { 165 | return socket.getLocalPort(); 166 | } finally { 167 | socket.close(); 168 | } 169 | } catch (IOException ioe) { 170 | throw new RuntimeException(ioe); 171 | } 172 | } 173 | 174 | } 175 | -------------------------------------------------------------------------------- /test/java/src/test/java/play/soap/test/PrimitivesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | package play.soap.test; 5 | 6 | import static java.lang.String.format; 7 | import static org.assertj.core.api.Assertions.assertThat; 8 | import static org.assertj.core.api.InstanceOfAssertFactories.LIST; 9 | 10 | import java.time.Duration; 11 | import java.util.List; 12 | import org.junit.jupiter.api.BeforeAll; 13 | import org.junit.jupiter.api.DisplayName; 14 | import org.junit.jupiter.api.Test; 15 | import org.testcontainers.containers.GenericContainer; 16 | import org.testcontainers.junit.jupiter.Container; 17 | import org.testcontainers.junit.jupiter.Testcontainers; 18 | import play.soap.PlayJaxWsProxyFactoryBean; 19 | import play.soap.test.primitives.Primitives; 20 | 21 | @Testcontainers 22 | @DisplayName("SOAP service that uses primitives should") 23 | public class PrimitivesTest { 24 | private static final String MOCK_SERVER_IMAGE = "play/soap-test-server"; 25 | private static final Duration TIMEOUT = Duration.ofSeconds(5); 26 | private static final int EXPOSED_PORT = 8080; 27 | 28 | @Container 29 | private static final GenericContainer PRIMITIVES_SERVER = 30 | new GenericContainer<>(MOCK_SERVER_IMAGE) 31 | .withExposedPorts(EXPOSED_PORT) 32 | .withCreateContainerCmdModifier( 33 | it -> it.withEntrypoint("bin/primitives_primitives_server")); 34 | 35 | private static Primitives PRIMITIVES; 36 | 37 | @BeforeAll 38 | static void initClient() { 39 | assertThat(PRIMITIVES_SERVER.isRunning()).isTrue(); 40 | PlayJaxWsProxyFactoryBean factory = new PlayJaxWsProxyFactoryBean(); 41 | factory.setServiceClass(Primitives.class); 42 | factory.setAddress( 43 | format( 44 | "http://%s:%s/primitives", 45 | PRIMITIVES_SERVER.getHost(), PRIMITIVES_SERVER.getMappedPort(EXPOSED_PORT))); 46 | PRIMITIVES = (Primitives) factory.create(); 47 | } 48 | 49 | @Test 50 | @DisplayName("work with boolean") 51 | public void testBoolean() { 52 | assertThat(PRIMITIVES.booleanOp(true)).succeedsWithin(TIMEOUT).isEqualTo(true); 53 | assertThat(PRIMITIVES.booleanOp(false)).succeedsWithin(TIMEOUT).isEqualTo(false); 54 | } 55 | 56 | @Test 57 | @DisplayName("work with boolean sequence") 58 | public void testBooleanSequence() { 59 | assertThat(PRIMITIVES.booleanSequence(List.of(true, false, true))) 60 | .succeedsWithin(TIMEOUT) 61 | .asInstanceOf(LIST) 62 | .containsExactly(true, false, true); 63 | assertThat(PRIMITIVES.booleanSequence(List.of())) 64 | .succeedsWithin(TIMEOUT) 65 | .asInstanceOf(LIST) 66 | .isEmpty(); 67 | } 68 | 69 | @Test 70 | @DisplayName("work with byte") 71 | public void testByte() { 72 | byte val = 1; 73 | assertThat(PRIMITIVES.byteOp(val)).succeedsWithin(TIMEOUT).isEqualTo(val); 74 | } 75 | 76 | @Test 77 | @DisplayName("work with byte sequence") 78 | public void testByteSequence() { 79 | List seq = List.of((byte) 1, (byte) 2, (byte) 3); 80 | assertThat(PRIMITIVES.byteSequence(seq)) 81 | .succeedsWithin(TIMEOUT) 82 | .asInstanceOf(LIST) 83 | .containsExactlyElementsOf(seq); 84 | assertThat(PRIMITIVES.byteSequence(List.of())) 85 | .succeedsWithin(TIMEOUT) 86 | .asInstanceOf(LIST) 87 | .isEmpty(); 88 | } 89 | 90 | @Test 91 | @DisplayName("work with double") 92 | public void testDouble() { 93 | assertThat(PRIMITIVES.doubleOp(1.0d)).succeedsWithin(TIMEOUT).isEqualTo(1.0d); 94 | } 95 | 96 | @Test 97 | @DisplayName("work with double sequence") 98 | public void testDoubleSequence() { 99 | assertThat(PRIMITIVES.doubleSequence(List.of(1.0d, 2.0d, 3.0d))) 100 | .succeedsWithin(TIMEOUT) 101 | .asInstanceOf(LIST) 102 | .containsExactly(1.0d, 2.0d, 3.0d); 103 | assertThat(PRIMITIVES.doubleSequence(List.of())) 104 | .succeedsWithin(TIMEOUT) 105 | .asInstanceOf(LIST) 106 | .isEmpty(); 107 | } 108 | 109 | @Test 110 | @DisplayName("work with float") 111 | public void testFloat() { 112 | assertThat(PRIMITIVES.floatOp(1.5f)).succeedsWithin(TIMEOUT).isEqualTo(1.5f); 113 | } 114 | 115 | @Test 116 | @DisplayName("work with float sequence") 117 | public void testFloatSequence() { 118 | assertThat(PRIMITIVES.floatSequence(List.of(1.5f, 2.5f, 3.5f))) 119 | .succeedsWithin(TIMEOUT) 120 | .asInstanceOf(LIST) 121 | .containsExactly(1.5f, 2.5f, 3.5f); 122 | assertThat(PRIMITIVES.floatSequence(List.of())) 123 | .succeedsWithin(TIMEOUT) 124 | .asInstanceOf(LIST) 125 | .isEmpty(); 126 | } 127 | 128 | @Test 129 | @DisplayName("work with int") 130 | public void testInt() { 131 | assertThat(PRIMITIVES.intOp(100)).succeedsWithin(TIMEOUT).isEqualTo(100); 132 | } 133 | 134 | @Test 135 | @DisplayName("work with int sequence") 136 | public void testIntSequence() { 137 | assertThat(PRIMITIVES.intSequence(List.of(100, 200, 300))) 138 | .succeedsWithin(TIMEOUT) 139 | .asInstanceOf(LIST) 140 | .containsExactly(100, 200, 300); 141 | assertThat(PRIMITIVES.intSequence(List.of())) 142 | .succeedsWithin(TIMEOUT) 143 | .asInstanceOf(LIST) 144 | .isEmpty(); 145 | } 146 | 147 | @Test 148 | @DisplayName("work with long") 149 | public void testLong() { 150 | assertThat(PRIMITIVES.longOp(1000L)).succeedsWithin(TIMEOUT).isEqualTo(1000L); 151 | } 152 | 153 | @Test 154 | @DisplayName("work with long sequence") 155 | public void testLongSequence() { 156 | assertThat(PRIMITIVES.longSequence(List.of(1000L, 2000L, 3000L))) 157 | .succeedsWithin(TIMEOUT) 158 | .asInstanceOf(LIST) 159 | .containsExactly(1000L, 2000L, 3000L); 160 | assertThat(PRIMITIVES.longSequence(List.of())) 161 | .succeedsWithin(TIMEOUT) 162 | .asInstanceOf(LIST) 163 | .isEmpty(); 164 | } 165 | 166 | @Test 167 | @DisplayName("work with short") 168 | public void testShort() { 169 | assertThat(PRIMITIVES.shortOp((short) 10)).succeedsWithin(TIMEOUT).isEqualTo((short) 10); 170 | } 171 | 172 | @Test 173 | @DisplayName("work with short sequence") 174 | public void testShortSequence() { 175 | assertThat(PRIMITIVES.shortSequence(List.of((short) 10, (short) 20, (short) 30))) 176 | .succeedsWithin(TIMEOUT) 177 | .asInstanceOf(LIST) 178 | .containsExactly((short) 10, (short) 20, (short) 30); 179 | assertThat(PRIMITIVES.shortSequence(List.of())) 180 | .succeedsWithin(TIMEOUT) 181 | .asInstanceOf(LIST) 182 | .isEmpty(); 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/client/handlers.adoc: -------------------------------------------------------------------------------- 1 | = Using JAX WS Handlers 2 | 3 | JAX WS provides an abstraction called handlers to allow cross cutting concerns to be implemented across all calls. Handlers are able to inspect and modify the incoming and outgoing messages, including SOAP data objects and request/response headers. They're also able to block requests from being made entirely. 4 | 5 | Use cases for handlers include logging, security, monitoring, and many other application specific concerns. For examples of how to implement security using handlers, see xref:client/security.adoc[]. 6 | 7 | == Handlers in Java 8 | 9 | === Implementing handlers in Java 10 | 11 | A handler can be implemented by extending a sub type of `javax.xml.ws.handler.Handler`. Which subtype you implement depends on your use case, for more details about the types of handlers, see https://docs.oracle.com/cd/E13222_01/wls/docs103/webserv_adv/handlers.html[here]. We'll implement a simple logging handler, to do this we extend `javax.xml.ws.handler.soap.SOAPHandler`. 12 | 13 | [,java] 14 | ---- 15 | import javax.xml.namespace.QName; 16 | import javax.xml.soap.SOAPMessage; 17 | import javax.xml.ws.handler.MessageContext; 18 | import javax.xml.ws.handler.soap.SOAPHandler; 19 | import javax.xml.ws.handler.soap.SOAPMessageContext; 20 | import java.util.Set; 21 | 22 | public class LoggingHandler implements SOAPHandler { 23 | public Set getHeaders() { 24 | return null; 25 | } 26 | 27 | public boolean handleMessage(SOAPMessageContext context) { 28 | Boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); 29 | SOAPMessage message = context.getMessage(); 30 | 31 | try { 32 | if (outbound) { 33 | System.out.println("Sending message:"); 34 | message.writeTo(System.out); 35 | } else { 36 | Integer responseCode = (Integer) context.get(MessageContext.HTTP_RESPONSE_CODE); 37 | System.out.println("Received " + responseCode + "response:"); 38 | message.writeTo(System.out); 39 | } 40 | System.out.println(); 41 | } catch (Exception e) { 42 | throw new RuntimeException(e); 43 | } 44 | return true; 45 | } 46 | 47 | public boolean handleFault(SOAPMessageContext context) { 48 | return true; 49 | } 50 | 51 | public void close(MessageContext context) { 52 | } 53 | } 54 | ---- 55 | 56 | The main method to implement here is the `handleMessage` method. It takes in the message context, and returns a boolean to say whether message processing should continue down the handler chain. By returning false, you can block the request. 57 | 58 | The same method is invoked for outgoing messages (that is, the request sent to the server) and incoming messages (that is, the response coming from the server). To know whether a message is incoming or outgoing, the outbound property needs to be checked. This is done using the following code: 59 | 60 | [,java] 61 | ---- 62 | Boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); 63 | ---- 64 | 65 | You can see that the SOAP message is also being loaded so that it can be logged, this is the XML representation of the method invocation or response. You can also see that the HTTP response code is being read from incoming messages, and being logged. 66 | 67 | === Using handlers in Java 68 | 69 | To use the logging handler that we implemented, we can supply it to get method for our port from the service. For example, to use it with the `HelloWorldService` that we saw earlier in the documentation, simply pass the list of handlers to the `getHelloWorld` method, like so: 70 | 71 | [,java] 72 | ---- 73 | HelloWorld client = helloWorldService.getHelloWorld(new LoggingHandler()); 74 | ---- 75 | 76 | == Handlers in Scala 77 | 78 | === Implementing handlers in Scala 79 | 80 | A handler can be implemented by extending a sub type of `javax.xml.ws.handler.Handler`. Which subtype you implement depends on your use case, for more details about the types of handlers, see https://docs.oracle.com/cd/E13222_01/wls/docs103/webserv_adv/handlers.html[here]. We'll implement a simple logging handler, to do this we extend `javax.xml.ws.handler.soap.SOAPHandler`. 81 | 82 | [,scala] 83 | ---- 84 | import javax.xml.ws.handler.MessageContext 85 | import javax.xml.ws.handler.soap.{SOAPMessageContext, SOAPHandler} 86 | 87 | class LoggingHandler extends SOAPHandler[SOAPMessageContext] { 88 | def getHeaders = null 89 | 90 | def handleMessage(context: SOAPMessageContext) = { 91 | val outbound = context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY) 92 | .asInstanceOf[java.lang.Boolean] 93 | val message = context.getMessage 94 | 95 | if (outbound) { 96 | println(s"Sending message:") 97 | message.writeTo(System.out) 98 | } else { 99 | val responseCode = context.get(MessageContext.HTTP_RESPONSE_CODE) 100 | println(s"Received $responseCode response:") 101 | message.writeTo(System.out) 102 | } 103 | println() 104 | true 105 | } 106 | 107 | def close(context: MessageContext) = () 108 | 109 | def handleFault(context: SOAPMessageContext) = { 110 | println(s"Received fault:") 111 | context.getMessage.writeTo(System.out) 112 | println() 113 | true 114 | } 115 | } 116 | ---- 117 | 118 | The main method to implement here is the `handleMessage` method. It takes in the message context, and returns a boolean to say whether message processing should continue down the handler chain. By returning false, you can block the request. 119 | 120 | The same method is invoked for outgoing messages (that is, the request sent to the server) and incoming messages (that is, the response coming from the server). To know whether a message is incoming or outgoing, the outbound property needs to be checked. This is done using the following code: 121 | 122 | [,scala] 123 | ---- 124 | val outbound = context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY) 125 | .asInstanceOf[java.lang.Boolean] 126 | ---- 127 | 128 | You can see that the SOAP message is also being loaded so that it can be logged, this is the XML representation of the method invocation or response. You can also see that the HTTP response code is being read from incoming messages, and being logged. 129 | 130 | === Using handlers in Scala 131 | 132 | To use the logging handler that we implemented, we can supply it to get method for our port from the service. For example, to use it with the `HelloWorldService` that we saw earlier in the documentation, simply pass the list of handlers to the `helloWorld` method, like so: 133 | 134 | [,scala] 135 | ---- 136 | val client: HelloWorld = helloWorldService.helloWorld(new LoggingHandler) 137 | ---- 138 | -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/client/play-soap-client.adoc: -------------------------------------------------------------------------------- 1 | = Using the Play SOAP client 2 | 3 | == Accessing the client 4 | 5 | Once you have sbt WSDL generating a soap client for you, it is quite straightforward to use. How you access it depends on the service and port names in the WSDL. Consider the following service section from a WSDL: 6 | 7 | [,xml] 8 | ---- 9 | 10 | 11 | 12 | 13 | 14 | ---- 15 | 16 | Assuming that the package name that the client was generated into is `com.example`, Play will generate a service class called `com.example.HelloWorldService`. This class is actually a Play plugin that allows you to configure the client, including configuring the address for each port to use. 17 | 18 | Note that there are some situations where sbt WSDL won't use the service name from the WSDL, these are when the name of the service conflicts with another class that it generated, such as the name of the service endpoint interface. In that case, sbt WSDL will append `_Service` to the end of the service name, for example `com.example.HelloWorldService_Service`. 19 | 20 | Having located the service class, you can now get a port. In the above WSDL there is one port named `HelloWorld`, and, according to the `HelloWorldSoapBinding` (not shown above), this returns a service endpoint interface called `HelloWorld`. To access the endpoint, simply have it injected into your components or controllers, like so in Scala: 21 | 22 | [,scala] 23 | ---- 24 | class MyComponent @Inject() (helloWorldService: HelloWorldService) { 25 | val client: HelloWorld = helloWorldService.helloWorld 26 | } 27 | ---- 28 | 29 | Or in Java: 30 | 31 | [,java] 32 | ---- 33 | public class MyComponent { 34 | 35 | private final HelloWorldService helloWorldService; 36 | 37 | @Inject 38 | public MyComponent(HelloWorldService helloWorldService) { 39 | this.helloWorldService - helloWorldService; 40 | } 41 | 42 | public void someMethod() { 43 | HelloWorld client = helloWorldService.getHelloWorld(); 44 | // use the client somehow 45 | } 46 | } 47 | ---- 48 | 49 | == Using the client 50 | 51 | Once you've got a reference to the `client`, you can invoke methods on it. For example, let's assume our client has operation called `sayHello` that takes a String parameter and returns a String parameter. To invoke this from a Play Scala action, you would do this: 52 | 53 | [,scala] 54 | ---- 55 | import play.api.libs.concurrent.Execution.Implicits._ 56 | 57 | def hello(name: String) = Action.async { 58 | val client: HelloWorld = helloWorldService.helloWorld 59 | client.sayHello(name).map { answer => 60 | Ok(answer) 61 | } 62 | } 63 | ---- 64 | 65 | To invoke it from a Play Java action you would do this: 66 | 67 | [,java] 68 | ---- 69 | import java.util.concurrent.CompletionStage; 70 | 71 | public CompletionStage hello(String name) { 72 | HelloWorld client = helloWorldService.getHelloWorld(); 73 | return client.sayHello(name).map(answer -> { 74 | return ok(answer); 75 | }); 76 | } 77 | ---- 78 | 79 | ### A note on using Scala 80 | 81 | The generated data objects will all be Java beans, with getter/setter style properties, and using Java collections. For convenience when working with the Java collections, you may import the Scala implicit conversions for Scala collections, like so: 82 | 83 | [,scala] 84 | ---- 85 | import scala.collection.JavaConverters._ 86 | ---- 87 | 88 | Using this you can work with Java collections as if they were Scala collections, and pass Scala collections to setters and methods that accept Java collections. 89 | 90 | It's also important to remember that many properties could be `null`. 91 | 92 | A pure Scala client that uses case classes, Scala collections and `Option` is a possible future enhancement for the Play SOAP library. 93 | 94 | == Configuring the client 95 | 96 | Configuration for the client works hierarchically, each configuration item is first checked to see if it's defined for the port, if not then for the service, and finally globally. The format for global configuration is `play.soap.*`. The format for configuration applying to a particular service is `play.soap.services.`, where `` is the fully qualified service name, for example, `com.example.HelloWorldService`. The format for configuration applying to a particular port is `play.soap.services..ports.`, where `` is the name of the port, for example `HelloWorld`. 97 | 98 | So for the client above, to set the debug log just for the port, you would set: 99 | 100 | [,hocon] 101 | ---- 102 | play.soap.services.com.example.HelloWorldService.ports.HelloWorld.debugLog = true 103 | ---- 104 | 105 | To set it for the whole service, you would set: 106 | 107 | [,hocon] 108 | ---- 109 | play.soap.services.com.example.HelloWorldService.debugLog = true 110 | ---- 111 | 112 | And to set it globally, you would set: 113 | 114 | [,hocon] 115 | ---- 116 | play.soap.debugLog = true 117 | ---- 118 | 119 | === Changing the address 120 | 121 | The address of a port can be set using the `address` property. For example, to set the address of every port for the `HelloWorldService`: 122 | 123 | [,hocon] 124 | ---- 125 | play.soap.services.com.example.HelloWorldService.address = "http://example.com/helloWorld" 126 | ---- 127 | 128 | === Turning on the debug log 129 | 130 | The debug log will log the outbound and inbound messages, including HTTP headers, made by the client. An example of this is as follows: 131 | 132 | [,none] 133 | ---- 134 | 16:52:17.953 [pool-1-thread-1] INFO o.a.c.s.H.HelloWorldPort.HelloWorld - Outbound Message 135 | --------------------------- 136 | ID: 1 137 | Address: http://example.com/helloWorld 138 | Encoding: UTF-8 139 | Http-Method: POST 140 | Content-Type: text/xml 141 | Headers: {Accept=[*/*], SOAPAction=[""]} 142 | Payload: world 143 | -------------------------------------- 144 | 16:52:18.180 [default-workqueue-1] INFO o.a.c.s.H.HelloWorldPort.HelloWorld - Inbound Message 145 | ---------------------------- 146 | ID: 1 147 | Response-Code: 200 148 | Encoding: UTF-8 149 | Content-Type: text/xml;charset=UTF-8 150 | Headers: {Content-Length=[204], content-type=[text/xml;charset=UTF-8], Server=[Jetty(8.1.15.v20140411)]} 151 | Payload: Hello world 152 | -------------------------------------- 153 | ---- 154 | 155 | The debug log can be turned on using the `debugLog` property, for example, to turn it on globally: 156 | 157 | [,hocon] 158 | ---- 159 | play.soap.debugLog = true 160 | ---- 161 | 162 | In combination with the `debugLog` property, you may need to adjust the logging levels in your Play application. To see the debug log, you need to ensure that `org.apache.cxf.services` is configured to log at least `INFO` messages. This can be further refined by supplying the service name, port and service endpoint interface name, for example, `org.apache.cxf.services.HelloWorldService`. 163 | -------------------------------------------------------------------------------- /client/src/main/scala/play/soap/PlayJaxWsProxyFactoryBean.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 3 | */ 4 | /* 5 | * Licensed to the Apache Software Foundation (ASF) under one 6 | * or more contributor license agreements. See the NOTICE file 7 | * distributed with this work for additional information 8 | * regarding copyright ownership. The ASF licenses this file 9 | * to you under the Apache License, Version 2.0 (the 10 | * "License"); you may not use this file except in compliance 11 | * with the License. You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, 16 | * software distributed under the License is distributed on an 17 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 | * KIND, either express or implied. See the License for the 19 | * specific language governing permissions and limitations 20 | * under the License. 21 | */ 22 | 23 | /* 24 | * This source file has been copied from 25 | * org.apache.cxf.jaxws.JaxWsProxyFactoryBean, converted to Scala, 26 | * and modified according to Play SOAP purposes. 27 | */ 28 | package play.soap 29 | 30 | import java.io.Closeable 31 | import java.lang.reflect.Proxy 32 | import java.util 33 | import javax.xml.namespace.QName 34 | import jakarta.xml.ws.BindingProvider 35 | import jakarta.xml.ws.handler.MessageContext 36 | import jakarta.xml.ws.handler.Handler 37 | 38 | import org.apache.cxf.common.classloader.ClassLoaderUtils 39 | import org.apache.cxf.common.injection.ResourceInjector 40 | import org.apache.cxf.endpoint.Client 41 | import org.apache.cxf.frontend.ClientProxy 42 | import org.apache.cxf.frontend.ClientProxyFactoryBean 43 | import org.apache.cxf.jaxws.context.WebServiceContextResourceResolver 44 | import org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilder 45 | import org.apache.cxf.jaxws.interceptors.HolderOutInterceptor 46 | import org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor 47 | import org.apache.cxf.jaxws.interceptors.HolderInInterceptor 48 | import org.apache.cxf.jaxws.interceptors.WrapperClassInInterceptor 49 | import org.apache.cxf.jaxws.JaxWsClientFactoryBean 50 | import org.apache.cxf.jaxws.support.JaxWsEndpointImpl 51 | import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean 52 | import org.apache.cxf.resource.ResourceResolver 53 | import org.apache.cxf.resource.DefaultResourceManager 54 | import org.apache.cxf.resource.ResourceManager 55 | import org.apache.cxf.service.Service 56 | import org.apache.cxf.service.model.ServiceInfo 57 | import org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean 58 | 59 | import java.util.{ List => JList } 60 | 61 | /** 62 | * Most of this code is copied from the Apache CXF JaxWsProxyFactoryBean 63 | */ 64 | private[soap] class PlayJaxWsProxyFactoryBean extends ClientProxyFactoryBean(new JaxWsClientFactoryBean()) { 65 | private var handlers: JList[Handler[_ <: MessageContext]] = new util.ArrayList[Handler[_ <: MessageContext]] 66 | private var loadHandlers: Boolean = true 67 | 68 | setServiceFactory(new PlayJaxWsServiceFactoryBean()) 69 | 70 | protected override def getConfiguredName: String = { 71 | var name: QName = getEndpointName 72 | if (name == null) { 73 | val sfb: JaxWsServiceFactoryBean = getClientFactoryBean.getServiceFactory.asInstanceOf[JaxWsServiceFactoryBean] 74 | name = sfb.getJaxWsImplementorInfo.getEndpointName 75 | } 76 | "play." + name + ".jaxws-client.proxyFactory" 77 | } 78 | 79 | /** 80 | * Specifies a list of JAX-WS Handler implementations that are to be used by the proxy. 81 | * 82 | * @param h 83 | * a List of Handler objects 84 | */ 85 | def setHandlers(h: JList[Handler[_ <: MessageContext]]): Unit = { 86 | handlers.clear() 87 | handlers.addAll(h) 88 | } 89 | 90 | /** 91 | * Returns the configured list of JAX-WS handlers for the proxy. 92 | * 93 | * @return 94 | * a List of Handler objects 95 | */ 96 | def getHandlers: JList[Handler[_ <: MessageContext]] = { 97 | handlers 98 | } 99 | 100 | def setLoadHandlers(b: Boolean): Unit = { 101 | loadHandlers = b 102 | } 103 | 104 | def isLoadHandlers: Boolean = { 105 | loadHandlers 106 | } 107 | 108 | protected override def clientClientProxy(c: Client): ClientProxy = { 109 | val cp = new PlayJaxWsClientProxy(c, c.getEndpoint.asInstanceOf[JaxWsEndpointImpl].getJaxwsBinding) 110 | cp.getRequestContext.putAll(this.getProperties) 111 | buildHandlerChain(cp) 112 | cp 113 | } 114 | 115 | protected override def getImplementingClasses: Array[Class[_]] = { 116 | val cls = getClientFactoryBean.getServiceClass 117 | Array(cls, classOf[BindingProvider], classOf[Closeable], classOf[Client]) 118 | } 119 | 120 | /** 121 | * Creates a JAX-WS proxy that can be used to make remote invocations. 122 | * 123 | * @return 124 | * the proxy. You must cast the returned object to the approriate class before making remote calls 125 | */ 126 | override def create(): AnyRef = { 127 | var orig: ClassLoaderUtils.ClassLoaderHolder = null 128 | try { 129 | if (getBus != null) { 130 | val loader: ClassLoader = getBus.getExtension(classOf[ClassLoader]) 131 | if (loader != null) { 132 | orig = ClassLoaderUtils.setThreadContextClassloader(loader) 133 | } 134 | } 135 | val obj: AnyRef = super.create() 136 | 137 | val service: Service = getServiceFactory.getService 138 | if (needWrapperClassInterceptor(service.getServiceInfos.get(0))) { 139 | val in = super.getInInterceptors 140 | val out = super.getOutInterceptors 141 | in.add(new WrapperClassInInterceptor) 142 | in.add(new HolderInInterceptor) 143 | out.add(new WrapperClassOutInterceptor) 144 | out.add(new HolderOutInterceptor) 145 | } 146 | 147 | obj 148 | } finally { 149 | if (orig != null) { 150 | orig.reset() 151 | } 152 | } 153 | } 154 | 155 | private def needWrapperClassInterceptor(serviceInfo: ServiceInfo): Boolean = { 156 | if (serviceInfo == null) { 157 | return false 158 | } 159 | import scala.jdk.CollectionConverters._ 160 | serviceInfo.getInterface.getOperations.asScala.exists(opInfo => 161 | opInfo.isUnwrappedCapable && opInfo.getProperty(ReflectionServiceFactoryBean.WRAPPERGEN_NEEDED) != null 162 | ) 163 | } 164 | 165 | private def buildHandlerChain(cp: PlayJaxWsClientProxy): Unit = { 166 | val builder: AnnotationHandlerChainBuilder = new AnnotationHandlerChainBuilder 167 | val sf: JaxWsServiceFactoryBean = getServiceFactory.asInstanceOf[JaxWsServiceFactoryBean] 168 | val chain: JList[Handler[_ <: MessageContext]] = new util.ArrayList[Handler[_ <: MessageContext]](handlers) 169 | if (loadHandlers) { 170 | chain.addAll( 171 | builder.buildHandlerChainFromClass( 172 | sf.getServiceClass, 173 | sf.getEndpointInfo.getName, 174 | sf.getServiceQName, 175 | this.getBindingId 176 | ) 177 | ) 178 | } 179 | if (!chain.isEmpty) { 180 | var resourceManager: ResourceManager = getBus.getExtension(classOf[ResourceManager]) 181 | val resolvers: JList[ResourceResolver] = resourceManager.getResourceResolvers 182 | resourceManager = new DefaultResourceManager(resolvers) 183 | resourceManager.addResourceResolver(new WebServiceContextResourceResolver) 184 | val injector: ResourceInjector = new ResourceInjector(resourceManager) 185 | import scala.jdk.CollectionConverters._ 186 | for (h <- chain.asScala) { 187 | if (Proxy.isProxyClass(h.getClass) && getServiceClass != null) { 188 | injector.inject(h, getServiceClass) 189 | injector.construct(h, getServiceClass) 190 | } else { 191 | injector.inject(h) 192 | injector.construct(h) 193 | } 194 | } 195 | } 196 | cp.getBinding.setHandlerChain(chain) 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /test/server/src/main/resources/wsdl/helloworld.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-play-java-future/conf/wsdls/helloWorld.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | -------------------------------------------------------------------------------- /plugin/src/sbt-test/play-soap/simple-client-scala-future/conf/wsdls/helloWorld.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------