Skip to content

Commit 1354cf2

Browse files
committed
Initial commit
0 parents  commit 1354cf2

File tree

16 files changed

+797
-0
lines changed

16 files changed

+797
-0
lines changed

.gitattributes

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# These are explicitly windows files and should use crlf
5+
*.bat text eol=crlf
6+

.github/workflows/ci.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
7+
workflow_dispatch:
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Set up JDK 11
14+
uses: actions/setup-java@v2
15+
with:
16+
java-version: '11'
17+
distribution: 'adopt'
18+
- name: Validate Gradle wrapper
19+
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
20+
- name: Build the server with Gradle
21+
run: ./gradlew :server:build --no-daemon
22+
- name: Test the server with Gradle
23+
run: ./gradlew :server:check --no-daemon
24+
- name: Cleanup Gradle Cache
25+
run: |
26+
rm -f ~/.gradle/caches/modules-2/modules-2.lock
27+
rm -f ~/.gradle/caches/modules-2/gc.properties

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
build
6+
7+
.idea

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 30246 Ingeniería Web (UNIZAR)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Web Engineering 2021-2022 / Lab2 RPC over HTTP
2+
3+
Please, go to the [Wiki](https://github.com/UNIZAR-30246-WebEngineering/lab2-rpc-over-http/wiki) in order to get the instructions for this assignment.
4+
5+
## Primary goal
6+
7+
Discover how to run the `server` and the `client`.
8+
Note that the `server` requires code derived from `translator.xsd`,
9+
and the `client` requires code derived from a `wsdl` file published by the `server`.
10+
11+
Next you must ensure that the client show something similar to:
12+
```
13+
Result of translating [hello] is [hola].
14+
```
15+
16+
## Secondary goal (:gift:)
17+
18+
Some ideas for obtaining a :gift: if you are the first that:
19+
20+
- **The server side**: Test the server side [properly](https://docs.spring.io/spring-ws/docs/3.1.1/reference/html/#_server_side_testing)
21+
- **Back to the future**: Upgrade to WSDL 2.0 and SOAP 1.2
22+
- **Armored SOAP**: Secure the endpoint [WS-Security](https://docs.spring.io/spring-ws/docs/3.1.1/reference/html/#security)
23+
- **Let's contract**: Re-implement the project following [Writing Contract-First Web Services tutorial](https://docs.spring.io/spring-ws/docs/3.1.1/reference/html/#tutorial)
24+
- **Do the Google way**: Re-implement the project with [gRPC](https://yidongnan.github.io/grpc-spring-boot-starter/en/)
25+
- **Do the Facebook way**: Re-implement the project with [GraphQL](https://www.graphql-java.com/tutorials/getting-started-with-spring-boot/)
26+
27+
User name | NIA | CI | Solution |Score
28+
----------|-----|----------|-----|----
29+
[UNIZAR-30246-WebEngineering](https://github.com/UNIZAR-30246-WebEngineering/lab2-rpc-over-http) |30246 | [![Build Status](https://github.com/UNIZAR-30246-WebEngineering/lab2-rpc-over-http/actions/workflows/ci.yml/badge.svg)](https://github.com/UNIZAR-30246-WebEngineering/lab2-rpc-over-http/actions/workflows/ci.yml) | [instructions](https://github.com/UNIZAR-30246-WebEngineering/lab2-rpc-over-http/wiki)
30+
your name | your nia | your CI status | your solution

build.gradle.kts

+206
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
import de.undercouch.gradle.tasks.download.Download
2+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3+
import org.springframework.boot.gradle.tasks.bundling.BootJar
4+
5+
plugins {
6+
id("org.springframework.boot") version "2.5.5" apply false
7+
id("io.spring.dependency-management") version "1.0.11.RELEASE" apply false
8+
kotlin("jvm") version "1.5.31" apply false
9+
kotlin("plugin.spring") version "1.5.31" apply false
10+
11+
id("de.undercouch.download") version "4.1.2"
12+
java
13+
}
14+
15+
group = "es.unizar"
16+
version = "0.0.1-SNAPSHOT"
17+
18+
val jaxbVersion by extra { "2.1.7" }
19+
20+
subprojects {
21+
apply(plugin = "java")
22+
apply(plugin = "org.springframework.boot")
23+
apply(plugin = "io.spring.dependency-management")
24+
apply(plugin = "org.jetbrains.kotlin.jvm")
25+
apply(plugin = "org.jetbrains.kotlin.plugin.spring")
26+
repositories {
27+
mavenCentral()
28+
}
29+
tasks.withType<KotlinCompile> {
30+
kotlinOptions {
31+
freeCompilerArgs = listOf("-Xjsr305=strict")
32+
jvmTarget = "11"
33+
}
34+
}
35+
tasks.withType<Test> {
36+
useJUnitPlatform()
37+
}
38+
dependencies {
39+
"implementation"("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
40+
}
41+
tasks.withType<BootJar> {
42+
duplicatesStrategy = DuplicatesStrategy.INCLUDE
43+
}
44+
}
45+
46+
project(":server") {
47+
48+
val generatedJavaDirs = "$buildDir/generated-sources/xjc"
49+
val generatedClassesDirs = "$buildDir/classes/xjc"
50+
val schema = "$projectDir/src/main/resources/ws/translator.xsd"
51+
val jaxb by configurations.creating
52+
53+
dependencies {
54+
"implementation"("org.springframework.boot:spring-boot-starter-web")
55+
"implementation"("org.springframework.boot:spring-boot-starter-web-services")
56+
"implementation"("wsdl4j:wsdl4j")
57+
"runtimeOnly"("org.glassfish.jaxb:jaxb-runtime")
58+
jaxb("com.sun.xml.bind:jaxb-xjc:2.1.7")
59+
"implementation"(files(layout.buildDirectory.dir("classes/xjc")) {
60+
builtBy("genJaxb")
61+
})
62+
}
63+
64+
task("genJaxb") {
65+
val sourcedestdir = file(generatedJavaDirs)
66+
val classesdestdir = file(generatedClassesDirs)
67+
68+
doLast {
69+
sourcedestdir.mkdirs()
70+
classesdestdir.mkdirs()
71+
ant.withGroovyBuilder {
72+
"taskdef"(
73+
"name" to "xjc",
74+
"classname" to "com.sun.tools.xjc.XJCTask",
75+
"classpath" to jaxb.asPath
76+
)
77+
78+
"xjc"(
79+
"destdir" to sourcedestdir,
80+
"schema" to schema,
81+
"package" to "client.translator"
82+
)
83+
84+
"javac"(
85+
"destdir" to generatedClassesDirs,
86+
"source" to 1.8,
87+
"target" to 1.8,
88+
"debug" to true,
89+
"debugLevel" to "lines,vars,source",
90+
"classpath" to jaxb.asPath
91+
) {
92+
"src"("path" to sourcedestdir)
93+
"include"("name" to "**/*.java")
94+
"include"("name" to "*.java")
95+
}
96+
}
97+
}
98+
}
99+
tasks.withType<KotlinCompile> {
100+
dependsOn("genJaxb")
101+
}
102+
java {
103+
sourceSets {
104+
getByName("main").java.srcDirs(generatedJavaDirs)
105+
}
106+
}
107+
}
108+
109+
project(":client") {
110+
111+
val generatedJavaDirs = "$buildDir/generated-sources/xjc"
112+
val generatedClassesDirs = "$buildDir/classes/xjc"
113+
val generatedResourceDirs = "$buildDir/generated-sources/resources"
114+
val metaInfDir = "$generatedResourceDirs/META-INF"
115+
val wsdlDir = "$metaInfDir/wsdl"
116+
val catalogFile = "$metaInfDir/jax-ws-catalog.xml"
117+
val translatorWsdlFile = "$wsdlDir/translator.wsdl"
118+
val translatorResourceWsdl = "wsdl/translator.wsdl"
119+
val serverWsdlLocation = "http://localhost:8080/ws/translator.wsdl"
120+
val jaxb by configurations.creating
121+
122+
dependencies {
123+
"implementation"("org.springframework.boot:spring-boot-starter-web-services") {
124+
exclude("org.springframework.boot", "spring-boot-starter-tomcat")
125+
}
126+
"implementation"("org.springframework.ws:spring-ws-core")
127+
"implementation"("org.glassfish.jaxb:jaxb-runtime")
128+
jaxb("com.sun.xml.bind:jaxb-xjc:2.1.7")
129+
"implementation"(files(layout.buildDirectory.dir("classes/xjc")) {
130+
builtBy("genJaxb")
131+
})
132+
}
133+
134+
/**
135+
* It is common that the remote wsdl location is hardcoded into the code.
136+
* As the wsdl location may be not available, we use the JAXWS catalog to map
137+
* this remote resource to a local copy.
138+
*/
139+
task("create-catalog") {
140+
val file = file(catalogFile)
141+
file.parentFile.mkdirs()
142+
file.writeText(
143+
"""
144+
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
145+
<system systemId="$serverWsdlLocation" uri="$translatorResourceWsdl"/>
146+
</catalog>
147+
""".trimIndent()
148+
)
149+
}
150+
151+
task<Download>("download-wsdl") {
152+
val file = file(translatorWsdlFile)
153+
file.parentFile.mkdirs()
154+
src(serverWsdlLocation)
155+
dest(file)
156+
overwrite(true)
157+
}
158+
159+
task("genJaxb") {
160+
dependsOn("download-wsdl", "create-catalog")
161+
group = BasePlugin.BUILD_GROUP
162+
val sourcedestdir = file(generatedJavaDirs)
163+
val classesdestdir = file(generatedClassesDirs)
164+
165+
doLast {
166+
sourcedestdir.mkdirs()
167+
classesdestdir.mkdirs()
168+
ant.withGroovyBuilder {
169+
"taskdef"(
170+
"name" to "xjc",
171+
"classname" to "com.sun.tools.xjc.XJCTask",
172+
"classpath" to jaxb.asPath
173+
)
174+
175+
"xjc"(
176+
"destdir" to sourcedestdir,
177+
"schema" to serverWsdlLocation,
178+
"package" to "client.translator"
179+
) {
180+
"arg"("value" to "-wsdl")
181+
}
182+
"javac"(
183+
"destdir" to generatedClassesDirs,
184+
"source" to 1.8,
185+
"target" to 1.8,
186+
"debug" to true,
187+
"debugLevel" to "lines,vars,source",
188+
"classpath" to jaxb.asPath
189+
) {
190+
"src"("path" to sourcedestdir)
191+
"include"("name" to "**/*.java")
192+
"include"("name" to "*.java")
193+
}
194+
}
195+
}
196+
}
197+
tasks.withType<KotlinCompile> {
198+
dependsOn("genJaxb")
199+
}
200+
java {
201+
sourceSets {
202+
getByName("main").java.srcDirs(generatedJavaDirs)
203+
getByName("main").resources.srcDirs(generatedResourceDirs)
204+
}
205+
}
206+
}

client/src/main/kotlin/Client.kt

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package client
2+
3+
import client.translator.TranslationRequest
4+
import client.translator.TranslationResponse
5+
import org.springframework.boot.CommandLineRunner
6+
import org.springframework.boot.autoconfigure.SpringBootApplication
7+
import org.springframework.boot.runApplication
8+
import org.springframework.context.annotation.Bean
9+
import org.springframework.oxm.jaxb.Jaxb2Marshaller
10+
import org.springframework.ws.client.WebServiceClientException
11+
import org.springframework.ws.client.core.support.WebServiceGatewaySupport
12+
13+
/**
14+
* A translation client.
15+
*/
16+
class TranslatorClient : WebServiceGatewaySupport() {
17+
fun translate(translate: TranslationRequest) = webServiceTemplate.marshalSendAndReceive(translate) as TranslationResponse
18+
}
19+
20+
@SpringBootApplication
21+
class Client {
22+
23+
/**
24+
* The Jaxb2 marshaller/unmarshaller.
25+
*/
26+
@Bean
27+
fun marshaller() = Jaxb2Marshaller().apply {
28+
contextPath = "client.translator"
29+
}
30+
31+
/**
32+
* Defines a [TranslatorClient].
33+
*/
34+
@Bean
35+
fun translatorClient(marshaller: Jaxb2Marshaller) = TranslatorClient().apply {
36+
defaultUri = "http://localhost:8080/ws"
37+
unmarshaller = marshaller
38+
setMarshaller(marshaller)
39+
}
40+
41+
/**
42+
* The code that is run by this client.
43+
*/
44+
@Bean
45+
fun lookup(translatorClient: TranslatorClient) = CommandLineRunner {
46+
val input = "Translate me!"
47+
val request = TranslationRequest().apply {
48+
langFrom = "en"
49+
langTo = "es"
50+
text = input
51+
}
52+
try {
53+
println("Result of translating [$input] is [${translatorClient.translate(request).translation}]")
54+
} catch(exception : WebServiceClientException) {
55+
println("Something wrong is happening with the the server; fix it!")
56+
}
57+
}
58+
}
59+
60+
/**
61+
* The main entry point.
62+
*/
63+
fun main(args: Array<String>) {
64+
runApplication<Client>(*args)
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
spring.main.banner-mode=off
2+
logging.pattern.console=

gradle/wrapper/gradle-wrapper.jar

58.1 KB
Binary file not shown.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)