Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vollt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sonia Zorba
vollt
Commits
cb5cdd73
Commit
cb5cdd73
authored
6 years ago
by
Grégory Mantelet
Browse files
Options
Downloads
Patches
Plain Diff
[UWS] Make the default backup mechanism independent from the library `cos`.
_This latter will soon be removed from UWSLib._
parent
e447a487
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/uws/service/backup/DefaultUWSBackupManager.java
+63
-29
63 additions, 29 deletions
src/uws/service/backup/DefaultUWSBackupManager.java
with
63 additions
and
29 deletions
src/uws/service/backup/DefaultUWSBackupManager.java
+
63
−
29
View file @
cb5cdd73
...
@@ -40,6 +40,8 @@ import java.util.NoSuchElementException;
...
@@ -40,6 +40,8 @@ import java.util.NoSuchElementException;
import
java.util.Timer
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
java.util.TimerTask
;
import
javax.xml.bind.DatatypeConverter
;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
...
@@ -47,9 +49,6 @@ import org.json.JSONTokener;
...
@@ -47,9 +49,6 @@ import org.json.JSONTokener;
import
org.json.JSONWriter
;
import
org.json.JSONWriter
;
import
org.json.Json4Uws
;
import
org.json.Json4Uws
;
import
com.oreilly.servlet.Base64Decoder
;
import
com.oreilly.servlet.Base64Encoder
;
import
uws.ISO8601Format
;
import
uws.ISO8601Format
;
import
uws.UWSException
;
import
uws.UWSException
;
import
uws.UWSToolBox
;
import
uws.UWSToolBox
;
...
@@ -87,7 +86,7 @@ import uws.service.request.UploadFile;
...
@@ -87,7 +86,7 @@ import uws.service.request.UploadFile;
* <p>Another positive value will be considered as the frequency (in milliseconds) of the automatic backup (= {@link #saveAll()}).</p>
* <p>Another positive value will be considered as the frequency (in milliseconds) of the automatic backup (= {@link #saveAll()}).</p>
*
*
* @author Grégory Mantelet (CDS;ARI)
* @author Grégory Mantelet (CDS;ARI)
* @version 4.
3
(0
5
/2018)
* @version 4.
4
(0
8
/2018)
*/
*/
public
class
DefaultUWSBackupManager
implements
UWSBackupManager
{
public
class
DefaultUWSBackupManager
implements
UWSBackupManager
{
...
@@ -619,19 +618,21 @@ public class DefaultUWSBackupManager implements UWSBackupManager {
...
@@ -619,19 +618,21 @@ public class DefaultUWSBackupManager implements UWSBackupManager {
oOutput
=
new
ObjectOutputStream
(
bArray
);
oOutput
=
new
ObjectOutputStream
(
bArray
);
oOutput
.
writeObject
(
jobInfo
);
oOutput
.
writeObject
(
jobInfo
);
oOutput
.
flush
();
oOutput
.
flush
();
return
Base64
Encoder
.
encode
(
bArray
.
toByteArray
());
return
to
Base64
(
bArray
.
toByteArray
());
}
catch
(
IOException
ioe
){
}
catch
(
IOException
ioe
){
throw
new
UWSException
(
UWSException
.
INTERNAL_SERVER_ERROR
,
ioe
,
"Unexpected error while serializing the given JobInfo!"
);
throw
new
UWSException
(
UWSException
.
INTERNAL_SERVER_ERROR
,
ioe
,
"Unexpected error while serializing the given JobInfo!"
);
}
finally
{
}
finally
{
if
(
oOutput
!=
null
){
if
(
oOutput
!=
null
){
try
{
try
{
oOutput
.
close
();
oOutput
.
close
();
}
catch
(
IOException
ioe
){}
}
catch
(
IOException
ioe
){
}
}
}
if
(
bArray
!=
null
){
if
(
bArray
!=
null
){
try
{
try
{
bArray
.
close
();
bArray
.
close
();
}
catch
(
IOException
ioe
){}
}
catch
(
IOException
ioe
){
}
}
}
}
}
}
}
...
@@ -656,7 +657,7 @@ public class DefaultUWSBackupManager implements UWSBackupManager {
...
@@ -656,7 +657,7 @@ public class DefaultUWSBackupManager implements UWSBackupManager {
protected
JobInfo
restoreJobInfo
(
final
Object
jsonValue
)
throws
UWSException
,
JSONException
{
protected
JobInfo
restoreJobInfo
(
final
Object
jsonValue
)
throws
UWSException
,
JSONException
{
ObjectInputStream
oInput
=
null
;
ObjectInputStream
oInput
=
null
;
try
{
try
{
byte
[]
bArray
=
Base64
Decoder
.
decodeToBytes
((
String
)
jsonValue
);
byte
[]
bArray
=
from
Base64
((
String
)
jsonValue
);
oInput
=
new
ObjectInputStream
(
new
ByteArrayInputStream
(
bArray
));
oInput
=
new
ObjectInputStream
(
new
ByteArrayInputStream
(
bArray
));
return
(
JobInfo
)
oInput
.
readObject
();
return
(
JobInfo
)
oInput
.
readObject
();
}
catch
(
Exception
ex
){
}
catch
(
Exception
ex
){
...
@@ -665,10 +666,41 @@ public class DefaultUWSBackupManager implements UWSBackupManager {
...
@@ -665,10 +666,41 @@ public class DefaultUWSBackupManager implements UWSBackupManager {
if
(
oInput
!=
null
){
if
(
oInput
!=
null
){
try
{
try
{
oInput
.
close
();
oInput
.
close
();
}
catch
(
IOException
ioe
){
}
}
catch
(
IOException
ioe
){
}
}
}
}
}
}
}
/**
* Encode the given bytes into a Base-64 string.
*
* @param bytes Bytes to encode.
*
* @return Base-64 encoded string.
*
* @since 4.4
*
* @see #fromBase64(String)
*/
protected
final
String
toBase64
(
final
byte
[]
bytes
){
return
DatatypeConverter
.
printBase64Binary
(
bytes
);
}
/**
* Decode the given Base-64 string into a bytes array.
*
* @param base64Str Base-64 string to decode.
*
* @return Decoded bytes.
*
* @since 4.4
*
* @see #toBase64(byte[])
*/
protected
final
byte
[]
fromBase64
(
final
String
base64Str
){
return
DatatypeConverter
.
parseBase64Binary
(
base64Str
);
}
/**
/**
* Get the JSON representation of the given {@link UploadFile}.
* Get the JSON representation of the given {@link UploadFile}.
...
@@ -1032,7 +1064,8 @@ public class DefaultUWSBackupManager implements UWSBackupManager {
...
@@ -1032,7 +1064,8 @@ public class DefaultUWSBackupManager implements UWSBackupManager {
UploadFile
upl
;
UploadFile
upl
;
try
{
try
{
for
(
int
i
=
0
;
i
<
uploads
.
length
();
i
++){
for
(
int
i
=
0
;
i
<
uploads
.
length
();
i
++){
upl
=
getUploadFile
(
uploads
.
getJSONObject
(
i
));;
upl
=
getUploadFile
(
uploads
.
getJSONObject
(
i
));
;
if
(
upl
!=
null
)
if
(
upl
!=
null
)
params
.
put
(
upl
.
paramName
,
upl
);
params
.
put
(
upl
.
paramName
,
upl
);
}
}
...
@@ -1150,7 +1183,8 @@ public class DefaultUWSBackupManager implements UWSBackupManager {
...
@@ -1150,7 +1183,8 @@ public class DefaultUWSBackupManager implements UWSBackupManager {
try
{
try
{
if
(
obj
.
has
(
"length"
))
if
(
obj
.
has
(
"length"
))
upl
.
length
=
Long
.
parseLong
(
obj
.
getString
(
"length"
));
upl
.
length
=
Long
.
parseLong
(
obj
.
getString
(
"length"
));
}
catch
(
NumberFormatException
ex
){}
}
catch
(
NumberFormatException
ex
){
}
return
upl
;
return
upl
;
}
catch
(
JSONException
je
){
}
catch
(
JSONException
je
){
getLogger
().
logUWS
(
LogLevel
.
ERROR
,
obj
,
"RESTORATION"
,
"Incorrect JSON format for the serialization of an uploaded file!"
,
je
);
getLogger
().
logUWS
(
LogLevel
.
ERROR
,
obj
,
"RESTORATION"
,
"Incorrect JSON format for the serialization of an uploaded file!"
,
je
);
...
...
This diff is collapsed.
Click to expand it.
Sonia Zorba
@zorba
mentioned in commit
3d22e42a
·
4 years ago
mentioned in commit
3d22e42a
mentioned in commit 3d22e42af3d6971c71e345963c17de79b07902cc
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment