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
9c6abd8c
Commit
9c6abd8c
authored
Jun 13, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Obsługa zdjęć w SOAP
parent
79e96bc4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
0 deletions
+74
-0
PhotoUtil.java
PC25-SoapSerwer/src/main/java/sklep/soap/PhotoUtil.java
+63
-0
Sklep.java
PC25-SoapSerwer/src/main/java/sklep/soap/Sklep.java
+11
-0
No files found.
PC25-SoapSerwer/src/main/java/sklep/soap/PhotoUtil.java
0 → 100644
View file @
9c6abd8c
package
sklep
.
soap
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.StandardCopyOption
;
import
sklep.db.DBException
;
import
sklep.db.DBSettings
;
import
sklep.db.RecordNotFound
;
public
class
PhotoUtil
{
private
static
final
String
EXT
=
".jpg"
;
public
static
File
getFile
(
int
productId
)
throws
DBException
,
RecordNotFound
{
Path
path
=
getPath
(
productId
);
File
file
=
path
.
toFile
();
if
(
file
.
exists
())
{
return
file
;
}
else
{
throw
new
RecordNotFound
(
"Cannot read photo for product id = "
+
productId
);
}
}
public
static
byte
[]
readBytes
(
int
productId
)
throws
DBException
,
RecordNotFound
{
Path
path
=
getPath
(
productId
);
try
{
return
Files
.
readAllBytes
(
path
);
}
catch
(
IOException
e
)
{
// System.err.println(e);
throw
new
RecordNotFound
(
"Cannot read photo for product id = "
+
productId
);
}
}
public
static
void
writeStream
(
int
productId
,
InputStream
inputStream
)
{
try
{
Path
path
=
getPath
(
productId
);
Files
.
copy
(
inputStream
,
path
,
StandardCopyOption
.
REPLACE_EXISTING
);
}
catch
(
Exception
e
)
{
// wypisujemy błąd, ale metoda kończy się normalnie
e
.
printStackTrace
();
}
}
public
static
void
writeBytes
(
int
productId
,
byte
[]
bytes
)
{
try
{
Path
path
=
getPath
(
productId
);
Files
.
write
(
path
,
bytes
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
private
static
Path
getPath
(
int
productId
)
throws
DBException
{
String
dir
=
DBSettings
.
load
().
getProperty
(
"photo_dir"
);
String
fileName
=
productId
+
EXT
;
return
Paths
.
get
(
dir
,
fileName
);
}
}
PC25-SoapSerwer/src/main/java/sklep/soap/Sklep.java
View file @
9c6abd8c
...
@@ -3,6 +3,7 @@ package sklep.soap;
...
@@ -3,6 +3,7 @@ package sklep.soap;
import
jakarta.jws.WebParam
;
import
jakarta.jws.WebParam
;
import
jakarta.jws.WebResult
;
import
jakarta.jws.WebResult
;
import
jakarta.jws.WebService
;
import
jakarta.jws.WebService
;
import
jakarta.xml.ws.soap.MTOM
;
import
sklep.db.*
;
import
sklep.db.*
;
import
sklep.model.*
;
import
sklep.model.*
;
...
@@ -15,6 +16,7 @@ import java.util.List;
...
@@ -15,6 +16,7 @@ import java.util.List;
// @XmlElement, @XmlValue ...
// @XmlElement, @XmlValue ...
@WebService
@WebService
@MTOM
public
class
Sklep
{
public
class
Sklep
{
@WebResult
(
name
=
"product"
)
@WebResult
(
name
=
"product"
)
...
@@ -65,4 +67,13 @@ public class Sklep {
...
@@ -65,4 +67,13 @@ public class Sklep {
}
}
}
}
@WebResult
(
name
=
"bytes"
)
public
byte
[]
getPhoto
(
@WebParam
(
name
=
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
return
PhotoUtil
.
readBytes
(
productId
);
}
public
void
savePhoto
(
@WebParam
(
name
=
"id"
)
int
productId
,
@WebParam
(
name
=
"bytes"
)
byte
[]
bytes
)
{
PhotoUtil
.
writeBytes
(
productId
,
bytes
);
}
}
}
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