Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
3f3e7979
Commit
3f3e7979
authored
Nov 04, 2014
by
Matija Obreza
Browse files
Fail service creation when Transifex credentials are invalid
parent
eab9249c
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/transifex/client/TransifexException.java
0 → 100644
View file @
3f3e7979
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.genesys2.transifex.client
;
public
class
TransifexException
extends
Exception
{
public
TransifexException
(
String
message
,
Throwable
e
)
{
super
(
message
,
e
);
}
}
src/main/java/org/genesys2/transifex/client/TransifexServiceImpl.java
View file @
3f3e7979
...
...
@@ -74,6 +74,24 @@ public class TransifexServiceImpl implements TransifexService, InitializingBean
public
void
afterPropertiesSet
()
throws
Exception
{
transifexProjectUrl
=
TRANSIFEX_API_URL
.
concat
(
"/project/"
).
concat
(
projectSlug
);
LOG
.
info
(
"Transifex project URL: "
+
transifexProjectUrl
);
ensureTransifexCredentials
();
}
private
void
ensureTransifexCredentials
()
throws
TransifexException
{
HttpHeaders
headers
=
basicAuthentication
();
HttpEntity
<
String
>
request
=
new
HttpEntity
<>(
headers
);
try
{
ResponseEntity
<
String
>
response
=
template
.
exchange
(
transifexProjectUrl
+
"/?details"
,
HttpMethod
.
GET
,
request
,
String
.
class
);
// response.getBody() // contains JSON information about the project
if
(
LOG
.
isInfoEnabled
())
{
LOG
.
info
(
"Transifex connection okay! HTTP status code="
+
response
.
getStatusCode
());
}
}
catch
(
HttpClientErrorException
e
)
{
// Fail here to stop initializing the context!
throw
new
TransifexException
(
"Transifex credentials are not valid."
,
e
);
}
}
// Transifex requires Basic HTTP authentication!
...
...
@@ -200,9 +218,9 @@ public class TransifexServiceImpl implements TransifexService, InitializingBean
// Create Multi value map with all necessary information for request
MultiValueMap
<
String
,
Object
>
map
=
new
LinkedMultiValueMap
<>();
//
map.add("slug", slug);
//
map.add("name", title);
//
map.add("i18n_type", "XHTML");
//
map.add("slug", slug);
//
map.add("name", title);
//
map.add("i18n_type", "XHTML");
File
tempFile
=
File
.
createTempFile
(
slug
,
".xhtml"
);
// default FileWriter support default encoding only
...
...
@@ -221,7 +239,7 @@ public class TransifexServiceImpl implements TransifexService, InitializingBean
// Send our post request(with .xhtml file) to Transifex
template
.
put
(
transifexProjectUrl
+
"/resource/{slug}/content/"
,
request
,
slug
);
}
catch
(
HttpClientErrorException
e
)
{
LOG
.
error
(
e
.
getMessage
());
LOG
.
error
(
e
.
getResponseBodyAsString
());
...
...
Write
Preview
Supports
Markdown
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