Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20240528-BJava
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
20240528-BJava
Commits
672abdea
Commit
672abdea
authored
Jun 28, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Przykład usługi SOAP opartej o "Provider" i XSLT
parent
d286d9d1
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
278 additions
and
0 deletions
+278
-0
pom.xml
PC25-SoapSerwer/pom.xml
+5
-0
RunXSLT.java
PC25-SoapSerwer/src/main/java/niskopoziomowe/RunXSLT.java
+46
-0
.gitkeep
PC25-SoapSerwer/src/main/webapp/.gitkeep
+0
-0
Kalkulator.wsdl
PC25-SoapSerwer/src/main/webapp/WEB-INF/wsdl/Kalkulator.wsdl
+169
-0
index.html
PC25-SoapSerwer/src/main/webapp/index.html
+11
-0
kalkulator.xsl
PC25-SoapSerwer/src/main/webapp/kalkulator.xsl
+47
-0
No files found.
PC25-SoapSerwer/pom.xml
View file @
672abdea
...
...
@@ -24,6 +24,11 @@
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
jakarta.annotation
</groupId>
<artifactId>
jakarta.annotation-api
</artifactId>
<version>
2.1.0
</version>
</dependency>
<dependency>
<groupId>
jakarta.xml.ws
</groupId>
<artifactId>
jakarta.xml.ws-api
</artifactId>
<version>
4.0.0
</version>
...
...
PC25-SoapSerwer/src/main/java/niskopoziomowe/RunXSLT.java
0 → 100644
View file @
672abdea
package
niskopoziomowe
;
import
jakarta.annotation.Resource
;
import
jakarta.servlet.ServletContext
;
import
javax.xml.transform.Source
;
import
javax.xml.transform.Transformer
;
import
javax.xml.transform.TransformerFactory
;
import
javax.xml.transform.dom.DOMResult
;
import
javax.xml.transform.dom.DOMSource
;
import
javax.xml.transform.stream.StreamSource
;
import
jakarta.xml.ws.Provider
;
import
jakarta.xml.ws.WebServiceContext
;
import
jakarta.xml.ws.WebServiceException
;
import
jakarta.xml.ws.WebServiceProvider
;
import
jakarta.xml.ws.handler.MessageContext
;
import
org.w3c.dom.Node
;
@WebServiceProvider
(
wsdlLocation
=
"WEB-INF/wsdl/Kalkulator.wsdl"
,
targetNamespace
=
"http://kalkulator.pl"
,
serviceName
=
"Kalkulator"
,
portName
=
"KalkulatorXSLT"
)
public
class
RunXSLT
implements
Provider
<
Source
>
{
@Resource
private
WebServiceContext
wsContext
;
public
Source
invoke
(
Source
request
)
{
try
{
ServletContext
servletContext
=
(
ServletContext
)
wsContext
.
getMessageContext
().
get
(
MessageContext
.
SERVLET_CONTEXT
);
StreamSource
xslt
=
new
StreamSource
(
servletContext
.
getResourceAsStream
(
"kalkulator.xsl"
));
// inne opcje, bez korzystania z WebServiceContext i ServletContext:
// StreamSource xslt = new StreamSource("C:/katalog/aplikacja/kalkulator.xsl");
// StreamSource xslt = new StreamSource("http://localhost:8080/PC10-Provider-1.0/kalkulator.xsl");
TransformerFactory
tf
=
TransformerFactory
.
newInstance
();
Transformer
tr
=
tf
.
newTransformer
(
xslt
);
DOMResult
result
=
new
DOMResult
();
tr
.
transform
(
request
,
result
);
Node
dom
=
result
.
getNode
();
DOMSource
ultimateResult
=
new
DOMSource
(
dom
);
return
ultimateResult
;
}
catch
(
Exception
e
)
{
throw
new
WebServiceException
(
"XSLTProvider error"
,
e
);
}
}
}
PC25-SoapSerwer/src/main/webapp/.gitkeep
0 → 100644
View file @
672abdea
PC25-SoapSerwer/src/main/webapp/WEB-INF/wsdl/Kalkulator.wsdl
0 → 100644
View file @
672abdea
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions
xmlns:soap=
"http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns=
"http://kalkulator.pl"
xmlns:wsdl=
"http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd=
"http://www.w3.org/2001/XMLSchema"
name=
"Kalkulator"
targetNamespace=
"http://kalkulator.pl"
>
<wsdl:types>
<xsd:schema
targetNamespace=
"http://kalkulator.pl"
>
<xsd:complexType
name=
"TwoInts"
>
<xsd:sequence>
<xsd:element
name=
"arg1"
type=
"xsd:int"
/>
<xsd:element
name=
"arg2"
type=
"xsd:int"
/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType
name=
"IntResult"
>
<xsd:sequence>
<xsd:element
name=
"result"
type=
"xsd:int"
/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType
name=
"DivResponse"
>
<xsd:sequence>
<xsd:element
name=
"quotient"
type=
"xsd:int"
/>
<xsd:element
name=
"rest"
type=
"xsd:int"
/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType
name=
"FloatSequence"
>
<xsd:sequence>
<xsd:element
name=
"arg"
type=
"xsd:float"
maxOccurs=
"unbounded"
/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType
name=
"FloatResult"
>
<xsd:sequence>
<xsd:element
name=
"result"
type=
"xsd:float"
/>
</xsd:sequence>
</xsd:complexType>
<xsd:element
name=
"iadd"
type=
"tns:TwoInts"
/>
<xsd:element
name=
"iaddResponse"
type=
"tns:IntResult"
/>
<xsd:element
name=
"isub"
type=
"tns:TwoInts"
/>
<xsd:element
name=
"isubResponse"
type=
"tns:IntResult"
/>
<xsd:element
name=
"idiv"
type=
"tns:TwoInts"
/>
<xsd:element
name=
"idivResponse"
type=
"tns:DivResponse"
/>
<xsd:element
name=
"fsum"
type=
"tns:FloatSequence"
/>
<xsd:element
name=
"fsumResponse"
type=
"tns:FloatResult"
/>
<xsd:element
name=
"favg"
type=
"tns:FloatSequence"
/>
<xsd:element
name=
"favgResponse"
type=
"tns:FloatResult"
/>
</xsd:schema>
</wsdl:types>
<wsdl:message
name=
"iaddRequest"
>
<wsdl:part
element=
"tns:iadd"
name=
"parameters"
/>
</wsdl:message>
<wsdl:message
name=
"iaddResponse"
>
<wsdl:part
element=
"tns:iaddResponse"
name=
"parameters"
/>
</wsdl:message>
<wsdl:message
name=
"isubRequest"
>
<wsdl:part
element=
"tns:isub"
name=
"parameters"
/>
</wsdl:message>
<wsdl:message
name=
"isubResponse"
>
<wsdl:part
element=
"tns:isubResponse"
name=
"parameters"
/>
</wsdl:message>
<wsdl:message
name=
"idivRequest"
>
<wsdl:part
element=
"tns:idiv"
name=
"parameters"
/>
</wsdl:message>
<wsdl:message
name=
"idivResponse"
>
<wsdl:part
element=
"tns:idivResponse"
name=
"parameters"
/>
</wsdl:message>
<wsdl:message
name=
"fsumRequest"
>
<wsdl:part
element=
"tns:fsum"
name=
"parameters"
/>
</wsdl:message>
<wsdl:message
name=
"fsumResponse"
>
<wsdl:part
element=
"tns:fsumResponse"
name=
"parameters"
/>
</wsdl:message>
<wsdl:message
name=
"favgRequest"
>
<wsdl:part
element=
"tns:favg"
name=
"parameters"
/>
</wsdl:message>
<wsdl:message
name=
"favgResponse"
>
<wsdl:part
element=
"tns:favgResponse"
name=
"parameters"
/>
</wsdl:message>
<wsdl:portType
name=
"Kalkulator"
>
<wsdl:operation
name=
"iadd"
>
<wsdl:input
message=
"tns:iaddRequest"
/>
<wsdl:output
message=
"tns:iaddResponse"
/>
</wsdl:operation>
<wsdl:operation
name=
"isub"
>
<wsdl:input
message=
"tns:isubRequest"
/>
<wsdl:output
message=
"tns:isubResponse"
/>
</wsdl:operation>
<wsdl:operation
name=
"idiv"
>
<wsdl:input
message=
"tns:idivRequest"
/>
<wsdl:output
message=
"tns:idivResponse"
/>
</wsdl:operation>
<wsdl:operation
name=
"fsum"
>
<wsdl:input
message=
"tns:fsumRequest"
/>
<wsdl:output
message=
"tns:fsumResponse"
/>
</wsdl:operation>
<wsdl:operation
name=
"favg"
>
<wsdl:input
message=
"tns:favgRequest"
/>
<wsdl:output
message=
"tns:favgResponse"
/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding
name=
"KalkulatorSOAP"
type=
"tns:Kalkulator"
>
<soap:binding
style=
"document"
transport=
"http://schemas.xmlsoap.org/soap/http"
/>
<wsdl:operation
name=
"iadd"
>
<soap:operation
soapAction=
"http://kalkulator.pl/iadd"
/>
<wsdl:input>
<soap:body
use=
"literal"
/>
</wsdl:input>
<wsdl:output>
<soap:body
use=
"literal"
/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation
name=
"isub"
>
<soap:operation
soapAction=
"http://kalkulator.pl/isub"
/>
<wsdl:input>
<soap:body
use=
"literal"
/>
</wsdl:input>
<wsdl:output>
<soap:body
use=
"literal"
/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation
name=
"idiv"
>
<soap:operation
soapAction=
"http://kalkulator.pl/idiv"
/>
<wsdl:input>
<soap:body
use=
"literal"
/>
</wsdl:input>
<wsdl:output>
<soap:body
use=
"literal"
/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation
name=
"fsum"
>
<soap:operation
soapAction=
"http://kalkulator.pl/fsum"
/>
<wsdl:input>
<soap:body
use=
"literal"
/>
</wsdl:input>
<wsdl:output>
<soap:body
use=
"literal"
/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation
name=
"favg"
>
<soap:operation
soapAction=
"http://kalkulator.pl/favg"
/>
<wsdl:input>
<soap:body
use=
"literal"
/>
</wsdl:input>
<wsdl:output>
<soap:body
use=
"literal"
/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service
name=
"Kalkulator"
>
<wsdl:port
binding=
"tns:KalkulatorSOAP"
name=
"KalkulatorXSLT"
>
<soap:address
location=
"http://localhost:8080/PC25-SoapSerwer/Kalkulator"
/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
PC25-SoapSerwer/src/main/webapp/index.html
0 → 100644
View file @
672abdea
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
>
<title>
Hello XSLTProvider
</title>
</head>
<body>
<p>
Hello XSLTProvider
</p>
</body>
</html>
\ No newline at end of file
PC25-SoapSerwer/src/main/webapp/kalkulator.xsl
0 → 100644
View file @
672abdea
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version=
"1.0"
xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform"
xmlns:kalk=
"http://kalkulator.pl"
>
<xsl:template
match=
"kalk:iadd"
>
<kalk:iaddResponse>
<result>
<xsl:value-of
select=
"arg1 + arg2"
/>
</result>
</kalk:iaddResponse>
</xsl:template>
<xsl:template
match=
"kalk:isub"
>
<kalk:isubResponse>
<result>
<xsl:value-of
select=
"arg1 - arg2"
/>
</result>
</kalk:isubResponse>
</xsl:template>
<xsl:template
match=
"kalk:idiv"
>
<kalk:idivResponse>
<quotient>
<xsl:value-of
select=
"floor(arg1 div arg2)"
/>
<!-- Poprawnie tylko dla dodatnich) -->
</quotient>
<rest>
<xsl:value-of
select=
"arg1 mod arg2"
/>
</rest>
</kalk:idivResponse>
</xsl:template>
<xsl:template
match=
"kalk:fsum"
>
<kalk:fsumResponse>
<result>
<xsl:value-of
select=
"sum(arg)"
/>
</result>
</kalk:fsumResponse>
</xsl:template>
<xsl:template
match=
"kalk:favg"
>
<kalk:favgResponse>
<result>
<xsl:value-of
select=
"sum(arg) div count(arg)"
/>
</result>
</kalk:favgResponse>
</xsl:template>
</xsl:stylesheet>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment